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);

98
public:
Pierre Kraemer's avatar
Pierre Kraemer committed
99 100 101 102 103
	/*! @name Generator and Deletor
	 *  To generate or delete faces in a 2-map
	 *************************************************************************/

	//@{
104 105
	//! Create an new face of nbEdges
	/*! @param nbEdges the number of edges
106
	 *  @param withBoudary create the face and its boundary (default true)
107 108
	 *  @return return a dart of the face
	 */
109
	virtual Dart newFace(unsigned int nbEdges, bool withBoundary = true) ;
110

111 112
	//! Delete the face of d
	/*! @param d a dart of the face
113
	 */
Pierre Kraemer's avatar
Pierre Kraemer committed
114
	virtual void deleteFace(Dart d) ;
115

untereiner's avatar
untereiner committed
116 117 118 119 120
	//! Delete a connected component of the map
	/*! @param d a dart of the connected component
	 */
	virtual void deleteCC(Dart d) ;

121 122 123 124 125
	//! Fill a hole with a face
	/*! \pre Dart d is boundary marked
	 *  @param d a dart of the face to fill
	 */
	virtual void fillHole(Dart d) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
126 127 128 129 130 131 132 133 134 135 136 137 138 139
	//@}

	/*! @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
	 */
	virtual void splitVertex(Dart d, Dart e);

Pierre Kraemer's avatar
Pierre Kraemer committed
140
	//! Delete the vertex of d (works only for internal vertices)
Pierre Kraemer's avatar
Pierre Kraemer committed
141 142
	/*! Does not create a hole -> all the faces
	 * 	around the vertex are merged into one face
Pierre Kraemer's avatar
Pierre Kraemer committed
143
	 *  @param d a dart of the vertex to delete
144
	 *  @return a dart of the resulting face (NIL if the deletion has not been executed)
Pierre Kraemer's avatar
Pierre Kraemer committed
145
	 */
146
	virtual Dart deleteVertex(Dart d);
Pierre Kraemer's avatar
Pierre Kraemer committed
147

Pierre Kraemer's avatar
Pierre Kraemer committed
148
	//! Cut the edge of d by inserting a new vertex
Pierre Kraemer's avatar
Pierre Kraemer committed
149
	/*! @param d a dart of the edge to cut
Pierre Kraemer's avatar
Pierre Kraemer committed
150
	 *  @return a dart of the new vertex
Pierre Kraemer's avatar
Pierre Kraemer committed
151
	 */
David Cazier's avatar
David Cazier committed
152
	virtual Dart cutEdge(Dart d);
Pierre Kraemer's avatar
Pierre Kraemer committed
153

Pierre Kraemer's avatar
Pierre Kraemer committed
154
	//! Undo the cut of the edge of d
Pierre Kraemer's avatar
Pierre Kraemer committed
155
	/*! @param d a dart of the edge to uncut
156
	 *  @return true if the uncut has been executed, false otherwise
Pierre Kraemer's avatar
Pierre Kraemer committed
157
	 */
Pierre Kraemer's avatar
Pierre Kraemer committed
158
	virtual bool uncutEdge(Dart d);
Pierre Kraemer's avatar
Pierre Kraemer committed
159

Pierre Kraemer's avatar
Pierre Kraemer committed
160 161
	//! Collapse an edge (that is deleted) possibly merging its vertices
	/*! If delDegenerateFaces is true, the method checks that no degenerate
162
	 *  faces are built (faces with less than 3 edges). If it occurs the faces
Pierre Kraemer's avatar
Pierre Kraemer committed
163 164 165 166 167
	 *  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)
168
	 *  @return a dart of the resulting vertex
Pierre Kraemer's avatar
Pierre Kraemer committed
169
	 */
170
	virtual Dart collapseEdge(Dart d, bool delDegenerateFaces = true);
Pierre Kraemer's avatar
Pierre Kraemer committed
171 172

	/**
173
	 * Flip the edge of d (rotation in phi1 order)
174
	 * WARNING : Works only for non-border edges
Pierre Kraemer's avatar
Pierre Kraemer committed
175 176 177 178 179 180
	 * @param d a dart of the edge to flip
	 * @return true if the flip has been executed, false otherwise
	 */
	virtual bool flipEdge(Dart d);

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

188 189 190 191 192 193 194 195 196 197 198 199 200 201
//	//! 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
//	 */
//	virtual void insertEdgeInVertex(Dart d, Dart e);
//
//	//! Remove an edge from a vertex orbit
//	/*! \pre Dart d must be phi2 sewed
//	 *  @param d the dart of the edge to remove from the vertex
//	 * @return true if the removal has been executed, false otherwise
//	 */
//	virtual bool removeEdgeFromVertex(Dart d);
202

Pierre Kraemer's avatar
Pierre Kraemer committed
203
	//! Sew two oriented faces along oriented edges
Pierre Kraemer's avatar
Pierre Kraemer committed
204
	/*! \pre Edges of darts d & e MUST be boundary edges
Pierre Kraemer's avatar
Pierre Kraemer committed
205 206
	 *  @param d a dart of the first face
	 *  @param e a dart of the second face
207
	 *  @param withBoundary: if false, faces must have phi2 fixed points (only for construction: import/primitives)
Pierre Kraemer's avatar
Pierre Kraemer committed
208
	 */
209
	virtual void sewFaces(Dart d, Dart e, bool withBoundary = true);
Pierre Kraemer's avatar
Pierre Kraemer committed
210

211 212 213
	//! Unsew two oriented faces
	/*! \pre Edge of dart d MUST NOT be a boundary edge
	 *  @param d a dart of a face
Pierre Kraemer's avatar
Pierre Kraemer committed
214 215
	 */
	virtual void unsewFaces(Dart d);
Sylvain Thery's avatar
Sylvain Thery committed
216

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

	//! 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.
233 234
	/*! Works only for non-boundary edges.
	 *  \warning Darts of the edge of d no longer exist after the call
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
	 *  @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
	 */
	void extractTrianglePair(Dart d) ;

	/**
	 * 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
	 */
	void insertTrianglePair(Dart d, Dart v1, Dart v2) ;

253
	/**
254
	 * Unsew the faces of the umbrella of the vertex of d
255 256
	 * @param d a dart from the vertex
	 */
Pierre Kraemer's avatar
Pierre Kraemer committed
257
	void unsewAroundVertex(Dart d) ;
Sylvain Thery's avatar
Sylvain Thery committed
258

Pierre Kraemer's avatar
Pierre Kraemer committed
259 260
	//! Merge two volumes along two faces.
	/*! Works only if the two faces have the same number of edges.
261
	 *  The faces adjacent to the two given faces are pairwise sewed
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
	 *  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
	 */
	virtual bool mergeVolumes(Dart d, Dart e);
	//@}

	/*! @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) ;

283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298
	//! 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
	/*! @param d a dart
	 */
	unsigned int vertexDegree(Dart d) ;

	//! Tell if the vertex of d is on the boundary of the map
	/*! @param d a dart
	 */
	bool isBoundaryVertex(Dart d) ;

Pierre Kraemer's avatar
Pierre Kraemer committed
299
	/**
Pierre Kraemer's avatar
Pierre Kraemer committed
300 301
	 * find the dart of vertex that belong to the boundary
	 * return NIL if the vertex is not on the boundary
Pierre Kraemer's avatar
Pierre Kraemer committed
302
	 */
303
	Dart findBoundaryEdgeOfVertex(Dart d);
Pierre Kraemer's avatar
Pierre Kraemer committed
304

Pierre Kraemer's avatar
Pierre Kraemer committed
305 306 307
	//! Test if dart d and e belong to the same edge
	/*! @param d a dart
	 *  @param e a dart
308
	 */
Pierre Kraemer's avatar
Pierre Kraemer committed
309
	bool sameEdge(Dart d, Dart e) ;
310

Pierre Kraemer's avatar
Pierre Kraemer committed
311
	/**
Pierre Kraemer's avatar
Pierre Kraemer committed
312
	 * tell if the edge of d is on the boundary of the map
Pierre Kraemer's avatar
Pierre Kraemer committed
313
	 */
Pierre Kraemer's avatar
Pierre Kraemer committed
314
	bool isBoundaryEdge(Dart d) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
315

untereiner's avatar
bla  
untereiner committed
316
	//! Test if dart d and e belong to the same oriented face
untereiner's avatar
untereiner committed
317 318 319 320 321
	/*! @param d a dart
	 *  @param e a dart
	 */
	bool sameOrientedFace(Dart d, Dart e);

Pierre Kraemer's avatar
Pierre Kraemer committed
322 323 324 325 326
	//! Test if dart d and e belong to the same face
	/*! @param d a dart
	 *  @param e a dart
	 */
	bool sameFace(Dart d, Dart e) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
327

328
	/**
Pierre Kraemer's avatar
Pierre Kraemer committed
329
	 * compute the number of edges of the face of d
330
	 */
Pierre Kraemer's avatar
Pierre Kraemer committed
331
	unsigned int faceDegree(Dart d) ;
Sylvain Thery's avatar
Sylvain Thery committed
332

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

	//! Test if dart d and e belong to the same oriented volume
Pierre Kraemer's avatar
Pierre Kraemer committed
339 340 341
	/*! @param d a dart
	 *  @param e a dart
	 */
342
	bool sameOrientedVolume(Dart d, Dart e) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
343

344
	//! Test if dart d and e belong to the same volume
345
	/*! @param d a dart
346
	 *  @param e a dart
Pierre Kraemer's avatar
Pierre Kraemer committed
347
	 */
348
	bool sameVolume(Dart d, Dart e) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
349

350 351
	//! Compute the number of faces in the volume of d
	/*! @param d a dart
Pierre Kraemer's avatar
Pierre Kraemer committed
352 353 354 355 356 357 358 359 360 361
	 */
	unsigned int volumeDegree(Dart d);

	// 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
362
	// TODO a mettre en algo
Pierre Kraemer's avatar
Pierre Kraemer committed
363 364
	/**
	 * Check if map is complete
Pierre Kraemer's avatar
Pierre Kraemer committed
365
	 * Should be executed after import
Pierre Kraemer's avatar
Pierre Kraemer committed
366 367
	 */
	virtual bool check();
untereiner's avatar
untereiner committed
368 369 370 371 372

	/**
	 * Check if a serie of darts is an oriented simple close path
	 */
	virtual bool checkSimpleOrientedPath(std::vector<Dart>& vd);
Pierre Kraemer's avatar
Pierre Kraemer committed
373 374 375 376 377 378
	//@}

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

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

untereiner's avatar
untereiner committed
386
	//! Apply a functor on every dart of an edge
Pierre Kraemer's avatar
Pierre Kraemer committed
387 388 389
	/*! @param d a dart of the edge
	 *  @param f the functor to apply
	 */
Pierre Kraemer's avatar
Pierre Kraemer committed
390
	bool foreach_dart_of_edge(Dart d, FunctorType& f, unsigned int thread = 0);
Pierre Kraemer's avatar
Pierre Kraemer committed
391

untereiner's avatar
untereiner committed
392
	//! Apply a functor on every dart of an oriented volume
Pierre Kraemer's avatar
Pierre Kraemer committed
393 394 395
	/*! @param d a dart of the volume
	 *  @param f the functor to apply
	 */
Pierre Kraemer's avatar
Pierre Kraemer committed
396
	bool foreach_dart_of_oriented_volume(Dart d, FunctorType& f, unsigned int thread = 0);
Pierre Kraemer's avatar
Pierre Kraemer committed
397

398 399 400 401
	//! Apply a functor on every dart of a volume
	/*! @param d a dart of the volume
	 *  @param f the functor to apply
	 */
Pierre Kraemer's avatar
Pierre Kraemer committed
402
	bool foreach_dart_of_volume(Dart d, FunctorType& f, unsigned int thread = 0);
Pierre Kraemer's avatar
Pierre Kraemer committed
403 404 405 406 407

	//! Apply a functor on every dart of a connected component
	/*! @param d a dart of the connected component
	 *  @param f the functor to apply
	 */
Pierre Kraemer's avatar
Pierre Kraemer committed
408
	bool foreach_dart_of_cc(Dart d, FunctorType& f, unsigned int thread = 0);
Pierre Kraemer's avatar
Pierre Kraemer committed
409
	//@}
Sylvain Thery's avatar
Sylvain Thery committed
410

Pierre Kraemer's avatar
Pierre Kraemer committed
411 412 413 414
	/*! @name Close map after import or creation
	 *  These functions must be used with care, generally only by import algorithms
	 *************************************************************************/

Sylvain Thery's avatar
Sylvain Thery committed
415
	//@{
416
	//! Close a topological hole (a sequence of connected fixed point of phi2). DO NOT USE, only for import/creation algorithm
Sylvain Thery's avatar
Sylvain Thery committed
417 418 419
	/*! \pre dart d MUST be fixed point of phi2 relation
	 *  Add a face to the map that closes the hole.
	 *  @param d a dart of the hole (with phi2(d)==d)
420
	 *  @param forboundary tag the created face as boundary (default is true)
Sylvain Thery's avatar
Sylvain Thery committed
421 422
	 *  @return the degree of the created face
	 */
423
	virtual unsigned int closeHole(Dart d, bool forboundary = true);
Sylvain Thery's avatar
Sylvain Thery committed
424

425
	//! Close the map removing topological holes: DO NOT USE, only for import/creation algorithm
Sylvain Thery's avatar
Sylvain Thery committed
426
	/*! Add faces to the map that close every existing hole.
427
	 *  These faces are marked as boundary.
Sylvain Thery's avatar
Sylvain Thery committed
428 429
	 */
	void closeMap();
Pierre Kraemer's avatar
Pierre Kraemer committed
430 431 432 433 434 435 436 437
	//@}
};

} // namespace CGoGN

#include "Topology/map/map2.hpp"

#endif