traversorCell.h 4.14 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

	Dart begin()
	{
57 58 59 60 61 62 63 64
		if(!firstTraversal)
		{
			if(dmark)
				dmark->unmarkAll() ;
			else
				cmark->unmarkAll() ;
		}

Pierre Kraemer's avatar
Pierre Kraemer committed
65
		current = m.begin() ;
Pierre Kraemer's avatar
Pierre Kraemer committed
66 67
		while(m.isBoundaryMarked(current))
			m.next(current) ;
68

Pierre Kraemer's avatar
Pierre Kraemer committed
69 70 71
		if(current == m.end())
			current = NIL ;
		else
72 73 74 75 76 77 78
		{
			if(dmark)
				dmark->markOrbit(ORBIT, current) ;
			else
				cmark->mark(current) ;
		}

Pierre Kraemer's avatar
Pierre Kraemer committed
79 80
		return current ;
	}
81

Pierre Kraemer's avatar
Pierre Kraemer committed
82
	Dart end() { return NIL ; }
83

Pierre Kraemer's avatar
Pierre Kraemer committed
84 85 86 87
	Dart next()
	{
		if(current != NIL)
		{
88 89 90 91 92 93 94
			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
95 96 97 98
			{
				m.next(current) ;
				if(current == m.end())
					current = NIL ;
99 100 101 102 103 104 105
				else
				{
					if(dmark)
						ismarked = dmark->isMarked(current) ;
					else
						ismarked = cmark->isMarked(current) ;
				}
Pierre Kraemer's avatar
Pierre Kraemer committed
106
			}
107

Pierre Kraemer's avatar
Pierre Kraemer committed
108
			if(current != NIL)
109 110 111 112 113 114
			{
				if(dmark)
					dmark->markOrbit(ORBIT, current) ;
				else
					cmark->mark(current) ;
			}
Pierre Kraemer's avatar
Pierre Kraemer committed
115 116 117 118 119 120 121
		}
		return current ;
	}
} ;

template <typename MAP>
class TraversorV : public TraversorCell<MAP, VERTEX>
Pierre Kraemer's avatar
Pierre Kraemer committed
122 123
{
public:
Pierre Kraemer's avatar
Pierre Kraemer committed
124
	TraversorV(MAP& m, unsigned int thread = 0) : TraversorCell<MAP, VERTEX>(m, thread) {}
Pierre Kraemer's avatar
Pierre Kraemer committed
125
};
Pierre Kraemer's avatar
Pierre Kraemer committed
126 127 128

template <typename MAP>
class TraversorE : public TraversorCell<MAP, EDGE>
Pierre Kraemer's avatar
Pierre Kraemer committed
129 130
{
public:
Pierre Kraemer's avatar
Pierre Kraemer committed
131
	TraversorE(MAP& m, unsigned int thread = 0) : TraversorCell<MAP, EDGE>(m, thread) {}
Pierre Kraemer's avatar
Pierre Kraemer committed
132
};
Pierre Kraemer's avatar
Pierre Kraemer committed
133 134 135

template <typename MAP>
class TraversorF : public TraversorCell<MAP, FACE>
Pierre Kraemer's avatar
Pierre Kraemer committed
136 137
{
public:
Pierre Kraemer's avatar
Pierre Kraemer committed
138
	TraversorF(MAP& m, unsigned int thread = 0) : TraversorCell<MAP, FACE>(m, thread) {}
Pierre Kraemer's avatar
Pierre Kraemer committed
139
};
Pierre Kraemer's avatar
Pierre Kraemer committed
140 141 142

template <typename MAP>
class TraversorW : public TraversorCell<MAP, VOLUME>
Pierre Kraemer's avatar
Pierre Kraemer committed
143 144
{
public:
Pierre Kraemer's avatar
Pierre Kraemer committed
145
	TraversorW(MAP& m, unsigned int thread = 0) : TraversorCell<MAP, VOLUME>(m, thread) {}
Pierre Kraemer's avatar
Pierre Kraemer committed
146
};
Pierre Kraemer's avatar
Pierre Kraemer committed
147 148 149 150

} // namespace CGoGN

#endif