importVolume.cpp 1.62 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13
#include "importVolume.h"

#include "mapHandler.h"

#include "Algo/Import/import.h"

#include <QFileDialog>
#include <QFileInfo>

bool ImportVolumePlugin::enable()
{
	importAction = new QAction("import", this);
	addMenuAction("Volume;Import", importAction);
14
	connect(importAction, SIGNAL(triggered()), this, SLOT(importFromFileDialog()));
15 16 17
	return true;
}

18
MapHandlerGen* ImportVolumePlugin::importFromFile(const QString& fileName)
19 20 21 22
{
	QFileInfo fi(fileName);
	if(fi.exists())
	{
23 24 25 26 27
		MapHandlerGen* mhg = m_window->addMap(fi.baseName(), 3);
		if(mhg)
		{
			MapHandler<PFP3>* mh = static_cast<MapHandler<PFP3>*>(mhg);
			PFP3::MAP* map = mh->getMap();
28

29 30
			std::vector<std::string> attrNames ;
			Algo::Volume::Import::importMesh<PFP3>(*map, fileName.toUtf8().constData(), attrNames);
31

32 33
			// get vertex position attribute
			VertexAttribute<PFP3::VEC3> position = map->getAttribute<PFP3::VEC3, CGoGN::VERTEX>(attrNames[0]);
34

35 36
			// create VBO for vertex position attribute
			mh->createVBO(position);
37

38 39
			// compute map bounding box
			mh->updateBB(position);
40

41 42 43 44 45
			// compute primitive connectivity VBOs
			mh->updatePrimitives(Algo::Render::GL2::POINTS);
			mh->updatePrimitives(Algo::Render::GL2::LINES);
			mh->updatePrimitives(Algo::Render::GL2::TRIANGLES);
		}
46
		return mhg;
47
	}
48 49
	else
		return NULL;
50 51
}

52 53 54 55 56 57
void ImportVolumePlugin::importFromFileDialog()
{
	QString fileName = QFileDialog::getOpenFileName(m_window, "Import file", m_window->getAppPath(), "Mesh Files (*.node *.ts *.off *.tet)");
	importFromFile(fileName);
}

58 59 60 61 62
#ifndef DEBUG
Q_EXPORT_PLUGIN2(ImportVolumePlugin, ImportVolumePlugin)
#else
Q_EXPORT_PLUGIN2(ImportVolumePluginD, ImportVolumePlugin)
#endif