traversorCell.h 5.63 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"
Pierre Kraemer's avatar
Pierre Kraemer committed
29
#include "Topology/generic/cells.h"
30
#include "Topology/generic/dartmarker.h"
31
#include "Topology/generic/cellmarker.h"
32
#include "Topology/generic/traversor/traversorGen.h"
Pierre Kraemer's avatar
Pierre Kraemer committed
33

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

Pierre Kraemer's avatar
Pierre Kraemer committed
36 37
namespace CGoGN
{
38 39 40 41 42 43 44 45 46
/**
 * Travsersor class
 * template params:
 *  - MAP type of map
 *  - ORBIT orbit of the cell
 *  - OPT type of optimization
 */

enum TraversalOptim {AUTO=0, FORCE_DART_MARKING, FORCE_CELL_MARKING, FORCE_QUICK_TRAVERSAL};
Pierre Kraemer's avatar
Pierre Kraemer committed
47

48
template <typename MAP, unsigned int ORBIT, TraversalOptim OPT = AUTO>
49
class TraversorCell
Pierre Kraemer's avatar
Pierre Kraemer committed
50
{
Sylvain Thery's avatar
Sylvain Thery committed
51
protected:
Sylvain Thery's avatar
Sylvain Thery committed
52
	const MAP& m ;
Pierre Kraemer's avatar
Pierre Kraemer committed
53
	unsigned int dimension ;
Pierre Kraemer's avatar
Pierre Kraemer committed
54

Sylvain Thery's avatar
Sylvain Thery committed
55
	const AttributeContainer* cont ;
Pierre Kraemer's avatar
Pierre Kraemer committed
56
	unsigned int qCurrent ;
Pierre Kraemer's avatar
Pierre Kraemer committed
57

58 59
	DartMarker<MAP>* dmark ;
	CellMarker<MAP, ORBIT>* cmark ;
Sylvain Thery's avatar
Sylvain Thery committed
60
	const AttributeMultiVector<Dart>* quickTraversal ;
Pierre Kraemer's avatar
Pierre Kraemer committed
61

Pierre Kraemer's avatar
Pierre Kraemer committed
62
	Cell<ORBIT> current ;
63
	bool firstTraversal ;
Pierre Kraemer's avatar
Pierre Kraemer committed
64

Sylvain Thery's avatar
Sylvain Thery committed
65
	// just for odd/even versions
66
	TraversorCell(const TraversorCell<MAP, ORBIT, OPT>& tc);
Sylvain Thery's avatar
Sylvain Thery committed
67

Pierre Kraemer's avatar
Pierre Kraemer committed
68
public:
Sylvain Thery's avatar
Sylvain Thery committed
69
	TraversorCell(const MAP& map, bool forceDartMarker = false, unsigned int thread = 0) ;
70 71 72

	~TraversorCell() ;

Pierre Kraemer's avatar
Pierre Kraemer committed
73
	inline Cell<ORBIT> begin() ;
74

Pierre Kraemer's avatar
Pierre Kraemer committed
75
	inline Cell<ORBIT> end() ;
76

Pierre Kraemer's avatar
Pierre Kraemer committed
77
	inline Cell<ORBIT> next() ;
78

Pierre Kraemer's avatar
Pierre Kraemer committed
79
	inline void skip(Cell<ORBIT> c);
Sylvain Thery's avatar
Sylvain Thery committed
80 81 82 83 84 85 86

	inline unsigned int nbCells();
} ;




87 88
template <typename MAP, unsigned int ORBIT, TraversalOptim OPT = AUTO>
class TraversorCellEven : public TraversorCell<MAP, ORBIT, OPT>
Sylvain Thery's avatar
Sylvain Thery committed
89 90
{
public:
91 92 93
	TraversorCellEven(const TraversorCell<MAP,ORBIT, OPT>& tra):
		TraversorCell<MAP, ORBIT, OPT>(tra) {}
	~TraversorCellEven() { this->cmark = NULL; this->dmark = NULL; }
Sylvain Thery's avatar
Sylvain Thery committed
94 95 96 97
	inline Cell<ORBIT> begin() ;
} ;


98 99
template <typename MAP, unsigned int ORBIT, TraversalOptim OPT = AUTO>
class TraversorCellOdd : public TraversorCell<MAP, ORBIT, OPT>
Sylvain Thery's avatar
Sylvain Thery committed
100 101
{
public:
102 103 104
	TraversorCellOdd(const TraversorCell<MAP, ORBIT, OPT>& tra):
		TraversorCell<MAP, ORBIT, OPT>(tra) {}
	~TraversorCellOdd() {this->cmark = NULL; this->dmark = NULL; }
Sylvain Thery's avatar
Sylvain Thery committed
105 106
	inline Cell<ORBIT> begin() ;
	inline Cell<ORBIT> next() ;
Pierre Kraemer's avatar
Pierre Kraemer committed
107 108
} ;

109 110


Sylvain Thery's avatar
Sylvain Thery committed
111 112 113



114 115 116
/*
 * Executes function f on each ORBIT
 */
Pierre Kraemer's avatar
Pierre Kraemer committed
117
template <unsigned int ORBIT, typename MAP, typename FUNC>
Sylvain Thery's avatar
Sylvain Thery committed
118 119
inline void foreach_cell(const MAP& map, FUNC f, TraversalOptim opt = AUTO, unsigned int thread = 0);

Pierre Kraemer's avatar
Pierre Kraemer committed
120

121 122 123
/*
 * Executes function f on each ORBIT until f returns false
 */
Pierre Kraemer's avatar
Pierre Kraemer committed
124
template <unsigned int ORBIT, typename MAP, typename FUNC>
Sylvain Thery's avatar
Sylvain Thery committed
125
inline void foreach_cell_until(const MAP& map, FUNC f, TraversalOptim opt = AUTO, unsigned int thread = 0);
126

Sylvain Thery's avatar
Sylvain Thery committed
127

Sylvain Thery's avatar
Sylvain Thery committed
128 129
namespace Parallel
{
130

Sylvain Thery's avatar
Sylvain Thery committed
131 132 133 134 135 136 137 138
/**
 * @brief foreach_cell
 * @param map
 * @param func function to apply on cells
 * @param needMarkers func need markers ?
 * @param opt optimization param of traversal
 * @param nbth number of used thread (0:for traversal, [1,nbth-1] for func computing
*/
Sylvain Thery's avatar
Sylvain Thery committed
139
template <unsigned int ORBIT, typename MAP, typename FUNC>
Sylvain Thery's avatar
Sylvain Thery committed
140
void foreach_cell(MAP& map, FUNC func, TraversalOptim opt = AUTO, unsigned int nbth = NumberOfThreads);
141 142 143 144

} // namespace Parallel


Sylvain Thery's avatar
Sylvain Thery committed
145

146

Sylvain Thery's avatar
Sylvain Thery committed
147

148 149
template <typename MAP, TraversalOptim OPT = AUTO>
class TraversorV : public TraversorCell<MAP, VERTEX, OPT>
Pierre Kraemer's avatar
Pierre Kraemer committed
150 151
{
public:
Sylvain Thery's avatar
Sylvain Thery committed
152
	TraversorV(const MAP& m, unsigned int thread = 0) : TraversorCell<MAP, VERTEX>(m, false, thread)
153
	{}
Pierre Kraemer's avatar
Pierre Kraemer committed
154
};
Pierre Kraemer's avatar
Pierre Kraemer committed
155

156 157
template <typename MAP, TraversalOptim OPT = AUTO>
class TraversorE : public TraversorCell<MAP, EDGE, OPT>
Pierre Kraemer's avatar
Pierre Kraemer committed
158 159
{
public:
Sylvain Thery's avatar
Sylvain Thery committed
160
	TraversorE(const MAP& m, unsigned int thread = 0) : TraversorCell<MAP, EDGE>(m, false, thread)
161
	{}
Pierre Kraemer's avatar
Pierre Kraemer committed
162
};
Pierre Kraemer's avatar
Pierre Kraemer committed
163

164 165
template <typename MAP, TraversalOptim OPT = AUTO>
class TraversorF : public TraversorCell<MAP, FACE, OPT>
Pierre Kraemer's avatar
Pierre Kraemer committed
166 167
{
public:
Sylvain Thery's avatar
Sylvain Thery committed
168
	TraversorF(const MAP& m, unsigned int thread = 0) : TraversorCell<MAP, FACE>(m, false, thread)
169
	{}
Pierre Kraemer's avatar
Pierre Kraemer committed
170
};
Pierre Kraemer's avatar
Pierre Kraemer committed
171

172 173
template <typename MAP, TraversalOptim OPT = AUTO>
class TraversorW : public TraversorCell<MAP, VOLUME, OPT>
Pierre Kraemer's avatar
Pierre Kraemer committed
174 175
{
public:
Sylvain Thery's avatar
Sylvain Thery committed
176
	TraversorW(const MAP& m, unsigned int thread = 0) : TraversorCell<MAP, VOLUME>(m, false, thread)
177
	{}
Pierre Kraemer's avatar
Pierre Kraemer committed
178
};
Pierre Kraemer's avatar
Pierre Kraemer committed
179

Sylvain Thery's avatar
Sylvain Thery committed
180 181


Pierre Kraemer's avatar
Pierre Kraemer committed
182 183
} // namespace CGoGN

184
#include "Topology/generic/traversor/traversorCell.hpp"
185

Pierre Kraemer's avatar
Pierre Kraemer committed
186
#endif