traversor2.h 9.96 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 28
* Contact information: cgogn@unistra.fr                                        *
*                                                                              *
*******************************************************************************/

#ifndef __TRAVERSOR2_H__
#define __TRAVERSOR2_H__

#include "Topology/generic/dart.h"
29
#include "Topology/generic/cells.h"
Pierre Kraemer's avatar
Pierre Kraemer committed
30 31 32

namespace CGoGN
{
33

Pierre Kraemer's avatar
Pierre Kraemer committed
34 35 36 37
/*******************************************************************************
					VERTEX CENTERED TRAVERSALS
*******************************************************************************/

Pierre Kraemer's avatar
Pierre Kraemer committed
38 39
// Traverse the edges incident to a given vertex
template <typename MAP>
40
class Traversor2VE
Pierre Kraemer's avatar
Pierre Kraemer committed
41 42
{
private:
Sylvain Thery's avatar
Sylvain Thery committed
43
	const MAP& m ;
44 45
	Edge start ;
	Edge current ;
Sylvain Thery's avatar
Sylvain Thery committed
46 47
	const std::vector<Dart>* m_QLT;
	std::vector<Dart>::const_iterator m_ItDarts;
Pierre Kraemer's avatar
Pierre Kraemer committed
48
public:
49
	Traversor2VE(const MAP& map, Vertex dart) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
50

51 52 53
	inline Edge begin() ;
	inline Edge end() ;
	inline Edge next() ;
Pierre Kraemer's avatar
Pierre Kraemer committed
54 55 56 57
} ;

// Traverse the faces incident to a given vertex
template <typename MAP>
58
class Traversor2VF
Pierre Kraemer's avatar
Pierre Kraemer committed
59 60
{
private:
Sylvain Thery's avatar
Sylvain Thery committed
61
	const MAP& m ;
62 63
	Face start ;
	Face current ;
Sylvain Thery's avatar
Sylvain Thery committed
64 65
	const std::vector<Dart>* m_QLT;
	std::vector<Dart>::const_iterator m_ItDarts;
Pierre Kraemer's avatar
Pierre Kraemer committed
66
public:
67
	Traversor2VF(const MAP& map, Vertex dart) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
68

69 70 71
	inline Face begin() ;
	inline Face end() ;
	inline Face next() ;
Pierre Kraemer's avatar
Pierre Kraemer committed
72 73 74 75
} ;

// Traverse the vertices adjacent to a given vertex through sharing a common edge
template <typename MAP>
76
class Traversor2VVaE
Pierre Kraemer's avatar
Pierre Kraemer committed
77 78
{
private:
Sylvain Thery's avatar
Sylvain Thery committed
79
	const MAP& m ;
80 81
	Vertex start ;
	Vertex current ;
Sylvain Thery's avatar
Sylvain Thery committed
82 83
	const std::vector<Dart>* m_QLT;
	std::vector<Dart>::const_iterator m_ItDarts;
Pierre Kraemer's avatar
Pierre Kraemer committed
84
public:
85
	Traversor2VVaE(const MAP& map, Vertex dart) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
86

87 88 89
	inline Vertex begin() ;
	inline Vertex end() ;
	inline Vertex next() ;
Pierre Kraemer's avatar
Pierre Kraemer committed
90 91 92 93
} ;

// Traverse the vertices adjacent to a given vertex through sharing a common face
template <typename MAP>
94
class Traversor2VVaF
Pierre Kraemer's avatar
Pierre Kraemer committed
95 96
{
private:
Sylvain Thery's avatar
Sylvain Thery committed
97
	const MAP& m ;
98 99
	Vertex start ;
	Vertex current ;
Pierre Kraemer's avatar
Pierre Kraemer committed
100

101
	Vertex stop ;
Sylvain Thery's avatar
Sylvain Thery committed
102 103
	const std::vector<Dart>* m_QLT;
	std::vector<Dart>::const_iterator m_ItDarts;
Pierre Kraemer's avatar
Pierre Kraemer committed
104
public:
105
	Traversor2VVaF(const MAP& map, Vertex dart) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
106

107 108 109
	inline Vertex begin() ;
	inline Vertex end() ;
	inline Vertex next() ;
Pierre Kraemer's avatar
Pierre Kraemer committed
110 111 112 113 114 115 116 117
} ;

/*******************************************************************************
					EDGE CENTERED TRAVERSALS
*******************************************************************************/

// Traverse the vertices incident to a given edge
template <typename MAP>
118
class Traversor2EV
Pierre Kraemer's avatar
Pierre Kraemer committed
119 120
{
private:
Sylvain Thery's avatar
Sylvain Thery committed
121
	const MAP& m ;
122 123
	Vertex start ;
	Vertex current ;
Sylvain Thery's avatar
Sylvain Thery committed
124 125
	const std::vector<Dart>* m_QLT;
	std::vector<Dart>::const_iterator m_ItDarts;
Pierre Kraemer's avatar
Pierre Kraemer committed
126
public:
127
	Traversor2EV(const MAP& map, Edge dart) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
128

129 130 131
	inline Vertex begin() ;
	inline Vertex end() ;
	inline Vertex next() ;
Pierre Kraemer's avatar
Pierre Kraemer committed
132 133 134 135
} ;

// Traverse the faces incident to a given edge
template <typename MAP>
136
class Traversor2EF
Pierre Kraemer's avatar
Pierre Kraemer committed
137 138
{
private:
Sylvain Thery's avatar
Sylvain Thery committed
139
	const MAP& m ;
140 141
	Face start ;
	Face current ;
Sylvain Thery's avatar
Sylvain Thery committed
142 143
	const std::vector<Dart>* m_QLT;
	std::vector<Dart>::const_iterator m_ItDarts;
Pierre Kraemer's avatar
Pierre Kraemer committed
144
public:
145
	Traversor2EF(const MAP& map, Edge dart) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
146

147 148 149
	inline Face begin() ;
	inline Face end() ;
	inline Face next() ;
Pierre Kraemer's avatar
Pierre Kraemer committed
150 151 152 153
} ;

// Traverse the edges adjacent to a given edge through sharing a common vertex
template <typename MAP>
154
class Traversor2EEaV
Pierre Kraemer's avatar
Pierre Kraemer committed
155 156
{
private:
Sylvain Thery's avatar
Sylvain Thery committed
157
	const MAP& m ;
158 159
	Edge start ;
	Edge current ;
Pierre Kraemer's avatar
Pierre Kraemer committed
160

161
	Edge stop1, stop2 ;
Sylvain Thery's avatar
Sylvain Thery committed
162 163
	const std::vector<Dart>* m_QLT;
	std::vector<Dart>::const_iterator m_ItDarts;
Pierre Kraemer's avatar
Pierre Kraemer committed
164
public:
165
	Traversor2EEaV(const MAP& map, Edge dart) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
166

167 168 169
	inline Edge begin() ;
	inline Edge end() ;
	inline Edge next() ;
Pierre Kraemer's avatar
Pierre Kraemer committed
170 171 172 173
} ;

// Traverse the edges adjacent to a given edge through sharing a common face
template <typename MAP>
174
class Traversor2EEaF
Pierre Kraemer's avatar
Pierre Kraemer committed
175 176
{
private:
Sylvain Thery's avatar
Sylvain Thery committed
177
	const MAP& m ;
178 179
	Edge start ;
	Edge current ;
Pierre Kraemer's avatar
Pierre Kraemer committed
180

181
	Edge stop1, stop2 ;
Sylvain Thery's avatar
Sylvain Thery committed
182 183
	const std::vector<Dart>* m_QLT;
	std::vector<Dart>::const_iterator m_ItDarts;
Pierre Kraemer's avatar
Pierre Kraemer committed
184
public:
185
	Traversor2EEaF(const MAP& map, Edge dart) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
186

187 188 189
	inline Edge begin() ;
	inline Edge end() ;
	inline Edge next() ;
Pierre Kraemer's avatar
Pierre Kraemer committed
190 191 192 193 194 195 196 197
} ;

/*******************************************************************************
					FACE CENTERED TRAVERSALS
*******************************************************************************/

// Traverse the vertices incident to a given face
template <typename MAP>
198
class Traversor2FV
Pierre Kraemer's avatar
Pierre Kraemer committed
199 200
{
private:
Sylvain Thery's avatar
Sylvain Thery committed
201
	const MAP& m ;
202 203
	Vertex start ;
	Vertex current ;
Sylvain Thery's avatar
Sylvain Thery committed
204 205
	const std::vector<Dart>* m_QLT;
	std::vector<Dart>::const_iterator m_ItDarts;
Pierre Kraemer's avatar
Pierre Kraemer committed
206
public:
207
	Traversor2FV(const MAP& map, Face dart) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
208

209 210 211
	inline Vertex begin() ;
	inline Vertex end() ;
	inline Vertex next() ;
Pierre Kraemer's avatar
Pierre Kraemer committed
212 213
} ;

214

215 216 217 218 219 220 221 222 223
//// Traverse the edges incident to a given face (equivalent to vertices)
//template <typename MAP>
//class Traversor2FE: public Traversor2FV<MAP>
//{
//public:
//	Traversor2FE(const MAP& map, Dart dart):Traversor2FV<MAP>(map,dart){}
//} ;

// Traverse the vertices incident to a given face
Pierre Kraemer's avatar
Pierre Kraemer committed
224
template <typename MAP>
225
class Traversor2FE
Pierre Kraemer's avatar
Pierre Kraemer committed
226
{
227 228 229 230 231 232
private:
	const MAP& m ;
	Edge start ;
	Edge current ;
	const std::vector<Dart>* m_QLT;
	std::vector<Dart>::const_iterator m_ItDarts;
Pierre Kraemer's avatar
Pierre Kraemer committed
233
public:
234 235 236 237 238
	Traversor2FE(const MAP& map, Face dart) ;

	inline Edge begin() ;
	inline Edge end() ;
	inline Edge next() ;
Pierre Kraemer's avatar
Pierre Kraemer committed
239 240
} ;

241

Pierre Kraemer's avatar
Pierre Kraemer committed
242 243
// Traverse the faces adjacent to a given face through sharing a common vertex
template <typename MAP>
244
class Traversor2FFaV
Pierre Kraemer's avatar
Pierre Kraemer committed
245 246
{
private:
Sylvain Thery's avatar
Sylvain Thery committed
247
	const MAP& m ;
248 249
	Face start ;
	Face current ;
Pierre Kraemer's avatar
Pierre Kraemer committed
250

251
	Face stop ;
Sylvain Thery's avatar
Sylvain Thery committed
252 253
	const std::vector<Dart>* m_QLT;
	std::vector<Dart>::const_iterator m_ItDarts;
Pierre Kraemer's avatar
Pierre Kraemer committed
254
public:
255
	Traversor2FFaV(const MAP& map, Face dart) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
256

257 258 259
	inline Face begin() ;
	inline Face end() ;
	inline Face next() ;
Pierre Kraemer's avatar
Pierre Kraemer committed
260 261
} ;

Pierre Kraemer's avatar
Pierre Kraemer committed
262
// Traverse the faces adjacent to a given face through sharing a common edge
thery's avatar
thery committed
263
// Warning mult-incidence is not managed (some faces can be send several times)
Pierre Kraemer's avatar
Pierre Kraemer committed
264
template <typename MAP>
265
class Traversor2FFaE
Pierre Kraemer's avatar
Pierre Kraemer committed
266 267
{
private:
Sylvain Thery's avatar
Sylvain Thery committed
268
	const MAP& m ;
269 270
	Face start ;
	Face current ;
Sylvain Thery's avatar
Sylvain Thery committed
271 272
	const std::vector<Dart>* m_QLT;
	std::vector<Dart>::const_iterator m_ItDarts;
Pierre Kraemer's avatar
Pierre Kraemer committed
273
public:
274
	Traversor2FFaE(const MAP& map, Face dart) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
275

276 277 278
	inline Face begin() ;
	inline Face end() ;
	inline Face next() ;
Pierre Kraemer's avatar
Pierre Kraemer committed
279 280
} ;

281 282 283 284 285

template <typename MAP, unsigned int F, unsigned int T>
class IncidentTrav2
{
public:
286 287
	IncidentTrav2(const MAP&, Cell<F>) {}

288 289 290 291 292 293 294 295
};


template <typename MAP>
class IncidentTrav2<MAP,VERTEX,EDGE>
{
public:
	Traversor2VE<MAP> t;
296
	IncidentTrav2(const MAP& m, Vertex d):t(m,d) {}
297 298 299 300 301 302 303
};

template <typename MAP>
class IncidentTrav2<MAP,VERTEX,FACE>
{
public:
	Traversor2VF<MAP> t;
304
	IncidentTrav2(const MAP& m, Vertex d):t(m,d) {}
305 306 307 308 309 310 311
};

template <typename MAP>
class IncidentTrav2<MAP,EDGE,VERTEX>
{
public:
	Traversor2EV<MAP> t;
312
	IncidentTrav2(const MAP& m, Edge d):t(m,d) {}
313 314 315 316 317 318 319
};

template <typename MAP>
class IncidentTrav2<MAP,EDGE,FACE>
{
public:
	Traversor2EF<MAP> t;
320
	IncidentTrav2(const MAP& m, Edge d):t(m,d) {}
321 322 323 324 325 326 327
};

template <typename MAP>
class IncidentTrav2<MAP,FACE,VERTEX>
{
public:
	Traversor2FV<MAP> t;
328
	IncidentTrav2(const MAP& m, Face d):t(m,d) {}
329 330 331 332 333 334 335
};

template <typename MAP>
class IncidentTrav2<MAP,FACE,EDGE>
{
public:
	Traversor2FE<MAP> t;
336
	IncidentTrav2(const MAP& m, Face d):t(m,d) {}
337 338 339 340 341 342 343 344
};



template <typename MAP, unsigned int F, unsigned int T>
class AdjacentTrav2
{
public:
345
	AdjacentTrav2(const MAP&, Cell<F>) {}
346 347 348 349 350 351 352 353
};


template <typename MAP>
class AdjacentTrav2<MAP,VERTEX,EDGE>
{
public:
	Traversor2VVaE<MAP> t;
354
	AdjacentTrav2(const MAP& m, Vertex d):t(m,d) {}
355 356 357 358 359 360 361
};

template <typename MAP>
class AdjacentTrav2<MAP,VERTEX,FACE>
{
public:
	Traversor2VVaF<MAP> t;
362
	AdjacentTrav2(const MAP& m, Vertex d):t(m,d) {}
363 364 365 366 367 368 369
};

template <typename MAP>
class AdjacentTrav2<MAP,EDGE,VERTEX>
{
public:
	Traversor2EEaV<MAP> t;
370
	AdjacentTrav2(const MAP& m, Edge d):t(m,d) {}
371 372 373 374 375 376 377
};

template <typename MAP>
class AdjacentTrav2<MAP,EDGE,FACE>
{
public:
	Traversor2EEaF<MAP> t;
378
	AdjacentTrav2(const MAP& m, Edge d):t(m,d) {}
379 380 381 382 383 384 385
};

template <typename MAP>
class AdjacentTrav2<MAP,FACE,VERTEX>
{
public:
	Traversor2FFaV<MAP> t;
386
	AdjacentTrav2(const MAP& m, Face d):t(m,d) {}
387 388 389 390 391 392 393
};

template <typename MAP>
class AdjacentTrav2<MAP,FACE,EDGE>
{
public:
	Traversor2FFaE<MAP> t;
394
	AdjacentTrav2(const MAP& m, Face d):t(m,d) {}
395 396 397
};


Pierre Kraemer's avatar
Pierre Kraemer committed
398
template <unsigned int ORBIT_TO, unsigned int ORBIT_FROM, typename MAP, typename FUNC>
Pierre Kraemer's avatar
Pierre Kraemer committed
399
inline void foreach_incident2(MAP& map, Cell<ORBIT_FROM> c, FUNC f)
400 401 402 403 404 405
{
	IncidentTrav2<MAP,ORBIT_FROM,ORBIT_TO> trav(const_cast<const MAP&>(map),c);
	for (Cell<ORBIT_TO> c = trav.t.begin(), e = trav.t.end(); c.dart != e.dart; c = trav.t.next())
		f(c);
}

406
template <unsigned int THRU, unsigned int ORBIT, typename MAP, typename FUNC>
Pierre Kraemer's avatar
Pierre Kraemer committed
407
inline void foreach_adjacent2(MAP& map, Cell<ORBIT> c, FUNC f)
408 409 410 411 412 413
{
	AdjacentTrav2<MAP,ORBIT,THRU> trav(const_cast<const MAP&>(map),c);
	for (Cell<ORBIT> c = trav.t.begin(), e = trav.t.end(); c.dart != e.dart; c = trav.t.next())
		f(c);
}

Pierre Kraemer's avatar
Pierre Kraemer committed
414 415
} // namespace CGoGN

416
#include "Topology/generic/traversor/traversor2.hpp"
Pierre Kraemer's avatar
Pierre Kraemer committed
417

Pierre Kraemer's avatar
Pierre Kraemer committed
418
#endif