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.

cellmarker.h 8.99 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
* Contact information: cgogn@unistra.fr                                        *
*                                                                              *
*******************************************************************************/

#ifndef __CELL_MARKER__
#define __CELL_MARKER__

#include "Topology/generic/marker.h"
29
#include "Topology/generic/attribmap.h"
Pierre Kraemer's avatar
Pierre Kraemer committed
30

Sylvain Thery's avatar
Sylvain Thery committed
31
#include "Topology/generic/functor.h"
32
#include "Utils/static_assert.h"
Pierre Kraemer's avatar
Pierre Kraemer committed
33
34
35
36
37

namespace CGoGN
{

/**
38
 * generic class that allows the marking of cells
Pierre Kraemer's avatar
Pierre Kraemer committed
39
40
 * \warning no default constructor
 */
41
class CellMarkerGen
Pierre Kraemer's avatar
Pierre Kraemer committed
42
43
{
protected:
Pierre Kraemer's avatar
Pierre Kraemer committed
44
45
46
47
	Mark m_mark ;
	AttribMap& m_map ;
	unsigned int m_cell ;
	unsigned int m_thread ;
Pierre Kraemer's avatar
Pierre Kraemer committed
48
49
50
51

public:
	/**
	 * constructor
52
	 * @param map the map on which we work
53
	 * @param cell the type of cell we want to mark VERTEX, EDGE,...
Pierre Kraemer's avatar
Pierre Kraemer committed
54
	 */
Pierre Kraemer's avatar
Pierre Kraemer committed
55
	CellMarkerGen(AttribMap& map, unsigned int cell, unsigned int thread = 0) : m_map(map), m_cell(cell), m_thread(thread)
Pierre Kraemer's avatar
Pierre Kraemer committed
56
	{
57
58
		if(!map.isOrbitEmbedded(cell))
			map.addEmbedding(cell) ;
Sylvain Thery's avatar
Sylvain Thery committed
59
		m_mark = m_map.getMarkerSet(m_cell,m_thread).getNewMark() ;
Sylvain Thery's avatar
Sylvain Thery committed
60
61
	}

62
	virtual ~CellMarkerGen()
Pierre Kraemer's avatar
Pierre Kraemer committed
63
	{
Sylvain Thery's avatar
Sylvain Thery committed
64
		m_map.getMarkerSet(m_cell,m_thread).releaseMark(m_mark) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
65
66
67
68
	}

protected:
	// protected copy constructor to forbid its usage
69
	CellMarkerGen(const CellMarkerGen& cm) : m_map(cm.m_map)
Pierre Kraemer's avatar
Pierre Kraemer committed
70
71
72
73
74
75
76
77
	{}

public:
	/**
	 * mark the cell of dart
	 */
	virtual void mark(Dart d)
	{
Sylvain Thery's avatar
Sylvain Thery committed
78
79
80
		assert(m_map.getMarkerSet(m_cell,m_thread).testMark(m_mark));
		assert(m_map.getMarkVector(m_cell, m_thread) != NULL);

Pierre Kraemer's avatar
Pierre Kraemer committed
81
		unsigned int a = m_map.getEmbedding(m_cell, d) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
82
		if (a == EMBNULL)
Pierre Kraemer's avatar
Pierre Kraemer committed
83
			a = m_map.embedNewCell(m_cell, d) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
84

Pierre Kraemer's avatar
Pierre Kraemer committed
85
		m_map.getMarkVector(m_cell, m_thread)->operator[](a).setMark(m_mark) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
86
87
88
89
90
91
92
	}

	/**
	 * unmark the cell of dart
	 */
	virtual void unmark(Dart d)
	{
Sylvain Thery's avatar
Sylvain Thery committed
93
94
95
		assert(m_map.getMarkerSet(m_cell,m_thread).testMark(m_mark));
		assert(m_map.getMarkVector(m_cell, m_thread) != NULL);

Pierre Kraemer's avatar
Pierre Kraemer committed
96
		unsigned int a = m_map.getEmbedding(m_cell, d) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
97
		if (a == EMBNULL)
Pierre Kraemer's avatar
Pierre Kraemer committed
98
			a = m_map.embedNewCell(m_cell, d) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
99

Pierre Kraemer's avatar
Pierre Kraemer committed
100
		m_map.getMarkVector(m_cell, m_thread)->operator[](a).unsetMark(m_mark) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
101
102
103
104
105
106
107
	}

	/**
	 * test if cell of dart is marked
	 */
	virtual bool isMarked(Dart d)
	{
Sylvain Thery's avatar
Sylvain Thery committed
108
109
110
		assert(m_map.getMarkerSet(m_cell,m_thread).testMark(m_mark));
		assert(m_map.getMarkVector(m_cell, m_thread) != NULL);

Pierre Kraemer's avatar
Pierre Kraemer committed
111
		unsigned int a = m_map.getEmbedding(m_cell, d) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
112
		if (a == EMBNULL)
Pierre Kraemer's avatar
Pierre Kraemer committed
113
			return false ;
Pierre Kraemer's avatar
Pierre Kraemer committed
114

Pierre Kraemer's avatar
Pierre Kraemer committed
115
		return m_map.getMarkVector(m_cell, m_thread)->operator[](a).testMark(m_mark) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
116
117
118
119
120
121
122
	}

	/**
	 * mark the cell
	 */
	virtual void mark(unsigned int em)
	{
Sylvain Thery's avatar
Sylvain Thery committed
123
124
125
		assert(m_map.getMarkerSet(m_cell,m_thread).testMark(m_mark));
		assert(m_map.getMarkVector(m_cell, m_thread) != NULL);

Pierre Kraemer's avatar
Pierre Kraemer committed
126
		m_map.getMarkVector(m_cell, m_thread)->operator[](em).setMark(m_mark) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
127
128
129
130
131
132
133
	}

	/**
	 * unmark the cell
	 */
	virtual void unmark(unsigned int em)
	{
Sylvain Thery's avatar
Sylvain Thery committed
134
135
136
		assert(m_map.getMarkerSet(m_cell,m_thread).testMark(m_mark));
		assert(m_map.getMarkVector(m_cell, m_thread) != NULL);

Pierre Kraemer's avatar
Pierre Kraemer committed
137
		m_map.getMarkVector(m_cell, m_thread)->operator[](em).unsetMark(m_mark) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
138
139
140
141
142
143
144
	}

	/**
	 * test if cell is marked
	 */
	virtual bool isMarked(unsigned int em)
	{
Sylvain Thery's avatar
Sylvain Thery committed
145
146
147
		assert(m_map.getMarkerSet(m_cell,m_thread).testMark(m_mark));
		assert(m_map.getMarkVector(m_cell, m_thread) != NULL);

Pierre Kraemer's avatar
Pierre Kraemer committed
148
		return m_map.getMarkVector(m_cell, m_thread)->operator[](em).testMark(m_mark) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
149
150
	}

151
152
153
	/**
	 * mark all the cells
	 */
Pierre Kraemer's avatar
Pierre Kraemer committed
154
155
	virtual void markAll()
	{
Sylvain Thery's avatar
Sylvain Thery committed
156
157
158
159
		assert(m_map.getMarkerSet(m_cell,m_thread).testMark(m_mark));
		AttributeMultiVector<Mark>* mark_vect = m_map.getMarkVector(m_cell, m_thread);
		assert(mark_vect != NULL);

Pierre Kraemer's avatar
Pierre Kraemer committed
160
		AttributeContainer& cont = m_map.getAttributeContainer(m_cell) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
161
		for (unsigned int i = cont.begin(); i != cont.end(); cont.next(i))
Sylvain Thery's avatar
Sylvain Thery committed
162
			mark_vect->operator[](i).setMark(m_mark) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
163
164
	}

165
166
167
168
	/**
	 * unmark all the cells
	 */
	virtual void unmarkAll() = 0 ;
Pierre Kraemer's avatar
Pierre Kraemer committed
169
170
171

	bool isAllUnmarked()
	{
Sylvain Thery's avatar
Sylvain Thery committed
172
173
174
175
176
		assert(m_map.getMarkerSet(m_cell,m_thread).testMark(m_mark));

		AttributeMultiVector<Mark>* mark_vect = m_map.getMarkVector(m_cell, m_thread);
		assert(mark_vect != NULL);

Pierre Kraemer's avatar
Pierre Kraemer committed
177
178
		AttributeContainer& cont = m_map.getAttributeContainer(m_cell) ;
		for (unsigned int i = cont.begin(); i != cont.end(); cont.next(i))
Sylvain Thery's avatar
Sylvain Thery committed
179
			if(mark_vect->operator[](i).testMark(m_mark))
Pierre Kraemer's avatar
Pierre Kraemer committed
180
181
182
				return false ;
		return true ;
	}
183
184
185
186
187
188
189
190
191
};

/**
 * class that allows the marking of cells
 * \warning no default constructor
 */
class CellMarker : public CellMarkerGen
{
public:
Pierre Kraemer's avatar
Pierre Kraemer committed
192
	CellMarker(AttribMap& map, unsigned int cell, unsigned int thread = 0) : CellMarkerGen(map, cell, thread)
193
194
195
196
197
198
199
200
201
202
203
204
	{}

	virtual ~CellMarker()
	{
		unmarkAll() ;
	}

protected:
	CellMarker(const CellMarker& cm) : CellMarkerGen(cm)
	{}

public:
Pierre Kraemer's avatar
Pierre Kraemer committed
205
206
	virtual void unmarkAll()
	{
Sylvain Thery's avatar
Sylvain Thery committed
207
208
209
210
		assert(m_map.getMarkerSet(m_cell,m_thread).testMark(m_mark));
		AttributeMultiVector<Mark>* mark_vect = m_map.getMarkVector(m_cell, m_thread);
		assert(mark_vect != NULL);

Pierre Kraemer's avatar
Pierre Kraemer committed
211
		AttributeContainer& cont = m_map.getAttributeContainer(m_cell) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
212
		for (unsigned int i = cont.begin(); i != cont.end(); cont.next(i))
Sylvain Thery's avatar
Sylvain Thery committed
213
			mark_vect->operator[](i).unsetMark(m_mark) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
214
215
216
217
218
219
220
221
	}
};

/**
 * class that allows the marking of cells
 * the marked cells are stored to optimize the unmarking task at destruction
 * \warning no default constructor
 */
222
class CellMarkerStore: public CellMarkerGen
Pierre Kraemer's avatar
Pierre Kraemer committed
223
224
225
226
227
{
protected:
	std::vector<unsigned int> m_markedCells ;

public:
Pierre Kraemer's avatar
Pierre Kraemer committed
228
	CellMarkerStore(AttribMap& map, unsigned int cell, unsigned int thread = 0) : CellMarkerGen(map, cell, thread)
Pierre Kraemer's avatar
Pierre Kraemer committed
229
230
	{}

231

Pierre Kraemer's avatar
Pierre Kraemer committed
232
	virtual ~CellMarkerStore()
233
	{
234
		unmarkAll() ;
235
236
//		assert(isAllUnmarked);
		CGoGN_ASSERT(isAllUnmarked())
237
238
	}

Pierre Kraemer's avatar
Pierre Kraemer committed
239
protected:
240
	CellMarkerStore(const CellMarkerStore& cm) : CellMarkerGen(cm)
Pierre Kraemer's avatar
Pierre Kraemer committed
241
242
243
244
245
	{}

public:
	void mark(Dart d)
	{
246
		CellMarkerGen::mark(d) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
247
		m_markedCells.push_back(m_map.getEmbedding(m_cell, d)) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
248
249
250
251
	}

	void mark(unsigned int em)
	{
252
253
		CellMarkerGen::mark(em) ;
		m_markedCells.push_back(em) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
254
255
256
257
	}

	void unmarkAll()
	{
Sylvain Thery's avatar
Sylvain Thery committed
258
259
260
261
		assert(m_map.getMarkerSet(m_cell,m_thread).testMark(m_mark));
		AttributeMultiVector<Mark>* mark_vect = m_map.getMarkVector(m_cell, m_thread);
		assert(mark_vect != NULL);

Pierre Kraemer's avatar
Pierre Kraemer committed
262
		for (std::vector<unsigned int>::iterator it = m_markedCells.begin(); it != m_markedCells.end(); ++it)
Sylvain Thery's avatar
Sylvain Thery committed
263
			mark_vect->operator[](*it).unsetMark(m_mark) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
264
265
266
267
268
269
270
271
	}
};

/**
 * class that allows the marking of cells
 * the markers are not unmarked at destruction
 * \warning no default constructor
 */
272
class CellMarkerNoUnmark: public CellMarkerGen
Pierre Kraemer's avatar
Pierre Kraemer committed
273
274
{
public:
Pierre Kraemer's avatar
Pierre Kraemer committed
275
	CellMarkerNoUnmark(AttribMap& map, unsigned int cell, unsigned int thread = 0) : CellMarkerGen(map, cell, thread)
Pierre Kraemer's avatar
Pierre Kraemer committed
276
	{}
Sylvain Thery's avatar
Sylvain Thery committed
277

Pierre Kraemer's avatar
Pierre Kraemer committed
278
279
	virtual ~CellMarkerNoUnmark()
	{
280
281
//		assert(isAllUnmarked()) ;
		CGoGN_ASSERT(isAllUnmarked())
Pierre Kraemer's avatar
Pierre Kraemer committed
282
	}
Pierre Kraemer's avatar
Pierre Kraemer committed
283
284

protected:
285
	CellMarkerNoUnmark(const CellMarkerNoUnmark& cm) : CellMarkerGen(cm)
Pierre Kraemer's avatar
Pierre Kraemer committed
286
	{}
287
288
289
290

public:
	void unmarkAll()
	{
Sylvain Thery's avatar
Sylvain Thery committed
291
292
293
294
		assert(m_map.getMarkerSet(m_cell,m_thread).testMark(m_mark));
		AttributeMultiVector<Mark>* mark_vect = m_map.getMarkVector(m_cell, m_thread);
		assert(mark_vect != NULL);

Pierre Kraemer's avatar
Pierre Kraemer committed
295
		AttributeContainer& cont = m_map.getAttributeContainer(m_cell) ;
296
		for (unsigned int i = cont.begin(); i != cont.end(); cont.next(i))
Sylvain Thery's avatar
Sylvain Thery committed
297
			mark_vect->operator[](i).unsetMark(m_mark) ;
298
	}
Pierre Kraemer's avatar
Pierre Kraemer committed
299
300
};

Sylvain Thery's avatar
Sylvain Thery committed
301
302

/**
303
 * selector that say if a dart has its cell marked
Sylvain Thery's avatar
Sylvain Thery committed
304
 */
305
class SelectorCellMarked : public FunctorSelect
Sylvain Thery's avatar
Sylvain Thery committed
306
307
{
protected:
308
	CellMarkerGen& m_cmarker ;
Sylvain Thery's avatar
Sylvain Thery committed
309
public:
310
	SelectorCellMarked(CellMarkerGen& cm) : m_cmarker(cm) {}
Sylvain Thery's avatar
Sylvain Thery committed
311
312
313
	bool operator()(Dart d) const
	{
		if (m_cmarker.isMarked(d))
314
315
			return true ;
		return false ;
Sylvain Thery's avatar
Sylvain Thery committed
316
317
318
	}
};

319
class SelectorCellUnmarked : public FunctorSelect
320
321
{
protected:
322
	CellMarkerGen& m_cmarker ;
323
public:
324
	SelectorCellUnmarked(CellMarkerGen& cm) : m_cmarker(cm) {}
325
326
327
	bool operator()(Dart d) const
	{
		if (!m_cmarker.isMarked(d))
328
329
			return true ;
		return false ;
330
331
	}
};
Sylvain Thery's avatar
Sylvain Thery committed
332

Pierre Kraemer's avatar
Pierre Kraemer committed
333
334
335
} // namespace CGoGN

#endif