traversorCell.hpp 4.94 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
{
Pierre Kraemer's avatar
Pierre Kraemer committed
32 33 34 35 36
	quickTraversal = map.template getQuickTraversal<ORBIT>() ;
	if(quickTraversal != NULL)
	{
		cont = &(m.template getAttributeContainer<ORBIT>()) ;
	}
37
	else
Pierre Kraemer's avatar
Pierre Kraemer committed
38 39 40 41 42 43
	{
		if(!forceDartMarker && map.template isOrbitEmbedded<ORBIT>())
			cmark = new CellMarker<ORBIT>(map, thread) ;
		else
			dmark = new DartMarker(map, thread) ;
	}
44 45
}

46 47
template <typename MAP, unsigned int ORBIT>
TraversorCell<MAP, ORBIT>::~TraversorCell()
48
{
Pierre Kraemer's avatar
Pierre Kraemer committed
49 50 51 52 53 54 55
	if(quickTraversal == NULL)
	{
		if(dmark)
			delete dmark ;
		else
			delete cmark ;
	}
56 57
}

58 59
template <typename MAP, unsigned int ORBIT>
Dart TraversorCell<MAP, ORBIT>::begin()
60
{
Pierre Kraemer's avatar
Pierre Kraemer committed
61
	if(quickTraversal != NULL)
62
	{
Pierre Kraemer's avatar
Pierre Kraemer committed
63 64
		qCurrent = cont->begin() ;
		current = (*quickTraversal)[qCurrent] ;
65 66 67
	}
	else
	{
Pierre Kraemer's avatar
Pierre Kraemer committed
68 69 70 71 72 73 74 75 76 77 78 79 80 81
		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 ;
82
		else
Pierre Kraemer's avatar
Pierre Kraemer committed
83 84 85 86 87 88 89 90
		{
			if(dmark)
				dmark->markOrbit<ORBIT>(current) ;
			else
				cmark->mark(current) ;
		}

		firstTraversal = false ;
91 92 93 94 95
	}

	return current ;
}

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

102 103
template <typename MAP, unsigned int ORBIT>
Dart TraversorCell<MAP, ORBIT>::next()
104 105 106
{
	if(current != NIL)
	{
Pierre Kraemer's avatar
Pierre Kraemer committed
107 108 109 110 111
		if(quickTraversal != NULL)
		{
			cont->next(qCurrent) ;
			current = (*quickTraversal)[qCurrent] ;
		}
112 113
		else
		{
Pierre Kraemer's avatar
Pierre Kraemer committed
114 115 116
			bool ismarked ;
			if(dmark)
				ismarked = dmark->isMarked(current) ;
117
			else
Pierre Kraemer's avatar
Pierre Kraemer committed
118 119 120
				ismarked = cmark->isMarked(current) ;

			while(current != NIL && (ismarked || m.isBoundaryMarked(current) || !m_good(current)))
121
			{
Pierre Kraemer's avatar
Pierre Kraemer committed
122 123 124
				m.next(current) ;
				if(current == m.end())
					current = NIL ;
125
				else
Pierre Kraemer's avatar
Pierre Kraemer committed
126 127 128 129 130 131
				{
					if(dmark)
						ismarked = dmark->isMarked(current) ;
					else
						ismarked = cmark->isMarked(current) ;
				}
132 133
			}

Pierre Kraemer's avatar
Pierre Kraemer committed
134 135 136 137 138 139 140
			if(current != NIL)
			{
				if(dmark)
					dmark->markOrbit<ORBIT>(current) ;
				else
					cmark->mark(current) ;
			}
141 142 143 144 145
		}
	}
	return current ;
}

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


156 157
template <typename MAP, unsigned int ORBIT>
TraversorDartsOfOrbit<MAP, ORBIT>::TraversorDartsOfOrbit(MAP& map, Dart d, unsigned int thread)
158 159
{
	m_vd.reserve(16);
Pierre Kraemer's avatar
Pierre Kraemer committed
160
	FunctorStoreNotBoundary<MAP> fs(map, m_vd);
Pierre Kraemer's avatar
Pierre Kraemer committed
161
	map.template foreach_dart_of_orbit<ORBIT>(d, fs, thread);
162 163 164
	m_vd.push_back(NIL);
}

165 166
template <typename MAP, unsigned int ORBIT>
Dart TraversorDartsOfOrbit<MAP, ORBIT>::begin()
167
{
Pierre Kraemer's avatar
Pierre Kraemer committed
168
	m_current = m_vd.begin();
169 170 171
	return *m_current;
}

172 173
template <typename MAP, unsigned int ORBIT>
Dart TraversorDartsOfOrbit<MAP, ORBIT>::end()
174 175 176
{
	return NIL;
}
177

178 179
template <typename MAP, unsigned int ORBIT>
Dart TraversorDartsOfOrbit<MAP, ORBIT>::next()
180 181 182 183 184 185
{
	if (*m_current != NIL)
		m_current++;
	return *m_current;
}

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