differentialProperties.cpp 6.96 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 15
	m_computeNormalAction = new QAction("Compute Normal", this);
	m_computeCurvatureAction = new QAction("Compute Curvature", this);
Pierre Kraemer's avatar
Pierre Kraemer committed
16

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

20 21
	connect(m_computeNormalAction, SIGNAL(triggered()), this, SLOT(cb_openComputeNormalDialog()));
	connect(m_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
	if(!currentItems.empty())
	{
		const QString& mapname = currentItems[0]->text();
Pierre Kraemer's avatar
Pierre Kraemer committed
50 51
		MapHandler<PFP2>* mh = static_cast<MapHandler<PFP2>*>(m_window->getMap(mapname));
		PFP2::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

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

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

67 68 69
		if(m_computeNormalDialog->check_createVBO->checkState() == Qt::Checked)
			mh->createVBO(normal);

70
		QList<View*> views = mh->getLinkedViews();
71
		foreach(View* view, views)
72
			view->updateGL();
73 74 75 76 77 78 79 80 81
	}
}

void DifferentialPropertiesPlugin::cb_computeCurvature()
{
	QList<QListWidgetItem*> currentItems = m_computeCurvatureDialog->mapList->selectedItems();
	if(!currentItems.empty())
	{
		const QString& mapname = currentItems[0]->text();
Pierre Kraemer's avatar
Pierre Kraemer committed
82 83
		MapHandler<PFP2>* mh = static_cast<MapHandler<PFP2>*>(m_window->getMap(mapname));
		PFP2::MAP* map = mh->getMap();
84 85 86 87

		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
88 89
		VertexAttribute<PFP2::VEC3> position = map->getAttribute<PFP2::VEC3, VERTEX>(positionName);
		VertexAttribute<PFP2::VEC3> normal = map->getAttribute<PFP2::VEC3, VERTEX>(normalName);
90 91 92 93 94 95

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

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

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

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

127 128 129 130 131
		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
132
		VertexAttribute<PFP2::VEC3> Knormal = map->getAttribute<PFP2::VEC3, VERTEX>(KnormalName);
133
		if(!Knormal.isValid())
Pierre Kraemer's avatar
Pierre Kraemer committed
134
			Knormal = map->addAttribute<PFP2::VEC3, VERTEX>(KnormalName);
135

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

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

		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
157

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

164 165 166 167 168
#ifndef DEBUG
Q_EXPORT_PLUGIN2(DifferentialPropertiesPlugin, DifferentialPropertiesPlugin)
#else
Q_EXPORT_PLUGIN2(DifferentialPropertiesPluginD, DifferentialPropertiesPlugin)
#endif