dartmarker.h 10.3 KB
Newer Older
Pierre Kraemer's avatar
Pierre Kraemer committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/*******************************************************************************
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps  *
* version 0.1                                                                  *
* Copyright (C) 2009, IGG Team, LSIIT, University of Strasbourg                *
*                                                                              *
* 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.           *
*                                                                              *
* Web site: https://iggservis.u-strasbg.fr/CGoGN/                              *
* 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:
42
43
	Marker m_marker ;
	AttributeMultiVector<Mark>* m_markerTable ;
Pierre Kraemer's avatar
Pierre Kraemer committed
44
public:
45
	FunctorMarker(MAP& map, Marker m, AttributeMultiVector<Mark>* mTable) : FunctorMap<MAP>(map), m_marker(m), m_markerTable(mTable) {}
46
47
	Marker getMarker() { return m_marker ; }
} ;
Pierre Kraemer's avatar
Pierre Kraemer committed
48
49

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

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

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

/**
92
 * generic class that allows the marking of darts
Pierre Kraemer's avatar
Pierre Kraemer committed
93
94
 * \warning no default constructor
 */
95
class DartMarkerGen
Pierre Kraemer's avatar
Pierre Kraemer committed
96
97
98
99
{
protected:
	Marker m_marker;
	GenericMap& m_map;
Sylvain Thery's avatar
Sylvain Thery committed
100
	unsigned int m_thread;
Pierre Kraemer's avatar
merge..    
Pierre Kraemer committed
101

Pierre Kraemer's avatar
Pierre Kraemer committed
102
103
104
105
106
public:
	/**
	 * constructor
	 * @param map the map on which we work
	 */
107
	DartMarkerGen(GenericMap& map): m_map(map), m_thread(0)
Pierre Kraemer's avatar
Pierre Kraemer committed
108
	{
109
		m_marker = map.getNewMarker(DART);
Sylvain Thery's avatar
Sylvain Thery committed
110
111
	}

112
	DartMarkerGen(GenericMap& map, unsigned int thread): m_map(map), m_thread(thread)
Sylvain Thery's avatar
Sylvain Thery committed
113
	{
114
		m_marker = map.getNewMarker(DART, thread);
Pierre Kraemer's avatar
Pierre Kraemer committed
115
116
	}

117
	virtual ~DartMarkerGen()
Pierre Kraemer's avatar
Pierre Kraemer committed
118
	{
Pierre Kraemer's avatar
merge..    
Pierre Kraemer committed
119
		m_map.releaseMarker(m_marker, m_thread);
Pierre Kraemer's avatar
Pierre Kraemer committed
120
121
122
123
	}

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

public:
	/**
129
	 * mark the dart
Pierre Kraemer's avatar
Pierre Kraemer committed
130
131
132
	 */
	virtual void mark(Dart d)
	{
133
		m_map.getMarkerVector(DART, m_thread)->operator[](d.index).setMark(m_marker);
Pierre Kraemer's avatar
Pierre Kraemer committed
134
135
136
	}

	/**
137
	 * unmark the dart
Pierre Kraemer's avatar
Pierre Kraemer committed
138
139
140
	 */
	virtual void unmark(Dart d)
	{
141
		m_map.getMarkerVector(DART, m_thread)->operator[](d.index).unsetMark(m_marker);
Pierre Kraemer's avatar
Pierre Kraemer committed
142
143
144
	}

	/**
145
	 * test if dart is marked
Pierre Kraemer's avatar
Pierre Kraemer committed
146
147
148
	 */
	virtual bool isMarked(Dart d)
	{
149
		return m_map.getMarkerVector(DART, m_thread)->operator[](d.index).testMark(m_marker);
Pierre Kraemer's avatar
Pierre Kraemer committed
150
151
	}

152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
//	/**
//	 * mark the dart
//	 */
//	virtual void mark(unsigned int d)
//	{
//		m_map.getMarkerVector(DART, m_thread)->operator[](d).setMark(m_marker);
//	}
//
//	/**
//	 * unmark the cell
//	 */
//	virtual void unmark(unsigned int d)
//	{
//		m_map.getMarkerVector(DART, m_thread)->operator[](d).unsetMark(m_marker);
//	}
//
//	/**
//	 * test if dart is marked
//	 */
//	virtual bool isMarked(unsigned int d)
//	{
//		return m_map.getMarkerVector(DART, m_thread)->operator[](d).testMark(m_marker);
//	}

Pierre Kraemer's avatar
Pierre Kraemer committed
176
	/**
177
	 * mark the darts of the given orbit of d
Pierre Kraemer's avatar
Pierre Kraemer committed
178
	 */
179
	virtual void markOrbit(unsigned int orbit, Dart d)
Pierre Kraemer's avatar
Pierre Kraemer committed
180
	{
181
182
		FunctorMark<GenericMap> fm(m_map, m_marker, m_map.getMarkerVector(DART, m_thread)) ;
		m_map.foreach_dart_of_orbit(orbit, d, fm, m_thread) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
183
184
185
	}

	/**
186
	 * unmark the darts of the given orbit of d
Pierre Kraemer's avatar
Pierre Kraemer committed
187
	 */
188
	virtual void unmarkOrbit(unsigned int orbit, Dart d)
Pierre Kraemer's avatar
Pierre Kraemer committed
189
	{
190
191
		FunctorUnmark<GenericMap> fm(m_map, m_marker, m_map.getMarkerVector(DART, m_thread)) ;
		m_map.foreach_dart_of_orbit(orbit, d, fm, m_thread) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
192
193
194
	}

	/**
195
	 * mark the darts of the given orbit of d in the parent map
Pierre Kraemer's avatar
Pierre Kraemer committed
196
	 */
197
198
	template <typename MAP>
	void markOrbitInParent(unsigned int orbit, Dart d)
Pierre Kraemer's avatar
Pierre Kraemer committed
199
	{
200
201
		FunctorMark<GenericMap> fm(m_map, m_marker, m_map.getMarkerVector(DART, m_thread)) ;
		foreach_dart_of_orbit_in_parent<MAP>(dynamic_cast<MAP*>(&m_map), orbit, d, fm, m_thread);
Pierre Kraemer's avatar
Pierre Kraemer committed
202
203
	}

204
205
206
207
208
	/**
	 * 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
209
	{
210
211
		FunctorUnmark<GenericMap> fm(m_map, m_marker, m_map.getMarkerVector(DART, m_thread)) ;
		foreach_dart_of_orbit_in_parent<MAP>(dynamic_cast<MAP*>(&m_map), orbit, d, fm, m_thread);
Pierre Kraemer's avatar
Pierre Kraemer committed
212
213
	}

214
215
216
217
	/**
	 * mark all darts
	 */
	virtual void markAll()
Pierre Kraemer's avatar
Pierre Kraemer committed
218
	{
219
		AttributeContainer& cont = m_map.getAttributeContainer(DART) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
220
		for (unsigned int i = cont.begin(); i != cont.end(); cont.next(i))
221
			m_map.getMarkerVector(DART, m_thread)->operator[](i).setMark(m_marker);
Pierre Kraemer's avatar
Pierre Kraemer committed
222
223
	}

224
225
226
227
228
	/**
	 * unmark all darts
	 */
	virtual void unmarkAll() = 0 ;
};
Pierre Kraemer's avatar
Pierre Kraemer committed
229

230
231
232
233
234
235
236
237
238
/**
 * class that allows the marking of darts
 * \warning no default constructor
 */
class DartMarker : public DartMarkerGen
{
public:
	DartMarker(GenericMap& map) : DartMarkerGen(map)
	{}
239

240
241
242
243
	DartMarker(GenericMap& map, unsigned int th): DartMarkerGen(map, th)
	{}

	virtual ~DartMarker()
244
	{
245
		unmarkAll() ;
246
247
	}

248
249
250
251
252
253
protected:
	DartMarker(const DartMarker& dm) : DartMarkerGen(dm)
	{}

public:
	void unmarkAll()
254
	{
255
256
257
		AttributeContainer& cont = m_map.getAttributeContainer(DART) ;
		for (unsigned int i = cont.begin(); i != cont.end(); cont.next(i))
			m_map.getMarkerVector(DART, m_thread)->operator[](i).unsetMark(m_marker);
258
	}
Pierre Kraemer's avatar
Pierre Kraemer committed
259
260
261
262
263
264
265
};

/**
 * class that allows the marking of darts
 * the marked darts are stored to optimize the unmarking task at destruction
 * \warning no default constructor
 */
266
class DartMarkerStore: public DartMarkerGen
Pierre Kraemer's avatar
Pierre Kraemer committed
267
268
269
270
271
{
protected:
	std::vector<unsigned int> m_markedDarts ;

public:
272
	DartMarkerStore(GenericMap& map) : DartMarkerGen(map)
Pierre Kraemer's avatar
Pierre Kraemer committed
273
274
	{}

275
	DartMarkerStore(GenericMap& map, unsigned int thread): DartMarkerGen(map, thread)
Sylvain Thery's avatar
Sylvain Thery committed
276
277
	{}

278
279
280
281
282
	~DartMarkerStore()
	{
		unmarkAll() ;
	}

Pierre Kraemer's avatar
Pierre Kraemer committed
283
protected:
284
	DartMarkerStore(const DartMarkerStore& dm) : DartMarkerGen(dm)
Pierre Kraemer's avatar
Pierre Kraemer committed
285
286
287
288
289
	{}

public:
	void mark(Dart d)
	{
290
		DartMarkerGen::mark(d) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
291
292
293
		m_markedDarts.push_back(d.index) ;
	}

294
	void markOrbit(unsigned int orbit, Dart d)
Pierre Kraemer's avatar
Pierre Kraemer committed
295
	{
296
297
		FunctorMarkStore<GenericMap> fm(m_map, m_marker, m_map.getMarkerVector(DART, m_thread), m_markedDarts) ;
		m_map.foreach_dart_of_orbit(orbit, d, fm, m_thread) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
298
299
	}

300
301
302
303
304
305
306
307
308
309
310
311
312
	template <typename MAP>
	void markOrbitInParent(unsigned int orbit, Dart d)
	{
		FunctorMarkStore<GenericMap> fm(m_map, m_marker, m_map.getMarkerVector(DART, m_thread), m_markedDarts) ;
		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
313
314
315
	void unmarkAll()
	{
		for (std::vector<unsigned int>::iterator it = m_markedDarts.begin(); it != m_markedDarts.end(); ++it)
316
			m_map.getMarkerVector(DART, m_thread)->operator[](*it).unsetMark(m_marker) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
317
318
319
320
321
322
323
324
	}
};

/**
 * class that allows the marking of darts
 * the markers are not unmarked at destruction
 * \warning no default constructor
 */
325
class DartMarkerNoUnmark: public DartMarkerGen
Pierre Kraemer's avatar
Pierre Kraemer committed
326
327
{
public:
328
	DartMarkerNoUnmark(GenericMap& map): DartMarkerGen(map)
Pierre Kraemer's avatar
Pierre Kraemer committed
329
330
	{}

331
	DartMarkerNoUnmark(GenericMap& map, unsigned int th): DartMarkerGen(map,th)
Sylvain Thery's avatar
Sylvain Thery committed
332
333
	{}

Pierre Kraemer's avatar
Pierre Kraemer committed
334
	~DartMarkerNoUnmark()
335
	{}
Pierre Kraemer's avatar
Pierre Kraemer committed
336
337

protected:
338
	DartMarkerNoUnmark(const DartMarkerNoUnmark& dm) : DartMarkerGen(dm)
Pierre Kraemer's avatar
Pierre Kraemer committed
339
	{}
340
341
342
343
344
345
346
347

public:
	void unmarkAll()
	{
		AttributeContainer& cont = m_map.getAttributeContainer(DART) ;
		for (unsigned int i = cont.begin(); i != cont.end(); cont.next(i))
			m_map.getMarkerVector(DART, m_thread)->operator[](i).unsetMark(m_marker) ;
	}
Pierre Kraemer's avatar
Pierre Kraemer committed
348
349
350
351
352
353
354
355
};

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

class SelectorMarked : public FunctorSelect
{
protected:
356
	DartMarkerGen& m_marker;
Pierre Kraemer's avatar
Pierre Kraemer committed
357
public:
358
	SelectorMarked(DartMarkerGen& m) : m_marker(m) {}
Pierre Kraemer's avatar
Pierre Kraemer committed
359
360
361
362
363
364
365
366
367
	bool operator()(Dart d) const
	{
		return m_marker.isMarked(d);
	}
};

class SelectorUnmarked : public FunctorSelect
{
protected:
368
	DartMarkerGen& m_marker;
Pierre Kraemer's avatar
Pierre Kraemer committed
369
public:
370
	SelectorUnmarked(DartMarkerGen& m) : m_marker(m) {}
Pierre Kraemer's avatar
Pierre Kraemer committed
371
372
373
374
375
376
377
378
379
380
381
	bool operator()(Dart d) const
	{
		return !m_marker.isMarked(d);
	}
};

// Functor version (needed for use with foreach_xxx)

class FunctorIsMarked : public FunctorType
{
protected:
382
	DartMarkerGen& m_marker;
Pierre Kraemer's avatar
Pierre Kraemer committed
383
public:
384
	FunctorIsMarked(DartMarkerGen& dm) : m_marker(dm) {}
Pierre Kraemer's avatar
Pierre Kraemer committed
385
386
387
388
389
390
391
392
393
	bool operator()(Dart d)
	{
		return m_marker.isMarked(d);
	}
};

class FunctorIsUnmarked : public FunctorType
{
protected:
394
	DartMarkerGen& m_marker;
Pierre Kraemer's avatar
Pierre Kraemer committed
395
public:
396
	FunctorIsUnmarked(DartMarkerGen& dm) : m_marker(dm) {}
Pierre Kraemer's avatar
Pierre Kraemer committed
397
398
399
400
401
402
403
404
405
	bool operator()(Dart d)
	{
		return !m_marker.isMarked(d);
	}
};

} // namespace CGoGN

#endif