Coupure prévue mardi 3 Août au matin pour maintenance du serveur. Nous faisons au mieux pour que celle-ci soit la plus brève possible.

dartmarker.h 9.39 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
* 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
{


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

Pierre Kraemer's avatar
Pierre Kraemer committed
47
48
49
50
51
public:
	/**
	 * constructor
	 * @param map the map on which we work
	 */
52
	DartMarkerGen(GenericMap& map): m_map(map), m_thread(0)
Pierre Kraemer's avatar
Pierre Kraemer committed
53
	{
Sylvain Thery's avatar
Sylvain Thery committed
54
55
//		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
56
57
	}

58
	DartMarkerGen(GenericMap& map, unsigned int thread): m_map(map), m_thread(thread)
Sylvain Thery's avatar
Sylvain Thery committed
59
	{
Sylvain Thery's avatar
Sylvain Thery committed
60
61
//		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
62
63
	}

64
	virtual ~DartMarkerGen()
Pierre Kraemer's avatar
Pierre Kraemer committed
65
	{
Sylvain Thery's avatar
Sylvain Thery committed
66
67
//		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
68
69
70
71
	}

protected:
	// protected copy constructor to forbid its usage
72
	DartMarkerGen(const DartMarkerGen& dm) : m_map(dm.m_map), m_thread(0), m_mark(NIL)
Pierre Kraemer's avatar
Pierre Kraemer committed
73
74
75
76
	{}

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

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

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

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

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

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

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

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

156
157
158
159
160
	/**
	 * unmark all darts
	 */
	virtual void unmarkAll() = 0 ;
};
Pierre Kraemer's avatar
Pierre Kraemer committed
161

162
163
164
165
166
167
168
169
170
/**
 * class that allows the marking of darts
 * \warning no default constructor
 */
class DartMarker : public DartMarkerGen
{
public:
	DartMarker(GenericMap& map) : DartMarkerGen(map)
	{}
171

172
173
174
175
	DartMarker(GenericMap& map, unsigned int th): DartMarkerGen(map, th)
	{}

	virtual ~DartMarker()
176
	{
177
		unmarkAll() ;
178
179
	}

180
181
182
183
184
185
protected:
	DartMarker(const DartMarker& dm) : DartMarkerGen(dm)
	{}

public:
	void unmarkAll()
186
	{
Sylvain Thery's avatar
Sylvain Thery committed
187
188
		assert(m_map.getMarkerSet(DART,m_thread).testMark(m_mark));

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

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

public:
206
	DartMarkerStore(GenericMap& map) : DartMarkerGen(map)
Pierre Kraemer's avatar
Pierre Kraemer committed
207
208
	{}

209
	DartMarkerStore(GenericMap& map, unsigned int thread): DartMarkerGen(map, thread)
Sylvain Thery's avatar
Sylvain Thery committed
210
211
	{}

212
213
214
215
216
	~DartMarkerStore()
	{
		unmarkAll() ;
	}

Pierre Kraemer's avatar
Pierre Kraemer committed
217
protected:
218
	DartMarkerStore(const DartMarkerStore& dm) : DartMarkerGen(dm),m_markedDarts(dm.m_markedDarts)
Pierre Kraemer's avatar
Pierre Kraemer committed
219
220
221
222
223
	{}

public:
	void mark(Dart d)
	{
224
		DartMarkerGen::mark(d) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
225
226
227
		m_markedDarts.push_back(d.index) ;
	}

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

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

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

268
	DartMarkerNoUnmark(GenericMap& map, unsigned int th): DartMarkerGen(map,th)
Sylvain Thery's avatar
Sylvain Thery committed
269
270
	{}

Pierre Kraemer's avatar
Pierre Kraemer committed
271
	~DartMarkerNoUnmark()
272
	{}
Pierre Kraemer's avatar
Pierre Kraemer committed
273
274

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

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

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

class SelectorMarked : public FunctorSelect
{
protected:
294
	DartMarkerGen& m_marker;
Pierre Kraemer's avatar
Pierre Kraemer committed
295
public:
296
	SelectorMarked(DartMarkerGen& m) : m_marker(m) {}
Pierre Kraemer's avatar
Pierre Kraemer committed
297
298
299
300
301
302
303
304
305
	bool operator()(Dart d) const
	{
		return m_marker.isMarked(d);
	}
};

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

// Functor version (needed for use with foreach_xxx)

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

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

} // namespace CGoGN

#endif