differentialProperties.cpp 5.59 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 11
	m_computeNormalDialog = new ComputeNormalDialog(m_window);
	m_computeCurvatureDialog = new ComputeCurvatureDialog(m_window);
12

13
	computeNormalAction = new QAction("Compute Normal", this);
Pierre Kraemer's avatar
Pierre Kraemer committed
14 15
	computeCurvatureAction = new QAction("Compute Curvature", this);

16
	addMenuAction("Surface;Differential Properties;Compute Normal", computeNormalAction);
Pierre Kraemer's avatar
Pierre Kraemer committed
17 18
	addMenuAction("Surface;Differential Properties;Compute Curvature", computeCurvatureAction);

19 20
	connect(computeNormalAction, SIGNAL(triggered()), this, SLOT(cb_openComputeNormalDialog()));
	connect(computeCurvatureAction, SIGNAL(triggered()), this, SLOT(cb_openComputeCurvatureDialog()));
21

22 23 24 25 26
	connect(m_computeNormalDialog, SIGNAL(accepted()), this, SLOT(cb_computeNormal()));
	connect(m_computeNormalDialog->button_apply, SIGNAL(clicked()), this, SLOT(cb_computeNormal()));

	connect(m_computeCurvatureDialog, SIGNAL(accepted()), this, SLOT(cb_computeCurvature()));
	connect(m_computeCurvatureDialog->button_apply, SIGNAL(clicked()), this, SLOT(cb_computeCurvature()));
27

28 29 30
	return true;
}

31 32 33 34 35 36 37
void DifferentialPropertiesPlugin::cb_openComputeNormalDialog()
{
	m_computeNormalDialog->init();
	m_computeNormalDialog->show();
}

void DifferentialPropertiesPlugin::cb_openComputeCurvatureDialog()
38
{
39 40
	m_computeCurvatureDialog->init();
	m_computeCurvatureDialog->show();
41 42
}

43
void DifferentialPropertiesPlugin::cb_computeNormal()
44
{
45
	QList<QListWidgetItem*> currentItems = m_computeNormalDialog->mapList->selectedItems();
46 47 48 49 50
	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
51

52 53 54 55 56 57
		std::string positionName = m_computeNormalDialog->combo_positionAttribute->currentText().toUtf8().constData();
		std::string normalName;
		if(m_computeNormalDialog->attributeName->text().isEmpty())
			normalName = m_computeNormalDialog->combo_normalAttribute->currentText().toUtf8().constData();
		else
			normalName = m_computeNormalDialog->attributeName->text().toUtf8().constData();
58 59 60 61
		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
62

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

65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
		if(m_computeNormalDialog->check_createVBO->checkState() == Qt::Checked)
			mh->createVBO(normal);

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

void DifferentialPropertiesPlugin::cb_computeCurvature()
{
	QList<QListWidgetItem*> currentItems = m_computeCurvatureDialog->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_computeCurvatureDialog->combo_positionAttribute->currentText().toUtf8().constData();
		std::string normalName = m_computeCurvatureDialog->combo_normalAttribute->currentText().toUtf8().constData();

		VertexAttribute<VEC3> position = map->getAttribute<VEC3, VERTEX>(positionName);
		VertexAttribute<VEC3> normal = map->getAttribute<VEC3, VERTEX>(normalName);

		std::string KmaxName;
		if(m_computeCurvatureDialog->KmaxAttributeName->text().isEmpty())
			KmaxName = m_computeCurvatureDialog->combo_KmaxAttribute->currentText().toUtf8().constData();
		else
			KmaxName = m_computeCurvatureDialog->KmaxAttributeName->text().toUtf8().constData();
		VertexAttribute<VEC3> Kmax = map->getAttribute<VEC3, VERTEX>(KmaxName);
		if(!Kmax.isValid())
			Kmax = map->addAttribute<VEC3, VERTEX>(KmaxName);

		std::string KminName;
		if(m_computeCurvatureDialog->KminAttributeName->text().isEmpty())
			KminName = m_computeCurvatureDialog->combo_KminAttribute->currentText().toUtf8().constData();
		else
			KminName = m_computeCurvatureDialog->KminAttributeName->text().toUtf8().constData();
		VertexAttribute<VEC3> Kmin = map->getAttribute<VEC3, VERTEX>(KminName);
		if(!Kmin.isValid())
			Kmin = map->addAttribute<VEC3, VERTEX>(KminName);

		std::string kmaxName;
		if(m_computeCurvatureDialog->kmaxAttributeName->text().isEmpty())
			kmaxName = m_computeCurvatureDialog->combo_kmaxAttribute->currentText().toUtf8().constData();
		else
			kmaxName = m_computeCurvatureDialog->kmaxAttributeName->text().toUtf8().constData();
		VertexAttribute<REAL> kmax = map->getAttribute<REAL, VERTEX>(kmaxName);
		if(!kmax.isValid())
			kmax = map->addAttribute<REAL, VERTEX>(kmaxName);

		std::string kminName;
		if(m_computeCurvatureDialog->kminAttributeName->text().isEmpty())
			kminName = m_computeCurvatureDialog->combo_kminAttribute->currentText().toUtf8().constData();
		else
			kminName = m_computeCurvatureDialog->kminAttributeName->text().toUtf8().constData();
		VertexAttribute<REAL> kmin = map->getAttribute<REAL, VERTEX>(kminName);
		if(!kmin.isValid())
			kmin = map->addAttribute<REAL, VERTEX>(kminName);

		Algo::Geometry::computeCurvatureVertices_NormalCycles<PFP>(*map, position, normal);

		if(m_computeNormalDialog->check_createVBO->checkState() == Qt::Checked)
131
			mh->createVBO(normal);
Pierre Kraemer's avatar
Pierre Kraemer committed
132 133 134 135 136 137 138

		QList<View*> views = m_window->getViewsList();
		foreach(View* view, views)
		{
			if(view->isLinkedToMap(mh))
				view->updateGL();
		}
139 140 141
	}
}

142 143 144 145 146
#ifndef DEBUG
Q_EXPORT_PLUGIN2(DifferentialPropertiesPlugin, DifferentialPropertiesPlugin)
#else
Q_EXPORT_PLUGIN2(DifferentialPropertiesPluginD, DifferentialPropertiesPlugin)
#endif