importSurface.cpp 1.77 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("Import;Import Surface", 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 29 30 31 32 33 34
	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
35
		h->createVBO(position);
Pierre Kraemer's avatar
Pierre Kraemer committed
36 37 38 39 40 41 42 43

		// 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
44
		h->createVBO(normal);
Pierre Kraemer's avatar
Pierre Kraemer committed
45 46

		// compute map bounding box
47
		h->updateBB(position);
Pierre Kraemer's avatar
Pierre Kraemer committed
48 49 50 51 52 53 54 55

		// 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);
	}
56 57 58
}

#ifndef DEBUG
59
Q_EXPORT_PLUGIN2(ImportSurfacePlugin, ImportSurfacePlugin)
60
#else
61
Q_EXPORT_PLUGIN2(ImportSurfacePluginD, ImportSurfacePlugin)
62
#endif