map3.h 8.89 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
	/*! @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
89
	/*! @param d,e the darts to link
Pierre Kraemer's avatar
Pierre Kraemer committed
90 91 92 93 94 95
	 *	- 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
96
	/*! @param d the dart to unlink
Pierre Kraemer's avatar
Pierre Kraemer committed
97 98 99 100 101
	 * - Before:	d->e and e->d
	 * - After:		d->d and e->e
	 */
	void phi3unsew(Dart d);

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

	//@{
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
	virtual void deleteVolume(Dart d);
Pierre Kraemer's avatar
Pierre Kraemer committed
113 114 115 116 117 118 119
	//@}

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

	//@{
120 121 122 123 124
	//TODO deleteVertex : works only for boundary vertices
	//! Delete the vertex of d
	/*! All the faces around the vertex are merged into one face
	 *  @param d a dart of the vertex to delete
	 *  @return true if the deletion has been executed, false otherwise
Pierre Kraemer's avatar
Pierre Kraemer committed
125
	 */
126
	virtual bool deleteVertex(Dart d);
Pierre Kraemer's avatar
Pierre Kraemer committed
127

128 129
	//! Cut the edge of d (all darts around edge orbit are cutted)
	/*! @param d a dart of the edge to cut
Pierre Kraemer's avatar
Pierre Kraemer committed
130
	 */
131
	virtual void cutEdge(Dart d);
Pierre Kraemer's avatar
Pierre Kraemer committed
132

133 134
	//! Uncut the edge of d (all darts around edge orbit are uncutted)
	/*! @param d a dart of the edge to uncut
Pierre Kraemer's avatar
Pierre Kraemer committed
135
	 */
136
	virtual void uncutEdge(Dart d);
Pierre Kraemer's avatar
Pierre Kraemer committed
137 138 139 140 141 142 143 144 145

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

146 147 148 149
	//! 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
Pierre Kraemer's avatar
Pierre Kraemer committed
150
	 */
151
	virtual void sewVolumes(Dart d, Dart e);
Pierre Kraemer's avatar
Pierre Kraemer committed
152

153 154
	//! Unsew two oriented volumes along their faces.
	/*! @param d a dart of one volume
Pierre Kraemer's avatar
Pierre Kraemer committed
155
	 */
156
	virtual void unsewVolumes(Dart d);
Pierre Kraemer's avatar
Pierre Kraemer committed
157

158 159
	//! Merge to volume along their common oriented face
	/*! @param d a dart of common face
Pierre Kraemer's avatar
Pierre Kraemer committed
160
	 */
161
	virtual bool mergeVolumes(Dart d);
Pierre Kraemer's avatar
Pierre Kraemer committed
162

untereiner's avatar
untereiner committed
163 164 165 166 167
	//! Split a volume into two volumes along a edge path
	/*! @param vd a vector of darts
	 */
	virtual void splitVolume(std::vector<Dart>& vd);

168
	//@}
Pierre Kraemer's avatar
Pierre Kraemer committed
169

170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186
	/*! @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) ;

187 188 189 190 191 192 193 194 195 196
	//! Compute the number of edges of the vertex of d
	/*! @param d a dart
	 */
	unsigned int vertexDegree(Dart d) ;

	//! Tell if the vertex of d is on the boundary
	/*! @param d a dart
	 */
	bool isBoundaryVertex(Dart d);

197 198 199 200 201 202 203 204 205 206 207 208
	//! 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) ;

209 210
	//! Compute the number of volumes around the edge of d
	/*! @param d a dart
Pierre Kraemer's avatar
Pierre Kraemer committed
211
	 */
untereiner's avatar
untereiner committed
212
	unsigned int edgeDegree(Dart d);
Pierre Kraemer's avatar
Pierre Kraemer committed
213

214 215 216
	//! Test if dart d and e belong to the same oriented face
	/*! @param d a dart
	 *  @param e a dart
untereiner's avatar
untereiner committed
217
	 */
218
	bool sameFace(Dart d, Dart e);
untereiner's avatar
untereiner committed
219

220 221
	//! Test if the face is on the boundary
	/*! @param d a dart from the face
Pierre Kraemer's avatar
Pierre Kraemer committed
222
	 */
223
	bool isBoundaryFace(Dart d);
Pierre Kraemer's avatar
Pierre Kraemer committed
224

225 226
	//! Tell if a face of the volume is on the boundary
	/*  @param d a dart
227
	 */
228
	bool isBoundaryVolume(Dart d);
Pierre Kraemer's avatar
Pierre Kraemer committed
229

230 231
	// TODO a mettre dans algo ?
	virtual bool check();
Pierre Kraemer's avatar
Pierre Kraemer committed
232 233 234 235 236 237 238
	//@}

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

	//@{
239 240 241 242 243 244
	//! Apply a functor on each dart of a vertex
	/*! @param d a dart of the vertex
	 *  @param fonct the functor
	 */
	bool foreach_dart_of_oriented_vertex(Dart d, FunctorType& f, unsigned int thread=0);

245 246 247 248
	//! 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
249
	bool foreach_dart_of_vertex(Dart d, FunctorType& f, unsigned int thread=0);
Pierre Kraemer's avatar
Pierre Kraemer committed
250

251 252 253 254
	//! 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
255
	bool foreach_dart_of_edge(Dart d, FunctorType& f, unsigned int thread=0);
Pierre Kraemer's avatar
Pierre Kraemer committed
256

Sylvain Thery's avatar
Sylvain Thery committed
257
	bool foreach_dart_of_open_edge(Dart d, FunctorType& f, unsigned int thread=0);
Pierre Kraemer's avatar
Pierre Kraemer committed
258

259 260 261 262
	//! 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
263
	bool foreach_dart_of_face(Dart d, FunctorType& f, unsigned int thread=0);
Pierre Kraemer's avatar
Pierre Kraemer committed
264 265

	// TODO change to oriented volume to handle higher dimension ?
266 267 268 269
	//! Apply a functor on each dart of an volume
	/*! @param d a dart of the volume
	 *  @param fonct the functor
	 */
Sylvain Thery's avatar
Sylvain Thery committed
270
	bool foreach_dart_of_volume(Dart d, FunctorType& f, unsigned int thread=0)
Pierre Kraemer's avatar
Pierre Kraemer committed
271 272 273 274
	{
		return foreach_dart_of_oriented_volume(d,f);
	}

275 276 277 278
	//! 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
279
	bool foreach_dart_of_cc(Dart d, FunctorType& f, unsigned int thread=0);
Pierre Kraemer's avatar
Pierre Kraemer committed
280 281 282 283 284 285 286 287 288
	//@}

};

} // namespace CGoGN

#include "Topology/map/map3.hpp"

#endif