traversorCell.hpp 4.71 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
{
Pierre Kraemer's avatar
Pierre Kraemer committed
32 33
	dimension = map.dimension();

34
	if(forceDartMarker)
35
		dmark = new DartMarker<MAP>(map, thread) ;
36
	else
Pierre Kraemer's avatar
Pierre Kraemer committed
37
	{
38 39 40
		quickTraversal = map.template getQuickTraversal<ORBIT>() ;
		if(quickTraversal != NULL)
		{
Sylvain Thery's avatar
Sylvain Thery committed
41 42
			cont = &(map.template getAttributeContainer<ORBIT>()) ;

43
		}
Pierre Kraemer's avatar
Pierre Kraemer committed
44
		else
45 46
		{
			if(map.template isOrbitEmbedded<ORBIT>())
47
				cmark = new CellMarker<MAP, ORBIT>(map, thread) ;
48
			else
49
				dmark = new DartMarker<MAP>(map, thread) ;
50
		}
Pierre Kraemer's avatar
Pierre Kraemer committed
51
	}
52 53
}

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

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

Pierre Kraemer's avatar
Pierre Kraemer committed
81 82 83
		current.dart = m.begin() ;
		while(current.dart != m.end() && (m.isBoundaryMarked(dimension, current.dart) ))
			m.next(current.dart) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
84

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

		firstTraversal = false ;
96 97 98 99 100
	}

	return current ;
}

101
template <typename MAP, unsigned int ORBIT>
Pierre Kraemer's avatar
Pierre Kraemer committed
102
Cell<ORBIT> TraversorCell<MAP, ORBIT>::end()
Pierre Kraemer's avatar
Pierre Kraemer committed
103
{
Pierre Kraemer's avatar
Pierre Kraemer committed
104
	return Cell<ORBIT>(NIL) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
105
}
106

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

155
template <typename MAP, unsigned int ORBIT>
Pierre Kraemer's avatar
Pierre Kraemer committed
156
void TraversorCell<MAP, ORBIT>::skip(Cell<ORBIT> c)
157 158
{
	if(dmark)
Pierre Kraemer's avatar
Pierre Kraemer committed
159
		dmark->template markOrbit<ORBIT>(c.dart) ;
160
	else
Pierre Kraemer's avatar
Pierre Kraemer committed
161
		cmark->mark(c) ;
162 163
}

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