traversorCell.h 3.96 KB
Newer Older
Pierre Kraemer's avatar
Pierre Kraemer committed
1 2 3
/*******************************************************************************
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps  *
* version 0.1                                                                  *
4
* Copyright (C) 2009-2012, IGG Team, LSIIT, University of Strasbourg           *
Pierre Kraemer's avatar
Pierre Kraemer committed
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
*                                                                              *
* 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.           *
*                                                                              *
20
* Web site: http://cgogn.unistra.fr/                                           *
Pierre Kraemer's avatar
Pierre Kraemer committed
21 22 23
* Contact information: cgogn@unistra.fr                                        *
*                                                                              *
*******************************************************************************/
24

Pierre Kraemer's avatar
Pierre Kraemer committed
25 26 27 28
#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"
31
#include "Topology/generic/traversor/traversorGen.h"
Pierre Kraemer's avatar
Pierre Kraemer committed
32

Pierre Kraemer's avatar
Pierre Kraemer committed
33 34
#include <functional>

Pierre Kraemer's avatar
Pierre Kraemer committed
35 36 37
namespace CGoGN
{

38
template <typename MAP, unsigned int ORBIT>
Sylvain Thery's avatar
Sylvain Thery committed
39
class TraversorCell //: public Traversor<MAP>
Pierre Kraemer's avatar
Pierre Kraemer committed
40 41
{
private:
Sylvain Thery's avatar
Sylvain Thery committed
42
	const MAP& m ;
Pierre Kraemer's avatar
Pierre Kraemer committed
43
	unsigned int dimension ;
Pierre Kraemer's avatar
Pierre Kraemer committed
44

Sylvain Thery's avatar
Sylvain Thery committed
45
	const AttributeContainer* cont ;
Pierre Kraemer's avatar
Pierre Kraemer committed
46
	unsigned int qCurrent ;
Pierre Kraemer's avatar
Pierre Kraemer committed
47

48 49
	DartMarker<MAP>* dmark ;
	CellMarker<MAP, ORBIT>* cmark ;
Sylvain Thery's avatar
Sylvain Thery committed
50
	const AttributeMultiVector<Dart>* quickTraversal ;
Pierre Kraemer's avatar
Pierre Kraemer committed
51

Pierre Kraemer's avatar
Pierre Kraemer committed
52
	Dart current ;
53
	bool firstTraversal ;
Pierre Kraemer's avatar
Pierre Kraemer committed
54 55

public:
Sylvain Thery's avatar
Sylvain Thery committed
56
	TraversorCell(const MAP& map, bool forceDartMarker = false, unsigned int thread = 0) ;
57 58 59

	~TraversorCell() ;

60
	inline Dart begin() ;
61

62
	inline Dart end() ;
63

64
	inline Dart next() ;
65

66
	inline void skip(Dart d);
Pierre Kraemer's avatar
Pierre Kraemer committed
67 68 69 70 71 72 73 74 75 76 77 78 79

	inline void apply(std::function<bool (Dart)> f)
	{
		for (Dart d = begin(); d != end(); d = next())
			if (f(d))
				return;
	}

	inline void apply(std::function<void (Dart)> f)
	{
		for (Dart d = begin(); d != end(); d = next())
			f(d);
	}
Pierre Kraemer's avatar
Pierre Kraemer committed
80 81
} ;

82 83


Pierre Kraemer's avatar
Pierre Kraemer committed
84 85 86 87 88 89 90 91 92
template <unsigned int ORBIT, typename MAP, typename FUNC>
inline void foreach_cell(const MAP& map, FUNC f, bool forceDartMarker = false, unsigned int thread = 0)
{
	TraversorCell<MAP, ORBIT> trav(map, forceDartMarker, thread);
	trav.apply(f);
}



Pierre Kraemer's avatar
Pierre Kraemer committed
93
template <typename MAP>
94
class TraversorV : public TraversorCell<MAP, VERTEX>
Pierre Kraemer's avatar
Pierre Kraemer committed
95 96
{
public:
Sylvain Thery's avatar
Sylvain Thery committed
97
	TraversorV(const MAP& m, unsigned int thread = 0) : TraversorCell<MAP, VERTEX>(m, false, thread)
98
	{}
Pierre Kraemer's avatar
Pierre Kraemer committed
99
};
Pierre Kraemer's avatar
Pierre Kraemer committed
100 101

template <typename MAP>
102
class TraversorE : public TraversorCell<MAP, EDGE>
Pierre Kraemer's avatar
Pierre Kraemer committed
103 104
{
public:
Sylvain Thery's avatar
Sylvain Thery committed
105
	TraversorE(const MAP& m, unsigned int thread = 0) : TraversorCell<MAP, EDGE>(m, false, thread)
106
	{}
Pierre Kraemer's avatar
Pierre Kraemer committed
107
};
Pierre Kraemer's avatar
Pierre Kraemer committed
108 109

template <typename MAP>
110
class TraversorF : public TraversorCell<MAP, FACE>
Pierre Kraemer's avatar
Pierre Kraemer committed
111 112
{
public:
Sylvain Thery's avatar
Sylvain Thery committed
113
	TraversorF(const MAP& m, unsigned int thread = 0) : TraversorCell<MAP, FACE>(m, false, thread)
114
	{}
Pierre Kraemer's avatar
Pierre Kraemer committed
115
};
Pierre Kraemer's avatar
Pierre Kraemer committed
116 117

template <typename MAP>
118
class TraversorW : public TraversorCell<MAP, VOLUME>
Pierre Kraemer's avatar
Pierre Kraemer committed
119 120
{
public:
Sylvain Thery's avatar
Sylvain Thery committed
121
	TraversorW(const MAP& m, unsigned int thread = 0) : TraversorCell<MAP, VOLUME>(m, false, thread)
122
	{}
Pierre Kraemer's avatar
Pierre Kraemer committed
123
};
Pierre Kraemer's avatar
Pierre Kraemer committed
124 125 126

} // namespace CGoGN

127
#include "Topology/generic/traversor/traversorCell.hpp"
128

Pierre Kraemer's avatar
Pierre Kraemer committed
129
#endif