ihm3.h 10.9 KB
Newer Older
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           *
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/                                           *
21
22
23
24
25
26
27
* Contact information: cgogn@unistra.fr                                        *
*                                                                              *
*******************************************************************************/

#ifndef __IMPLICIT_HIERARCHICAL_MAP3__
#define __IMPLICIT_HIERARCHICAL_MAP3__

28
#include "Topology/map/embeddedMap3.h"
29
30
31
32
33
34
35

namespace CGoGN
{

namespace Algo
{

36
37
38
namespace Volume
{

untereiner's avatar
untereiner committed
39
namespace IHM
40
41
{

untereiner's avatar
untereiner committed
42

Pierre Kraemer's avatar
Pierre Kraemer committed
43
template<typename T, unsigned int ORBIT> class AttributeHandler_IHM ;
44

45
class ImplicitHierarchicalMap3 : public EmbeddedMap3
46
{
Pierre Kraemer's avatar
Pierre Kraemer committed
47
	template<typename T, unsigned int ORBIT> friend class AttributeHandler_IHM ;
48
49

public:
50
51
52
53
54
55

	FunctorType* vertexVertexFunctor ;
	FunctorType* edgeVertexFunctor ;
	FunctorType* faceVertexFunctor ;
	FunctorType* volumeVertexFunctor ;

56
57
58
59
60
	unsigned int m_curLevel ;
	unsigned int m_maxLevel ;
	unsigned int m_edgeIdCount ;
	unsigned int m_faceIdCount;

61
62
63
	DartAttribute<unsigned int> m_dartLevel ;
	DartAttribute<unsigned int> m_edgeId ;
	DartAttribute<unsigned int> m_faceId ;
64

Sylvain Thery's avatar
Sylvain Thery committed
65
	AttributeMultiVector<unsigned int>* m_nextLevelCell[NB_ORBITS] ;
66
67
68
69
70
71

public:
	ImplicitHierarchicalMap3() ;

	~ImplicitHierarchicalMap3() ;

72
	static const unsigned int DIMENSION = 3 ;
73
74
75
76
77

	//!
	/*!
	 *
	 */
78
79
	void update_topo_shortcuts();

80
81
82
83
	//!
	/*!
	 *
	 */
84
	void initImplicitProperties() ;
85

86
87
88
89
90
91
	/**
	 * clear the map
	 * @param remove attrib remove attribute (not only clear the content)
	 */
	void clear(bool removeAttrib);

92
93
94
	/*! @name Attributes Management
	 *  To handles Attributes for each level of an implicit 3-map
	 *************************************************************************/
95

96
97
98
99
100
	//@{
	//!
	/*!
	 *
	 */
Pierre Kraemer's avatar
Pierre Kraemer committed
101
102
	template <typename T, unsigned int ORBIT>
	AttributeHandler_IHM<T, ORBIT> addAttribute(const std::string& nameAttr) ;
untereiner's avatar
untereiner committed
103

104
105
106
107
	//!
	/*!
	 *
	 */
Pierre Kraemer's avatar
Pierre Kraemer committed
108
109
	template <typename T, unsigned int ORBIT>
	AttributeHandler_IHM<T, ORBIT> getAttribute(const std::string& nameAttr) ;
110
	//@}
untereiner's avatar
untereiner committed
111

112
113
114
	/*! @name Basic Topological Operators
	 *  Redefinition of the basic topological operators
	 *************************************************************************/
115

116
	//@{
117
118
119
120
121
122
	virtual Dart newDart() ;

	Dart phi1(Dart d) ;

	Dart phi_1(Dart d) ;

123
124
	Dart phi2(Dart d) ;

125
126
127
128
129
130
131
132
133
134
135
136
137
private:
	Dart phi2bis(Dart d) ;

public:
	Dart phi3(Dart d);

	Dart alpha0(Dart d);

	Dart alpha1(Dart d);

	Dart alpha2(Dart d);

	Dart alpha_2(Dart d);
138
	//@}
139

untereiner's avatar
untereiner committed
140
141
142
143
144
145
	/*! @name Topological Operators with Cells id management
	 *  Topological operations on Hierarchical Implicit 3-maps
	 *************************************************************************/

	//@{

146
147
148
149
150
151
	//!
	/*!
	 *
	 */
	void swapEdges(Dart d, Dart e);

152
153
154
155
156
157
158
159
160
161
	//!
	/*!
	 *
	 */
	void saveRelationsAroundVertex(Dart d, std::vector<std::pair<Dart, Dart> >& vd);

	void unsewAroundVertex(std::vector<std::pair<Dart, Dart> >& vd);

	Dart quadranguleFace(Dart d);

162
	void deleteVertexSubdividedFace(Dart d);
untereiner's avatar
untereiner committed
163
	//@}
164

165
166
167
168
169
	void setVertexVertexFunctor(FunctorType* f) { vertexVertexFunctor = f ; }
	void setEdgeVertexFunctor(FunctorType* f) { edgeVertexFunctor = f ; }
	void setFaceVertexFunctor(FunctorType* f) { faceVertexFunctor = f ; }
	void setVolumeVertexFunctor(FunctorType* f) { volumeVertexFunctor = f ; }

170
171
172
173
174
	void computeVertexVertexFunctor(Dart d) { (*vertexVertexFunctor)(d); }
	void computeEdgeVertexFunctor(Dart d) { (*edgeVertexFunctor)(d); }
	void computeFaceVertexFunctor(Dart d) { (*faceVertexFunctor)(d); }
	void computerVolumeVertexFunctor(Dart d) { (*volumeVertexFunctor)(d); }

175
176
177
178
	/*! @name Levels Management
	 *  Operations to manage the levels of an Implicit Hierarchical 3-map
	 *************************************************************************/

untereiner's avatar
untereiner committed
179
180
181
182
183
	void incCurrentLevel();

	void decCurrentLevel();


184
185
186
187
188
	//@{
	//!
	/*!
	 *
	 */
189
190
	unsigned int getCurrentLevel() ;

191
192
193
194
	//!
	/*!
	 *
	 */
195
196
	void setCurrentLevel(unsigned int l) ;

197
198
199
200
	//!
	/*!
	 *
	 */
201
202
	unsigned int getMaxLevel() ;

203
204
205
206
	//!
	/*!
	 *
	 */
207
208
	unsigned int getDartLevel(Dart d) ;

209
210
211
212
	//!
	/*!
	 *
	 */
213
	void setDartLevel(Dart d, unsigned int i) ;
214
	//@}
215

216
217
218
	/*! @name Id Management
	 * Operations to manage the ids of edges and faces
	 *************************************************************************/
219

220
221
222
	//@{
	//! Give a new unique id to all the edges of the map
	/*!
223
224
225
	 */
	void initEdgeId() ;

226
227
	//! Return the next available edge id
	/*!
228
229
230
	 */
	unsigned int getNewEdgeId() ;

231
232
	//! Return the id of the edge of d
	/*!
233
	 */
234
235
	unsigned int getEdgeId(Dart d) ;

236
237
	//! Set an edge id to all darts from an orbit of d
	/*!
238
	 */
239
240
	void setEdgeId(Dart d, unsigned int i, unsigned int orbit); //TODO a virer
	void setEdgeId(Dart d, unsigned int i);
241

242
243
	//! Give a new unique id to all the faces of the map
	/*!
244
	 */
245
246
	void initFaceId() ;

247
248
	//! Return the next available face id
	/*!
249
250
251
	 */
	unsigned int getNewFaceId() ;

252
253
	//! Return the id of the face of d
	/*!
254
	 */
255
256
	unsigned int getFaceId(Dart d) ;

257
258
	//! Set a face id to all darts from an orbit of d
	/*!
259
	 */
260
	void setFaceId(Dart d, unsigned int i, unsigned int orbit); //TODO a virer
261
	void setFaceId(unsigned int orbit, Dart d);
262
	//@}
263

264
265
266
	/*! @name Cells Information
	 * Operations to manage the cells informations :
	 *************************************************************************/
267

268
269
270
	//@{
	//! Return the level of insertion of the vertex of d
	/*!
271
272
273
	 */
	unsigned int vertexInsertionLevel(Dart d) ;

274
275
	//! Return the level of the edge of d in the current level map
	/*!
276
277
278
	 */
	unsigned int edgeLevel(Dart d) ;

279
280
	//! Return the level of the face of d in the current level map
	/*!
281
282
283
	 */
	unsigned int faceLevel(Dart d);

284
285
	//! Return the level of the volume of d in the current level map
	/*!
286
287
288
	 */
	unsigned int volumeLevel(Dart d);

289
290
	//! Return the oldest dart of the face of d in the current level map
	/*!
291
292
293
	 */
	Dart faceOldestDart(Dart d);

294
295
	//! Return the oldest dart of the volume of d in the current level map
	/*!
296
297
298
	 */
	Dart volumeOldestDart(Dart d);

299
300
301
	//! Return true if the edge of d in the current level map
	//! has already been subdivided to the next level
	/*!
302
303
304
	 */
	bool edgeIsSubdivided(Dart d) ;

305
306
307
308
309
	//! Return true if the edge of d in the current level map
	//! is subdivided to the next level,
	//! none of its resulting edges is in turn subdivided to the next level
	//! and the middle vertex is of degree 2
	/*!
untereiner's avatar
untereiner committed
310
311
312
	 */
	bool edgeCanBeCoarsened(Dart d);

313
314
315
316
317
318
	//! Return true if the face of d in the current level map
	//! has already been subdivided to the next level
	/*!
	 */
	bool faceIsSubdivided(Dart d) ;

319
320
	//!
	/*!
321
322
323
	 */
	bool faceCanBeCoarsened(Dart d);

324
325
	//! Return true if the volume of d in the current level map
	//! has already been subdivided to the next level
326
	/*!
untereiner's avatar
untereiner committed
327
	 */
328
	bool volumeIsSubdivided(Dart d);
untereiner's avatar
untereiner committed
329

330
331
	//!
	/*!
untereiner's avatar
untereiner committed
332
333
334
	 */
	bool volumeIsSubdividedOnce(Dart d);

335
336
337
338

	/*! @name
	 *************************************************************************/

339
340
	//!
	/*!
341
	 */
342
	bool neighborhoodLevelDiffersMoreThanOne(Dart d);
untereiner's avatar
untereiner committed
343

344
345
	//! wired !!!
	/*!
346
	 */
347
	bool coarsenNeighborhoodLevelDiffersMoreThanOne(Dart d);
348
349
350
351
352
353
354
	//@}

	/*! @name Cell Functors
	 * Redefition of the 3-maps map traversor
	 *************************************************************************/

	//@{
355
	virtual Dart begin() const;
356

357
	virtual Dart end() const;
358

359
	virtual void next(Dart& d) const ;
360
361
362
363
364
365
366
367

	virtual bool foreach_dart_of_vertex(Dart d, FunctorType& f, unsigned int thread = 0) ;

	virtual bool foreach_dart_of_edge(Dart d, FunctorType& f, unsigned int thread = 0) ;

	bool foreach_dart_of_oriented_face(Dart d, FunctorType& f, unsigned int thread = 0);
	virtual bool foreach_dart_of_face(Dart d, FunctorType& f, unsigned int thread = 0) ;

untereiner's avatar
untereiner committed
368
369
	bool foreach_dart_of_oriented_volume(Dart d, FunctorType& f, unsigned int thread = 0);
	virtual bool foreach_dart_of_volume(Dart d, FunctorType& f, unsigned int thread = 0) ;
370
371

	virtual bool foreach_dart_of_cc(Dart d, FunctorType& f, unsigned int thread = 0) ;
untereiner's avatar
untereiner committed
372
373
374
375
376
377
378


	virtual bool foreach_dart_of_vertex2(Dart d, FunctorType& f, unsigned int thread = 0);

	virtual bool foreach_dart_of_edge2(Dart d, FunctorType& f, unsigned int thread = 0);

	virtual bool foreach_dart_of_face2(Dart d, FunctorType& f, unsigned int thread = 0);
379
380
	//@}

381
382
	template <unsigned int ORBIT>
	unsigned int getEmbedding(Dart d);
383
384
} ;

Pierre Kraemer's avatar
Pierre Kraemer committed
385
386
template <typename T, unsigned int ORBIT>
class AttributeHandler_IHM : public AttributeHandler<T, ORBIT>
387
388
389
390
{
public:
	typedef T DATA_TYPE ;

Pierre Kraemer's avatar
Pierre Kraemer committed
391
	AttributeHandler_IHM() : AttributeHandler<T, ORBIT>()
392
393
	{}

Pierre Kraemer's avatar
Pierre Kraemer committed
394
	AttributeHandler_IHM(GenericMap* m, AttributeMultiVector<T>* amv) : AttributeHandler<T, ORBIT>(m, amv)
395
396
397
398
	{}

	AttributeMultiVector<T>* getDataVector() const
	{
Pierre Kraemer's avatar
Pierre Kraemer committed
399
		return AttributeHandler<T, ORBIT>::getDataVector() ;
400
401
402
403
	}

	bool isValid() const
	{
Pierre Kraemer's avatar
Pierre Kraemer committed
404
		return AttributeHandler<T, ORBIT>::isValid() ;
405
406
	}

407
	virtual T& operator[](Dart d) ;
408

409
	virtual const T& operator[](Dart d) const ;
410
411
412

	T& operator[](unsigned int a)
	{
Pierre Kraemer's avatar
Pierre Kraemer committed
413
		return AttributeHandler<T, ORBIT>::operator[](a) ;
414
415
416
417
	}

	const T& operator[](unsigned int a) const
	{
Pierre Kraemer's avatar
Pierre Kraemer committed
418
		return AttributeHandler<T, ORBIT>::operator[](a) ;
419
	}
420

421
} ;
422

untereiner's avatar
untereiner committed
423
template <typename T>
424
class VertexAttribute_IHM : public IHM::AttributeHandler_IHM<T, VERTEX>
untereiner's avatar
untereiner committed
425
426
{
public:
427
428
429
	VertexAttribute_IHM() : IHM::AttributeHandler_IHM<T, VERTEX>() {}
	VertexAttribute_IHM(const IHM::AttributeHandler_IHM<T, VERTEX>& ah) : IHM::AttributeHandler_IHM<T, VERTEX>(ah) {}
	VertexAttribute_IHM<T>& operator=(const IHM::AttributeHandler_IHM<T, VERTEX>& ah) { this->IHM::AttributeHandler_IHM<T, VERTEX>::operator=(ah); return *this; }
untereiner's avatar
untereiner committed
430
431
};

432
} //namespace IHM
433
} // Volume
434
435
436
437
438
439
440
} //namespace Algo

} //namespace CGoGN

#include "Algo/ImplicitHierarchicalMesh/ihm3.hpp"

#endif
441
442
443
444
445
446

////!
///*!
// */
//bool faceIsSubdividedOnce(Dart d);