differentialProperties.cpp 6.51 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
		MapHandler<PFP2>* mh = static_cast<MapHandler<PFP2>*>(m_window->getMap(mapname));
Pierre Kraemer's avatar
Pierre Kraemer committed
48

49 50
		QString positionName = m_computeNormalDialog->combo_positionAttribute->currentText();
		QString normalName;
51
		if(m_computeNormalDialog->normalAttributeName->text().isEmpty())
52
			normalName = m_computeNormalDialog->combo_normalAttribute->currentText();
53
		else
54
			normalName = m_computeNormalDialog->normalAttributeName->text();
55

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

61
		PFP2::MAP* map = mh->getMap();
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
		MapHandler<PFP2>* mh = static_cast<MapHandler<PFP2>*>(m_window->getMap(mapname));
80

81 82
		QString positionName = m_computeCurvatureDialog->combo_positionAttribute->currentText();
		QString normalName = m_computeCurvatureDialog->combo_normalAttribute->currentText();
83

84 85
		VertexAttribute<PFP2::VEC3> position = mh->getAttribute<PFP2::VEC3, VERTEX>(positionName);
		VertexAttribute<PFP2::VEC3> normal = mh->getAttribute<PFP2::VEC3, VERTEX>(normalName);
86

87
		QString KmaxName;
88
		if(m_computeCurvatureDialog->KmaxAttributeName->text().isEmpty())
89
			KmaxName = m_computeCurvatureDialog->combo_KmaxAttribute->currentText();
90
		else
91 92
			KmaxName = m_computeCurvatureDialog->KmaxAttributeName->text();
		VertexAttribute<PFP2::VEC3> Kmax = mh->getAttribute<PFP2::VEC3, VERTEX>(KmaxName);
93
		if(!Kmax.isValid())
94
			Kmax = mh->addAttribute<PFP2::VEC3, VERTEX>(KmaxName);
95

96
		QString kmaxName;
97
		if(m_computeCurvatureDialog->kmaxAttributeName->text().isEmpty())
98
			kmaxName = m_computeCurvatureDialog->combo_kmaxAttribute->currentText();
99
		else
100 101
			kmaxName = m_computeCurvatureDialog->kmaxAttributeName->text();
		VertexAttribute<PFP2::REAL> kmax = mh->getAttribute<PFP2::REAL, VERTEX>(kmaxName);
102
		if(!kmax.isValid())
103
			kmax = mh->addAttribute<PFP2::REAL, VERTEX>(kmaxName);
104

105
		QString KminName;
106
		if(m_computeCurvatureDialog->KminAttributeName->text().isEmpty())
107
			KminName = m_computeCurvatureDialog->combo_KminAttribute->currentText();
108
		else
109 110
			KminName = m_computeCurvatureDialog->KminAttributeName->text();
		VertexAttribute<PFP2::VEC3> Kmin = mh->getAttribute<PFP2::VEC3, VERTEX>(KminName);
111
		if(!Kmin.isValid())
112
			Kmin = mh->addAttribute<PFP2::VEC3, VERTEX>(KminName);
113

114
		QString kminName;
115
		if(m_computeCurvatureDialog->kminAttributeName->text().isEmpty())
116
			kminName = m_computeCurvatureDialog->combo_kminAttribute->currentText();
117
		else
118 119
			kminName = m_computeCurvatureDialog->kminAttributeName->text();
		VertexAttribute<PFP2::REAL> kmin = mh->getAttribute<PFP2::REAL, VERTEX>(kminName);
120
		if(!kmin.isValid())
121
			kmin = mh->addAttribute<PFP2::REAL, VERTEX>(kminName);
122

123
		QString KnormalName;
124
		if(m_computeCurvatureDialog->KnormalAttributeName->text().isEmpty())
125
			KnormalName = m_computeCurvatureDialog->combo_KnormalAttribute->currentText();
126
		else
127 128
			KnormalName = m_computeCurvatureDialog->KnormalAttributeName->text();
		VertexAttribute<PFP2::VEC3> Knormal = mh->getAttribute<PFP2::VEC3, VERTEX>(KnormalName);
129
		if(!Knormal.isValid())
130
			Knormal = mh->addAttribute<PFP2::VEC3, VERTEX>(KnormalName);
131

132
		EdgeAttribute<PFP2::REAL> edgeAngle = mh->getAttribute<PFP2::REAL, EDGE>("edgeAngle");
133
		if(!edgeAngle.isValid())
134
			edgeAngle = mh->addAttribute<PFP2::REAL, EDGE>("edgeAngle");
135

136 137
		PFP2::MAP* map = mh->getMap();
		Algo::Surface::Geometry::computeAnglesBetweenNormalsOnEdges<PFP2>(*map, position, edgeAngle);
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