differentialProperties.cpp 1.79 KB
Newer Older
1 2 3 4 5 6
#include "differentialProperties.h"

#include "mapHandler.h"

#include "Algo/Geometry/normal.h"

7

8 9
bool DifferentialPropertiesPlugin::enable()
{
10
	m_computeNormalsDialog = new ComputeNormalsDialog(m_window);
11 12 13

	computeNormalsAction = new QAction("import", this);
	addMenuAction("Surface;DifferentialProperties;Compute Normals", computeNormalsAction);
14 15 16 17
	connect(computeNormalsAction, SIGNAL(triggered()), this, SLOT(cb_openComputeNormalsDialog()));

	connect(m_computeNormalsDialog, SIGNAL(accepted()), this, SLOT(cb_computeNormals()));

18 19 20
	return true;
}

21
void DifferentialPropertiesPlugin::cb_openComputeNormalsDialog()
22
{
23
	m_computeNormalsDialog->init();
24 25 26
	m_computeNormalsDialog->show();
}

27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
void DifferentialPropertiesPlugin::cb_computeNormals()
{
	QList<QListWidgetItem*> currentItems = m_computeNormalsDialog->mapList->selectedItems();
	if(!currentItems.empty())
	{
		const QString& mapname = currentItems[0]->text();
		MapHandler<PFP>* mh = reinterpret_cast<MapHandler<PFP>*>(m_window->getMap(mapname));
		MAP* map = mh->getMap();
		std::string positionName = m_computeNormalsDialog->combo_positionAttribute->currentText().toUtf8().constData();
		std::string normalName = m_computeNormalsDialog->attributeName->text().toUtf8().constData();
		VertexAttribute<VEC3> position = map->getAttribute<VEC3, VERTEX>(positionName);
		VertexAttribute<VEC3> normal = map->getAttribute<VEC3, VERTEX>(normalName);
		if(!normal.isValid())
			normal = map->addAttribute<VEC3, VERTEX>(normalName);
		Algo::Geometry::computeNormalVertices<PFP>(*map, position, normal);
42 43
		if(m_computeNormalsDialog->check_createVBO->checkState() == Qt::Checked)
			mh->createVBO(normal);
44 45 46
	}
}

47 48 49 50 51
#ifndef DEBUG
Q_EXPORT_PLUGIN2(DifferentialPropertiesPlugin, DifferentialPropertiesPlugin)
#else
Q_EXPORT_PLUGIN2(DifferentialPropertiesPluginD, DifferentialPropertiesPlugin)
#endif