mapCommon.h 10.4 KB
Newer Older
Pierre Kraemer's avatar
Pierre Kraemer committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
/*******************************************************************************
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps  *
* version 0.1                                                                  *
* Copyright (C) 2009-2012, IGG Team, LSIIT, University of Strasbourg           *
*                                                                              *
* 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.           *
*                                                                              *
* Web site: http://cgogn.unistra.fr/                                           *
* Contact information: cgogn@unistra.fr                                        *
*                                                                              *
*******************************************************************************/

#ifndef __MAP_COMMON__
#define __MAP_COMMON__

#include "Topology/generic/attributeHandler.h"
Sylvain Thery's avatar
Sylvain Thery committed
29
#include "Topology/generic/cells.h"
Pierre Kraemer's avatar
Pierre Kraemer committed
30
31
32
33

namespace CGoGN
{

Pierre Kraemer's avatar
Pierre Kraemer committed
34
template <typename MAP_IMPL>
Pierre Kraemer's avatar
Pierre Kraemer committed
35
36
37
38
39
40
41
42
43
44
45
46
47
class MapCommon : public MAP_IMPL
{
	typedef MAP_IMPL IMPL;

	/****************************************
	 *           DARTS TRAVERSALS           *
	 ****************************************/
public:
	/**
	* execute functor for each orbit
	* @param dim the dimension of the orbit
	* @param f the functor
	*/
Pierre Kraemer's avatar
Pierre Kraemer committed
48
	template <unsigned int ORBIT>
Pierre Kraemer's avatar
Pierre Kraemer committed
49
50
51
52
53
54
	bool foreach_orbit(FunctorType& f, unsigned int thread = 0);

	//! Count the number of orbits of dimension dim in the map
	/*! @param dim the dimension of the orbit
	 * 	@return the number of orbits
	 */
Pierre Kraemer's avatar
Pierre Kraemer committed
55
56
57
58
	template <unsigned int ORBIT>
	unsigned int getNbOrbits() const;

	unsigned int getNbOrbits(unsigned int orbit) const;
Pierre Kraemer's avatar
Pierre Kraemer committed
59
60
61
62
63
64
65

	//! For an orbit of a given dimension, return the number of incident cells of an other given dimension
	/*! @param d a dart
	 */
	template <unsigned int ORBIT, unsigned int INCIDENT>
	unsigned int degree(Dart d) const;

Sylvain Thery's avatar
Sylvain Thery committed
66
67
68
69
	template <unsigned int ORBIT>
	bool sameOrbit(Cell<ORBIT> c1, Cell<ORBIT> c2, unsigned int thread=0) const;


Pierre Kraemer's avatar
Pierre Kraemer committed
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
	/****************************************
	 *         EMBEDDING MANAGEMENT         *
	 ****************************************/

	/**
	 * get the cell index of the given dimension associated to dart d
	 * @return EMBNULL if the orbit of d is not attached to any cell
	 */
	template<unsigned int ORBIT>
	inline unsigned int getEmbedding(Dart d) const;

	/**
	 * Set the cell index of the given dimension associated to dart d
	 */
	template <unsigned int ORBIT>
	void setDartEmbedding(Dart d, unsigned int emb) ;

	/**
	 * Set the cell index of the given dimension associated to dart d
	 * !!! WARNING !!! use only on freshly inserted darts (no unref is done on old embedding) !!! WARNING !!!
	 */
	template <unsigned int ORBIT>
	void initDartEmbedding(Dart d, unsigned int emb) ;

	/**
	 * Copy the index of the cell associated to a dart over an other dart
	 * @param orbit the id of orbit embedding
	 * @param dest the dart to overwrite
	 * @param src the dart to copy
	 */
	template <unsigned int ORBIT>
	inline void copyDartEmbedding(Dart dest, Dart src) ;

	/**
	* Set the index of the associated cell to all the darts of an orbit
	* @param orbit orbit to embed
	* @param d a dart of the topological vertex
	* @param em index of attribute to store as embedding
	*/
	template <unsigned int ORBIT>
	void setOrbitEmbedding(Dart d, unsigned int em) ;

	/**
	 * Set the index of the associated cell to all the darts of an orbit
	 * !!! WARNING !!! use only on freshly inserted darts (no unref is done on old embedding)!!! WARNING !!!
	 */
	template <unsigned int ORBIT>
	void initOrbitEmbedding(Dart d, unsigned int em) ;

	/**
	* Associate an new cell to all darts of an orbit
	* @param orbit orbit to embed
	* @param d a dart of the topological cell
	* @return index of the attribute in table
	*/
	template <unsigned int ORBIT>
	unsigned int setOrbitEmbeddingOnNewCell(Dart d) ;

	/**
	 * Associate an new cell to all darts of an orbit
	 * !!! WARNING !!! use only on freshly inserted darts (no unref is done on old embedding)!!! WARNING !!!
	 */
	template <unsigned int ORBIT>
	unsigned int initOrbitEmbeddingOnNewCell(Dart d) ;

	/**
	 * Copy the cell associated to a dart over an other dart
	 * @param orbit attribute orbit to use
	 * @param d the dart to overwrite (dest)
	 * @param e the dart to copy (src)
	 */
	template <unsigned int ORBIT>
	void copyCell(Dart d, Dart e) ;

	/**
	 * Traverse the map and embed all orbits of the given dimension with a new cell
	 * @param realloc if true -> all the orbits are embedded on new cells, if false -> already embedded orbits are not impacted
	 */
	template <unsigned int ORBIT>
	void initAllOrbitsEmbedding(bool realloc = false) ;

	/****************************************
	 *         BOUNDARY MANAGEMENT          *
	 ****************************************/
protected:
	/**
	 * mark a dart as  belonging to boundary
	 */
Pierre Kraemer's avatar
Pierre Kraemer committed
158
	template <unsigned int DIM>
Pierre Kraemer's avatar
Pierre Kraemer committed
159
160
161
162
163
	void boundaryMark(Dart d) ;

	/**
	 * unmark a dart from the boundary
	 */
Pierre Kraemer's avatar
Pierre Kraemer committed
164
	template <unsigned int DIM>
Pierre Kraemer's avatar
Pierre Kraemer committed
165
166
167
168
169
170
171
172
173
174
175
176
177
178
	void boundaryUnmark(Dart d) ;

	/**
	 * mark an orbit of dart as belonging to boundary
	 */
	template <unsigned int ORBIT, unsigned int DIM>
	void boundaryMarkOrbit(Dart d) ;

	/**
	 * unmark an orbit of dart from the boundary
	 */
	template <unsigned int ORBIT, unsigned int DIM>
	void boundaryUnmarkOrbit(Dart d) ;

Pierre Kraemer's avatar
Pierre Kraemer committed
179
180
181
182
183
184
	/**
	 * clear all boundary markers
	 */
	template<unsigned int DIM>
	void boundaryUnmarkAll() ;

Pierre Kraemer's avatar
Pierre Kraemer committed
185
186
187
188
public:
	/**
	 * test if a dart belong to the boundary
	 */
Pierre Kraemer's avatar
Pierre Kraemer committed
189
190
	template <unsigned int DIM>
	inline bool isBoundaryMarked(Dart d) const ;
Pierre Kraemer's avatar
Pierre Kraemer committed
191

Pierre Kraemer's avatar
Pierre Kraemer committed
192
193
194
	inline bool isBoundaryMarkedCurrent(Dart d) const ;

	inline bool isBoundaryMarked(unsigned int dim, Dart d) const ;
Pierre Kraemer's avatar
Pierre Kraemer committed
195
196
197
198
199
200
201
202
203
204
205

	/****************************************
	 *        ATTRIBUTES MANAGEMENT         *
	 ****************************************/

	/**
	* Create an attribute for a given orbit
	* @param nameAttr attribute name
	* @return an AttributeHandler
	*/
	template <typename T, unsigned int ORBIT>
Pierre Kraemer's avatar
Pierre Kraemer committed
206
	inline AttributeHandler<T, ORBIT, MAP_IMPL> addAttribute(const std::string& nameAttr = "") ;
Pierre Kraemer's avatar
Pierre Kraemer committed
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243

	/**
	 * remove an attribute
	 * @param attr a handler to the attribute to remove
	 * @return true if remove succeed else false
	 */
	template <typename T, unsigned int ORBIT>
	inline bool removeAttribute(AttributeHandler<T, ORBIT, MAP_IMPL>& attr) ;

	/**
	* search an attribute for a given orbit
	* @param nameAttr attribute name
	* @return an AttributeHandler
	*/
	template <typename T, unsigned int ORBIT>
	inline AttributeHandler<T, ORBIT, MAP_IMPL> getAttribute(const std::string& nameAttr) ;

	/**
	* check if an attribute exist ( get, test if valid and add if necessary)
	* @param nameAttr attribute name
	* @return an AttributeHandler
	*/
	template <typename T, unsigned int ORBIT>
	AttributeHandler<T, ORBIT, MAP_IMPL> checkAttribute(const std::string& nameAttr) ;

	/**
	 * swap the content of two attributes (efficient, only swap pointers)
	 */
	template <typename T, unsigned int ORBIT>
	bool swapAttributes(AttributeHandler<T, ORBIT, MAP_IMPL>& attr1, AttributeHandler<T, ORBIT, MAP_IMPL>& attr2) ;

	/**
	 * copy the content of src attribute to dst attribute
	 */
	template <typename T, unsigned int ORBIT>
	bool copyAttribute(AttributeHandler<T, ORBIT, MAP_IMPL>& dst, AttributeHandler<T, ORBIT, MAP_IMPL>& src) ;

Pierre Kraemer's avatar
Pierre Kraemer committed
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
	/**
	 * get a DartAttribute to an involution of the map
	 */
	inline DartAttribute<Dart, MAP_IMPL> getInvolution(unsigned int i);

	/**
	 * get a DartAttribute to a permutation of the map
	 */
	inline DartAttribute<Dart, MAP_IMPL> getPermutation(unsigned int i);

	/**
	 * get a DartAttribute to a permutation of the map
	 */
	inline DartAttribute<Dart, MAP_IMPL> getPermutationInv(unsigned int i);

	/****************************************
	 *     QUICK TRAVERSAL MANAGEMENT       *
	 ****************************************/

	template <unsigned int ORBIT>
	void enableQuickTraversal() ;

	template <unsigned int ORBIT>
	void updateQuickTraversal() ;

	template <unsigned int ORBIT>
	const AttributeMultiVector<Dart>* getQuickTraversal() const;

	template <unsigned int ORBIT>
	void disableQuickTraversal() ;

	template <unsigned int ORBIT, unsigned int INCI>
	void enableQuickIncidentTraversal();

	template <unsigned int ORBIT, unsigned int INCI>
	void updateQuickIncidentTraversal();

	template <unsigned int ORBIT, unsigned int INCI>
	const AttributeMultiVector<NoTypeNameAttribute<std::vector<Dart> > >* getQuickIncidentTraversal() const;

	template <unsigned int ORBIT, unsigned int INCI>
	void disableQuickIncidentTraversal();

	template <unsigned int ORBIT, unsigned int ADJ>
	void enableQuickAdjacentTraversal();

	template <unsigned int ORBIT, unsigned int ADJ>
	void updateQuickAdjacentTraversal();

	template <unsigned int ORBIT, unsigned int INCI>
	const AttributeMultiVector<NoTypeNameAttribute<std::vector<Dart> > >* getQuickAdjacentTraversal() const;

	template <unsigned int ORBIT, unsigned int ADJ>
	void disableQuickAdjacentTraversal();

Pierre Kraemer's avatar
Pierre Kraemer committed
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
	/****************************************
	 *               UTILITIES              *
	 ****************************************/

	/**
	 * use the given attribute to store the indices of the cells of the corresponding orbit
	 * @return the number of cells of the orbit
	 */
	template <unsigned int ORBIT>
	unsigned int computeIndexCells(AttributeHandler<unsigned int, ORBIT, MAP_IMPL>& idx) ;

	/**
	 * ensure that each orbit as one embedding and that each embedding is handle by only one orbit
	 */
	template <unsigned int ORBIT>
	void bijectiveOrbitEmbedding();
};

} //namespace CGoGN

#include "Topology/generic/mapCommon.hpp"

#endif