gmap3.h 12 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
* Contact information: cgogn@unistra.fr                                        *
*                                                                              *
*******************************************************************************/

#ifndef __GMAP3_H__
#define __GMAP3_H__

#include "Topology/gmap/gmap2.h"

namespace CGoGN
{

/**
Pierre Kraemer's avatar
Pierre Kraemer committed
34
* The class of 3-GMap
Pierre Kraemer's avatar
Pierre Kraemer committed
35 36 37 38
*/
class GMap3 : public GMap2
{
protected:
39
	AttributeMultiVector<Dart>* m_beta3 ;
Pierre Kraemer's avatar
Pierre Kraemer committed
40

41 42
	void init() ;

Pierre Kraemer's avatar
Pierre Kraemer committed
43
public:
Thomas's avatar
Thomas committed
44 45
	typedef GMap2 ParentMap;

Pierre Kraemer's avatar
Pierre Kraemer committed
46
	inline static unsigned int ORBIT_IN_PARENT(unsigned int o) { return o+7; }
47 48
	inline static unsigned int ORBIT_IN_PARENT2(unsigned int o) { return o+5; }

Pierre Kraemer's avatar
Pierre Kraemer committed
49 50 51
	static const unsigned int IN_PARENT = 7 ;
	static const unsigned int IN_PARENT2 = 5 ;

52 53 54 55 56 57 58
	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;

59 60
	static const unsigned int DIMENSION = 3 ;

Pierre Kraemer's avatar
Pierre Kraemer committed
61 62
	GMap3();

63
	virtual std::string mapTypeName() const;
Pierre Kraemer's avatar
Pierre Kraemer committed
64

65
	virtual unsigned int dimension() const;
Pierre Kraemer's avatar
Pierre Kraemer committed
66

67 68
	virtual void clear(bool removeAttrib);

Sylvain Thery's avatar
Sylvain Thery committed
69 70
	virtual void update_topo_shortcuts();

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

Pierre Kraemer's avatar
Pierre Kraemer committed
73 74 75 76 77 78
	/*! @name Basic Topological Operators
	 * Access and Modification
	 *************************************************************************/

	virtual Dart newDart();

Sylvain Thery's avatar
Sylvain Thery committed
79
	Dart beta3(Dart d) const;
Pierre Kraemer's avatar
Pierre Kraemer committed
80 81

	template <int N>
Sylvain Thery's avatar
Sylvain Thery committed
82
	Dart beta(const Dart d) const;
Pierre Kraemer's avatar
Pierre Kraemer committed
83

Sylvain Thery's avatar
Sylvain Thery committed
84
	Dart phi3(Dart d) const;
Pierre Kraemer's avatar
Pierre Kraemer committed
85 86

	template <int N>
Sylvain Thery's avatar
Sylvain Thery committed
87
	Dart phi(const Dart d) const;
Pierre Kraemer's avatar
Pierre Kraemer committed
88

Sylvain Thery's avatar
Sylvain Thery committed
89
	Dart alpha0(Dart d) const;
Pierre Kraemer's avatar
Pierre Kraemer committed
90

Sylvain Thery's avatar
Sylvain Thery committed
91
	Dart alpha1(Dart d) const;
Pierre Kraemer's avatar
Pierre Kraemer committed
92

Sylvain Thery's avatar
Sylvain Thery committed
93
	Dart alpha2(Dart d) const;
Pierre Kraemer's avatar
Pierre Kraemer committed
94

Sylvain Thery's avatar
Sylvain Thery committed
95
	Dart alpha_2(Dart d) const;
Pierre Kraemer's avatar
Pierre Kraemer committed
96

Pierre Kraemer's avatar
Pierre Kraemer committed
97
protected:
Pierre Kraemer's avatar
Pierre Kraemer committed
98 99 100 101
	void beta3sew(Dart d, Dart e);

	void beta3unsew(Dart d);

Pierre Kraemer's avatar
Pierre Kraemer committed
102
public:
103
	/*! @name Generator and Deletor
Pierre Kraemer's avatar
Pierre Kraemer committed
104
	 *  To generate or delete volumes in a 3-G-map
105
	 *************************************************************************/
Pierre Kraemer's avatar
Pierre Kraemer committed
106 107

	//@{
108 109 110
	//! 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
111
	 */
112
	void deleteVolume(Dart d);
Pierre Kraemer's avatar
Pierre Kraemer committed
113 114 115 116 117 118

	//! 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
119 120 121
	//@}

	/*! @name Topological Operators
Pierre Kraemer's avatar
Pierre Kraemer committed
122
	 *  Topological operations on 3-G-maps
Pierre Kraemer's avatar
Pierre Kraemer committed
123 124 125
	 *************************************************************************/

	//@{
Pierre Kraemer's avatar
Pierre Kraemer committed
126
	//! Delete the vertex of d
127
	/*! All the volumes around the vertex are merged into one volume
Pierre Kraemer's avatar
Pierre Kraemer committed
128
	 *  @param d a dart of the vertex to delete
129
	 *  @return a Dart of the resulting volume
Pierre Kraemer's avatar
Pierre Kraemer committed
130 131 132 133
	 */
	virtual Dart deleteVertex(Dart d);

	//! Cut the edge of d (all darts around edge orbit are cut)
134
	/*! @param d a dart of the edge to cut
135
	 *  @return a dart of the new vertex
Pierre Kraemer's avatar
Pierre Kraemer committed
136
	 */
137
	virtual Dart cutEdge(Dart d);
138

Pierre Kraemer's avatar
Pierre Kraemer committed
139 140 141 142 143
	//! Uncut the edge of d (all darts around edge orbit are uncut)
	/*! @param d a dart of the edge to uncut
	 */
	virtual bool uncutEdge(Dart d);

144 145 146 147 148
	/**
	 * Precondition for deleting edge
	 */
	bool deleteEdgePreCond(Dart d);

149 150 151 152 153 154 155
	//! 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
	 */
	virtual Dart deleteEdge(Dart d);

156 157 158 159 160
	/**
	 * Precondition for splitting face
	 */
	bool splitFacePreCond(Dart d, Dart e);

161 162 163 164 165 166
	//! 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);
Pierre Kraemer's avatar
Pierre Kraemer committed
167

168
	//! Sew two oriented volumes along their faces.
Pierre Kraemer's avatar
Pierre Kraemer committed
169
	/*! The oriented faces should not be beta3-linked and have the same degree
170 171
	 *  @param d a dart of the first volume
	 *  @param e a dart of the second volume
Pierre Kraemer's avatar
Pierre Kraemer committed
172
	 *  @param withBoundary: if false, volumes must have beta3 fixed points (only for construction: import/primitives)
Thomas's avatar
Thomas committed
173
	 */
Pierre Kraemer's avatar
Pierre Kraemer committed
174
	virtual void sewVolumes(Dart d, Dart e, bool withBoundary = true);
Thomas's avatar
Thomas committed
175

176 177
	//! unsew two oriented volumes along their faces.
	/*! @param d a dart of one volume
Thomas's avatar
Thomas committed
178
	 */
Pierre Kraemer's avatar
Pierre Kraemer committed
179
	virtual void unsewVolumes(Dart d);
Thomas's avatar
Thomas committed
180

181 182
	//! merge to volume sewed by one face
	/*! @param d a dart of common face
Thomas's avatar
Thomas committed
183
	 */
Pierre Kraemer's avatar
Pierre Kraemer committed
184
	virtual bool mergeVolumes(Dart d);
185

186
	virtual bool mergeVolumes(Dart /*d*/, Dart /*e*/) { assert("use mergeVolumes(d,e) only in dimension 2");return false;}
187 188


Pierre Kraemer's avatar
Pierre Kraemer committed
189 190 191 192 193
	//! Split a volume into two volumes along a edge path
	/*! @param vd a vector of darts
	 */
	virtual void splitVolume(std::vector<Dart>& vd);
	//@}
Thomas's avatar
Thomas committed
194

195 196 197 198 199 200 201 202 203
	/*! @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
	 */
Sylvain Thery's avatar
Sylvain Thery committed
204
	bool sameOrientedVertex(Dart d, Dart e) const;
205 206 207 208 209

	//! Test if dart d and e belong to the same vertex
	/*! @param d a dart
	 *  @param e a dart
	 */
Sylvain Thery's avatar
Sylvain Thery committed
210
	bool sameVertex(Dart d, Dart e) const;
211

212 213 214
	//! Compute the number of edges of the vertex of d
	/*! @param d a dart
	 */
Sylvain Thery's avatar
Sylvain Thery committed
215
	unsigned int vertexDegree(Dart d) const;
216

217 218 219 220 221 222

	//! Check number of edges of the vertex of d with given parameter
	/*! @param d a dart
	 *	@param vd degree to compare with
	 *  @return  negative/null/positive if vertex degree is less/equal/greater than given degree
	 */
Sylvain Thery's avatar
Sylvain Thery committed
223
	int checkVertexDegree(Dart d, unsigned int vd) const;
224 225


226 227 228
	//! Tell if the vertex of d is on the boundary
	/*! @param d a dart
	 */
Sylvain Thery's avatar
Sylvain Thery committed
229
	virtual bool isBoundaryVertex(Dart d) const;
230

231 232 233 234
	//! Test if dart d and e belong to the same oriented edge
	/*! @param d a dart
	 *  @param e a dart
	 */
Sylvain Thery's avatar
Sylvain Thery committed
235
	bool sameOrientedEdge(Dart d, Dart e) const;
236 237 238 239 240

	//! Test if dart d and e belong to the same edge
	/*! @param d a dart
	 *  @param e a dart
	 */
Sylvain Thery's avatar
Sylvain Thery committed
241
	bool sameEdge(Dart d, Dart e) const;
242

243 244 245
	//! Compute the number of volumes around the edge of d
	/*! @param d a dart
	 */
Sylvain Thery's avatar
Sylvain Thery committed
246
	unsigned int edgeDegree(Dart d) const;
Pierre Kraemer's avatar
Pierre Kraemer committed
247 248 249 250

	/**
	 * tell if the edge of d is on the boundary of the map
	 */
Sylvain Thery's avatar
Sylvain Thery committed
251
	bool isBoundaryEdge(Dart d) const;
Pierre Kraemer's avatar
Pierre Kraemer committed
252 253 254 255 256

	/**
	 * find the dart of edge that belong to the boundary
	 * return NIL if the edge is not on the boundary
	 */
Sylvain Thery's avatar
Sylvain Thery committed
257
	Dart findBoundaryFaceOfEdge(Dart d) const;
258

259 260 261 262
	//!Test if dart d and e belong to the same oriented face
	/*! @param d a dart
	 *  @param e a dart
	 */
Sylvain Thery's avatar
Sylvain Thery committed
263
	bool sameOrientedFace(Dart d, Dart e) const;
264 265 266 267 268

	//!Test if dart d and e belong to the same oriented face
	/*! @param d a dart
	 *  @param e a dart
	 */
Sylvain Thery's avatar
Sylvain Thery committed
269
	bool sameFace(Dart d, Dart e) const;
270

Pierre Kraemer's avatar
Pierre Kraemer committed
271 272 273
	//! Test if the face is on the boundary
	/*! @param d a dart from the face
	 */
Sylvain Thery's avatar
Sylvain Thery committed
274
	bool isBoundaryFace(Dart d) const;
Thomas's avatar
Thomas committed
275

Pierre Kraemer's avatar
Pierre Kraemer committed
276 277 278
	//! Tell if a face of the volume is on the boundary
	/*  @param d a dart
	 */
Sylvain Thery's avatar
Sylvain Thery committed
279
	bool isBoundaryVolume(Dart d) const;
Pierre Kraemer's avatar
Pierre Kraemer committed
280

Sylvain Thery's avatar
Sylvain Thery committed
281
	virtual bool check() const;
Pierre Kraemer's avatar
Pierre Kraemer committed
282
	//@}
283

Pierre Kraemer's avatar
Pierre Kraemer committed
284 285 286 287 288 289
	/*! @name Cell Functors
	 *  Apply functors to all darts of a cell
	 *************************************************************************/

	//@{
	/**
290 291
	* Apply a functor on each dart of an oriented vertex
	* @param d a dart of the oriented vertex
292 293
	* @param fonct functor obj ref
	*/
Sylvain Thery's avatar
Sylvain Thery committed
294
	bool foreach_dart_of_oriented_vertex(Dart d, FunctorType& fonct, unsigned int thread = 0) const;
295 296 297

	/**
	* Apply a functor on each dart of a vertex
298
	* @param d a dart of the vertex
Pierre Kraemer's avatar
Pierre Kraemer committed
299 300
	* @param fonct functor obj ref
	*/
Sylvain Thery's avatar
Sylvain Thery committed
301
	bool foreach_dart_of_vertex(Dart d, FunctorType& fonct, unsigned int thread = 0) const;
Pierre Kraemer's avatar
Pierre Kraemer committed
302

303 304 305 306 307
	/**
	* Apply a functor on each dart of an oriented edge
	* @param d a dart of the oriented edge
	* @param fonct functor obj ref
	*/
Sylvain Thery's avatar
Sylvain Thery committed
308
	bool foreach_dart_of_oriented_edge(Dart d, FunctorType& fonct, unsigned int thread = 0) const;
309

Pierre Kraemer's avatar
Pierre Kraemer committed
310 311
	/**
	* Apply a functor on each dart of an edge
312
	* @param d a dart of the edge
Pierre Kraemer's avatar
Pierre Kraemer committed
313 314
	* @param fonct functor obj ref
	*/
Sylvain Thery's avatar
Sylvain Thery committed
315
	bool foreach_dart_of_edge(Dart d, FunctorType& fonct, unsigned int thread = 0) const;
Pierre Kraemer's avatar
Pierre Kraemer committed
316 317

	//! Apply a functor on every dart of a face
318
	/*! @param d a dart of the face
Pierre Kraemer's avatar
Pierre Kraemer committed
319 320
	 *  @param f the functor to apply
	 */
Sylvain Thery's avatar
Sylvain Thery committed
321
	bool foreach_dart_of_face(Dart d, FunctorType& fonct, unsigned int thread = 0) const;
Pierre Kraemer's avatar
Pierre Kraemer committed
322

323 324 325 326
	//! Apply a functor on every dart of an oriented volume
	/*! @param d a dart of the oriented volume
	 *  @param f the functor to apply
	 */
Sylvain Thery's avatar
Sylvain Thery committed
327
	bool foreach_dart_of_oriented_volume(Dart d, FunctorType& fonct, unsigned int thread = 0) const;
328

329 330 331 332
	//! 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
333
	bool foreach_dart_of_volume(Dart d, FunctorType& fonct, unsigned int thread = 0) const;
334

Pierre Kraemer's avatar
Pierre Kraemer committed
335 336 337 338 339
	/**
	* Apply a functor on each dart of a cc
	* @param d a dart of the cc
	* @param fonct functor obj ref
	*/
Sylvain Thery's avatar
Sylvain Thery committed
340
	bool foreach_dart_of_cc(Dart d, FunctorType& fonct, unsigned int thread = 0) const;
341 342 343 344 345 346 347 348



	/**
	* Apply a functor on each dart of a vertex
	* @param d a dart of the face
	* @param fonct functor obj ref
	*/
Sylvain Thery's avatar
Sylvain Thery committed
349
	bool foreach_dart_of_vertex2(Dart d, FunctorType& fonct, unsigned int thread = 0) const;
350 351 352 353 354 355

	/**
	* Apply a functor on each dart of an edge
	* @param d a dart of the oriented face
	* @param fonct functor obj ref
	*/
Sylvain Thery's avatar
Sylvain Thery committed
356
	bool foreach_dart_of_edge2(Dart d, FunctorType& fonct, unsigned int thread = 0) const;
357 358 359 360 361

	//! Apply a functor on every dart of a face
	/*! @param d a dart of the volume
	 *  @param f the functor to apply
	 */
Sylvain Thery's avatar
Sylvain Thery committed
362
	bool foreach_dart_of_face2(Dart d, FunctorType& fonct, unsigned int thread = 0) const;
Pierre Kraemer's avatar
Pierre Kraemer committed
363
	//@}
Pierre Kraemer's avatar
Pierre Kraemer committed
364 365 366 367 368 369

	/*! @name Close map after import or creation
	 *  These functions must be used with care, generally only by import algorithms
	 *************************************************************************/

	//@{
370 371 372 373 374
	/**
	 * create a face of map1 marked as boundary
	 */
	Dart newBoundaryCycle(unsigned int nbE);

Pierre Kraemer's avatar
Pierre Kraemer committed
375 376 377 378 379 380 381 382 383 384 385 386
	//! 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.
387
	 *  @return the number of closed holes
Pierre Kraemer's avatar
Pierre Kraemer committed
388
	 */
389
	unsigned int closeMap();
390 391 392 393 394 395 396 397 398 399 400 401 402
	//@}

	/*! @name Compute dual
	 * These functions compute the dual mesh
	 *************************************************************************/

	//@{
	//! Dual mesh computation
	/*!
	 */
	void computeDual();
	//@}

Pierre Kraemer's avatar
Pierre Kraemer committed
403 404 405 406 407 408 409
};

} // namespace CGoGN

#include "Topology/gmap/gmap3.hpp"

#endif