cells.h 11.3 KB
Newer Older
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 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187
/*******************************************************************************
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps  *
* version 0.1                                                                  *
* Copyright (C) 2009-2012, 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.unistra.fr/                                           *
* Contact information: cgogn@unistra.fr                                        *
*                                                                              *
*******************************************************************************/

#ifndef CELLS_H_
#define CELLS_H_

#include <iostream>
#include "dart.h"
#include "traversor2.h"
#include "traversor3.h"
#include "traversorCell.h"



namespace CGoGN
{

class ForeachHide
{

};

/// MACRO FOR SIMPLE TRAVERSALS WITH CELLS

#define YforeachIncident2(FROM, Cell_PARAM, TO, Cell_ITER, MAP_TYPE, MAP_PARAM,LNN)\
  IncidentTrav2<MAP_TYPE,FROM,TO> Cell_ITER##_TraversalMacroLocalLoop##LNN(MAP_PARAM,Cell_PARAM); \
  for ( Cell<TO> Cell_ITER ( Cell_ITER##_TraversalMacroLocalLoop##LNN.t.begin()), Cell_ITER##_endTMLoop( Cell_ITER##_TraversalMacroLocalLoop##LNN.t.end());\
	Cell_ITER != Cell_ITER ## _endTMLoop; Cell_ITER.dart() = Cell_ITER ## _TraversalMacroLocalLoop##LNN.t.next())
#define XforeachIncident2(FROM, Cell_PARAM, TO, Cell_ITER, MAP_TYPE, MAP_PARAM,LNN) YforeachIncident2(FROM, Cell_PARAM, TO, Cell_ITER, MAP_TYPE, MAP_PARAM,LNN)
#define foreachIncident2(FROM, Cell_PARAM, TO, Cell_ITER, MAP_TYPE, MAP_PARAM) XforeachIncident2(FROM, Cell_PARAM, TO, Cell_ITER, MAP_TYPE, MAP_PARAM,__LINE__)



#define YforeachAdjacent2(ORBIT,THRU, Cell_PARAM, Cell_ITER, MAP_TYPE, MAP_PARAM,LNN)\
  AdjacentTrav2<MAP_TYPE,ORBIT,THRU> Cell_ITER##_TraversalMacroLocalLoop##LNN(MAP_PARAM,Cell_PARAM); \
  for (Cell<ORBIT> Cell_ITER ( Cell_ITER##_TraversalMacroLocalLoop##LNN.t.begin()), Cell_ITER##_endTMLoop( Cell_ITER##_TraversalMacroLocalLoop##LNN.t.end()); \
	Cell_ITER != Cell_ITER##_endTMLoop; Cell_ITER.dart() = Cell_ITER##_TraversalMacroLocalLoop##LNN.t.next())
#define XforeachAdjacent2(ORBIT,THRU, Cell_PARAM, Cell_ITER, MAP_TYPE, MAP_PARAM,LNN) YforeachAdjacent2(ORBIT,THRU, Cell_PARAM, Cell_ITER, MAP_TYPE, MAP_PARAM,LNN)
#define foreachAdjacent2(ORBIT,THRU, Cell_PARAM, Cell_ITER, MAP_TYPE, MAP_PARAM) XforeachAdjacent2(ORBIT,THRU, Cell_PARAM, Cell_ITER, MAP_TYPE, MAP_PARAM,__LINE__)


#define YforeachIncident3(FROM, Cell_PARAM, TO, Cell_ITER, MAP_TYPE, MAP_PARAM,LNN)\
  Traversor3XY<MAP_TYPE,FROM,TO> Cell_ITER##_TraversalMacroLocalLoop##LNN(MAP_PARAM,Cell_PARAM); \
  for ( Cell<TO> Cell_ITER ( Cell_ITER##_TraversalMacroLocalLoop##LNN.begin()), Cell_ITER##_endTMLoop( Cell_ITER##_TraversalMacroLocalLoop##LNN.end());\
	Cell_ITER != Cell_ITER ## _endTMLoop; Cell_ITER.dart() = Cell_ITER ## _TraversalMacroLocalLoop##LNN.next())
#define XforeachIncident3(FROM, Cell_PARAM, TO, Cell_ITER, MAP_TYPE, MAP_PARAM,LNN) YforeachIncident3(FROM, Cell_PARAM, TO, Cell_ITER, MAP_TYPE, MAP_PARAM,LNN)
#define foreachIncident3(FROM, Cell_PARAM, TO, Cell_ITER, MAP_TYPE, MAP_PARAM) XforeachIncident3(FROM, Cell_PARAM, TO, Cell_ITER, MAP_TYPE, MAP_PARAM,__LINE__)

#define YforeachAdjacent3(ORBIT,THRU, Cell_PARAM, Cell_ITER, MAP_TYPE, MAP_PARAM,LNN)\
Traversor3XXaY<MAP_TYPE,ORBIT,THRU> Cell_ITER##_TraversalMacroLocalLoop##LNN(MAP_PARAM,Cell_PARAM); \
  for (Cell<ORBIT> Cell_ITER ( Cell_ITER##_TraversalMacroLocalLoop##LNN.begin()), Cell_ITER##_endTMLoop( Cell_ITER##_TraversalMacroLocalLoop##LNN.end()); \
	Cell_ITER != Cell_ITER##_endTMLoop; Cell_ITER.dart() = Cell_ITER##_TraversalMacroLocalLoop##LNN.next())
#define XforeachAdjacent3(ORBIT,THRU, Cell_PARAM, Cell_ITER, MAP_TYPE, MAP_PARAM,LNN) YforeachAdjacent3(ORBIT,THRU, Cell_PARAM, Cell_ITER, MAP_TYPE, MAP_PARAM,LNN)
#define foreachAdjacent3(ORBIT,THRU, Cell_PARAM, Cell_ITER, MAP_TYPE, MAP_PARAM) XforeachAdjacent3(ORBIT,THRU, Cell_PARAM, Cell_ITER, MAP_TYPE, MAP_PARAM,__LINE__)


#define YforeachCell(ORBIT, Cell_ITER, MAP_TYPE, MAP_PARAM,LNN)\
	TraversorCell<MAP_TYPE,ORBIT> Cell_ITER##_TraversalMacroLocalLoop##LNN(MAP_PARAM);\
	for (Cell<ORBIT> Cell_ITER ( Cell_ITER##_TraversalMacroLocalLoop##LNN.begin()), Cell_ITER##_endTMLoop( Cell_ITER##_TraversalMacroLocalLoop##LNN.end()); \
	  Cell_ITER != Cell_ITER##_endTMLoop; Cell_ITER.dart() = Cell_ITER##_TraversalMacroLocalLoop##LNN.next())
#define XforeachCell(ORBIT, Cell_ITER, MAP_TYPE, MAP_PARAM,LNN)  YforeachCell(ORBIT, Cell_ITER, MAP_TYPE, MAP_PARAM,LNN)
#define foreachCell(ORBIT, Cell_ITER, MAP_TYPE, MAP_PARAM)  XforeachCell(ORBIT, Cell_ITER, MAP_TYPE, MAP_PARAM,__LINE__)


///// VERSION WITHOUT TYPE OF MAP, use PFP::MAP

/*

#define foreachIncident2PFP(FROM, Cell_PARAM, TO, Cell_ITER, MAP_PARAM)\
  IncidentTrav2<typename PFP::MAP,FROM,TO> Cell_ITER##_TraversalMacroLocalLoop__LINE__(MAP_PARAM,Cell_PARAM); \
  for ( Cell<TO> Cell_ITER ( Cell_ITER##_TraversalMacroLocalLoop__LINE__.t.begin()), Cell_ITER##_endTMLoop( Cell_ITER##_TraversalMacroLocalLoop__LINE__.t.end());\
	Cell_ITER != Cell_ITER ## _endTMLoop; Cell_ITER.dart() = Cell_ITER ## _TraversalMacroLocalLoop__LINE__.t.next())

#define foreachAdjacent2PFP(ORBIT,THRU, Cell_PARAM, Cell_ITER, MAP_PARAM)\
  AdjacentTrav2<typename PFP::MAP,ORBIT,THRU> Cell_ITER##_TraversalMacroLocalLoop__LINE__(MAP_PARAM,Cell_PARAM); \
  for (Cell<ORBIT> Cell_ITER ( Cell_ITER##_TraversalMacroLocalLoop__LINE__.t.begin()), Cell_ITER##_endTMLoop( Cell_ITER##_TraversalMacroLocalLoop__LINE__.t.end()); \
	Cell_ITER != Cell_ITER##_endTMLoop; Cell_ITER.dart() = Cell_ITER##_TraversalMacroLocalLoop__LINE__.t.next())


#define foreachIncident3PFP(FROM, Cell_PARAM, TO, Cell_ITER, MAP_PARAM)\
  Traversor3XY<typename PFP::MAP,FROM,TO> Cell_ITER##_TraversalMacroLocalLoop__LINE__(MAP_PARAM,Cell_PARAM); \
  for ( Cell<TO> Cell_ITER ( Cell_ITER##_TraversalMacroLocalLoop__LINE__.begin()), Cell_ITER##_endTMLoop( Cell_ITER##_TraversalMacroLocalLoop__LINE__.end());\
	Cell_ITER != Cell_ITER ## _endTMLoop; Cell_ITER.dart() = Cell_ITER ## _TraversalMacroLocalLoop__LINE__.next())

#define foreachAdjacent3PFP(ORBIT,THRU, Cell_PARAM, Cell_ITER, MAP_PARAM)\
  Traversor3XXaY<typename PFP::MAP,ORBIT,THRU> Cell_ITER##_TraversalMacroLocalLoop__LINE__(MAP_PARAM,Cell_PARAM); \
  for (Cell<ORBIT> Cell_ITER ( Cell_ITER##_TraversalMacroLocalLoop__LINE__.begin()), Cell_ITER##_endTMLoop( Cell_ITER##_TraversalMacroLocalLoop__LINE__.end()); \
	Cell_ITER != Cell_ITER##_endTMLoop; Cell_ITER.dart() = Cell_ITER##_TraversalMacroLocalLoop__LINE__.next())


#define foreachCellPFP(ORBIT, Cell_ITER, MAP_PARAM)\
	TraversorCell<typename PFP::MAP,ORBIT> Cell_ITER##_TraversalMacroLocalLoop__LINE__(MAP_PARAM);\
	for (Cell<ORBIT> Cell_ITER ( Cell_ITER##_TraversalMacroLocalLoop__LINE__.begin()), Cell_ITER##_endTMLoop( Cell_ITER##_TraversalMacroLocalLoop__LINE__.end()); \
	  Cell_ITER != Cell_ITER##_endTMLoop; Cell_ITER.dart() = Cell_ITER##_TraversalMacroLocalLoop__LINE__.next())

*/


/// MultiThread versions of foreach___3
/// for dimension no need (to not use marker)

#define YforeachIncident3MT(FROM, Cell_PARAM, TO, Cell_ITER, MAP_TYPE, MAP_PARAM, THREAD,LNN)\
Traversor3XY<MAP_TYPE,FROM,TO> Cell_ITER##_TraversalMacroLocalLoop##LNN(MAP_PARAM,Cell_PARAM,false,THREAD); \
for ( Cell<TO> Cell_ITER ( Cell_ITER##_TraversalMacroLocalLoop##LNN.begin()), Cell_ITER##_endTMLoop( Cell_ITER##_TraversalMacroLocalLoop##LNN.end());\
  Cell_ITER != Cell_ITER ## _endTMLoop; Cell_ITER.dart() = Cell_ITER ## _TraversalMacroLocalLoop##LNN.next())
#define XforeachIncident3MT(FROM, Cell_PARAM, TO, Cell_ITER, MAP_TYPE, MAP_PARAM, THREAD,LNN) YforeachIncident3MT(FROM, Cell_PARAM, TO, Cell_ITER, MAP_TYPE, MAP_PARAM, THREAD,LNN)
#define foreachIncident3MT(FROM, Cell_PARAM, TO, Cell_ITER, MAP_TYPE, MAP_PARAM, THREAD) XforeachIncident3MT(FROM, Cell_PARAM, TO, Cell_ITER, MAP_TYPE, MAP_PARAM, THREAD,__LINE__)

#define YforeachAdjacent3MT(ORBIT,THRU, Cell_PARAM, Cell_ITER, MAP_TYPE, MAP_PARAM, THREAD,LNN)\
Traversor3XXaY<MAP_TYPE,ORBIT,THRU> Cell_ITER##_TraversalMacroLocalLoop##LNN(MAP_PARAM,Cell_PARAM,false,THREAD); \
for (Cell<ORBIT> Cell_ITER ( Cell_ITER##_TraversalMacroLocalLoop##LNN.begin()), Cell_ITER##_endTMLoop( Cell_ITER##_TraversalMacroLocalLoop##LNN.end()); \
  Cell_ITER != Cell_ITER##_endTMLoop; Cell_ITER.dart() = Cell_ITER##_TraversalMacroLocalLoop##LNN.next())
#define XforeachAdjacent3MT(ORBIT,THRU, Cell_PARAM, Cell_ITER, MAP_TYPE, MAP_PARAM, THREAD,LNN) YforeachAdjacent3MT(ORBIT,THRU, Cell_PARAM, Cell_ITER, MAP_TYPE, MAP_PARAM, THREAD,LNN)
#define foreachAdjacent3MT(ORBIT,THRU, Cell_PARAM, Cell_ITER, MAP_TYPE, MAP_PARAM, THREAD) XforeachAdjacent3MT(ORBIT,THRU, Cell_PARAM, Cell_ITER, MAP_TYPE, MAP_PARAM, THREAD,__LINE__)



#define YforeachCellMT(ORBIT, Cell_ITER, MAP_TYPE, MAP_PARAM, THREAD,LNN)\
TraversorCell<MAP_TYPE,ORBIT> Cell_ITER##_TraversalMacroLocalLoop##LNN(MAP_PARAM,false,THREAD);\
for (Cell<ORBIT> Cell_ITER ( Cell_ITER##_TraversalMacroLocalLoop##LNN.begin()), Cell_ITER##_endTMLoop( Cell_ITER##_TraversalMacroLocalLoop##LNN.end()); \
  Cell_ITER != Cell_ITER##_endTMLoop; Cell_ITER.dart() = Cell_ITER##_TraversalMacroLocalLoop##LNN.next())
#define XforeachCellMT(ORBIT, Cell_ITER, MAP_TYPE, MAP_PARAM, THREAD,LNN) YforeachCellMT(ORBIT, Cell_ITER, MAP_TYPE, MAP_PARAM, THREAD,LNN)
#define foreachCellMT(ORBIT, Cell_ITER, MAP_TYPE, MAP_PARAM, THREAD) XforeachCellMT(ORBIT, Cell_ITER, MAP_TYPE, MAP_PARAM, THREAD,__LINE__)



/**
 * class for cellular typing
 *
 * warning to automatic conversion
 * cell -> Dart (or const Dart&) ok
 * Dart -> Cell (or const Cell&) ok
 */
template <unsigned int ORBIT>
class Cell
{
	Dart m_d;
public:
	/// emoty construtor
	Cell(): m_d() {}
	/// construtor from Dart
	inline Cell(Dart d): m_d(d) {}
	/// copy constructor
	inline Cell(const Cell<ORBIT>& c): m_d(c.m_d) {}
	/// return the dart
	inline Dart dart() const { return m_d; }
	/// return a ref to dart
	inline Dart& dart() { return m_d; }
	/// equal operation
	inline bool operator==(Cell<ORBIT> d) const { return d.m_d.index == m_d.index; }
	inline bool operator!=(Cell<ORBIT> d) const { return d.m_d.index != m_d.index; }
	/// Dart cast operator
	inline operator Dart() {return m_d;}
};

typedef Cell<VERTEX> Vertex;
typedef Cell<EDGE>   Edge;
typedef Cell<FACE>   Face;
typedef Cell<VOLUME> Vol;




}

#endif /* CELLS_H_ */