map3.h 11.4 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
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
60
61
62
63
64
65
public:
	typedef Map2 ParentMap;

	Map3();

	virtual std::string mapTypeName();

	virtual unsigned int dimension();

66
67
	virtual void clear(bool removeAttrib);

Pierre Kraemer's avatar
Pierre Kraemer committed
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
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
	/*! @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
	/*  @param d,e the darts to link
	 *	- 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
	/*  @param d the dart to unlink
	 * - Before:	d->e and e->d
	 * - After:		d->d and e->e
	 */
	void phi3unsew(Dart d);

	/*! @name Generator and Deletor
	 *  To generate or delete volumes in a 3-map
	 *************************************************************************/

public:

	//@{
	//! Delete an oriented volume
	/*! @param d a dart of the volume
	 */
	virtual void deleteOrientedVolume(Dart d);
	//@}

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

	//@{
	//! Sew two oriented volumes along their faces. 
	/*! The oriented faces should not be phi3-linked and have the same length
	 *  @param d a dart of the first volume
	 *  @param e a dart of the second volume
	 */
	virtual void sewVolumes(Dart d, Dart e);

	//! Unsew two oriented volumes along their faces.
	/*! @param d a dart of one volume
	 */
	virtual void unsewVolumes(Dart d);

	//! Merge to volume sewed by one face
	/*! @param d a dart of common face
	 */
	virtual bool mergeVolumes(Dart d);

	//! 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
	 *  @return the dart of the new edge lying in the vertex of d after the cut
	 */
	virtual void splitFace(Dart d, Dart e);

	//! Cut the edge of d
	/*! @param d a dart of the edge to cut
	 */
	virtual void cutEdge(Dart d);

untereiner's avatar
untereiner committed
150
	//! Uncut the edge of d
untereiner's avatar
untereiner committed
151
	/*! @param d a dart of the edge to uncut
Pierre Kraemer's avatar
Pierre Kraemer committed
152
	 */
untereiner's avatar
untereiner committed
153
	virtual void uncutEdge(Dart d);
Pierre Kraemer's avatar
Pierre Kraemer committed
154

untereiner's avatar
untereiner committed
155
156
157
	//!
	/*!
	 *
Pierre Kraemer's avatar
Pierre Kraemer committed
158
	 */
untereiner's avatar
untereiner committed
159
	virtual bool deleteVertex(Dart d);
Pierre Kraemer's avatar
Pierre Kraemer committed
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178

	//!
	/*! Flip the edge of d (rotation in phi1 order)
	 *  WARNING : works only if the edge is owned by exactly one or two volumes
	 *  @param d the edge to flip
	 */
	//virtual bool flipEdge(Dart d);

	//!
	/*! Flip the edge of d (rotation in phi_1 order)
	 *  WARNING : works only if the edge is owned by exactly one or two volumes
	 *  @param d the edge to flip
	 */
	//virtual bool flipBackEdge(Dart d);

	//!
	/*!
	 *
	 */
untereiner's avatar
untereiner committed
179
	//virtual bool flipFace(Dart d);
Pierre Kraemer's avatar
Pierre Kraemer committed
180
181
182
183
184
185

    //! Insert a face in phi2 along the orbit phi<-1,2,-1>
    /*! The cardinality of <phi1>(nF) must be equal to the cardinality of <phi(-1,2,-1)>(d)
     *  @param d a dart where the face should be inserted
     *  @param e a dart from the face to insert
     */
untereiner's avatar
untereiner committed
186
	//virtual void insertFace(Dart d, Dart e);
Pierre Kraemer's avatar
Pierre Kraemer committed
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224

	//! Collapse an edge (that is deleted) possibly merging its vertices
	/*! If delDegenerateFaces is true, the method checks that no degenerate
	 *  faces are build (faces with less than 3 edges). If it occurs the faces
	 *  are deleted and the adjacencies are updated (see deleteIfDegenerated).
	 *  \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
	 *  @param delDegenerateFaces a boolean (default to true)
	 */
	virtual int collapseEdge(Dart d, bool delDegenerateFaces = true, bool delDegenerateVolumes = true);

	//!
	/*!
	 *
	 * @param
	 * @param
	 * @param
	 */
	virtual void collapseFace(Dart d, bool delDegenerateFaces = true, bool delDegenerateVolumes = true);

	//!
	/*!
	 *
	 * @param
	 * @param
	 * @param
	 */
	virtual void collapseVolume(Dart d, bool delDegenerateFaces = true, bool delDegenerateVolumes = true);

	/** Fusion two faces deleting the two edges after d and e
	 *  and their respective phi3 faces
	 *! \pre Dart d and e should belong to distinct faces
	 *  \pre Dart d and e should not be phi2-linked
	 *  \pre Dart d and e should not be phi3-linked
	 *  @param d a dart in the first face
	 *  @param e a dart in the second face
	 */
225
	virtual bool mergeFaces(Dart d, Dart e);
Pierre Kraemer's avatar
Pierre Kraemer committed
226
227
228
229
230
231
232

	//!
	/*!
	 *
	 */
	virtual Dart cutSpike(Dart d);

233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
	/*! @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
	 */
	bool sameOrientedVertex(Dart d, Dart e) ;

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

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

Pierre Kraemer's avatar
Pierre Kraemer committed
263
264
265
266
267
268
	//!
	/*
	 *
	 */
	virtual int edgeDegree(Dart d);

untereiner's avatar
untereiner committed
269
270
271
272
273
	/**
	 * compute the number of edges of the vertex of d
	 */
	unsigned int vertexDegree(Dart d) ;

Pierre Kraemer's avatar
Pierre Kraemer committed
274
275
276
277
278
279
	//!
	/* Tell if a face of the volume is on the boundary
	 *
	 */
	virtual bool isBoundaryVolume(Dart d);

280
281
282
283
	/**
	 *
	 */
	virtual bool isBoundaryVertex(Dart d);
Pierre Kraemer's avatar
Pierre Kraemer committed
284
285
286
287
288
289
290
291
292
293
294
295
296

	//@}

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

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

	/**
	* Apply a functor on each dart of an edge
	* @param d a dart of the oriented edge
	* @param fonct the functor
	*/
Sylvain Thery's avatar
Sylvain Thery committed
304
	bool foreach_dart_of_edge(Dart d, FunctorType& f, unsigned int thread=0);
Pierre Kraemer's avatar
Pierre Kraemer committed
305

Sylvain Thery's avatar
Sylvain Thery committed
306
	bool foreach_dart_of_open_edge(Dart d, FunctorType& f, unsigned int thread=0);
Pierre Kraemer's avatar
Pierre Kraemer committed
307
308
309
310
311
312

	/**
	* Apply a functor on each dart of an oriented face
	* @param d a dart of the oriented face
	* @param fonct the functor
	*/
Sylvain Thery's avatar
Sylvain Thery committed
313
	bool foreach_dart_of_face(Dart d, FunctorType& f, unsigned int thread=0);
Pierre Kraemer's avatar
Pierre Kraemer committed
314
315
316
317
318
319
320

	/**
	* Apply a functor on each dart of an volume
	* @param d a dart of the volume
	* @param fonct the functor
	*/
	// TODO change to oriented volume to handle higher dimension ?
Sylvain Thery's avatar
Sylvain Thery committed
321
	bool foreach_dart_of_volume(Dart d, FunctorType& f, unsigned int thread=0)
Pierre Kraemer's avatar
Pierre Kraemer committed
322
323
324
325
326
327
328
329
330
331
332
333
	{
		return foreach_dart_of_oriented_volume(d,f);
	}

//	template<typename TMAP>
//	bool foreach_dart_of_parent_cell(int dim, Dart d, FunctorType& f);

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

	/**
	* Search one dart per volumes degree-connex to the volume of d
	* and apply a functor on this dart of a cc if selected by the functorselect
	* @param d a dart of the volume
	* @param degree degree of connexity : 0=vertex-connexity, 1=edge-connexity, 2=face-connexity
	* @param f the functor
	* @param s the selector
	*/
untereiner's avatar
untereiner committed
344
	 bool foreach_connex_volume(Dart d, int degree, FunctorType& f, FunctorSelect& s, unsigned int thread=0);
Pierre Kraemer's avatar
Pierre Kraemer committed
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
	//@}

//	template<typename TMAP>
//	bool markOrbitOf(int dim, Dart d, Marker m);
//
//	template<typename TMAP>
//	bool unmarkOrbitOf(int dim, Dart d, Marker m);



	//TODO devrait disparaitre
	// pour les mêmes raisons que dans map2
	/**
	* Close map: add external faces to map which contain
	* dart with phi2 fixed point. Only topological operation
	* embeddings are not updated.
	* WARNING: all added dart are marked !!
	* @ return index of the marker which with addes darts are marked
	*/
untereiner's avatar
untereiner committed
364
	virtual void closeMap(DartMarker& marker);
Pierre Kraemer's avatar
Pierre Kraemer committed
365
366
367
368
369
370
371
372
373
374
375
376
377
378

	//TODO a mettre en algo
	/**
	* Reverse orientation of map (reverse orientation of all faces)
	* no dart created, each dart keeps its embedding, only changing phi1, phi2 and phi3
	*/
	void reverseOrientation();


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

	//@{
untereiner's avatar
untereiner committed
379
380
381
382
383
384
385
386

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


Pierre Kraemer's avatar
Pierre Kraemer committed
387
388
	// TODO devrait disparaitre
	// pour les mêmes raisons que dans map2
untereiner's avatar
untereiner committed
389
	virtual bool check();
Pierre Kraemer's avatar
Pierre Kraemer committed
390
391
392
393
394
395
396
397
	//@}
};

} // namespace CGoGN

#include "Topology/map/map3.hpp"

#endif