traversorCell.hpp 7.2 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 29
template <typename MAP, unsigned int ORBIT>
TraversorCell<MAP, ORBIT>::TraversorCell(MAP& map, const FunctorSelect& good, bool forceDartMarker, unsigned int thread) :
30
	m(map), dmark(NULL), cmark(NULL), quickTraversal(NULL), current(NIL), firstTraversal(true), m_good(good)
31
{
32 33
	if(forceDartMarker)
		dmark = new DartMarker(map, thread) ;
34
	else
Pierre Kraemer's avatar
Pierre Kraemer committed
35
	{
36 37 38 39 40
		quickTraversal = map.template getQuickTraversal<ORBIT>() ;
		if(quickTraversal != NULL)
		{
			cont = &(m.template getAttributeContainer<ORBIT>()) ;
		}
Pierre Kraemer's avatar
Pierre Kraemer committed
41
		else
42 43 44 45 46 47
		{
			if(map.template isOrbitEmbedded<ORBIT>())
				cmark = new CellMarker<ORBIT>(map, thread) ;
			else
				dmark = new DartMarker(map, thread) ;
		}
Pierre Kraemer's avatar
Pierre Kraemer committed
48
	}
49 50
}

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

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

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

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

		firstTraversal = false ;
93 94 95 96 97
	}

	return current ;
}

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

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

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

158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 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 216 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 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293


//special version (partial specialization) for Genric Map
template <unsigned int ORBIT>
TraversorCell<GenericMap, ORBIT>::TraversorCell(GenericMap& map, const FunctorSelect& good, bool forceDartMarker, unsigned int thread) :
	m(map), dmark(NULL), cmark(NULL), quickTraversal(NULL), current(NIL), firstTraversal(true), m_good(good)
{
	if(forceDartMarker)
		dmark = new DartMarker(map, thread) ;
	else
	{
		quickTraversal = map.template getQuickTraversal<ORBIT>() ;
		if(quickTraversal != NULL)
		{
			cont = &(m.template getAttributeContainer<ORBIT>()) ;
		}
		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() ;
		while(current != m.end() && (m.isBoundaryMarkedCurrent(current) || !m_good(current)))
			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()
{
	if(current != NIL)
	{
		if(quickTraversal != NULL)
		{
			cont->next(qCurrent) ;
			current = (*quickTraversal)[qCurrent] ;
		}
		else
		{
			if(dmark)
			{
				bool ismarked = dmark->isMarked(current) ;
				while(current != NIL && (ismarked || m.isBoundaryMarkedCurrent(current) || !m_good(current)))
				{
					m.next(current) ;
					if(current == m.end())
						current = NIL ;
					else
						ismarked = dmark->isMarked(current) ;
				}
				if(current != NIL)
					dmark->markOrbit<ORBIT>(current) ;
			}
			else
			{
				bool ismarked = cmark->isMarked(current) ;
				while(current != NIL && (ismarked || m.isBoundaryMarkedCurrent(current) || !m_good(current)))
				{
					m.next(current) ;
					if(current == m.end())
						current = NIL ;
					else
						ismarked = cmark->isMarked(current) ;
				}
				if(current != NIL)
					cmark->mark(current) ;
			}
		}
	}
	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
294
} // namespace CGoGN