importSurface.cpp 1.43 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;
Pierre Kraemer's avatar
Pierre Kraemer committed
30
			Algo::Surface::Import::importMesh<PFP2>(*map, fileName.toUtf8().constData(), 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]);
Pierre Kraemer's avatar
Pierre Kraemer committed
34

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

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

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

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