importVolume.cpp 1.72 KB
Newer Older
1
2
3
4
5
6
7
8
9
#include "importVolume.h"

#include "mapHandler.h"

#include "Algo/Import/import.h"

#include <QFileDialog>
#include <QFileInfo>

10
11
12
13
14
15
namespace CGoGN
{

namespace SCHNApps
{

16
17
18
19
bool ImportVolumePlugin::enable()
{
	importAction = new QAction("import", this);
	addMenuAction("Volume;Import", importAction);
20
	connect(importAction, SIGNAL(triggered()), this, SLOT(importFromFileDialog()));
21
22
23
	return true;
}

24
MapHandlerGen* ImportVolumePlugin::importFromFile(const QString& fileName)
25
26
27
28
{
	QFileInfo fi(fileName);
	if(fi.exists())
	{
29
30
31
32
33
		MapHandlerGen* mhg = m_window->addMap(fi.baseName(), 3);
		if(mhg)
		{
			MapHandler<PFP3>* mh = static_cast<MapHandler<PFP3>*>(mhg);
			PFP3::MAP* map = mh->getMap();
34

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

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

42
			// create position VBO
43
			mh->createVBO(position);
44

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

48
49
50
			// compute map bounding box
			mh->updateBB(position);
		}
51
		return mhg;
52
	}
53
54
	else
		return NULL;
55
56
}

57
58
void ImportVolumePlugin::importFromFileDialog()
{
59
60
61
62
63
64
	QStringList fileNames = QFileDialog::getOpenFileNames(m_window, "Import volumes", m_window->getAppPath(), "Volume mesh Files (*.node *.ts *.off *.tet)");
	QStringList::Iterator it = fileNames.begin();
	while(it != fileNames.end()) {
		importFromFile(*it);
		++it;
	}
65
66
}

67
68
69
70
71
#ifndef DEBUG
Q_EXPORT_PLUGIN2(ImportVolumePlugin, ImportVolumePlugin)
#else
Q_EXPORT_PLUGIN2(ImportVolumePluginD, ImportVolumePlugin)
#endif
72
73
74
75

} // namespace SCHNApps

} // namespace CGoGN