traversorCell.hpp 4.45 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 30
template <typename MAP, unsigned int ORBIT>
TraversorCell<MAP, ORBIT>::TraversorCell(MAP& map, const FunctorSelect& good, bool forceDartMarker, unsigned int thread) :
	m(map), dmark(NULL), cmark(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 79 80 81 82 83
		if(!firstTraversal)
		{
			if(dmark)
				dmark->unmarkAll() ;
			else
				cmark->unmarkAll() ;
		}

		current = m.begin() ;
		while(current != m.end() && (m.isBoundaryMarked(current) || !m_good(current)))
			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 119
				bool ismarked = dmark->isMarked(current) ;
				while(current != NIL && (ismarked || m.isBoundaryMarked(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 133 134 135 136 137 138 139 140 141
				bool ismarked = cmark->isMarked(current) ;
				while(current != NIL && (ismarked || m.isBoundaryMarked(current) || !m_good(current)))
				{
					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) ;
}

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