importSurface.cpp 1.47 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
		GenericMap* m = m_window->createMap(2);
Pierre Kraemer's avatar
Pierre Kraemer committed
26
		PFP2::MAP* map = static_cast<PFP2::MAP*>(m);
27
		MapHandler<PFP2>* h = new MapHandler<PFP2>(fi.baseName(), m_window, map);
Pierre Kraemer's avatar
Pierre Kraemer committed
28
29

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

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

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

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

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

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

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