Commit 29b48c13 authored by Sylvain Thery's avatar Sylvain Thery

new traversal (c++11 for) syntax cell/neighbours

parent c40a4912
......@@ -136,7 +136,7 @@ void VertexTyped(MAP& map, T& va)
// });
// other syntax for traversal
for (Vertex v : allVertices<MAP>(map))
for (Vertex v : allVerticesOf(map))
{
va[v] = 1.1 * va[v];
std::cout << "V:" << v << " -> "<<va[v]<< std::endl;
......
......@@ -73,7 +73,7 @@ int main()
// using parallel foreach
// parameter position must be captured explicitly even if it used as first parameter of foreach !
Parallel::foreach_attribute(position, [&position] (unsigned int id, unsigned int thread) // for each elt of the position attribute
Parallel::foreach_attribute(position, [&position] (unsigned int id, unsigned int /*thread*/) // for each elt of the position attribute
{
position[id] *= 2.0f;
}, 4); // 4:4 thread, false for no need for markers in threaded code.
......
......@@ -111,17 +111,18 @@ int main()
}); // 4:4 thread, false for no need for markers in threaded code.
std::cout << "After // processing"<< std::endl;
foreach_cell<VERTEX>(myMap, [&] (Vertex v) // for each Vertex v of the MAP myMap
// last and simple traversal method (new for c++11 syntax)
for(Vertex v : allVerticesOf(myMap))
{
std::cout << position[v] << " / ";
});
}
std::cout << std::endl;
// Example with // accumulation
// computing the sum of area faces
// force number of threads to 4 (0 for traverse, 1,2,3 for computation)
CGoGN::Parallel::NumberOfThreads = 4;
......@@ -137,6 +138,8 @@ int main()
std::cout << surf[0]<< "/"<< surf[1]<< "/"<< surf[2]<< "/"<< std::endl;
std::cout << "Total="<<surf[0]+surf[1]+surf[2]<< std::endl;
// example of traversal in two pass (optimizing marking/unmarking)
TraversorV<MAP> tv0(myMap);
TraversorCellEven<MAP, VERTEX> tv1(tv0);
TraversorCellOdd<MAP, VERTEX> tv2(tv0);
......
......@@ -102,5 +102,16 @@ int main()
std::cout << "vertex of dart " << x << " adjacent to vertex of dart " << v.dart << " by a face" << std::endl;
});
// WITH FOR C++11 SYNTAX
for(Face f : facesIncidentToVertex2(myMap,v))
{
std::cout << "Face of dart " << f << " incident to vertex of dart " << v.dart << std::endl;
}
for (Vertex x : verticesAdjacentByFace2(myMap,v))
{
std::cout << "vertex of dart " << x << " adjacent to vertex of dart " << v.dart << " by a face" << std::endl;
}
return 0;
}
......@@ -51,6 +51,10 @@ public:
inline Edge begin() ;
inline Edge end() ;
inline Edge next() ;
typedef Edge IterType;
typedef Vertex ParamType;
typedef MAP MapType;
} ;
// Traverse the faces incident to a given vertex
......@@ -69,6 +73,10 @@ public:
inline Face begin() ;
inline Face end() ;
inline Face next() ;
typedef Face IterType;
typedef Vertex ParamType;
typedef MAP MapType;
} ;
// Traverse the vertices adjacent to a given vertex through sharing a common edge
......@@ -87,6 +95,10 @@ public:
inline Vertex begin() ;
inline Vertex end() ;
inline Vertex next() ;
typedef Vertex IterType;
typedef Vertex ParamType;
typedef MAP MapType;
} ;
// Traverse the vertices adjacent to a given vertex through sharing a common face
......@@ -107,6 +119,10 @@ public:
inline Vertex begin() ;
inline Vertex end() ;
inline Vertex next() ;
typedef Vertex IterType;
typedef Vertex ParamType;
typedef MAP MapType;
} ;
/*******************************************************************************
......@@ -129,6 +145,10 @@ public:
inline Vertex begin() ;
inline Vertex end() ;
inline Vertex next() ;
typedef Vertex IterType;
typedef Edge ParamType;
typedef MAP MapType;
} ;
// Traverse the faces incident to a given edge
......@@ -147,6 +167,10 @@ public:
inline Face begin() ;
inline Face end() ;
inline Face next() ;
typedef Face IterType;
typedef Edge ParamType;
typedef MAP MapType;
} ;
// Traverse the edges adjacent to a given edge through sharing a common vertex
......@@ -167,6 +191,10 @@ public:
inline Edge begin() ;
inline Edge end() ;
inline Edge next() ;
typedef Edge IterType;
typedef Edge ParamType;
typedef MAP MapType;
} ;
// Traverse the edges adjacent to a given edge through sharing a common face
......@@ -187,6 +215,10 @@ public:
inline Edge begin() ;
inline Edge end() ;
inline Edge next() ;
typedef Edge IterType;
typedef Edge ParamType;
typedef MAP MapType;
} ;
/*******************************************************************************
......@@ -209,6 +241,10 @@ public:
inline Vertex begin() ;
inline Vertex end() ;
inline Vertex next() ;
typedef Vertex IterType;
typedef Face ParamType;
typedef MAP MapType;
} ;
......@@ -236,6 +272,10 @@ public:
inline Edge begin() ;
inline Edge end() ;
inline Edge next() ;
typedef Edge IterType;
typedef Face ParamType;
typedef MAP MapType;
} ;
......@@ -257,6 +297,10 @@ public:
inline Face begin() ;
inline Face end() ;
inline Face next() ;
typedef Face IterType;
typedef Face ParamType;
typedef MAP MapType;
} ;
// Traverse the faces adjacent to a given face through sharing a common edge
......@@ -276,6 +320,10 @@ public:
inline Face begin() ;
inline Face end() ;
inline Face next() ;
typedef Face IterType;
typedef Face ParamType;
typedef MAP MapType;
} ;
......@@ -394,6 +442,7 @@ public:
AdjacentTrav2(const MAP& m, Face d):t(m,d) {}
};
// foreach traversal function
template <unsigned int ORBIT_TO, unsigned int ORBIT_FROM, typename MAP, typename FUNC>
inline void foreach_incident2(MAP& map, Cell<ORBIT_FROM> c, FUNC f)
......@@ -411,6 +460,141 @@ inline void foreach_adjacent2(MAP& map, Cell<ORBIT> c, FUNC f)
f(c);
}
/**
* template classs that add iterator to Traversor
* to allow the use of c++11 syntax for (auto d : v)
*/
template <typename TRAV>
class Iteratorize: public TRAV
{
public:
typedef typename TRAV::MapType MAP;
typedef typename TRAV::IterType ITER;
typedef typename TRAV::ParamType PARAM;
Iteratorize(const MAP& map, PARAM p):
TRAV(map,p){}
class iterator
{
Iteratorize<TRAV>* m_ptr;
ITER m_index;
public:
inline iterator(Iteratorize<TRAV>* p, ITER i): m_ptr(p),m_index(i){}
inline iterator& operator++()
{
m_index = m_ptr->next();
return *this;
}
inline ITER& operator*()
{
return m_index;
}
inline bool operator!=(const iterator& it)
{
return m_index.dart != it.m_index.dart;
}
};
inline iterator begin()
{
return iterator(this,TRAV::begin());
}
inline iterator end()
{
return iterator(this,TRAV::end());
}
};
// functions that return the traversor+iterator
// functions instead of typedef because function
// allows the compiler to deduce template param
template <typename MAP>
inline Iteratorize< Traversor2VE<MAP> > edgesIncidentToVertex2(const MAP& m, Vertex c)
{
return Iteratorize< Traversor2VE<MAP> >(m, c);
}
template <typename MAP>
inline Iteratorize< Traversor2VF<MAP> > facesIncidentToVertex2(const MAP& m, Vertex c)
{
return Iteratorize< Traversor2VF<MAP> >(m, c);
}
template <typename MAP>
inline Iteratorize< Traversor2EV<MAP> > verticesIncidentToEdge2(const MAP& m, Edge c)
{
return Iteratorize< Traversor2EV<MAP> >(m, c);
}
template <typename MAP>
inline Iteratorize< Traversor2EF<MAP> > facesIncidentToEdge2(const MAP& m, Edge c)
{
return Iteratorize< Traversor2EF<MAP> >(m, c);
}
template <typename MAP>
inline Iteratorize< Traversor2FV<MAP> > verticesIncidentToFace2(const MAP& m, Face c)
{
return Iteratorize< Traversor2FV<MAP> >(m, c);
}
template <typename MAP>
inline Iteratorize< Traversor2FE<MAP> > edgesIncidentToFace2(const MAP& m, Face c)
{
return Iteratorize< Traversor2FE<MAP> >(m, c);
}
template <typename MAP>
inline Iteratorize< Traversor2VVaE<MAP> > verticesAdjacentByEdge2(const MAP& m, Vertex c)
{
return Iteratorize< Traversor2VVaE<MAP> >(m, c);
}
template <typename MAP>
inline Iteratorize< Traversor2VVaF<MAP> > verticesAdjacentByFace2(const MAP& m, Vertex c)
{
return Iteratorize< Traversor2VVaF<MAP> >(m, c);
}
template <typename MAP>
inline Iteratorize< Traversor2EEaV<MAP> > edgesAdjacentByVertex2(const MAP& m, Edge c)
{
return Iteratorize< Traversor2EEaV<MAP> >(m, c);
}
template <typename MAP>
inline Iteratorize< Traversor2EEaF<MAP> > edgesAdjacentByFace2(const MAP& m, Edge c)
{
return Iteratorize< Traversor2EEaF<MAP> >(m, c);
}
template <typename MAP>
inline Iteratorize< Traversor2FFaV<MAP> > facesAdjacentByVertex2(const MAP& m, Face c)
{
return Iteratorize< Traversor2FFaV<MAP> >(m, c);
}
template <typename MAP>
inline Iteratorize< Traversor2FFaE<MAP> > facesAdjacentByEdge2(const MAP& m, Face c)
{
return Iteratorize< Traversor2FFaE<MAP> >(m, c);
}
} // namespace CGoGN
#include "Topology/generic/traversor/traversor2.hpp"
......
......@@ -82,9 +82,22 @@ public:
Traversor3XY(const MAP& map, Cell<ORBX> c, MarkerForTraversor<MAP, ORBY>& tmo, bool forceDartMarker = false, unsigned int thread = 0) ;
~Traversor3XY();
Traversor3XY(Traversor3XY<MAP,ORBX,ORBY>&& tra):
m_map(tra.m_map),m_tradoo(std::move(tra.m_tradoo))
{
m_dmark = tra.m_dmark;
m_cmark = tra.m_cmark;
m_current = tra.m_current;
// m_tradoo = std::move(tra.m_tradoo);
}
Cell<ORBY> begin() ;
Cell<ORBY> end() ;
Cell<ORBY> next() ;
typedef Cell<ORBY> IterType;
typedef Cell<ORBX> ParamType;
typedef MAP MapType;
} ;
/**
......@@ -108,6 +121,10 @@ public:
Cell<ORBX> begin();
Cell<ORBX> end();
Cell<ORBX> next();
typedef Cell<ORBX> IterType;
typedef Cell<ORBX> ParamType;
typedef MAP MapType;
};
/**
......@@ -123,12 +140,15 @@ public:
/**
* Traverse edges incident to volume
*/
//template <typename MAP>
//class Traversor3WE: public Traversor3XY<MAP, VOLUME, EDGE>
//{
//public:
// Traversor3WE(const MAP& m, Vol dart, bool forceDartMarker = false, unsigned int thread = 0) : Traversor3XY<MAP, VOLUME, EDGE>(m, dart, forceDartMarker, thread) {}
//};
template <typename MAP>
class Traversor3WE: public Traversor3XY<MAP, VOLUME, EDGE>
{
public:
Traversor3WE(const MAP& m, Vol dart, bool forceDartMarker = false, unsigned int thread = 0) : Traversor3XY<MAP, VOLUME, EDGE>(m, dart, forceDartMarker, thread) {}
};
using Traversor3WE = Traversor3XY<MAP, VOLUME, EDGE>;
/**
* Traverse faces incident to volume
......@@ -369,6 +389,212 @@ inline void foreach_adjacent3(MAP& map, Cell<ORBIT> c, FUNC f, bool forceDartMar
}
/**
* template classs that add iterator to Traversor
* to allow the use of c++11 syntax for (auto d : v)
*/
template <typename TRAV>
class Iteratorize3: public TRAV
{
public:
typedef typename TRAV::MapType MAP;
typedef typename TRAV::IterType ITER;
typedef typename TRAV::ParamType PARAM;
Iteratorize3(const MAP& map, PARAM p):
TRAV(map,p){}
class iterator
{
Iteratorize3<TRAV>* m_ptr;
ITER m_index;
public:
inline iterator(Iteratorize3<TRAV>* p, ITER i): m_ptr(p),m_index(i){}
inline iterator& operator++()
{
m_index = m_ptr->next();
return *this;
}
inline ITER& operator*()
{
return m_index;
}
inline bool operator!=(const iterator& it)
{
return m_index.dart != it.m_index.dart;
}
};
inline iterator begin()
{
return iterator(this,TRAV::begin());
}
inline iterator end()
{
return iterator(this,TRAV::end());
}
};
// functions that return the traversor+iterator
// functions instead of typedef because function
// allows the compiler to deduce template param
template <typename MAP>
inline Iteratorize3< Traversor3VE<MAP> > edgesIncidentToVertex3(const MAP& m, Vertex c)
{
return Iteratorize3< Traversor3VE<MAP> >(m, c);
}
template <typename MAP>
inline Iteratorize3< Traversor3VF<MAP> > facesIncidentToVertex3(const MAP& m, Vertex c)
{
return Iteratorize3< Traversor3VF<MAP> >(m, c);
}
template <typename MAP>
inline Iteratorize3< Traversor3VW<MAP> > VolumesIncidentToVertex3(const MAP& m, Vertex c)
{
return Iteratorize3< Traversor3VW<MAP> >(m, c);
}
template <typename MAP>
inline Iteratorize3< Traversor3EV<MAP> > verticesIncidentToEdge3(const MAP& m, Edge c)
{
return Iteratorize3< Traversor3EV<MAP> >(m, c);
}
template <typename MAP>
inline Iteratorize3< Traversor3EF<MAP> > facesIncidentToEdge3(const MAP& m, Edge c)
{
return Iteratorize3< Traversor3EF<MAP> >(m, c);
}
template <typename MAP>
inline Iteratorize3< Traversor3EW<MAP> > volumesIncidentToEdge3(const MAP& m, Edge c)
{
return Iteratorize3< Traversor3EW<MAP> >(m, c);
}
template <typename MAP>
inline Iteratorize3< Traversor3FV<MAP> > verticesIncidentToFace3(const MAP& m, Face c)
{
return Iteratorize3< Traversor3FV<MAP> >(m, c);
}
template <typename MAP>
inline Iteratorize3< Traversor3FE<MAP> > edgesIncidentToFace3(const MAP& m, Face c)
{
return Iteratorize3< Traversor3FE<MAP> >(m, c);
}
template <typename MAP>
inline Iteratorize3< Traversor3FW<MAP> > volumesIncidentToFace3(const MAP& m, Face c)
{
return Iteratorize3< Traversor3FW<MAP> >(m, c);
}
template <typename MAP>
inline Iteratorize3< Traversor3WV<MAP> > verticesIncidentToVolume3(const MAP& m, Vol c)
{
return Iteratorize3< Traversor3WV<MAP> >(m, c);
}
template <typename MAP>
inline Iteratorize3< Traversor3WE<MAP> > edgesIncidentToVolume3(const MAP& m, Vol c)
{
return Iteratorize3< Traversor3WE<MAP> >(m, c);
}
template <typename MAP>
inline Iteratorize3< Traversor3WF<MAP> > facesIncidentToVolume3(const MAP& m, Vol c)
{
return Iteratorize3< Traversor3WF<MAP> >(m, c);
}
template <typename MAP>
inline Iteratorize3< Traversor3VVaE<MAP> > verticesAdjacentByEdge3(const MAP& m, Vertex c)
{
return Iteratorize3< Traversor3VVaE<MAP> >(m, c);
}
template <typename MAP>
inline Iteratorize3< Traversor3VVaF<MAP> > verticesAdjacentByFace3(const MAP& m, Vertex c)
{
return Iteratorize3< Traversor3VVaF<MAP> >(m, c);
}
template <typename MAP>
inline Iteratorize3< Traversor3VVaW<MAP> > verticesAdjacentByVolume3(const MAP& m, Vertex c)
{
return Iteratorize3< Traversor3VVaW<MAP> >(m, c);
}
template <typename MAP>
inline Iteratorize3< Traversor3EEaV<MAP> > edgesAdjacentByVertex3(const MAP& m, Edge c)
{
return Iteratorize3< Traversor3EEaV<MAP> >(m, c);
}
template <typename MAP>
inline Iteratorize3< Traversor3EEaF<MAP> > edgesAdjacentByFace3(const MAP& m, Edge c)
{
return Iteratorize3< Traversor3EEaF<MAP> >(m, c);
}
template <typename MAP>
inline Iteratorize3< Traversor3EEaW<MAP> > edgesAdjacentByVolume3(const MAP& m, Edge c)
{
return Iteratorize3< Traversor3EEaW<MAP> >(m, c);
}
template <typename MAP>
inline Iteratorize3< Traversor3FFaV<MAP> > facesAdjacentByVertex3(const MAP& m, Face c)
{
return Iteratorize3< Traversor3FFaV<MAP> >(m, c);
}
template <typename MAP>
inline Iteratorize3< Traversor3FFaE<MAP> > facesAdjacentByEdge3(const MAP& m, Face c)
{
return Iteratorize3< Traversor3FFaE<MAP> >(m, c);
}
template <typename MAP>
inline Iteratorize3< Traversor3FFaW<MAP> > facesAdjacentByVolume3(const MAP& m, Face c)
{
return Iteratorize3< Traversor3FFaW<MAP> >(m, c);
}
template <typename MAP>
inline Iteratorize3< Traversor3WWaV<MAP> > volumesAdjacentByVertex3(const MAP& m, Vol c)
{
return Iteratorize3< Traversor3WWaV<MAP> >(m, c);
}
template <typename MAP>
inline Iteratorize3< Traversor3WWaE<MAP> > volumesAdjacentByEdge3(const MAP& m, Vol c)
{
return Iteratorize3< Traversor3WWaE<MAP> >(m, c);
}
template <typename MAP>
inline Iteratorize3< Traversor3WWaF<MAP> > volumesAdjacentByFace3(const MAP& m, Vol c)
{
return Iteratorize3< Traversor3WWaF<MAP> >(m, c);
}
} // namespace CGoGN
......
......@@ -186,8 +186,8 @@ public:
class iterator
{
Cell<ORBIT> m_index;
TraversorCell<MAP,ORBIT,OPT>* m_ptr;
Cell<ORBIT> m_index;
public:
......@@ -223,6 +223,57 @@ public:
};
template <typename MAP>
inline allCells<MAP, VERTEX, AUTO> allVerticesOf(const MAP& m,unsigned int thread=0)
{
return allCells<MAP,VERTEX,AUTO>(m, false, thread);
}
template <typename MAP>
inline allCells<MAP, EDGE, AUTO> allEdgesOf(const MAP& m,unsigned int thread=0)
{
return allCells<MAP,EDGE,AUTO>(m, false, thread);
}
template <typename MAP>
inline allCells<MAP, FACE, AUTO> allFacesOf(const MAP& m,unsigned int thread=0)
{
return allCells<MAP,FACE,AUTO>(m, false, thread);
}
template <typename MAP>
inline allCells<MAP, VOLUME, AUTO> allVolumesOf(const MAP& m,unsigned int thread=0)
{
return allCells<MAP,VOLUME,AUTO>(m, false, thread);
}
template <TraversalOptim OPT, typename MAP>
inline allCells<MAP, VERTEX, OPT> allVerticesOf(const MAP& m,unsigned int thread=0)
{
return allCells<MAP,VERTEX,OPT>(m, false, thread);
}
template <TraversalOptim OPT, typename MAP>
inline allCells<MAP, EDGE, OPT> allEdgesOf(const MAP& m,unsigned int thread=0)
{
return allCells<MAP,EDGE,OPT>(m, false, thread);
}
template <TraversalOptim OPT, typename MAP>
inline allCells<MAP, FACE, OPT> allFacesOf(const MAP& m,unsigned int thread=0)
{
return allCells<MAP,FACE,OPT>(m, false, thread);
}
template <TraversalOptim OPT, typename MAP>
inline allCells<MAP, VOLUME, OPT> allVolumesOf(const MAP& m,unsigned int thread=0)
{
return allCells<MAP,VOLUME,OPT>(m, false, thread);
}
/*
template <typename MAP, TraversalOptim OPT = AUTO>
class allVertices : public allCells<MAP, VERTEX, OPT>
{
......@@ -256,7 +307,7 @@ public:
{}
};
*/
......
......@@ -46,6 +46,11 @@ public:
~TraversorDartsOfOrbit();
TraversorDartsOfOrbit(TraversorDartsOfOrbit<MAP,ORBIT>&& tr):
m_vd(tr.m_vd), m_current(tr.m_current),m_thread(tr.m_thread)
{
}
Dart begin() ;
Dart end() ;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment