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.83 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"
Pierre Kraemer's avatar
Pierre Kraemer committed
32
33
34
35
36

namespace CGoGN
{

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

public:
	/**
	 * constructor
	 * @param map the map on which we work (not stored use to get table of markers and new marker.
51
	 * @param cell the type of cell we want to mark VERTEX, EDGE,...
Pierre Kraemer's avatar
Pierre Kraemer committed
52
53
	 * \pre the cell is embedded in the map
	 */
54
	CellMarkerGen(AttribMap& map, unsigned int cell) : m_map(map), m_thread(0)
Pierre Kraemer's avatar
Pierre Kraemer committed
55
	{
56
57
		if(!map.isOrbitEmbedded(cell))
			map.addEmbedding(cell) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
58
59
60
		m_marker = map.getNewMarker(cell);
	}

61
	CellMarkerGen(AttribMap& map, unsigned int cell, unsigned int thread) : m_map(map), m_thread(thread)
Sylvain Thery's avatar
Sylvain Thery committed
62
	{
63
		m_marker = map.getNewMarker(cell, thread);
Sylvain Thery's avatar
Sylvain Thery committed
64
65
	}

66
	virtual ~CellMarkerGen()
Pierre Kraemer's avatar
Pierre Kraemer committed
67
	{
68
		m_map.releaseMarker(m_marker, m_thread);
Pierre Kraemer's avatar
Pierre Kraemer committed
69
70
71
72
	}

protected:
	// protected copy constructor to forbid its usage
73
	CellMarkerGen(const CellMarkerGen& cm) : m_map(cm.m_map)
Pierre Kraemer's avatar
Pierre Kraemer committed
74
75
76
77
78
79
80
81
82
	{}

public:
	/**
	 * mark the cell of dart
	 */
	virtual void mark(Dart d)
	{
		unsigned int cell = m_marker.getCell() ;
Pierre Kraemer's avatar
Pierre Kraemer committed
83
		unsigned int a = m_map.getEmbedding(cell, d);
Pierre Kraemer's avatar
Pierre Kraemer committed
84
85
86
		if (a == EMBNULL)
			a = m_map.embedNewCell(cell, d);

87
		m_map.getMarkerVector(cell, m_thread)->operator[](a).setMark(m_marker);
Pierre Kraemer's avatar
Pierre Kraemer committed
88
89
90
91
92
93
94
95
	}

	/**
	 * unmark the cell of dart
	 */
	virtual void unmark(Dart d)
	{
		unsigned int cell = m_marker.getCell() ;
Pierre Kraemer's avatar
Pierre Kraemer committed
96
		unsigned int a = m_map.getEmbedding(cell, d);
Pierre Kraemer's avatar
Pierre Kraemer committed
97
98
99
		if (a == EMBNULL)
			a = m_map.embedNewCell(cell, d);

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

	/**
	 * test if cell of dart is marked
	 */
	virtual bool isMarked(Dart d)
	{
		unsigned int cell = m_marker.getCell() ;
Pierre Kraemer's avatar
Pierre Kraemer committed
109
		unsigned int a = m_map.getEmbedding(cell, d);
Pierre Kraemer's avatar
Pierre Kraemer committed
110
111
112
		if (a == EMBNULL)
			return false;

113
		return m_map.getMarkerVector(cell, m_thread)->operator[](a).testMark(m_marker);
Pierre Kraemer's avatar
Pierre Kraemer committed
114
115
116
117
118
119
120
	}

	/**
	 * mark the cell
	 */
	virtual void mark(unsigned int em)
	{
121
		m_map.getMarkerVector(m_marker.getCell(), m_thread)->operator[](em).setMark(m_marker);
Pierre Kraemer's avatar
Pierre Kraemer committed
122
123
124
125
126
127
128
	}

	/**
	 * unmark the cell
	 */
	virtual void unmark(unsigned int em)
	{
129
		m_map.getMarkerVector(m_marker.getCell(), m_thread)->operator[](em).unsetMark(m_marker);
Pierre Kraemer's avatar
Pierre Kraemer committed
130
131
132
133
134
135
136
	}

	/**
	 * test if cell is marked
	 */
	virtual bool isMarked(unsigned int em)
	{
137
		return m_map.getMarkerVector(m_marker.getCell(), m_thread)->operator[](em).testMark(m_marker);
Pierre Kraemer's avatar
Pierre Kraemer committed
138
139
	}

140
141
142
	/**
	 * mark all the cells
	 */
Pierre Kraemer's avatar
Pierre Kraemer committed
143
144
145
	virtual void markAll()
	{
		unsigned int cell = m_marker.getCell() ;
146
		AttributeContainer& cont = m_map.getAttributeContainer(cell) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
147
		for (unsigned int i = cont.begin(); i != cont.end(); cont.next(i))
148
			m_map.getMarkerVector(cell,m_thread)->operator[](i).setMark(m_marker);
Pierre Kraemer's avatar
Pierre Kraemer committed
149
150
	}

151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
	/**
	 * unmark all the cells
	 */
	virtual void unmarkAll() = 0 ;
};

/**
 * class that allows the marking of cells
 * \warning no default constructor
 */
class CellMarker : public CellMarkerGen
{
public:
	CellMarker(AttribMap& map, unsigned int cell) : CellMarkerGen(map, cell)
	{}

	CellMarker(AttribMap& map, unsigned int cell, unsigned int thread) : CellMarkerGen(map, cell, thread)
	{}

	virtual ~CellMarker()
	{
		unmarkAll() ;
	}

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

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

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

public:
200
	CellMarkerStore(AttribMap& map, unsigned int cell) : CellMarkerGen(map, cell)
Pierre Kraemer's avatar
Pierre Kraemer committed
201
202
	{}

203
	CellMarkerStore(AttribMap& map, unsigned int cell, unsigned int thread) : CellMarkerGen(map, cell, thread)
Sylvain Thery's avatar
Sylvain Thery committed
204
205
	{}

206
207
	~CellMarkerStore()
	{
208
		unmarkAll() ;
209
210
	}

Pierre Kraemer's avatar
Pierre Kraemer committed
211
protected:
212
	CellMarkerStore(const CellMarkerStore& cm) : CellMarkerGen(cm)
Pierre Kraemer's avatar
Pierre Kraemer committed
213
214
215
216
217
	{}

public:
	void mark(Dart d)
	{
218
		CellMarkerGen::mark(d) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
219
		m_markedCells.push_back(m_map.getEmbedding(m_marker.getCell(), d)) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
220
221
222
223
	}

	void mark(unsigned int em)
	{
224
225
		CellMarkerGen::mark(em) ;
		m_markedCells.push_back(em) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
226
227
228
229
230
231
	}

	void unmarkAll()
	{
		unsigned int cell = m_marker.getCell() ;
		for (std::vector<unsigned int>::iterator it = m_markedCells.begin(); it != m_markedCells.end(); ++it)
232
			m_map.getMarkerVector(cell,m_thread)->operator[](*it).unsetMark(m_marker) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
233
234
235
236
237
238
239
240
	}
};

/**
 * class that allows the marking of cells
 * the markers are not unmarked at destruction
 * \warning no default constructor
 */
241
class CellMarkerNoUnmark: public CellMarkerGen
Pierre Kraemer's avatar
Pierre Kraemer committed
242
243
{
public:
244
	CellMarkerNoUnmark(AttribMap& map, unsigned int cell) : CellMarkerGen(map, cell)
Pierre Kraemer's avatar
Pierre Kraemer committed
245
246
	{}

Sylvain Thery's avatar
Sylvain Thery committed
247

248
	CellMarkerNoUnmark(AttribMap& map, unsigned int cell, unsigned int thread) : CellMarkerGen(map, cell, thread)
Sylvain Thery's avatar
Sylvain Thery committed
249
250
	{}

Pierre Kraemer's avatar
Pierre Kraemer committed
251
	~CellMarkerNoUnmark()
252
	{}
Pierre Kraemer's avatar
Pierre Kraemer committed
253
254

protected:
255
	CellMarkerNoUnmark(const CellMarkerNoUnmark& cm) : CellMarkerGen(cm)
Pierre Kraemer's avatar
Pierre Kraemer committed
256
	{}
257
258
259
260
261
262
263
264
265

public:
	void unmarkAll()
	{
		unsigned int cell = m_marker.getCell() ;
		AttributeContainer& cont = m_map.getAttributeContainer(cell) ;
		for (unsigned int i = cont.begin(); i != cont.end(); cont.next(i))
			m_map.getMarkerVector(cell, m_thread)->operator[](i).unsetMark(m_marker) ;
	}
Pierre Kraemer's avatar
Pierre Kraemer committed
266
267
};

Sylvain Thery's avatar
Sylvain Thery committed
268
269

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

286
class SelectorCellUnmarked : public FunctorSelect
287
288
{
protected:
289
	CellMarkerGen& m_cmarker ;
290
public:
291
	SelectorCellUnmarked(CellMarkerGen& cm) : m_cmarker(cm) {}
292
293
294
	bool operator()(Dart d) const
	{
		if (!m_cmarker.isMarked(d))
295
296
			return true ;
		return false ;
297
298
	}
};
Sylvain Thery's avatar
Sylvain Thery committed
299

Pierre Kraemer's avatar
Pierre Kraemer committed
300
301
302
} // namespace CGoGN

#endif