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

#include "mapHandler.h"

#include "Algo/Geometry/normal.h"
6
#include "Algo/Geometry/curvature.h"
7 8 9

bool DifferentialPropertiesPlugin::enable()
{
10 11
	m_computeNormalDialog = new ComputeNormalDialog(m_window);
	m_computeCurvatureDialog = new ComputeCurvatureDialog(m_window);
12

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

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

19 20
	connect(m_computeNormalAction, SIGNAL(triggered()), this, SLOT(openComputeNormalDialog()));
	connect(m_computeCurvatureAction, SIGNAL(triggered()), this, SLOT(openComputeCurvatureDialog()));
21

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

25 26
	connect(m_computeCurvatureDialog, SIGNAL(accepted()), this, SLOT(computeCurvature()));
	connect(m_computeCurvatureDialog->button_apply, SIGNAL(clicked()), this, SLOT(computeCurvature()));
27

28 29 30
	return true;
}

31
void DifferentialPropertiesPlugin::openComputeNormalDialog()
32 33 34 35
{
	m_computeNormalDialog->show();
}

36
void DifferentialPropertiesPlugin::openComputeCurvatureDialog()
37
{
38
	m_computeCurvatureDialog->show();
39 40
}

41
void DifferentialPropertiesPlugin::computeNormal()
42
{
43
	QList<QListWidgetItem*> currentItems = m_computeNormalDialog->mapList->selectedItems();
44 45 46
	if(!currentItems.empty())
	{
		const QString& mapname = currentItems[0]->text();
Pierre Kraemer's avatar
Pierre Kraemer committed
47 48
		MapHandler<PFP2>* mh = static_cast<MapHandler<PFP2>*>(m_window->getMap(mapname));
		PFP2::MAP* map = mh->getMap();
Pierre Kraemer's avatar
Pierre Kraemer committed
49

50 51
		std::string positionName = m_computeNormalDialog->combo_positionAttribute->currentText().toUtf8().constData();
		std::string normalName;
52
		if(m_computeNormalDialog->normalAttributeName->text().isEmpty())
53 54
			normalName = m_computeNormalDialog->combo_normalAttribute->currentText().toUtf8().constData();
		else
55
			normalName = m_computeNormalDialog->normalAttributeName->text().toUtf8().constData();
56

Pierre Kraemer's avatar
Pierre Kraemer committed
57 58
		VertexAttribute<PFP2::VEC3> position = map->getAttribute<PFP2::VEC3, VERTEX>(positionName);
		VertexAttribute<PFP2::VEC3> normal = map->getAttribute<PFP2::VEC3, VERTEX>(normalName);
59
		if(!normal.isValid())
Pierre Kraemer's avatar
Pierre Kraemer committed
60
			normal = map->addAttribute<PFP2::VEC3, VERTEX>(normalName);
Pierre Kraemer's avatar
Pierre Kraemer committed
61

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

64 65 66
		if(m_computeNormalDialog->check_createVBO->checkState() == Qt::Checked)
			mh->createVBO(normal);

67
		QList<View*> views = mh->getLinkedViews();
68
		foreach(View* view, views)
69
			view->updateGL();
70 71 72
	}
}

73
void DifferentialPropertiesPlugin::computeCurvature()
74 75 76 77 78
{
	QList<QListWidgetItem*> currentItems = m_computeCurvatureDialog->mapList->selectedItems();
	if(!currentItems.empty())
	{
		const QString& mapname = currentItems[0]->text();
Pierre Kraemer's avatar
Pierre Kraemer committed
79 80
		MapHandler<PFP2>* mh = static_cast<MapHandler<PFP2>*>(m_window->getMap(mapname));
		PFP2::MAP* map = mh->getMap();
81 82 83 84

		std::string positionName = m_computeCurvatureDialog->combo_positionAttribute->currentText().toUtf8().constData();
		std::string normalName = m_computeCurvatureDialog->combo_normalAttribute->currentText().toUtf8().constData();

Pierre Kraemer's avatar
Pierre Kraemer committed
85 86
		VertexAttribute<PFP2::VEC3> position = map->getAttribute<PFP2::VEC3, VERTEX>(positionName);
		VertexAttribute<PFP2::VEC3> normal = map->getAttribute<PFP2::VEC3, VERTEX>(normalName);
87 88 89 90 91 92

		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();
Pierre Kraemer's avatar
Pierre Kraemer committed
93
		VertexAttribute<PFP2::VEC3> Kmax = map->getAttribute<PFP2::VEC3, VERTEX>(KmaxName);
94
		if(!Kmax.isValid())
Pierre Kraemer's avatar
Pierre Kraemer committed
95
			Kmax = map->addAttribute<PFP2::VEC3, VERTEX>(KmaxName);
96 97 98 99 100 101

		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();
Pierre Kraemer's avatar
Pierre Kraemer committed
102
		VertexAttribute<PFP2::REAL> kmax = map->getAttribute<PFP2::REAL, VERTEX>(kmaxName);
103
		if(!kmax.isValid())
Pierre Kraemer's avatar
Pierre Kraemer committed
104
			kmax = map->addAttribute<PFP2::REAL, VERTEX>(kmaxName);
105

106 107 108 109 110
		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();
Pierre Kraemer's avatar
Pierre Kraemer committed
111
		VertexAttribute<PFP2::VEC3> Kmin = map->getAttribute<PFP2::VEC3, VERTEX>(KminName);
112
		if(!Kmin.isValid())
Pierre Kraemer's avatar
Pierre Kraemer committed
113
			Kmin = map->addAttribute<PFP2::VEC3, VERTEX>(KminName);
114

115 116 117 118 119
		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();
Pierre Kraemer's avatar
Pierre Kraemer committed
120
		VertexAttribute<PFP2::REAL> kmin = map->getAttribute<PFP2::REAL, VERTEX>(kminName);
121
		if(!kmin.isValid())
Pierre Kraemer's avatar
Pierre Kraemer committed
122
			kmin = map->addAttribute<PFP2::REAL, VERTEX>(kminName);
123

124 125 126 127 128
		std::string KnormalName;
		if(m_computeCurvatureDialog->KnormalAttributeName->text().isEmpty())
			KnormalName = m_computeCurvatureDialog->combo_KnormalAttribute->currentText().toUtf8().constData();
		else
			KnormalName = m_computeCurvatureDialog->KnormalAttributeName->text().toUtf8().constData();
Pierre Kraemer's avatar
Pierre Kraemer committed
129
		VertexAttribute<PFP2::VEC3> Knormal = map->getAttribute<PFP2::VEC3, VERTEX>(KnormalName);
130
		if(!Knormal.isValid())
Pierre Kraemer's avatar
Pierre Kraemer committed
131
			Knormal = map->addAttribute<PFP2::VEC3, VERTEX>(KnormalName);
132

Pierre Kraemer's avatar
Pierre Kraemer committed
133
		EdgeAttribute<PFP2::REAL> edgeAngle = map->getAttribute<PFP2::REAL, EDGE>("edgeAngle");
134
		if(!edgeAngle.isValid())
Pierre Kraemer's avatar
Pierre Kraemer committed
135
			edgeAngle = map->addAttribute<PFP2::REAL, EDGE>("edgeAngle");
136
		Algo::Surface::Geometry::computeAnglesBetweenNormalsOnEdges<PFP2>(*map, position, edgeAngle);
137

138
		Algo::Surface::Geometry::computeCurvatureVertices_NormalCycles_Projected<PFP2>(*map, 0.01f * mh->getBBdiagSize(), position, normal, edgeAngle, kmax, kmin, Kmax, Kmin, Knormal);
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153

		if(m_computeCurvatureDialog->check_KmaxCreateVBO->checkState() == Qt::Checked)
			mh->createVBO(Kmax);

		if(m_computeCurvatureDialog->check_kmaxCreateVBO->checkState() == Qt::Checked)
			mh->createVBO(kmax);

		if(m_computeCurvatureDialog->check_KminCreateVBO->checkState() == Qt::Checked)
			mh->createVBO(Kmin);

		if(m_computeCurvatureDialog->check_kminCreateVBO->checkState() == Qt::Checked)
			mh->createVBO(kmin);

		if(m_computeCurvatureDialog->check_KnormalCreateVBO->checkState() == Qt::Checked)
			mh->createVBO(Knormal);
Pierre Kraemer's avatar
Pierre Kraemer committed
154

155
		QList<View*> views = mh->getLinkedViews();
Pierre Kraemer's avatar
Pierre Kraemer committed
156
		foreach(View* view, views)
157
			view->updateGL();
158 159 160
	}
}

161 162 163 164 165
#ifndef DEBUG
Q_EXPORT_PLUGIN2(DifferentialPropertiesPlugin, DifferentialPropertiesPlugin)
#else
Q_EXPORT_PLUGIN2(DifferentialPropertiesPluginD, DifferentialPropertiesPlugin)
#endif