Commit 73c2b1f3 authored by Sylvain Thery's avatar Sylvain Thery

foreach incident/adjacent dim 3

parent 399679f2
......@@ -74,31 +74,34 @@ typename V_ATT::DATA_TYPE volumeCentroidELW(typename PFP::MAP& map, Vol d, const
// Traversor3WE<typename PFP::MAP> t(map, d,false,thread) ;
// for(Dart it = t.begin(); it != t.end();it = t.next())
foreachIncident3MT(VOLUME,d,EDGE,it,typename PFP::MAP,map,thread)
// foreachIncident3MT(VOLUME,d,EDGE,it,typename PFP::MAP,map,thread)
foreach_incident3<EDGE>(map,d, [&] (Edge it)
{
EMB e1 = attributs[it.dart];
EMB e2 = attributs[map.phi1(it)];
double l = (e2-e1).norm();
center += (e1+e2)*l;
count += 2.0*l ;
}
},false,thread);
center /= double(count);
return center ;
}
template <typename PFP, typename V_ATT>
typename V_ATT::DATA_TYPE faceCentroid(typename PFP::MAP& map, Face d, const V_ATT& attributs)
typename V_ATT::DATA_TYPE faceCentroid(typename PFP::MAP& map, Face f, const V_ATT& attributs)
{
typename V_ATT::DATA_TYPE center(0.0);
unsigned int count = 0 ;
// Traversor2FV<typename PFP::MAP> t(map, d) ;
// for(Dart it = t.begin(); it != t.end(); it = t.next())
foreachIncident2(FACE,d,VERTEX,it,typename PFP::MAP,map)
// foreachIncident2(FACE,d,VERTEX,it,typename PFP::MAP,map)
foreach_incident2<VERTEX>(map, f, [&](Vertex it)
{
center += attributs[it];
++count ;
}
});
center /= double(count);
return center ;
}
......
......@@ -27,6 +27,8 @@
#include "Topology/generic/dart.h"
//#include "Topology/generic/traversorGen.h"
#include "Topology/generic/cells.h"
#include <functional>
namespace CGoGN
{
......@@ -41,16 +43,16 @@ class Traversor2VE//: public Traversor<MAP>
{
private:
const MAP& m ;
Dart start ;
Dart current ;
Edge start ;
Edge current ;
const std::vector<Dart>* m_QLT;
std::vector<Dart>::const_iterator m_ItDarts;
public:
Traversor2VE(const MAP& map, Dart dart) ;
Traversor2VE(const MAP& map, Vertex dart) ;
inline Dart begin() ;
inline Dart end() ;
inline Dart next() ;
inline Edge begin() ;
inline Edge end() ;
inline Edge next() ;
} ;
// Traverse the faces incident to a given vertex
......@@ -59,16 +61,16 @@ class Traversor2VF //: public Traversor<MAP>
{
private:
const MAP& m ;
Dart start ;
Dart current ;
Face start ;
Face current ;
const std::vector<Dart>* m_QLT;
std::vector<Dart>::const_iterator m_ItDarts;
public:
Traversor2VF(const MAP& map, Dart dart) ;
Traversor2VF(const MAP& map, Vertex dart) ;
inline Dart begin() ;
inline Dart end() ;
inline Dart next() ;
inline Face begin() ;
inline Face end() ;
inline Face next() ;
} ;
// Traverse the vertices adjacent to a given vertex through sharing a common edge
......@@ -77,16 +79,16 @@ class Traversor2VVaE //: public Traversor<MAP>
{
private:
const MAP& m ;
Dart start ;
Dart current ;
Vertex start ;
Vertex current ;
const std::vector<Dart>* m_QLT;
std::vector<Dart>::const_iterator m_ItDarts;
public:
Traversor2VVaE(const MAP& map, Dart dart) ;
Traversor2VVaE(const MAP& map, Vertex dart) ;
inline Dart begin() ;
inline Dart end() ;
inline Dart next() ;
inline Vertex begin() ;
inline Vertex end() ;
inline Vertex next() ;
} ;
// Traverse the vertices adjacent to a given vertex through sharing a common face
......@@ -95,18 +97,18 @@ class Traversor2VVaF //: public Traversor<MAP>
{
private:
const MAP& m ;
Dart start ;
Dart current ;
Vertex start ;
Vertex current ;
Dart stop ;
Vertex stop ;
const std::vector<Dart>* m_QLT;
std::vector<Dart>::const_iterator m_ItDarts;
public:
Traversor2VVaF(const MAP& map, Dart dart) ;
Traversor2VVaF(const MAP& map, Vertex dart) ;
inline Dart begin() ;
inline Dart end() ;
inline Dart next() ;
inline Vertex begin() ;
inline Vertex end() ;
inline Vertex next() ;
} ;
/*******************************************************************************
......@@ -119,16 +121,16 @@ class Traversor2EV //: public Traversor<MAP>
{
private:
const MAP& m ;
Dart start ;
Dart current ;
Vertex start ;
Vertex current ;
const std::vector<Dart>* m_QLT;
std::vector<Dart>::const_iterator m_ItDarts;
public:
Traversor2EV(const MAP& map, Dart dart) ;
Traversor2EV(const MAP& map, Edge dart) ;
inline Dart begin() ;
inline Dart end() ;
inline Dart next() ;
inline Vertex begin() ;
inline Vertex end() ;
inline Vertex next() ;
} ;
// Traverse the faces incident to a given edge
......@@ -137,16 +139,16 @@ class Traversor2EF //: public Traversor<MAP>
{
private:
const MAP& m ;
Dart start ;
Dart current ;
Face start ;
Face current ;
const std::vector<Dart>* m_QLT;
std::vector<Dart>::const_iterator m_ItDarts;
public:
Traversor2EF(const MAP& map, Dart dart) ;
Traversor2EF(const MAP& map, Edge dart) ;
inline Dart begin() ;
inline Dart end() ;
inline Dart next() ;
inline Face begin() ;
inline Face end() ;
inline Face next() ;
} ;
// Traverse the edges adjacent to a given edge through sharing a common vertex
......@@ -155,18 +157,18 @@ class Traversor2EEaV //: public Traversor<MAP>
{
private:
const MAP& m ;
Dart start ;
Dart current ;
Edge start ;
Edge current ;
Dart stop1, stop2 ;
Edge stop1, stop2 ;
const std::vector<Dart>* m_QLT;
std::vector<Dart>::const_iterator m_ItDarts;
public:
Traversor2EEaV(const MAP& map, Dart dart) ;
Traversor2EEaV(const MAP& map, Edge dart) ;
inline Dart begin() ;
inline Dart end() ;
inline Dart next() ;
inline Edge begin() ;
inline Edge end() ;
inline Edge next() ;
} ;
// Traverse the edges adjacent to a given edge through sharing a common face
......@@ -175,18 +177,18 @@ class Traversor2EEaF //: public Traversor<MAP>
{
private:
const MAP& m ;
Dart start ;
Dart current ;
Edge start ;
Edge current ;
Dart stop1, stop2 ;
Edge stop1, stop2 ;
const std::vector<Dart>* m_QLT;
std::vector<Dart>::const_iterator m_ItDarts;
public:
Traversor2EEaF(const MAP& map, Dart dart) ;
Traversor2EEaF(const MAP& map, Edge dart) ;
inline Dart begin() ;
inline Dart end() ;
inline Dart next() ;
inline Edge begin() ;
inline Edge end() ;
inline Edge next() ;
} ;
/*******************************************************************************
......@@ -199,45 +201,64 @@ class Traversor2FV //: public Traversor<MAP>
{
private:
const MAP& m ;
Dart start ;
Dart current ;
Vertex start ;
Vertex current ;
const std::vector<Dart>* m_QLT;
std::vector<Dart>::const_iterator m_ItDarts;
public:
Traversor2FV(const MAP& map, Dart dart) ;
Traversor2FV(const MAP& map, Face dart) ;
inline Dart begin() ;
inline Dart end() ;
inline Dart next() ;
inline Vertex begin() ;
inline Vertex end() ;
inline Vertex next() ;
} ;
// Traverse the edges incident to a given face (equivalent to vertices)
//// Traverse the edges incident to a given face (equivalent to vertices)
//template <typename MAP>
//class Traversor2FE: public Traversor2FV<MAP>
//{
//public:
// Traversor2FE(const MAP& map, Dart dart):Traversor2FV<MAP>(map,dart){}
//} ;
// Traverse the vertices incident to a given face
template <typename MAP>
class Traversor2FE: public Traversor2FV<MAP>
class Traversor2FE //: public Traversor<MAP>
{
private:
const MAP& m ;
Edge start ;
Edge current ;
const std::vector<Dart>* m_QLT;
std::vector<Dart>::const_iterator m_ItDarts;
public:
Traversor2FE(const MAP& map, Dart dart):Traversor2FV<MAP>(map,dart){}
Traversor2FE(const MAP& map, Face dart) ;
inline Edge begin() ;
inline Edge end() ;
inline Edge next() ;
} ;
// Traverse the faces adjacent to a given face through sharing a common vertex
template <typename MAP>
class Traversor2FFaV //: public Traversor<MAP>
{
private:
const MAP& m ;
Dart start ;
Dart current ;
Face start ;
Face current ;
Dart stop ;
Face stop ;
const std::vector<Dart>* m_QLT;
std::vector<Dart>::const_iterator m_ItDarts;
public:
Traversor2FFaV(const MAP& map, Dart dart) ;
Traversor2FFaV(const MAP& map, Face dart) ;
inline Dart begin() ;
inline Dart end() ;
inline Dart next() ;
inline Face begin() ;
inline Face end() ;
inline Face next() ;
} ;
// Traverse the faces adjacent to a given face through sharing a common edge
......@@ -247,16 +268,16 @@ class Traversor2FFaE //: public Traversor<MAP>
{
private:
const MAP& m ;
Dart start ;
Dart current ;
Face start ;
Face current ;
const std::vector<Dart>* m_QLT;
std::vector<Dart>::const_iterator m_ItDarts;
public:
Traversor2FFaE(const MAP& map, Dart dart) ;
Traversor2FFaE(const MAP& map, Face dart) ;
inline Dart begin() ;
inline Dart end() ;
inline Dart next() ;
inline Face begin() ;
inline Face end() ;
inline Face next() ;
} ;
......@@ -264,7 +285,8 @@ template <typename MAP, unsigned int F, unsigned int T>
class IncidentTrav2
{
public:
IncidentTrav2(const MAP&, Dart) {}
IncidentTrav2(const MAP&, Cell<F>) {}
};
......@@ -273,7 +295,7 @@ class IncidentTrav2<MAP,VERTEX,EDGE>
{
public:
Traversor2VE<MAP> t;
IncidentTrav2(const MAP& m, Dart d):t(m,d) {}
IncidentTrav2(const MAP& m, Vertex d):t(m,d) {}
};
template <typename MAP>
......@@ -281,7 +303,7 @@ class IncidentTrav2<MAP,VERTEX,FACE>
{
public:
Traversor2VF<MAP> t;
IncidentTrav2(const MAP& m, Dart d):t(m,d) {}
IncidentTrav2(const MAP& m, Vertex d):t(m,d) {}
};
template <typename MAP>
......@@ -289,7 +311,7 @@ class IncidentTrav2<MAP,EDGE,VERTEX>
{
public:
Traversor2EV<MAP> t;
IncidentTrav2(const MAP& m, Dart d):t(m,d) {}
IncidentTrav2(const MAP& m, Edge d):t(m,d) {}
};
template <typename MAP>
......@@ -297,7 +319,7 @@ class IncidentTrav2<MAP,EDGE,FACE>
{
public:
Traversor2EF<MAP> t;
IncidentTrav2(const MAP& m, Dart d):t(m,d) {}
IncidentTrav2(const MAP& m, Edge d):t(m,d) {}
};
template <typename MAP>
......@@ -305,7 +327,7 @@ class IncidentTrav2<MAP,FACE,VERTEX>
{
public:
Traversor2FV<MAP> t;
IncidentTrav2(const MAP& m, Dart d):t(m,d) {}
IncidentTrav2(const MAP& m, Face d):t(m,d) {}
};
template <typename MAP>
......@@ -313,7 +335,7 @@ class IncidentTrav2<MAP,FACE,EDGE>
{
public:
Traversor2FE<MAP> t;
IncidentTrav2(const MAP& m, Dart d):t(m,d) {}
IncidentTrav2(const MAP& m, Face d):t(m,d) {}
};
......@@ -322,7 +344,7 @@ template <typename MAP, unsigned int F, unsigned int T>
class AdjacentTrav2
{
public:
AdjacentTrav2(const MAP&, Dart) {}
AdjacentTrav2(const MAP&, Cell<F>) {}
};
......@@ -331,7 +353,7 @@ class AdjacentTrav2<MAP,VERTEX,EDGE>
{
public:
Traversor2VVaE<MAP> t;
AdjacentTrav2(const MAP& m, Dart d):t(m,d) {}
AdjacentTrav2(const MAP& m, Vertex d):t(m,d) {}
};
template <typename MAP>
......@@ -339,7 +361,7 @@ class AdjacentTrav2<MAP,VERTEX,FACE>
{
public:
Traversor2VVaF<MAP> t;
AdjacentTrav2(const MAP& m, Dart d):t(m,d) {}
AdjacentTrav2(const MAP& m, Vertex d):t(m,d) {}
};
template <typename MAP>
......@@ -347,7 +369,7 @@ class AdjacentTrav2<MAP,EDGE,VERTEX>
{
public:
Traversor2EEaV<MAP> t;
AdjacentTrav2(const MAP& m, Dart d):t(m,d) {}
AdjacentTrav2(const MAP& m, Edge d):t(m,d) {}
};
template <typename MAP>
......@@ -355,7 +377,7 @@ class AdjacentTrav2<MAP,EDGE,FACE>
{
public:
Traversor2EEaF<MAP> t;
AdjacentTrav2(const MAP& m, Dart d):t(m,d) {}
AdjacentTrav2(const MAP& m, Edge d):t(m,d) {}
};
template <typename MAP>
......@@ -363,7 +385,7 @@ class AdjacentTrav2<MAP,FACE,VERTEX>
{
public:
Traversor2FFaV<MAP> t;
AdjacentTrav2(const MAP& m, Dart d):t(m,d) {}
AdjacentTrav2(const MAP& m, Face d):t(m,d) {}
};
template <typename MAP>
......@@ -371,10 +393,28 @@ class AdjacentTrav2<MAP,FACE,EDGE>
{
public:
Traversor2FFaE<MAP> t;
AdjacentTrav2(const MAP& m, Dart d):t(m,d) {}
AdjacentTrav2(const MAP& m, Face d):t(m,d) {}
};
template < unsigned int ORBIT_TO, unsigned int ORBIT_FROM, typename MAP>
inline void foreach_incident2(MAP& map, Cell<ORBIT_FROM> c, std::function<void (Cell<ORBIT_TO>)> f)
{
IncidentTrav2<MAP,ORBIT_FROM,ORBIT_TO> trav(const_cast<const MAP&>(map),c);
for (Cell<ORBIT_TO> c = trav.t.begin(), e = trav.t.end(); c.dart != e.dart; c = trav.t.next())
f(c);
}
template <unsigned int THRU, unsigned int ORBIT, typename MAP>
inline void foreach_adjacent2( MAP& map, Cell<ORBIT> c, std::function<void (Cell<ORBIT>)> f)
{
AdjacentTrav2<MAP,ORBIT,THRU> trav(const_cast<const MAP&>(map),c);
for (Cell<ORBIT> c = trav.t.begin(), e = trav.t.end(); c.dart != e.dart; c = trav.t.next())
f(c);
}
} // namespace CGoGN
#include "Topology/generic/traversor/traversor2.hpp"
......
......@@ -32,22 +32,22 @@ namespace CGoGN
// Traversor2VE
template <typename MAP>
Traversor2VE<MAP>::Traversor2VE(const MAP& map, Dart dart) : m(map), start(dart),m_QLT(NULL)
Traversor2VE<MAP>::Traversor2VE(const MAP& map, Vertex dart) : m(map), start(dart),m_QLT(NULL)
{
const AttributeMultiVector<NoTypeNameAttribute<std::vector<Dart> > >* quickTraversal = map.template getQuickIncidentTraversal<VERTEX,EDGE>() ;
if (quickTraversal != NULL)
{
m_QLT = &(quickTraversal->operator[](map.template getEmbedding<VERTEX>(dart)));
m_QLT = &(quickTraversal->operator[](map.getEmbedding(dart)));
}
}
template <typename MAP>
Dart Traversor2VE<MAP>::begin()
Edge Traversor2VE<MAP>::begin()
{
if(m_QLT != NULL)
{
m_ItDarts = m_QLT->begin();
return *m_ItDarts++;
return Edge(*m_ItDarts++);
}
current = start ;
......@@ -55,24 +55,24 @@ Dart Traversor2VE<MAP>::begin()
}
template <typename MAP>
Dart Traversor2VE<MAP>::end()
Edge Traversor2VE<MAP>::end()
{
return NIL ;
return Edge(NIL) ;
}
template <typename MAP>
Dart Traversor2VE<MAP>::next()
Edge Traversor2VE<MAP>::next()
{
if(m_QLT != NULL)
{
return *m_ItDarts++;
return Edge(*m_ItDarts++);
}
if(current != NIL)
if(current.dart != NIL)
{
// current = m.alpha1(current) ;
current = m.phi2(m.phi_1(current)) ;
if(current == start)
current = Edge(m.phi2(m.phi_1(current.dart))) ;
if(current.dart == start.dart)
current = NIL ;
}
return current ;
......@@ -81,7 +81,7 @@ Dart Traversor2VE<MAP>::next()
// Traversor2VF
template <typename MAP>
Traversor2VF<MAP>::Traversor2VF(const MAP& map, Dart dart) : m(map), start(dart),m_QLT(NULL)
Traversor2VF<MAP>::Traversor2VF(const MAP& map, Vertex dart) : m(map), start(dart),m_QLT(NULL)
{
const AttributeMultiVector<NoTypeNameAttribute<std::vector<Dart> > >* quickTraversal = map.template getQuickIncidentTraversal<VERTEX,FACE>() ;
if (quickTraversal != NULL)
......@@ -96,12 +96,12 @@ Traversor2VF<MAP>::Traversor2VF(const MAP& map, Dart dart) : m(map), start(dart)
}
template <typename MAP>
Dart Traversor2VF<MAP>::begin()
Face Traversor2VF<MAP>::begin()
{
if(m_QLT != NULL)
{
m_ItDarts = m_QLT->begin();
return *m_ItDarts++;
return Face(*m_ItDarts++);
}
current = start ;
......@@ -109,24 +109,24 @@ Dart Traversor2VF<MAP>::begin()
}
template <typename MAP>
Dart Traversor2VF<MAP>::end()
Face Traversor2VF<MAP>::end()
{
return NIL ;
}
template <typename MAP>
Dart Traversor2VF<MAP>::next()
Face Traversor2VF<MAP>::next()
{
if(m_QLT != NULL)
{
return *m_ItDarts++;
return Face(*m_ItDarts++);
}
if(current != NIL)
if(current.dart != NIL)
{
current = m.phi2(m.phi_1(current)) ;
if(m.template isBoundaryMarked<2>(current)) // jump over a boundary face
current = m.phi2(m.phi_1(current)) ;
if(current == start)
if(current.dart == start.dart)
current = NIL ;
}
return current ;
......@@ -135,7 +135,7 @@ Dart Traversor2VF<MAP>::next()
// Traversor2VVaE
template <typename MAP>
Traversor2VVaE<MAP>::Traversor2VVaE(const MAP& map, Dart dart) : m(map),m_QLT(NULL)
Traversor2VVaE<MAP>::Traversor2VVaE(const MAP& map, Vertex dart) : m(map),m_QLT(NULL)
{
const AttributeMultiVector<NoTypeNameAttribute<std::vector<Dart> > >* quickTraversal = map.template getQuickAdjacentTraversal<VERTEX,EDGE>() ;
if (quickTraversal != NULL)
......@@ -149,7 +149,7 @@ Traversor2VVaE<MAP>::Traversor2VVaE(const MAP& map, Dart dart) : m(map),m_QLT(NU
}
template <typename MAP>
Dart Traversor2VVaE<MAP>::begin()
Vertex Traversor2VVaE<MAP>::begin()
{
if(m_QLT != NULL)
{
......@@ -162,22 +162,22 @@ Dart Traversor2VVaE<MAP>::begin()
}
template <typename MAP>
Dart Traversor2VVaE<MAP>::end()
Vertex Traversor2VVaE<MAP>::end()
{
return NIL ;
}
template <typename MAP>
Dart Traversor2VVaE<MAP>::next()
Vertex Traversor2VVaE<MAP>::next()
{
if(m_QLT != NULL)
{
return *m_ItDarts++;
return Vertex(*m_ItDarts++);