differentialProperties.cpp 2.29 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

Pierre Kraemer's avatar
Pierre Kraemer committed
12 13 14 15 16 17
	computeNormalsAction = new QAction("Compute Normals", this);
	computeCurvatureAction = new QAction("Compute Curvature", this);

	addMenuAction("Surface;Differential Properties;Compute Normals", computeNormalsAction);
	addMenuAction("Surface;Differential Properties;Compute Curvature", computeCurvatureAction);

18
	connect(computeNormalsAction, SIGNAL(triggered()), this, SLOT(cb_openComputeNormalsDialog()));
Pierre Kraemer's avatar
Pierre Kraemer committed
19
	connect(computeCurvatureAction, SIGNAL(triggered()), this, SLOT(cb_openComputeNormalsDialog()));
20 21

	connect(m_computeNormalsDialog, SIGNAL(accepted()), this, SLOT(cb_computeNormals()));
Pierre Kraemer's avatar
Pierre Kraemer committed
22
	connect(m_computeNormalsDialog->button_apply, SIGNAL(clicked()), this, SLOT(cb_computeNormals()));
23

24 25 26
	return true;
}

27
void DifferentialPropertiesPlugin::cb_openComputeNormalsDialog()
28
{
29
	m_computeNormalsDialog->init();
30 31 32
	m_computeNormalsDialog->show();
}

33 34 35 36 37 38 39 40
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();
Pierre Kraemer's avatar
Pierre Kraemer committed
41

42 43 44 45 46 47
		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);
Pierre Kraemer's avatar
Pierre Kraemer committed
48

49
		Algo::Geometry::computeNormalVertices<PFP>(*map, position, normal);
Pierre Kraemer's avatar
Pierre Kraemer committed
50

51 52
		if(m_computeNormalsDialog->check_createVBO->checkState() == Qt::Checked)
			mh->createVBO(normal);
Pierre Kraemer's avatar
Pierre Kraemer committed
53 54 55 56 57 58 59

		QList<View*> views = m_window->getViewsList();
		foreach(View* view, views)
		{
			if(view->isLinkedToMap(mh))
				view->updateGL();
		}
60 61 62
	}
}

63 64 65 66 67
#ifndef DEBUG
Q_EXPORT_PLUGIN2(DifferentialPropertiesPlugin, DifferentialPropertiesPlugin)
#else
Q_EXPORT_PLUGIN2(DifferentialPropertiesPluginD, DifferentialPropertiesPlugin)
#endif