traversorCell.hpp 4.24 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
/*******************************************************************************
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps  *
* version 0.1                                                                  *
* Copyright (C) 2009-2011, IGG Team, LSIIT, University of Strasbourg           *
*                                                                              *
* 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.           *
*                                                                              *
* Web site: http://cgogn.u-strasbg.fr/                                         *
* Contact information: cgogn@unistra.fr                                        *
*                                                                              *
*******************************************************************************/

namespace CGoGN
{

template <typename MAP>
TraversorCell<MAP>::TraversorCell(MAP& map, unsigned int orbit, const FunctorSelect& good, bool forceDartMarker, unsigned int thread) :
Pierre Kraemer's avatar
Pierre Kraemer committed
30
	m(map), m_orbit(orbit), dmark(NULL), cmark(NULL), current(NIL), firstTraversal(true), m_good(good)
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
{
	if(!forceDartMarker && map.isOrbitEmbedded(m_orbit))
		cmark = new CellMarker(map, m_orbit, thread) ;
	else
		dmark = new DartMarker(map, thread) ;
}

template <typename MAP>
TraversorCell<MAP>::~TraversorCell()
{
	if(dmark)
		delete dmark ;
	else
		delete cmark ;
}

template <typename MAP>
Dart TraversorCell<MAP>::begin()
{
	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 ;
	else
	{
		if(dmark)
			dmark->markOrbit(m_orbit, current) ;
		else
			cmark->mark(current) ;
	}

	firstTraversal = false ;
	return current ;
}

template <typename MAP>
Pierre Kraemer's avatar
Pierre Kraemer committed
77 78 79 80
Dart TraversorCell<MAP>::end()
{
	return NIL ;
}
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131

template <typename MAP>
Dart TraversorCell<MAP>::next()
{
	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)))
		{
			m.next(current) ;
			if(current == m.end())
				current = NIL ;
			else
			{
				if(dmark)
					ismarked = dmark->isMarked(current) ;
				else
					ismarked = cmark->isMarked(current) ;
			}
		}

		if(current != NIL)
		{
			if(dmark)
				dmark->markOrbit(m_orbit, current) ;
			else
				cmark->mark(current) ;
		}
	}
	return current ;
}

template <typename MAP>
void TraversorCell<MAP>::mark(Dart d)
{
	if(dmark)
		dmark->markOrbit(m_orbit, d) ;
	else
		cmark->mark(d) ;
}


template <typename MAP>
TraversorDartsOfOrbit<MAP>::TraversorDartsOfOrbit(MAP& map, unsigned int orbit, Dart d, unsigned int thread)
{
	m_vd.reserve(16);
Pierre Kraemer's avatar
Pierre Kraemer committed
132
	FunctorStoreNotBoundary<MAP> fs(map, m_vd);
133 134 135 136 137 138 139
	map.foreach_dart_of_orbit(orbit, d, fs, thread);
	m_vd.push_back(NIL);
}

template <typename MAP>
Dart TraversorDartsOfOrbit<MAP>::begin()
{
Pierre Kraemer's avatar
Pierre Kraemer committed
140
	m_current = m_vd.begin();
141 142 143 144
	return *m_current;
}

template <typename MAP>
145 146 147 148
Dart TraversorDartsOfOrbit<MAP>::end()
{
	return NIL;
}
149 150 151 152 153 154 155 156 157

template <typename MAP>
Dart TraversorDartsOfOrbit<MAP>::next()
{
	if (*m_current != NIL)
		m_current++;
	return *m_current;
}

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