differentialProperties.cpp 9.28 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
	connect(m_window, SIGNAL(mapAdded(MapHandlerGen*)), this, SLOT(mapAdded(MapHandlerGen*)));
	connect(m_window, SIGNAL(mapRemoved(MapHandlerGen*)), this, SLOT(mapRemoved(MapHandlerGen*)));

31 32 33
	return true;
}

34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
void DifferentialPropertiesPlugin::mapAdded(MapHandlerGen *map)
{
	connect(map, SIGNAL(attributeModified(unsigned int, QString)), this, SLOT(attributeModified(unsigned int, QString)));
}

void DifferentialPropertiesPlugin::mapRemoved(MapHandlerGen *map)
{
	disconnect(map, SIGNAL(attributeModified(unsigned int, QString)), this, SLOT(attributeModified(unsigned int, QString)));
}

void DifferentialPropertiesPlugin::attributeModified(unsigned int orbit, QString nameAttr)
{
	if(orbit == VERTEX)
	{
		MapHandlerGen* map = static_cast<MapHandlerGen*>(QObject::sender());
		if(computeNormalLastParameters.contains(map->getName()))
		{
			ComputeNormalParameters& params = computeNormalLastParameters[map->getName()];
			if(params.positionName == nameAttr && params.autoUpdate)
				computeNormal(map->getName(), params.positionName, params.normalName, params.createVBO);
		}
	}
}

58
void DifferentialPropertiesPlugin::openComputeNormalDialog()
59 60 61 62
{
	m_computeNormalDialog->show();
}

63
void DifferentialPropertiesPlugin::openComputeCurvatureDialog()
64
{
65
	m_computeCurvatureDialog->show();
66 67
}

68
void DifferentialPropertiesPlugin::computeNormalFromDialog()
69
{
70
	QList<QListWidgetItem*> currentItems = m_computeNormalDialog->mapList->selectedItems();
71 72
	if(!currentItems.empty())
	{
73
		const QString& mapName = currentItems[0]->text();
Pierre Kraemer's avatar
Pierre Kraemer committed
74

75
		QString positionName = m_computeNormalDialog->combo_positionAttribute->currentText();
76

77
		QString normalName;
78
		if(m_computeNormalDialog->normalAttributeName->text().isEmpty())
79
			normalName = m_computeNormalDialog->combo_normalAttribute->currentText();
80
		else
81
			normalName = m_computeNormalDialog->normalAttributeName->text();
82

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

85 86 87
		bool autoUpdate = (currentItems[0]->checkState() == Qt::Checked);

		computeNormal(mapName, positionName, normalName, createVBO, autoUpdate);
88 89 90
	}
}

91
void DifferentialPropertiesPlugin::computeCurvatureFromDialog()
92 93 94 95
{
	QList<QListWidgetItem*> currentItems = m_computeCurvatureDialog->mapList->selectedItems();
	if(!currentItems.empty())
	{
96
		const QString& mapName = currentItems[0]->text();
97

98 99
		QString positionName = m_computeCurvatureDialog->combo_positionAttribute->currentText();
		QString normalName = m_computeCurvatureDialog->combo_normalAttribute->currentText();
100

101
		QString KmaxName;
102
		if(m_computeCurvatureDialog->KmaxAttributeName->text().isEmpty())
103
			KmaxName = m_computeCurvatureDialog->combo_KmaxAttribute->currentText();
104
		else
105
			KmaxName = m_computeCurvatureDialog->KmaxAttributeName->text();
106
		bool KmaxVBO = (m_computeCurvatureDialog->check_KmaxCreateVBO->checkState() == Qt::Checked);
107

108
		QString kmaxName;
109
		if(m_computeCurvatureDialog->kmaxAttributeName->text().isEmpty())
110
			kmaxName = m_computeCurvatureDialog->combo_kmaxAttribute->currentText();
111
		else
112
			kmaxName = m_computeCurvatureDialog->kmaxAttributeName->text();
113
		bool kmaxVBO = (m_computeCurvatureDialog->check_kmaxCreateVBO->checkState() == Qt::Checked);
114

115
		QString KminName;
116
		if(m_computeCurvatureDialog->KminAttributeName->text().isEmpty())
117
			KminName = m_computeCurvatureDialog->combo_KminAttribute->currentText();
118
		else
119
			KminName = m_computeCurvatureDialog->KminAttributeName->text();
120
		bool KminVBO = (m_computeCurvatureDialog->check_KminCreateVBO->checkState() == Qt::Checked);
121

122
		QString kminName;
123
		if(m_computeCurvatureDialog->kminAttributeName->text().isEmpty())
124
			kminName = m_computeCurvatureDialog->combo_kminAttribute->currentText();
125
		else
126
			kminName = m_computeCurvatureDialog->kminAttributeName->text();
127
		bool kminVBO = (m_computeCurvatureDialog->check_kminCreateVBO->checkState() == Qt::Checked);
128

129
		QString KnormalName;
130
		if(m_computeCurvatureDialog->KnormalAttributeName->text().isEmpty())
131
			KnormalName = m_computeCurvatureDialog->combo_KnormalAttribute->currentText();
132
		else
133
			KnormalName = m_computeCurvatureDialog->KnormalAttributeName->text();
134
		bool KnormalVBO = (m_computeCurvatureDialog->check_KnormalCreateVBO->checkState() == Qt::Checked);
135

136 137 138 139 140 141
		computeCurvature(
			mapName, positionName, normalName, KmaxName, kmaxName, KminName, kminName, KnormalName,
			KmaxVBO, kmaxVBO, KminVBO, kminVBO, KnormalVBO
		);
	}
}
142

143 144 145 146
void DifferentialPropertiesPlugin::computeNormal(
	const QString& mapName,
	const QString& positionAttributeName,
	const QString& normalAttributeName,
147 148
	bool createNormalVBO,
	bool autoUpdateNormal)
149 150 151 152
{
	MapHandler<PFP2>* mh = static_cast<MapHandler<PFP2>*>(m_window->getMap(mapName));
	if(mh == NULL)
		return;
Pierre Kraemer's avatar
Pierre Kraemer committed
153

154 155 156 157 158 159 160 161 162 163 164 165 166 167
	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);

168
	computeNormalLastParameters[mapName] =
169 170 171
		ComputeNormalParameters(positionAttributeName, normalAttributeName, createNormalVBO, autoUpdateNormal) ;

	mh->notifyAttributeModification(normal);
172

173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190
	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,
191 192 193 194 195 196
	bool createKnormalVBO,
	bool autoUpdateKmax,
	bool autoUpdatekmax,
	bool autoUpdateKmin,
	bool autoUpdatekmin,
	bool autoUpdateKnormal)
197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246
{
	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();
247 248
}

249 250 251 252 253
#ifndef DEBUG
Q_EXPORT_PLUGIN2(DifferentialPropertiesPlugin, DifferentialPropertiesPlugin)
#else
Q_EXPORT_PLUGIN2(DifferentialPropertiesPluginD, DifferentialPropertiesPlugin)
#endif