traversor1.h 4.59 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 29 30 31 32
/*******************************************************************************
* 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 __TRAVERSOR1_H__
#define __TRAVERSOR1_H__

#include "Topology/generic/dart.h"

namespace CGoGN
{

Pierre Kraemer's avatar
Pierre Kraemer committed
33 34 35 36
/*******************************************************************************
					VERTEX CENTERED TRAVERSALS
*******************************************************************************/

Pierre Kraemer's avatar
Pierre Kraemer committed
37 38 39 40 41 42 43 44 45
// Traverse the edges incident to a given vertex
template <typename MAP>
class Traversor1VE
{
private:
	MAP& m ;
	Dart start ;
	Dart current ;

Pierre Kraemer's avatar
Pierre Kraemer committed
46 47
	Dart d2 ;

Pierre Kraemer's avatar
Pierre Kraemer committed
48 49
public:
	Traversor1VE(MAP& map, Dart dart) : m(map), start(dart)
Pierre Kraemer's avatar
Pierre Kraemer committed
50 51 52 53 54
	{
		d2 = m.phi_1(start) ;
		if(d2 == start) // 1 edge loop case
			d2 = NIL ;
	}
Pierre Kraemer's avatar
Pierre Kraemer committed
55 56 57 58 59

	Dart begin() { current = start ; return current ; }
	Dart end() { return NIL ; }
	Dart next()
	{
Pierre Kraemer's avatar
Pierre Kraemer committed
60 61 62 63 64 65 66
		if(current != NIL)
		{
			if(current == start)
				current = d2 ;
			else
				current = NIL ;
		}
Pierre Kraemer's avatar
Pierre Kraemer committed
67 68 69 70 71 72 73 74 75 76 77 78
		return current ;
	}
} ;

// Traverse the vertices adjacent to a given vertex through sharing a common edge
class Traversor1VVaE
{
private:
	MAP& m ;
	Dart start ;
	Dart current ;

Pierre Kraemer's avatar
Pierre Kraemer committed
79 80
	Dart d2 ;

Pierre Kraemer's avatar
Pierre Kraemer committed
81 82 83 84
public:
	Traversor1VVaE(MAP& map, Dart dart) : m(map)
	{
		start = m.phi_1(dart) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
85 86 87 88 89 90 91 92
		if(start == dart) // 1 edge loop case
			start = NIL ;
		else
		{
			d2 = m.phi1(dart) ;
			if(d2 == start) // 2 edges loop case
				d2 = NIL ;
		}
Pierre Kraemer's avatar
Pierre Kraemer committed
93 94 95 96 97 98
	}

	Dart begin() { current = start ; return current ; }
	Dart end() { return NIL ; }
	Dart next()
	{
Pierre Kraemer's avatar
Pierre Kraemer committed
99 100 101 102 103 104 105
		if(current != NIL)
		{
			if(current == start)
				current = d2 ;
			else
				current = NIL ;
		}
Pierre Kraemer's avatar
Pierre Kraemer committed
106 107 108 109
		return current ;
	}
} ;

Pierre Kraemer's avatar
Pierre Kraemer committed
110 111 112 113
/*******************************************************************************
					EDGE CENTERED TRAVERSALS
*******************************************************************************/

Pierre Kraemer's avatar
Pierre Kraemer committed
114 115 116 117 118 119 120 121 122
// Traverse the vertices incident to a given edge
template <typename MAP>
class Traversor1EV
{
private:
	MAP& m ;
	Dart start ;
	Dart current ;

Pierre Kraemer's avatar
Pierre Kraemer committed
123 124
	Dart d2 ;

Pierre Kraemer's avatar
Pierre Kraemer committed
125 126
public:
	Traversor1EV(MAP& map, Dart dart) : m(map), start(dart)
Pierre Kraemer's avatar
Pierre Kraemer committed
127 128 129 130 131
	{
		d2 = m.phi1(start) ;
		if(d2 == start) // 1 edge loop case
			d2 = NIL ;
	}
Pierre Kraemer's avatar
Pierre Kraemer committed
132 133 134 135 136

	Dart begin() { current = start ; return current ; }
	Dart end() { return NIL ; }
	Dart next()
	{
Pierre Kraemer's avatar
Pierre Kraemer committed
137 138 139 140 141 142 143
		if(current != NIL)
		{
			if(current == start)
				current = d2 ;
			else
				current = NIL ;
		}
Pierre Kraemer's avatar
Pierre Kraemer committed
144 145 146 147 148 149 150 151 152 153 154 155
		return current ;
	}
} ;

// Traverse the edges adjacent to a given edge through sharing a common vertex
class Traversor1EEaV
{
private:
	MAP& m ;
	Dart start ;
	Dart current ;

Pierre Kraemer's avatar
Pierre Kraemer committed
156 157
	Dart d2 ;

Pierre Kraemer's avatar
Pierre Kraemer committed
158 159 160 161
public:
	Traversor1EEaV(MAP& map, Dart dart) : m(map)
	{
		start = m.phi_1(dart) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
162 163 164 165 166 167 168 169
		if(start == dart) // 1 edge loop case
			start = NIL ;
		else
		{
			d2 = m.phi1(dart) ;
			if(d2 == start) // 2 edges loop case
				d2 = NIL ;
		}
Pierre Kraemer's avatar
Pierre Kraemer committed
170 171 172 173 174 175
	}

	Dart begin() { current = start ; return current ; }
	Dart end() { return NIL ; }
	Dart next()
	{
Pierre Kraemer's avatar
Pierre Kraemer committed
176 177 178 179 180 181 182
		if(current != NIL)
		{
			if(current == start)
				current = d2 ;
			else
				current = NIL ;
		}
Pierre Kraemer's avatar
Pierre Kraemer committed
183 184 185 186 187 188 189
		return current ;
	}
} ;

} // namespace CGoGN

#endif