importSurface.cpp 1.55 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 15 16 17
	connect(importAction, SIGNAL(triggered()), this, SLOT(cb_import()));
	return true;
}

18
void ImportSurfacePlugin::cb_import()
19
{
20
	QString fileName = QFileDialog::getOpenFileName(m_window, "Import file", m_window->getAppPath(), "Mesh Files (*.ply *.off *.trian)");
21 22
	QFileInfo fi(fileName);

Pierre Kraemer's avatar
Pierre Kraemer committed
23 24
	if(fi.exists())
	{
25 26 27 28
//		typename PFP2::MAP* m = new typename PFP2::MAP();
		GenericMap* m = m_window->createMap(2);
		typename PFP2::MAP* map = static_cast<typename PFP2::MAP*>(m);
		MapHandler<PFP2>* h = new MapHandler<PFP2>(fi.baseName(), m_window, map);
Pierre Kraemer's avatar
Pierre Kraemer committed
29 30

		std::vector<std::string> attrNames ;
31
		Algo::Surface::Import::importMesh<PFP2>(*map, fileName.toUtf8().constData(), attrNames);
Pierre Kraemer's avatar
Pierre Kraemer committed
32 33

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

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

		// compute map bounding box
40
		h->updateBB(position);
Pierre Kraemer's avatar
Pierre Kraemer committed
41 42

		// compute primitive connectivity VBOs
43 44 45
		h->updatePrimitives(Algo::Render::GL2::POINTS);
		h->updatePrimitives(Algo::Render::GL2::LINES);
		h->updatePrimitives(Algo::Render::GL2::TRIANGLES);
Pierre Kraemer's avatar
Pierre Kraemer committed
46 47 48

		m_window->addMap(h);
	}
49 50 51
}

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