traversor3.h 12.3 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 __TRAVERSOR3_H__
#define __TRAVERSOR3_H__

28 29
#include "Topology/generic/dart.h"
#include "Topology/generic/cellmarker.h"
30 31 32
#include "Topology/generic/traversor/traversorCell.h"
//#include "Topology/generic/traversor/traversorGen.h"
#include "Topology/generic/traversor/traversorDoO.h"
33

Pierre Kraemer's avatar
Pierre Kraemer committed
34 35
namespace CGoGN
{
Pierre Kraemer's avatar
Pierre Kraemer committed
36

37 38 39 40
/**
 * class Marker for Traversor usefull to combine
 * several TraversorXY
 */
Pierre Kraemer's avatar
Pierre Kraemer committed
41
template <typename MAP, unsigned int ORBIT>
42
class MarkerForTraversor
Pierre Kraemer's avatar
Pierre Kraemer committed
43 44
{
private:
Sylvain Thery's avatar
Sylvain Thery committed
45
	const MAP& m_map ;
Pierre Kraemer's avatar
Pierre Kraemer committed
46 47
	DartMarkerStore<MAP>* m_dmark ;
	CellMarkerStore<MAP, ORBIT>* m_cmark ;
48

Pierre Kraemer's avatar
Pierre Kraemer committed
49
public:
Sylvain Thery's avatar
Sylvain Thery committed
50
	MarkerForTraversor(const MAP& map, bool forceDartMarker = false, unsigned int thread = 0) ;
51
	~MarkerForTraversor();
Pierre Kraemer's avatar
Pierre Kraemer committed
52 53 54

	DartMarkerStore<MAP>* dmark();
	CellMarkerStore<MAP, ORBIT>* cmark();
55 56 57
	void mark(Cell<ORBIT> c);
	void unmark(Cell<ORBIT> c);
	bool isMarked(Cell<ORBIT> c);
58
} ;
Pierre Kraemer's avatar
Pierre Kraemer committed
59

60 61 62 63
/**
 * Generic class Traversor (do not use directly)
 * Traverse all Y incident to X
 */
Pierre Kraemer's avatar
Pierre Kraemer committed
64
template <typename MAP, unsigned int ORBX, unsigned int ORBY>
Sylvain Thery's avatar
Sylvain Thery committed
65
class Traversor3XY//: public Traversor<MAP>
66 67
{
private:
Sylvain Thery's avatar
Sylvain Thery committed
68
	const MAP& m_map ;
Pierre Kraemer's avatar
Pierre Kraemer committed
69 70
	DartMarkerStore<MAP>* m_dmark ;
	CellMarkerStore<MAP, ORBY>* m_cmark ;
71
	Cell<ORBY> m_current ;
Pierre Kraemer's avatar
Pierre Kraemer committed
72
	TraversorDartsOfOrbit<MAP, ORBX> m_tradoo;
Sylvain Thery's avatar
Sylvain Thery committed
73

Sylvain Thery's avatar
Sylvain Thery committed
74 75
	const std::vector<Dart>* m_QLT;
	std::vector<Dart>::const_iterator m_ItDarts;
Sylvain Thery's avatar
Sylvain Thery committed
76

77
	bool m_allocated;
78
	bool m_first;
79

80
public:
81 82
	Traversor3XY(const MAP& map, Cell<ORBX> c, bool forceDartMarker = false, unsigned int thread = 0) ;
	Traversor3XY(const MAP& map, Cell<ORBX> c, MarkerForTraversor<MAP, ORBY>& tmo, bool forceDartMarker = false, unsigned int thread = 0) ;
83
	~Traversor3XY();
84

85 86 87
	Cell<ORBY> begin() ;
	Cell<ORBY> end() ;
	Cell<ORBY> next() ;
Pierre Kraemer's avatar
Pierre Kraemer committed
88 89
} ;

90 91 92 93
/**
 * Generic class Traversor (do not use directly)
 * Traverse all X adjacent to X by an Y
 */
Pierre Kraemer's avatar
Pierre Kraemer committed
94
template <typename MAP, unsigned int ORBX, unsigned int ORBY>
Sylvain Thery's avatar
Sylvain Thery committed
95
class Traversor3XXaY//: public Traversor<MAP>
Pierre Kraemer's avatar
Pierre Kraemer committed
96 97
{
private:
Sylvain Thery's avatar
Sylvain Thery committed
98
	const MAP& m_map ;
99 100
	std::vector<Dart> m_vecDarts;
	std::vector<Dart>::iterator m_iter;
Sylvain Thery's avatar
Sylvain Thery committed
101

Sylvain Thery's avatar
Sylvain Thery committed
102 103
	const std::vector<Dart>* m_QLT;
	std::vector<Dart>::const_iterator m_ItDarts;
104

105
public:
106
	Traversor3XXaY(const MAP& map, Cell<ORBX> c, bool forceDartMarker = false, unsigned int thread = 0);
107

108 109 110
	Cell<ORBX> begin();
	Cell<ORBX> end();
	Cell<ORBX> next();
111 112 113 114 115 116
};

/**
 * Traverse vertices incident to volume
 */
template <typename MAP>
Pierre Kraemer's avatar
Pierre Kraemer committed
117
class Traversor3WV: public Traversor3XY<MAP, VOLUME, VERTEX>
118
{
Pierre Kraemer's avatar
Pierre Kraemer committed
119
public:
120
	Traversor3WV(const MAP& m, Vol dart, bool forceDartMarker = false, unsigned int thread = 0) : Traversor3XY<MAP, VOLUME, VERTEX>(m, dart, forceDartMarker, thread)	{}
121
};
Pierre Kraemer's avatar
Pierre Kraemer committed
122

123 124 125 126
/**
 * Traverse edges incident to volume
 */
template <typename MAP>
Pierre Kraemer's avatar
Pierre Kraemer committed
127
class Traversor3WE: public Traversor3XY<MAP, VOLUME, EDGE>
128 129
{
public:
130
	Traversor3WE(const MAP& m, Vol dart, bool forceDartMarker = false, unsigned int thread = 0) : Traversor3XY<MAP, VOLUME, EDGE>(m, dart, forceDartMarker, thread)	{}
131
};
Pierre Kraemer's avatar
Pierre Kraemer committed
132

133 134 135
/**
 * Traverse faces incident to volume
 */
Pierre Kraemer's avatar
Pierre Kraemer committed
136
template <typename MAP>
Pierre Kraemer's avatar
Pierre Kraemer committed
137
class Traversor3WF: public Traversor3XY<MAP, VOLUME, FACE>
Pierre Kraemer's avatar
Pierre Kraemer committed
138
{
139
public:
140
	Traversor3WF(const MAP& m, Vol dart, bool forceDartMarker = false, unsigned int thread = 0) : Traversor3XY<MAP, VOLUME, FACE>(m, dart, forceDartMarker, thread) {}
141 142 143 144 145 146
};

/**
 * Traverse vertices incident to face
 */
template <typename MAP>
Pierre Kraemer's avatar
Pierre Kraemer committed
147
class Traversor3FV: public Traversor3XY<MAP, FACE, VERTEX>
148
{
Pierre Kraemer's avatar
Pierre Kraemer committed
149
public:
150
	Traversor3FV(const MAP& m, Face dart, bool forceDartMarker = false, unsigned int thread = 0) : Traversor3XY<MAP, FACE, VERTEX>(m, dart, forceDartMarker, thread)	{}
151
};
Pierre Kraemer's avatar
Pierre Kraemer committed
152

153 154 155 156
/**
 * Traverse edges incident to face
 */
template <typename MAP>
Pierre Kraemer's avatar
Pierre Kraemer committed
157
class Traversor3FE: public Traversor3XY<MAP, FACE, EDGE>
158 159
{
public:
160
	Traversor3FE(const MAP& m, Face dart, bool forceDartMarker = false, unsigned int thread = 0) : Traversor3XY<MAP, FACE, EDGE>(m, dart, forceDartMarker, thread)	{}
161
};
Pierre Kraemer's avatar
Pierre Kraemer committed
162

163 164 165 166
/**
 * Traverse volumes incident to face
 */
template <typename MAP>
Pierre Kraemer's avatar
Pierre Kraemer committed
167
class Traversor3FW: public Traversor3XY<MAP, FACE, VOLUME>
168 169
{
public:
170
	Traversor3FW(const MAP& m, Face dart, bool forceDartMarker = false, unsigned int thread = 0) : Traversor3XY<MAP, FACE, VOLUME>(m, dart, forceDartMarker, thread)	{}
171
};
Pierre Kraemer's avatar
Pierre Kraemer committed
172

173 174 175 176
/**
 * Traverse vertices incident to edge
 */
template <typename MAP>
Pierre Kraemer's avatar
Pierre Kraemer committed
177
class Traversor3EV: public Traversor3XY<MAP, EDGE, VERTEX>
178 179
{
public:
180
	Traversor3EV(const MAP& m, Edge dart, bool forceDartMarker = false, unsigned int thread = 0) : Traversor3XY<MAP, EDGE, VERTEX>(m, dart, forceDartMarker, thread)	{}
181
};
Pierre Kraemer's avatar
Pierre Kraemer committed
182

183 184 185 186
/**
 * Traverse faces incident to edge
 */
template <typename MAP>
Pierre Kraemer's avatar
Pierre Kraemer committed
187
class Traversor3EF: public Traversor3XY<MAP, EDGE, FACE>
188 189
{
public:
190
	Traversor3EF(const MAP& m, Edge dart, bool forceDartMarker = false, unsigned int thread = 0) : Traversor3XY<MAP, EDGE, FACE>(m, dart, forceDartMarker, thread)	{}
191
};
Pierre Kraemer's avatar
Pierre Kraemer committed
192

193 194 195 196
/**
 * Traverse volumes incident to edge
 */
template <typename MAP>
Pierre Kraemer's avatar
Pierre Kraemer committed
197
class Traversor3EW: public Traversor3XY<MAP, EDGE, VOLUME>
198 199
{
public:
200
	Traversor3EW(const MAP& m, Edge dart, bool forceDartMarker = false, unsigned int thread = 0) : Traversor3XY<MAP, EDGE, VOLUME>(m, dart, forceDartMarker, thread)	{}
201
};
Pierre Kraemer's avatar
Pierre Kraemer committed
202

203 204 205 206
/**
 * Traverse edges incident to vertex
 */
template <typename MAP>
Pierre Kraemer's avatar
Pierre Kraemer committed
207
class Traversor3VE: public Traversor3XY<MAP, VERTEX, EDGE>
208
{
209
public:
210
	Traversor3VE(const MAP& m, Vertex dart, bool forceDartMarker = false, unsigned int thread = 0) : Traversor3XY<MAP, VERTEX, EDGE>(m, dart, forceDartMarker, thread)	{}
211
};
212

213 214 215 216
/**
 * Traverse faces incident to vertex
 */
template <typename MAP>
Pierre Kraemer's avatar
Pierre Kraemer committed
217
class Traversor3VF: public Traversor3XY<MAP, VERTEX, FACE>
218
{
219
public:
220
	Traversor3VF(const MAP& m, Vertex dart, bool forceDartMarker = false, unsigned int thread = 0) : Traversor3XY<MAP, VERTEX, FACE>(m, dart, forceDartMarker, thread)	{}
221
};
222

223 224 225 226
/**
 * Traverse volumes incident to vertex
 */
template <typename MAP>
Pierre Kraemer's avatar
Pierre Kraemer committed
227
class Traversor3VW: public Traversor3XY<MAP, VERTEX, VOLUME>
228 229
{
public:
230
	Traversor3VW(const MAP& m, Vertex dart, bool forceDartMarker = false, unsigned int thread = 0) : Traversor3XY<MAP, VERTEX, VOLUME>(m, dart, forceDartMarker, thread)	{}
231 232 233 234 235 236
};

/**
 * Traverse vertices adjacent to a vertex by an edge
 */
template <typename MAP>
Pierre Kraemer's avatar
Pierre Kraemer committed
237
class Traversor3VVaE: public Traversor3XXaY<MAP, VERTEX, EDGE>
238 239
{
public:
240
	Traversor3VVaE(const MAP& m, Vertex d, bool forceDartMarker = false, unsigned int thread = 0) : Traversor3XXaY<MAP, VERTEX, EDGE>(m, d, forceDartMarker, thread)	{}
241 242 243 244 245 246
};

/**
 * Traverse vertices adjacent to a vertex by a face
 */
template <typename MAP>
Pierre Kraemer's avatar
Pierre Kraemer committed
247
class Traversor3VVaF: public Traversor3XXaY<MAP, VERTEX, FACE>
248 249
{
public:
250
	Traversor3VVaF(const MAP& m, Vertex d, bool forceDartMarker = false, unsigned int thread = 0) : Traversor3XXaY<MAP, VERTEX, FACE>(m, d, forceDartMarker, thread)	{}
251 252 253 254 255 256
};

/**
 * Traverse vertices adjacent to a vertex by a volume
 */
template <typename MAP>
Pierre Kraemer's avatar
Pierre Kraemer committed
257
class Traversor3VVaW: public Traversor3XXaY<MAP, VERTEX, VOLUME>
258 259
{
public:
260
	Traversor3VVaW(const MAP& m, Vertex d, bool forceDartMarker = false, unsigned int thread = 0) : Traversor3XXaY<MAP, VERTEX, VOLUME>(m, d, forceDartMarker, thread)	{}
261 262 263 264 265 266
};

/**
 * Traverse edges adjacent to an egde by a vertex
 */
template <typename MAP>
Pierre Kraemer's avatar
Pierre Kraemer committed
267
class Traversor3EEaV: public Traversor3XXaY<MAP, EDGE, VERTEX>
268 269
{
public:
270
	Traversor3EEaV(const MAP& m, Edge d, bool forceDartMarker = false, unsigned int thread = 0) : Traversor3XXaY<MAP, EDGE, VERTEX>(m, d, forceDartMarker, thread)	{}
271 272 273 274 275 276
};

/**
 * Traverse edges adjacent to an egde by a face
 */
template <typename MAP>
Pierre Kraemer's avatar
Pierre Kraemer committed
277
class Traversor3EEaF: public Traversor3XXaY<MAP, EDGE, FACE>
278 279
{
public:
280
	Traversor3EEaF(const MAP& m, Edge d, bool forceDartMarker = false, unsigned int thread = 0) : Traversor3XXaY<MAP, EDGE, FACE>(m, d, forceDartMarker, thread)	{}
281 282 283 284 285 286
};

/**
 * Traverse edges adjacent to an egde by a volume
 */
template <typename MAP>
Pierre Kraemer's avatar
Pierre Kraemer committed
287
class Traversor3EEaW: public Traversor3XXaY<MAP, EDGE, VOLUME>
288 289
{
public:
290
	Traversor3EEaW(const MAP& m, Edge d, bool forceDartMarker = false, unsigned int thread = 0) : Traversor3XXaY<MAP, EDGE, VOLUME>(m, d, forceDartMarker, thread)	{}
291 292 293 294 295 296
};

/**
 * Traverse faces adjacent to a face by a vertex
 */
template <typename MAP>
Pierre Kraemer's avatar
Pierre Kraemer committed
297
class Traversor3FFaV: public Traversor3XXaY<MAP, FACE, VERTEX>
298 299
{
public:
300
	Traversor3FFaV(const MAP& m, Face d, bool forceDartMarker = false, unsigned int thread = 0) : Traversor3XXaY<MAP, FACE, VERTEX>(m, d, forceDartMarker, thread)	{}
301 302 303 304 305 306
};

/**
 * Traverse faces adjacent to a face by an edge
 */
template <typename MAP>
Pierre Kraemer's avatar
Pierre Kraemer committed
307
class Traversor3FFaE: public Traversor3XXaY<MAP, FACE, EDGE>
308 309
{
public:
310
	Traversor3FFaE(const MAP& m, Face d, bool forceDartMarker = false, unsigned int thread = 0) : Traversor3XXaY<MAP, FACE, EDGE>(m, d, forceDartMarker, thread)	{}
311 312 313 314 315 316
};

/**
 * Traverse faces adjacent to a face by a volume
 */
template <typename MAP>
Pierre Kraemer's avatar
Pierre Kraemer committed
317
class Traversor3FFaW: public Traversor3XXaY<MAP, FACE, VOLUME>
318 319
{
public:
320
	Traversor3FFaW(const MAP& m, Face d, bool forceDartMarker = false, unsigned int thread = 0) : Traversor3XXaY<MAP, FACE, VOLUME>(m, d, forceDartMarker, thread)	{}
321
};
Pierre Kraemer's avatar
Pierre Kraemer committed
322

323
/**
324
 * Traverse volumes adjacent to a volume by a vertex
325
 */
326
template <typename MAP>
Pierre Kraemer's avatar
Pierre Kraemer committed
327
class Traversor3WWaV: public Traversor3XXaY<MAP, VOLUME, VERTEX>
328 329
{
public:
330
	Traversor3WWaV(const MAP& m, Vol d, bool forceDartMarker = false, unsigned int thread = 0) : Traversor3XXaY<MAP, VOLUME, VERTEX>(m, d, forceDartMarker, thread)	{}
331 332
};

333
/**
334
 * Traverse volumes adjacent to a volume by an edge
335
 */
336
template <typename MAP>
Pierre Kraemer's avatar
Pierre Kraemer committed
337
class Traversor3WWaE: public Traversor3XXaY<MAP, VOLUME, EDGE>
338 339
{
public:
340
	Traversor3WWaE(const MAP& m, Vol d, bool forceDartMarker = false, unsigned int thread = 0) : Traversor3XXaY<MAP, VOLUME, EDGE>(m, d, forceDartMarker, thread)	{}
341 342
};

343
/**
344
 * Traverse volumes adjacent to a volume by a face
345
 */
346
template <typename MAP>
Pierre Kraemer's avatar
Pierre Kraemer committed
347
class Traversor3WWaF: public Traversor3XXaY<MAP, VOLUME, FACE>
348 349
{
public:
350
	Traversor3WWaF(const MAP& m, Vol d, bool forceDartMarker = false, unsigned int thread = 0) : Traversor3XXaY<MAP, VOLUME, FACE>(m, d, forceDartMarker, thread)	{}
351 352
};

353

Pierre Kraemer's avatar
Pierre Kraemer committed
354
template <unsigned int ORBIT_TO, unsigned int ORBIT_FROM, typename MAP, typename FUNC>
355
inline void foreach_incident3(MAP& map, Cell<ORBIT_FROM> c, FUNC f, bool forceDartMarker = false, unsigned int thread = 0)
356 357 358 359 360 361 362
{
	Traversor3XY<MAP,ORBIT_FROM,ORBIT_TO> trav(const_cast<const MAP&>(map),c,forceDartMarker,thread);
	for (Cell<ORBIT_TO> c = trav.begin(), e = trav.end(); c.dart != e.dart; c = trav.next())
		f(c);
}


363
template <unsigned int THRU, unsigned int ORBIT, typename MAP, typename FUNC>
Pierre Kraemer's avatar
Pierre Kraemer committed
364
inline void foreach_adjacent3(MAP& map, Cell<ORBIT> c, FUNC f, bool forceDartMarker = false, unsigned int thread = 0)
365 366 367 368 369 370 371 372
{
	Traversor3XXaY<MAP,ORBIT,THRU> trav(const_cast<const MAP&>(map),c,forceDartMarker,thread);
	for (Cell<ORBIT> c = trav.begin(), e = trav.end(); c.dart != e.dart; c = trav.next())
		f(c);
}



Pierre Kraemer's avatar
Pierre Kraemer committed
373 374
} // namespace CGoGN

375
#include "Topology/generic/traversor/traversor3.hpp"
Pierre Kraemer's avatar
Pierre Kraemer committed
376 377

#endif