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 7.58 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
52

public:
	/**
	 * constructor
	 * @param map the map on which we work (not stored use to get table of markers and new marker.
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) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
59
		m_mark = map.getNewMark(cell, thread) ;
Sylvain Thery's avatar
Sylvain Thery committed
60
61
	}

62
	virtual ~CellMarkerGen()
Pierre Kraemer's avatar
Pierre Kraemer committed
63
	{
Pierre Kraemer's avatar
Pierre Kraemer committed
64
		m_map.releaseMark(m_mark, m_cell, m_thread);
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)
	{
Pierre Kraemer's avatar
Pierre Kraemer committed
78
		unsigned int a = m_map.getEmbedding(m_cell, d) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
79
		if (a == EMBNULL)
Pierre Kraemer's avatar
Pierre Kraemer committed
80
			a = m_map.embedNewCell(m_cell, d) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
81

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

	/**
	 * unmark the cell of dart
	 */
	virtual void unmark(Dart d)
	{
Pierre Kraemer's avatar
Pierre Kraemer committed
90
		unsigned int a = m_map.getEmbedding(m_cell, d) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
91
		if (a == EMBNULL)
Pierre Kraemer's avatar
Pierre Kraemer committed
92
			a = m_map.embedNewCell(m_cell, d) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
93

Pierre Kraemer's avatar
Pierre Kraemer committed
94
		m_map.getMarkVector(m_cell, m_thread)->operator[](a).unsetMark(m_mark) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
95
96
97
98
99
100
101
	}

	/**
	 * test if cell of dart is marked
	 */
	virtual bool isMarked(Dart d)
	{
Pierre Kraemer's avatar
Pierre Kraemer committed
102
		unsigned int a = m_map.getEmbedding(m_cell, d) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
103
		if (a == EMBNULL)
Pierre Kraemer's avatar
Pierre Kraemer committed
104
			return false ;
Pierre Kraemer's avatar
Pierre Kraemer committed
105

Pierre Kraemer's avatar
Pierre Kraemer committed
106
		return m_map.getMarkVector(m_cell, m_thread)->operator[](a).testMark(m_mark) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
107
108
109
110
111
112
113
	}

	/**
	 * mark the cell
	 */
	virtual void mark(unsigned int em)
	{
Pierre Kraemer's avatar
Pierre Kraemer committed
114
		m_map.getMarkVector(m_cell, m_thread)->operator[](em).setMark(m_mark) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
115
116
117
118
119
120
121
	}

	/**
	 * unmark the cell
	 */
	virtual void unmark(unsigned int em)
	{
Pierre Kraemer's avatar
Pierre Kraemer committed
122
		m_map.getMarkVector(m_cell, m_thread)->operator[](em).unsetMark(m_mark) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
123
124
125
126
127
128
129
	}

	/**
	 * test if cell is marked
	 */
	virtual bool isMarked(unsigned int em)
	{
Pierre Kraemer's avatar
Pierre Kraemer committed
130
		return m_map.getMarkVector(m_cell, m_thread)->operator[](em).testMark(m_mark) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
131
132
	}

133
134
135
	/**
	 * mark all the cells
	 */
Pierre Kraemer's avatar
Pierre Kraemer committed
136
137
	virtual void markAll()
	{
Pierre Kraemer's avatar
Pierre Kraemer committed
138
		AttributeContainer& cont = m_map.getAttributeContainer(m_cell) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
139
		for (unsigned int i = cont.begin(); i != cont.end(); cont.next(i))
Pierre Kraemer's avatar
Pierre Kraemer committed
140
			m_map.getMarkVector(m_cell, m_thread)->operator[](i).setMark(m_mark) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
141
142
	}

143
144
145
146
	/**
	 * unmark all the cells
	 */
	virtual void unmarkAll() = 0 ;
Pierre Kraemer's avatar
Pierre Kraemer committed
147
148
149
150
151
152
153
154
155

	bool isAllUnmarked()
	{
		AttributeContainer& cont = m_map.getAttributeContainer(m_cell) ;
		for (unsigned int i = cont.begin(); i != cont.end(); cont.next(i))
			if(m_map.getMarkVector(m_cell, m_thread)->operator[](i).testMark(m_mark))
				return false ;
		return true ;
	}
156
157
158
159
160
161
162
163
164
};

/**
 * class that allows the marking of cells
 * \warning no default constructor
 */
class CellMarker : public CellMarkerGen
{
public:
Pierre Kraemer's avatar
Pierre Kraemer committed
165
	CellMarker(AttribMap& map, unsigned int cell, unsigned int thread = 0) : CellMarkerGen(map, cell, thread)
166
167
168
169
170
171
172
173
174
175
176
177
	{}

	virtual ~CellMarker()
	{
		unmarkAll() ;
	}

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

public:
Pierre Kraemer's avatar
Pierre Kraemer committed
178
179
	virtual void unmarkAll()
	{
Pierre Kraemer's avatar
Pierre Kraemer committed
180
		AttributeContainer& cont = m_map.getAttributeContainer(m_cell) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
181
		for (unsigned int i = cont.begin(); i != cont.end(); cont.next(i))
Pierre Kraemer's avatar
Pierre Kraemer committed
182
			m_map.getMarkVector(m_cell, m_thread)->operator[](i).unsetMark(m_mark) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
183
184
185
186
187
188
189
190
	}
};

/**
 * class that allows the marking of cells
 * the marked cells are stored to optimize the unmarking task at destruction
 * \warning no default constructor
 */
191
class CellMarkerStore: public CellMarkerGen
Pierre Kraemer's avatar
Pierre Kraemer committed
192
193
194
195
196
{
protected:
	std::vector<unsigned int> m_markedCells ;

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

200

Pierre Kraemer's avatar
Pierre Kraemer committed
201
	virtual ~CellMarkerStore()
202
	{
203
		unmarkAll() ;
204
205
//		assert(isAllUnmarked);
		CGoGN_ASSERT(isAllUnmarked())
206
207
	}

Pierre Kraemer's avatar
Pierre Kraemer committed
208
protected:
209
	CellMarkerStore(const CellMarkerStore& cm) : CellMarkerGen(cm)
Pierre Kraemer's avatar
Pierre Kraemer committed
210
211
212
213
214
	{}

public:
	void mark(Dart d)
	{
215
		CellMarkerGen::mark(d) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
216
		m_markedCells.push_back(m_map.getEmbedding(m_cell, d)) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
217
218
219
220
	}

	void mark(unsigned int em)
	{
221
222
		CellMarkerGen::mark(em) ;
		m_markedCells.push_back(em) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
223
224
225
226
227
	}

	void unmarkAll()
	{
		for (std::vector<unsigned int>::iterator it = m_markedCells.begin(); it != m_markedCells.end(); ++it)
Pierre Kraemer's avatar
Pierre Kraemer committed
228
			m_map.getMarkVector(m_cell, m_thread)->operator[](*it).unsetMark(m_mark) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
229
230
231
232
233
234
235
236
	}
};

/**
 * class that allows the marking of cells
 * the markers are not unmarked at destruction
 * \warning no default constructor
 */
237
class CellMarkerNoUnmark: public CellMarkerGen
Pierre Kraemer's avatar
Pierre Kraemer committed
238
239
{
public:
Pierre Kraemer's avatar
Pierre Kraemer committed
240
	CellMarkerNoUnmark(AttribMap& map, unsigned int cell, unsigned int thread = 0) : CellMarkerGen(map, cell, thread)
Pierre Kraemer's avatar
Pierre Kraemer committed
241
	{}
Sylvain Thery's avatar
Sylvain Thery committed
242

Pierre Kraemer's avatar
Pierre Kraemer committed
243
244
	virtual ~CellMarkerNoUnmark()
	{
245
246
//		assert(isAllUnmarked()) ;
		CGoGN_ASSERT(isAllUnmarked())
Pierre Kraemer's avatar
Pierre Kraemer committed
247
	}
Pierre Kraemer's avatar
Pierre Kraemer committed
248
249

protected:
250
	CellMarkerNoUnmark(const CellMarkerNoUnmark& cm) : CellMarkerGen(cm)
Pierre Kraemer's avatar
Pierre Kraemer committed
251
	{}
252
253
254
255

public:
	void unmarkAll()
	{
Pierre Kraemer's avatar
Pierre Kraemer committed
256
		AttributeContainer& cont = m_map.getAttributeContainer(m_cell) ;
257
		for (unsigned int i = cont.begin(); i != cont.end(); cont.next(i))
Pierre Kraemer's avatar
Pierre Kraemer committed
258
			m_map.getMarkVector(m_cell, m_thread)->operator[](i).unsetMark(m_mark) ;
259
	}
Pierre Kraemer's avatar
Pierre Kraemer committed
260
261
};

Sylvain Thery's avatar
Sylvain Thery committed
262
263

/**
264
 * selector that say if a dart has its cell marked
Sylvain Thery's avatar
Sylvain Thery committed
265
 */
266
class SelectorCellMarked : public FunctorSelect
Sylvain Thery's avatar
Sylvain Thery committed
267
268
{
protected:
269
	CellMarkerGen& m_cmarker ;
Sylvain Thery's avatar
Sylvain Thery committed
270
public:
271
	SelectorCellMarked(CellMarkerGen& cm) : m_cmarker(cm) {}
Sylvain Thery's avatar
Sylvain Thery committed
272
273
274
	bool operator()(Dart d) const
	{
		if (m_cmarker.isMarked(d))
275
276
			return true ;
		return false ;
Sylvain Thery's avatar
Sylvain Thery committed
277
278
279
	}
};

280
class SelectorCellUnmarked : public FunctorSelect
281
282
{
protected:
283
	CellMarkerGen& m_cmarker ;
284
public:
285
	SelectorCellUnmarked(CellMarkerGen& cm) : m_cmarker(cm) {}
286
287
288
	bool operator()(Dart d) const
	{
		if (!m_cmarker.isMarked(d))
289
290
			return true ;
		return false ;
291
292
	}
};
Sylvain Thery's avatar
Sylvain Thery committed
293

Pierre Kraemer's avatar
Pierre Kraemer committed
294
295
296
} // namespace CGoGN

#endif