importSurface.cpp 1.37 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 21 22
	QString fileName = QFileDialog::getOpenFileName(m_window, "Import file", m_window->getAppPath(), "Mesh Files (*.ply *.off)");
	QFileInfo fi(fileName);

Pierre Kraemer's avatar
Pierre Kraemer committed
23 24 25 26 27 28
	if(fi.exists())
	{
		MAP* m = new MAP();
		MapHandler<PFP>* h = new MapHandler<PFP>(fi.baseName(), m_window, m);

		std::vector<std::string> attrNames ;
Thery Sylvain's avatar
Thery Sylvain committed
29
		Algo::Surface::Import::importMesh<PFP>(*m, fileName.toUtf8().constData(), attrNames);
Pierre Kraemer's avatar
Pierre Kraemer committed
30 31 32 33 34

		// get vertex position attribute
		VertexAttribute<VEC3> position = m->getAttribute<VEC3, CGoGN::VERTEX>(attrNames[0]);

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

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

		// compute primitive connectivity VBOs
41 42 43
		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
44 45 46

		m_window->addMap(h);
	}
47 48 49
}

#ifndef DEBUG
50
Q_EXPORT_PLUGIN2(ImportSurfacePlugin, ImportSurfacePlugin)
51
#else
52
Q_EXPORT_PLUGIN2(ImportSurfacePluginD, ImportSurfacePlugin)
53
#endif