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

#ifndef __MAP1_H__
#define __MAP1_H__

Pierre Kraemer's avatar
Pierre Kraemer committed
28
#include "Topology/generic/mapCommon.h"
Pierre Kraemer's avatar
Pierre Kraemer committed
29
30
#include "Topology/generic/dartmarker.h"
#include "Topology/generic/cellmarker.h"
31
#include "Algo/Topo/basic.h"
Pierre Kraemer's avatar
Pierre Kraemer committed
32
33
34
35
36
37
38
39

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.
40
41
42
 *  - 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
43
 */
Pierre Kraemer's avatar
Pierre Kraemer committed
44
45
template <typename MAP_IMPL>
class Map1 : public MapCommon<MAP_IMPL>
Pierre Kraemer's avatar
Pierre Kraemer committed
46
{
47
protected:
48
49
50
	// protected copy constructor to prevent the copy of map
	Map1(const Map1<MAP_IMPL>& m):MapCommon<MAP_IMPL>(m) {}

51
52
	void init() ;

Pierre Kraemer's avatar
Pierre Kraemer committed
53
public:
Pierre Kraemer's avatar
Pierre Kraemer committed
54
	typedef MAP_IMPL IMPL;
Pierre Kraemer's avatar
Pierre Kraemer committed
55
	typedef MapCommon<MAP_IMPL> ParentMap;
Pierre Kraemer's avatar
Pierre Kraemer committed
56

Pierre Kraemer's avatar
Pierre Kraemer committed
57
58
	Map1();

59
60
	static const unsigned int DIMENSION = 1 ;

61
	virtual std::string mapTypeName() const;
Pierre Kraemer's avatar
Pierre Kraemer committed
62

63
	virtual unsigned int dimension() const;
Pierre Kraemer's avatar
Pierre Kraemer committed
64

65
66
	virtual void clear(bool removeAttrib);

Pierre Kraemer's avatar
Pierre Kraemer committed
67
68
	virtual unsigned int getNbInvolutions() const;
	virtual unsigned int getNbPermutations() const;
Sylvain Thery's avatar
Sylvain Thery committed
69

Pierre Kraemer's avatar
Pierre Kraemer committed
70
71
72
73
	/*! @name Basic Topological Operators
	 * Access and Modification
	 *************************************************************************/

Sylvain Thery's avatar
Sylvain Thery committed
74
	Dart phi1(Dart d) const;
Pierre Kraemer's avatar
Pierre Kraemer committed
75

Sylvain Thery's avatar
Sylvain Thery committed
76
	Dart phi_1(Dart d) const;
Pierre Kraemer's avatar
Pierre Kraemer committed
77
78

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

Sylvain Thery's avatar
Sylvain Thery committed
81
	Dart alpha1(Dart d) const;
Pierre Kraemer's avatar
Pierre Kraemer committed
82

Sylvain Thery's avatar
Sylvain Thery committed
83
	Dart alpha_1(Dart d) const;
Pierre Kraemer's avatar
Pierre Kraemer committed
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113

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
	 */
114
	Dart newCycle(unsigned int nbEdges) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
115
116
117
118

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

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

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

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

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

144
	//! Split a cycle between vertices d and e
Pierre Kraemer's avatar
Pierre Kraemer committed
145
146
147
148
	/*! \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
	 */
149
	void splitCycle(Dart d, Dart e);
Pierre Kraemer's avatar
Pierre Kraemer committed
150

151
	//! Merge two cycles on vertices d and e
Pierre Kraemer's avatar
Pierre Kraemer committed
152
153
154
155
	/*! \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
	 */
156
157
	void mergeCycles(Dart d, Dart e);

158
	//! Link two cycles by adding an edge between two vertices
159
160
161
162
163
	/*! \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
164
165
166
167

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

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

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

182
183
184
	//! 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
185
	 */
Sylvain Thery's avatar
Sylvain Thery committed
186
	unsigned int cycleDegree(Dart d) const;
Pierre Kraemer's avatar
Pierre Kraemer committed
187

188
189
190
191
192
	//! Check the Length of a cycle (its number of oriented edges)
	/*! @param d a dart of the cycle
	 *  @param degree the length to compare
	 *  @return  negative/null/positive if face degree is less/equal/greater than given degree
	 */
Sylvain Thery's avatar
Sylvain Thery committed
193
	 int checkCycleDegree(Dart d, unsigned int degree) const;
194

Pierre Kraemer's avatar
Pierre Kraemer committed
195
	/**
196
197
	 * 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
198
	 */
Sylvain Thery's avatar
Sylvain Thery committed
199
	bool isCycleTriangle(Dart d) const;
Pierre Kraemer's avatar
Pierre Kraemer committed
200
201
202
203
204
205
206
	//@}

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

	//@{
207
208
209
210
211
212
213
214
215
	//! Apply a function on every dart of an orbit
	/*! @param c a cell
	 *  @param f a function
	 */
	template <unsigned int ORBIT, typename FUNC>
	void foreach_dart_of_orbit(Cell<ORBIT> c, FUNC f, unsigned int thread = 0) const ;
	template <unsigned int ORBIT, typename FUNC>
	void foreach_dart_of_orbit(Cell<ORBIT> c, FUNC& f, unsigned int thread = 0) const ;

Pierre Kraemer's avatar
Pierre Kraemer committed
216
217
218
219
	//! Apply a functor on every dart of a vertex
	/*! @param d a dart of the vertex
	 *  @param f the functor to apply
	 */
220
221
	template <typename FUNC>
	void foreach_dart_of_vertex(Dart d, FUNC& f, unsigned int thread = 0) const;
Pierre Kraemer's avatar
Pierre Kraemer committed
222
223
224
225
226

	//! Apply a functor on every dart of an edge
	/*! @param d a dart of the edge
	 *  @param f the functor to apply
	 */
227
228
	template <typename FUNC>
	void foreach_dart_of_edge(Dart d, FUNC& f, unsigned int thread = 0) const;
Pierre Kraemer's avatar
Pierre Kraemer committed
229
230

	//! Apply a functor on every dart of a connected component
231
	/*! @param d a dart of the connected component
Pierre Kraemer's avatar
Pierre Kraemer committed
232
233
	 *  @param f the functor to apply
	 */
234
235
	template <typename FUNC>
	void foreach_dart_of_cc(Dart d, FUNC& f, unsigned int thread = 0) const;
Pierre Kraemer's avatar
Pierre Kraemer committed
236
237
238
239
240
241
242
243
	//@}
} ;

} // namespace CGoGN

#include "Topology/map/map1.hpp"

#endif