differentialProperties.cpp 7.85 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(computeNormalFromDialog()));
	connect(m_computeNormalDialog->button_apply, SIGNAL(clicked()), this, SLOT(computeNormalFromDialog()));
24

25 26
	connect(m_computeCurvatureDialog, SIGNAL(accepted()), this, SLOT(computeCurvatureFromDialog()));
	connect(m_computeCurvatureDialog->button_apply, SIGNAL(clicked()), this, SLOT(computeCurvatureFromDialog()));
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::computeNormalFromDialog()
42
{
43
	QList<QListWidgetItem*> currentItems = m_computeNormalDialog->mapList->selectedItems();
44 45
	if(!currentItems.empty())
	{
46
		const QString& mapName = currentItems[0]->text();
Pierre Kraemer's avatar
Pierre Kraemer committed
47

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

55
		bool createVBO = (m_computeNormalDialog->check_createVBO->checkState() == Qt::Checked);
Pierre Kraemer's avatar
Pierre Kraemer committed
56

57
		computeNormal(mapName, positionName, normalName, createVBO);
58 59 60
	}
}

61
void DifferentialPropertiesPlugin::computeCurvatureFromDialog()
62 63 64 65
{
	QList<QListWidgetItem*> currentItems = m_computeCurvatureDialog->mapList->selectedItems();
	if(!currentItems.empty())
	{
66
		const QString& mapName = currentItems[0]->text();
67

68 69
		QString positionName = m_computeCurvatureDialog->combo_positionAttribute->currentText();
		QString normalName = m_computeCurvatureDialog->combo_normalAttribute->currentText();
70

71
		QString KmaxName;
72
		if(m_computeCurvatureDialog->KmaxAttributeName->text().isEmpty())
73
			KmaxName = m_computeCurvatureDialog->combo_KmaxAttribute->currentText();
74
		else
75
			KmaxName = m_computeCurvatureDialog->KmaxAttributeName->text();
76

77
		QString kmaxName;
78
		if(m_computeCurvatureDialog->kmaxAttributeName->text().isEmpty())
79
			kmaxName = m_computeCurvatureDialog->combo_kmaxAttribute->currentText();
80
		else
81
			kmaxName = m_computeCurvatureDialog->kmaxAttributeName->text();
82

83
		QString KminName;
84
		if(m_computeCurvatureDialog->KminAttributeName->text().isEmpty())
85
			KminName = m_computeCurvatureDialog->combo_KminAttribute->currentText();
86
		else
87
			KminName = m_computeCurvatureDialog->KminAttributeName->text();
88

89
		QString kminName;
90
		if(m_computeCurvatureDialog->kminAttributeName->text().isEmpty())
91
			kminName = m_computeCurvatureDialog->combo_kminAttribute->currentText();
92
		else
93
			kminName = m_computeCurvatureDialog->kminAttributeName->text();
94

95
		QString KnormalName;
96
		if(m_computeCurvatureDialog->KnormalAttributeName->text().isEmpty())
97
			KnormalName = m_computeCurvatureDialog->combo_KnormalAttribute->currentText();
98
		else
99
			KnormalName = m_computeCurvatureDialog->KnormalAttributeName->text();
100

101
		bool KmaxVBO = (m_computeCurvatureDialog->check_KmaxCreateVBO->checkState() == Qt::Checked);
102

103
		bool kmaxVBO = (m_computeCurvatureDialog->check_kmaxCreateVBO->checkState() == Qt::Checked);
104

105
		bool KminVBO = (m_computeCurvatureDialog->check_KminCreateVBO->checkState() == Qt::Checked);
106

107
		bool kminVBO = (m_computeCurvatureDialog->check_kminCreateVBO->checkState() == Qt::Checked);
108

109
		bool KnormalVBO = (m_computeCurvatureDialog->check_KnormalCreateVBO->checkState() == Qt::Checked);
110

111 112 113 114 115 116
		computeCurvature(
			mapName, positionName, normalName, KmaxName, kmaxName, KminName, kminName, KnormalName,
			KmaxVBO, kmaxVBO, KminVBO, kminVBO, KnormalVBO
		);
	}
}
117

118 119 120 121 122 123 124 125 126
void DifferentialPropertiesPlugin::computeNormal(
	const QString& mapName,
	const QString& positionAttributeName,
	const QString& normalAttributeName,
	bool createNormalVBO)
{
	MapHandler<PFP2>* mh = static_cast<MapHandler<PFP2>*>(m_window->getMap(mapName));
	if(mh == NULL)
		return;
Pierre Kraemer's avatar
Pierre Kraemer committed
127

128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210
	VertexAttribute<PFP2::VEC3> position = mh->getAttribute<PFP2::VEC3, VERTEX>(positionAttributeName);
	if(!position.isValid())
		return;

	VertexAttribute<PFP2::VEC3> normal = mh->getAttribute<PFP2::VEC3, VERTEX>(normalAttributeName);
	if(!normal.isValid())
		normal = mh->addAttribute<PFP2::VEC3, VERTEX>(normalAttributeName);

	PFP2::MAP* map = mh->getMap();
	Algo::Surface::Geometry::computeNormalVertices<PFP2>(*map, position, normal);

	if(createNormalVBO)
		mh->createVBO(normal);

	QList<View*> views = mh->getLinkedViews();
	foreach(View* view, views)
		view->updateGL();
}

void DifferentialPropertiesPlugin::computeCurvature(
	const QString& mapName,
	const QString& positionAttributeName,
	const QString& normalAttributeName,
	const QString& KmaxAttributeName,
	const QString& kmaxAttributeName,
	const QString& KminAttributeName,
	const QString& kminAttributeName,
	const QString& KnormalAttributeName,
	bool createKmaxVBO,
	bool createkmaxVBO,
	bool createKminVBO,
	bool createkminVBO,
	bool createKnormalVBO)
{
	MapHandler<PFP2>* mh = static_cast<MapHandler<PFP2>*>(m_window->getMap(mapName));
	if(mh == NULL)
		return;

	VertexAttribute<PFP2::VEC3> position = mh->getAttribute<PFP2::VEC3, VERTEX>(positionAttributeName);
	if(!position.isValid())
		return;

	VertexAttribute<PFP2::VEC3> normal = mh->getAttribute<PFP2::VEC3, VERTEX>(normalAttributeName);
	if(!normal.isValid())
		return;

	VertexAttribute<PFP2::VEC3> Kmax = mh->getAttribute<PFP2::VEC3, VERTEX>(KmaxAttributeName);
	if(!Kmax.isValid())
		Kmax = mh->addAttribute<PFP2::VEC3, VERTEX>(KmaxAttributeName);

	VertexAttribute<PFP2::REAL> kmax = mh->getAttribute<PFP2::REAL, VERTEX>(kmaxAttributeName);
	if(!kmax.isValid())
		kmax = mh->addAttribute<PFP2::REAL, VERTEX>(kmaxAttributeName);

	VertexAttribute<PFP2::VEC3> Kmin = mh->getAttribute<PFP2::VEC3, VERTEX>(KminAttributeName);
	if(!Kmin.isValid())
		Kmin = mh->addAttribute<PFP2::VEC3, VERTEX>(KminAttributeName);

	VertexAttribute<PFP2::REAL> kmin = mh->getAttribute<PFP2::REAL, VERTEX>(kminAttributeName);
	if(!kmin.isValid())
		kmin = mh->addAttribute<PFP2::REAL, VERTEX>(kminAttributeName);

	VertexAttribute<PFP2::VEC3> Knormal = mh->getAttribute<PFP2::VEC3, VERTEX>(KnormalAttributeName);
	if(!Knormal.isValid())
		Knormal = mh->addAttribute<PFP2::VEC3, VERTEX>(KnormalAttributeName);

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

	PFP2::MAP* map = mh->getMap();
	Algo::Surface::Geometry::computeAnglesBetweenNormalsOnEdges<PFP2>(*map, position, edgeAngle);
	Algo::Surface::Geometry::computeCurvatureVertices_NormalCycles_Projected<PFP2>(*map, 0.02f * mh->getBBdiagSize(), position, normal, edgeAngle, kmax, kmin, Kmax, Kmin, Knormal);

	if(createKmaxVBO) mh->createVBO(Kmax);
	if(createkmaxVBO) mh->createVBO(kmax);
	if(createKminVBO) mh->createVBO(Kmin);
	if(createkminVBO) mh->createVBO(kmin);
	if(createKnormalVBO) mh->createVBO(Knormal);

	QList<View*> views = mh->getLinkedViews();
	foreach(View* view, views)
		view->updateGL();
211 212
}

213 214 215 216 217
#ifndef DEBUG
Q_EXPORT_PLUGIN2(DifferentialPropertiesPlugin, DifferentialPropertiesPlugin)
#else
Q_EXPORT_PLUGIN2(DifferentialPropertiesPluginD, DifferentialPropertiesPlugin)
#endif