Création d'un compte pour un collaborateur extérieur au laboratoire depuis l'intranet ICube : https://intranet.icube.unistra.fr/fr/labs/member/profile

dartmarker.h 10.8 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
	{
Sylvain Thery's avatar
Sylvain Thery committed
112
113
//		m_mark = m_map.m_marksets[DART][m_thread].getNewMark() ;
		m_mark = m_map.getMarkerSet(DART,m_thread).getNewMark() ;
Sylvain Thery's avatar
Sylvain Thery committed
114
115
	}

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

122
	virtual ~DartMarkerGen()
Pierre Kraemer's avatar
Pierre Kraemer committed
123
	{
Sylvain Thery's avatar
Sylvain Thery committed
124
125
//		m_map.m_marksets[DART][m_thread].releaseMark(m_mark) ;
		m_map.getMarkerSet(DART,m_thread).releaseMark(m_mark) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
126
127
128
129
	}

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

public:
	/**
135
	 * mark the dart
Pierre Kraemer's avatar
Pierre Kraemer committed
136
137
138
	 */
	virtual void mark(Dart d)
	{
Sylvain Thery's avatar
Sylvain Thery committed
139
		assert(m_map.getMarkerSet(DART,m_thread).testMark(m_mark));
Pierre Kraemer's avatar
Pierre Kraemer committed
140
		m_map.getMarkVector(DART, m_thread)->operator[](d.index).setMark(m_mark);
Pierre Kraemer's avatar
Pierre Kraemer committed
141
142
143
	}

	/**
144
	 * unmark the dart
Pierre Kraemer's avatar
Pierre Kraemer committed
145
146
147
	 */
	virtual void unmark(Dart d)
	{
Sylvain Thery's avatar
Sylvain Thery committed
148
		assert(m_map.getMarkerSet(DART,m_thread).testMark(m_mark));
Pierre Kraemer's avatar
Pierre Kraemer committed
149
		m_map.getMarkVector(DART, m_thread)->operator[](d.index).unsetMark(m_mark);
Pierre Kraemer's avatar
Pierre Kraemer committed
150
151
152
	}

	/**
153
	 * test if dart is marked
Pierre Kraemer's avatar
Pierre Kraemer committed
154
155
156
	 */
	virtual bool isMarked(Dart d)
	{
Sylvain Thery's avatar
Sylvain Thery committed
157
		assert(m_map.getMarkerSet(DART,m_thread).testMark(m_mark));
Pierre Kraemer's avatar
Pierre Kraemer committed
158
		return m_map.getMarkVector(DART, m_thread)->operator[](d.index).testMark(m_mark);
Pierre Kraemer's avatar
Pierre Kraemer committed
159
160
161
	}

	/**
162
	 * mark the darts of the given orbit of d
Pierre Kraemer's avatar
Pierre Kraemer committed
163
	 */
164
	virtual void markOrbit(unsigned int orbit, Dart d)
Pierre Kraemer's avatar
Pierre Kraemer committed
165
	{
Sylvain Thery's avatar
Sylvain Thery committed
166
		assert(m_map.getMarkerSet(DART,m_thread).testMark(m_mark));
Pierre Kraemer's avatar
Pierre Kraemer committed
167
		FunctorMark<GenericMap> fm(m_map, m_mark, m_map.getMarkVector(DART, m_thread)) ;
168
		m_map.foreach_dart_of_orbit(orbit, d, fm, m_thread) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
169
170
171
	}

	/**
172
	 * unmark the darts of the given orbit of d
Pierre Kraemer's avatar
Pierre Kraemer committed
173
	 */
174
	virtual void unmarkOrbit(unsigned int orbit, Dart d)
Pierre Kraemer's avatar
Pierre Kraemer committed
175
	{
Sylvain Thery's avatar
Sylvain Thery committed
176
		assert(m_map.getMarkerSet(DART,m_thread).testMark(m_mark));
Pierre Kraemer's avatar
Pierre Kraemer committed
177
		FunctorUnmark<GenericMap> fm(m_map, m_mark, m_map.getMarkVector(DART, m_thread)) ;
178
		m_map.foreach_dart_of_orbit(orbit, d, fm, m_thread) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
179
180
181
	}

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

192
193
194
195
196
	/**
	 * 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
197
	{
Sylvain Thery's avatar
Sylvain Thery committed
198
		assert(m_map.getMarkerSet(DART,m_thread).testMark(m_mark));
Pierre Kraemer's avatar
Pierre Kraemer committed
199
		FunctorUnmark<GenericMap> fm(m_map, m_mark, m_map.getMarkVector(DART, m_thread)) ;
200
		foreach_dart_of_orbit_in_parent<MAP>(dynamic_cast<MAP*>(&m_map), orbit, d, fm, m_thread);
Pierre Kraemer's avatar
Pierre Kraemer committed
201
202
	}

203
204
205
206
	/**
	 * mark all darts
	 */
	virtual void markAll()
Pierre Kraemer's avatar
Pierre Kraemer committed
207
	{
Sylvain Thery's avatar
Sylvain Thery committed
208
		assert(m_map.getMarkerSet(DART,m_thread).testMark(m_mark));
209
		AttributeContainer& cont = m_map.getAttributeContainer(DART) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
210
		for (unsigned int i = cont.begin(); i != cont.end(); cont.next(i))
Pierre Kraemer's avatar
Pierre Kraemer committed
211
			m_map.getMarkVector(DART, m_thread)->operator[](i).setMark(m_mark);
Pierre Kraemer's avatar
Pierre Kraemer committed
212
213
	}

214
215
216
217
218
	/**
	 * unmark all darts
	 */
	virtual void unmarkAll() = 0 ;
};
Pierre Kraemer's avatar
Pierre Kraemer committed
219

220
221
222
223
224
225
226
227
228
/**
 * class that allows the marking of darts
 * \warning no default constructor
 */
class DartMarker : public DartMarkerGen
{
public:
	DartMarker(GenericMap& map) : DartMarkerGen(map)
	{}
229

230
231
232
233
	DartMarker(GenericMap& map, unsigned int th): DartMarkerGen(map, th)
	{}

	virtual ~DartMarker()
234
	{
235
		unmarkAll() ;
236
237
	}

238
239
240
241
242
243
protected:
	DartMarker(const DartMarker& dm) : DartMarkerGen(dm)
	{}

public:
	void unmarkAll()
244
	{
Sylvain Thery's avatar
Sylvain Thery committed
245
246
		assert(m_map.getMarkerSet(DART,m_thread).testMark(m_mark));

247
248
		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
249
			m_map.getMarkVector(DART, m_thread)->operator[](i).unsetMark(m_mark);
250
	}
Pierre Kraemer's avatar
Pierre Kraemer committed
251
252
253
254
255
256
257
};

/**
 * class that allows the marking of darts
 * the marked darts are stored to optimize the unmarking task at destruction
 * \warning no default constructor
 */
258
class DartMarkerStore: public DartMarkerGen
Pierre Kraemer's avatar
Pierre Kraemer committed
259
260
261
262
263
{
protected:
	std::vector<unsigned int> m_markedDarts ;

public:
264
	DartMarkerStore(GenericMap& map) : DartMarkerGen(map)
Pierre Kraemer's avatar
Pierre Kraemer committed
265
266
	{}

267
	DartMarkerStore(GenericMap& map, unsigned int thread): DartMarkerGen(map, thread)
Sylvain Thery's avatar
Sylvain Thery committed
268
269
	{}

270
271
272
273
274
	~DartMarkerStore()
	{
		unmarkAll() ;
	}

Pierre Kraemer's avatar
Pierre Kraemer committed
275
protected:
276
	DartMarkerStore(const DartMarkerStore& dm) : DartMarkerGen(dm)
Pierre Kraemer's avatar
Pierre Kraemer committed
277
278
279
280
281
	{}

public:
	void mark(Dart d)
	{
282
		DartMarkerGen::mark(d) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
283
284
285
		m_markedDarts.push_back(d.index) ;
	}

286
	void markOrbit(unsigned int orbit, Dart d)
Pierre Kraemer's avatar
Pierre Kraemer committed
287
	{
Sylvain Thery's avatar
Sylvain Thery committed
288
		assert(m_map.getMarkerSet(DART,m_thread).testMark(m_mark));
Pierre Kraemer's avatar
Pierre Kraemer committed
289
		FunctorMarkStore<GenericMap> fm(m_map, m_mark, m_map.getMarkVector(DART, m_thread), m_markedDarts) ;
290
		m_map.foreach_dart_of_orbit(orbit, d, fm, m_thread) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
291
292
	}

293
294
295
	template <typename MAP>
	void markOrbitInParent(unsigned int orbit, Dart d)
	{
Sylvain Thery's avatar
Sylvain Thery committed
296
		assert(m_map.getMarkerSet(DART,m_thread).testMark(m_mark));
Pierre Kraemer's avatar
Pierre Kraemer committed
297
		FunctorMarkStore<GenericMap> fm(m_map, m_mark, m_map.getMarkVector(DART, m_thread), m_markedDarts) ;
298
299
300
301
302
303
304
305
306
		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
307
308
	void unmarkAll()
	{
Sylvain Thery's avatar
Sylvain Thery committed
309
		assert(m_map.getMarkerSet(DART,m_thread).testMark(m_mark));
Pierre Kraemer's avatar
Pierre Kraemer committed
310
		for (std::vector<unsigned int>::iterator it = m_markedDarts.begin(); it != m_markedDarts.end(); ++it)
Pierre Kraemer's avatar
Pierre Kraemer committed
311
			m_map.getMarkVector(DART, m_thread)->operator[](*it).unsetMark(m_mark) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
312
313
314
315
316
317
318
319
	}
};

/**
 * class that allows the marking of darts
 * the markers are not unmarked at destruction
 * \warning no default constructor
 */
320
class DartMarkerNoUnmark: public DartMarkerGen
Pierre Kraemer's avatar
Pierre Kraemer committed
321
322
{
public:
323
	DartMarkerNoUnmark(GenericMap& map): DartMarkerGen(map)
Pierre Kraemer's avatar
Pierre Kraemer committed
324
325
	{}

326
	DartMarkerNoUnmark(GenericMap& map, unsigned int th): DartMarkerGen(map,th)
Sylvain Thery's avatar
Sylvain Thery committed
327
328
	{}

Pierre Kraemer's avatar
Pierre Kraemer committed
329
	~DartMarkerNoUnmark()
330
	{}
Pierre Kraemer's avatar
Pierre Kraemer committed
331
332

protected:
333
	DartMarkerNoUnmark(const DartMarkerNoUnmark& dm) : DartMarkerGen(dm)
Pierre Kraemer's avatar
Pierre Kraemer committed
334
	{}
335
336
337
338

public:
	void unmarkAll()
	{
Sylvain Thery's avatar
Sylvain Thery committed
339
		assert(m_map.getMarkerSet(DART,m_thread).testMark(m_mark));
340
341
		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
342
			m_map.getMarkVector(DART, m_thread)->operator[](i).unsetMark(m_mark) ;
343
	}
Pierre Kraemer's avatar
Pierre Kraemer committed
344
345
346
347
348
349
350
351
};

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

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

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

// Functor version (needed for use with foreach_xxx)

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

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

} // namespace CGoGN

#endif