dartmarker.h 9.82 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
* Contact information: cgogn@unistra.fr                                        *
*                                                                              *
*******************************************************************************/

#ifndef __DART_MARKER__
#define __DART_MARKER__

#include "Topology/generic/marker.h"
#include "Topology/generic/genericmap.h"
#include "Topology/generic/functor.h"

namespace CGoGN
{

// Marker Functors
/********************************************************/

template <typename MAP>
class FunctorMarker : public FunctorMap<MAP>
{
protected:
Pierre Kraemer's avatar
Pierre Kraemer committed
42
43
	Mark m_mark ;
	AttributeMultiVector<Mark>* m_markTable ;
Pierre Kraemer's avatar
Pierre Kraemer committed
44
public:
Pierre Kraemer's avatar
Pierre Kraemer committed
45
46
47
	FunctorMarker(MAP& map, Mark m, AttributeMultiVector<Mark>* mTable) : FunctorMap<MAP>(map), m_mark(m), m_markTable(mTable)
	{}
//	Mark getMark() { return m_mark ; }
48
} ;
Pierre Kraemer's avatar
Pierre Kraemer committed
49
50

template <typename MAP>
51
class FunctorMark : public FunctorMarker<MAP>
Pierre Kraemer's avatar
Pierre Kraemer committed
52
53
{
public:
Pierre Kraemer's avatar
Pierre Kraemer committed
54
55
	FunctorMark(MAP& map, Mark m, AttributeMultiVector<Mark>* mTable) : FunctorMarker<MAP>(map, m, mTable)
	{}
Pierre Kraemer's avatar
Pierre Kraemer committed
56
57
	bool operator()(Dart d)
	{
Pierre Kraemer's avatar
Pierre Kraemer committed
58
		this->m_markTable->operator[](d.index).setMark(this->m_mark) ;
59
		return false ;
Pierre Kraemer's avatar
Pierre Kraemer committed
60
	}
61
} ;
Pierre Kraemer's avatar
Pierre Kraemer committed
62
63

template <typename MAP>
64
class FunctorMarkStore : public FunctorMarker<MAP>
Pierre Kraemer's avatar
Pierre Kraemer committed
65
{
66
67
protected:
	std::vector<unsigned int>& m_markedDarts ;
Pierre Kraemer's avatar
Pierre Kraemer committed
68
public:
Pierre Kraemer's avatar
Pierre Kraemer committed
69
	FunctorMarkStore(MAP& map, Mark m, AttributeMultiVector<Mark>* mTable, std::vector<unsigned int>& marked) :
70
71
72
		FunctorMarker<MAP>(map, m, mTable),
		m_markedDarts(marked)
	{}
Pierre Kraemer's avatar
Pierre Kraemer committed
73
74
	bool operator()(Dart d)
	{
Pierre Kraemer's avatar
Pierre Kraemer committed
75
		this->m_markTable->operator[](d.index).setMark(this->m_mark) ;
76
77
		m_markedDarts.push_back(d.index) ;
		return false ;
Pierre Kraemer's avatar
Pierre Kraemer committed
78
	}
79
} ;
Pierre Kraemer's avatar
Pierre Kraemer committed
80

81
82
83
84
template <typename MAP>
class FunctorUnmark : public FunctorMarker<MAP>
{
public:
Pierre Kraemer's avatar
Pierre Kraemer committed
85
86
	FunctorUnmark(MAP& map, Mark m, AttributeMultiVector<Mark>* mTable) : FunctorMarker<MAP>(map, m, mTable)
	{}
87
88
	bool operator()(Dart d)
	{
Pierre Kraemer's avatar
Pierre Kraemer committed
89
		this->m_markTable->operator[](d.index).unsetMark(this->m_mark) ;
90
91
92
		return false ;
	}
} ;
Pierre Kraemer's avatar
Pierre Kraemer committed
93
94

/**
95
 * generic class that allows the marking of darts
Pierre Kraemer's avatar
Pierre Kraemer committed
96
97
 * \warning no default constructor
 */
98
class DartMarkerGen
Pierre Kraemer's avatar
Pierre Kraemer committed
99
100
{
protected:
101
102
103
	GenericMap& m_map ;
	unsigned int m_thread ;
	Mark m_mark ;
Pierre Kraemer's avatar
merge..    
Pierre Kraemer committed
104

Pierre Kraemer's avatar
Pierre Kraemer committed
105
106
107
108
109
public:
	/**
	 * constructor
	 * @param map the map on which we work
	 */
110
	DartMarkerGen(GenericMap& map): m_map(map), m_thread(0)
Pierre Kraemer's avatar
Pierre Kraemer committed
111
	{
112
		m_mark = m_map.m_marksets[DART][m_thread].getNewMark() ;
Sylvain Thery's avatar
Sylvain Thery committed
113
114
	}

115
	DartMarkerGen(GenericMap& map, unsigned int thread): m_map(map), m_thread(thread)
Sylvain Thery's avatar
Sylvain Thery committed
116
	{
117
		m_mark = m_map.m_marksets[DART][m_thread].getNewMark() ;
Pierre Kraemer's avatar
Pierre Kraemer committed
118
119
	}

120
	virtual ~DartMarkerGen()
Pierre Kraemer's avatar
Pierre Kraemer committed
121
	{
122
		m_map.m_marksets[DART][m_thread].releaseMark(m_mark) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
123
124
125
126
	}

protected:
	// protected copy constructor to forbid its usage
127
	DartMarkerGen(const DartMarkerGen& dm) : m_map(dm.m_map)
Pierre Kraemer's avatar
Pierre Kraemer committed
128
129
130
131
	{}

public:
	/**
132
	 * mark the dart
Pierre Kraemer's avatar
Pierre Kraemer committed
133
134
135
	 */
	virtual void mark(Dart d)
	{
Pierre Kraemer's avatar
Pierre Kraemer committed
136
		m_map.getMarkVector(DART, m_thread)->operator[](d.index).setMark(m_mark);
Pierre Kraemer's avatar
Pierre Kraemer committed
137
138
139
	}

	/**
140
	 * unmark the dart
Pierre Kraemer's avatar
Pierre Kraemer committed
141
142
143
	 */
	virtual void unmark(Dart d)
	{
Pierre Kraemer's avatar
Pierre Kraemer committed
144
		m_map.getMarkVector(DART, m_thread)->operator[](d.index).unsetMark(m_mark);
Pierre Kraemer's avatar
Pierre Kraemer committed
145
146
147
	}

	/**
148
	 * test if dart is marked
Pierre Kraemer's avatar
Pierre Kraemer committed
149
150
151
	 */
	virtual bool isMarked(Dart d)
	{
Pierre Kraemer's avatar
Pierre Kraemer committed
152
		return m_map.getMarkVector(DART, m_thread)->operator[](d.index).testMark(m_mark);
Pierre Kraemer's avatar
Pierre Kraemer committed
153
154
155
	}

	/**
156
	 * mark the darts of the given orbit of d
Pierre Kraemer's avatar
Pierre Kraemer committed
157
	 */
158
	virtual void markOrbit(unsigned int orbit, Dart d)
Pierre Kraemer's avatar
Pierre Kraemer committed
159
	{
Pierre Kraemer's avatar
Pierre Kraemer committed
160
		FunctorMark<GenericMap> fm(m_map, m_mark, m_map.getMarkVector(DART, m_thread)) ;
161
		m_map.foreach_dart_of_orbit(orbit, d, fm, m_thread) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
162
163
164
	}

	/**
165
	 * unmark the darts of the given orbit of d
Pierre Kraemer's avatar
Pierre Kraemer committed
166
	 */
167
	virtual void unmarkOrbit(unsigned int orbit, Dart d)
Pierre Kraemer's avatar
Pierre Kraemer committed
168
	{
Pierre Kraemer's avatar
Pierre Kraemer committed
169
		FunctorUnmark<GenericMap> fm(m_map, m_mark, m_map.getMarkVector(DART, m_thread)) ;
170
		m_map.foreach_dart_of_orbit(orbit, d, fm, m_thread) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
171
172
173
	}

	/**
174
	 * mark the darts of the given orbit of d in the parent map
Pierre Kraemer's avatar
Pierre Kraemer committed
175
	 */
176
177
	template <typename MAP>
	void markOrbitInParent(unsigned int orbit, Dart d)
Pierre Kraemer's avatar
Pierre Kraemer committed
178
	{
Pierre Kraemer's avatar
Pierre Kraemer committed
179
		FunctorMark<GenericMap> fm(m_map, m_mark, m_map.getMarkVector(DART, m_thread)) ;
180
		foreach_dart_of_orbit_in_parent<MAP>(dynamic_cast<MAP*>(&m_map), orbit, d, fm, m_thread);
Pierre Kraemer's avatar
Pierre Kraemer committed
181
182
	}

183
184
185
186
187
	/**
	 * unmark the darts of the given orbit of d in the parent map
	 */
	template <typename MAP>
	void unmarkOrbitInParent(unsigned int orbit, Dart d)
Pierre Kraemer's avatar
Pierre Kraemer committed
188
	{
Pierre Kraemer's avatar
Pierre Kraemer committed
189
		FunctorUnmark<GenericMap> fm(m_map, m_mark, m_map.getMarkVector(DART, m_thread)) ;
190
		foreach_dart_of_orbit_in_parent<MAP>(dynamic_cast<MAP*>(&m_map), orbit, d, fm, m_thread);
Pierre Kraemer's avatar
Pierre Kraemer committed
191
192
	}

193
194
195
196
	/**
	 * mark all darts
	 */
	virtual void markAll()
Pierre Kraemer's avatar
Pierre Kraemer committed
197
	{
198
		AttributeContainer& cont = m_map.getAttributeContainer(DART) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
199
		for (unsigned int i = cont.begin(); i != cont.end(); cont.next(i))
Pierre Kraemer's avatar
Pierre Kraemer committed
200
			m_map.getMarkVector(DART, m_thread)->operator[](i).setMark(m_mark);
Pierre Kraemer's avatar
Pierre Kraemer committed
201
202
	}

203
204
205
206
207
	/**
	 * unmark all darts
	 */
	virtual void unmarkAll() = 0 ;
};
Pierre Kraemer's avatar
Pierre Kraemer committed
208

209
210
211
212
213
214
215
216
217
/**
 * class that allows the marking of darts
 * \warning no default constructor
 */
class DartMarker : public DartMarkerGen
{
public:
	DartMarker(GenericMap& map) : DartMarkerGen(map)
	{}
218

219
220
221
222
	DartMarker(GenericMap& map, unsigned int th): DartMarkerGen(map, th)
	{}

	virtual ~DartMarker()
223
	{
224
		unmarkAll() ;
225
226
	}

227
228
229
230
231
232
protected:
	DartMarker(const DartMarker& dm) : DartMarkerGen(dm)
	{}

public:
	void unmarkAll()
233
	{
234
235
		AttributeContainer& cont = m_map.getAttributeContainer(DART) ;
		for (unsigned int i = cont.begin(); i != cont.end(); cont.next(i))
Pierre Kraemer's avatar
Pierre Kraemer committed
236
			m_map.getMarkVector(DART, m_thread)->operator[](i).unsetMark(m_mark);
237
	}
Pierre Kraemer's avatar
Pierre Kraemer committed
238
239
240
241
242
243
244
};

/**
 * class that allows the marking of darts
 * the marked darts are stored to optimize the unmarking task at destruction
 * \warning no default constructor
 */
245
class DartMarkerStore: public DartMarkerGen
Pierre Kraemer's avatar
Pierre Kraemer committed
246
247
248
249
250
{
protected:
	std::vector<unsigned int> m_markedDarts ;

public:
251
	DartMarkerStore(GenericMap& map) : DartMarkerGen(map)
Pierre Kraemer's avatar
Pierre Kraemer committed
252
253
	{}

254
	DartMarkerStore(GenericMap& map, unsigned int thread): DartMarkerGen(map, thread)
Sylvain Thery's avatar
Sylvain Thery committed
255
256
	{}

257
258
259
260
261
	~DartMarkerStore()
	{
		unmarkAll() ;
	}

Pierre Kraemer's avatar
Pierre Kraemer committed
262
protected:
263
	DartMarkerStore(const DartMarkerStore& dm) : DartMarkerGen(dm)
Pierre Kraemer's avatar
Pierre Kraemer committed
264
265
266
267
268
	{}

public:
	void mark(Dart d)
	{
269
		DartMarkerGen::mark(d) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
270
271
272
		m_markedDarts.push_back(d.index) ;
	}

273
	void markOrbit(unsigned int orbit, Dart d)
Pierre Kraemer's avatar
Pierre Kraemer committed
274
	{
Pierre Kraemer's avatar
Pierre Kraemer committed
275
		FunctorMarkStore<GenericMap> fm(m_map, m_mark, m_map.getMarkVector(DART, m_thread), m_markedDarts) ;
276
		m_map.foreach_dart_of_orbit(orbit, d, fm, m_thread) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
277
278
	}

279
280
281
	template <typename MAP>
	void markOrbitInParent(unsigned int orbit, Dart d)
	{
Pierre Kraemer's avatar
Pierre Kraemer committed
282
		FunctorMarkStore<GenericMap> fm(m_map, m_mark, m_map.getMarkVector(DART, m_thread), m_markedDarts) ;
283
284
285
286
287
288
289
290
291
		foreach_dart_of_orbit_in_parent<MAP>(dynamic_cast<MAP*>(&m_map), orbit, d, fm, m_thread);
	}

//	void mark(unsigned int d)
//	{
//		DartMarkerGen::mark(d) ;
//		m_markedDarts.push_back(d) ;
//	}

Pierre Kraemer's avatar
Pierre Kraemer committed
292
293
294
	void unmarkAll()
	{
		for (std::vector<unsigned int>::iterator it = m_markedDarts.begin(); it != m_markedDarts.end(); ++it)
Pierre Kraemer's avatar
Pierre Kraemer committed
295
			m_map.getMarkVector(DART, m_thread)->operator[](*it).unsetMark(m_mark) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
296
297
298
299
300
301
302
303
	}
};

/**
 * class that allows the marking of darts
 * the markers are not unmarked at destruction
 * \warning no default constructor
 */
304
class DartMarkerNoUnmark: public DartMarkerGen
Pierre Kraemer's avatar
Pierre Kraemer committed
305
306
{
public:
307
	DartMarkerNoUnmark(GenericMap& map): DartMarkerGen(map)
Pierre Kraemer's avatar
Pierre Kraemer committed
308
309
	{}

310
	DartMarkerNoUnmark(GenericMap& map, unsigned int th): DartMarkerGen(map,th)
Sylvain Thery's avatar
Sylvain Thery committed
311
312
	{}

Pierre Kraemer's avatar
Pierre Kraemer committed
313
	~DartMarkerNoUnmark()
314
	{}
Pierre Kraemer's avatar
Pierre Kraemer committed
315
316

protected:
317
	DartMarkerNoUnmark(const DartMarkerNoUnmark& dm) : DartMarkerGen(dm)
Pierre Kraemer's avatar
Pierre Kraemer committed
318
	{}
319
320
321
322
323
324

public:
	void unmarkAll()
	{
		AttributeContainer& cont = m_map.getAttributeContainer(DART) ;
		for (unsigned int i = cont.begin(); i != cont.end(); cont.next(i))
Pierre Kraemer's avatar
Pierre Kraemer committed
325
			m_map.getMarkVector(DART, m_thread)->operator[](i).unsetMark(m_mark) ;
326
	}
Pierre Kraemer's avatar
Pierre Kraemer committed
327
328
329
330
331
332
333
334
};

// Selector and count functors testing for marker existence
/********************************************************/

class SelectorMarked : public FunctorSelect
{
protected:
335
	DartMarkerGen& m_marker;
Pierre Kraemer's avatar
Pierre Kraemer committed
336
public:
337
	SelectorMarked(DartMarkerGen& m) : m_marker(m) {}
Pierre Kraemer's avatar
Pierre Kraemer committed
338
339
340
341
342
343
344
345
346
	bool operator()(Dart d) const
	{
		return m_marker.isMarked(d);
	}
};

class SelectorUnmarked : public FunctorSelect
{
protected:
347
	DartMarkerGen& m_marker;
Pierre Kraemer's avatar
Pierre Kraemer committed
348
public:
349
	SelectorUnmarked(DartMarkerGen& m) : m_marker(m) {}
Pierre Kraemer's avatar
Pierre Kraemer committed
350
351
352
353
354
355
356
357
358
359
360
	bool operator()(Dart d) const
	{
		return !m_marker.isMarked(d);
	}
};

// Functor version (needed for use with foreach_xxx)

class FunctorIsMarked : public FunctorType
{
protected:
361
	DartMarkerGen& m_marker;
Pierre Kraemer's avatar
Pierre Kraemer committed
362
public:
363
	FunctorIsMarked(DartMarkerGen& dm) : m_marker(dm) {}
Pierre Kraemer's avatar
Pierre Kraemer committed
364
365
366
367
368
369
370
371
372
	bool operator()(Dart d)
	{
		return m_marker.isMarked(d);
	}
};

class FunctorIsUnmarked : public FunctorType
{
protected:
373
	DartMarkerGen& m_marker;
Pierre Kraemer's avatar
Pierre Kraemer committed
374
public:
375
	FunctorIsUnmarked(DartMarkerGen& dm) : m_marker(dm) {}
Pierre Kraemer's avatar
Pierre Kraemer committed
376
377
378
379
380
381
382
383
384
	bool operator()(Dart d)
	{
		return !m_marker.isMarked(d);
	}
};

} // namespace CGoGN

#endif