importSurface.cpp 1.48 KB
Newer Older
1
#include "importSurface.h"
2 3

#include "mapHandler.h"
4

5 6
#include "Algo/Import/import.h"

Pierre Kraemer's avatar
Pierre Kraemer committed
7 8 9
#include <QFileDialog>
#include <QFileInfo>

10
bool ImportSurfacePlugin::enable()
11 12
{
	importAction = new QAction("import", this);
13
	addMenuAction("Surface;Import", importAction);
14
	connect(importAction, SIGNAL(triggered()), this, SLOT(importFromFileDialog()));
15 16 17
	return true;
}

18
MapHandlerGen* ImportSurfacePlugin::importFromFile(const QString& fileName)
19
{
20
	QFileInfo fi(fileName);
Pierre Kraemer's avatar
Pierre Kraemer committed
21 22
	if(fi.exists())
	{
Pierre Kraemer's avatar
Pierre Kraemer committed
23 24 25 26 27
		MapHandlerGen* mhg = m_window->addMap(fi.baseName(), 2);
		if(mhg)
		{
			MapHandler<PFP2>* mh = static_cast<MapHandler<PFP2>*>(mhg);
			PFP2::MAP* map = mh->getMap();
Pierre Kraemer's avatar
Pierre Kraemer committed
28

29
			std::vector<std::string> attrNames;
30
			Algo::Surface::Import::importMesh<PFP2>(*map, fileName.toStdString(), attrNames);
Pierre Kraemer's avatar
Pierre Kraemer committed
31

Pierre Kraemer's avatar
Pierre Kraemer committed
32 33
			// get vertex position attribute
			VertexAttribute<PFP2::VEC3> position = map->getAttribute<PFP2::VEC3, CGoGN::VERTEX>(attrNames[0]);
34
			mh->registerAttribute<PFP2::VEC3, VERTEX>(position);
Pierre Kraemer's avatar
Pierre Kraemer committed
35

Pierre Kraemer's avatar
Pierre Kraemer committed
36 37
			// create VBO for vertex position attribute
			mh->createVBO(position);
Pierre Kraemer's avatar
Pierre Kraemer committed
38

Pierre Kraemer's avatar
Pierre Kraemer committed
39 40 41
			// compute map bounding box
			mh->updateBB(position);
		}
42
		return mhg;
Pierre Kraemer's avatar
Pierre Kraemer committed
43
	}
44 45
	else
		return NULL;
46 47
}

48 49 50 51 52 53
void ImportSurfacePlugin::importFromFileDialog()
{
	QString fileName = QFileDialog::getOpenFileName(m_window, "Import file", m_window->getAppPath(), "Mesh Files (*.ply *.off *.trian)");
	importFromFile(fileName);
}

54
#ifndef DEBUG
55
Q_EXPORT_PLUGIN2(ImportSurfacePlugin, ImportSurfacePlugin)
56
#else
57
Q_EXPORT_PLUGIN2(ImportSurfacePluginD, ImportSurfacePlugin)
58
#endif