edgeSelector.h 24.4 KB
Newer Older
Kenneth Vanhoey's avatar
Kenneth Vanhoey 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           *
Kenneth Vanhoey's avatar
Kenneth Vanhoey 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/                                           *
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
21
22
23
24
25
26
27
28
* Contact information: cgogn@unistra.fr                                        *
*                                                                              *
*******************************************************************************/

#ifndef __EDGESELECTOR_H__
#define __EDGESELECTOR_H__

#include "Algo/Decimation/selector.h"
29
#include "Algo/Geometry/boundingbox.h"
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
30

31
32
33
#include "Container/fakeAttribute.h"
#include "Utils/qem.h"
#include "Utils/quadricRGBfunctions.h"
34
35
#include "Algo/Geometry/normal.h"
#include "Algo/Selection/collector.h"
36
#include "Algo/Geometry/curvature.h"
37
#include "Algo/Geometry/area.h"
38

Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
39
40
41
42
43
44
namespace CGoGN
{

namespace Algo
{

45
46
47
namespace Surface
{

Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
namespace Decimation
{

template <typename PFP>
class EdgeSelector_MapOrder : public EdgeSelector<PFP>
{
public:
	typedef typename PFP::MAP MAP ;
	typedef typename PFP::VEC3 VEC3 ;
	typedef typename PFP::REAL REAL ;

private:
	Dart cur ;

public:
63
	EdgeSelector_MapOrder(MAP& m, VertexAttribute<typename PFP::VEC3>& pos, std::vector<ApproximatorGen<PFP>*>& approx, const FunctorSelect& select) :
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
64
65
66
67
68
69
70
71
72
73
		EdgeSelector<PFP>(m, pos, approx, select)
	{}
	~EdgeSelector_MapOrder()
	{}
	SelectorType getType() { return S_MapOrder ; }
	bool init() ;
	bool nextEdge(Dart& d) ;
	void updateBeforeCollapse(Dart d)
	{}
	void updateAfterCollapse(Dart d2, Dart dd2) ;
untereiner's avatar
untereiner committed
74

75
	void updateWithoutCollapse() { }
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
76

Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
} ;

template <typename PFP>
class EdgeSelector_Random : public EdgeSelector<PFP>
{
public:
	typedef typename PFP::MAP MAP ;
	typedef typename PFP::VEC3 VEC3 ;
	typedef typename PFP::REAL REAL ;

private:
	std::vector<Dart> darts ;
	unsigned int cur ;
	bool allSkipped ;

public:
93
	EdgeSelector_Random(MAP& m, VertexAttribute<typename PFP::VEC3>& pos, std::vector<ApproximatorGen<PFP>*>& approx, const FunctorSelect& select) :
94
95
96
		EdgeSelector<PFP>(m, pos, approx, select),
		cur(0),
		allSkipped(false)
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
97
98
99
100
101
102
103
104
105
	{}
	~EdgeSelector_Random()
	{}
	SelectorType getType() { return S_Random ; }
	bool init() ;
	bool nextEdge(Dart& d) ;
	void updateBeforeCollapse(Dart d2)
	{}
	void updateAfterCollapse(Dart d2, Dart dd2) ;
untereiner's avatar
untereiner committed
106

107
	void updateWithoutCollapse();
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
} ;

template <typename PFP>
class EdgeSelector_Length : public EdgeSelector<PFP>
{
public:
	typedef typename PFP::MAP MAP ;
	typedef typename PFP::VEC3 VEC3 ;
	typedef typename PFP::REAL REAL ;

private:
	typedef struct
	{
		typename std::multimap<float,Dart>::iterator it ;
		bool valid ;
		static std::string CGoGNnameOfType() { return "LengthEdgeInfo" ; }
	} LengthEdgeInfo ;
	typedef NoMathIOAttribute<LengthEdgeInfo> EdgeInfo ;

127
	EdgeAttribute<EdgeInfo> edgeInfo ;
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
128
129
130
131
132
133
134
135
136

	std::multimap<float,Dart> edges ;
	typename std::multimap<float,Dart>::iterator cur ;

	void initEdgeInfo(Dart d) ;
	void updateEdgeInfo(Dart d, bool recompute) ;
	void computeEdgeInfo(Dart d, EdgeInfo& einfo) ;

public:
137
	EdgeSelector_Length(MAP& m, VertexAttribute<typename PFP::VEC3>& pos, std::vector<ApproximatorGen<PFP>*>& approx, const FunctorSelect& select) :
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
138
139
		EdgeSelector<PFP>(m, pos, approx, select)
	{
140
		edgeInfo = m.template addAttribute<EdgeInfo, EDGE>("edgeInfo") ;
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
141
142
143
144
145
146
147
148
149
150
	}
	~EdgeSelector_Length()
	{
		this->m_map.removeAttribute(edgeInfo) ;
	}
	SelectorType getType() { return S_EdgeLength ; }
	bool init() ;
	bool nextEdge(Dart& d) ;
	void updateBeforeCollapse(Dart d) ;
	void updateAfterCollapse(Dart d2, Dart dd2) ;
untereiner's avatar
untereiner committed
151

152
	void updateWithoutCollapse();
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170

	void getEdgeErrors(EdgeAttribute<typename PFP::REAL> *errors)
	{
		assert(errors != NULL || !"EdgeSelector::setColorMap requires non null vertexattribute argument") ;
		if (!errors->isValid())
			std::cerr << "EdgeSelector::setColorMap requires valid edgeattribute argument" << std::endl ;
		assert(edgeInfo.isValid()) ;

		TraversorE<typename PFP::MAP> travE(this->m_map) ;
		for(Dart d = travE.begin() ; d != travE.end() ; d = travE.next())
		{
			(*errors)[d] = -1 ;
			if (edgeInfo[d].valid)
			{
				(*errors)[d] = edgeInfo[d].it->first ;
			}
		}
	}
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
} ;

template <typename PFP>
class EdgeSelector_QEM : public EdgeSelector<PFP>
{
public:
	typedef typename PFP::MAP MAP ;
	typedef typename PFP::VEC3 VEC3 ;
	typedef typename PFP::REAL REAL ;

private:
	typedef	struct
	{
		typename std::multimap<float,Dart>::iterator it ;
		bool valid ;
		static std::string CGoGNnameOfType() { return "QEMedgeInfo" ; }
	} QEMedgeInfo ;
	typedef NoMathIOAttribute<QEMedgeInfo> EdgeInfo ;

190
	EdgeAttribute<EdgeInfo> edgeInfo ;
191
192
	VertexAttribute<Utils::Quadric<REAL> > quadric ;
	Utils::Quadric<REAL> tmpQ ;
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
193
194
195
196

	std::multimap<float,Dart> edges ;
	typename std::multimap<float,Dart>::iterator cur ;

197
	Approximator<PFP, typename PFP::VEC3, EDGE>* m_positionApproximator ;
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
198
199
200
201
202
203

	void initEdgeInfo(Dart d) ;
	void updateEdgeInfo(Dart d, bool recompute) ;
	void computeEdgeInfo(Dart d, EdgeInfo& einfo) ;

public:
204
	EdgeSelector_QEM(MAP& m, VertexAttribute<typename PFP::VEC3>& pos, std::vector<ApproximatorGen<PFP>*>& approx, const FunctorSelect& select) :
205
206
		EdgeSelector<PFP>(m, pos, approx, select),
		m_positionApproximator(NULL)
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
207
	{
208
		edgeInfo = m.template addAttribute<EdgeInfo, EDGE>("edgeInfo") ;
209
		quadric = m.template addAttribute<Utils::Quadric<REAL>, VERTEX>("QEMquadric") ;
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
210
211
212
213
214
215
216
217
218
219
220
	}
	~EdgeSelector_QEM()
	{
		this->m_map.removeAttribute(quadric) ;
		this->m_map.removeAttribute(edgeInfo) ;
	}
	SelectorType getType() { return S_QEM ; }
	bool init() ;
	bool nextEdge(Dart& d) ;
	void updateBeforeCollapse(Dart d) ;
	void updateAfterCollapse(Dart d2, Dart dd2) ;
untereiner's avatar
untereiner committed
221

222
	void updateWithoutCollapse();
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
} ;

template <typename PFP>
class EdgeSelector_QEMml : public EdgeSelector<PFP>
{
public:
	typedef typename PFP::MAP MAP ;
	typedef typename PFP::VEC3 VEC3 ;
	typedef typename PFP::REAL REAL ;

private:
	typedef	struct
	{
		typename std::multimap<float,Dart>::iterator it ;
		bool valid ;
		static std::string CGoGNnameOfType() { return "QEMedgeInfo" ; }
	} QEMedgeInfo ;
	typedef NoMathIOAttribute<QEMedgeInfo> EdgeInfo ;

242
	EdgeAttribute<EdgeInfo> edgeInfo ;
243
	VertexAttribute<Utils::Quadric<REAL> > quadric ;
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
244
245
246
247

	std::multimap<float,Dart> edges ;
	typename std::multimap<float,Dart>::iterator cur ;

248
	Approximator<PFP, typename PFP::VEC3, EDGE>* m_positionApproximator ;
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
249
250
251
252
253
254
255

	void initEdgeInfo(Dart d) ;
	void updateEdgeInfo(Dart d, bool recompute) ;
	void computeEdgeInfo(Dart d, EdgeInfo& einfo) ;
	void recomputeQuadric(const Dart d, const bool recomputeNeighbors = false) ;

public:
256
	EdgeSelector_QEMml(MAP& m, VertexAttribute<typename PFP::VEC3>& pos, std::vector<ApproximatorGen<PFP>*>& approx, const FunctorSelect& select) :
257
258
		EdgeSelector<PFP>(m, pos, approx, select),
		m_positionApproximator(NULL)
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
259
	{
260
		edgeInfo = m.template addAttribute<EdgeInfo, EDGE>("edgeInfo") ;
261
		quadric = m.template addAttribute<Utils::Quadric<REAL>, VERTEX>("QEMquadric") ;
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
262
263
264
265
266
267
268
269
270
271
272
	}
	~EdgeSelector_QEMml()
	{
		this->m_map.removeAttribute(quadric) ;
		this->m_map.removeAttribute(edgeInfo) ;
	}
	SelectorType getType() { return S_QEMml ; }
	bool init() ;
	bool nextEdge(Dart& d) ;
	void updateBeforeCollapse(Dart d) ;
	void updateAfterCollapse(Dart d2, Dart dd2) ;
untereiner's avatar
untereiner committed
273

274
	void updateWithoutCollapse();
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
275
276
} ;

277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305

template <typename PFP>
class EdgeSelector_NormalArea : public EdgeSelector<PFP>
{
public:
	typedef typename PFP::MAP MAP ;
	typedef typename PFP::VEC3 VEC3 ;
	typedef typename PFP::REAL REAL ;

private:
	typedef	struct
	{
		typename std::multimap<float,Dart>::iterator it ;
		bool valid ;
		static std::string CGoGNnameOfType() { return "NormalAreaEdgeInfo" ; }
	} NormalAreaEdgeInfo ;
	typedef NoMathIOAttribute<NormalAreaEdgeInfo> EdgeInfo ;

	EdgeAttribute<EdgeInfo> edgeInfo ;
	EdgeAttribute<Geom::Matrix<3,3,REAL> > edgeMatrix ;

	std::multimap<float,Dart> edges ;
	typename std::multimap<float,Dart>::iterator cur ;

	Approximator<PFP, typename PFP::VEC3, EDGE>* m_positionApproximator ;

	void initEdgeInfo(Dart d) ;
	void updateEdgeInfo(Dart d) ;
	void computeEdgeInfo(Dart d, EdgeInfo& einfo) ;
306
	void computeEdgeMatrix(Dart d) ;
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
//	void recomputeQuadric(const Dart d, const bool recomputeNeighbors = false) ;

public:
	EdgeSelector_NormalArea(MAP& m, VertexAttribute<typename PFP::VEC3>& pos, std::vector<ApproximatorGen<PFP>*>& approx, const FunctorSelect& select) :
		EdgeSelector<PFP>(m, pos, approx, select),
		m_positionApproximator(NULL)
	{
		edgeInfo = m.template addAttribute<EdgeInfo, EDGE>("edgeInfo") ;
		edgeMatrix = m.template addAttribute<Geom::Matrix<3,3,REAL>, EDGE>("NormalAreaMatrix") ;
	}
	~EdgeSelector_NormalArea()
	{
		this->m_map.removeAttribute(edgeMatrix) ;
		this->m_map.removeAttribute(edgeInfo) ;
	}
	SelectorType getType() { return S_NormalArea ; }
	bool init() ;
	bool nextEdge(Dart& d) ;
	void updateBeforeCollapse(Dart d) ;
	void updateAfterCollapse(Dart d2, Dart dd2) ;

	void updateWithoutCollapse() { }
} ;


Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
template <typename PFP>
class EdgeSelector_Curvature : public EdgeSelector<PFP>
{
public:
	typedef typename PFP::MAP MAP ;
	typedef typename PFP::VEC3 VEC3 ;
	typedef typename PFP::REAL REAL ;

private:
	typedef	struct
	{
		typename std::multimap<float,Dart>::iterator it ;
		bool valid ;
		static std::string CGoGNnameOfType() { return "CurvatureEdgeInfo" ; }
	} CurvatureEdgeInfo ;
	typedef NoMathIOAttribute<CurvatureEdgeInfo> EdgeInfo ;

349
350
351
	Geom::BoundingBox<VEC3> bb ;
	REAL radius ;

352
	VertexAttribute<VEC3> normal ;
353
	EdgeAttribute<EdgeInfo> edgeInfo ;
354
355
356
357
358
359
	EdgeAttribute<REAL> edgeangle ;
	VertexAttribute<REAL> kmax ;
	VertexAttribute<REAL> kmin ;
	VertexAttribute<VEC3> Kmax ;
	VertexAttribute<VEC3> Kmin ;
	VertexAttribute<VEC3> Knormal ;
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
360
361
362
363

	std::multimap<float,Dart> edges ;
	typename std::multimap<float,Dart>::iterator cur ;

364
	Approximator<PFP, VEC3,EDGE>* m_positionApproximator ;
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
365
366
367
368
369
370

	void initEdgeInfo(Dart d) ;
	void updateEdgeInfo(Dart d, bool recompute) ;
	void computeEdgeInfo(Dart d, EdgeInfo& einfo) ;

public:
371
	EdgeSelector_Curvature(MAP& m, VertexAttribute<VEC3>& pos, std::vector<ApproximatorGen<PFP>*>& approx, const FunctorSelect& select) :
372
373
		EdgeSelector<PFP>(m, pos, approx, select),
		m_positionApproximator(NULL)
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
374
	{
375
376
377
		bb = Algo::Geometry::computeBoundingBox<PFP>(m, pos) ;
		radius = bb.diagSize() * 0.003 ;

378
		normal = m.template getAttribute<VEC3, VERTEX>("normal") ;
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
379
380
		if(!normal.isValid())
		{
381
			normal = m.template addAttribute<VEC3, VERTEX>("normal") ;
382
			Algo::Surface::Geometry::computeNormalVertices<PFP>(m, pos, normal) ;
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
383
384
		}

385
		edgeangle = m.template getAttribute<REAL, EDGE>("edgeangle") ;
386
387
		if(!edgeangle.isValid())
		{
388
			edgeangle = m.template addAttribute<REAL, EDGE>("edgeangle") ;
389
			Algo::Surface::Geometry::computeAnglesBetweenNormalsOnEdges<PFP>(m, pos, edgeangle) ;
390
391
		}

392
393
394
395
396
		kmax = m.template getAttribute<REAL, VERTEX>("kmax") ;
		kmin = m.template getAttribute<REAL, VERTEX>("kmin") ;
		Kmax = m.template getAttribute<VEC3, VERTEX>("Kmax") ;
		Kmin = m.template getAttribute<VEC3, VERTEX>("Kmin") ;
		Knormal = m.template getAttribute<VEC3, VERTEX>("Knormal") ;
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
397
398
		// as all these attributes are computed simultaneously by computeCurvatureVertices
		// one can assume that if one of them is not valid, the others must be created too
399
		if(!kmax.isValid())
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
400
		{
401
402
403
404
405
			kmax = m.template addAttribute<REAL, VERTEX>("kmax") ;
			kmin = m.template addAttribute<REAL, VERTEX>("kmin") ;
			Kmax = m.template addAttribute<VEC3, VERTEX>("Kmax") ;
			Kmin = m.template addAttribute<VEC3, VERTEX>("Kmin") ;
			Knormal = m.template addAttribute<VEC3, VERTEX>("Knormal") ;
406
			Algo::Surface::Geometry::computeCurvatureVertices_NormalCycles<PFP>(m, radius, pos, normal, edgeangle, kmax, kmin, Kmax, Kmin, Knormal) ;
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
407
408
		}

409
		edgeInfo = m.template addAttribute<EdgeInfo, EDGE>("edgeInfo") ;
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
410
411
412
	}
	~EdgeSelector_Curvature()
	{
413
414
415
416
417
418
		this->m_map.removeAttribute(edgeangle) ;
		this->m_map.removeAttribute(kmax) ;
		this->m_map.removeAttribute(kmin) ;
		this->m_map.removeAttribute(Kmax) ;
		this->m_map.removeAttribute(Kmin) ;
		this->m_map.removeAttribute(Knormal) ;
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
419
420
421
422
423
424
425
		this->m_map.removeAttribute(edgeInfo) ;
	}
	SelectorType getType() { return S_Curvature ; }
	bool init() ;
	bool nextEdge(Dart& d) ;
	void updateBeforeCollapse(Dart d) ;
	void updateAfterCollapse(Dart d2, Dart dd2) ;
untereiner's avatar
untereiner committed
426

427
	void updateWithoutCollapse();
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
428
429
} ;

430
431
432
433

template <typename PFP>
class EdgeSelector_CurvatureTensor : public EdgeSelector<PFP>
{
Sauvage's avatar
Sauvage committed
434
	// TODO : this selector still needs to be tested
435
436
437
438
439
440
441
442
443
444
445
446
public:
	typedef typename PFP::MAP MAP ;
	typedef typename PFP::VEC3 VEC3 ;
	typedef typename PFP::REAL REAL ;

private:
	typedef	struct
	{
		typename std::multimap<float,Dart>::iterator it ;
		bool valid ;
		static std::string CGoGNnameOfType() { return "CurvatureTensorEdgeInfo" ; }
	} CurvatureTensorEdgeInfo ;
447
	typedef NoMathIOAttribute<CurvatureTensorEdgeInfo> EdgeInfo ;
448
449
450
451
452
453
454
455
456
457

	EdgeAttribute<EdgeInfo> edgeInfo ;
	EdgeAttribute<REAL> edgeangle ;

	std::multimap<float,Dart> edges ;
	typename std::multimap<float,Dart>::iterator cur ;

	Approximator<PFP, VEC3,EDGE>* m_positionApproximator ;

	void initEdgeInfo(Dart d) ;
458
	void updateEdgeInfo(Dart d) ; // TODO : usually has a 2nd arg (, bool recompute) : why ??
459
460
461
462
463
464
465
466
467
468
469
	void computeEdgeInfo(Dart d, EdgeInfo& einfo) ;

public:
	EdgeSelector_CurvatureTensor(MAP& m, VertexAttribute<VEC3>& pos, std::vector<ApproximatorGen<PFP>*>& approx, const FunctorSelect& select) :
		EdgeSelector<PFP>(m, pos, approx, select),
		m_positionApproximator(NULL)
	{
		edgeangle = m.template getAttribute<REAL, EDGE>("edgeangle") ;
		if(!edgeangle.isValid())
		{
			edgeangle = m.template addAttribute<REAL, EDGE>("edgeangle") ;
470
			Algo::Surface::Geometry::computeAnglesBetweenNormalsOnEdges<PFP>(m, pos, edgeangle) ;
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
		}

		edgeInfo = m.template addAttribute<EdgeInfo, EDGE>("edgeInfo") ;
	}
	~EdgeSelector_CurvatureTensor()
	{
		this->m_map.removeAttribute(edgeangle) ; // TODO : pas malin s'il existait avant
		this->m_map.removeAttribute(edgeInfo) ;
	}
	SelectorType getType() { return S_CurvatureTensor ; }
	bool init() ;
	bool nextEdge(Dart& d) ;
	void updateBeforeCollapse(Dart d) ;
	void updateAfterCollapse(Dart d2, Dart dd2) ;

	void updateWithoutCollapse() {};
} ;


Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
template <typename PFP>
class EdgeSelector_MinDetail : public EdgeSelector<PFP>
{
public:
	typedef typename PFP::MAP MAP ;
	typedef typename PFP::VEC3 VEC3 ;
	typedef typename PFP::REAL REAL ;

private:
	typedef	struct
	{
		typename std::multimap<float,Dart>::iterator it ;
		bool valid ;
		static std::string CGoGNnameOfType() { return "MinDetailEdgeInfo" ; }
	} MinDetailEdgeInfo ;
	typedef NoMathIOAttribute<MinDetailEdgeInfo> EdgeInfo ;

507
	EdgeAttribute<EdgeInfo> edgeInfo ;
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
508
509
510
511

	std::multimap<float,Dart> edges ;
	typename std::multimap<float,Dart>::iterator cur ;

512
	Approximator<PFP, typename PFP::VEC3, EDGE>* m_positionApproximator ;
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
513
514
515
516
517
518

	void initEdgeInfo(Dart d) ;
	void updateEdgeInfo(Dart d, bool recompute) ;
	void computeEdgeInfo(Dart d, EdgeInfo& einfo) ;

public:
519
	EdgeSelector_MinDetail(MAP& m, VertexAttribute<typename PFP::VEC3>& pos, std::vector<ApproximatorGen<PFP>*>& approx, const FunctorSelect& select) :
520
521
		EdgeSelector<PFP>(m, pos, approx, select),
		m_positionApproximator(NULL)
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
522
	{
523
		edgeInfo = m.template addAttribute<EdgeInfo, EDGE>("edgeInfo") ;
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
524
525
526
527
528
529
530
531
532
533
	}
	~EdgeSelector_MinDetail()
	{
		this->m_map.removeAttribute(edgeInfo) ;
	}
	SelectorType getType() { return S_MinDetail ; }
	bool init() ;
	bool nextEdge(Dart& d) ;
	void updateBeforeCollapse(Dart d) ;
	void updateAfterCollapse(Dart d2, Dart dd2) ;
untereiner's avatar
untereiner committed
534

535
	void updateWithoutCollapse();
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
536
537
} ;

538
/*****************************************************************************************************************
539
 *                                      EDGE NAIVE COLOR METRIC (using QEMml)                                    *
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
 *****************************************************************************************************************/
template <typename PFP>
class EdgeSelector_ColorNaive : public EdgeSelector<PFP>
{
public:
	typedef typename PFP::MAP MAP ;
	typedef typename PFP::VEC3 VEC3 ;
	typedef typename PFP::REAL REAL ;

private:
	typedef	struct
	{
		typename std::multimap<float,Dart>::iterator it ;
		bool valid ;
		static std::string CGoGNnameOfType() { return "ColorNaiveEdgeInfo" ; }
	} ColorNaiveedgeInfo ;
	typedef NoMathIOAttribute<ColorNaiveedgeInfo> EdgeInfo ;

	EdgeAttribute<EdgeInfo> edgeInfo ;
559
	VertexAttribute<Utils::Quadric<REAL> > m_quadric ;
560

561
562
563
564
	VertexAttribute<VEC3> m_pos, m_color ;
	int m_approxindex_pos, m_attrindex_pos ;
	int m_approxindex_color, m_attrindex_color ;

565
	std::vector<Approximator<PFP, typename PFP::VEC3, EDGE>* > m_approx ;
566

567
568
569
570
571
572
573
574
575
576
577
	std::multimap<float,Dart> edges ;
	typename std::multimap<float,Dart>::iterator cur ;

	void initEdgeInfo(Dart d) ;
	void updateEdgeInfo(Dart d, bool recompute) ;
	void computeEdgeInfo(Dart d,EdgeInfo& einfo) ;
	void recomputeQuadric(const Dart d, const bool recomputeNeighbors = false) ;

public:
	EdgeSelector_ColorNaive(MAP& m, VertexAttribute<typename PFP::VEC3>& pos, std::vector<ApproximatorGen<PFP>*>& approx, const FunctorSelect& select = allDarts) :
		EdgeSelector<PFP>(m, pos, approx, select),
578
579
580
581
		m_approxindex_pos(-1),
		m_attrindex_pos(-1),
		m_approxindex_color(-1),
		m_attrindex_color(-1)
582
583
	{
		edgeInfo = m.template addAttribute<EdgeInfo, EDGE>("edgeInfo") ;
584
		m_quadric = m.template addAttribute<Utils::Quadric<REAL>, VERTEX>("QEMquadric") ;
585
586
587
588
589
590
591
592
593
594
595
	}
	~EdgeSelector_ColorNaive()
	{
		this->m_map.removeAttribute(edgeInfo) ;
		this->m_map.removeAttribute(m_quadric) ;
	}
	SelectorType getType() { return S_ColorNaive ; }
	bool init() ;
	bool nextEdge(Dart& d) ;
	void updateBeforeCollapse(Dart d) ;
	void updateAfterCollapse(Dart d2, Dart dd2) ;
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
596
597

	void updateWithoutCollapse() { }
598
599
} ;

600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
/*****************************************************************************************************************
 *                                 QEM extended to color metric                                                  *
 *****************************************************************************************************************/
template <typename PFP>
class EdgeSelector_QEMextColor : public EdgeSelector<PFP>
{
public:
	typedef typename PFP::MAP MAP ;
	typedef typename PFP::REAL REAL ;
	typedef typename PFP::VEC3 VEC3 ;
	typedef typename Geom::Vector<6,REAL> VEC6 ;

private:
	typedef	struct
	{
		typename std::multimap<float,Dart>::iterator it ;
		bool valid ;
		static std::string CGoGNnameOfType() { return "QEMextColorEdgeInfo" ; }
	} QEMextColorEdgeInfo ;
	typedef NoMathIOAttribute<QEMextColorEdgeInfo> EdgeInfo ;

	EdgeAttribute<EdgeInfo> edgeInfo ;
622
	VertexAttribute<Utils::QuadricNd<REAL,6> > m_quadric ;
623

624
625
626
627
	VertexAttribute<VEC3> m_pos, m_color ;
	int m_approxindex_pos, m_attrindex_pos ;
	int m_approxindex_color, m_attrindex_color ;

628
	std::vector<Approximator<PFP, typename PFP::VEC3, EDGE>* > m_approx ;
629

630
631
632
633
634
635
636
637
638
639
640
	std::multimap<float,Dart> edges ;
	typename std::multimap<float,Dart>::iterator cur ;

	void initEdgeInfo(Dart d) ;
	void updateEdgeInfo(Dart d, bool recompute) ;
	void computeEdgeInfo(Dart d,EdgeInfo& einfo) ;
	void recomputeQuadric(const Dart d, const bool recomputeNeighbors = false) ;

public:
	EdgeSelector_QEMextColor(MAP& m, VertexAttribute<typename PFP::VEC3>& pos, std::vector<ApproximatorGen<PFP>*>& approx, const FunctorSelect& select = allDarts) :
		EdgeSelector<PFP>(m, pos, approx, select),
641
642
643
644
		m_approxindex_pos(-1),
		m_attrindex_pos(-1),
		m_approxindex_color(-1),
		m_attrindex_color(-1)
645
646
	{
		edgeInfo = m.template addAttribute<EdgeInfo, EDGE>("edgeInfo") ;
647
		m_quadric = m.template addAttribute<Utils::QuadricNd<REAL,6>, VERTEX>("QEMext-quadric") ;
648
649
650
651
652
653
654
655
656
657
658
	}
	~EdgeSelector_QEMextColor()
	{
		this->m_map.removeAttribute(edgeInfo) ;
		this->m_map.removeAttribute(m_quadric) ;
	}
	SelectorType getType() { return S_QEMextColor ; }
	bool init() ;
	bool nextEdge(Dart& d) ;
	void updateBeforeCollapse(Dart d) ;
	void updateAfterCollapse(Dart d2, Dart dd2) ;
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
659
660

	void updateWithoutCollapse() { }
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678

	void getEdgeErrors(EdgeAttribute<typename PFP::REAL> *errors)
	{
		assert(errors != NULL || !"EdgeSelector::setColorMap requires non null vertexattribute argument") ;
		if (!errors->isValid())
			std::cerr << "EdgeSelector::setColorMap requires valid edgeattribute argument" << std::endl ;
		assert(edgeInfo.isValid()) ;

		TraversorE<typename PFP::MAP> travE(this->m_map) ;
		for(Dart d = travE.begin() ; d != travE.end() ; d = travE.next())
		{
			(*errors)[d] = -1 ;
			if (edgeInfo[d].valid)
			{
				(*errors)[d] = edgeInfo[d].it->first ;
			}
		}
	}
679
} ;
680

681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
/*****************************************************************************************************************
 *                                 LIGHTFIELD QUADRIC ERROR METRIC                                               *
 *****************************************************************************************************************/
template <typename PFP>
class EdgeSelector_Lightfield : public EdgeSelector<PFP>
{
public:
	typedef typename PFP::MAP MAP ;
	typedef typename PFP::REAL REAL ;
	typedef typename PFP::VEC3 VEC3 ;
	typedef typename Geom::Vector<6,REAL> VEC6 ;

private:
	typedef	struct
	{
		typename std::multimap<float,Dart>::iterator it ;
		bool valid ;
		static std::string CGoGNnameOfType() { return "QEMextColorEdgeInfo" ; }
699
700
	} LightfieldEdgeInfo ;
	typedef NoMathIOAttribute<LightfieldEdgeInfo> EdgeInfo ;
701
702
703
704

	EdgeAttribute<EdgeInfo> edgeInfo ;

	VertexAttribute<VEC3> m_pos, m_frameT, m_frameB, m_frameN ;
705
	std::vector<VertexAttribute<VEC3> > m_HF ;
706
707
	int m_approxindex_pos, m_attrindex_pos ;
	int m_approxindex_FN, m_attrindex_FN ;
708
709
	std::vector<unsigned int> m_approxindex_HF, m_attrindex_HF ;
	unsigned int m_K ;
710

711
712
	VertexAttribute<Utils::Quadric<REAL> > m_quadricGeom ;
	EdgeAttribute<Utils::QuadricHF<REAL> > m_quadricHF ;
713

714
	std::vector<Approximator<PFP, typename PFP::VEC3, EDGE>* > m_approx ;
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729

	std::multimap<float,Dart> edges ;
	typename std::multimap<float,Dart>::iterator cur ;

	void initEdgeInfo(Dart d) ;
	void updateEdgeInfo(Dart d, bool recompute) ;
	void computeEdgeInfo(Dart d,EdgeInfo& einfo) ;
	void recomputeQuadric(const Dart d, const bool recomputeNeighbors = false) ;

public:
	EdgeSelector_Lightfield(MAP& m, VertexAttribute<typename PFP::VEC3>& pos, std::vector<ApproximatorGen<PFP>*>& approx, const FunctorSelect& select = allDarts) :
		EdgeSelector<PFP>(m, pos, approx, select),
		m_approxindex_pos(-1),
		m_attrindex_pos(-1),
		m_approxindex_FN(-1),
730
731
		m_attrindex_FN(-1),
		m_K(0)
732
733
	{
		edgeInfo = m.template addAttribute<EdgeInfo, EDGE>("edgeInfo") ;
734
735
		m_quadricGeom = m.template addAttribute<Utils::Quadric<REAL>, VERTEX>("QEMquadric") ;
		m_quadricHF = m.template getAttribute<Utils::QuadricHF<REAL>, EDGE>("HFquadric") ;
736
737
738
739
740
741
742
743
744
745
746
	}
	~EdgeSelector_Lightfield()
	{
		this->m_map.removeAttribute(edgeInfo) ;
		this->m_map.removeAttribute(m_quadricGeom) ;
	}
	SelectorType getType() { return S_Lightfield ; }
	bool init() ;
	bool nextEdge(Dart& d) ;
	void updateBeforeCollapse(Dart d) ;
	void updateAfterCollapse(Dart d2, Dart dd2) ;
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
747
748

	void updateWithoutCollapse() { }
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767

	void getEdgeErrors(EdgeAttribute<typename PFP::REAL> *errors)
	{
		assert(errors != NULL || !"EdgeSelector::setColorMap requires non null vertexattribute argument") ;
		if (!errors->isValid())
			std::cerr << "EdgeSelector::setColorMap requires valid edgeattribute argument" << std::endl ;
		assert(edgeInfo.isValid()) ;

		TraversorE<typename PFP::MAP> travE(this->m_map) ;
		for(Dart d = travE.begin() ; d != travE.end() ; d = travE.next())
		{
			if (edgeInfo[d].valid)
			{
				(*errors)[d] = edgeInfo[d].it->first ;
			}
			else
				(*errors)[d] = -1 ;
		}
	}
768
769
} ;

Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
770
771
} // namespace Decimation

772
773
}

Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
774
775
776
777
778
779
780
} // namespace Algo

} // namespace CGoGN

#include "Algo/Decimation/edgeSelector.hpp"

#endif