dartmarker.h 8.71 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
42
/*******************************************************************************
* 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:
	Marker m_marker;
43
	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) {}
Pierre Kraemer's avatar
Pierre Kraemer committed
46
47
48
49
50
51
52
	Marker getMarker() { return m_marker; }
};

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

template <typename MAP>
class FunctorUnmark: public FunctorMarker<MAP>
{
public:
65
	FunctorUnmark(MAP& map, Marker m, AttributeMultiVector<Mark>* mTable) : FunctorMarker<MAP>(map, m, mTable) {}
Pierre Kraemer's avatar
Pierre Kraemer committed
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
	bool operator()(Dart d)
	{
		this->m_markerTable->operator[](d.index).unsetMark(this->m_marker);
		return false;
	}
};


/**
 * class that allows the marking of darts
 * \warning no default constructor
 */
class DartMarker
{
protected:
	Marker m_marker;
	GenericMap& m_map;
Sylvain Thery's avatar
Sylvain Thery committed
83
	unsigned int m_thread;
Pierre Kraemer's avatar
merge..    
Pierre Kraemer committed
84

Pierre Kraemer's avatar
Pierre Kraemer committed
85
86
87
88
89
public:
	/**
	 * constructor
	 * @param map the map on which we work
	 */
Sylvain Thery's avatar
Sylvain Thery committed
90
	DartMarker(GenericMap& map): m_map(map), m_thread(0)
Pierre Kraemer's avatar
Pierre Kraemer committed
91
	{
Pierre Kraemer's avatar
merge..    
Pierre Kraemer committed
92
		m_marker = map.getNewMarker(DART_ORBIT, 0);
Sylvain Thery's avatar
Sylvain Thery committed
93
94
95
96
	}

	DartMarker(GenericMap& map, unsigned int thread): m_map(map), m_thread(thread)
	{
Pierre Kraemer's avatar
merge..    
Pierre Kraemer committed
97
		m_marker = map.getNewMarker(DART_ORBIT, thread);
Pierre Kraemer's avatar
Pierre Kraemer committed
98
99
100
101
102
	}

	virtual ~DartMarker()
	{
		unmarkAll();
Pierre Kraemer's avatar
merge..    
Pierre Kraemer committed
103
		m_map.releaseMarker(m_marker, m_thread);
Pierre Kraemer's avatar
Pierre Kraemer committed
104
105
106
107
108
109
110
111
112
113
114
115
116
	}

protected:
	// protected copy constructor to forbid its usage
	DartMarker(const DartMarker& dm) : m_map(dm.m_map)
	{}

public:
	/**
	 * mark the cell of dart
	 */
	virtual void mark(Dart d)
	{
Pierre Kraemer's avatar
merge..    
Pierre Kraemer committed
117
		m_map.getMarkerVector(DART_ORBIT, m_thread)->operator[](d.index).setMark(m_marker);
Pierre Kraemer's avatar
Pierre Kraemer committed
118
119
120
121
122
123
124
	}

	/**
	 * unmark the cell of dart
	 */
	virtual void unmark(Dart d)
	{
Pierre Kraemer's avatar
merge..    
Pierre Kraemer committed
125
		m_map.getMarkerVector(DART_ORBIT, m_thread)->operator[](d.index).unsetMark(m_marker);
Pierre Kraemer's avatar
Pierre Kraemer committed
126
127
128
129
130
131
132
	}

	/**
	 * test if cell of dart is marked
	 */
	virtual bool isMarked(Dart d)
	{
Pierre Kraemer's avatar
merge..    
Pierre Kraemer committed
133
		return m_map.getMarkerVector(DART_ORBIT, m_thread)->operator[](d.index).testMark(m_marker);
Pierre Kraemer's avatar
Pierre Kraemer committed
134
135
136
137
138
139
140
	}

	/**
	 * mark the cell
	 */
	virtual void mark(unsigned int em)
	{
Pierre Kraemer's avatar
merge..    
Pierre Kraemer committed
141
		m_map.getMarkerVector(DART_ORBIT, m_thread)->operator[](em).setMark(m_marker);
Pierre Kraemer's avatar
Pierre Kraemer committed
142
143
144
145
146
147
148
	}

	/**
	 * unmark the cell
	 */
	virtual void unmark(unsigned int em)
	{
Pierre Kraemer's avatar
merge..    
Pierre Kraemer committed
149
		m_map.getMarkerVector(DART_ORBIT, m_thread)->operator[](em).unsetMark(m_marker);
Pierre Kraemer's avatar
Pierre Kraemer committed
150
151
152
153
154
155
156
	}

	/**
	 * test if cell is marked
	 */
	virtual bool isMarked(unsigned int em)
	{
Pierre Kraemer's avatar
merge..    
Pierre Kraemer committed
157
		return m_map.getMarkerVector(DART_ORBIT, m_thread)->operator[](em).testMark(m_marker);
Pierre Kraemer's avatar
Pierre Kraemer committed
158
159
160
161
	}

	virtual void markAll()
	{
162
		AttributeContainer& cont = m_map.getAttributeContainer(DART_ORBIT) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
163
		for (unsigned int i = cont.begin(); i != cont.end(); cont.next(i))
Pierre Kraemer's avatar
merge..    
Pierre Kraemer committed
164
			m_map.getMarkerVector(DART_ORBIT, m_thread)->operator[](i).setMark(m_marker);
Pierre Kraemer's avatar
Pierre Kraemer committed
165
166
167
168
	}

	virtual void unmarkAll()
	{
169
		AttributeContainer& cont = m_map.getAttributeContainer(DART_ORBIT) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
170
		for (unsigned int i = cont.begin(); i != cont.end(); cont.next(i))
Pierre Kraemer's avatar
merge..    
Pierre Kraemer committed
171
			m_map.getMarkerVector(DART_ORBIT, m_thread)->operator[](i).unsetMark(m_marker);
Pierre Kraemer's avatar
Pierre Kraemer committed
172
173
174
175
	}

	virtual void markOrbit(unsigned int orbit, Dart d)
	{
Pierre Kraemer's avatar
merge..    
Pierre Kraemer committed
176
		FunctorMark<GenericMap> fm(m_map, m_marker, m_map.getMarkerVector(DART_ORBIT, m_thread)) ;
Sylvain Thery's avatar
Sylvain Thery committed
177
		m_map.foreach_dart_of_orbit(orbit, d, fm, m_thread) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
178
179
180
181
	}

	virtual void unmarkOrbit(unsigned int orbit, Dart d)
	{
Sylvain Thery's avatar
Sylvain Thery committed
182
183
		FunctorUnmark<GenericMap> fm(m_map, m_marker, m_map.getMarkerVector(DART_ORBIT, m_thread)) ;
		m_map.foreach_dart_of_orbit(orbit, d, fm, m_thread) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
184
	}
185
186
187
188

	template <typename MAP>
	void markOrbitInParent(unsigned int orbit, Dart d)
	{
Pierre Kraemer's avatar
merge..    
Pierre Kraemer committed
189
		FunctorMark<GenericMap> fm(m_map, m_marker, m_map.getMarkerVector(DART_ORBIT, m_thread)) ;
190
191
192
193
194
195
196
197
198
		foreach_dart_of_orbit_in_parent<MAP>(dynamic_cast<MAP*>(&m_map), orbit, d, fm, m_thread);
	}

	template <typename MAP>
	void unmarkOrbit(unsigned int orbit, Dart d)
	{
		FunctorUnmark<GenericMap> fm(m_map, m_marker, m_map.getMarkerVector(DART_ORBIT, m_thread)) ;
		foreach_dart_of_orbit_in_parent<MAP>(m_map, orbit, d, fm, m_thread);
	}
Pierre Kraemer's avatar
Pierre Kraemer committed
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
};

/**
 * class that allows the marking of darts
 * the marked darts are stored to optimize the unmarking task at destruction
 * \warning no default constructor
 */
class DartMarkerStore: public DartMarker
{
protected:
	std::vector<unsigned int> m_markedDarts ;

public:
	/**
	 * constructor
	 * @param map the map on which we work
	 */
	DartMarkerStore(GenericMap& map): DartMarker(map)
	{}

Sylvain Thery's avatar
Sylvain Thery committed
219
220
221
	DartMarkerStore(GenericMap& map, unsigned int th): DartMarker(map,th)
	{}

Pierre Kraemer's avatar
Pierre Kraemer committed
222
223
224
225
226
protected:
	// protected copy constructor to forbid its usage
	DartMarkerStore(const DartMarkerStore& dm) : DartMarker(dm)
	{}

Sylvain Thery's avatar
Sylvain Thery committed
227

Pierre Kraemer's avatar
Pierre Kraemer committed
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
public:
	/**
	 * mark the cell of dart
	 */
	void mark(Dart d)
	{
		DartMarker::mark(d) ;
		m_markedDarts.push_back(d.index) ;
	}

	/**
	 * mark the cell
	 */
	void mark(unsigned int em)
	{
		DartMarker::mark(em) ;
Pierre Kraemer's avatar
merge..    
Pierre Kraemer committed
244
		m_markedDarts.push_back(em) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
245
246
247
248
249
	}

	void unmarkAll()
	{
		for (std::vector<unsigned int>::iterator it = m_markedDarts.begin(); it != m_markedDarts.end(); ++it)
Pierre Kraemer's avatar
merge..    
Pierre Kraemer committed
250
			m_map.getMarkerVector(DART_ORBIT, m_thread)->operator[](*it).unsetMark(m_marker) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
	}
};

/**
 * class that allows the marking of darts
 * the markers are not unmarked at destruction
 * \warning no default constructor
 */
class DartMarkerNoUnmark: public DartMarker
{
public:
	/**
	 * constructor
	 * @param map the map on which we work
	 */
	DartMarkerNoUnmark(GenericMap& map): DartMarker(map)
	{}

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

Pierre Kraemer's avatar
Pierre Kraemer committed
272
273
	~DartMarkerNoUnmark()
	{
Pierre Kraemer's avatar
merge..    
Pierre Kraemer committed
274
		m_map.releaseMarker(m_marker, m_thread);
Pierre Kraemer's avatar
Pierre Kraemer committed
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
	}

protected:
	// protected copy constructor to forbid its usage
	DartMarkerNoUnmark(const DartMarkerNoUnmark& dm) : DartMarker(dm)
	{}
};

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

class SelectorMarked : public FunctorSelect
{
protected:
	DartMarker& m_marker;
public:
	SelectorMarked( DartMarker& m) : m_marker(m) {}
	bool operator()(Dart d) const
	{
		return m_marker.isMarked(d);
	}
};

class SelectorUnmarked : public FunctorSelect
{
protected:
	DartMarker& m_marker;
public:
	SelectorUnmarked( DartMarker& m) : m_marker(m) {}
	bool operator()(Dart d) const
	{
		return !m_marker.isMarked(d);
	}
};

// Functor version (needed for use with foreach_xxx)

class FunctorIsMarked : public FunctorType
{
protected:
	DartMarker& m_marker;
public:
	FunctorIsMarked(DartMarker& dm) : m_marker(dm) {}
	bool operator()(Dart d)
	{
		return m_marker.isMarked(d);
	}
};

class FunctorIsUnmarked : public FunctorType
{
protected:
	DartMarker& m_marker;
public:
	FunctorIsUnmarked(DartMarker& dm) : m_marker(dm) {}
	bool operator()(Dart d)
	{
		return !m_marker.isMarked(d);
	}
};

} // namespace CGoGN

#endif