diff --git a/Apps/Examples/viewer.cpp b/Apps/Examples/viewer.cpp index c603cedc75abee69d79f9763666e4d5c375d0449..4616bd3deb027708dec591a71ee54f7690392db7 100644 --- a/Apps/Examples/viewer.cpp +++ b/Apps/Examples/viewer.cpp @@ -272,31 +272,31 @@ void Viewer::cb_keyPress(int keycode) if(!pos2.isValid()) pos2 = myMap.addAttribute("pos2") ; - foreach_cell_EvenOddd(myMap, [&] (Vertex d) - { - pos2[d] = VEC3(0,0,0); - int nb=0; - foreach_adjacent2(myMap,d,[&](Vertex e) - { - pos2[d] += position[e]; - nb++; - }); - pos2[d]/=nb; - }, - [&] (Vertex d) - { - position[d] = VEC3(0,0,0); - int nb=0; - foreach_adjacent2(myMap,d,[&](Vertex e) - { - position[d] += pos2[e]; - nb++; - }); - position[d]/=nb; - }, - 3); - - std::cout << "Even/Odd "<< ch.elapsed()<< " ms "<< std::endl; +// foreach_cell_EvenOddd(myMap, [&] (Vertex d) +// { +// pos2[d] = VEC3(0,0,0); +// int nb=0; +// foreach_adjacent2(myMap,d,[&](Vertex e) +// { +// pos2[d] += position[e]; +// nb++; +// }); +// pos2[d]/=nb; +// }, +// [&] (Vertex d) +// { +// position[d] = VEC3(0,0,0); +// int nb=0; +// foreach_adjacent2(myMap,d,[&](Vertex e) +// { +// position[d] += pos2[e]; +// nb++; +// }); +// position[d]/=nb; +// }, +// 3); + +// std::cout << "Even/Odd "<< ch.elapsed()<< " ms "<< std::endl; Algo::Surface::Geometry::computeNormalVertices(myMap, position, normal) ; m_positionVBO->updateData(position) ; m_normalVBO->updateData(normal) ; @@ -460,22 +460,32 @@ void Viewer::cb_keyPress(int keycode) Utils::Chrono ch; ch.start(); - TraversorCell trav(myMap,true); - TraversorCellEven tr1(trav); - TraversorCellOdd tr2(trav); + for (unsigned int i=0; i<4; ++i) + Algo::Surface::Geometry::Parallel::computeNormalVertices(myMap, position, normal) ; + std::cout << "Algo::Surface::Geometry::Parallel::computeNormalVertices "<< ch.elapsed()<< " ms "<< std::endl; - for(unsigned int i=0; i<5; ++i) - { - for (Cell v = tr1.begin(), e = tr1.end(); v.dart != e.dart; v = tr1.next()) - { - normal[v][0] = 0.0f; - } - for (Cell v = tr2.begin(), e = tr2.end(); v.dart != e.dart; v = tr2.next()) + ch.start(); + for (unsigned int i=0; i<4; ++i) + Parallel::foreach_cell(myMap,[&](Vertex v, unsigned int th) { - normal[v][0] = 0.0f; - } - } - std::cout << "Timing 5 traversors even/odd "<< ch.elapsed()<< " ms "<< std::endl; + normal[v] = Algo::Surface::Geometry::vertexNormal(myMap,v,position); + },4,false,FORCE_CELL_MARKING); + + std::cout << "Parallel::foreach_cell "<< ch.elapsed()<< " ms "<< std::endl; + +// ch.start(); +// Parallel::foreach_cell_EO(myMap,[&](Vertex v, unsigned int thr) +// { +// normal[v] = Algo::Surface::Geometry::vertexNormal(myMap,v,position); +// }, +// [&](Vertex v, unsigned int th) +// { +// normal[v] = Algo::Surface::Geometry::vertexNormal(myMap,v,position); +// },2,4,false,FORCE_CELL_MARKING); + +// std::cout << "Parallel::foreach_cell_EO "<< ch.elapsed()<< " ms "<< std::endl; + + } break; diff --git a/include/Algo/Geometry/area.hpp b/include/Algo/Geometry/area.hpp index 438ec7fd5c0e8a8ca7d3964ae45e79690847ac8e..77ec75e8a9199ed50c78441011760e13010e1174 100644 --- a/include/Algo/Geometry/area.hpp +++ b/include/Algo/Geometry/area.hpp @@ -201,73 +201,49 @@ void computeVoronoiAreaVertices(typename PFP::MAP& map, const VertexAttribute -class FunctorConvexFaceArea: public FunctorMapThreaded -{ - const VertexAttribute& m_position; - FaceAttribute& m_area; -public: - FunctorConvexFaceArea( typename PFP::MAP& map, const VertexAttribute& position, FaceAttribute& area): - FunctorMapThreaded(map), m_position(position), m_area(area) - { } - - void run(Dart d, unsigned int threadID) - { - m_area[d] = convexFaceArea(this->m_map, d, m_position) ; - } -}; - template void computeAreaFaces(typename PFP::MAP& map, const VertexAttribute& position, FaceAttribute& area, unsigned int nbth) { - FunctorConvexFaceArea funct(map,position,area); - Algo::Parallel::foreach_cell(map, funct, nbth, false); +// if (map.isOrbitEmbedded()) +// { +// Parallel::foreach_cell(map,[&](Face f, unsigned int thr) +// { +// area[f] = convexFaceArea(map, f, position) ; +// },nbth,false,FORCE_CELL_MARKING); +// } +// else +// { +// Parallel::foreach_cell(map,[&](Face f, unsigned int thr) +// { +// area[f] = convexFaceArea(map, f, position) ; +// },nbth,false,AUTO); +// } + + // TODO A REMPLACER QUAND PLGTS CHANGES + + CGoGN::Parallel::foreach_cell(map,[&](Face f, unsigned int thr) + { + area[f] = convexFaceArea(map, f, position) ; + },nbth,false,AUTO); } -template -class FunctorVertexOneRingArea: public FunctorMapThreaded -{ - const VertexAttribute& m_position; - VertexAttribute& m_area; -public: - FunctorVertexOneRingArea( typename PFP::MAP& map, const VertexAttribute& position, VertexAttribute& area): - FunctorMapThreaded(map), m_position(position), m_area(area) - { } - - void run(Dart d, unsigned int threadID) - { - m_area[d] = vertexOneRingArea(this->m_map, d, m_position) ; - } -}; template void computeOneRingAreaVertices(typename PFP::MAP& map, const VertexAttribute& position, VertexAttribute& area, unsigned int nbth) { - FunctorConvexFaceArea funct(map,position,area); - Algo::Parallel::foreach_cell(map, funct, nbth, false); -} - -template -class FunctorVertexVoronoiArea: public FunctorMapThreaded -{ - const VertexAttribute& m_position; - VertexAttribute& m_area; -public: - FunctorVertexVoronoiArea( typename PFP::MAP& map, const VertexAttribute& position, VertexAttribute& area): - FunctorMapThreaded(map), m_position(position), m_area(area) - { } - - void run(Dart d, unsigned int threadID) + CGoGN::Parallel::foreach_cell(map,[&](Vertex v, unsigned int thr) { - m_area[d] = vertexVoronoiArea(this->m_map, d, m_position) ; - } -}; + area[v] = vertexOneRingArea(map, v, position) ; + },nbth,false,FORCE_CELL_MARKING); +} template void computeVoronoiAreaVertices(typename PFP::MAP& map, const VertexAttribute& position, VertexAttribute& area, unsigned int nbth) { - FunctorConvexFaceArea funct(map,position,area); - Algo::Parallel::foreach_cell(map, funct, nbth, false); + CGoGN::Parallel::foreach_cell(map,[&](Vertex v, unsigned int thr) + { + area[v] = vertexVoronoiArea(map, v, position) ; + },nbth,false,FORCE_CELL_MARKING); } } // namespace Parallel diff --git a/include/Algo/Geometry/centroid.hpp b/include/Algo/Geometry/centroid.hpp index de903dd3ebeddc78fb93f5c5d340eb10a2c24f4a..baef25b6f636d7fd74ceaf08afeb3c1a463f1141 100644 --- a/include/Algo/Geometry/centroid.hpp +++ b/include/Algo/Geometry/centroid.hpp @@ -169,71 +169,25 @@ void computeNeighborhoodCentroidVertices(typename PFP::MAP& map, const V_ATT& po namespace Parallel { -template -class FunctorComputeCentroidFaces: public FunctorMapThreaded -{ - const V_ATT& m_position; - F_ATT& m_fcentroid; - -public: - FunctorComputeCentroidFaces( typename PFP::MAP& map, const V_ATT& position, F_ATT& fcentroid): - FunctorMapThreaded(map), m_position(position), m_fcentroid(fcentroid) - { } - - void run(Dart d, unsigned int /*threadID*/) - { - m_fcentroid[d] = faceCentroid(this->m_map, d, m_position) ; - } -}; - -template -class FunctorComputeCentroidELWFaces: public FunctorMapThreaded -{ - const V_ATT& m_position; - F_ATT& m_fcentroid; - -public: - FunctorComputeCentroidELWFaces( typename PFP::MAP& map, const V_ATT& position, F_ATT& fcentroid): - FunctorMapThreaded(map), m_position(position), m_fcentroid(fcentroid) - { } - - void run(Dart d, unsigned int threadID) - { - m_fcentroid[d] = faceCentroidELW(this->m_map, d, m_position) ; - } -}; - -template -class FunctorComputeNeighborhoodCentroidVertices: public FunctorMapThreaded -{ - const V_ATT& m_position; - V_ATT& m_vcentroid; - -public: - FunctorComputeNeighborhoodCentroidVertices( typename PFP::MAP& map, const V_ATT& position, V_ATT& vcentroid): - FunctorMapThreaded(map), m_position(position), m_vcentroid(vcentroid) - { } - - void run(Dart d, unsigned int /*threadID*/) - { - m_vcentroid[d] = vertexNeighborhoodCentroid(this->m_map, d, m_position) ; - } -}; - template void computeCentroidFaces(typename PFP::MAP& map, const V_ATT& position, F_ATT& face_centroid, - unsigned int nbth, unsigned int current_thread) + unsigned int nbth) { - FunctorComputeCentroidFaces funct(map,position,face_centroid); - Algo::Parallel::foreach_cell(map, funct, nbth, false, current_thread); + CGoGN::Parallel::foreach_cell(map,[&](Face f, unsigned int thr) + { + face_centroid[f] = faceCentroid(map, f, position) ; + },nbth,false,AUTO); } template void computeCentroidELWFaces(typename PFP::MAP& map, const V_ATT& position, F_ATT& face_centroid, unsigned int nbth, unsigned int current_thread) { - FunctorComputeCentroidELWFaces funct(map,position,face_centroid); - Algo::Parallel::foreach_cell(map, funct, nbth, false, current_thread); + CGoGN::Parallel::foreach_cell(map,[&](Face f, unsigned int thr) + { + face_centroid[f] = faceCentroidELW(map, f, position) ; + },nbth,false,AUTO); + } template @@ -241,8 +195,10 @@ void computeNeighborhoodCentroidVertices(typename PFP::MAP& map, const V_ATT& position, V_ATT& vertex_centroid, unsigned int nbth, unsigned int current_thread) { - FunctorComputeNeighborhoodCentroidVertices funct(map,position,vertex_centroid); - Algo::Parallel::foreach_cell(map, funct, nbth, false); + CGoGN::Parallel::foreach_cell(map,[&](Vertex v, unsigned int thr) + { + vertex_centroid[v] = vertexNeighborhoodCentroid(map, v, position) ; + },nbth,false,FORCE_CELL_MARKING); } } // namespace Parallel @@ -308,79 +264,35 @@ void computeNeighborhoodCentroidVertices(typename PFP::MAP& map, const V_ATT& po namespace Parallel { -template -class FunctorComputeCentroidVolumes: public FunctorMapThreaded -{ - const V_ATT& m_position; - W_ATT& m_vol_centroid; - -public: - FunctorComputeCentroidVolumes( typename PFP::MAP& map, const V_ATT& position, W_ATT& vol_centroid): - FunctorMapThreaded(map), m_position(position), m_vol_centroid(vol_centroid) - { } - - void run(Dart d, unsigned int threadID) - { - m_vol_centroid[d] = Surface::Geometry::volumeCentroid(this->m_map, d, m_position,threadID) ; - } -}; - template void computeCentroidVolumes(typename PFP::MAP& map, const V_ATT& position, W_ATT& vol_centroid, unsigned int nbth) { - FunctorComputeCentroidVolumes funct(map,position,vol_centroid); - Algo::Parallel::foreach_cell(map, funct, nbth, true); -} - -template -class FunctorComputeCentroidELWVolumes: public FunctorMapThreaded -{ - const V_ATT& m_position; - W_ATT& m_vol_centroid; - -public: - FunctorComputeCentroidELWVolumes( typename PFP::MAP& map, const V_ATT& position, W_ATT& vol_centroid): - FunctorMapThreaded(map), m_position(position), m_vol_centroid(vol_centroid) - { } - - void run(Dart d, unsigned int threadID) + CGoGN::Parallel::foreach_cell(map,[&](Vol v, unsigned int thr) { - m_vol_centroid[d] = Surface::Geometry::volumeCentroidELW(this->m_map, d, m_position, threadID) ; - } -}; + vol_centroid[v] = Surface::Geometry::volumeCentroid(map, v, position, thr) ; + },nbth,true,AUTO); +} template void computeCentroidELWVolumes(typename PFP::MAP& map, const V_ATT& position, W_ATT& vol_centroid, unsigned int nbth) { - FunctorComputeCentroidELWVolumes funct(map,position,vol_centroid); - Algo::Parallel::foreach_cell(map, funct, nbth, true); + CGoGN::Parallel::foreach_cell(map,[&](Vol v, unsigned int thr) + { + vol_centroid[v] = Surface::Geometry::volumeCentroidELW(map, v, position, thr) ; + },nbth,true,AUTO); } -template -class FunctorComputeNeighborhoodCentroidVertices: public FunctorMapThreaded -{ - const V_ATT& m_position; - V_ATT& m_vcentroid; - -public: - FunctorComputeNeighborhoodCentroidVertices( typename PFP::MAP& map, const V_ATT& position, V_ATT& vcentroid): - FunctorMapThreaded(map), m_position(position), m_vcentroid(vcentroid) - { } - - void run(Dart d, unsigned int /*threadID*/) - { - m_vcentroid[d] = vertexNeighborhoodCentroid(this->m_map, d, m_position) ; - } -}; template void computeNeighborhoodCentroidVertices(typename PFP::MAP& map, const V_ATT& position, V_ATT& vertex_centroid, unsigned int nbth) { - FunctorComputeNeighborhoodCentroidVertices funct(map,position,vertex_centroid); - Algo::Parallel::foreach_cell(map, funct, nbth, false); + CGoGN::Parallel::foreach_cell(map,[&](Vertex v, unsigned int thr) + { + vertex_centroid[v] = Volume::Geometry::vertexNeighborhoodCentroid(map, v, position,thr) ; + },nbth,true,FORCE_CELL_MARKING); } } // namespace Parallel diff --git a/include/Algo/Geometry/curvature.hpp b/include/Algo/Geometry/curvature.hpp index 7a2c3541cb0f1a12a516a8dbfd8f414264c58b0c..64f5c1edd0d5cc006c67f8a71aaabacea1843fba 100644 --- a/include/Algo/Geometry/curvature.hpp +++ b/include/Algo/Geometry/curvature.hpp @@ -602,54 +602,6 @@ void normalCycles_ProjectTensor(Geom::Matrix<3,3,typename PFP::REAL>& tensor, co namespace Parallel { - -template -class FunctorComputeCurvatureVertices_NormalCycles: public FunctorMapThreaded -{ - typedef typename PFP::MAP MAP ; - typedef typename PFP::MAP::IMPL MAP_IMPL ; - typedef typename PFP::VEC3 VEC3 ; - typedef typename PFP::REAL REAL ; - - REAL m_radius; - const VertexAttribute& m_position; - const VertexAttribute& m_normal; - const EdgeAttribute& m_edgeangle; - VertexAttribute& m_kmax; - VertexAttribute& m_kmin; - VertexAttribute& m_Kmax; - VertexAttribute& m_Kmin; - VertexAttribute& m_Knormal; -public: - FunctorComputeCurvatureVertices_NormalCycles( - MAP& map, - REAL radius, - const VertexAttribute& position, - const VertexAttribute& normal, - const EdgeAttribute& edgeangle, - VertexAttribute& kmax, - VertexAttribute& kmin, - VertexAttribute& Kmax, - VertexAttribute& Kmin, - VertexAttribute& Knormal): - FunctorMapThreaded(map), - m_radius(radius), - m_position(position), - m_normal(normal), - m_edgeangle(edgeangle), - m_kmax(kmax), - m_kmin(kmin), - m_Kmax(Kmax), - m_Kmin(Kmin), - m_Knormal(Knormal) - { } - - void run(Dart d, unsigned int threadID) - { - computeCurvatureVertex_NormalCycles(this->m_map, d, m_radius, m_position, m_normal, m_edgeangle, m_kmax, m_kmin, m_Kmax, m_Kmin, m_Knormal, threadID) ; - } -}; - template void computeCurvatureVertices_NormalCycles( typename PFP::MAP& map, @@ -681,50 +633,13 @@ void computeCurvatureVertices_NormalCycles( map.template initAllOrbitsEmbedding(); } - FunctorComputeCurvatureVertices_NormalCycles funct(map, radius, position, normal, edgeangle, kmax, kmin, Kmax, Kmin, Knormal); - Algo::Parallel::foreach_cell(map, funct, nbth, true); + Parallel::foreach_cell(map,[&](Vertex v, unsigned int threadID) + { + computeCurvatureVertex_NormalCycles(map, v, radius, position, normal, edgeangle, kmax, kmin, Kmax, Kmin, Knormal, threadID) ; + },nbth,true,FORCE_CELL_MARKING); } - -template -class FunctorComputeCurvatureVertices_QuadraticFitting: public FunctorMapThreaded -{ - typedef typename PFP::MAP MAP ; - typedef typename PFP::MAP::IMPL MAP_IMPL ; - typedef typename PFP::VEC3 VEC3 ; - typedef typename PFP::REAL REAL ; - - const VertexAttribute& m_position; - const VertexAttribute& m_normal; - VertexAttribute& m_kmax; - VertexAttribute& m_kmin; - VertexAttribute& m_Kmax; - VertexAttribute& m_Kmin; -public: - FunctorComputeCurvatureVertices_QuadraticFitting( - MAP& map, - const VertexAttribute& position, - const VertexAttribute& normal, - VertexAttribute& kmax, - VertexAttribute& kmin, - VertexAttribute& Kmax, - VertexAttribute& Kmin): - FunctorMapThreaded(map), - m_position(position), - m_normal(normal), - m_kmax(kmax), - m_kmin(kmin), - m_Kmax(Kmax), - m_Kmin(Kmin) - { } - - void run(Dart d, unsigned int threadID) - { - computeCurvatureVertex_QuadraticFitting(this->m_map, d, m_position, m_normal, m_kmax, m_kmin, m_Kmax, m_Kmin) ; - } -}; - template void computeCurvatureVertices_QuadraticFitting( typename PFP::MAP& map, @@ -736,8 +651,11 @@ void computeCurvatureVertices_QuadraticFitting( VertexAttribute& Kmin, unsigned int nbth) { - FunctorComputeCurvatureVertices_QuadraticFitting funct(map, position, normal, kmax, kmin, Kmax, Kmin); - Algo::Parallel::foreach_cell(map, funct, nbth, true); + Parallel::foreach_cell(map,[&](Vertex v, unsigned int threadID) + { + computeCurvatureVertex_QuadraticFitting(map, v, position, normal, kmax, kmin, Kmax, Kmin, threadID) ; + },nbth,true,FORCE_CELL_MARKING); + } } // namespace Parallel diff --git a/include/Algo/Geometry/normal.hpp b/include/Algo/Geometry/normal.hpp index 2801d6c076158629b6509796dfe184a75956bec3..e699b76baaa23a1ca5d39d874f9b5ba0f95471aa 100644 --- a/include/Algo/Geometry/normal.hpp +++ b/include/Algo/Geometry/normal.hpp @@ -163,84 +163,6 @@ void computeNormalVertices(typename PFP::MAP& map, const V_ATT& position, V_ATT& } - -namespace Parallel -{ - -template -class FunctorComputeNormalVertices : public FunctorMapThreaded -{ - const V_ATT& m_position; - V_ATT& m_normal; -public: - FunctorComputeNormalVertices(typename PFP::MAP& map, const V_ATT& position, V_ATT& normal): - FunctorMapThreaded(map), m_position(position), m_normal(normal) - { } - - void run(Dart d, unsigned int /*threadID*/) - { - m_normal[d] = vertexNormal(this->m_map, d, m_position) ; - } -}; - -template -void computeNormalVertices(typename PFP::MAP& map, const V_ATT& position, V_ATT& normal, unsigned int nbth) -{ - FunctorComputeNormalVertices funct(map, position, normal); - Algo::Parallel::foreach_cell(map, funct, nbth, false); -} - -template -class FunctorComputeNormalFaces : public FunctorMapThreaded -{ - const V_ATT& m_position; - F_ATT& m_normal; -public: - FunctorComputeNormalFaces(typename PFP::MAP& map, const V_ATT& position, F_ATT& normal): - FunctorMapThreaded(map), m_position(position), m_normal(normal) - { } - - void run(Dart d, unsigned int /*threadID*/) - { - m_normal[d] = faceNormal(this->m_map, d, m_position) ; - } -}; - -template -void computeNormalFaces(typename PFP::MAP& map, const V_ATT& position, F_ATT& normal, unsigned int nbth) -{ - FunctorComputeNormalFaces funct(map, position, normal); - Algo::Parallel::foreach_cell(map, funct, nbth, false); -} - -template -class FunctorComputeAngleBetweenNormalsOnEdge: public FunctorMapThreaded -{ - const V_ATT& m_position; - E_ATT& m_angles; - -public: - FunctorComputeAngleBetweenNormalsOnEdge( typename PFP::MAP& map, const V_ATT& position, E_ATT& angles): - FunctorMapThreaded(map), m_position(position), m_angles(angles) - { } - - void run(Dart d, unsigned int threadID) - { - m_angles[d] = computeAngleBetweenNormalsOnEdge(this->m_map, d, m_position) ; - } -}; - -template -void computeAnglesBetweenNormalsOnEdges(typename PFP::MAP& map, const V_ATT& position, E_ATT& angles, unsigned int nbth) -{ - FunctorComputeAngleBetweenNormalsOnEdge funct(map,position,angles); - Algo::Parallel::foreach_cell(map, funct, nbth, false); -} - -} // namespace Parallel - - - template typename PFP::REAL computeAngleBetweenNormalsOnEdge(typename PFP::MAP& map, Edge e, const V_ATT& position) { @@ -284,6 +206,42 @@ void computeAnglesBetweenNormalsOnEdges(typename PFP::MAP& map, const V_ATT& pos false, thread); } + + +namespace Parallel +{ + +template +void computeNormalVertices(typename PFP::MAP& map, const V_ATT& position, V_ATT& normal, unsigned int nbth) +{ + CGoGN::Parallel::foreach_cell(map,[&](Vertex v, unsigned int thr) + { + normal[v] = vertexNormal(map, v, position) ; + },nbth,true,FORCE_CELL_MARKING); +} + +template +void computeNormalFaces(typename PFP::MAP& map, const V_ATT& position, F_ATT& normal, unsigned int nbth) +{ + CGoGN::Parallel::foreach_cell(map,[&](Face f, unsigned int thr) + { + normal[f] = faceNormal(map, f, position) ; + },nbth,true,AUTO); +} + + +template +void computeAnglesBetweenNormalsOnEdges(typename PFP::MAP& map, const V_ATT& position, E_ATT& angles, unsigned int nbth) +{ + CGoGN::Parallel::foreach_cell(map,[&](Edge e, unsigned int thr) + { + angles[e] = computeAngleBetweenNormalsOnEdge(map, e, position) ; + },nbth,true,AUTO); +} + +} // namespace Parallel + + } // namespace Geometry } // namespace Surface diff --git a/include/Algo/Geometry/volume.hpp b/include/Algo/Geometry/volume.hpp index d8f61618c89b538bb2559e83521fd26eebb393a3..f357000a95a95e9ca4935b383ba6096c44ce9414 100644 --- a/include/Algo/Geometry/volume.hpp +++ b/include/Algo/Geometry/volume.hpp @@ -138,50 +138,29 @@ typename PFP::REAL totalVolume(typename PFP::MAP& map, const VertexAttribute -class FunctorTotalVolume: public FunctorMapThreaded -{ - const VertexAttribute& m_position; - double m_vol; - -public: - FunctorTotalVolume( typename PFP::MAP& map, const VertexAttribute& position): - FunctorMapThreaded(map), m_position(position), m_vol(0.0) - { } - - void run(Dart d, unsigned int threadID) - { - m_vol += convexPolyhedronVolume(this->m_map, d, m_position, threadID) ; - } - - double getVol() const - { - return m_vol; - } -}; - template typename PFP::REAL totalVolume(typename PFP::MAP& map, const VertexAttribute& position, unsigned int nbth) { + // get number of thread of processor if needed if (nbth == 0) - nbth = Algo::Parallel::optimalNbThreads(); + nbth = boost::thread::hardware_concurrency(); - std::vector*> functs; - for (unsigned int i = 0; i < nbth; ++i) - { - functs.push_back(new FunctorTotalVolume(map,position)); - } + // allocate a vector of 1 accumulator for each thread + std::vector vols(nbth,0.0); - double total = 0.0; + // foreach volume + CGoGN::Parallel::foreach_cell(map,[&](Vol v, unsigned int thr) + { + // add volume to the thread accumulator + vols[thr-1] += convexPolyhedronVolume(map, v, position, thr) ; + },nbth); - Algo::Parallel::foreach_cell(map, functs, true); + // compute the sum of volumes + typename PFP::REAL total(0); + for (unsigned int i=0; i< nbth; ++i ) + total += vols[i]; - for (unsigned int i=0; i < nbth; ++i) - { - total += reinterpret_cast*>(functs[i])->getVol(); - delete functs[i]; - } - return typename PFP::REAL(total); + return total; } } // namespace Parallel diff --git a/include/Topology/generic/traversor/traversorCell.h b/include/Topology/generic/traversor/traversorCell.h index bdc5785f24e8475abef3782759087da0e353ddba..76ba3cf23b7f8976053a16223642d16b88004fba 100644 --- a/include/Topology/generic/traversor/traversorCell.h +++ b/include/Topology/generic/traversor/traversorCell.h @@ -115,161 +115,22 @@ public: * Executes function f on each ORBIT */ template -inline void foreach_cell(const MAP& map, FUNC f, TraversalOptim opt = AUTO, unsigned int thread = 0) -{ - switch(opt) - { - case FORCE_DART_MARKING: - { - TraversorCell trav(map, false, thread); - for (Cell c = trav.begin(), e = trav.end(); c.dart != e.dart; c = trav.next()) - f(c); - } - break; - case FORCE_CELL_MARKING: - { - TraversorCell trav(map, false, thread); - for (Cell c = trav.begin(), e = trav.end(); c.dart != e.dart; c = trav.next()) - f(c); - } - break; - case FORCE_QUICK_TRAVERSAL: - { - TraversorCell trav(map, false, thread); - for (Cell c = trav.begin(), e = trav.end(); c.dart != e.dart; c = trav.next()) - f(c); - } - break; - case AUTO: - default: - { - TraversorCell trav(map, false, thread); - for (Cell c = trav.begin(), e = trav.end(); c.dart != e.dart; c = trav.next()) - f(c); - } - break; - - } -} +inline void foreach_cell(const MAP& map, FUNC f, TraversalOptim opt = AUTO, unsigned int thread = 0); + /* * Executes function f on each ORBIT until f returns false */ template -inline void foreach_cell_until(const MAP& map, FUNC f, TraversalOptim opt = AUTO, unsigned int thread = 0) -{ - switch(opt) - { - case FORCE_DART_MARKING: - { - TraversorCell trav(map, false, thread); - for (Cell c = trav.begin(), e = trav.end(); c.dart != e.dart; c = trav.next()) - if (!f(c)) - break; - } - break; - case FORCE_CELL_MARKING: - { - TraversorCell trav(map, false, thread); - for (Cell c = trav.begin(), e = trav.end(); c.dart != e.dart; c = trav.next()) - if (!f(c)) - break; - } - break; - case FORCE_QUICK_TRAVERSAL: - { - TraversorCell trav(map, false, thread); - for (Cell c = trav.begin(), e = trav.end(); c.dart != e.dart; c = trav.next()) - if (!f(c)) - break; - } - break; - case AUTO: - default: - { - TraversorCell trav(map, false, thread); - for (Cell c = trav.begin(), e = trav.end(); c.dart != e.dart; c = trav.next()) - if (!f(c)) - break; - } - break; - } -} +inline void foreach_cell_until(const MAP& map, FUNC f, TraversalOptim opt = AUTO, unsigned int thread = 0); /* * Executes function f on each ORBIT, then * execute function g on each ORBIT * Optimization on marking (even pass marking, odd pass unmarking) */ -template -inline void foreach_cell_EvenOddd(const MAP& map, FUNC f, FUNC2 g, unsigned int nbpasses=1, TraversalOptim opt = AUTO, unsigned int thread = 0) -{ - switch(opt) - { - case FORCE_DART_MARKING: - { - TraversorCell trav(map, false, thread); - TraversorCellEven tr1(trav); - TraversorCellOdd tr2(trav); - - for (unsigned int i=0; i c = trav.begin(), e = trav.end(); c.dart != e.dart; c = trav.next()) - f(c); - for (Cell c = trav.begin(), e = trav.end(); c.dart != e.dart; c = trav.next()) - g(c); - } - } - break; - case FORCE_CELL_MARKING: - { - TraversorCell trav(map, false, thread); - TraversorCellEven tr1(trav); - TraversorCellOdd tr2(trav); - - for (unsigned int i=0; i c = trav.begin(), e = trav.end(); c.dart != e.dart; c = trav.next()) - f(c); - for (Cell c = trav.begin(), e = trav.end(); c.dart != e.dart; c = trav.next()) - g(c); - } - } - break; - case FORCE_QUICK_TRAVERSAL: - { - TraversorCell trav(map, false, thread); - TraversorCellEven tr1(trav); - TraversorCellOdd tr2(trav); - - for (unsigned int i=0; i c = trav.begin(), e = trav.end(); c.dart != e.dart; c = trav.next()) - f(c); - for (Cell c = trav.begin(), e = trav.end(); c.dart != e.dart; c = trav.next()) - g(c); - } - } - break; - case AUTO: - default: - { - TraversorCell trav(map, false, thread); - TraversorCellEven tr1(trav); - TraversorCellOdd tr2(trav); - - for (unsigned int i=0; i c = trav.begin(), e = trav.end(); c.dart != e.dart; c = trav.next()) - f(c); - for (Cell c = trav.begin(), e = trav.end(); c.dart != e.dart; c = trav.next()) - g(c); - } - } - break; - } -} - +//template +//void foreach_cell_EvenOddd(const MAP& map, FUNC f, FUNC2 g, unsigned int nbpasses=1, TraversalOptim opt = AUTO, unsigned int thread = 0); namespace Parallel @@ -278,37 +139,37 @@ template void foreach_cell(MAP& map, FUNC func, unsigned int nbth=0, bool needMarkers=true, TraversalOptim opt=AUTO); //template -//void foreach_cell_EO(MAP& map, FUNC_E funcEven, FUNC_O funcOdd,unsigned int nbth=0, bool needMarkers=true, TraversalOptim opt = AUTO); - +//void foreach_cell_EO(MAP& map, FUNC_E funcEven, FUNC_O funcOdd, unsigned int nbPasses=1, unsigned int nbth=0, bool needMarkers=true, TraversalOptim opt = AUTO); } -template -class TraversorV : public TraversorCell + +template +class TraversorV : public TraversorCell { public: TraversorV(const MAP& m, unsigned int thread = 0) : TraversorCell(m, false, thread) {} }; -template -class TraversorE : public TraversorCell +template +class TraversorE : public TraversorCell { public: TraversorE(const MAP& m, unsigned int thread = 0) : TraversorCell(m, false, thread) {} }; -template -class TraversorF : public TraversorCell +template +class TraversorF : public TraversorCell { public: TraversorF(const MAP& m, unsigned int thread = 0) : TraversorCell(m, false, thread) {} }; -template -class TraversorW : public TraversorCell +template +class TraversorW : public TraversorCell { public: TraversorW(const MAP& m, unsigned int thread = 0) : TraversorCell(m, false, thread) @@ -317,7 +178,6 @@ public: - } // namespace CGoGN #include "Topology/generic/traversor/traversorCell.hpp" diff --git a/include/Topology/generic/traversor/traversorCell.hpp b/include/Topology/generic/traversor/traversorCell.hpp index b150319dca3d26e1942394bda93c017fe49af85f..546b55a42a550c4bd1a0868737ee2334927a32f7 100644 --- a/include/Topology/generic/traversor/traversorCell.hpp +++ b/include/Topology/generic/traversor/traversorCell.hpp @@ -74,9 +74,8 @@ TraversorCell::TraversorCell(const MAP& map, bool forceDartMarke template TraversorCell::TraversorCell(const TraversorCell& tc) : - m(tc.m), dmark(tc.dmark), cmark(tc.cmark), - quickTraversal(tc.quickTraversal), current(tc.current), firstTraversal(tc.firstTraversal), - dimension(tc.dimension) + m(tc.m), dimension(tc.dimension), cont( tc.cont), qCurrent(tc.qCurrent), dmark(tc.dmark), cmark(tc.cmark), + quickTraversal(tc.quickTraversal), current(tc.current), firstTraversal(tc.firstTraversal) { } @@ -464,6 +463,159 @@ Cell TraversorCellOdd::next() +template +inline void foreach_cell(const MAP& map, FUNC f, TraversalOptim opt, unsigned int thread) +{ + switch(opt) + { + case FORCE_DART_MARKING: + { + TraversorCell trav(map, false, thread); + for (Cell c = trav.begin(), e = trav.end(); c.dart != e.dart; c = trav.next()) + f(c); + } + break; + case FORCE_CELL_MARKING: + { + TraversorCell trav(map, false, thread); + for (Cell c = trav.begin(), e = trav.end(); c.dart != e.dart; c = trav.next()) + f(c); + } + break; + case FORCE_QUICK_TRAVERSAL: + { + TraversorCell trav(map, false, thread); + for (Cell c = trav.begin(), e = trav.end(); c.dart != e.dart; c = trav.next()) + f(c); + } + break; + case AUTO: + default: + { + TraversorCell trav(map, false, thread); + for (Cell c = trav.begin(), e = trav.end(); c.dart != e.dart; c = trav.next()) + f(c); + } + break; + + } +} + +template +inline void foreach_cell_until(const MAP& map, FUNC f, TraversalOptim opt, unsigned int thread) +{ + switch(opt) + { + case FORCE_DART_MARKING: + { + TraversorCell trav(map, false, thread); + for (Cell c = trav.begin(), e = trav.end(); c.dart != e.dart; c = trav.next()) + if (!f(c)) + break; + } + break; + case FORCE_CELL_MARKING: + { + TraversorCell trav(map, false, thread); + for (Cell c = trav.begin(), e = trav.end(); c.dart != e.dart; c = trav.next()) + if (!f(c)) + break; + } + break; + case FORCE_QUICK_TRAVERSAL: + { + TraversorCell trav(map, false, thread); + for (Cell c = trav.begin(), e = trav.end(); c.dart != e.dart; c = trav.next()) + if (!f(c)) + break; + } + break; + case AUTO: + default: + { + TraversorCell trav(map, false, thread); + for (Cell c = trav.begin(), e = trav.end(); c.dart != e.dart; c = trav.next()) + if (!f(c)) + break; + } + break; + } +} + + +//template +//inline void foreach_cell_EvenOdd(const MAP& map, FUNC f, FUNC2 g, unsigned int nbpasses, TraversalOptim opt, unsigned int thread) +//{ +// switch(opt) +// { +// case FORCE_DART_MARKING: +// { +// TraversorCell trav(map, false, thread); +// TraversorCellEven tr1(trav); +// TraversorCellOdd tr2(trav); + +// for (unsigned int i=0; i c = trav.begin(), e = trav.end(); c.dart != e.dart; c = trav.next()) +// f(c); +// for (Cell c = trav.begin(), e = trav.end(); c.dart != e.dart; c = trav.next()) +// g(c); +// } +// } +// break; +// case FORCE_CELL_MARKING: +// { +// TraversorCell trav(map, false, thread); +// TraversorCellEven tr1(trav); +// TraversorCellOdd tr2(trav); + +// for (unsigned int i=0; i c = trav.begin(), e = trav.end(); c.dart != e.dart; c = trav.next()) +// f(c); +// for (Cell c = trav.begin(), e = trav.end(); c.dart != e.dart; c = trav.next()) +// g(c); +// } +// } +// break; +// case FORCE_QUICK_TRAVERSAL: +// { +// TraversorCell trav(map, false, thread); +// TraversorCellEven tr1(trav); +// TraversorCellOdd tr2(trav); + +// for (unsigned int i=0; i c = trav.begin(), e = trav.end(); c.dart != e.dart; c = trav.next()) +// f(c); +// for (Cell c = trav.begin(), e = trav.end(); c.dart != e.dart; c = trav.next()) +// g(c); +// } +// } +// break; +// case AUTO: +// default: +// { +// TraversorCell trav(map, false, thread); +// TraversorCellEven tr1(trav); +// TraversorCellOdd tr2(trav); + +// for (unsigned int i=0; i c = trav.begin(), e = trav.end(); c.dart != e.dart; c = trav.next()) +// f(c); +// for (Cell c = trav.begin(), e = trav.end(); c.dart != e.dart; c = trav.next()) +// g(c); +// } +// } +// break; +// } +//} + + + + + namespace Parallel { @@ -494,6 +646,7 @@ public: { for (typename std::vector::const_iterator it = m_cells.begin(); it != m_cells.end(); ++it) m_lambda(*it,m_id); + m_cells.clear(); m_sync1.wait(); // wait every body has finished m_sync2.wait(); // wait vectors has been refilled } @@ -584,6 +737,129 @@ void foreach_cell_tmpl(MAP& map, FUNC func, unsigned int nbth, bool needMarkers) delete[] tempo; } + +//template +//void foreach_cell_EO_tmpl(MAP& map, FUNC_E funcEven, FUNC_O funcOdd, unsigned int nbPasses, unsigned int nbth, bool needMarkers=true) +//{ +// if (nbth==0) +// nbth = boost::thread::hardware_concurrency(); + +// std::vector< Cell >* vd = new std::vector< Cell >[nbth]; + +// for (unsigned int i = 0; i < nbth; ++i) +// vd[i].reserve(SIZE_BUFFER_THREAD); + +// bool finished_even=false; +// bool finished_odd=false; +// // lauch threads +// if (needMarkers) +// { +// unsigned int nbth_prec = map.getNbThreadMarkers(); +// if (nbth_prec < nbth+1) +// map.addThreadMarker(nbth+1-nbth_prec); +// } + +// boost::thread** threads = new boost::thread*[2*nbth]; +// ThreadFunction** tfse = new ThreadFunction*[nbth]; +// ThreadFunction** tfso = new ThreadFunction*[nbth]; + +// boost::barrier sync1(nbth+1); +// boost::barrier sync2(nbth+1); +// boost::barrier sync3(nbth+1); +// boost::barrier sync4(nbth+1); + +// for (unsigned int i = 0; i < nbth; ++i) +// { +// tfse[i] = new ThreadFunction(funcEven, vd[i],sync1,sync2, finished_even,1+i); +// threads[i] = new boost::thread( boost::ref( *(tfse[i]) ) ); + +// tfso[i] = new ThreadFunction(funcOdd, vd[i],sync3,sync4, finished_odd,1+i); +// threads[nbth+i] = new boost::thread( boost::ref( *(tfso[i]) ) ); +// } + +// // and continue to traverse the map +// std::vector< Cell >* tempo = new std::vector< Cell >[nbth]; +// for (unsigned int i = 0; i < nbth; ++i) +// tempo[i].reserve(SIZE_BUFFER_THREAD); + +// TraversorCell trav(map); + +// for (unsigned i=0; i cell = trav.begin(); +// Cell c_end = trav.end(); +// while (cell.dart != c_end.dart) +// { +// for (unsigned int i = 0; i < nbth; ++i) +// tempo[i].clear(); + +// unsigned int nb = 0; +// while ((cell.dart != c_end.dart) && (nb < nbth*SIZE_BUFFER_THREAD) ) +// { +// tempo[nb%nbth].push_back(cell); +// nb++; +// cell = trav.next(); +// } +// sync1.wait();// wait for all thread to finish its vector +// for (unsigned int i = 0; i < nbth; ++i) +// vd[i].swap(tempo[i]); +// sync2.wait();// everybody refilled then go +// } +// sync1.wait();// wait for all thread to finish its vector +// sync2.wait(); // just wait for last barrier wait ! + +// cell = trav.begin(); +// c_end = trav.end(); +// while (cell.dart != c_end.dart) +// { +// for (unsigned int i = 0; i < nbth; ++i) +// tempo[i].clear(); +// unsigned int nb = 0; + +// while ((cell.dart != c_end.dart) && (nb < nbth*SIZE_BUFFER_THREAD) ) +// { +// tempo[nb%nbth].push_back(cell); +// nb++; +// cell = trav.next(); +// } +// sync3.wait();// wait for all thread to finish its vector +// for (unsigned int i = 0; i < nbth; ++i) +// vd[i].swap(tempo[i]); +// sync4.wait();// everybody refilled then go +// } +// sync3.wait();// wait for all thread to finish its vector +// sync4.wait(); // just wait for last barrier wait ! +// } + +// sync1.wait();// wait for all thread to finish its vector +// finished_even = true;// say finsih to everyone +// sync2.wait(); // just wait for last barrier wait ! +// sync3.wait();// wait for all thread to finish its vector +// finished_odd = true;// say finsih to everyone +// sync4.wait(); // just wait for last barrier wait ! + +// //wait for all theads to be finished +// for (unsigned int i = 0; i < nbth; ++i) +// { +// threads[i]->join(); +// delete threads[i]; +// delete tfse[i]; +// threads[i+nbth]->join(); +// delete threads[i+nbth]; +// delete tfso[i]; +// } + +// delete[] tfse; +// delete[] tfso; +// delete[] threads; +// delete[] vd; +// delete[] tempo; +//} + + + + + template void foreach_cell(MAP& map, FUNC func, unsigned int nbth, bool needMarkers, TraversalOptim opt) { @@ -602,11 +878,33 @@ void foreach_cell(MAP& map, FUNC func, unsigned int nbth, bool needMarkers, Trav default: foreach_cell_tmpl(map,func,nbth,needMarkers); break; - } - } + +//template +//void foreach_cell_EO(MAP& map, FUNC_E funcEven, FUNC_O funcOdd, unsigned int nbPasses, unsigned int nbth, bool needMarkers, TraversalOptim opt) +//{ +// switch(opt) +// { +// case FORCE_DART_MARKING: +// foreach_cell_EO_tmpl(map,funcEven,funcOdd,nbPasses,nbth,needMarkers); +// break; +// case FORCE_CELL_MARKING: +// foreach_cell_EO_tmpl(map,funcEven,funcOdd,nbPasses,nbth,needMarkers); +// break; +// case FORCE_QUICK_TRAVERSAL: +// foreach_cell_EO_tmpl(map,funcEven,funcOdd,nbPasses,nbth,needMarkers); +// break; +// case AUTO: +// default: +// foreach_cell_EO_tmpl(map,funcEven,funcOdd,nbPasses,nbth,needMarkers); +// break; +// } +//} + + + }// namespace Parallel