Création d'un compte pour un collaborateur extérieur au laboratoire depuis l'intranet ICube : https://intranet.icube.unistra.fr/fr/labs/member/profile

edgeSelector.h 12.3 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
34
35
#include "Container/fakeAttribute.h"
#include "Utils/qem.h"
#include "Utils/quadricRGBfunctions.h"
#include "Algo/Geometry/curvature.h"

Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
namespace CGoGN
{

namespace Algo
{

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:
57
	EdgeSelector_MapOrder(MAP& m, VertexAttribute<typename PFP::VEC3>& pos, std::vector<ApproximatorGen<PFP>*>& approx, const FunctorSelect& select) :
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
58
59
60
61
62
63
64
65
66
67
		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
68
69

	bool nextEdgeWithoutUpdates(Dart& d) { }
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
} ;

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:
86
	EdgeSelector_Random(MAP& m, VertexAttribute<typename PFP::VEC3>& pos, std::vector<ApproximatorGen<PFP>*>& approx, const FunctorSelect& select) :
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
87
88
89
90
91
92
93
94
95
96
		EdgeSelector<PFP>(m, pos, approx, select)
	{}
	~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
97
98

	bool nextEdgeWithoutUpdates(Dart& d) { }
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
} ;

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 ;

118
	EdgeAttribute<EdgeInfo> edgeInfo ;
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
119
120
121
122
123
124
125
126
127

	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:
128
	EdgeSelector_Length(MAP& m, VertexAttribute<typename PFP::VEC3>& pos, std::vector<ApproximatorGen<PFP>*>& approx, const FunctorSelect& select) :
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
129
130
		EdgeSelector<PFP>(m, pos, approx, select)
	{
131
		edgeInfo = m.template addAttribute<EdgeInfo, EDGE>("edgeInfo") ;
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
132
133
134
135
136
137
138
139
140
141
	}
	~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
142
143

	bool nextEdgeWithoutUpdates(Dart& d) { }
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
} ;

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 ;

163
164
	EdgeAttribute<EdgeInfo> edgeInfo ;
	VertexAttribute<Quadric<REAL> > quadric ;
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
165
166
167
168
169
170
171
172
173
174
175
176
	Quadric<REAL> tmpQ ;

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

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

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

public:
177
	EdgeSelector_QEM(MAP& m, VertexAttribute<typename PFP::VEC3>& pos, std::vector<ApproximatorGen<PFP>*>& approx, const FunctorSelect& select) :
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
178
179
		EdgeSelector<PFP>(m, pos, approx, select)
	{
180
181
		edgeInfo = m.template addAttribute<EdgeInfo, EDGE>("edgeInfo") ;
		quadric = m.template addAttribute<Quadric<REAL>, VERTEX>("QEMquadric") ;
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
182
183
184
185
186
187
188
189
190
191
192
	}
	~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
193
194

	bool nextEdgeWithoutUpdates(Dart& d);
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
} ;

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 ;

214
215
	EdgeAttribute<EdgeInfo> edgeInfo ;
	VertexAttribute<Quadric<REAL> > quadric ;
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
216
217
218
219
220
221
222
223
224
225
226
227

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

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

	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:
228
	EdgeSelector_QEMml(MAP& m, VertexAttribute<typename PFP::VEC3>& pos, std::vector<ApproximatorGen<PFP>*>& approx, const FunctorSelect& select) :
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
229
230
		EdgeSelector<PFP>(m, pos, approx, select)
	{
231
232
		edgeInfo = m.template addAttribute<EdgeInfo, EDGE>("edgeInfo") ;
		quadric = m.template addAttribute<Quadric<REAL>, VERTEX>("QEMquadric") ;
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
233
234
235
236
237
238
239
240
241
242
243
	}
	~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
244
245

	bool nextEdgeWithoutUpdates(Dart& d) { }
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
} ;

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 ;

265
266
267
	Geom::BoundingBox<VEC3> bb ;
	REAL radius ;

268
	VertexAttribute<VEC3> normal ;
269
	EdgeAttribute<EdgeInfo> edgeInfo ;
270
271
272
273
274
275
	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
276
277
278
279

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

280
	Approximator<PFP, VEC3>* m_positionApproximator ;
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
281
282
283
284
285
286

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

public:
287
	EdgeSelector_Curvature(MAP& m, VertexAttribute<VEC3>& pos, std::vector<ApproximatorGen<PFP>*>& approx, const FunctorSelect& select) :
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
288
289
		EdgeSelector<PFP>(m, pos, approx, select)
	{
290
291
292
		bb = Algo::Geometry::computeBoundingBox<PFP>(m, pos) ;
		radius = bb.diagSize() * 0.003 ;

293
		normal = m.template getAttribute<VEC3, VERTEX>("normal") ;
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
294
295
		if(!normal.isValid())
		{
296
			normal = m.template addAttribute<VEC3, VERTEX>("normal") ;
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
297
298
299
			Algo::Geometry::computeNormalVertices<PFP>(m, pos, normal) ;
		}

300
		edgeangle = m.template getAttribute<REAL, EDGE>("edgeangle") ;
301
302
		if(!edgeangle.isValid())
		{
303
			edgeangle = m.template addAttribute<REAL, EDGE>("edgeangle") ;
304
305
306
			Algo::Geometry::computeAnglesBetweenNormalsOnEdges<PFP>(m, pos, edgeangle) ;
		}

307
308
309
310
311
		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
312
313
		// 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
314
		if(!kmax.isValid())
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
315
		{
316
317
318
319
320
			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") ;
321
			Algo::Geometry::computeCurvatureVertices_NormalCycles<PFP>(m, radius, pos, normal, edgeangle, kmax, kmin, Kmax, Kmin, Knormal) ;
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
322
323
		}

324
		edgeInfo = m.template addAttribute<EdgeInfo, EDGE>("edgeInfo") ;
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
325
326
327
	}
	~EdgeSelector_Curvature()
	{
328
329
330
331
332
333
		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
334
335
336
337
338
339
340
		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
341
342

	bool nextEdgeWithoutUpdates(Dart& d) { }
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
} ;

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 ;

362
	EdgeAttribute<EdgeInfo> edgeInfo ;
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
363
364
365
366
367
368
369
370
371
372
373

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

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

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

public:
374
	EdgeSelector_MinDetail(MAP& m, VertexAttribute<typename PFP::VEC3>& pos, std::vector<ApproximatorGen<PFP>*>& approx, const FunctorSelect& select) :
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
375
376
		EdgeSelector<PFP>(m, pos, approx, select)
	{
377
		edgeInfo = m.template addAttribute<EdgeInfo, EDGE>("edgeInfo") ;
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
378
379
380
381
382
383
384
385
386
387
	}
	~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
388
389

	bool nextEdgeWithoutUpdates(Dart& d) { }
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
390
391
392
393
394
395
396
397
398
399
400
} ;

} // namespace Decimation

} // namespace Algo

} // namespace CGoGN

#include "Algo/Decimation/edgeSelector.hpp"

#endif