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 9.36 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
* 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
{

/**
36
 * generic class that allows the marking of darts
Pierre Kraemer's avatar
Pierre Kraemer committed
37
38
 * \warning no default constructor
 */
39
class DartMarkerGen
Pierre Kraemer's avatar
Pierre Kraemer committed
40
41
{
protected:
42
43
44
	GenericMap& m_map ;
	unsigned int m_thread ;
	Mark m_mark ;
Pierre Kraemer's avatar
merge..    
Pierre Kraemer committed
45

Pierre Kraemer's avatar
Pierre Kraemer committed
46
47
48
49
50
public:
	/**
	 * constructor
	 * @param map the map on which we work
	 */
51
	DartMarkerGen(GenericMap& map): m_map(map), m_thread(0)
Pierre Kraemer's avatar
Pierre Kraemer committed
52
	{
Pierre Kraemer's avatar
Pierre Kraemer committed
53
		m_mark = m_map.getMarkerSet(DART, m_thread).getNewMark() ;
Sylvain Thery's avatar
Sylvain Thery committed
54
55
	}

56
	DartMarkerGen(GenericMap& map, unsigned int thread): m_map(map), m_thread(thread)
Sylvain Thery's avatar
Sylvain Thery committed
57
	{
Pierre Kraemer's avatar
Pierre Kraemer committed
58
		m_mark = m_map.getMarkerSet(DART, m_thread).getNewMark() ;
Pierre Kraemer's avatar
Pierre Kraemer committed
59
60
	}

61
	virtual ~DartMarkerGen()
Pierre Kraemer's avatar
Pierre Kraemer committed
62
	{
Pierre Kraemer's avatar
Pierre Kraemer committed
63
		m_map.getMarkerSet(DART, m_thread).releaseMark(m_mark) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
64
65
66
67
	}

protected:
	// protected copy constructor to forbid its usage
Pierre Kraemer's avatar
Pierre Kraemer committed
68
	DartMarkerGen(const DartMarkerGen& dm) : m_map(dm.m_map), m_thread(0), m_mark(0)
Pierre Kraemer's avatar
Pierre Kraemer committed
69
70
71
72
	{}

public:
	/**
73
	 * mark the dart
Pierre Kraemer's avatar
Pierre Kraemer committed
74
75
76
	 */
	virtual void mark(Dart d)
	{
Pierre Kraemer's avatar
Pierre Kraemer committed
77
		assert(m_map.getMarkerSet(DART, m_thread).testMark(m_mark));
Pierre Kraemer's avatar
Pierre Kraemer committed
78
		m_map.getMarkVector(DART, m_thread)->operator[](d.index).setMark(m_mark);
Pierre Kraemer's avatar
Pierre Kraemer committed
79
80
81
	}

	/**
82
	 * unmark the dart
Pierre Kraemer's avatar
Pierre Kraemer committed
83
84
85
	 */
	virtual void unmark(Dart d)
	{
Pierre Kraemer's avatar
Pierre Kraemer committed
86
		assert(m_map.getMarkerSet(DART, m_thread).testMark(m_mark));
Pierre Kraemer's avatar
Pierre Kraemer committed
87
		m_map.getMarkVector(DART, m_thread)->operator[](d.index).unsetMark(m_mark);
Pierre Kraemer's avatar
Pierre Kraemer committed
88
89
90
	}

	/**
91
	 * test if dart is marked
Pierre Kraemer's avatar
Pierre Kraemer committed
92
	 */
93
	virtual bool isMarked(Dart d) const
Pierre Kraemer's avatar
Pierre Kraemer committed
94
	{
Pierre Kraemer's avatar
Pierre Kraemer committed
95
		assert(m_map.getMarkerSet(DART, m_thread).testMark(m_mark));
Pierre Kraemer's avatar
Pierre Kraemer committed
96
		return m_map.getMarkVector(DART, m_thread)->operator[](d.index).testMark(m_mark);
Pierre Kraemer's avatar
Pierre Kraemer committed
97
98
99
	}

	/**
100
	 * mark the darts of the given orbit of d
Pierre Kraemer's avatar
Pierre Kraemer committed
101
	 */
102
	virtual void markOrbit(unsigned int orbit, Dart d)
Pierre Kraemer's avatar
Pierre Kraemer committed
103
	{
Sylvain Thery's avatar
Sylvain Thery committed
104
		assert(m_map.getMarkerSet(DART,m_thread).testMark(m_mark));
Pierre Kraemer's avatar
Pierre Kraemer committed
105
		FunctorMark<GenericMap> fm(m_map, m_mark, m_map.getMarkVector(DART, m_thread)) ;
106
		m_map.foreach_dart_of_orbit(orbit, d, fm, m_thread) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
107
108
109
	}

	/**
110
	 * unmark the darts of the given orbit of d
Pierre Kraemer's avatar
Pierre Kraemer committed
111
	 */
112
	virtual void unmarkOrbit(unsigned int orbit, Dart d)
Pierre Kraemer's avatar
Pierre Kraemer committed
113
	{
Sylvain Thery's avatar
Sylvain Thery committed
114
		assert(m_map.getMarkerSet(DART,m_thread).testMark(m_mark));
Pierre Kraemer's avatar
Pierre Kraemer committed
115
		FunctorUnmark<GenericMap> fm(m_map, m_mark, m_map.getMarkVector(DART, m_thread)) ;
116
		m_map.foreach_dart_of_orbit(orbit, d, fm, m_thread) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
117
118
119
	}

	/**
120
	 * mark the darts of the given orbit of d in the parent map
Pierre Kraemer's avatar
Pierre Kraemer committed
121
	 */
122
123
	template <typename MAP>
	void markOrbitInParent(unsigned int orbit, Dart d)
Pierre Kraemer's avatar
Pierre Kraemer committed
124
	{
Sylvain Thery's avatar
Sylvain Thery committed
125
		assert(m_map.getMarkerSet(DART,m_thread).testMark(m_mark));
Pierre Kraemer's avatar
Pierre Kraemer committed
126
		FunctorMark<GenericMap> fm(m_map, m_mark, m_map.getMarkVector(DART, m_thread)) ;
127
		foreach_dart_of_orbit_in_parent<MAP>(dynamic_cast<MAP*>(&m_map), orbit, d, fm, m_thread);
Pierre Kraemer's avatar
Pierre Kraemer committed
128
129
	}

130
131
132
133
134
	/**
	 * 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
135
	{
Sylvain Thery's avatar
Sylvain Thery committed
136
		assert(m_map.getMarkerSet(DART,m_thread).testMark(m_mark));
Pierre Kraemer's avatar
Pierre Kraemer committed
137
		FunctorUnmark<GenericMap> fm(m_map, m_mark, m_map.getMarkVector(DART, m_thread)) ;
138
		foreach_dart_of_orbit_in_parent<MAP>(dynamic_cast<MAP*>(&m_map), orbit, d, fm, m_thread);
Pierre Kraemer's avatar
Pierre Kraemer committed
139
140
	}

141
142
143
144
	/**
	 * mark all darts
	 */
	virtual void markAll()
Pierre Kraemer's avatar
Pierre Kraemer committed
145
	{
Sylvain Thery's avatar
Sylvain Thery committed
146
		assert(m_map.getMarkerSet(DART,m_thread).testMark(m_mark));
147
		AttributeContainer& cont = m_map.getAttributeContainer(DART) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
148
		for (unsigned int i = cont.begin(); i != cont.end(); cont.next(i))
Pierre Kraemer's avatar
Pierre Kraemer committed
149
			m_map.getMarkVector(DART, m_thread)->operator[](i).setMark(m_mark);
Pierre Kraemer's avatar
Pierre Kraemer committed
150
151
	}

152
153
154
155
156
	/**
	 * unmark all darts
	 */
	virtual void unmarkAll() = 0 ;
};
Pierre Kraemer's avatar
Pierre Kraemer committed
157

158
159
160
161
162
163
164
165
166
/**
 * class that allows the marking of darts
 * \warning no default constructor
 */
class DartMarker : public DartMarkerGen
{
public:
	DartMarker(GenericMap& map) : DartMarkerGen(map)
	{}
167

168
169
170
171
	DartMarker(GenericMap& map, unsigned int th): DartMarkerGen(map, th)
	{}

	virtual ~DartMarker()
172
	{
173
		unmarkAll() ;
174
175
	}

176
177
178
179
180
181
protected:
	DartMarker(const DartMarker& dm) : DartMarkerGen(dm)
	{}

public:
	void unmarkAll()
182
	{
Sylvain Thery's avatar
Sylvain Thery committed
183
184
		assert(m_map.getMarkerSet(DART,m_thread).testMark(m_mark));

185
186
		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
187
			m_map.getMarkVector(DART, m_thread)->operator[](i).unsetMark(m_mark);
188
	}
Pierre Kraemer's avatar
Pierre Kraemer committed
189
190
191
192
193
194
195
};

/**
 * class that allows the marking of darts
 * the marked darts are stored to optimize the unmarking task at destruction
 * \warning no default constructor
 */
196
class DartMarkerStore: public DartMarkerGen
Pierre Kraemer's avatar
Pierre Kraemer committed
197
198
199
200
201
{
protected:
	std::vector<unsigned int> m_markedDarts ;

public:
202
	DartMarkerStore(GenericMap& map) : DartMarkerGen(map)
Pierre Kraemer's avatar
Pierre Kraemer committed
203
204
	{}

205
	DartMarkerStore(GenericMap& map, unsigned int thread): DartMarkerGen(map, thread)
Sylvain Thery's avatar
Sylvain Thery committed
206
207
	{}

208
209
210
211
212
	~DartMarkerStore()
	{
		unmarkAll() ;
	}

Pierre Kraemer's avatar
Pierre Kraemer committed
213
protected:
214
	DartMarkerStore(const DartMarkerStore& dm) : DartMarkerGen(dm),m_markedDarts(dm.m_markedDarts)
Pierre Kraemer's avatar
Pierre Kraemer committed
215
216
217
218
219
	{}

public:
	void mark(Dart d)
	{
220
		DartMarkerGen::mark(d) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
221
222
223
		m_markedDarts.push_back(d.index) ;
	}

224
	void markOrbit(unsigned int orbit, Dart d)
Pierre Kraemer's avatar
Pierre Kraemer committed
225
	{
Sylvain Thery's avatar
Sylvain Thery committed
226
		assert(m_map.getMarkerSet(DART,m_thread).testMark(m_mark));
Pierre Kraemer's avatar
Pierre Kraemer committed
227
		FunctorMarkStore<GenericMap> fm(m_map, m_mark, m_map.getMarkVector(DART, m_thread), m_markedDarts) ;
228
		m_map.foreach_dart_of_orbit(orbit, d, fm, m_thread) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
229
230
	}

231
232
233
	template <typename MAP>
	void markOrbitInParent(unsigned int orbit, Dart d)
	{
Sylvain Thery's avatar
Sylvain Thery committed
234
		assert(m_map.getMarkerSet(DART,m_thread).testMark(m_mark));
Pierre Kraemer's avatar
Pierre Kraemer committed
235
		FunctorMarkStore<GenericMap> fm(m_map, m_mark, m_map.getMarkVector(DART, m_thread), m_markedDarts) ;
236
237
238
239
240
241
242
243
244
		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
245
246
	void unmarkAll()
	{
Sylvain Thery's avatar
Sylvain Thery committed
247
		assert(m_map.getMarkerSet(DART,m_thread).testMark(m_mark));
Pierre Kraemer's avatar
Pierre Kraemer committed
248
		for (std::vector<unsigned int>::iterator it = m_markedDarts.begin(); it != m_markedDarts.end(); ++it)
Pierre Kraemer's avatar
Pierre Kraemer committed
249
			m_map.getMarkVector(DART, m_thread)->operator[](*it).unsetMark(m_mark) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
250
251
252
253
254
255
256
257
	}
};

/**
 * class that allows the marking of darts
 * the markers are not unmarked at destruction
 * \warning no default constructor
 */
258
class DartMarkerNoUnmark: public DartMarkerGen
Pierre Kraemer's avatar
Pierre Kraemer committed
259
260
{
public:
261
	DartMarkerNoUnmark(GenericMap& map): DartMarkerGen(map)
Pierre Kraemer's avatar
Pierre Kraemer committed
262
263
	{}

264
	DartMarkerNoUnmark(GenericMap& map, unsigned int th): DartMarkerGen(map,th)
Sylvain Thery's avatar
Sylvain Thery committed
265
266
	{}

Pierre Kraemer's avatar
Pierre Kraemer committed
267
	~DartMarkerNoUnmark()
268
	{}
Pierre Kraemer's avatar
Pierre Kraemer committed
269
270

protected:
271
	DartMarkerNoUnmark(const DartMarkerNoUnmark& dm) : DartMarkerGen(dm)
Pierre Kraemer's avatar
Pierre Kraemer committed
272
	{}
273
274
275
276

public:
	void unmarkAll()
	{
Sylvain Thery's avatar
Sylvain Thery committed
277
		assert(m_map.getMarkerSet(DART,m_thread).testMark(m_mark));
278
279
		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
280
			m_map.getMarkVector(DART, m_thread)->operator[](i).unsetMark(m_mark) ;
281
	}
Pierre Kraemer's avatar
Pierre Kraemer committed
282
283
284
285
286
287
288
289
};

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

class SelectorMarked : public FunctorSelect
{
protected:
290
	DartMarkerGen& m_marker;
Pierre Kraemer's avatar
Pierre Kraemer committed
291
public:
292
	SelectorMarked(DartMarkerGen& m) : m_marker(m) {}
Pierre Kraemer's avatar
Pierre Kraemer committed
293
294
295
296
	bool operator()(Dart d) const
	{
		return m_marker.isMarked(d);
	}
297
	FunctorSelect* copy() const { return new SelectorMarked(m_marker);}
Pierre Kraemer's avatar
Pierre Kraemer committed
298
299
300
301
302
};

class SelectorUnmarked : public FunctorSelect
{
protected:
303
	DartMarkerGen& m_marker;
Pierre Kraemer's avatar
Pierre Kraemer committed
304
public:
305
	SelectorUnmarked(DartMarkerGen& m) : m_marker(m) {}
Pierre Kraemer's avatar
Pierre Kraemer committed
306
307
308
309
	bool operator()(Dart d) const
	{
		return !m_marker.isMarked(d);
	}
310
	FunctorSelect* copy() const { return new SelectorUnmarked(m_marker);}
Pierre Kraemer's avatar
Pierre Kraemer committed
311
312
313
314
315
316
317
};

// Functor version (needed for use with foreach_xxx)

class FunctorIsMarked : public FunctorType
{
protected:
318
	DartMarkerGen& m_marker;
Pierre Kraemer's avatar
Pierre Kraemer committed
319
public:
320
	FunctorIsMarked(DartMarkerGen& dm) : m_marker(dm) {}
Pierre Kraemer's avatar
Pierre Kraemer committed
321
322
323
324
325
326
327
328
329
	bool operator()(Dart d)
	{
		return m_marker.isMarked(d);
	}
};

class FunctorIsUnmarked : public FunctorType
{
protected:
330
	DartMarkerGen& m_marker;
Pierre Kraemer's avatar
Pierre Kraemer committed
331
public:
332
	FunctorIsUnmarked(DartMarkerGen& dm) : m_marker(dm) {}
Pierre Kraemer's avatar
Pierre Kraemer committed
333
334
335
336
337
338
339
340
341
	bool operator()(Dart d)
	{
		return !m_marker.isMarked(d);
	}
};

} // namespace CGoGN

#endif