volume_import.cpp 1.76 KB
Newer Older
1
#include "volume_import.h"
Pierre Kraemer's avatar
Pierre Kraemer committed
2

3
#include "schnapps.h"
Pierre Kraemer's avatar
Pierre Kraemer committed
4 5 6 7 8 9 10 11 12 13 14 15 16
#include "mapHandler.h"

#include "Algo/Import/import.h"

#include <QFileDialog>
#include <QFileInfo>

namespace CGoGN
{

namespace SCHNApps
{

17
bool Volume_Import_Plugin::enable()
Pierre Kraemer's avatar
Pierre Kraemer committed
18 19
{
	importAction = new QAction("import", this);
20
	m_schnapps->addMenuAction(this, "Volume;Import", importAction);
Pierre Kraemer's avatar
Pierre Kraemer committed
21 22 23 24
	connect(importAction, SIGNAL(triggered()), this, SLOT(importFromFileDialog()));
	return true;
}

25
MapHandlerGen* Volume_Import_Plugin::importFromFile(const QString& fileName)
Pierre Kraemer's avatar
Pierre Kraemer committed
26 27 28 29
{
	QFileInfo fi(fileName);
	if(fi.exists())
	{
30
		MapHandlerGen* mhg = m_schnapps->addMap(fi.baseName(), 3);
Pierre Kraemer's avatar
Pierre Kraemer committed
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
		if(mhg)
		{
			MapHandler<PFP3>* mh = static_cast<MapHandler<PFP3>*>(mhg);
			PFP3::MAP* map = mh->getMap();

			std::vector<std::string> attrNames ;
			Algo::Volume::Import::importMesh<PFP3>(*map, fileName.toStdString(), attrNames);

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

			// update corresponding VBO & emit attribute update signal
			mh->notifyAttributeModification(position);

			// compute map bounding box
			mh->updateBB(position);
		}
		return mhg;
	}
	else
		return NULL;
}

55
void Volume_Import_Plugin::importFromFileDialog()
Pierre Kraemer's avatar
Pierre Kraemer committed
56
{
57
	QStringList fileNames = QFileDialog::getOpenFileNames(m_schnapps, "Import volumes", m_schnapps->getAppPath(), "Volume mesh Files (*.msh *.vtu *.nas *.vbgz *.tetmesh *.node *.ts *.off *.tet)");
Pierre Kraemer's avatar
Pierre Kraemer committed
58 59 60 61 62 63 64 65
	QStringList::Iterator it = fileNames.begin();
	while(it != fileNames.end()) {
		importFromFile(*it);
		++it;
	}
}

#ifndef DEBUG
66
Q_EXPORT_PLUGIN2(Volume_Import_Plugin, Volume_Import_Plugin)
Pierre Kraemer's avatar
Pierre Kraemer committed
67
#else
68
Q_EXPORT_PLUGIN2(Volume_Import_PluginD, Volume_Import_Plugin)
Pierre Kraemer's avatar
Pierre Kraemer committed
69 70 71 72 73
#endif

} // namespace SCHNApps

} // namespace CGoGN