import.cpp 2.17 KB
Newer Older
1
2
#include "import.h"

3
#include "system.h"
4
#include "mapHandler.h"
5

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

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

11
12
13
14
15
16
17
18
19
20
21
22
23
24
bool ImportPlugin::enable()
{
	importAction = new QAction("import", this);
	addMenuAction("Import;import", importAction);
	connect(importAction, SIGNAL(triggered()), this, SLOT(cb_import()));
	return true;
}

void ImportPlugin::disable()
{
}

void ImportPlugin::cb_import()
{
25
26
27
	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
28
29
30
31
32
33
34
35
36
37
38
39
	if(fi.exists())
	{
		MAP* m = new MAP();
		MapHandler<PFP>* h = new MapHandler<PFP>(fi.baseName(), m_window, m);

		std::vector<std::string> attrNames ;
		Algo::Import::importMesh<PFP>(*m, fileName.toUtf8().constData(), attrNames);

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

		// create VBO for vertex position attribute
40
41
42
		h->createVBO(position);
//		Utils::VBO* positionVBO = h->getVBO(position.name());
//		positionVBO->updateData(position);
Pierre Kraemer's avatar
Pierre Kraemer committed
43
44
45
46
47
48
49
50

		// compute vertex normal attribute
		VertexAttribute<VEC3> normal = m->getAttribute<VEC3, CGoGN::VERTEX>("normal");
		if(!normal.isValid())
			normal = m->addAttribute<VEC3, CGoGN::VERTEX>("normal");
		Algo::Geometry::computeNormalVertices<PFP>(*m, position, normal);

		// create VBO for vertex normal attribute
51
52
53
		h->createVBO(normal);
//		CGoGN::Utils::VBO* normalVBO = h->getVBO(normal);
//		normalVBO->updateData(normal);
Pierre Kraemer's avatar
Pierre Kraemer committed
54
55

		// compute map bounding box
56
		h->updateBB(position);
Pierre Kraemer's avatar
Pierre Kraemer committed
57
58
59
60
61
62
63
64

		// compute primitive connectivity VBOs
		h->updatePrimitives(CGoGN::Algo::Render::GL2::POINTS, CGoGN::allDarts);
		h->updatePrimitives(CGoGN::Algo::Render::GL2::LINES, CGoGN::allDarts);
		h->updatePrimitives(CGoGN::Algo::Render::GL2::TRIANGLES, CGoGN::allDarts);

		m_window->addMap(h);
	}
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
}

/**
 * If we want to compile this plugin in debug mode,
 * we also define a DEBUG macro at the compilation
 */
#ifndef DEBUG
// essential Qt function:
// arguments are
//  - the compiled name of the plugin
//  - the main class of our plugin
Q_EXPORT_PLUGIN2(ImportPlugin, ImportPlugin)
#else
Q_EXPORT_PLUGIN2(ImportPluginD, ImportPlugin)
#endif