cellmarker.h 13 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 __CELL_MARKER__
#define __CELL_MARKER__

#include "Topology/generic/marker.h"
Sylvain Thery's avatar
Sylvain Thery committed
29
#include "Topology/generic/genericmap.h"
Sylvain Thery's avatar
Sylvain Thery committed
30
#include "Topology/generic/functor.h"
31
32
#include "Algo/Topo/embedding.h"

33
#include "Utils/static_assert.h"
Pierre Kraemer's avatar
Pierre Kraemer committed
34
35
36

namespace CGoGN
{
Sylvain Thery's avatar
Sylvain Thery committed
37
38
39
40
/**
 * @brief The CellMarkerGen class
 * @warning CellMarkerGen is no polymorphic version of CellMarker
 */
41
class CellMarkerGen
Pierre Kraemer's avatar
Pierre Kraemer committed
42
{
43
44
	friend class GenericMap ;

Pierre Kraemer's avatar
Pierre Kraemer committed
45
protected:
Sylvain Thery's avatar
Sylvain Thery committed
46
	AttributeMultiVector<MarkerBool>* m_markVector ;
47
	unsigned int m_cell ;
Sylvain Thery's avatar
Sylvain Thery committed
48
	unsigned int m_thread;
Pierre Kraemer's avatar
Pierre Kraemer committed
49

50
public:
51
	CellMarkerGen(unsigned int cell, unsigned int thread = 0) :
Sylvain Thery's avatar
Sylvain Thery committed
52
		m_cell(cell),m_thread(thread)
53
54
	{}

Pierre Kraemer's avatar
Pierre Kraemer committed
55
	virtual ~CellMarkerGen()
56
57
	{}

58
59
	unsigned int getCell() { return m_cell ; }

60
61
62
63
64
protected:
	// protected copy constructor to forbid its usage
	CellMarkerGen(const CellMarkerGen& /*cm*/)
	{}

65
66
67
68
69
70
};

/**
 * generic class that allows the marking of cells
 * \warning no default constructor
 */
71
template <typename MAP, unsigned int CELL>
72
73
class CellMarkerBase : public CellMarkerGen
{
74
75
76
protected:
	MAP& m_map ;

Pierre Kraemer's avatar
Pierre Kraemer committed
77
78
79
public:
	/**
	 * constructor
80
	 * @param map the map on which we work
Pierre Kraemer's avatar
Pierre Kraemer committed
81
	 */
82
83
84
	CellMarkerBase(MAP& map, unsigned int thread = 0) :
		CellMarkerGen(CELL, thread),
		m_map(map)
Pierre Kraemer's avatar
Pierre Kraemer committed
85
	{
86
87
		if(!m_map.template isOrbitEmbedded<CELL>())
			m_map.template addEmbedding<CELL>() ;
Sylvain Thery's avatar
Sylvain Thery committed
88
		m_markVector = m_map.template askMarkVector<CELL>(m_thread);
Sylvain Thery's avatar
Sylvain Thery committed
89
90
	}

91
92
93
	CellMarkerBase(const MAP& map, unsigned int thread = 0) :
		CellMarkerGen(CELL, thread),
		m_map(const_cast<MAP&>(map))
Sylvain Thery's avatar
Sylvain Thery committed
94
	{
95
96
		if(!m_map.template isOrbitEmbedded<CELL>())
			m_map.template addEmbedding<CELL>() ;
Sylvain Thery's avatar
Sylvain Thery committed
97
		m_markVector = m_map.template askMarkVector<CELL>(m_thread);
Sylvain Thery's avatar
Sylvain Thery committed
98
99
	}

Pierre Kraemer's avatar
Pierre Kraemer committed
100
	virtual ~CellMarkerBase()
Pierre Kraemer's avatar
Pierre Kraemer committed
101
	{
102
		if (GenericMap::alive(&m_map))
Sylvain Thery's avatar
Sylvain Thery committed
103
			m_map.template releaseMarkVector<CELL>(m_markVector,m_thread);
Pierre Kraemer's avatar
Pierre Kraemer committed
104
105
	}

106
107
108
109
	/**
	 * @brief update: realloc the marker in map
	 * @warning call only after map cleaning
	 */
Sylvain Thery's avatar
Sylvain Thery committed
110
111
112
113
	void update()
	{
		if(!m_map.template isOrbitEmbedded<CELL>())
			m_map.template addEmbedding<CELL>() ;
Sylvain Thery's avatar
Sylvain Thery committed
114
		m_markVector = m_map.template askMarkVector<CELL>(m_thread);
Sylvain Thery's avatar
Sylvain Thery committed
115
116
117
	}


Pierre Kraemer's avatar
Pierre Kraemer committed
118
119
protected:
	// protected copy constructor to forbid its usage
120
121
122
	CellMarkerBase(const CellMarkerBase<MAP, CELL>& cm) :
		m_map(cm.m_map),
		CellMarkerGen(CELL)
Pierre Kraemer's avatar
Pierre Kraemer committed
123
124
125
126
127
128
	{}

public:
	/**
	 * mark the cell of dart
	 */
129
	inline void mark(Cell<CELL> c)
Pierre Kraemer's avatar
Pierre Kraemer committed
130
	{
Pierre Kraemer's avatar
Pierre Kraemer committed
131
		assert(m_markVector != NULL);
Sylvain Thery's avatar
Sylvain Thery committed
132

133
		unsigned int a = m_map.getEmbedding(c) ;
134

Sylvain Thery's avatar
Sylvain Thery committed
135
		if (a == EMBNULL)
136
137
			a = Algo::Topo::setOrbitEmbeddingOnNewCell(m_map, c) ;

Sylvain Thery's avatar
Sylvain Thery committed
138
		m_markVector->setTrue(a);
Pierre Kraemer's avatar
Pierre Kraemer committed
139
140
141
142
143
	}

	/**
	 * unmark the cell of dart
	 */
144
	inline void unmark(Cell<CELL> c)
Pierre Kraemer's avatar
Pierre Kraemer committed
145
	{
146
		assert(m_markVector != NULL);
Sylvain Thery's avatar
Sylvain Thery committed
147

148
		unsigned int a = m_map.getEmbedding(c) ;
149

Sylvain Thery's avatar
Sylvain Thery committed
150
		if (a == EMBNULL)
151
152
			a = Algo::Topo::setOrbitEmbeddingOnNewCell(m_map, c) ;

Sylvain Thery's avatar
Sylvain Thery committed
153
		m_markVector->setFalse(a);
Pierre Kraemer's avatar
Pierre Kraemer committed
154
155
156
157
158
	}

	/**
	 * test if cell of dart is marked
	 */
159
	inline bool isMarked(Cell<CELL> c) const
Pierre Kraemer's avatar
Pierre Kraemer committed
160
	{
161
		assert(m_markVector != NULL);
Sylvain Thery's avatar
Sylvain Thery committed
162

163
		unsigned int a = m_map.getEmbedding(c) ;
164

Sylvain Thery's avatar
Sylvain Thery committed
165
166
		if (a == EMBNULL)
			return false ;
167

Sylvain Thery's avatar
Sylvain Thery committed
168
		return m_markVector->operator[](a);
Pierre Kraemer's avatar
Pierre Kraemer committed
169
170
171
172
173
	}

	/**
	 * mark the cell
	 */
Sylvain Thery's avatar
Sylvain Thery committed
174
	inline void mark(unsigned int em)
Pierre Kraemer's avatar
Pierre Kraemer committed
175
	{
176
		assert(m_markVector != NULL);
Sylvain Thery's avatar
Sylvain Thery committed
177
		m_markVector->setTrue(em);
Pierre Kraemer's avatar
Pierre Kraemer committed
178
179
180
181
182
	}

	/**
	 * unmark the cell
	 */
Sylvain Thery's avatar
Sylvain Thery committed
183
	inline void unmark(unsigned int em)
Pierre Kraemer's avatar
Pierre Kraemer committed
184
	{
185
		assert(m_markVector != NULL);
Sylvain Thery's avatar
Sylvain Thery committed
186
		m_markVector->setFalse(em);
Pierre Kraemer's avatar
Pierre Kraemer committed
187
188
189
190
191
	}

	/**
	 * test if cell is marked
	 */
Sylvain Thery's avatar
Sylvain Thery committed
192
	inline bool isMarked(unsigned int em) const
Pierre Kraemer's avatar
Pierre Kraemer committed
193
	{
194
		assert(m_markVector != NULL);
Sylvain Thery's avatar
Sylvain Thery committed
195

Pierre Kraemer's avatar
Pierre Kraemer committed
196
197
		if (em == EMBNULL)
			return false ;
Sylvain Thery's avatar
Sylvain Thery committed
198
		return m_markVector->operator[](em);
Pierre Kraemer's avatar
Pierre Kraemer committed
199
200
	}

201
202
203
	/**
	 * mark all the cells
	 */
Sylvain Thery's avatar
Sylvain Thery committed
204
	inline void markAll()
Pierre Kraemer's avatar
Pierre Kraemer committed
205
	{
206
		assert(m_markVector != NULL);
207
208
209
210
211
212
213

		AttributeContainer& cont = m_map.template getAttributeContainer<CELL>() ;
		if (cont.hasBrowser())
			for (unsigned int i = cont.begin(); i != cont.end(); cont.next(i))
				this->m_markVector->setTrue(i);
		else
			m_markVector->allTrue();
Pierre Kraemer's avatar
Pierre Kraemer committed
214
215
	}

Sylvain Thery's avatar
Sylvain Thery committed
216
	inline bool isAllUnmarked()
Pierre Kraemer's avatar
Pierre Kraemer committed
217
	{
218
		assert(m_markVector != NULL);
Sylvain Thery's avatar
Sylvain Thery committed
219

220
		AttributeContainer& cont = m_map.template getAttributeContainer<CELL>() ;
221
222
223
224
		if (cont.hasBrowser())
		{
			for (unsigned int i = cont.begin(); i != cont.end(); cont.next(i))
				if(m_markVector->operator[](i))
Pierre Kraemer's avatar
Pierre Kraemer committed
225
				return false ;
226
227
228
229
			return true ;
		}
		//else
		return m_markVector->isAllFalse();
Pierre Kraemer's avatar
Pierre Kraemer committed
230
	}
231
232
233
234
235
236
};

/**
 * class that allows the marking of cells
 * \warning no default constructor
 */
237
238
template <typename MAP, unsigned int CELL>
class CellMarker : public CellMarkerBase<MAP, CELL>
239
240
{
public:
241
	CellMarker(MAP& map, unsigned int thread = 0) : CellMarkerBase<MAP, CELL>(map, thread)
242
243
	{}

244
245
	CellMarker(const MAP& map, unsigned int thread = 0) :
		CellMarkerBase<MAP, CELL>(map, thread)
Sylvain Thery's avatar
Sylvain Thery committed
246
247
	{}

Pierre Kraemer's avatar
Pierre Kraemer committed
248
	virtual ~CellMarker()
249
250
251
252
253
	{
		unmarkAll() ;
	}

protected:
254
255
	CellMarker(const CellMarker& cm) :
		CellMarkerBase<MAP, CELL>(cm)
256
257
258
	{}

public:
Sylvain Thery's avatar
Sylvain Thery committed
259
	inline void unmarkAll()
Pierre Kraemer's avatar
Pierre Kraemer committed
260
	{
Pierre Kraemer's avatar
Pierre Kraemer committed
261
		assert(this->m_markVector != NULL);
262
263
264
265
266
267
268

		AttributeContainer& cont = this->m_map.template getAttributeContainer<CELL>() ;
		if (cont.hasBrowser())
			for (unsigned int i = cont.begin(); i != cont.end(); cont.next(i))
				this->m_markVector->setFalse(i);
		else
			this->m_markVector->allFalse();
Pierre Kraemer's avatar
Pierre Kraemer committed
269
270
271
272
273
274
275
276
	}
};

/**
 * class that allows the marking of cells
 * the marked cells are stored to optimize the unmarking task at destruction
 * \warning no default constructor
 */
277
278
template <typename MAP, unsigned int CELL>
class CellMarkerStore: public CellMarkerBase<MAP, CELL>
Pierre Kraemer's avatar
Pierre Kraemer committed
279
280
{
protected:
Sylvain Thery's avatar
Sylvain Thery committed
281
	std::vector<unsigned int>* m_markedCells ;
Pierre Kraemer's avatar
Pierre Kraemer committed
282
283

public:
284
285
	CellMarkerStore(MAP& map, unsigned int thread = 0) :
		CellMarkerBase<MAP, CELL>(map, thread)
286
	{
Sylvain Thery's avatar
Sylvain Thery committed
287
288
//		m_markedCells.reserve(128);
		m_markedCells = GenericMap::askUIntBuffer(thread);
289
	}
Pierre Kraemer's avatar
Pierre Kraemer committed
290

291
292
	CellMarkerStore(const MAP& map, unsigned int thread = 0) :
		CellMarkerBase<MAP, CELL>(map, thread)
293
	{
Sylvain Thery's avatar
Sylvain Thery committed
294
295
//		m_markedCells.reserve(128);
		m_markedCells = GenericMap::askUIntBuffer(thread);
296
	}
Sylvain Thery's avatar
Sylvain Thery committed
297

Pierre Kraemer's avatar
Pierre Kraemer committed
298
	virtual ~CellMarkerStore()
299
	{
300
		unmarkAll() ;
Sylvain Thery's avatar
Sylvain Thery committed
301
		GenericMap::releaseUIntBuffer(m_markedCells, this->m_thread);
302
//		assert(isAllUnmarked);
Pierre Kraemer's avatar
Pierre Kraemer committed
303
//		CGoGN_ASSERT(this->isAllUnmarked())
304
305
	}

Pierre Kraemer's avatar
Pierre Kraemer committed
306
protected:
307
308
	CellMarkerStore(const CellMarkerStore& cm) :
		CellMarkerBase<MAP, CELL>(cm)
Pierre Kraemer's avatar
Pierre Kraemer committed
309
310
311
	{}

public:
Pierre Kraemer's avatar
Pierre Kraemer committed
312
	inline void mark(Cell<CELL> d)
Pierre Kraemer's avatar
Pierre Kraemer committed
313
	{
314
		CellMarkerBase<MAP, CELL>::mark(d) ;
Sylvain Thery's avatar
Sylvain Thery committed
315
		m_markedCells->push_back(this->m_map.template getEmbedding<CELL>(d)) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
316
317
	}

Sylvain Thery's avatar
Sylvain Thery committed
318
	inline void mark(unsigned int em)
Pierre Kraemer's avatar
Pierre Kraemer committed
319
	{
320
		CellMarkerBase<MAP, CELL>::mark(em) ;
Sylvain Thery's avatar
Sylvain Thery committed
321
		m_markedCells->push_back(em) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
322
323
	}

Sylvain Thery's avatar
Sylvain Thery committed
324
	inline void unmarkAll()
Pierre Kraemer's avatar
Pierre Kraemer committed
325
	{
Pierre Kraemer's avatar
Pierre Kraemer committed
326
		assert(this->m_markVector != NULL);
Sylvain Thery's avatar
Sylvain Thery committed
327

Sylvain Thery's avatar
Sylvain Thery committed
328
		for (std::vector<unsigned int>::iterator it = m_markedCells->begin(); it != m_markedCells->end(); ++it)
Sylvain Thery's avatar
Sylvain Thery committed
329
			this->m_markVector->setFalse(*it);
Pierre Kraemer's avatar
Pierre Kraemer committed
330
331
	}
};
332

pitiot's avatar
pitiot committed
333
334
335
336
337
/**
 * class that allows the marking of Darts
 * the marked Darts are stored to optimize the unmarking task at destruction
 * \warning no default constructor
 */
338
339
template <typename MAP, unsigned int CELL>
class CellMarkerMemo: public CellMarkerBase<MAP, CELL>
pitiot's avatar
pitiot committed
340
341
342
343
344
{
protected:
	std::vector<Dart> m_markedDarts ;

public:
345
346
	CellMarkerMemo(MAP& map, unsigned int thread = 0) :
		CellMarkerBase<MAP, CELL>(map, thread)
347
348
349
	{
		m_markedDarts.reserve(128);
	}
pitiot's avatar
pitiot committed
350

351
352
	CellMarkerMemo(const MAP& map, unsigned int thread = 0) :
		CellMarkerBase<MAP, CELL>(map, thread)
353
354
355
	{
		m_markedDarts.reserve(128);
	}
Sylvain Thery's avatar
Sylvain Thery committed
356

Pierre Kraemer's avatar
Pierre Kraemer committed
357
	virtual ~CellMarkerMemo()
pitiot's avatar
pitiot committed
358
359
360
	{
		unmarkAll() ;
//		assert(isAllUnmarked);
Pierre Kraemer's avatar
Pierre Kraemer committed
361
//		CGoGN_ASSERT(this->isAllUnmarked())
pitiot's avatar
pitiot committed
362
363
364
	}

protected:
365
366
	CellMarkerMemo(const CellMarkerMemo& cm) :
		CellMarkerBase<MAP, CELL>(cm)
pitiot's avatar
pitiot committed
367
	{}
Pierre Kraemer's avatar
Pierre Kraemer committed
368

pitiot's avatar
pitiot committed
369
public:
Pierre Kraemer's avatar
Pierre Kraemer committed
370
	inline void mark(Cell<CELL> c)
pitiot's avatar
pitiot committed
371
	{
Pierre Kraemer's avatar
Pierre Kraemer committed
372
		if(!this->isMarked(c))
pitiot's avatar
pitiot committed
373
		{
Pierre Kraemer's avatar
Pierre Kraemer committed
374
375
			CellMarkerBase<MAP, CELL>::mark(c) ;
			m_markedDarts.push_back(c.dart) ;
pitiot's avatar
pitiot committed
376
377
378
		}
	}

Sylvain Thery's avatar
Sylvain Thery committed
379
	inline void unmarkAll()
pitiot's avatar
pitiot committed
380
381
382
	{
		assert(this->m_markVector != NULL);
		for (std::vector<Dart>::iterator it = m_markedDarts.begin(); it != m_markedDarts.end(); ++it)
pitiot's avatar
pitiot committed
383
384
385
		{
			this->unmark(*it) ;
		}
386
		m_markedDarts.clear();
pitiot's avatar
pitiot committed
387

pitiot's avatar
pitiot committed
388
	}
Sylvain Thery's avatar
Sylvain Thery committed
389

390
	inline const std::vector<Dart>& get_markedCells()
pitiot's avatar
pitiot committed
391
392
393
394
	{
		return m_markedDarts;
	}
};
395

Pierre Kraemer's avatar
Pierre Kraemer committed
396
397
398
399
400
/**
 * class that allows the marking of cells
 * the markers are not unmarked at destruction
 * \warning no default constructor
 */
401
402
template <typename MAP, unsigned int CELL>
class CellMarkerNoUnmark: public CellMarkerBase<MAP, CELL>
Pierre Kraemer's avatar
Pierre Kraemer committed
403
{
404
405
406
#ifndef NDEBUG
	int m_counter;
#endif
Pierre Kraemer's avatar
Pierre Kraemer committed
407
public:
408
409
	CellMarkerNoUnmark(MAP& map, unsigned int thread = 0) :
		CellMarkerBase<MAP, CELL>(map, thread)
410
411
412
  #ifndef NDEBUG
		,m_counter(0)
  #endif
Pierre Kraemer's avatar
Pierre Kraemer committed
413
	{}
Sylvain Thery's avatar
Sylvain Thery committed
414

415
416
	CellMarkerNoUnmark(const MAP& map, unsigned int thread = 0) :
		CellMarkerBase<MAP, CELL>(map, thread)
417
418
419
  #ifndef NDEBUG
		,m_counter(0)
  #endif
Sylvain Thery's avatar
Sylvain Thery committed
420
421
	{}

Pierre Kraemer's avatar
Pierre Kraemer committed
422
	virtual ~CellMarkerNoUnmark()
Pierre Kraemer's avatar
Pierre Kraemer committed
423
	{
424
425
426
427
428
429
430
431
#ifndef NDEBUG
		if (m_counter != 0)
		{
			CGoGNerr << "CellMarkerNoUnmark: Warning problem unmarking not complete"<< CGoGNendl;
			CGoGNerr << "CellMarkerNoUnmark:  -> calling unmarkAll()"<< CGoGNendl;
			unmarkAll();
		}
#endif
Pierre Kraemer's avatar
Pierre Kraemer committed
432
	}
Pierre Kraemer's avatar
Pierre Kraemer committed
433
434

protected:
435
436
	CellMarkerNoUnmark(const CellMarkerNoUnmark& cm) :
		CellMarkerBase<MAP, CELL>(cm)
437
438
439
  #ifndef NDEBUG
		,m_counter(cm.m_counter)
  #endif
Pierre Kraemer's avatar
Pierre Kraemer committed
440
	{}
441
442

public:
Sylvain Thery's avatar
Sylvain Thery committed
443
	inline void unmarkAll()
444
	{
Pierre Kraemer's avatar
Pierre Kraemer committed
445
		assert(this->m_markVector != NULL);
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478

		AttributeContainer& cont = this->m_map.template getAttributeContainer<CELL>() ;
		if (cont.hasBrowser())
			for (unsigned int i = cont.begin(); i != cont.end(); cont.next(i))
				this->m_markVector->setFalse(i);
		else
			this->m_markVector->allFalse();
	}


#ifndef NDEBUG
	inline void mark(Cell<CELL> c)
	{
		if (this->isMarked(c))
			return;
		CellMarkerBase<MAP, CELL>::mark(c) ;
		m_counter++;
	}

	inline void unmark(Cell<CELL> c)
	{
		if (!this->isMarked(c))
			return;
		CellMarkerBase<MAP, CELL>::unmark(c) ;
		m_counter--;
	}

	inline void mark(unsigned int i)
	{
		if (this->isMarked(i))
			return;
		CellMarkerBase<MAP, CELL>::mark(i) ;
		m_counter++;
479
	}
480
481
482
483
484
485
486
487
488
489
490
491
492

	/**
	 * unmark the dart
	 */
	inline void unmark(unsigned int i)
	{
		if (!this->isMarked(i))
			return;
		CellMarkerBase<MAP, CELL>::unmark(i) ;
		m_counter--;
	}

#endif
Pierre Kraemer's avatar
Pierre Kraemer committed
493
494
};

495
496
// Selector and count functors testing for marker existence
/********************************************************/
Sylvain Thery's avatar
Sylvain Thery committed
497
498

/**
499
 * selector that say if a dart has its cell marked
Sylvain Thery's avatar
Sylvain Thery committed
500
 */
501
template <typename MAP, unsigned int CELL>
502
class SelectorCellMarked : public FunctorSelect
Sylvain Thery's avatar
Sylvain Thery committed
503
504
{
protected:
505
506
	const CellMarkerBase<MAP, CELL>& m_cmarker ;

Sylvain Thery's avatar
Sylvain Thery committed
507
public:
508
509
510
	SelectorCellMarked(const CellMarkerBase<MAP, CELL>& cm) :
		m_cmarker(cm)
	{}
Sylvain Thery's avatar
Sylvain Thery committed
511

Pierre Kraemer's avatar
Pierre Kraemer committed
512
	inline bool operator()(Cell<CELL> d) const
Sylvain Thery's avatar
Sylvain Thery committed
513
514
	{
		if (m_cmarker.isMarked(d))
515
516
			return true ;
		return false ;
Sylvain Thery's avatar
Sylvain Thery committed
517
	}
Pierre Kraemer's avatar
Pierre Kraemer committed
518

Sylvain Thery's avatar
Sylvain Thery committed
519
	inline FunctorSelect* copy() const { return new SelectorCellMarked(m_cmarker); }
Sylvain Thery's avatar
Sylvain Thery committed
520
521
};

522
template <typename MAP, unsigned int CELL>
523
class SelectorCellUnmarked : public FunctorSelect
524
525
{
protected:
526
527
	const CellMarkerBase<MAP, CELL>& m_cmarker ;

528
public:
529
530
531
532
	SelectorCellUnmarked(const CellMarkerBase<MAP, CELL>& cm) :
		m_cmarker(cm)
	{}

Pierre Kraemer's avatar
Pierre Kraemer committed
533
	inline bool operator()(Cell<CELL> d) const
534
535
	{
		if (!m_cmarker.isMarked(d))
536
537
			return true ;
		return false ;
538
	}
539
540
541
542
543

	inline FunctorSelect* copy() const
	{
		return new SelectorCellUnmarked(m_cmarker);
	}
544
};
Sylvain Thery's avatar
Sylvain Thery committed
545

Thomas's avatar
Thomas committed
546
547
// Functor version (needed for use with foreach_xxx)

548
template <typename MAP, unsigned int CELL>
Thomas's avatar
Thomas committed
549
550
551
class FunctorCellIsMarked : public FunctorType
{
protected:
552
553
	CellMarkerBase<MAP, CELL>& m_marker;

Thomas's avatar
Thomas committed
554
public:
555
556
557
558
	FunctorCellIsMarked(CellMarkerBase<MAP, CELL>& cm) :
		m_marker(cm)
	{}

Pierre Kraemer's avatar
Pierre Kraemer committed
559
	inline bool operator()(Cell<CELL> d)
Thomas's avatar
Thomas committed
560
561
562
563
564
	{
		return m_marker.isMarked(d);
	}
};

565
template <typename MAP, unsigned int CELL>
Thomas's avatar
Thomas committed
566
567
568
class FunctorCellIsUnmarked : public FunctorType
{
protected:
569
	CellMarkerBase<MAP, CELL>& m_marker;
Thomas's avatar
Thomas committed
570
public:
571
572
573
574
	FunctorCellIsUnmarked(CellMarkerBase<MAP, CELL>& cm) :
		m_marker(cm)
	{}

Pierre Kraemer's avatar
Pierre Kraemer committed
575
	inline bool operator()(Cell<CELL> d)
Thomas's avatar
Thomas committed
576
577
578
579
580
	{
		return !m_marker.isMarked(d);
	}
};

Pierre Kraemer's avatar
Pierre Kraemer committed
581
582
583
} // namespace CGoGN

#endif