map3.h 14.3 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-2012, 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.unistra.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 51 52
* Contact information: cgogn@unistra.fr                                        *
*                                                                              *
*******************************************************************************/

#ifndef __MAP3_H__
#define __MAP3_H__

#include "Topology/map/map2.h"

namespace CGoGN
{

/*! \brief The class of dual 3-dimensional combinatorial maps:
 *  set of oriented volumes pairwise sewed by an adjacency relation.
 *  A dual 3-map represents close or open oriented 3-manifolds (volume subdivisions).
 *  - A dual 3-map is made of darts linked by the phi1 permutation
 * 	and/or the phi2 and phi3 one-to-one relation.
 *  - In this class darts are interpreted as oriented edges.
 *  - The phi1 relation defines oriented faces (see tMap1)
 *  and faces may have arbitrary size (degenerated faces are accepted).
 *  - The phi2 relation links oriented faces along oriented edges building
 *  oriented surfaces. A close oriented surface define an oriented volume.
 *  - Volume are linked along whole faces with the phi3 relation 
 *  - Faces that have no phi3-link are border faces. If there exists
 *  such edges the maps is open.
 *  - When every face is phi3-linked, the map is close. In this case
 *  some optimizations are enable that speed up the processing of cells.
 *  @param DART the type of dart used in the class
 */
class Map3 : public Map2
{
protected:
53
	AttributeMultiVector<Dart>* m_phi3 ;
Pierre Kraemer's avatar
Pierre Kraemer committed
54

55 56
	void init() ;

Pierre Kraemer's avatar
Pierre Kraemer committed
57 58 59
public:
	typedef Map2 ParentMap;

Pierre Kraemer's avatar
Pierre Kraemer committed
60
	inline static unsigned int ORBIT_IN_PARENT(unsigned int o){ return o+7; }
61 62
	inline static unsigned int ORBIT_IN_PARENT2(unsigned int o) { return o+5; }

Pierre Kraemer's avatar
Pierre Kraemer committed
63 64 65
	static const unsigned int IN_PARENT = 7 ;
	static const unsigned int IN_PARENT2 = 5 ;

66 67 68 69 70 71 72
	static const unsigned int VERTEX_OF_PARENT = VERTEX+7;
	static const unsigned int EDGE_OF_PARENT = EDGE+7;
	static const unsigned int FACE_OF_PARENT = FACE+7;

	static const unsigned int VERTEX_OF_PARENT2 = VERTEX+5;
	static const unsigned int EDGE_OF_PARENT2 = EDGE+5;

Pierre Kraemer's avatar
Pierre Kraemer committed
73 74
	Map3();

75
	virtual std::string mapTypeName() const;
Pierre Kraemer's avatar
Pierre Kraemer committed
76

77
	virtual unsigned int dimension() const;
Pierre Kraemer's avatar
Pierre Kraemer committed
78

79 80
	virtual void clear(bool removeAttrib);

Sylvain Thery's avatar
Sylvain Thery committed
81 82
	virtual void update_topo_shortcuts();

83 84
	virtual void compactTopoRelations(const std::vector<unsigned int>& oldnew);

Pierre Kraemer's avatar
Pierre Kraemer committed
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
	/*! @name Basic Topological Operators
	 * Access and Modification
	 *************************************************************************/

	virtual Dart newDart();

	Dart phi3(Dart d);

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

	Dart alpha0(Dart d);

	Dart alpha1(Dart d);

	Dart alpha2(Dart d);

	Dart alpha_2(Dart d);

protected:
	//! Link dart d with dart e by an involution
106
	/*! @param d,e the darts to link
Pierre Kraemer's avatar
Pierre Kraemer committed
107 108 109 110 111 112
	 *	- Before:	d->d and e->e
	 *	- After:	d->e and e->d
	 */
	void phi3sew(Dart d, Dart e);

	//! Unlink the current dart by an involution
113
	/*! @param d the dart to unlink
Pierre Kraemer's avatar
Pierre Kraemer committed
114 115 116 117 118
	 * - Before:	d->e and e->d
	 * - After:		d->d and e->e
	 */
	void phi3unsew(Dart d);

119
public:
Pierre Kraemer's avatar
Pierre Kraemer committed
120 121 122 123 124
	/*! @name Generator and Deletor
	 *  To generate or delete volumes in a 3-map
	 *************************************************************************/

	//@{
125 126 127
	//! Delete a volume erasing all its darts.
	/*! The phi3-links around the volume are removed
	 *  @param d a dart of the volume
Pierre Kraemer's avatar
Pierre Kraemer committed
128
	 */
129
	virtual void deleteVolume(Dart d);
untereiner's avatar
untereiner committed
130 131 132 133 134 135

	//! Fill a hole with a volume
	/*! \pre Dart d is boundary marked
	 *  @param d a dart of the volume to fill
	 */
	virtual void fillHole(Dart d) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
136 137 138 139 140 141 142
	//@}

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

	//@{
Lionel Untereiner's avatar
Lionel Untereiner committed
143
	//! Split the vertex along a permutation of faces
untereiner's avatar
untereiner committed
144 145 146
	/*! \per Darts d & e MUST belong to the same vertex
	 * 	\per Darts d & e MUST belong to different volumes
	 *  \per Works only on the boundary
Lionel Untereiner's avatar
Lionel Untereiner committed
147
	 *  @param vd a vector of darts
untereiner's avatar
untereiner committed
148
	 */
untereiner's avatar
untereiner committed
149
	virtual Dart splitVertex(std::vector<Dart>& vd);
untereiner's avatar
untereiner committed
150

151 152
	virtual void splitVertex(Dart d, Dart e) { assert("use splitVertex(d,e) only in dimension 2");}

153
	//! Delete the vertex of d
154
	/*! All the volumes around the vertex are merged into one volume
155
	 *  @param d a dart of the vertex to delete
156
	 *  @return a Dart of the resulting volume
Pierre Kraemer's avatar
Pierre Kraemer committed
157
	 */
158
	virtual Dart deleteVertex(Dart d);
Pierre Kraemer's avatar
Pierre Kraemer committed
159

Pierre Kraemer's avatar
Pierre Kraemer committed
160
	//! Cut the edge of d (all darts around edge orbit are cut)
161
	/*! @param d a dart of the edge to cut
Pierre Kraemer's avatar
Pierre Kraemer committed
162
	 *  @return a dart of the new vertex
Pierre Kraemer's avatar
Pierre Kraemer committed
163
	 */
David Cazier's avatar
David Cazier committed
164
	virtual Dart cutEdge(Dart d);
Pierre Kraemer's avatar
Pierre Kraemer committed
165

Pierre Kraemer's avatar
Pierre Kraemer committed
166
	//! Uncut the edge of d (all darts around edge orbit are uncut)
167
	/*! @param d a dart of the edge to uncut
Pierre Kraemer's avatar
Pierre Kraemer committed
168
	 */
169
	virtual bool uncutEdge(Dart d);
Pierre Kraemer's avatar
Pierre Kraemer committed
170

Sylvain Thery's avatar
Sylvain Thery committed
171 172 173 174 175 176

	/**
	 * Precondition for deleting edge
	 */
	bool deleteEdgePreCond(Dart d);

177 178 179 180
	//! Delete the edge of d
	/*! All the volumes around the edge are merged into one volume
	 *  @param d a dart of the edge to delete
	 *  @return a Dart of the resulting volume
untereiner's avatar
untereiner committed
181 182 183 184 185 186 187 188 189 190 191
	 */
	virtual Dart deleteEdge(Dart d);

	//! Collapse an edge (that is deleted) possibly merging its vertices
	/*! \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
	 *  @return a dart of the resulting vertex
	 */
	virtual Dart collapseEdge(Dart d, bool delDegenerateVolumes = true);

192 193 194 195 196 197
	//! Delete a face if and only if it has one or two edges
	/*! If the face is sewed to two distinct adjacent faces,
	 *  then those two faces are sewed
	 *  @param d a dart of the face
	 *  @return true if the collapse has been executed, false otherwise
	 */
Sylvain Thery's avatar
Sylvain Thery committed
198 199 200 201 202 203 204 205
//	virtual bool collapseDegeneratedFace(Dart d);

	//! Split Face Pre-condition
	/*!
	 *  @param d dart of first vertex
	 *  @param e dart of second vertex
	 */
	bool splitFacePreCond(Dart d, Dart e);
206

Pierre Kraemer's avatar
Pierre Kraemer committed
207 208 209 210 211 212 213
	//! Split a face inserting an edge between two vertices
	/*! \pre Dart d and e should belong to the same face and be distinct
	 *  @param d dart of first vertex
	 *  @param e dart of second vertex
	 */
	virtual void splitFace(Dart d, Dart e);

Thomas's avatar
Thomas committed
214 215 216 217 218 219 220 221
	//! Merge the two faces incident to the edge of d.
	/*! Works only for edges of degree 2.
	 *  \warning Darts of the edge of 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);

222 223 224 225 226 227 228
	//! Collapse a face (that is deleted) possibly merging its vertices
	/*! \warning
	 *  @param d a dart in the deleted face
	 *  @return a dart of the resulting vertex
	 */
	virtual Dart collapseFace(Dart d, bool delDegenerateVolumes = true);

229 230 231 232 233 234
	//! Delete a volume if and only if it has a face with degree < 3 or only 3 vertices
	/*! If the volume is sewed to two distinct adjacent volumes and if the face degree
	 *  of the two adjacent volumes is equal then those two volumes are sewed
	 *  @param d a dart of the face
	 *  @return true if the collapse has been executed, false otherwise
	 */
235
	bool collapseDegeneretedVolume(Dart d);
236

Sylvain Thery's avatar
Sylvain Thery committed
237 238 239 240
	//!! sewVolumes Pre-condition
	bool sewVolumesPreCond(Dart d, Dart e);


241
	//! Sew two oriented volumes along their faces. 
Pierre Kraemer's avatar
Pierre Kraemer committed
242
	/*! The oriented faces should not be phi3-linked and have the same degree
243 244
	 *  @param d a dart of the first volume
	 *  @param e a dart of the second volume
245
	 *  @param withBoundary: if false, volumes must have phi3 fixed points (only for construction: import/primitives)
Pierre Kraemer's avatar
Pierre Kraemer committed
246
	 */
247
	virtual void sewVolumes(Dart d, Dart e, bool withBoundary = true);
Pierre Kraemer's avatar
Pierre Kraemer committed
248

Sylvain Thery's avatar
Sylvain Thery committed
249 250 251
	//! Unsew volumes pre-condition
	bool unsewVolumesPreCond(Dart d);

252 253
	//! Unsew two oriented volumes along their faces.
	/*! @param d a dart of one volume
Pierre Kraemer's avatar
Pierre Kraemer committed
254
	 */
255
	virtual void unsewVolumes(Dart d);
Pierre Kraemer's avatar
Pierre Kraemer committed
256

257
	//! Merge two volumes along their common oriented face
258
	/*! @param d a dart of common face
Pierre Kraemer's avatar
Pierre Kraemer committed
259
	 */
260
	virtual bool mergeVolumes(Dart d);
Pierre Kraemer's avatar
Pierre Kraemer committed
261

262 263 264
	virtual bool mergeVolumes(Dart d, Dart e) { assert("use mergeVolumes(d,e) only in dimension 2");return false;}


untereiner's avatar
untereiner committed
265 266 267 268
	//! Split a volume into two volumes along a edge path
	/*! @param vd a vector of darts
	 */
	virtual void splitVolume(std::vector<Dart>& vd);
269 270 271 272 273 274 275

	//! Collapse a volume (that is deleted) possibly merging its vertices
	/*! \warning
	 *  @param d a dart in the deleted volume
	 *  @return a dart of the resulting vertex
	 */
	virtual Dart collapseVolume(Dart d, bool delDegenerateVolumes = true);
276
	//@}
Pierre Kraemer's avatar
Pierre Kraemer committed
277

278 279 280 281 282 283 284 285 286 287 288
	/*! @name Topological Queries
	 *  Return or set various topological information
	 *************************************************************************/

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

289 290 291 292 293
	//! Compute the number of edges of the vertex of d
	/*! @param d a dart
	 */
	unsigned int vertexDegree(Dart d) ;

294 295 296 297 298
	//! Compute the number of edges of the vertex of d on the boundary
	/*!	@param d a dart
	 */
	unsigned int vertexDegreeOnBoundary(Dart d);

299 300 301
	//! Tell if the vertex of d is on the boundary
	/*! @param d a dart
	 */
Pierre Kraemer's avatar
Pierre Kraemer committed
302
	bool isBoundaryVertex(Dart d) ;
303

untereiner's avatar
untereiner committed
304 305 306 307 308 309
	//! Find the dart of vertex that belong to the boundary
	/*! return NIL if the vertex is not on the boundary
	 *  @param d a dart
	 */
	Dart findBoundaryFaceOfVertex(Dart d) ;

310 311 312 313 314 315 316 317 318 319 320 321
	//! Test if dart d and e belong to the same oriented edge
	/*! @param d a dart
	 *  @param e a dart
	 */
	bool sameOrientedEdge(Dart d, Dart e) ;

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

322 323
	//! Compute the number of volumes around the edge of d
	/*! @param d a dart
Pierre Kraemer's avatar
Pierre Kraemer committed
324
	 */
Pierre Kraemer's avatar
Pierre Kraemer committed
325
	unsigned int edgeDegree(Dart d) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
326

untereiner's avatar
untereiner committed
327 328
	//! Tell if the edge of d is on the boundary of the map
	/*! @param d a dart
untereiner's avatar
bla  
untereiner committed
329 330 331
	 */
	bool isBoundaryEdge(Dart d) ;

untereiner's avatar
untereiner committed
332 333 334
	//! Find the dart of edge that belong to the boundary
	/*! return NIL if the edge is not on the boundary
	 *  @param d a dart
untereiner's avatar
untereiner committed
335
	 */
Pierre Kraemer's avatar
Pierre Kraemer committed
336
	Dart findBoundaryFaceOfEdge(Dart d) ;
untereiner's avatar
untereiner committed
337

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

344 345
	//! Test if the face is on the boundary
	/*! @param d a dart from the face
Pierre Kraemer's avatar
Pierre Kraemer committed
346
	 */
Pierre Kraemer's avatar
Pierre Kraemer committed
347
	bool isBoundaryFace(Dart d) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
348

349 350
	//! Tell if a face of the volume is on the boundary
	/*  @param d a dart
351
	 */
Pierre Kraemer's avatar
Pierre Kraemer committed
352
	bool isBoundaryVolume(Dart d) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
353

untereiner's avatar
untereiner committed
354 355 356 357 358
	//! Tell if an edge of the volume is on the boundary
	/*	@param d a dart
	 */
	bool hasBoundaryEdge(Dart d);

untereiner's avatar
untereiner committed
359 360 361
	//! Check the map completeness
	/*! Test if phi3 and phi2 ares involutions and if phi1 is a permutation
	 */
Pierre Kraemer's avatar
Pierre Kraemer committed
362
	virtual bool check() ;
Pierre Kraemer's avatar
Pierre Kraemer committed
363 364 365 366 367 368 369
	//@}

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

	//@{
370 371 372 373
	//! Apply a functor on each dart of a vertex
	/*! @param d a dart of the vertex
	 *  @param fonct the functor
	 */
untereiner's avatar
bla  
untereiner committed
374
	bool foreach_dart_of_vertex(Dart d, FunctorType& f, unsigned int thread = 0);
Pierre Kraemer's avatar
Pierre Kraemer committed
375

376 377 378 379
	//! Apply a functor on each dart of an edge
	/*! @param d a dart of the oriented edge
	 *  @param fonct the functor
	 */
untereiner's avatar
bla  
untereiner committed
380
	bool foreach_dart_of_edge(Dart d, FunctorType& f, unsigned int thread = 0);
Pierre Kraemer's avatar
Pierre Kraemer committed
381

382
	//! Apply a functor on each dart of a face
383 384 385
	/*! @param d a dart of the oriented face
	 *  @param fonct the functor
	 */
untereiner's avatar
bla  
untereiner committed
386
	bool foreach_dart_of_face(Dart d, FunctorType& f, unsigned int thread = 0);
Pierre Kraemer's avatar
Pierre Kraemer committed
387

388 389 390 391
	//! Apply a functor on each dart of a face
	/*! @param d a dart of the oriented face
	 *  @param fonct the functor
	 */
392
	bool foreach_dart_of_volume(Dart d, FunctorType& f, unsigned int thread = 0);
393

394 395 396 397
	//! Apply a functor on each dart of a cc
	/*! @param d a dart of the cc
	 *  @param fonct the functor
	 */
untereiner's avatar
bla  
untereiner committed
398
	bool foreach_dart_of_cc(Dart d, FunctorType& f, unsigned int thread = 0);
399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418


	//! Apply a functor on each dart of a vertex
	/*! @param d a dart of the vertex
	 *  @param fonct the functor
	 */
	bool foreach_dart_of_vertex2(Dart d, FunctorType& f, unsigned int thread = 0);

	//! Apply a functor on each dart of an edge
	/*! @param d a dart of the oriented edge
	 *  @param fonct the functor
	 */
	bool foreach_dart_of_edge2(Dart d, FunctorType& f, unsigned int thread = 0);

	//! Apply a functor on each dart of an oriented face
	/*! @param d a dart of the oriented face
	 *  @param fonct the functor
	 */
	bool foreach_dart_of_face2(Dart d, FunctorType& f, unsigned int thread = 0);

Pierre Kraemer's avatar
Pierre Kraemer committed
419 420
	//@}

untereiner's avatar
untereiner committed
421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437
	/*! @name Close map after import or creation
	 *  These functions must be used with care, generally only by import algorithms
	 *************************************************************************/

	//@{
	//! Close a topological hole (a sequence of connected fixed point of phi3). DO NOT USE, only for import/creation algorithm
	/*! \pre dart d MUST be fixed point of phi3 relation
	 *  Add a volume to the map that closes the hole.
	 *  @param d a dart of the hole (with phi3(d)==d)
	 *  @param forboundary tag the created face as boundary (default is true)
	 *  @return the degree of the created volume
	 */
	virtual unsigned int closeHole(Dart d, bool forboundary = true);

	//! Close the map removing topological holes: DO NOT USE, only for import/creation algorithm
	/*! Add volumes to the map that close every existing hole.
	 *  These faces are marked as boundary.
438
	 *  @return the number of closed holes
untereiner's avatar
untereiner committed
439
	 */
440
	unsigned int closeMap();
untereiner's avatar
untereiner committed
441
	//@}
Pierre Kraemer's avatar
Pierre Kraemer committed
442 443 444 445 446 447 448
};

} // namespace CGoGN

#include "Topology/map/map3.hpp"

#endif