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

#ifndef __MAP1_H__
#define __MAP1_H__

#include "Topology/generic/attribmap.h"
#include "Topology/generic/dartmarker.h"
#include "Topology/generic/cellmarker.h"

namespace CGoGN
{

/*! \brief The class of dual 1-dimensional combinatorial maps: set of oriented faces.
 *  - A dual 1-map is made of darts linked by the phi1 permutation.
 *  - In this class darts are interpreted as oriented edges.
 *  - The phi1 relation defines cycles of darts or (oriented) faces.
39 40 41
 *  - Faces may have arbitrary size.
 *  - Faces with only one edge (sometime called loops) are accepted.
 *  - Degenerated faces with only two edges are accepted.
Pierre Kraemer's avatar
Pierre Kraemer committed
42 43 44 45
 */
class Map1 : public AttribMap
{
protected:
46 47
	AttributeMultiVector<Dart>* m_phi1 ;
	AttributeMultiVector<Dart>* m_phi_1 ;
Pierre Kraemer's avatar
Pierre Kraemer committed
48

49 50
	void init() ;

Pierre Kraemer's avatar
Pierre Kraemer committed
51 52 53 54 55 56 57
public:
	Map1();

	virtual std::string mapTypeName();

	virtual unsigned int dimension();

58 59
	virtual void clear(bool removeAttrib);

Pierre Kraemer's avatar
Pierre Kraemer committed
60 61 62 63 64 65 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 98 99 100 101 102 103 104 105
	/*! @name Basic Topological Operators
	 * Access and Modification
	 *************************************************************************/

	virtual Dart newDart();

	Dart phi1(Dart d);

	Dart phi_1(Dart d);

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

	Dart alpha1(Dart d);

	Dart alpha_1(Dart d);

protected:
	//! Link the current dart to dart d with a permutation
	/*! @param d the dart to which the current is linked
	 * - Before:	d->f and e->g
	 * - After:		d->g and e->f
	 * Join the permutations cycles of dart d and e
	 * - Starting from two cycles : d->f->...->d and e->g->...->e
	 * - It makes one cycle d->g->...->e->f->...->d
	 * If e = g then insert e in the cycle of d : d->e->f->...->d
	 */
	void phi1sew(Dart d, Dart e);

	//! Unlink the successor of a given dart in a permutation
	/*!	@param d a dart
	 * - Before:	d->e->f
	 * - After:		d->f and e->e
	 */
	void phi1unsew(Dart d);

public:
	/*! @name Generator and Deletor
	 *  To generate or delete faces in a 1-map
	 *************************************************************************/

	//@{
	//! Create an new face made of nbEdges linked darts.
	/*! @param nbEdges the number of edges
	 *  @return return a dart of the face
	 */
106
	Dart newCycle(unsigned int nbEdges) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
107

Sylvain Thery's avatar
Sylvain Thery committed
108 109 110 111
	//! Create an new face for boundary (marked)
	/*! @param nbEdges the number of edges
	 *  @return return a dart of the face
	 */
112
	Dart newBoundaryCycle(unsigned int nbEdges);
Sylvain Thery's avatar
Sylvain Thery committed
113

Pierre Kraemer's avatar
Pierre Kraemer committed
114 115 116
	//! Delete an oriented face erasing all its darts
	/*! @param d a dart of the face
	 */
117
	void deleteCycle(Dart d) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
118 119 120 121 122 123 124
	//@}

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

	//@{
125
	//! Cut an edge inserting a new dart between d and its successor in the cycle
Pierre Kraemer's avatar
Pierre Kraemer committed
126 127 128
	/*! @param d the edge to cut
	 * \image hmtl map1_cutEdge.png
	 */
David Cazier's avatar
David Cazier committed
129
	Dart cutEdge(Dart d);
Pierre Kraemer's avatar
Pierre Kraemer committed
130

Pierre Kraemer's avatar
Pierre Kraemer committed
131 132 133 134 135
	//! Undo the cut of the edge of d
	/*! @param d a dart of the edge to uncut
	 */
	void uncutEdge(Dart d);

136
	//! Collapse an edge of a cycle
Pierre Kraemer's avatar
Pierre Kraemer committed
137 138 139 140 141
	/*!  \warning Dart d no longer exists after the call
	 *  @param d the edge
	 */
	void collapseEdge(Dart d);

142
	//! Split a cycle between vertices d and e
Pierre Kraemer's avatar
Pierre Kraemer committed
143 144 145 146
	/*! \pre Dart d and e MUST be different and belong to the same face
	 *  @param d first dart in the face
	 *  @param e second dart in the face
	 */
147
	void splitCycle(Dart d, Dart e);
Pierre Kraemer's avatar
Pierre Kraemer committed
148

149
	//! Merge two cycles on vertices d and e
Pierre Kraemer's avatar
Pierre Kraemer committed
150 151 152 153
	/*! \pre Dart d and e MUST belong to distinct faces
	 *  @param d a dart in the first face
	 *  @param e a dart in the second face
	 */
154 155
	void mergeCycles(Dart d, Dart e);

156
	//! Link two cycles by adding an edge between two vertices
157 158 159 160 161
	/*! \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
	 */
	void linkCycles(Dart d, Dart e);
Pierre Kraemer's avatar
Pierre Kraemer committed
162 163 164 165

	//! reverse a face (phi1 become phi_1 and ...)
	/*! @param d a dart of face
	 */
166
	void reverseCycle(Dart d) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
167 168 169 170 171 172 173
	//@}

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

	//@{
174
	//! Test if darts d and e belong to the same cycle
Pierre Kraemer's avatar
Pierre Kraemer committed
175 176 177
	/*! @param d a dart
	 *  @param e a dart
	 */
178
	bool sameCycle(Dart d, Dart e) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
179

180 181 182
	//! Length of a cycle (its number of oriented edges)
	/*! @param d a dart of the cycle
	 *  @return the length of the cycle
Pierre Kraemer's avatar
Pierre Kraemer committed
183
	 */
184
	unsigned int cycleDegree(Dart d) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
185 186

	/**
187 188
	 * check if the cycle of d is a triangle
	 * @return a boolean indicating if the cycle is a triangle
Pierre Kraemer's avatar
Pierre Kraemer committed
189
	 */
190
	bool isCycleTriangle(Dart d);
Pierre Kraemer's avatar
Pierre Kraemer committed
191 192 193 194 195 196 197 198 199 200 201
	//@}

	/*! @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
	 */
202
	bool foreach_dart_of_vertex(Dart d, FunctorType& f, unsigned int thread = 0);
Pierre Kraemer's avatar
Pierre Kraemer committed
203 204 205 206 207

	//! Apply a functor on every dart of an edge
	/*! @param d a dart of the edge
	 *  @param f the functor to apply
	 */
208
	bool foreach_dart_of_edge(Dart d, FunctorType& f, unsigned int thread = 0);
Pierre Kraemer's avatar
Pierre Kraemer committed
209 210 211 212 213

	//! Apply a functor on every dart of an oriented face
	/*! @param d a dart of the face
	 *  @param f the functor to apply
	 */
214
	bool foreach_dart_of_oriented_face(Dart d, FunctorType& f, unsigned int thread = 0) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
215

216 217 218 219 220
	//! Apply a functor on every dart of a face
	/*! @param d a dart of the face
	 *  @param f the functor to apply
	 */
	bool foreach_dart_of_face(Dart d, FunctorType& f, unsigned int thread = 0);
Pierre Kraemer's avatar
Pierre Kraemer committed
221 222 223 224 225

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

	//! Apply a functor on every dart of a connected component
229
	/*! @param d a dart of the connected component
Pierre Kraemer's avatar
Pierre Kraemer committed
230 231
	 *  @param f the functor to apply
	 */
232
	bool foreach_dart_of_cc(Dart d, FunctorType& f, unsigned int thread = 0);
Pierre Kraemer's avatar
Pierre Kraemer committed
233 234 235 236 237 238 239 240
	//@}
} ;

} // namespace CGoGN

#include "Topology/map/map1.hpp"

#endif