traversorCell.hpp 4.5 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) ;
}

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