traversorCell.hpp 4.77 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
		current = (*quickTraversal)[cont->begin()] ;
64 65 66
	}
	else
	{
Pierre Kraemer's avatar
Pierre Kraemer committed
67 68 69 70 71 72 73 74 75 76 77 78 79 80
		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 ;
81
		else
Pierre Kraemer's avatar
Pierre Kraemer committed
82 83 84 85 86 87 88 89
		{
			if(dmark)
				dmark->markOrbit<ORBIT>(current) ;
			else
				cmark->mark(current) ;
		}

		firstTraversal = false ;
90 91 92 93 94
	}

	return current ;
}

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

101 102
template <typename MAP, unsigned int ORBIT>
Dart TraversorCell<MAP, ORBIT>::next()
103 104 105 106 107 108 109 110 111 112 113
{
	if(current != NIL)
	{
		bool ismarked ;
		if(dmark)
			ismarked = dmark->isMarked(current) ;
		else
			ismarked = cmark->isMarked(current) ;

		while(current != NIL && (ismarked || m.isBoundaryMarked(current) || !m_good(current)))
		{
114
			m.next(current) ;
115 116 117 118 119 120 121 122 123 124 125 126 127 128
			if(current == m.end())
				current = NIL ;
			else
			{
				if(dmark)
					ismarked = dmark->isMarked(current) ;
				else
					ismarked = cmark->isMarked(current) ;
			}
		}

		if(current != NIL)
		{
			if(dmark)
129
				dmark->markOrbit<ORBIT>(current) ;
130 131 132 133 134 135 136
			else
				cmark->mark(current) ;
		}
	}
	return current ;
}

137 138
template <typename MAP, unsigned int ORBIT>
void TraversorCell<MAP, ORBIT>::skip(Dart d)
139 140
{
	if(dmark)
141
		dmark->markOrbit<ORBIT>(d) ;
142 143 144 145 146
	else
		cmark->mark(d) ;
}


147 148
template <typename MAP, unsigned int ORBIT>
TraversorDartsOfOrbit<MAP, ORBIT>::TraversorDartsOfOrbit(MAP& map, Dart d, unsigned int thread)
149 150
{
	m_vd.reserve(16);
Pierre Kraemer's avatar
Pierre Kraemer committed
151
	FunctorStoreNotBoundary<MAP> fs(map, m_vd);
Pierre Kraemer's avatar
Pierre Kraemer committed
152
	map.template foreach_dart_of_orbit<ORBIT>(d, fs, thread);
153 154 155
	m_vd.push_back(NIL);
}

156 157
template <typename MAP, unsigned int ORBIT>
Dart TraversorDartsOfOrbit<MAP, ORBIT>::begin()
158
{
Pierre Kraemer's avatar
Pierre Kraemer committed
159
	m_current = m_vd.begin();
160 161 162
	return *m_current;
}

163 164
template <typename MAP, unsigned int ORBIT>
Dart TraversorDartsOfOrbit<MAP, ORBIT>::end()
165 166 167
{
	return NIL;
}
168

169 170
template <typename MAP, unsigned int ORBIT>
Dart TraversorDartsOfOrbit<MAP, ORBIT>::next()
171 172 173 174 175 176
{
	if (*m_current != NIL)
		m_current++;
	return *m_current;
}

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