traversorCell.h 4.25 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 35 36 37 38 39

namespace CGoGN
{

template <typename MAP, unsigned int ORBIT>
class TraversorCell
{
private:
	MAP& m ;
40 41
	DartMarker* dmark ;
	CellMarker* cmark ;
Pierre Kraemer's avatar
Pierre Kraemer committed
42
	Dart current ;
43
	bool firstTraversal ;
Pierre Kraemer's avatar
Pierre Kraemer committed
44 45

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

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

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

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

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

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

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

Pierre Kraemer's avatar
Pierre Kraemer committed
93 94 95 96
	Dart next()
	{
		if(current != NIL)
		{
97 98 99 100 101 102 103
			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
104 105 106 107
			{
				m.next(current) ;
				if(current == m.end())
					current = NIL ;
108 109 110 111 112 113 114
				else
				{
					if(dmark)
						ismarked = dmark->isMarked(current) ;
					else
						ismarked = cmark->isMarked(current) ;
				}
Pierre Kraemer's avatar
Pierre Kraemer committed
115
			}
116

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

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

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

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

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

} // namespace CGoGN

#endif