cellmarker.h 7.77 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
/*******************************************************************************
* 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 __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

#define VERTEX_CELL	VERTEX_ORBIT
#define EDGE_CELL	EDGE_ORBIT
Pierre Kraemer's avatar
Pierre Kraemer committed
35
#define ORIENTED_FACE_CELL	ORIENTED_FACE_ORBIT
Pierre Kraemer's avatar
Pierre Kraemer committed
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
#define FACE_CELL	FACE_ORBIT
#define VOLUME_CELL	VOLUME_ORBIT
#define DART_CELL	DART_ORBIT	// ??

namespace CGoGN
{

/**
 * class that allows the marking of cells
 * \warning no default constructor
 */
class CellMarker
{
protected:
	Marker m_marker;
51
	AttribMap& m_map;
Sylvain Thery's avatar
Sylvain Thery committed
52
	unsigned int m_thread;
Pierre Kraemer's avatar
Pierre Kraemer committed
53 54 55 56 57 58 59 60

public:
	/**
	 * constructor
	 * @param map the map on which we work (not stored use to get table of markers and new marker.
	 * @param cell the type of cell we want to mark VERTEX_CELL, EDGE_CELL,...
	 * \pre the cell is embedded in the map
	 */
61 62

	CellMarker(AttribMap& map, unsigned int cell): m_map(map), m_thread(0)
Pierre Kraemer's avatar
Pierre Kraemer committed
63
	{
64 65
		if(!map.isOrbitEmbedded(cell))
			map.addEmbedding(cell) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
66 67 68
		m_marker = map.getNewMarker(cell);
	}

69
	CellMarker(AttribMap& map, unsigned int cell, unsigned int thread): m_map(map), m_thread(thread)
Sylvain Thery's avatar
Sylvain Thery committed
70 71 72 73
	{
		m_marker = map.getNewMarker(cell,thread);
	}

Pierre Kraemer's avatar
Pierre Kraemer committed
74 75 76
	virtual ~CellMarker()
	{
		unmarkAll();
Sylvain Thery's avatar
Sylvain Thery committed
77
		m_map.releaseMarker(m_marker,m_thread);
Pierre Kraemer's avatar
Pierre Kraemer committed
78 79 80 81 82 83 84 85 86 87 88 89 90 91
	}

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

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

Sylvain Thery's avatar
Sylvain Thery committed
96
		m_map.getMarkerVector(cell,m_thread)->operator[](a).setMark(m_marker);
Pierre Kraemer's avatar
Pierre Kraemer committed
97 98 99 100 101 102 103 104
	}

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

Sylvain Thery's avatar
Sylvain Thery committed
109
		m_map.getMarkerVector(cell,m_thread)->operator[](a).unsetMark(m_marker);
Pierre Kraemer's avatar
Pierre Kraemer committed
110 111 112 113 114 115 116 117
	}

	/**
	 * 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
118
		unsigned int a = m_map.getEmbedding(cell, d);
Pierre Kraemer's avatar
Pierre Kraemer committed
119 120 121
		if (a == EMBNULL)
			return false;

Sylvain Thery's avatar
Sylvain Thery committed
122
		return m_map.getMarkerVector(cell,m_thread)->operator[](a).testMark(m_marker);
Pierre Kraemer's avatar
Pierre Kraemer committed
123 124 125 126 127 128 129
	}

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

	/**
	 * unmark the cell
	 */
	virtual void unmark(unsigned int em)
	{
Sylvain Thery's avatar
Sylvain Thery committed
138
		m_map.getMarkerVector(m_marker.getCell(),m_thread)->operator[](em).unsetMark(m_marker);
Pierre Kraemer's avatar
Pierre Kraemer committed
139 140 141 142 143 144 145
	}

	/**
	 * test if cell is marked
	 */
	virtual bool isMarked(unsigned int em)
	{
Sylvain Thery's avatar
Sylvain Thery committed
146
		return m_map.getMarkerVector(m_marker.getCell(),m_thread)->operator[](em).testMark(m_marker);
Pierre Kraemer's avatar
Pierre Kraemer committed
147 148 149 150 151
	}

	virtual void markAll()
	{
		unsigned int cell = m_marker.getCell() ;
152
		AttributeContainer& cont = m_map.getAttributeContainer(cell) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
153
		for (unsigned int i = cont.begin(); i != cont.end(); cont.next(i))
154
			m_map.getMarkerVector(cell,m_thread)->operator[](i).setMark(m_marker);
Pierre Kraemer's avatar
Pierre Kraemer committed
155 156 157 158 159
	}

	virtual void unmarkAll()
	{
		unsigned int cell = m_marker.getCell() ;
160
		AttributeContainer& cont = m_map.getAttributeContainer(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
			m_map.getMarkerVector(cell,m_thread)->operator[](i).unsetMark(m_marker);
Pierre Kraemer's avatar
Pierre Kraemer committed
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182
	}
};

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

public:
	/**
	 * constructor
	 * @param map the map on which we work (not stored use to get table of markers and new marker.
	 * @param cell the type of cell we want to mark VERTEX_CELL, EDGE_CELL,...
	 * \pre the cell is embedded in the map
	 */
183
	CellMarkerStore(AttribMap& map, unsigned int cell): CellMarker(map, cell)
Pierre Kraemer's avatar
Pierre Kraemer committed
184 185
	{}

186
	CellMarkerStore(AttribMap& map, unsigned int cell, unsigned int thread): CellMarker(map, cell,thread)
Sylvain Thery's avatar
Sylvain Thery committed
187 188
	{}

Pierre Kraemer's avatar
Pierre Kraemer committed
189 190 191 192 193
protected:
	// protected copy constructor to forbid its usage
	CellMarkerStore(const CellMarkerStore& cm) : CellMarker(cm)
	{}

Sylvain Thery's avatar
Sylvain Thery committed
194

Pierre Kraemer's avatar
Pierre Kraemer committed
195 196 197 198 199 200 201
public:
	/**
	 * mark the cell of dart
	 */
	void mark(Dart d)
	{
		CellMarker::mark(d) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
202
		m_markedCells.push_back(m_map.getEmbedding(m_marker.getCell(), d)) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
203 204 205 206 207 208 209 210 211 212 213 214 215 216 217
	}

	/**
	 * mark the cell
	 */
	void mark(unsigned int em)
	{
		CellMarker::mark(em) ;
		m_markedCells.push_back(em);
	}

	void unmarkAll()
	{
		unsigned int cell = m_marker.getCell() ;
		for (std::vector<unsigned int>::iterator it = m_markedCells.begin(); it != m_markedCells.end(); ++it)
Sylvain Thery's avatar
Sylvain Thery committed
218
			m_map.getMarkerVector(cell,m_thread)->operator[](*it).unsetMark(m_marker);
Pierre Kraemer's avatar
Pierre Kraemer committed
219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235
	}
};

/**
 * class that allows the marking of cells
 * the markers are not unmarked at destruction
 * \warning no default constructor
 */
class CellMarkerNoUnmark: public CellMarker
{
public:
	/**
	 * constructor
	 * @param map the map on which we work (not stored use to get table of markers and new marker.
	 * @param cell the type of cell we want to mark VERTEX_CELL, EDGE_CELL,...
	 * \pre the cell is embedded in the map
	 */
236
	CellMarkerNoUnmark(AttribMap& map, unsigned int cell): CellMarker(map, cell)
Pierre Kraemer's avatar
Pierre Kraemer committed
237 238
	{}

Sylvain Thery's avatar
Sylvain Thery committed
239

240
	CellMarkerNoUnmark(AttribMap& map, unsigned int cell, unsigned int thread): CellMarker(map, cell,thread)
Sylvain Thery's avatar
Sylvain Thery committed
241 242
	{}

Pierre Kraemer's avatar
Pierre Kraemer committed
243 244
	~CellMarkerNoUnmark()
	{
Sylvain Thery's avatar
Sylvain Thery committed
245
		m_map.releaseMarker(m_marker,m_thread);
Pierre Kraemer's avatar
Pierre Kraemer committed
246 247 248 249 250 251 252 253
	}

protected:
	// protected copy constructor to forbid its usage
	CellMarkerNoUnmark(const CellMarkerNoUnmark& cm) : CellMarker(cm)
	{}
};

Sylvain Thery's avatar
Sylvain Thery committed
254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271

/**
 * selector that say if a dart has it cell marked
 */
class SelectorCellMarked: public FunctorSelect
{
protected:
	CellMarker& m_cmarker;
public:
	SelectorCellMarked(CellMarker& cm): m_cmarker(cm) {}
	bool operator()(Dart d) const
	{
		if (m_cmarker.isMarked(d))
			return true;
		return false;
	}
};

272 273 274 275 276 277 278 279 280 281 282 283 284
class SelectorCellUnmarked: public FunctorSelect
{
protected:
	CellMarker& m_cmarker;
public:
	SelectorCellUnmarked(CellMarker& cm): m_cmarker(cm) {}
	bool operator()(Dart d) const
	{
		if (!m_cmarker.isMarked(d))
			return true;
		return false;
	}
};
Sylvain Thery's avatar
Sylvain Thery committed
285 286


Pierre Kraemer's avatar
Pierre Kraemer committed
287 288 289
} // namespace CGoGN

#endif