traversorCell.hpp 7.12 KB
Newer Older
1 2 3
/*******************************************************************************
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps  *
* version 0.1                                                                  *
4
* Copyright (C) 2009-2012, IGG Team, LSIIT, University of Strasbourg           *
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.unistra.fr/                                           *
21 22 23 24 25 26 27
* Contact information: cgogn@unistra.fr                                        *
*                                                                              *
*******************************************************************************/

namespace CGoGN
{

28
template <typename MAP, unsigned int ORBIT>
Sylvain Thery's avatar
Sylvain Thery committed
29
TraversorCell<MAP, ORBIT>::TraversorCell(const MAP& map, bool forceDartMarker, unsigned int thread) :
30
	m(map), dmark(NULL), cmark(NULL), quickTraversal(NULL), current(NIL), firstTraversal(true)
31
{
32 33
	if(forceDartMarker)
		dmark = new DartMarker(map, thread) ;
34
	else
Pierre Kraemer's avatar
Pierre Kraemer committed
35
	{
36 37 38
		quickTraversal = map.template getQuickTraversal<ORBIT>() ;
		if(quickTraversal != NULL)
		{
Sylvain Thery's avatar
Sylvain Thery committed
39 40
			cont = &(map.template getAttributeContainer<ORBIT>()) ;

41
		}
Pierre Kraemer's avatar
Pierre Kraemer committed
42
		else
43 44 45 46 47 48
		{
			if(map.template isOrbitEmbedded<ORBIT>())
				cmark = new CellMarker<ORBIT>(map, thread) ;
			else
				dmark = new DartMarker(map, thread) ;
		}
Pierre Kraemer's avatar
Pierre Kraemer committed
49
	}
50 51
}

52 53
template <typename MAP, unsigned int ORBIT>
TraversorCell<MAP, ORBIT>::~TraversorCell()
54
{
55 56 57 58
	if(dmark)
		delete dmark ;
	else if(cmark)
		delete cmark ;
59 60
}

61 62
template <typename MAP, unsigned int ORBIT>
Dart TraversorCell<MAP, ORBIT>::begin()
63
{
Pierre Kraemer's avatar
Pierre Kraemer committed
64
	if(quickTraversal != NULL)
65
	{
Pierre Kraemer's avatar
Pierre Kraemer committed
66 67
		qCurrent = cont->begin() ;
		current = (*quickTraversal)[qCurrent] ;
68 69 70
	}
	else
	{
Pierre Kraemer's avatar
Pierre Kraemer committed
71 72 73 74 75 76 77 78 79
		if(!firstTraversal)
		{
			if(dmark)
				dmark->unmarkAll() ;
			else
				cmark->unmarkAll() ;
		}

		current = m.begin() ;
80
		while(current != m.end() && (m.template isBoundaryMarked<MAP::DIMENSION>(current) ))
Pierre Kraemer's avatar
Pierre Kraemer committed
81 82 83 84
			m.next(current) ;

		if(current == m.end())
			current = NIL ;
85
		else
Pierre Kraemer's avatar
Pierre Kraemer committed
86 87 88 89 90 91 92 93
		{
			if(dmark)
				dmark->markOrbit<ORBIT>(current) ;
			else
				cmark->mark(current) ;
		}

		firstTraversal = false ;
94 95 96 97 98
	}

	return current ;
}

99 100
template <typename MAP, unsigned int ORBIT>
Dart TraversorCell<MAP, ORBIT>::end()
Pierre Kraemer's avatar
Pierre Kraemer committed
101 102 103
{
	return NIL ;
}
104

105 106
template <typename MAP, unsigned int ORBIT>
Dart TraversorCell<MAP, ORBIT>::next()
107
{
108 109 110 111
	assert(current != NIL);
//	if(current != NIL)
//	{
	if(quickTraversal != NULL)
112
	{
113 114
		cont->next(qCurrent) ;
		if (qCurrent != cont->end())
Pierre Kraemer's avatar
Pierre Kraemer committed
115
			current = (*quickTraversal)[qCurrent] ;
116 117 118 119 120
		else current = NIL;
	}
	else
	{
		if(dmark)
121
		{
122 123
			bool ismarked = dmark->isMarked(current) ;
			while(current != NIL && (ismarked || m.template isBoundaryMarked<MAP::DIMENSION>(current)))
124
			{
125 126 127 128 129
				m.next(current) ;
				if(current == m.end())
					current = NIL ;
				else
					ismarked = dmark->isMarked(current) ;
130
			}
131 132 133 134 135 136 137
			if(current != NIL)
				dmark->markOrbit<ORBIT>(current) ;
		}
		else
		{
			bool ismarked = cmark->isMarked(current) ;
			while(current != NIL && (ismarked || m.template isBoundaryMarked<MAP::DIMENSION>(current) ))
Pierre Kraemer's avatar
Pierre Kraemer committed
138
			{
139 140 141 142 143
				m.next(current) ;
				if(current == m.end())
					current = NIL ;
				else
					ismarked = cmark->isMarked(current) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
144
			}
145 146
			if(current != NIL)
				cmark->mark(current) ;
147 148
		}
	}
149
//	}
150 151 152
	return current ;
}

153 154
template <typename MAP, unsigned int ORBIT>
void TraversorCell<MAP, ORBIT>::skip(Dart d)
155 156
{
	if(dmark)
157
		dmark->markOrbit<ORBIT>(d) ;
158 159 160 161
	else
		cmark->mark(d) ;
}

162 163 164 165


//special version (partial specialization) for Genric Map
template <unsigned int ORBIT>
Sylvain Thery's avatar
Sylvain Thery committed
166
TraversorCell<GenericMap, ORBIT>::TraversorCell(const GenericMap& map, bool forceDartMarker, unsigned int thread) :
167
	m(map), dmark(NULL), cmark(NULL), quickTraversal(NULL), current(NIL), firstTraversal(true)
168 169 170 171 172 173 174 175
{
	if(forceDartMarker)
		dmark = new DartMarker(map, thread) ;
	else
	{
		quickTraversal = map.template getQuickTraversal<ORBIT>() ;
		if(quickTraversal != NULL)
		{
Sylvain Thery's avatar
Sylvain Thery committed
176
			cont = &(map.template getAttributeContainer<ORBIT>()) ;
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215
		}
		else
		{
			if(map.template isOrbitEmbedded<ORBIT>())
				cmark = new CellMarker<ORBIT>(map, thread) ;
			else
				dmark = new DartMarker(map, thread) ;
		}
	}
}

template <unsigned int ORBIT>
TraversorCell<GenericMap, ORBIT>::~TraversorCell()
{
	if(dmark)
		delete dmark ;
	else if(cmark)
		delete cmark ;
}

template <unsigned int ORBIT>
Dart TraversorCell<GenericMap, ORBIT>::begin()
{
	if(quickTraversal != NULL)
	{
		qCurrent = cont->begin() ;
		current = (*quickTraversal)[qCurrent] ;
	}
	else
	{
		if(!firstTraversal)
		{
			if(dmark)
				dmark->unmarkAll() ;
			else
				cmark->unmarkAll() ;
		}

		current = m.begin() ;
216
		while(current != m.end() && (m.isBoundaryMarkedCurrent(current) ))
217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243
			m.next(current) ;

		if(current == m.end())
			current = NIL ;
		else
		{
			if(dmark)
				dmark->markOrbit<ORBIT>(current) ;
			else
				cmark->mark(current) ;
		}

		firstTraversal = false ;
	}

	return current ;
}

template <unsigned int ORBIT>
Dart TraversorCell<GenericMap, ORBIT>::end()
{
	return NIL ;
}

template <unsigned int ORBIT>
Dart TraversorCell<GenericMap, ORBIT>::next()
{
244 245 246 247
	assert(current != NIL);
//	if(current != NIL)
//	{
	if(quickTraversal != NULL)
248
	{
249 250
		cont->next(qCurrent) ;
		if (qCurrent != cont->end())
251
			current = (*quickTraversal)[qCurrent] ;
252 253 254 255 256
		else current = NIL;
	}
	else
	{
		if(dmark)
257
		{
258 259
			bool ismarked = dmark->isMarked(current) ;
			while(current != NIL && (ismarked || m.isBoundaryMarkedCurrent(current) ))
260
			{
261 262 263 264 265
				m.next(current) ;
				if(current == m.end())
					current = NIL ;
				else
					ismarked = dmark->isMarked(current) ;
266
			}
267 268 269 270 271 272 273
			if(current != NIL)
				dmark->markOrbit<ORBIT>(current) ;
		}
		else
		{
			bool ismarked = cmark->isMarked(current) ;
			while(current != NIL && (ismarked || m.isBoundaryMarkedCurrent(current) ))
274
			{
275 276 277 278 279
				m.next(current) ;
				if(current == m.end())
					current = NIL ;
				else
					ismarked = cmark->isMarked(current) ;
280
			}
281 282
			if(current != NIL)
				cmark->mark(current) ;
283 284
		}
	}
285
//	}
286 287 288 289 290 291 292 293 294 295 296 297 298 299 300
	return current ;
}

template <unsigned int ORBIT>
void TraversorCell<GenericMap, ORBIT>::skip(Dart d)
{
	if(dmark)
		dmark->markOrbit<ORBIT>(d) ;
	else
		cmark->mark(d) ;
}




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