Commit fa5e0982 authored by Pierre Kraemer's avatar Pierre Kraemer

change foreach_dart_of_xxx functions to std::function

parent 01ce9ff4
......@@ -505,8 +505,14 @@ int main(int argc, char **argv)
std::cout << "Compute Volume ->"<< std::endl;
ch.start();
float vol = Algo::Geometry::totalVolume<PFP>(myMap, position);
std::cout << ch.elapsed()<< " ms val="<<vol<< std::endl;
ch.start();
vol += Algo::Geometry::totalVolume<PFP>(myMap, position);
std::cout << ch.elapsed()<< " ms val="<<vol<< std::endl;
ch.start();
vol += Algo::Geometry::totalVolume<PFP>(myMap, position);
std::cout << ch.elapsed()<< " ms val="<<vol<< std::endl;
ch.start();
vol += Algo::Geometry::totalVolume<PFP>(myMap, position);
std::cout << ch.elapsed()<< " ms val="<<vol<< std::endl;
......
......@@ -139,11 +139,9 @@ void MyQT::cb_Save()
}
template <unsigned int ORBIT>
void MyQT::colorizeCell(Dart d, float r,float g, float b)
void MyQT::colorizeCell(Cell<ORBIT> c, float r, float g, float b)
{
TraversorDartsOfOrbit<PFP::MAP, ORBIT>doo (myMap, d);
for (Dart e = doo.begin(); e != doo.end(); e = doo.next())
m_render_topo->setDartColor(e, r, g, b);
myMap.foreach_dart_of_orbit(c, [&] (Dart d) { m_render_topo->setDartColor(d, r, g, b); });
}
void MyQT::traverse2()
......
......@@ -117,7 +117,7 @@ protected:
void cb_mousePress(int button, int x, int y);
template <unsigned int ORBIT>
void colorizeCell(Dart d, float r,float g, float b);
void colorizeCell(Cell<ORBIT> c, float r,float g, float b);
void traverse2();
void dynamicMarkOrbit(unsigned int orb);
......
......@@ -189,11 +189,9 @@ void MyQT::cb_Save()
}
template <unsigned int ORBIT>
void MyQT::colorizeCell(Dart d, float r,float g, float b)
void MyQT::colorizeCell(Cell<ORBIT> c, float r, float g, float b)
{
TraversorDartsOfOrbit<PFP::MAP, ORBIT>doo (myMap, d);
for (Dart e = doo.begin(); e != doo.end(); e = doo.next())
m_render_topo->setDartColor(e, r, g, b);
myMap.foreach_dart_of_orbit(c, [&] (Dart d) { m_render_topo->setDartColor(d, r, g, b); });
}
void MyQT::traverse2()
......
......@@ -115,7 +115,7 @@ protected:
void cb_mousePress(int button, int x, int y);
template <unsigned int ORBIT>
void colorizeCell(Dart d, float r,float g, float b);
void colorizeCell(Cell<ORBIT> c, float r,float g, float b);
void traverse2();
void traverse3();
......
......@@ -37,13 +37,13 @@ namespace Geometry
{
template <typename PFP>
typename PFP::REAL tetrahedronSignedVolume(typename PFP::MAP& map, Dart d, const VertexAttribute<typename PFP::VEC3, typename PFP::MAP::IMPL>& position) ;
typename PFP::REAL tetrahedronSignedVolume(typename PFP::MAP& map, Vol v, const VertexAttribute<typename PFP::VEC3, typename PFP::MAP::IMPL>& position) ;
template <typename PFP>
typename PFP::REAL tetrahedronVolume(typename PFP::MAP& map, Dart d, const VertexAttribute<typename PFP::VEC3, typename PFP::MAP::IMPL>& position) ;
typename PFP::REAL tetrahedronVolume(typename PFP::MAP& map, Vol v, const VertexAttribute<typename PFP::VEC3, typename PFP::MAP::IMPL>& position) ;
template <typename PFP>
typename PFP::REAL convexPolyhedronVolume(typename PFP::MAP& map, Dart d, const VertexAttribute<typename PFP::VEC3, typename PFP::MAP::IMPL>& position, unsigned int thread = 0) ;
typename PFP::REAL convexPolyhedronVolume(typename PFP::MAP& map, Vol v, const VertexAttribute<typename PFP::VEC3, typename PFP::MAP::IMPL>& position, unsigned int thread = 0) ;
template <typename PFP>
typename PFP::REAL totalVolume(typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3, typename PFP::MAP::IMPL>& position, unsigned int thread = 0) ;
......
......@@ -36,85 +36,87 @@ namespace Geometry
{
template <typename PFP>
typename PFP::REAL tetrahedronSignedVolume(typename PFP::MAP& map, Dart d, const VertexAttribute<typename PFP::VEC3, typename PFP::MAP::IMPL>& position)
typename PFP::REAL tetrahedronSignedVolume(typename PFP::MAP& map, Vol v, const VertexAttribute<typename PFP::VEC3, typename PFP::MAP::IMPL>& position)
{
typedef typename PFP::VEC3 VEC3;
VEC3 p1 = position[d] ;
VEC3 p2 = position[map.phi1(d)] ;
VEC3 p3 = position[map.phi_1(d)] ;
VEC3 p4 = position[map.phi_1(map.phi2(d))] ;
VEC3 p1 = position[v.dart] ;
VEC3 p2 = position[map.phi1(v)] ;
VEC3 p3 = position[map.phi_1(v)] ;
VEC3 p4 = position[map.phi_1(map.phi2(v))] ;
return Geom::tetraSignedVolume(p1, p2, p3, p4) ;
}
template <typename PFP>
typename PFP::REAL tetrahedronVolume(typename PFP::MAP& map, Dart d, const VertexAttribute<typename PFP::VEC3, typename PFP::MAP::IMPL>& position)
typename PFP::REAL tetrahedronVolume(typename PFP::MAP& map, Vol v, const VertexAttribute<typename PFP::VEC3, typename PFP::MAP::IMPL>& position)
{
typedef typename PFP::VEC3 VEC3;
VEC3 p1 = position[d] ;
VEC3 p2 = position[map.phi1(d)] ;
VEC3 p3 = position[map.phi_1(d)] ;
VEC3 p4 = position[map.phi_1(map.phi2(d))] ;
VEC3 p1 = position[v.dart] ;
VEC3 p2 = position[map.phi1(v)] ;
VEC3 p3 = position[map.phi_1(v)] ;
VEC3 p4 = position[map.phi_1(map.phi2(v))] ;
return Geom::tetraVolume(p1, p2, p3, p4) ;
}
template <typename PFP>
typename PFP::REAL convexPolyhedronVolume(typename PFP::MAP& map, Dart d, const VertexAttribute<typename PFP::VEC3, typename PFP::MAP::IMPL>& position, unsigned int thread)
typename PFP::REAL convexPolyhedronVolume(typename PFP::MAP& map, Vol v, const VertexAttribute<typename PFP::VEC3, typename PFP::MAP::IMPL>& position, unsigned int thread)
{
typedef typename PFP::MAP MAP;
typedef typename PFP::VEC3 VEC3;
if (Volume::Modelisation::Tetrahedralization::isTetrahedron<PFP>(map,d,thread))
return tetrahedronVolume<PFP>(map,d,position) ;
if (Volume::Modelisation::Tetrahedralization::isTetrahedron<PFP>(map, v, thread))
return tetrahedronVolume<PFP>(map, v, position) ;
else
{
typename PFP::REAL vol = 0 ;
VEC3 vCentroid = Algo::Surface::Geometry::volumeCentroid<PFP>(map, d, position, thread) ;
VEC3 vCentroid = Algo::Surface::Geometry::volumeCentroid<PFP>(map, v, position, thread) ;
DartMarkerStore<MAP> mark(map,thread); // Lock a marker
DartMarkerStore<MAP> mark(map, thread) ; // Lock a marker
std::vector<Dart> visitedFaces ;
std::vector<Face> visitedFaces ;
visitedFaces.reserve(100) ;
visitedFaces.push_back(d) ;
mark.template markOrbit<FACE>(d) ;
Face f(v.dart) ;
visitedFaces.push_back(f) ;
mark.markOrbit(f) ;
for(unsigned int iface = 0; iface != visitedFaces.size(); ++iface)
for(unsigned int iface = 0; iface != visitedFaces.size(); ++iface)
{
Dart e = visitedFaces[iface] ;
if(map.isCycleTriangle(e))
f = visitedFaces[iface] ;
if(map.isCycleTriangle(f))
{
VEC3 p1 = position[e] ;
VEC3 p2 = position[map.phi1(e)] ;
VEC3 p3 = position[map.phi_1(e)] ;
VEC3 p1 = position[f.dart] ;
VEC3 p2 = position[map.phi1(f)] ;
VEC3 p3 = position[map.phi_1(f)] ;
vol += Geom::tetraVolume(p1, p2, p3, vCentroid) ;
}
else
{
VEC3 fCentroid = Algo::Surface::Geometry::faceCentroid<PFP>(map, e, position) ;
Dart f = e ;
VEC3 fCentroid = Algo::Surface::Geometry::faceCentroid<PFP>(map, f, position) ;
Dart d = f.dart ;
do
{
VEC3 p1 = position[f] ;
VEC3 p2 = position[map.phi1(f)] ;
VEC3 p1 = position[d] ;
VEC3 p2 = position[map.phi1(d)] ;
vol += Geom::tetraVolume(p1, p2, fCentroid, vCentroid) ;
f = map.phi1(f) ;
} while(f != e) ;
d = map.phi1(d) ;
} while(d != f.dart) ;
}
Dart currentFace = e;
Dart d = f.dart;
do // add all face neighbours to the table
{
Dart ee = map.phi2(e) ;
if(!mark.isMarked(ee)) // not already marked
Dart dd = map.phi2(d) ;
if(!mark.isMarked(dd)) // not already marked
{
visitedFaces.push_back(ee) ;
mark.template markOrbit<FACE>(ee) ;
Face ff(dd);
visitedFaces.push_back(ff) ;
mark.markOrbit(ff) ;
}
e = map.phi1(e) ;
} while(e != currentFace) ;
d = map.phi1(d) ;
} while(d != f.dart) ;
}
return vol ;
......
......@@ -399,7 +399,7 @@ public:
//@}
template <unsigned int ORBIT>
unsigned int getEmbedding(Dart d) const;
unsigned int getEmbedding(Cell<ORBIT> c) const;
} ;
template <typename T, unsigned int ORBIT>
......
......@@ -579,10 +579,10 @@ inline unsigned int ImplicitHierarchicalMap3::edgeLevel(Dart d)
}
template <unsigned int ORBIT>
inline unsigned int ImplicitHierarchicalMap3::getEmbedding(Dart d) const
inline unsigned int ImplicitHierarchicalMap3::getEmbedding(Cell<ORBIT> c) const
{
unsigned int nbSteps = m_curLevel - vertexInsertionLevel(d);
unsigned int index = EmbeddedMap3::getEmbedding<ORBIT>(d);
unsigned int nbSteps = m_curLevel - vertexInsertionLevel(c.dart);
unsigned int index = EmbeddedMap3::getEmbedding(c);
unsigned int step = 0;
while(step < nbSteps)
......@@ -602,9 +602,9 @@ inline bool ImplicitHierarchicalMap3::isWellEmbedded()
//std::cout << "yeahhh ? " << std::endl;
TraversorV<ImplicitHierarchicalMap3> tv(*this);
for(Dart dv = tv.begin() ; dv != tv.end() ; dv = tv.next())
for(Vertex dv = tv.begin() ; dv.dart != tv.end() ; dv = tv.next())
{
unsigned int curem = this->getEmbedding<VERTEX>(dv);
unsigned int curem = this->getEmbedding(dv);
//std::cout << "current emb = " << curem << std::endl;
unsigned int count = 0;
......
......@@ -470,12 +470,12 @@ Dart splitVertex(typename PFP::MAP& map, std::vector<Dart>& vd)
*************************************************************************************************/
template <typename PFP>
bool isTetrahedron(typename PFP::MAP& map, Dart d, unsigned int thread)
bool isTetrahedron(typename PFP::MAP& map, Vol v, unsigned int thread)
{
unsigned int nbFaces = 0;
//Test the number of faces end its valency
Traversor3WF<typename PFP::MAP> travWF(map, d, false, thread);
Traversor3WF<typename PFP::MAP> travWF(map, v, false, thread);
for(Dart dit = travWF.begin() ; dit != travWF.end(); dit = travWF.next())
{
//increase the number of faces
......@@ -484,7 +484,7 @@ bool isTetrahedron(typename PFP::MAP& map, Dart d, unsigned int thread)
return false;
//test the valency of this face
if(map.faceDegree(dit) != 3)
if(!map.isCycleTriangle(dit))
return false;
}
......
......@@ -45,20 +45,18 @@ public:
} ;
template <typename PFP>
unsigned int vertexLevel(typename PFP::MAP& map, Dart d)
unsigned int vertexLevel(typename PFP::MAP& map, Vertex v)
{
assert(map.getDartLevel(d) <= map.getCurrentLevel() || !"edgeLevel : called with a dart inserted after current level") ;
assert(map.getDartLevel(v.dart) <= map.getCurrentLevel() || !"vertexLevel : called with a dart inserted after current level") ;
unsigned int level = map.getMaxLevel();
TraversorDartsOfOrbit<typename PFP::MAP,VERTEX> tv(map,d);
for(Dart dit = tv.begin() ; dit != tv.end() ; dit = tv.next())
map.foreach_dart_of_orbit(v, [&] (Dart d)
{
unsigned int ldit = map.getDartLevel(dit) ;
unsigned int ldit = map.getDartLevel(d) ;
if(ldit < level)
level = ldit;
}
});
// Dart dit = d;
// do
......
......@@ -38,193 +38,6 @@ namespace Algo
namespace Selection
{
//
//template <typename PFP>
//class FuncFaceInter: public FunctorMap<typename PFP::MAP>
//{
// typedef typename PFP::MAP MAP;
//
//protected:
// std::vector<Dart>& m_faces;
// std::vector<typename PFP::VEC3>& m_Ipoints ;
// const typename PFP::VEC3& m_A;
// const typename PFP::VEC3& m_AB;
// const VertexAttribute<typename PFP::VEC3>& m_positions;
//
//public:
// /**
// * @param map the map
// * @param f vector of selected darts
// * @param A first point of ray
// * @param AB direction of ray
// */
// FuncFaceInter(MAP& map, const VertexAttribute<typename PFP::VEC3>& position, std::vector<Dart>& f, std::vector<typename PFP::VEC3>& ip, const typename PFP::VEC3& A, const typename PFP::VEC3& AB):
// FunctorMap<typename PFP::MAP>(map), m_faces(f), m_Ipoints(ip), m_A(A), m_AB(AB), m_positions(position)
// {}
//
// bool operator()(Dart d)
// {
// const typename PFP::VEC3& Ta = m_positions[d];
//
// Dart dd = this->m_map.phi1(d);
// Dart ddd = this->m_map.phi1(dd);
// bool notfound = true;
// do
// {
// // get back position of triangle Ta,Tb,Tc
// const typename PFP::VEC3& Tb = m_positions[dd];
// const typename PFP::VEC3& Tc = m_positions[ddd];
// typename PFP::VEC3 I;
//// if (Geom::intersectionLineTriangle<typename PFP::VEC3>(m_A, m_AB, Ta, Tb, Tc, I))
// if (Geom::intersectionRayTriangleOpt<typename PFP::VEC3>(m_A, m_AB, Ta, Tb, Tc, I))
// {
// m_faces.push_back(d);
// m_Ipoints.push_back(I);
// notfound = false;
// }
// // next triangle if we are in polygon
// dd = ddd;
// ddd = this->m_map.phi1(dd);
// } while ((ddd != d) && notfound);
// return false;
// }
//};
//
//
//template <typename PFP>
//class FuncEdgeInter: public FunctorMap<typename PFP::MAP>
//{
// typedef typename PFP::MAP MAP;
//
//protected:
// std::vector<Dart>& m_edges;
// const typename PFP::VEC3& m_A;
// const typename PFP::VEC3& m_AB;
// float m_AB2;
// float m_distMax;
// const VertexAttribute<typename PFP::VEC3>& m_positions;
//
//public:
// /**
// * @param map the map
// * @param e vector of selected darts
// * @param A first point of ray
// * @param AB direction of ray
// * @param AB2 squared length of direction
// * @param dm2 max distance from ray squared
// */
// FuncEdgeInter(MAP& map, const VertexAttribute<typename PFP::VEC3>& position, std::vector<Dart>& e, const typename PFP::VEC3& A, const typename PFP::VEC3& AB, typename PFP::REAL AB2, typename PFP::REAL dm2):
// FunctorMap<typename PFP::MAP>(map), m_edges(e), m_A(A), m_AB(AB), m_AB2(AB2), m_distMax(dm2), m_positions(position)
// {}
//
// bool operator()(Dart d)
// {
// // get back position of segment PQ
// const typename PFP::VEC3& P = m_positions[d];
// Dart dd = this->m_map.phi1(d);
// const typename PFP::VEC3& Q = m_positions[dd];
// // the three distance to P, Q and (PQ) not used here
// float dist = Geom::squaredDistanceLine2Seg(m_A, m_AB, m_AB2, P, Q);
//
// if (dist < m_distMax)
// {
// m_edges.push_back(d);
// }
// return false;
// }
//};
//
//
//template <typename PFP>
//class FuncVertexInter: public FunctorMap<typename PFP::MAP>
//{
// typedef typename PFP::MAP MAP;
//
//protected:
// std::vector<Dart>& m_vertices;
// const typename PFP::VEC3& m_A;
// const typename PFP::VEC3& m_AB;
// float m_AB2;
// float m_distMax;
// const VertexAttribute<typename PFP::VEC3>& m_positions;
//public:
// /**
// * @param map the map
// * @param v vector of selected darts
// * @param A first point of ray
// * @param AB direction of ray
// * @param AB2 squared length of direction
// * @param dm2 max distance from ray squared
// */
// FuncVertexInter(MAP& map, const VertexAttribute<typename PFP::VEC3>& position, std::vector<Dart>& v, const typename PFP::VEC3& A, const typename PFP::VEC3& AB, typename PFP::REAL AB2, typename PFP::REAL dm2):
// FunctorMap<typename PFP::MAP>(map), m_vertices(v), m_A(A), m_AB(AB), m_AB2(AB2), m_distMax(dm2), m_positions(position)
// {}
//
// bool operator()(Dart d)
// {
// const typename PFP::VEC3& P = m_positions[d];
// float dist = Geom::squaredDistanceLine2Point(m_A, m_AB, m_AB2, P);
// if (dist < m_distMax)
// {
// m_vertices.push_back(d);
// }
// return false;
// }
//};
/**
* Functor which store the dart that correspond to the subpart of face
* that is intersected
* Must be called in foreachface
*/
template <typename PFP>
class FuncDartMapD2Inter: public FunctorMap<typename PFP::MAP>
{
typedef typename PFP::MAP MAP ;
typedef typename PFP::MAP::IMPL MAP_IMPL ;
typedef typename PFP::VEC3 VEC3 ;
protected:
std::vector<Dart>& m_darts ;
const VEC3& m_A ;
const VEC3& m_AB ;
const VertexAttribute<VEC3, MAP_IMPL>& m_positions;
public:
/**
* @param map the map
* @param f vector of selected darts
* @param A first point of ray
* @param AB direction of ray
*/
FuncDartMapD2Inter(MAP& map, const VertexAttribute<VEC3, MAP_IMPL>& position, std::vector<Dart>& f, const VEC3& A, const VEC3& AB):
FunctorMap<MAP>(map), m_darts(f), m_A(A), m_AB(AB), m_positions(position)
{}
bool operator()(Dart d)
{
typename PFP::VEC3 center = Surface::Geometry::faceCentroid<PFP>(this->m_map, d, m_positions) ;
bool notfound = true ;
Dart face = d ;
do
{
// get back position of triangle
const VEC3& Tb = m_positions[face]; //this->m_map.getVertexEmb(face)->getPosition() ;
const VEC3& Tc = m_positions[this->m_map.phi1(face)]; //this->m_map.getVertexEmb(this->m_map.phi1(face))->getPosition() ;
// typename PFP::VEC3 I;
// if (Geom::intersectionLineTriangle(m_A, m_AB, center, Tb, Tc, I))
if (Geom::intersectionRayTriangleOpt(m_A, m_AB, center, Tb, Tc))
{
m_darts.push_back(face) ;
notfound = false ;
}
face = this->m_map.phi1(face) ;
} while((face != d) && notfound) ;
return false;
}
};
namespace Parallel
{
......@@ -247,7 +60,12 @@ protected:
public:
FuncVertexInter(MAP& map, const VertexAttribute<VEC3, MAP_IMPL>& position, const VEC3& A, const VEC3& AB, REAL AB2, REAL dm2):
FunctorMapThreaded<typename PFP::MAP>(map), m_positions(position), m_A(A), m_AB(AB), m_AB2(AB2), m_distMax(dm2)
FunctorMapThreaded<typename PFP::MAP>(map),
m_positions(position),
m_A(A),
m_AB(AB),
m_AB2(AB2),
m_distMax(dm2)
{}
void run(Dart d, unsigned int thread)
......@@ -262,7 +80,7 @@ public:
}
const std::vector<std::pair<REAL, Dart> >& getVertexDistances() { return m_vd;}
const std::vector<std::pair<REAL, Dart> >& getVertexDistances() { return m_vd; }
};
template <typename PFP>
......@@ -283,7 +101,12 @@ protected:
public:
FuncEdgeInter(MAP& map, const VertexAttribute<VEC3, MAP_IMPL>& position, const VEC3& A, const VEC3& AB, REAL AB2, REAL dm2):
FunctorMapThreaded<typename PFP::MAP>(map), m_positions(position), m_A(A), m_AB(AB), m_AB2(AB2), m_distMax(dm2)
FunctorMapThreaded<typename PFP::MAP>(map),
m_positions(position),
m_A(A),
m_AB(AB),
m_AB2(AB2),
m_distMax(dm2)
{}
void run(Dart d, unsigned int thread)
......@@ -302,7 +125,7 @@ public:
}
}
const std::vector<std::pair<REAL, Dart> >& getEdgeDistances() { return m_ed;}
const std::vector<std::pair<REAL, Dart> >& getEdgeDistances() { return m_ed; }
};
template <typename PFP>
......@@ -321,7 +144,10 @@ protected:
public:
FuncFaceInter(MAP& map, const VertexAttribute<VEC3, MAP_IMPL>& position, const VEC3& A, const VEC3& AB):
FunctorMapThreaded<typename PFP::MAP>(map), m_positions(position), m_A(A), m_AB(AB)
FunctorMapThreaded<typename PFP::MAP>(map),
m_positions(position),
m_A(A),
m_AB(AB)
{}
void run(Dart d, unsigned int thread)
......@@ -349,7 +175,7 @@ public:
} while ((ddd != d) && notfound);
}
const std::vector<std::pair<REAL, Dart> >& getFaceDistances() { return m_fd;}
const std::vector<std::pair<REAL, Dart> >& getFaceDistances() { return m_fd; }
};
} // namespace Parallel
......
......@@ -25,7 +25,6 @@
#ifndef RAYSELECTOR_H_
#define RAYSELECTOR_H_
#include <vector>
#include "Algo/Selection/raySelectFunctor.hpp"
......
......@@ -150,43 +150,43 @@ public:
/**
* mark the cell of dart
*/
inline void mark(Cell<CELL> d)
inline void mark(Cell<CELL> c)
{
assert(m_map.template getMarkerSet<CELL>(m_thread).testMark(m_mark));
assert(m_markVector != NULL);
unsigned int a = m_map.template getEmbedding<CELL>(d) ;
unsigned int a = m_map.getEmbedding(c) ;
if (a == EMBNULL)
a = m_map.template setOrbitEmbeddingOnNewCell<CELL>(d) ;
m_markVector->operator[](a).setMark(m_mark) ;
a = m_map.setOrbitEmbeddingOnNewCell(c) ;
(*m_markVector)[a].setMark(m_mark) ;
}
/**
* unmark the cell of dart
*/
inline void unmark(Cell<CELL> d)
inline void unmark(Cell<CELL> c)
{
assert(m_map.template getMarkerSet<CELL>(m_thread).testMark(m_mark));
assert(m_markVector != NULL);
unsigned int a = m_map.template getEmbedding<CELL>(d) ;
unsigned int a = m_map.getEmbedding(c) ;
if (a == EMBNULL)
a = m_map.template setOrbitEmbeddingOnNewCell<CELL>(d) ;
m_markVector->operator[](a).unsetMark(m_mark) ;