traversorCell.h 4.27 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 46

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

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

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

Pierre Kraemer's avatar
Pierre Kraemer committed
74
		current = m.begin() ;
Pierre Kraemer's avatar
Pierre Kraemer committed
75 76
		while(m.isBoundaryMarked(current))
			m.next(current) ;
77

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

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

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

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

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

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

template <typename MAP>
Sylvain Thery's avatar
Sylvain Thery committed
131
class TraversorV : public TraversorCell<MAP>
Pierre Kraemer's avatar
Pierre Kraemer committed
132 133
{
public:
Sylvain Thery's avatar
Sylvain Thery committed
134
	TraversorV(MAP& m, unsigned int thread = 0) : TraversorCell<MAP>(m, VERTEX, thread)
135
	{}
Pierre Kraemer's avatar
Pierre Kraemer committed
136
};
Pierre Kraemer's avatar
Pierre Kraemer committed
137 138

template <typename MAP>
Sylvain Thery's avatar
Sylvain Thery committed
139
class TraversorE : public TraversorCell<MAP>
Pierre Kraemer's avatar
Pierre Kraemer committed
140 141
{
public:
Sylvain Thery's avatar
Sylvain Thery committed
142
	TraversorE(MAP& m, unsigned int thread = 0) : TraversorCell<MAP>(m, EDGE, thread)
143
	{}
Pierre Kraemer's avatar
Pierre Kraemer committed
144
};
Pierre Kraemer's avatar
Pierre Kraemer committed
145 146

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

template <typename MAP>
Sylvain Thery's avatar
Sylvain Thery committed
155
class TraversorW : public TraversorCell<MAP>
Pierre Kraemer's avatar
Pierre Kraemer committed
156 157
{
public:
Sylvain Thery's avatar
Sylvain Thery committed
158
	TraversorW(MAP& m, unsigned int thread = 0) : TraversorCell<MAP>(m, VOLUME, thread)
159
	{}
Pierre Kraemer's avatar
Pierre Kraemer committed
160
};
Pierre Kraemer's avatar
Pierre Kraemer committed
161 162 163 164

} // namespace CGoGN

#endif