Création d'un compte pour un collaborateur extérieur au laboratoire depuis l'intranet ICube : https://intranet.icube.unistra.fr/fr/labs/member/profile

cellmarker.h 7.49 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
{
protected:
Pierre Kraemer's avatar
Pierre Kraemer committed
43
	Mark m_mark;
44
	AttribMap& m_map;
Pierre Kraemer's avatar
Pierre Kraemer committed
45
	unsigned int m_cell;
Sylvain Thery's avatar
Sylvain Thery committed
46
	unsigned int m_thread;
Pierre Kraemer's avatar
Pierre Kraemer committed
47
48
49
50
51

public:
	/**
	 * constructor
	 * @param map the map on which we work (not stored use to get table of markers and new marker.
52
	 * @param cell the type of cell we want to mark VERTEX, EDGE,...
Pierre Kraemer's avatar
Pierre Kraemer committed
53
	 */
Pierre Kraemer's avatar
Pierre Kraemer committed
54
	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
55
	{
56
57
		if(!map.isOrbitEmbedded(cell))
			map.addEmbedding(cell) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
58
		m_mark = map.getNewMark(cell, thread);
Sylvain Thery's avatar
Sylvain Thery committed
59
60
	}

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

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

public:
	/**
	 * mark the cell of dart
	 */
	virtual void mark(Dart d)
	{
Pierre Kraemer's avatar
Pierre Kraemer committed
77
		unsigned int a = m_map.getEmbedding(m_cell, d);
Pierre Kraemer's avatar
Pierre Kraemer committed
78
		if (a == EMBNULL)
Pierre Kraemer's avatar
Pierre Kraemer committed
79
			a = m_map.embedNewCell(m_cell, d);
Pierre Kraemer's avatar
Pierre Kraemer committed
80

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

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

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

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

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

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

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

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

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

142
143
144
145
146
147
148
149
150
151
152
153
154
	/**
	 * unmark all the cells
	 */
	virtual void unmarkAll() = 0 ;
};

/**
 * class that allows the marking of cells
 * \warning no default constructor
 */
class CellMarker : public CellMarkerGen
{
public:
Pierre Kraemer's avatar
Pierre Kraemer committed
155
	CellMarker(AttribMap& map, unsigned int cell, unsigned int thread = 0) : CellMarkerGen(map, cell, thread)
156
157
158
159
160
161
162
163
164
165
166
167
	{}

	virtual ~CellMarker()
	{
		unmarkAll() ;
	}

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

public:
Pierre Kraemer's avatar
Pierre Kraemer committed
168
169
	virtual void unmarkAll()
	{
Pierre Kraemer's avatar
Pierre Kraemer committed
170
		AttributeContainer& cont = m_map.getAttributeContainer(m_cell) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
171
		for (unsigned int i = cont.begin(); i != cont.end(); cont.next(i))
Pierre Kraemer's avatar
Pierre Kraemer committed
172
			m_map.getMarkVector(m_cell, m_thread)->operator[](i).unsetMark(m_mark) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
173
174
175
176
177
178
179
180
	}
};

/**
 * class that allows the marking of cells
 * the marked cells are stored to optimize the unmarking task at destruction
 * \warning no default constructor
 */
181
class CellMarkerStore: public CellMarkerGen
Pierre Kraemer's avatar
Pierre Kraemer committed
182
183
184
185
186
{
protected:
	std::vector<unsigned int> m_markedCells ;

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

Pierre Kraemer's avatar
Pierre Kraemer committed
190
	virtual ~CellMarkerStore()
191
	{
192
		unmarkAll() ;
193
194
	}

Pierre Kraemer's avatar
Pierre Kraemer committed
195
protected:
196
	CellMarkerStore(const CellMarkerStore& cm) : CellMarkerGen(cm)
Pierre Kraemer's avatar
Pierre Kraemer committed
197
198
199
200
201
	{}

public:
	void mark(Dart d)
	{
202
		CellMarkerGen::mark(d) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
203
		m_markedCells.push_back(m_map.getEmbedding(m_cell, d)) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
204
205
206
207
	}

	void mark(unsigned int em)
	{
208
209
		CellMarkerGen::mark(em) ;
		m_markedCells.push_back(em) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
210
211
212
213
214
	}

	void unmarkAll()
	{
		for (std::vector<unsigned int>::iterator it = m_markedCells.begin(); it != m_markedCells.end(); ++it)
Pierre Kraemer's avatar
Pierre Kraemer committed
215
			m_map.getMarkVector(m_cell, m_thread)->operator[](*it).unsetMark(m_mark) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
216
217
218
219
220
221
222
223
	}
};

/**
 * class that allows the marking of cells
 * the markers are not unmarked at destruction
 * \warning no default constructor
 */
224
class CellMarkerNoUnmark: public CellMarkerGen
Pierre Kraemer's avatar
Pierre Kraemer committed
225
226
{
public:
Pierre Kraemer's avatar
Pierre Kraemer committed
227
228
229
230
	CellMarkerNoUnmark(AttribMap& map, unsigned int cell, unsigned int thread = 0) : CellMarkerGen(map, cell, thread)
	{
		std::cout << "CellMarkerNoUnmark.." << std::endl ;
	}
Sylvain Thery's avatar
Sylvain Thery committed
231

Pierre Kraemer's avatar
Pierre Kraemer committed
232
233
234
235
	virtual ~CellMarkerNoUnmark()
	{
		assert(isAllUnmarked());
	}
Pierre Kraemer's avatar
Pierre Kraemer committed
236
237

protected:
238
	CellMarkerNoUnmark(const CellMarkerNoUnmark& cm) : CellMarkerGen(cm)
Pierre Kraemer's avatar
Pierre Kraemer committed
239
	{}
240

Pierre Kraemer's avatar
Pierre Kraemer committed
241
242
243
244
245
246
247
248
249
	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 ;
	}

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

Sylvain Thery's avatar
Sylvain Thery committed
259
260

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

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

Pierre Kraemer's avatar
Pierre Kraemer committed
291
292
293
} // namespace CGoGN

#endif