curvature.hpp 27.9 KB
Newer Older
Pierre Kraemer's avatar
Pierre Kraemer committed
1 2 3
/*******************************************************************************
 * CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps  *
 * version 0.1                                                                  *
4
 * Copyright (C) 2009-2012, IGG Team, LSIIT, University of Strasbourg           *
Pierre Kraemer's avatar
Pierre Kraemer committed
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
 *                                                                              *
 * This library is free software; you can redistribute it and/or modify it      *
 * under the terms of the GNU Lesser General Public License as published by the *
 * Free Software Foundation; either version 2.1 of the License, or (at your     *
 * option) any later version.                                                   *
 *                                                                              *
 * This library is distributed in the hope that it will be useful, but WITHOUT  *
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or        *
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License  *
 * for more details.                                                            *
 *                                                                              *
 * You should have received a copy of the GNU Lesser General Public License     *
 * along with this library; if not, write to the Free Software Foundation,      *
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA.           *
 *                                                                              *
20
 * Web site: http://cgogn.unistra.fr/                                           *
Pierre Kraemer's avatar
Pierre Kraemer committed
21 22 23 24 25 26
 * Contact information: cgogn@unistra.fr                                        *
 *                                                                              *
 *******************************************************************************/

#include "Algo/Geometry/localFrame.h"
#include "Geometry/matrix.h"
27 28
#include "Topology/generic/traversor/traversorCell.h"
#include "Topology/generic/traversor/traversor2.h"
Sylvain Thery's avatar
Sylvain Thery committed
29

Pierre Kraemer's avatar
Pierre Kraemer committed
30 31 32 33 34 35
namespace CGoGN
{

namespace Algo
{

36 37 38
namespace Surface
{

Pierre Kraemer's avatar
Pierre Kraemer committed
39 40 41 42
namespace Geometry
{

template <typename PFP>
Pierre Kraemer's avatar
Pierre Kraemer committed
43 44
void computeCurvatureVertices_QuadraticFitting(
	typename PFP::MAP& map,
Pierre Kraemer's avatar
Pierre Kraemer committed
45 46 47 48 49 50
	const VertexAttribute<typename PFP::VEC3, typename PFP::MAP::IMPL>& position,
	const VertexAttribute<typename PFP::VEC3, typename PFP::MAP::IMPL>& normal,
	VertexAttribute<typename PFP::REAL, typename PFP::MAP::IMPL>& kmax,
	VertexAttribute<typename PFP::REAL, typename PFP::MAP::IMPL>& kmin,
	VertexAttribute<typename PFP::VEC3, typename PFP::MAP::IMPL>& Kmax,
	VertexAttribute<typename PFP::VEC3, typename PFP::MAP::IMPL>& Kmin)
Pierre Kraemer's avatar
Pierre Kraemer committed
51
{
52
	TraversorV<typename PFP::MAP> t(map) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
53 54
	for(Vertex v = t.begin(); v != t.end(); v = t.next())
		computeCurvatureVertex_QuadraticFitting<PFP>(map, v, position, normal, kmax, kmin, Kmax, Kmin) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
55 56 57
}

template <typename PFP>
Pierre Kraemer's avatar
Pierre Kraemer committed
58 59
void computeCurvatureVertex_QuadraticFitting(
	typename PFP::MAP& map,
Pierre Kraemer's avatar
Pierre Kraemer committed
60
	Vertex v,
Pierre Kraemer's avatar
Pierre Kraemer committed
61 62 63 64 65 66
	const VertexAttribute<typename PFP::VEC3, typename PFP::MAP::IMPL>& position,
	const VertexAttribute<typename PFP::VEC3, typename PFP::MAP::IMPL>& normal,
	VertexAttribute<typename PFP::REAL, typename PFP::MAP::IMPL>& kmax,
	VertexAttribute<typename PFP::REAL, typename PFP::MAP::IMPL>& kmin,
	VertexAttribute<typename PFP::VEC3, typename PFP::MAP::IMPL>& Kmax,
	VertexAttribute<typename PFP::VEC3, typename PFP::MAP::IMPL>& Kmin)
Pierre Kraemer's avatar
Pierre Kraemer committed
67 68 69 70 71
{
	typedef typename PFP::REAL REAL ;
	typedef typename PFP::VEC3 VEC3 ;
	typedef typename PFP::MATRIX33 MATRIX33 ;

Pierre Kraemer's avatar
Pierre Kraemer committed
72
	VEC3 n = normal[v] ;
Pierre Kraemer's avatar
Pierre Kraemer committed
73

Pierre Kraemer's avatar
Pierre Kraemer committed
74
	MATRIX33 localFrame = Algo::Geometry::vertexLocalFrame<PFP>(map, v, position, n) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
75 76 77 78 79
	MATRIX33 invLocalFrame ;
	localFrame.invert(invLocalFrame) ;

	REAL a, b, c, d, e;
	//vertexCubicFitting(map,dart,localFrame,a,b,c,d,e,f,g,h,i) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
80
	vertexQuadraticFitting<PFP>(map, v, localFrame, position, normal, a, b, c, d, e) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
81

Pierre Kraemer's avatar
Pierre Kraemer committed
82
//	REAL kmax_v, kmin_v, Kmax_x, Kmax_y ;
Pierre Kraemer's avatar
Pierre Kraemer committed
83
//	/*int res = */slaev2_(&a, &b, &c, &kmax_v, &kmin_v, &Kmax_x, &Kmax_y) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
84

Pierre Kraemer's avatar
Pierre Kraemer committed
85
	Eigen::Matrix<REAL,2,2> m;
86
	m << 2*a, b, b, 2*c;
Pierre Kraemer's avatar
Pierre Kraemer committed
87 88 89 90 91

	// solve eigen problem
	Eigen::SelfAdjointEigenSolver<Eigen::Matrix<REAL,2,2> > solver(m);

	const Eigen::Matrix<REAL,2,1>& ev = solver.eigenvalues();
Pierre Kraemer's avatar
Pierre Kraemer committed
92 93
	REAL kmax_v = ev[0];
	REAL kmin_v = ev[1];
Pierre Kraemer's avatar
Pierre Kraemer committed
94 95 96

	const Eigen::Matrix<REAL,2,2>& evec = solver.eigenvectors();
	VEC3 Kmax_v(evec(0,0), evec(1,0), 0.0f) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
97
	Kmax_v = invLocalFrame * Kmax_v ;
Pierre Kraemer's avatar
Pierre Kraemer committed
98 99 100
	VEC3 Kmin_v(evec(0,1), evec(1,1), 0.0f) ;
	Kmin_v = invLocalFrame * Kmin_v ;
//	VEC3 Kmin_v = n ^ Kmax_v ;
Pierre Kraemer's avatar
Pierre Kraemer committed
101

Pierre Kraemer's avatar
Pierre Kraemer committed
102
	if (kmax_v < kmin_v)
103
	{
Pierre Kraemer's avatar
Pierre Kraemer committed
104 105 106 107
		kmax[v] = -kmax_v ;
		kmin[v] = -kmin_v ;
		Kmax[v] = Kmax_v ;
		Kmin[v] = Kmin_v ;
108 109 110
	}
	else
	{
Pierre Kraemer's avatar
Pierre Kraemer committed
111 112 113 114
		kmax[v] = -kmin_v ;
		kmin[v] = -kmax_v ;
		Kmax[v] = Kmin_v ;
		Kmin[v] = Kmax_v ;
115
	}
Pierre Kraemer's avatar
Pierre Kraemer committed
116 117 118
}

template <typename PFP>
Pierre Kraemer's avatar
Pierre Kraemer committed
119
void vertexQuadraticFitting(
Pierre Kraemer's avatar
Pierre Kraemer committed
120
	typename PFP::MAP& map,
Pierre Kraemer's avatar
Pierre Kraemer committed
121
	Vertex v,
Pierre Kraemer's avatar
Pierre Kraemer committed
122
	typename PFP::MATRIX33& localFrame,
Pierre Kraemer's avatar
Pierre Kraemer committed
123 124
	const VertexAttribute<typename PFP::VEC3, typename PFP::MAP::IMPL>& position,
	const VertexAttribute<typename PFP::VEC3, typename PFP::MAP::IMPL>& normal,
Pierre Kraemer's avatar
Pierre Kraemer committed
125
	float& a, float& b, float& c, float& d, float& e)
Pierre Kraemer's avatar
Pierre Kraemer committed
126
{
Pierre Kraemer's avatar
Pierre Kraemer committed
127
	typename PFP::VEC3 p = position[v] ;
Pierre Kraemer's avatar
Pierre Kraemer committed
128

129 130 131 132 133 134
	NLContext nlContext = nlNewContext() ;
	nlMakeCurrent(nlContext) ;
	nlSolverParameteri(NL_NB_VARIABLES, 5) ;
	nlSolverParameteri(NL_LEAST_SQUARES, NL_TRUE) ;
	nlBegin(NL_SYSTEM) ;
	nlBegin(NL_MATRIX) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
135 136 137 138 139 140
	foreach_adjacent2<EDGE>(map, v, [&] (Vertex it) {
		typename PFP::VEC3 itp = position[it] ;
		quadraticFittingAddVertexPos<PFP>(v, itp, localFrame) ;
		typename PFP::VEC3 itn = normal[it] ;
		quadraticFittingAddVertexNormal<PFP>(itp, itn, p, localFrame) ;
	});
141 142 143 144 145 146 147 148 149 150 151
	nlEnd(NL_MATRIX) ;
	nlEnd(NL_SYSTEM) ;
	nlSolve() ;

	a = nlGetVariable(0) ;
	b = nlGetVariable(1) ;
	c = nlGetVariable(2) ;
	d = nlGetVariable(3) ;
	e = nlGetVariable(4) ;

	nlDeleteContext(nlContext) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
152 153 154
}

template <typename PFP>
155
void quadraticFittingAddVertexPos(typename PFP::VEC3& v, typename PFP::VEC3& p, typename PFP::MATRIX33& localFrame)
Pierre Kraemer's avatar
Pierre Kraemer committed
156 157 158 159
{
	typename PFP::VEC3 vec = v - p ;
	vec = localFrame * vec ;

160 161 162 163 164 165 166 167
	nlRowParameterd(NL_RIGHT_HAND_SIDE, vec[2]) ;
	nlBegin(NL_ROW) ;
	nlCoefficient(0, vec[0]*vec[0]) ;
	nlCoefficient(1, vec[0]*vec[1]) ;
	nlCoefficient(2, vec[1]*vec[1]) ;
	nlCoefficient(3, vec[0]) ;
	nlCoefficient(4, vec[1]) ;
	nlEnd(NL_ROW) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
168 169 170
}

template <typename PFP>
171
void quadraticFittingAddVertexNormal(typename PFP::VEC3& v, typename PFP::VEC3& n, typename PFP::VEC3& p, typename PFP::MATRIX33& localFrame)
Pierre Kraemer's avatar
Pierre Kraemer committed
172 173 174 175 176
{
	typename PFP::VEC3 vec = v - p ;
	vec = localFrame * vec ;
	typename PFP::VEC3 norm = localFrame * n ;

177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193
	nlRowParameterd(NL_RIGHT_HAND_SIDE, -1.0f * norm[0]) ;
	nlBegin(NL_ROW);
	nlCoefficient(0, 2.0f * vec[0] * norm[2]) ;
	nlCoefficient(1, vec[1] * norm[2]) ;
	nlCoefficient(2, 0) ;
	nlCoefficient(3, 1.0f * norm[2]) ;
	nlCoefficient(4, 0) ;
	nlEnd(NL_ROW) ;

	nlRowParameterd(NL_RIGHT_HAND_SIDE, -1.0f * norm[1]) ;
	nlBegin(NL_ROW);
	nlCoefficient(0, 0) ;
	nlCoefficient(1, vec[0] * norm[2]) ;
	nlCoefficient(2, 2.0f * vec[1] * norm[2]) ;
	nlCoefficient(3, 0) ;
	nlCoefficient(4, 1.0f * norm[2]) ;
	nlEnd(NL_ROW) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
194 195 196
}
/*
template <typename PFP>
Pierre Kraemer's avatar
Pierre Kraemer committed
197
void vertexCubicFitting(Dart dart, gmtl::Vec3f& normal, float& a, float& b, float& c, float& d, float& e, float& f, float& g, float& h, float& i)
Pierre Kraemer's avatar
Pierre Kraemer committed
198 199
{
	gmtl::Matrix33f localFrame, invLocalFrame ;
200
	Geometry::vertexLocalFrame<PFP>(m_map,dart,normal,localFrame) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
201 202 203 204 205
	gmtl::invertFull(invLocalFrame, localFrame) ;
	gmtl::Vec3f p = m_map.getVertexEmb(dart)->getPosition() ;
	solverC->reset(false) ;
	solverC->set_least_squares(true) ;
	solverC->begin_system() ;
206 207
	Traversor2VVaE<typename PFP::MAP> tav(map, dart) ;
	for(Dart it = tav.begin(); it != tav.end(); it = tav.next())
Pierre Kraemer's avatar
Pierre Kraemer committed
208 209
	{
		// 1-ring vertices
210
		gmtl::Vec3f v = m_map.getVertexEmb(it)->getPosition() ;
Pierre Kraemer's avatar
Pierre Kraemer committed
211
		cubicFittingAddVertexPos(v,p,localFrame) ;
212
		gmtl::Vec3f n = m_normalsV[m_map.getVertexEmb(it)->getLabel()] ;
Pierre Kraemer's avatar
Pierre Kraemer committed
213
		cubicFittingAddVertexNormal(v,n,p,localFrame) ;
214
	}
Pierre Kraemer's avatar
Pierre Kraemer committed
215 216
	solverC->end_system() ;
	solverC->solve() ;
217

Pierre Kraemer's avatar
Pierre Kraemer committed
218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233
	a = solverC->variable(0).value() ;
	b = solverC->variable(1).value() ;
	c = solverC->variable(2).value() ;
	d = solverC->variable(3).value() ;
	e = solverC->variable(4).value() ;
	f = solverC->variable(5).value() ;
	g = solverC->variable(6).value() ;
	h = solverC->variable(7).value() ;
	i = solverC->variable(8).value() ;

//	normal = gmtl::Vec3f(-h, -i, 1.0f) ;
//	gmtl::normalize(normal) ;
//	normal = invLocalFrame * normal ;
}

template <typename PFP>
Pierre Kraemer's avatar
Pierre Kraemer committed
234
void cubicFittingAddVertexPos(gmtl::Vec3f& v, gmtl::Vec3f& p, gmtl::Matrix33f& localFrame)
Pierre Kraemer's avatar
Pierre Kraemer committed
235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254
{
	gmtl::Vec3f vec = v - p ;
	vec = localFrame * vec ;
	solverC->begin_row() ;

	solverC->add_coefficient(0, vec[0]*vec[0]*vec[0]) ;
	solverC->add_coefficient(1, vec[0]*vec[0]*vec[1]) ;
	solverC->add_coefficient(2, vec[0]*vec[1]*vec[1]) ;
	solverC->add_coefficient(3, vec[1]*vec[1]*vec[1]) ;
	solverC->add_coefficient(4, vec[0]*vec[0]) ;
	solverC->add_coefficient(5, vec[0]*vec[1]) ;
	solverC->add_coefficient(6, vec[1]*vec[1]) ;
	solverC->add_coefficient(7, vec[0]) ;
	solverC->add_coefficient(8, vec[1]) ;

	solverC->set_right_hand_side(vec[2]) ;
	solverC->end_row() ;
}

template <typename PFP>
Pierre Kraemer's avatar
Pierre Kraemer committed
255
void cubicFittingAddVertexNormal(gmtl::Vec3f& v, gmtl::Vec3f& n, gmtl::Vec3f& p, gmtl::Matrix33f& localFrame)
Pierre Kraemer's avatar
Pierre Kraemer committed
256 257 258 259 260
{
	gmtl::Vec3f vec = v - p ;
	vec = localFrame * vec ;
	gmtl::Vec3f norm = localFrame * n ;

261
	solverC->begin_row() ;
Pierre Kraemer's avatar
Pierre Kraemer committed
262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287
	solverC->add_coefficient(0, 3.0f*vec[0]*vec[0]) ;
	solverC->add_coefficient(1, 2.0f*vec[0]*vec[1]) ;
	solverC->add_coefficient(2, vec[1]*vec[1]) ;
	solverC->add_coefficient(3, 0) ;
	solverC->add_coefficient(4, 2.0f*vec[0]) ;
	solverC->add_coefficient(5, vec[1]) ;
	solverC->add_coefficient(6, 0) ;
	solverC->add_coefficient(7, 1.0f) ;
	solverC->add_coefficient(8, 0) ;
	solverC->set_right_hand_side(-1.0f*norm[0]/norm[2]) ;
	solverC->end_row() ;

	solverC->begin_row() ;
	solverC->add_coefficient(0, 0) ;
	solverC->add_coefficient(1, vec[0]*vec[0]) ;
	solverC->add_coefficient(2, 2.0f*vec[0]*vec[1]) ;
	solverC->add_coefficient(3, 3.0f*vec[1]*vec[1]) ;
	solverC->add_coefficient(4, 0) ;
	solverC->add_coefficient(5, vec[0]) ;
	solverC->add_coefficient(6, 2.0f*vec[1]) ;
	solverC->add_coefficient(7, 0) ;
	solverC->add_coefficient(8, 1.0f) ;
	solverC->set_right_hand_side(-1.0f*norm[1]/norm[2]) ;
	solverC->end_row() ;
}
*/
Pierre Kraemer's avatar
Pierre Kraemer committed
288 289 290 291 292

template <typename PFP>
void computeCurvatureVertices_NormalCycles(
	typename PFP::MAP& map,
	typename PFP::REAL radius,
Pierre Kraemer's avatar
Pierre Kraemer committed
293 294 295 296 297 298 299 300
	const VertexAttribute<typename PFP::VEC3, typename PFP::MAP::IMPL>& position,
	const VertexAttribute<typename PFP::VEC3, typename PFP::MAP::IMPL>& normal,
	const EdgeAttribute<typename PFP::REAL, typename PFP::MAP::IMPL>& edgeangle,
	VertexAttribute<typename PFP::REAL, typename PFP::MAP::IMPL>& kmax,
	VertexAttribute<typename PFP::REAL, typename PFP::MAP::IMPL>& kmin,
	VertexAttribute<typename PFP::VEC3, typename PFP::MAP::IMPL>& Kmax,
	VertexAttribute<typename PFP::VEC3, typename PFP::MAP::IMPL>& Kmin,
	VertexAttribute<typename PFP::VEC3, typename PFP::MAP::IMPL>& Knormal,
301
	unsigned int thread)
Pierre Kraemer's avatar
Pierre Kraemer committed
302
{
303
	TraversorV<typename PFP::MAP> t(map) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
304 305
	for(Vertex v = t.begin(); v != t.end(); v = t.next())
		computeCurvatureVertex_NormalCycles<PFP>(map, v, radius, position, normal, edgeangle, kmax, kmin, Kmax, Kmin, Knormal,thread) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
306 307 308 309 310
}

template <typename PFP>
void computeCurvatureVertex_NormalCycles(
	typename PFP::MAP& map,
Pierre Kraemer's avatar
Pierre Kraemer committed
311
	Vertex v,
Pierre Kraemer's avatar
Pierre Kraemer committed
312
	typename PFP::REAL radius,
Pierre Kraemer's avatar
Pierre Kraemer committed
313 314 315 316 317 318 319 320
	const VertexAttribute<typename PFP::VEC3, typename PFP::MAP::IMPL>& position,
	const VertexAttribute<typename PFP::VEC3, typename PFP::MAP::IMPL>& normal,
	const EdgeAttribute<typename PFP::REAL, typename PFP::MAP::IMPL>& edgeangle,
	VertexAttribute<typename PFP::REAL, typename PFP::MAP::IMPL>& kmax,
	VertexAttribute<typename PFP::REAL, typename PFP::MAP::IMPL>& kmin,
	VertexAttribute<typename PFP::VEC3, typename PFP::MAP::IMPL>& Kmax,
	VertexAttribute<typename PFP::VEC3, typename PFP::MAP::IMPL>& Kmin,
	VertexAttribute<typename PFP::VEC3, typename PFP::MAP::IMPL>& Knormal,
321
	unsigned int thread)
Pierre Kraemer's avatar
Pierre Kraemer committed
322
{
323 324
	typedef typename PFP::REAL REAL ;
	typedef typename PFP::VEC3 VEC3 ;
325 326
	typedef Geom::Matrix<3,3,REAL> MATRIX;
	typedef Eigen::Matrix<REAL,3,1> E_VEC3;
Sauvage's avatar
Sauvage committed
327
	typedef Eigen::Matrix<REAL,3,3,Eigen::RowMajor> E_MATRIX;
328

329
	// collect the normal cycle tensor
330
	Selection::Collector_WithinSphere<PFP> neigh(map, position, radius, thread) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
331
	neigh.collectAll(v) ;
332

333
	MATRIX tensor(0) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
334
	neigh.computeNormalCyclesTensor(position, edgeangle, tensor);
335

336
	// solve eigen problem
Pierre Kraemer's avatar
Pierre Kraemer committed
337
	Eigen::SelfAdjointEigenSolver<E_MATRIX> solver(Utils::convertRef<E_MATRIX>(tensor));
338 339
	const VEC3& ev = Utils::convertRef<VEC3>(solver.eigenvalues());
	const MATRIX& evec = Utils::convertRef<MATRIX>(solver.eigenvectors());
340

Pierre Kraemer's avatar
Pierre Kraemer committed
341
	normalCycles_SortAndSetEigenComponents<PFP>(ev,evec,kmax[v],kmin[v],Kmax[v],Kmin[v],Knormal[v],normal[v],thread);
Sauvage's avatar
Sauvage committed
342 343 344 345 346 347 348 349 350 351

//	if (dart.index % 15000 == 0)
//	{
//		CGoGNout << solver.eigenvalues() << CGoGNendl;
//		CGoGNout << solver.eigenvectors() << CGoGNendl;
//		normalCycles_SortTensor<PFP>(tensor);
//		solver.compute(Utils::convertRef<E_MATRIX>(tensor));
//		CGoGNout << solver.eigenvalues() << CGoGNendl;
//		CGoGNout << solver.eigenvectors() << CGoGNendl;
//	}
352 353
}

Sauvage's avatar
Sauvage committed
354 355 356 357
template <typename PFP>
void computeCurvatureVertices_NormalCycles_Projected(
	typename PFP::MAP& map,
	typename PFP::REAL radius,
Pierre Kraemer's avatar
Pierre Kraemer committed
358 359 360 361 362 363 364 365
	const VertexAttribute<typename PFP::VEC3, typename PFP::MAP::IMPL>& position,
	const VertexAttribute<typename PFP::VEC3, typename PFP::MAP::IMPL>& normal,
	const EdgeAttribute<typename PFP::REAL, typename PFP::MAP::IMPL>& edgeangle,
	VertexAttribute<typename PFP::REAL, typename PFP::MAP::IMPL>& kmax,
	VertexAttribute<typename PFP::REAL, typename PFP::MAP::IMPL>& kmin,
	VertexAttribute<typename PFP::VEC3, typename PFP::MAP::IMPL>& Kmax,
	VertexAttribute<typename PFP::VEC3, typename PFP::MAP::IMPL>& Kmin,
	VertexAttribute<typename PFP::VEC3, typename PFP::MAP::IMPL>& Knormal,
366
	unsigned int thread)
Sauvage's avatar
Sauvage committed
367
{
368
	TraversorV<typename PFP::MAP> t(map) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
369 370
	for(Vertex v = t.begin(); v.dart != t.end(); v = t.next())
		computeCurvatureVertex_NormalCycles_Projected<PFP>(map, v, radius, position, normal, edgeangle, kmax, kmin, Kmax, Kmin, Knormal, thread) ;
Sauvage's avatar
Sauvage committed
371 372 373 374 375
}

template <typename PFP>
void computeCurvatureVertex_NormalCycles_Projected(
	typename PFP::MAP& map,
Pierre Kraemer's avatar
Pierre Kraemer committed
376
	Vertex v,
Sauvage's avatar
Sauvage committed
377
	typename PFP::REAL radius,
Pierre Kraemer's avatar
Pierre Kraemer committed
378 379 380 381 382 383 384 385
	const VertexAttribute<typename PFP::VEC3, typename PFP::MAP::IMPL>& position,
	const VertexAttribute<typename PFP::VEC3, typename PFP::MAP::IMPL>& normal,
	const EdgeAttribute<typename PFP::REAL, typename PFP::MAP::IMPL>& edgeangle,
	VertexAttribute<typename PFP::REAL, typename PFP::MAP::IMPL>& kmax,
	VertexAttribute<typename PFP::REAL, typename PFP::MAP::IMPL>& kmin,
	VertexAttribute<typename PFP::VEC3, typename PFP::MAP::IMPL>& Kmax,
	VertexAttribute<typename PFP::VEC3, typename PFP::MAP::IMPL>& Kmin,
	VertexAttribute<typename PFP::VEC3, typename PFP::MAP::IMPL>& Knormal,
386
	unsigned int thread)
Sauvage's avatar
Sauvage committed
387
{
388
	typedef typename PFP::REAL REAL ;
Sauvage's avatar
Sauvage committed
389 390 391 392
	typedef typename PFP::VEC3 VEC3 ;
	typedef Geom::Matrix<3,3,REAL> MATRIX;
	typedef Eigen::Matrix<REAL,3,1> E_VEC3;
	typedef Eigen::Matrix<REAL,3,3,Eigen::RowMajor> E_MATRIX;
393

394
	// collect the normal cycle tensor
395
	Selection::Collector_WithinSphere<PFP> neigh(map, position, radius, thread) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
396
	neigh.collectAll(v) ;
397

Sauvage's avatar
Sauvage committed
398
	MATRIX tensor(0) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
399
	neigh.computeNormalCyclesTensor(position, edgeangle, tensor);
400

Sauvage's avatar
Sauvage committed
401
	// project the tensor
Pierre Kraemer's avatar
Pierre Kraemer committed
402
	normalCycles_ProjectTensor<PFP>(tensor, normal[v], thread);
403

Sauvage's avatar
Sauvage committed
404
	// solve eigen problem
Pierre Kraemer's avatar
Pierre Kraemer committed
405
	Eigen::SelfAdjointEigenSolver<E_MATRIX> solver(Utils::convertRef<E_MATRIX>(tensor));
Sauvage's avatar
Sauvage committed
406 407 408
	const VEC3& ev = Utils::convertRef<VEC3>(solver.eigenvalues());
	const MATRIX& evec = Utils::convertRef<MATRIX>(solver.eigenvectors());

Pierre Kraemer's avatar
Pierre Kraemer committed
409
	normalCycles_SortAndSetEigenComponents<PFP>(ev,evec,kmax[v],kmin[v],Kmax[v],Kmin[v],Knormal[v],normal[v],thread);
Sauvage's avatar
Sauvage committed
410 411
}

412 413 414
template <typename PFP>
void computeCurvatureVertices_NormalCycles(
	typename PFP::MAP& map,
Pierre Kraemer's avatar
Pierre Kraemer committed
415
	Algo::Surface::Selection::Collector<PFP>& neigh,
Pierre Kraemer's avatar
Pierre Kraemer committed
416 417 418 419 420 421 422 423
	const VertexAttribute<typename PFP::VEC3, typename PFP::MAP::IMPL>& position,
	const VertexAttribute<typename PFP::VEC3, typename PFP::MAP::IMPL>& normal,
	const EdgeAttribute<typename PFP::REAL, typename PFP::MAP::IMPL>& edgeangle,
	VertexAttribute<typename PFP::REAL, typename PFP::MAP::IMPL>& kmax,
	VertexAttribute<typename PFP::REAL, typename PFP::MAP::IMPL>& kmin,
	VertexAttribute<typename PFP::VEC3, typename PFP::MAP::IMPL>& Kmax,
	VertexAttribute<typename PFP::VEC3, typename PFP::MAP::IMPL>& Kmin,
	VertexAttribute<typename PFP::VEC3, typename PFP::MAP::IMPL>& Knormal,
424
	unsigned int thread)
425
{
426
	TraversorV<typename PFP::MAP> t(map) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
427 428
	for(Vertex v = t.begin(); v != t.end(); v = t.next())
		computeCurvatureVertex_NormalCycles<PFP>(map, v, neigh, position, normal, edgeangle, kmax, kmin, Kmax, Kmin, Knormal,thread) ;
429 430 431 432
}

template <typename PFP>
void computeCurvatureVertex_NormalCycles(
Pierre Kraemer's avatar
Pierre Kraemer committed
433 434
	Vertex v,
	Algo::Surface::Selection::Collector<PFP>& neigh,
Pierre Kraemer's avatar
Pierre Kraemer committed
435 436 437 438 439 440 441 442
	const VertexAttribute<typename PFP::VEC3, typename PFP::MAP::IMPL>& position,
	const VertexAttribute<typename PFP::VEC3, typename PFP::MAP::IMPL>& normal,
	const EdgeAttribute<typename PFP::REAL, typename PFP::MAP::IMPL>& edgeangle,
	VertexAttribute<typename PFP::REAL, typename PFP::MAP::IMPL>& kmax,
	VertexAttribute<typename PFP::REAL, typename PFP::MAP::IMPL>& kmin,
	VertexAttribute<typename PFP::VEC3, typename PFP::MAP::IMPL>& Kmax,
	VertexAttribute<typename PFP::VEC3, typename PFP::MAP::IMPL>& Kmin,
	VertexAttribute<typename PFP::VEC3, typename PFP::MAP::IMPL>& Knormal,
443
	unsigned int thread)
444 445 446 447 448
{
	typedef typename PFP::REAL REAL ;
	typedef typename PFP::VEC3 VEC3 ;
	typedef Geom::Matrix<3,3,REAL> MATRIX;
	typedef Eigen::Matrix<REAL,3,1> E_VEC3;
Sauvage's avatar
Sauvage committed
449
	typedef Eigen::Matrix<REAL,3,3,Eigen::RowMajor> E_MATRIX;
450 451

	// collect the normal cycle tensor
Pierre Kraemer's avatar
Pierre Kraemer committed
452
	neigh.collectAll(v) ;
453

454
	MATRIX tensor(0) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
455
	neigh.computeNormalCyclesTensor(position, edgeangle, tensor);
456

457
	// solve eigen problem
Pierre Kraemer's avatar
Pierre Kraemer committed
458
	Eigen::SelfAdjointEigenSolver<E_MATRIX> solver(Utils::convertRef<E_MATRIX>(tensor));
459 460 461
	const VEC3& ev = Utils::convertRef<VEC3>(solver.eigenvalues());
	const MATRIX& evec = Utils::convertRef<MATRIX>(solver.eigenvectors());

Pierre Kraemer's avatar
Pierre Kraemer committed
462
	normalCycles_SortAndSetEigenComponents<PFP>(ev,evec,kmax[v],kmin[v],Kmax[v],Kmin[v],Knormal[v],normal[v],thread);
463 464
}

Sauvage's avatar
Sauvage committed
465 466 467
template <typename PFP>
void computeCurvatureVertices_NormalCycles_Projected(
	typename PFP::MAP& map,
Pierre Kraemer's avatar
Pierre Kraemer committed
468
	Algo::Surface::Selection::Collector<PFP>& neigh,
Pierre Kraemer's avatar
Pierre Kraemer committed
469 470 471 472 473 474 475 476
	const VertexAttribute<typename PFP::VEC3, typename PFP::MAP::IMPL>& position,
	const VertexAttribute<typename PFP::VEC3, typename PFP::MAP::IMPL>& normal,
	const EdgeAttribute<typename PFP::REAL, typename PFP::MAP::IMPL>& edgeangle,
	VertexAttribute<typename PFP::REAL, typename PFP::MAP::IMPL>& kmax,
	VertexAttribute<typename PFP::REAL, typename PFP::MAP::IMPL>& kmin,
	VertexAttribute<typename PFP::VEC3, typename PFP::MAP::IMPL>& Kmax,
	VertexAttribute<typename PFP::VEC3, typename PFP::MAP::IMPL>& Kmin,
	VertexAttribute<typename PFP::VEC3, typename PFP::MAP::IMPL>& Knormal,
477
	unsigned int thread)
Sauvage's avatar
Sauvage committed
478
{
479
	TraversorV<typename PFP::MAP> t(map) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
480 481
	for(Vertex v = t.begin(); v != t.end(); v = t.next())
		computeCurvatureVertex_NormalCycles_Projected<PFP>(map, v, neigh, position, normal, edgeangle, kmax, kmin, Kmax, Kmin, Knormal,thread) ;
Sauvage's avatar
Sauvage committed
482 483 484 485
}

template <typename PFP>
void computeCurvatureVertex_NormalCycles_Projected(
Pierre Kraemer's avatar
Pierre Kraemer committed
486 487
	Vertex v,
	Algo::Surface::Selection::Collector<PFP>& neigh,
Pierre Kraemer's avatar
Pierre Kraemer committed
488 489 490 491 492 493 494 495
	const VertexAttribute<typename PFP::VEC3, typename PFP::MAP::IMPL>& position,
	const VertexAttribute<typename PFP::VEC3, typename PFP::MAP::IMPL>& normal,
	const EdgeAttribute<typename PFP::REAL, typename PFP::MAP::IMPL>& edgeangle,
	VertexAttribute<typename PFP::REAL, typename PFP::MAP::IMPL>& kmax,
	VertexAttribute<typename PFP::REAL, typename PFP::MAP::IMPL>& kmin,
	VertexAttribute<typename PFP::VEC3, typename PFP::MAP::IMPL>& Kmax,
	VertexAttribute<typename PFP::VEC3, typename PFP::MAP::IMPL>& Kmin,
	VertexAttribute<typename PFP::VEC3, typename PFP::MAP::IMPL>& Knormal,
496
	unsigned int thread)
Sauvage's avatar
Sauvage committed
497 498 499 500 501 502 503 504
{
	typedef typename PFP::REAL REAL ;
	typedef typename PFP::VEC3 VEC3 ;
	typedef Geom::Matrix<3,3,REAL> MATRIX;
	typedef Eigen::Matrix<REAL,3,1> E_VEC3;
	typedef Eigen::Matrix<REAL,3,3,Eigen::RowMajor> E_MATRIX;

	// collect the normal cycle tensor
Pierre Kraemer's avatar
Pierre Kraemer committed
505
	neigh.collectAll(v) ;
Sauvage's avatar
Sauvage committed
506 507

	MATRIX tensor(0) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
508
	neigh.computeNormalCyclesTensor(position, edgeangle, tensor);
Sauvage's avatar
Sauvage committed
509 510

	// project the tensor
Pierre Kraemer's avatar
Pierre Kraemer committed
511
	normalCycles_ProjectTensor<PFP>(tensor, normal[v], thread);
Sauvage's avatar
Sauvage committed
512 513

	// solve eigen problem
Pierre Kraemer's avatar
Pierre Kraemer committed
514
	Eigen::SelfAdjointEigenSolver<E_MATRIX> solver(Utils::convertRef<E_MATRIX>(tensor));
Sauvage's avatar
Sauvage committed
515 516 517
	const VEC3& ev = Utils::convertRef<VEC3>(solver.eigenvalues());
	const MATRIX& evec = Utils::convertRef<MATRIX>(solver.eigenvectors());

Pierre Kraemer's avatar
Pierre Kraemer committed
518
	normalCycles_SortAndSetEigenComponents<PFP>(ev,evec,kmax[v],kmin[v],Kmax[v],Kmin[v],Knormal[v],normal[v],thread);
Sauvage's avatar
Sauvage committed
519
}
520

521 522 523 524 525 526 527 528 529 530
template <typename PFP>
void normalCycles_SortAndSetEigenComponents(
	const typename PFP::VEC3& e_val,
	const Geom::Matrix<3,3,typename PFP::REAL> & e_vec,
	typename PFP::REAL& kmax,
	typename PFP::REAL& kmin,
	typename PFP::VEC3& Kmax,
	typename PFP::VEC3& Kmin,
	typename PFP::VEC3& Knormal,
	const typename PFP::VEC3& normal,
Sylvain Thery's avatar
Sylvain Thery committed
531
	unsigned int /*thread*/)
532
{
Sauvage's avatar
Sauvage committed
533
	// sort eigen components : ev[inormal] has minimal absolute value ; kmin = ev[imin] <= ev[imax] = kmax
Pierre Kraemer's avatar
Pierre Kraemer committed
534
	int inormal = 0, imin, imax ;
Pierre Kraemer's avatar
Pierre Kraemer committed
535 536
	if (fabs(e_val[1]) < fabs(e_val[inormal])) inormal = 1;
	if (fabs(e_val[2]) < fabs(e_val[inormal])) inormal = 2;
Sauvage's avatar
Sauvage committed
537 538
	imin = (inormal + 1) % 3;
	imax = (inormal + 2) % 3;
Sauvage's avatar
Sauvage committed
539
	if (e_val[imax] < e_val[imin]) { int tmp = imin ; imin = imax ; imax = tmp ; }
540

541
	// set curvatures from sorted eigen components
542 543
	// warning : Kmin and Kmax are switched w.r.t. kmin and kmax
	// normal direction : minimal absolute eigen value
Sauvage's avatar
Sauvage committed
544 545 546
	Knormal[0] = e_vec(0,inormal);
	Knormal[1] = e_vec(1,inormal);
	Knormal[2] = e_vec(2,inormal);
547
	if (Knormal * normal < 0) Knormal *= -1; // change orientation
548
	// min curvature
Sauvage's avatar
Sauvage committed
549 550 551 552
	kmin = e_val[imin] ;
	Kmin[0] = e_vec(0,imax);
	Kmin[1] = e_vec(1,imax);
	Kmin[2] = e_vec(2,imax);
553
	// max curvature
Sauvage's avatar
Sauvage committed
554 555 556 557
	kmax = e_val[imax] ;
	Kmax[0] = e_vec(0,imin);
	Kmax[1] = e_vec(1,imin);
	Kmax[2] = e_vec(2,imin);
Pierre Kraemer's avatar
Pierre Kraemer committed
558 559
}

Sauvage's avatar
Sauvage committed
560
template <typename PFP>
Pierre Kraemer's avatar
Pierre Kraemer committed
561
void normalCycles_SortTensor(Geom::Matrix<3,3,typename PFP::REAL>& tensor, unsigned int /*thread*/)
Sauvage's avatar
Sauvage committed
562 563 564 565 566 567 568 569
{
	typedef typename PFP::REAL REAL ;
	typedef typename PFP::VEC3 VEC3 ;
	typedef Geom::Matrix<3,3,REAL> MATRIX;
	typedef Eigen::Matrix<REAL,3,1> E_VEC3;
	typedef Eigen::Matrix<REAL,3,3,Eigen::RowMajor> E_MATRIX;

	// compute eigen components
Pierre Kraemer's avatar
Pierre Kraemer committed
570
	Eigen::SelfAdjointEigenSolver<E_MATRIX> solver(Utils::convertRef<E_MATRIX>(tensor));
Sauvage's avatar
Sauvage committed
571 572
	const VEC3& e_val = Utils::convertRef<VEC3>(solver.eigenvalues());
	const MATRIX& e_vec = Utils::convertRef<MATRIX>(solver.eigenvectors());
Sauvage's avatar
Sauvage committed
573

Sauvage's avatar
Sauvage committed
574
	// switch kmin and kmax w.r.t. Kmin and Kmax
Pierre Kraemer's avatar
Pierre Kraemer committed
575
	int inormal = 0, imin, imax ;
Pierre Kraemer's avatar
Pierre Kraemer committed
576 577
	if (fabs(e_val[1]) < fabs(e_val[inormal])) inormal = 1;
	if (fabs(e_val[2]) < fabs(e_val[inormal])) inormal = 2;
Sauvage's avatar
Sauvage committed
578 579 580 581 582 583 584 585 586 587 588 589 590
	imin = (inormal + 1) % 3;
	imax = (inormal + 2) % 3;
	if (e_val[imax] < e_val[imin]) { int tmp = imin ; imin = imax ; imax = tmp ; }

	tensor = e_vec;
	int i; REAL v;
	i = inormal; v = e_val[inormal];
	tensor(0,i) *= v; tensor(1,i) *= v; tensor(2,i) *= v;
	i = imin; v = e_val[imax];
	tensor(0,i) *= v; tensor(1,i) *= v; tensor(2,i) *= v;
	i = imax; v = e_val[imin];
	tensor(0,i) *= v; tensor(1,i) *= v; tensor(2,i) *= v;
	tensor = tensor*e_vec.transposed();
Sauvage's avatar
Sauvage committed
591 592
}

Sauvage's avatar
Sauvage committed
593
template <typename PFP>
Pierre Kraemer's avatar
Pierre Kraemer committed
594
void normalCycles_ProjectTensor(Geom::Matrix<3,3,typename PFP::REAL>& tensor, const typename PFP::VEC3& normal_vector, unsigned int thread)
Sauvage's avatar
Sauvage committed
595 596 597
{
	Geom::Matrix<3,3,typename PFP::REAL> proj;
	proj.identity();
Pierre Kraemer's avatar
Pierre Kraemer committed
598
	proj -= Geom::transposed_vectors_mult(normal_vector, normal_vector);
Sauvage's avatar
Sauvage committed
599
	tensor = proj * tensor * proj;
Pierre Kraemer's avatar
Pierre Kraemer committed
600 601
}

602 603 604 605 606 607 608

namespace Parallel
{

template <typename PFP>
class FunctorComputeCurvatureVertices_NormalCycles: public FunctorMapThreaded<typename PFP::MAP >
{
Pierre Kraemer's avatar
Pierre Kraemer committed
609 610 611 612 613 614 615 616 617 618 619 620 621 622
	typedef typename PFP::MAP MAP ;
	typedef typename PFP::MAP::IMPL MAP_IMPL ;
	typedef typename PFP::VEC3 VEC3 ;
	typedef typename PFP::REAL REAL ;

	REAL m_radius;
	const VertexAttribute<VEC3, MAP_IMPL>& m_position;
	const VertexAttribute<VEC3, MAP_IMPL>& m_normal;
	const EdgeAttribute<REAL, MAP_IMPL>& m_edgeangle;
	VertexAttribute<REAL, MAP_IMPL>& m_kmax;
	VertexAttribute<REAL, MAP_IMPL>& m_kmin;
	VertexAttribute<VEC3, MAP_IMPL>& m_Kmax;
	VertexAttribute<VEC3, MAP_IMPL>& m_Kmin;
	VertexAttribute<VEC3, MAP_IMPL>& m_Knormal;
623
public:
Pierre Kraemer's avatar
Pierre Kraemer committed
624 625 626 627 628 629 630 631 632 633 634 635
	 FunctorComputeCurvatureVertices_NormalCycles(
		MAP& map,
		REAL radius,
		const VertexAttribute<VEC3, MAP_IMPL>& position,
		const VertexAttribute<VEC3, MAP_IMPL>& normal,
		const EdgeAttribute<REAL, MAP_IMPL>& edgeangle,
		VertexAttribute<REAL, MAP_IMPL>& kmax,
		VertexAttribute<REAL, MAP_IMPL>& kmin,
		VertexAttribute<VEC3, MAP_IMPL>& Kmax,
		VertexAttribute<VEC3, MAP_IMPL>& Kmin,
		VertexAttribute<VEC3, MAP_IMPL>& Knormal):
	  FunctorMapThreaded<MAP>(map),
636 637 638 639 640 641 642 643
	  m_radius(radius),
	  m_position(position),
	  m_normal(normal),
	  m_edgeangle(edgeangle),
	  m_kmax(kmax),
	  m_kmin(kmin),
	  m_Kmax(Kmax),
	  m_Kmin(Kmin),
Sylvain Thery's avatar
Sylvain Thery committed
644
	  m_Knormal(Knormal)
645 646
	 { }

647
	void run(Dart d, unsigned int threadID)
648
	{
Sylvain Thery's avatar
Sylvain Thery committed
649
		computeCurvatureVertex_NormalCycles<PFP>(this->m_map, d, m_radius, m_position, m_normal, m_edgeangle, m_kmax, m_kmin, m_Kmax, m_Kmin, m_Knormal, threadID) ;
650 651 652 653 654 655 656
	}
};

template <typename PFP>
void computeCurvatureVertices_NormalCycles(
	typename PFP::MAP& map,
	typename PFP::REAL radius,
Pierre Kraemer's avatar
Pierre Kraemer committed
657 658 659 660 661 662 663 664
	const VertexAttribute<typename PFP::VEC3, typename PFP::MAP::IMPL>& position,
	const VertexAttribute<typename PFP::VEC3, typename PFP::MAP::IMPL>& normal,
	const EdgeAttribute<typename PFP::REAL, typename PFP::MAP::IMPL>& edgeangle,
	VertexAttribute<typename PFP::REAL, typename PFP::MAP::IMPL>& kmax,
	VertexAttribute<typename PFP::REAL, typename PFP::MAP::IMPL>& kmin,
	VertexAttribute<typename PFP::VEC3, typename PFP::MAP::IMPL>& Kmax,
	VertexAttribute<typename PFP::VEC3, typename PFP::MAP::IMPL>& Kmin,
	VertexAttribute<typename PFP::VEC3, typename PFP::MAP::IMPL>& Knormal,
665
	unsigned int nbth)
666
{
Sylvain Thery's avatar
Sylvain Thery committed
667
	// WAHOO BIG PROBLEM WITH LAZZY EMBEDDING !!!
Pierre Kraemer's avatar
Pierre Kraemer committed
668
	if (!map.template isOrbitEmbedded<VERTEX>())
Sylvain Thery's avatar
Sylvain Thery committed
669
	{
Pierre Kraemer's avatar
Pierre Kraemer committed
670 671
		CellMarkerNoUnmark<typename PFP::MAP, VERTEX> cm(map);
		map.template initAllOrbitsEmbedding<VERTEX>();
Sylvain Thery's avatar
Sylvain Thery committed
672
	}
Pierre Kraemer's avatar
Pierre Kraemer committed
673
	if (!map.template isOrbitEmbedded<EDGE>())
Sylvain Thery's avatar
Sylvain Thery committed
674
	{
Pierre Kraemer's avatar
Pierre Kraemer committed
675 676
		CellMarkerNoUnmark<typename PFP::MAP, EDGE> cm(map);
		map.template initAllOrbitsEmbedding<EDGE>();
Sylvain Thery's avatar
Sylvain Thery committed
677
	}
Pierre Kraemer's avatar
Pierre Kraemer committed
678
	if (!map.template isOrbitEmbedded<FACE>())
Sylvain Thery's avatar
Sylvain Thery committed
679
	{
Pierre Kraemer's avatar
Pierre Kraemer committed
680 681
		CellMarkerNoUnmark<typename PFP::MAP, FACE> cm(map);
		map.template initAllOrbitsEmbedding<FACE>();
Sylvain Thery's avatar
Sylvain Thery committed
682 683
	}

684
	FunctorComputeCurvatureVertices_NormalCycles<PFP> funct(map, radius, position, normal, edgeangle, kmax, kmin, Kmax, Kmin, Knormal);
685
	Algo::Parallel::foreach_cell<typename PFP::MAP,VERTEX>(map, funct, nbth, true);
686 687
}

Sylvain Thery's avatar
Sylvain Thery committed
688 689 690 691 692


template <typename PFP>
class FunctorComputeCurvatureVertices_QuadraticFitting: public FunctorMapThreaded<typename PFP::MAP >
{
Pierre Kraemer's avatar
Pierre Kraemer committed
693 694 695 696 697 698 699 700 701 702 703
	typedef typename PFP::MAP MAP ;
	typedef typename PFP::MAP::IMPL MAP_IMPL ;
	typedef typename PFP::VEC3 VEC3 ;
	typedef typename PFP::REAL REAL ;

	const VertexAttribute<VEC3, MAP_IMPL>& m_position;
	const VertexAttribute<VEC3, MAP_IMPL>& m_normal;
	VertexAttribute<REAL, MAP_IMPL>& m_kmax;
	VertexAttribute<REAL, MAP_IMPL>& m_kmin;
	VertexAttribute<VEC3, MAP_IMPL>& m_Kmax;
	VertexAttribute<VEC3, MAP_IMPL>& m_Kmin;
Sylvain Thery's avatar
Sylvain Thery committed
704
public:
Pierre Kraemer's avatar
Pierre Kraemer committed
705 706 707 708 709 710 711 712 713
	 FunctorComputeCurvatureVertices_QuadraticFitting(
		MAP& map,
		const VertexAttribute<VEC3, MAP_IMPL>& position,
		const VertexAttribute<VEC3, MAP_IMPL>& normal,
		VertexAttribute<REAL, MAP_IMPL>& kmax,
		VertexAttribute<REAL, MAP_IMPL>& kmin,
		VertexAttribute<VEC3, MAP_IMPL>& Kmax,
		VertexAttribute<VEC3, MAP_IMPL>& Kmin):
	  FunctorMapThreaded<MAP>(map),
Sylvain Thery's avatar
Sylvain Thery committed
714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730
	  m_position(position),
	  m_normal(normal),
	  m_kmax(kmax),
	  m_kmin(kmin),
	  m_Kmax(Kmax),
	  m_Kmin(Kmin)
	 { }

	void run(Dart d, unsigned int threadID)
	{
		computeCurvatureVertex_QuadraticFitting<PFP>(this->m_map, d, m_position, m_normal, m_kmax, m_kmin, m_Kmax, m_Kmin) ;
	}
};

template <typename PFP>
void computeCurvatureVertices_QuadraticFitting(
	typename PFP::MAP& map,
Pierre Kraemer's avatar
Pierre Kraemer committed
731 732 733 734 735 736
	const VertexAttribute<typename PFP::VEC3, typename PFP::MAP::IMPL>& position,
	const VertexAttribute<typename PFP::VEC3, typename PFP::MAP::IMPL>& normal,
	VertexAttribute<typename PFP::REAL, typename PFP::MAP::IMPL>& kmax,
	VertexAttribute<typename PFP::REAL, typename PFP::MAP::IMPL>& kmin,
	VertexAttribute<typename PFP::VEC3, typename PFP::MAP::IMPL>& Kmax,
	VertexAttribute<typename PFP::VEC3, typename PFP::MAP::IMPL>& Kmin,
737
	unsigned int nbth)
Sylvain Thery's avatar
Sylvain Thery committed
738 739
{
	FunctorComputeCurvatureVertices_QuadraticFitting<PFP> funct(map, position, normal, kmax, kmin, Kmax, Kmin);
740
	Algo::Parallel::foreach_cell<typename PFP::MAP,VERTEX>(map, funct, nbth, true);
741 742
}

Sylvain Thery's avatar
Sylvain Thery committed
743
} // namespace Parallel
744 745


Pierre Kraemer's avatar
Pierre Kraemer committed
746 747
} // namespace Geometry

Pierre Kraemer's avatar
Pierre Kraemer committed
748
} // namespace Surface
749

Pierre Kraemer's avatar
Pierre Kraemer committed
750 751 752
} // namespace Algo

} // namespace CGoGN