Coupure prévue mardi 3 Août au matin pour maintenance du serveur. Nous faisons au mieux pour que celle-ci soit la plus brève possible.

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
10
bool DifferentialPropertiesPlugin::enable()
{
11
12
	m_computeNormalDialog = new ComputeNormalDialog(m_window);
	m_computeCurvatureDialog = new ComputeCurvatureDialog(m_window);
13

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

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

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

23
24
25
26
27
	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()));
28

29
30
31
	return true;
}

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

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

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

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

Thery Sylvain's avatar
Thery Sylvain committed
64
		Algo::Surface::Geometry::computeNormalVertices<PFP>(*map, position, normal);
Pierre Kraemer's avatar
Pierre Kraemer committed
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
		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 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);

111
112
113
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();
		VertexAttribute<VEC3> Kmin = map->getAttribute<VEC3, VERTEX>(KminName);
		if(!Kmin.isValid())
			Kmin = map->addAttribute<VEC3, VERTEX>(KminName);

120
121
122
123
124
125
126
127
128
		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);

129
130
131
132
133
134
135
136
		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();
		VertexAttribute<VEC3> Knormal = map->getAttribute<VEC3, VERTEX>(KnormalName);
		if(!Knormal.isValid())
			Knormal = map->addAttribute<VEC3, VERTEX>(KnormalName);
137

138
139
140
		EdgeAttribute<REAL> edgeAngle = map->getAttribute<REAL, EDGE>("edgeAngle");
		if(!edgeAngle.isValid())
			edgeAngle = map->addAttribute<REAL, EDGE>("edgeAngle");
141
		Algo::Surface::Geometry::computeAnglesBetweenNormalsOnEdges<PFP>(*map, position, edgeAngle);
142

143
		Algo::Surface::Geometry::computeCurvatureVertices_NormalCycles_Projected<PFP>(*map, 0.01f * mh->getBBdiagSize(), position, normal, edgeAngle, kmax, kmin, Kmax, Kmin, Knormal);
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158

		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
159
160
161
162
163
164
165

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

169
170
171
172
173
#ifndef DEBUG
Q_EXPORT_PLUGIN2(DifferentialPropertiesPlugin, DifferentialPropertiesPlugin)
#else
Q_EXPORT_PLUGIN2(DifferentialPropertiesPluginD, DifferentialPropertiesPlugin)
#endif