map2.h 14 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-2011, 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.u-strasbg.fr/                                         *
Pierre Kraemer's avatar
Pierre Kraemer committed
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
* Contact information: cgogn@unistra.fr                                        *
*                                                                              *
*******************************************************************************/

#ifndef __MAP2_H__
#define __MAP2_H__

#include "Topology/map/map1.h"

namespace CGoGN
{

/*! \brief The class of dual 2-dimensional combinatorial maps:
 *  set of oriented faces pairwise sewed by an adjacency relation.
 *  A dual 2-map represents close or open oriented 2-manifolds (surfaces).
 *  - A dual 2-map is made of darts linked by the phi1 permutation
 * 	and/or the phi2 one-to-one relation.
 *  - In this class darts are interpreted as oriented edges.
 *  - The phi1 relation defines oriented faces (see Map1)
 *  and faces may have arbitrary size (degenerated faces are accepted).
 *  - The phi2 relation links oriented faces along oriented edges.
 *  A set of phi2-linked faces represents a surface 
 *  - Edges that have no phi2-link are border edges. If there exists
 *  such edges the map is open.
 *  - When every edge is phi2-linked, the map is closed. In this case
 *  some optimizations are enabled that speed up the processing of vertices.
 */
class Map2 : public Map1
{
protected:
51
	AttributeMultiVector<Dart>* m_phi2 ;
Pierre Kraemer's avatar
Pierre Kraemer committed
52

53
54
	void init() ;

Pierre Kraemer's avatar
Pierre Kraemer committed
55
56
57
58
59
60
61
62
63
public:
	typedef Map1 ParentMap;

	Map2();

	virtual std::string mapTypeName();

	virtual unsigned int dimension();

64
65
	virtual void clear(bool removeAttrib);

Pierre Kraemer's avatar
Pierre Kraemer committed
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
	/*! @name Basic Topological Operators
	 * Access and Modification
	 *************************************************************************/

	virtual Dart newDart();

	Dart phi2(Dart d);

	template <int N>
	Dart phi(Dart d);

	Dart alpha0(Dart d);

	Dart alpha1(Dart d);

	Dart alpha_1(Dart d);

protected:
	//! Link dart d with dart e by an involution
	/*  @param d,e the darts to link
	 *	- Before:	d->d and e->e
	 *	- After:	d->e and e->d
	 */
	void phi2sew(Dart d, Dart e);

	//! Unlink the current dart by an involution
	/*  @param d the dart to unlink
	 * - Before:	d->e and e->d
	 * - After:		d->d and e->e
	 */
	void phi2unsew(Dart d);

Sylvain Thery's avatar
Sylvain Thery committed
98
99
100
101
102
	//! merge a face that has been tag as boundary with existing boundary if needed
	/*  @param d a dart of the face
	 */
	void mergeFacewithBoundary(Dart d);

Sylvain Thery's avatar
Sylvain Thery committed
103
104
105
106
107
	/**
	 * merge two faces of boundary
	 */
	void mergeBoundaryFaces(Dart dd, Dart ee);

Pierre Kraemer's avatar
Pierre Kraemer committed
108
109
110
111
112
113
114
115
116
	/*! @name Generator and Deletor
	 *  To generate or delete faces in a 2-map
	 *************************************************************************/

	//@{
	//! Delete an oriented face erasing all its darts.
	/*! The phi2-links around the face are removed
	 *  @param d a dart of the face
	 */
Sylvain Thery's avatar
Sylvain Thery committed
117
	void deleteOrientedFace(Dart d) ; // OK boundary
Pierre Kraemer's avatar
Pierre Kraemer committed
118
119

public:
120
121
122
123
124
125
126

	//! Create an new face of nbEdges
	/*! @param nbEdges the number of edges
	 *  @return return a dart of the face
	 */
	virtual Dart newFace(unsigned int nbEdges) ;

Pierre Kraemer's avatar
Pierre Kraemer committed
127
128
129
130
131
132
133
134
135
136
137
138
139
	virtual void deleteFace(Dart d) ;
	//@}

	/*! @name Topological Operators
	 *  Topological operations on 2-maps
	 *************************************************************************/

	//@{
	//! Split a vertex v between d and e inserting an edge after d and e
	/*! \pre Darts d & e MUST belong to the same vertex
	 *  @param d first dart in vertex v
	 *  @param e second dart in vertex v
	 */
Sylvain Thery's avatar
Sylvain Thery committed
140
	virtual void splitVertex(Dart d, Dart e); // OK boundary
Sylvain Thery's avatar
Sylvain Thery committed
141

Pierre Kraemer's avatar
Pierre Kraemer committed
142
143
144
145
146
	//! Delete the vertex of d (works only for internal vertices)
	/*! All the faces around the vertex are merged into one face
	 *  @param d a dart of the vertex to delete
	 * @return true if the deletion has been executed, false otherwise
	 */
Sylvain Thery's avatar
Sylvain Thery committed
147
	virtual bool deleteVertex(Dart d) ;	// OK boundary
Sylvain Thery's avatar
Sylvain Thery committed
148

149
150
151
152
153
	//! Link two vertices belonging to distinct faces (add an edge between the two vertices)
	/*! \pre Dart d and e MUST be different and belong to distinct face
	 *  @param d first dart in the face
	 *  @param e second dart in the face
	 */
Sylvain Thery's avatar
Sylvain Thery committed
154
155
	virtual void linkVertices(Dart d, Dart e);	//TODO removing ??

Pierre Kraemer's avatar
Pierre Kraemer committed
156
	//! Cut the edge of d
Pierre Kraemer's avatar
Pierre Kraemer committed
157
158
	/*! @param d a dart of the edge to cut
	 */
Sylvain Thery's avatar
Sylvain Thery committed
159
	virtual void cutEdge(Dart d);// OK boundary
Sylvain Thery's avatar
Sylvain Thery committed
160

Pierre Kraemer's avatar
Pierre Kraemer committed
161
	//! Undo the cut of the edge of d
Pierre Kraemer's avatar
Pierre Kraemer committed
162
	/*! @param d a dart of the edge to uncut
Pierre Kraemer's avatar
Pierre Kraemer committed
163
	 * @return true if the uncut has been executed, false otherwise
Pierre Kraemer's avatar
Pierre Kraemer committed
164
	 */
Pierre Kraemer's avatar
Pierre Kraemer committed
165
	virtual bool uncutEdge(Dart d);// OK boundary
Pierre Kraemer's avatar
Pierre Kraemer committed
166

Pierre Kraemer's avatar
Pierre Kraemer committed
167
168
	//! Collapse an edge (that is deleted) possibly merging its vertices
	/*! If delDegenerateFaces is true, the method checks that no degenerate
169
	 *  faces are built (faces with less than 3 edges). If it occurs the faces
Pierre Kraemer's avatar
Pierre Kraemer committed
170
171
172
173
174
	 *  are deleted and the adjacencies are updated (see collapseDegeneratedFace).
	 *  \warning This may produce two distinct vertices if the edge
	 *  was the only link between two border faces
	 *  @param d a dart in the deleted edge
	 *  @param delDegenerateFaces a boolean (default to true)
175
	 *  @return a dart of the resulting vertex
Pierre Kraemer's avatar
Pierre Kraemer committed
176
	 */
Sylvain Thery's avatar
Sylvain Thery committed
177
	virtual Dart collapseEdge(Dart d, bool delDegenerateFaces = true);	//TODO close degenerated boundary ???
Sylvain Thery's avatar
Sylvain Thery committed
178

Pierre Kraemer's avatar
Pierre Kraemer committed
179
	/**
180
	 * Flip the edge of d (rotation in phi1 order)
Pierre Kraemer's avatar
Pierre Kraemer committed
181
182
183
184
185
186
187
	 * WARNING : Works only for non-border edges.
	 * @param d a dart of the edge to flip
	 * @return true if the flip has been executed, false otherwise
	 */
	virtual bool flipEdge(Dart d);

	/**
188
	 * Flip the edge of d (rotation in phi_1 order)
Pierre Kraemer's avatar
Pierre Kraemer committed
189
190
191
192
193
194
	 * WARNING : Works only for non-border edges.
	 * @param d a dart of the edge to flip
	 * @return true if the flip has been executed, false otherwise
	 */
	virtual bool flipBackEdge(Dart d);

195
196
197
198
199
200
	//! Insert an edge after a dart in the vertex orbit
	/*! \pre Dart d and e MUST be different and belong to distinct face
	 *  \pre Dart e must be phi2-linked with its phi_1 dart
	 *  @param d dart of the vertex
	 *  @param e dart of the edge
	 */
Sylvain Thery's avatar
Sylvain Thery committed
201
202
	virtual void insertEdgeInVertex(Dart d, Dart e);	//TODO modification for new boundary managing method

203
204
205
206
207

	//! Remove an edge from a vertex orbit
	/*! \pre Dart d must be phi2 sewn
	 *  @param d the dart of the edge to remove from the vertex
	 */
Sylvain Thery's avatar
Sylvain Thery committed
208
209
	virtual void removeEdgeFromVertex(Dart d);	//TODO modification for new boundary managing method

210

Pierre Kraemer's avatar
Pierre Kraemer committed
211
212
213
214
215
	//! Sew two oriented faces along oriented edges
	/*! \pre Darts d & e MUST be fixed point of phi2 relation
	 *  @param d a dart of the first face
	 *  @param e a dart of the second face
	 */
Sylvain Thery's avatar
Sylvain Thery committed
216
	virtual void sewFaces(Dart d, Dart e);
Sylvain Thery's avatar
Sylvain Thery committed
217

Pierre Kraemer's avatar
Pierre Kraemer committed
218
219
220
221

	//! Unsew two oriented faces along oriented edges
	 /*! @param d a dart of one face
	 */
Sylvain Thery's avatar
Sylvain Thery committed
222
	virtual void unsewFaces(Dart d);
Sylvain Thery's avatar
Sylvain Thery committed
223

Pierre Kraemer's avatar
Pierre Kraemer committed
224
225
226
227
228
229
230
	
	//! Delete an oriented face if and only if it has one or two edges
	/*! If the face is phi2-linked to two distinct adjacent faces,
	 *  then those two faces are phi2-linked
	 *  @param d a dart of the face
	 *  @return true if the collapse has been executed, false otherwise
	 */
Sylvain Thery's avatar
Sylvain Thery committed
231
	virtual bool collapseDegeneratedFace(Dart d);
Sylvain Thery's avatar
Sylvain Thery committed
232

Pierre Kraemer's avatar
Pierre Kraemer committed
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252

	//! Split a face f between d and e inserting an edge between vertices d & e
	/*! \pre Darts d & e MUST belong to the same face
	 *  @param d first dart in face f
	 *  @param e second dart in face f
	 */
	virtual void splitFace(Dart d, Dart e);

	//! Merge the two faces incident to the edge of d.
	/*! Works only for non-border edges.
	 *  \warning Darts d & phi2(d) no longer exist after the call
	 *  @param d a dart in the first face
	 *  @return true if the merge has been executed, false otherwise
	 */
	virtual bool mergeFaces(Dart d);

	/**
	 * Extract a pair of sewed triangles and sew their adjacent faces
	 * d is a dart of the common edge of the pair of triangles
	 */
Sylvain Thery's avatar
Sylvain Thery committed
253
	void extractTrianglePair(Dart d) ;
Sylvain Thery's avatar
Sylvain Thery committed
254

Pierre Kraemer's avatar
Pierre Kraemer committed
255
256
257
258
259
260

	/**
	 * Insert a pair of sewed triangles in a vertex by exploding the edges of v1 and v2
	 * v1 and v2 belong to the same vertex
	 * d is a dart of the common edge of the pair of triangles
	 */
Sylvain Thery's avatar
Sylvain Thery committed
261
	void insertTrianglePair(Dart d, Dart v1, Dart v2) ;
Sylvain Thery's avatar
Sylvain Thery committed
262

Pierre Kraemer's avatar
Pierre Kraemer committed
263

264
265
266
267
268
	/**
	 * Unsew opposite edges from the faces around a vertex
	 * \warning Darts may have
	 * @param d a dart from the vertex
	 */
Sylvain Thery's avatar
Sylvain Thery committed
269
	void unsewAroundVertex(Dart d) ;
Sylvain Thery's avatar
Sylvain Thery committed
270

271
272

	/**
Sylvain Thery's avatar
Sylvain Thery committed
273
	 * Unsew the Umbrella aroud a vertex, close the hole and then
274
275
276
	 * create a symetric to construct a polyedron
	 * @param d a dart from the vertex
	 */
Sylvain Thery's avatar
Sylvain Thery committed
277
//	void explodPolyhedron(Dart d);	//TODO modification for new boundary managing method ???
Sylvain Thery's avatar
Sylvain Thery committed
278

279

Pierre Kraemer's avatar
Pierre Kraemer committed
280
281
282
283
284
285
286
287
288
289
	//! Merge two volumes along two faces.
	/*! Works only if the two faces have the same number of edges.
	 *  The faces adjacent to the two given faces are pairwise phi2-linked
	 *  then the 2 faces are deleted.
	 *  If the two faces belong to different surfaces, the surfaces are merged,
	 *  else a handle is created that increases the genus of the surface.
	 *  @param d a dart of the first face
	 *  @param e a dart of the second face
	 *  @return true if the merge has been executed, false otherwise
	 */
Sylvain Thery's avatar
Sylvain Thery committed
290
	virtual bool mergeVolumes(Dart d, Dart e);
Sylvain Thery's avatar
Sylvain Thery committed
291

Pierre Kraemer's avatar
Pierre Kraemer committed
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
	//@}

	/*! @name Topological Queries
	 *  Return or set various topological information
	 *************************************************************************/

	//@{
	//! Test if dart d and e belong to the same oriented vertex
	/*! @param d a dart
	 *  @param e a dart
	 */
	bool sameOrientedVertex(Dart d, Dart e) ;

	//! Test if dart d and e belong to the same vertex
	/*! @param d a dart
	 *  @param e a dart
	 */
	bool sameVertex(Dart d, Dart e) ;

	/**
	 * compute the number of edges of the vertex of d
	 */
	unsigned int vertexDegree(Dart d) ;

	/**
	 * compute the number of faces in the volume of d
	 */
	unsigned int volumeDegree(Dart d);

	/**
	 * tell if the vertex of d is on the boundary of the map
	 */
Sylvain Thery's avatar
Sylvain Thery committed
324
	bool isBoundaryVertex(Dart d) ;		// OK boundary
Pierre Kraemer's avatar
Pierre Kraemer committed
325

Sylvain Thery's avatar
Sylvain Thery committed
326
327
328
329
330
331
	/**
	 * find the dart of vertex that belong to the boundary
	 */
	Dart findBoundaryVertex(Dart d);

	/**
Pierre Kraemer's avatar
Pierre Kraemer committed
332
	 * tell if the edge of d is on the boundary of the map
Sylvain Thery's avatar
Sylvain Thery committed
333
334
335
	 */
	bool isBoundaryEdge(Dart d) ;		// OK boundary

Pierre Kraemer's avatar
Pierre Kraemer committed
336
337
338
339
340
	/**
	 * tell if the face of d is on the boundary of the map
	 */
	bool isBoundaryFace(Dart d) ;

Sylvain Thery's avatar
Sylvain Thery committed
341

Pierre Kraemer's avatar
Pierre Kraemer committed
342
343
344
345
346
	//! Follow the boundary of a surface as if it was a oriented face.
	/*! This operation alternate phi1 and phi2 operator until another
	 *  boudary dart is reached.
	 *  @param d a boundary dart
	 */
Sylvain Thery's avatar
Sylvain Thery committed
347
	Dart nextOnBoundary(Dart d);		// OK boundary
Pierre Kraemer's avatar
Pierre Kraemer committed
348
349
350
351
352
353
354
355

	// TODO a mettre en algo
	/**
	 * check if the mesh is triangular or not
	 * @return a boolean indicating if the mesh is triangular
	 */
	bool isTriangular() ;

Pierre Kraemer's avatar
Pierre Kraemer committed
356
	// TODO a mettre en algo
Pierre Kraemer's avatar
Pierre Kraemer committed
357
358
	/**
	 * Check if map is complete
Pierre Kraemer's avatar
Pierre Kraemer committed
359
	 * Should be executed after import
Pierre Kraemer's avatar
Pierre Kraemer committed
360
361
362
363
364
365
366
367
368
369
370
371
372
	 */
	virtual bool check();
	//@}

	/*! @name Cell Functors
	 *  Apply functors to all darts of a cell
	 *************************************************************************/

	//@{
	//! Apply a functor on every dart of a vertex
	/*! @param d a dart of the vertex
	 *  @param f the functor to apply
	 */
Sylvain Thery's avatar
Sylvain Thery committed
373
	bool foreach_dart_of_vertex(Dart d, FunctorType& f, unsigned int thread=0);
Pierre Kraemer's avatar
Pierre Kraemer committed
374
375
376
377
378

	//! Apply a functor on every dart of a edge
	/*! @param d a dart of the edge
	 *  @param f the functor to apply
	 */
Sylvain Thery's avatar
Sylvain Thery committed
379
	bool foreach_dart_of_edge(Dart d, FunctorType& f, unsigned int thread=0);
Pierre Kraemer's avatar
Pierre Kraemer committed
380
381
382
383
384

	//! Apply a functor on every dart of a volume
	/*! @param d a dart of the volume
	 *  @param f the functor to apply
	 */
Sylvain Thery's avatar
Sylvain Thery committed
385
	bool foreach_dart_of_oriented_volume(Dart d, FunctorType& f, unsigned int thread=0);
Pierre Kraemer's avatar
Pierre Kraemer committed
386

Sylvain Thery's avatar
Sylvain Thery committed
387
	bool foreach_dart_of_volume(Dart d, FunctorType& f, unsigned int thread=0);
Pierre Kraemer's avatar
Pierre Kraemer committed
388
389
390
391
392

	//! Apply a functor on every dart of a connected component
	/*! @param d a dart of the connected component
	 *  @param f the functor to apply
	 */
Sylvain Thery's avatar
Sylvain Thery committed
393
	bool foreach_dart_of_cc(Dart d, FunctorType& f, unsigned int thread=0);
Pierre Kraemer's avatar
Pierre Kraemer committed
394
395
396
397
398
399

	//!
	/*! TODO Ajout a valider
	 * restreint aux complexes simpliciaux
	 * Apply a functor on the all darts in the set of the star from orbit
	 */
Sylvain Thery's avatar
Sylvain Thery committed
400
	bool foreach_dart_of_star(Dart d, unsigned int orbit, FunctorType& f, unsigned int thread=0);
Pierre Kraemer's avatar
Pierre Kraemer committed
401
402
403
404
405
406

	//!
	/*! TODO Ajout a valider
	 * restreint aux complexes simpliciaux
	 * Apply a functor on the all darts in the set of the link from orbit
	 */
Sylvain Thery's avatar
Sylvain Thery committed
407
	bool foreach_dart_of_link(Dart d, unsigned int orbit, FunctorType& f, unsigned int thread=0);
Pierre Kraemer's avatar
Pierre Kraemer committed
408
409

	//@}
Sylvain Thery's avatar
Sylvain Thery committed
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434

	//@{
	//! Close a topological hole (a sequence of connected fixed point of phi2). DO NO USE, only for import algorithm
	/*! \pre dart d MUST be fixed point of phi2 relation
	 *  Add a face to the map that closes the hole.
	 *  The darts of this face are marked with holeMarker.
	 *  @param d a dart of the hole (with phi2(d)==d)
	 *  @return the degree of the created face
	 */
	virtual unsigned int closeHole(Dart d);


	//! Close the map removing topological holes: DO NO USE, only for import algorithm
	/*! Add faces to the map that close every existing hole.
	 *  These faces are marked.
	 *  \warning The embeddings of vertices are not updated
	 */
	void closeMap();
//	void closeMap(DartMarker& marker);

	/**
	 * sew oriented face, DO NO USE, only for import algorithm
	 */
	void sewOrientedFaces(Dart d, Dart e);
	//@}
Pierre Kraemer's avatar
Pierre Kraemer committed
435
436
437
438
439
440
441
};

} // namespace CGoGN

#include "Topology/map/map2.hpp"

#endif