traversorCell.h 4.95 KB
Newer Older
Pierre Kraemer's avatar
Pierre Kraemer committed
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
/*******************************************************************************
* 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                                        *
*                                                                              *
*******************************************************************************/

#ifndef __TRAVERSOR_CELL_H__
#define __TRAVERSOR_CELL_H__

#include "Topology/generic/dart.h"
29
#include "Topology/generic/dartmarker.h"
30
#include "Topology/generic/cellmarker.h"
Pierre Kraemer's avatar
Pierre Kraemer committed
31 32 33 34

namespace CGoGN
{

Sylvain Thery's avatar
Sylvain Thery committed
35
template <typename MAP>
Pierre Kraemer's avatar
Pierre Kraemer committed
36 37 38 39
class TraversorCell
{
private:
	MAP& m ;
40
	unsigned int m_orbit ;
41 42
	DartMarker* dmark ;
	CellMarker* cmark ;
Pierre Kraemer's avatar
Pierre Kraemer committed
43
	Dart current ;
44
	bool firstTraversal ;
Pierre Kraemer's avatar
Pierre Kraemer committed
45
	const FunctorSelect& m_good ;
Pierre Kraemer's avatar
Pierre Kraemer committed
46 47

public:
48
	TraversorCell(MAP& map, unsigned int orbit, const FunctorSelect& good = allDarts, bool forceDartMarker = false, unsigned int thread = 0) :
Pierre Kraemer's avatar
Pierre Kraemer committed
49
		m(map), m_orbit(orbit), dmark(NULL), cmark(NULL), current(NIL), firstTraversal(true), m_good(good)
50
	{
51
		if(!forceDartMarker && map.isOrbitEmbedded(m_orbit))
Sylvain Thery's avatar
Sylvain Thery committed
52
			cmark = new CellMarker(map, m_orbit, thread) ;
53 54 55
		else
			dmark = new DartMarker(map, thread) ;
	}
Pierre Kraemer's avatar
Pierre Kraemer committed
56

57 58 59 60 61 62 63 64
	~TraversorCell()
	{
		if(dmark)
			delete dmark ;
		else
			delete cmark ;
	}

Pierre Kraemer's avatar
Pierre Kraemer committed
65 66
	Dart begin()
	{
67 68 69 70 71 72 73 74
		if(!firstTraversal)
		{
			if(dmark)
				dmark->unmarkAll() ;
			else
				cmark->unmarkAll() ;
		}

Pierre Kraemer's avatar
Pierre Kraemer committed
75
		current = m.begin() ;
76
		while(current != m.end() && (m.isBoundaryMarked(current) || !m_good(current)))
Pierre Kraemer's avatar
Pierre Kraemer committed
77
			m.next(current) ;
78

Pierre Kraemer's avatar
Pierre Kraemer committed
79 80 81
		if(current == m.end())
			current = NIL ;
		else
82 83
		{
			if(dmark)
Sylvain Thery's avatar
Sylvain Thery committed
84
				dmark->markOrbit(m_orbit, current) ;
85 86 87 88
			else
				cmark->mark(current) ;
		}

89
		firstTraversal = false ;
Pierre Kraemer's avatar
Pierre Kraemer committed
90 91
		return current ;
	}
92

Pierre Kraemer's avatar
Pierre Kraemer committed
93
	Dart end() { return NIL ; }
94

Pierre Kraemer's avatar
Pierre Kraemer committed
95 96 97 98
	Dart next()
	{
		if(current != NIL)
		{
99 100 101 102 103 104
			bool ismarked ;
			if(dmark)
				ismarked = dmark->isMarked(current) ;
			else
				ismarked = cmark->isMarked(current) ;

Pierre Kraemer's avatar
Pierre Kraemer committed
105
			while(current != NIL && (ismarked || m.isBoundaryMarked(current) || !m_good(current)))
Pierre Kraemer's avatar
Pierre Kraemer committed
106 107 108 109
			{
				m.next(current) ;
				if(current == m.end())
					current = NIL ;
110 111 112 113 114 115 116
				else
				{
					if(dmark)
						ismarked = dmark->isMarked(current) ;
					else
						ismarked = cmark->isMarked(current) ;
				}
Pierre Kraemer's avatar
Pierre Kraemer committed
117
			}
118

Pierre Kraemer's avatar
Pierre Kraemer committed
119
			if(current != NIL)
120 121
			{
				if(dmark)
Sylvain Thery's avatar
Sylvain Thery committed
122
					dmark->markOrbit(m_orbit, current) ;
123 124 125
				else
					cmark->mark(current) ;
			}
Pierre Kraemer's avatar
Pierre Kraemer committed
126 127 128
		}
		return current ;
	}
129 130 131 132 133 134 135 136

	void mark(Dart d)
	{
		if(dmark)
			dmark->markOrbit(m_orbit, d) ;
		else
			cmark->mark(d) ;
	}
Pierre Kraemer's avatar
Pierre Kraemer committed
137 138 139
} ;

template <typename MAP>
Sylvain Thery's avatar
Sylvain Thery committed
140
class TraversorV : public TraversorCell<MAP>
Pierre Kraemer's avatar
Pierre Kraemer committed
141 142
{
public:
Pierre Kraemer's avatar
Pierre Kraemer committed
143
	TraversorV(MAP& m, const FunctorSelect& good = allDarts, unsigned int thread = 0) : TraversorCell<MAP>(m, VERTEX, good, thread)
144
	{}
Pierre Kraemer's avatar
Pierre Kraemer committed
145
};
Pierre Kraemer's avatar
Pierre Kraemer committed
146 147

template <typename MAP>
Sylvain Thery's avatar
Sylvain Thery committed
148
class TraversorE : public TraversorCell<MAP>
Pierre Kraemer's avatar
Pierre Kraemer committed
149 150
{
public:
Pierre Kraemer's avatar
Pierre Kraemer committed
151
	TraversorE(MAP& m, const FunctorSelect& good = allDarts, unsigned int thread = 0) : TraversorCell<MAP>(m, EDGE, good, thread)
152
	{}
Pierre Kraemer's avatar
Pierre Kraemer committed
153
};
Pierre Kraemer's avatar
Pierre Kraemer committed
154

untereiner's avatar
untereiner committed
155 156 157 158 159 160 161 162
template <typename MAP>
class TraversorOF : public TraversorCell<MAP>
{
public:
	TraversorOF(MAP& m, const FunctorSelect& good = allDarts, unsigned int thread = 0) : TraversorCell<MAP>(m, ORIENTED_FACE, good, thread)
	{}
};

Pierre Kraemer's avatar
Pierre Kraemer committed
163
template <typename MAP>
Sylvain Thery's avatar
Sylvain Thery committed
164
class TraversorF : public TraversorCell<MAP>
Pierre Kraemer's avatar
Pierre Kraemer committed
165 166
{
public:
Pierre Kraemer's avatar
Pierre Kraemer committed
167
	TraversorF(MAP& m, const FunctorSelect& good = allDarts, unsigned int thread = 0) : TraversorCell<MAP>(m, FACE, good, thread)
168
	{}
Pierre Kraemer's avatar
Pierre Kraemer committed
169
};
Pierre Kraemer's avatar
Pierre Kraemer committed
170 171

template <typename MAP>
Sylvain Thery's avatar
Sylvain Thery committed
172
class TraversorW : public TraversorCell<MAP>
Pierre Kraemer's avatar
Pierre Kraemer committed
173 174
{
public:
Pierre Kraemer's avatar
Pierre Kraemer committed
175
	TraversorW(MAP& m, const FunctorSelect& good = allDarts, unsigned int thread = 0) : TraversorCell<MAP>(m, VOLUME, good, thread)
176
	{}
Pierre Kraemer's avatar
Pierre Kraemer committed
177
};
Pierre Kraemer's avatar
Pierre Kraemer committed
178 179 180 181

} // namespace CGoGN

#endif