diff --git a/include/Algo/Geometry/centroid.h b/include/Algo/Geometry/centroid.h index 74d8c8014058ae25b8f365b560c2c3a4c434d541..78538a6e0951c016a54a88526d10ac95a3afe9e7 100644 --- a/include/Algo/Geometry/centroid.h +++ b/include/Algo/Geometry/centroid.h @@ -49,7 +49,7 @@ namespace Geometry * @param attributs the vector of attribute or cell */ template -EMB volumeCentroidGen(typename PFP::MAP& map, Dart d, const EMBV& attributs); +EMB volumeCentroidGen(typename PFP::MAP& map, Dart d, const EMBV& attributs, unsigned int thread = 0); /** * Compute volume centroid @@ -59,9 +59,9 @@ EMB volumeCentroidGen(typename PFP::MAP& map, Dart d, const EMBV& attributs); * @param position the vector of attribute */ template -typename PFP::VEC3 volumeCentroid(typename PFP::MAP& map, Dart d, const VertexAttribute& position) +typename PFP::VEC3 volumeCentroid(typename PFP::MAP& map, Dart d, const VertexAttribute& position, unsigned int thread = 0) { - return volumeCentroidGen, typename PFP::VEC3>(map, d, position); + return volumeCentroidGen, typename PFP::VEC3>(map, d, position, thread); } /** @@ -116,13 +116,38 @@ typename PFP::VEC3 vertexNeighborhoodCentroid(typename PFP::MAP& map, Dart d, co } template -void computeCentroidVolumes(typename PFP::MAP& map, const VertexAttribute& position, VolumeAttribute& vol_centroid, const FunctorSelect& select = allDarts) ; +void computeCentroidVolumes(typename PFP::MAP& map, + const VertexAttribute& position, VolumeAttribute& vol_centroid, + const FunctorSelect& select = allDarts, unsigned int thread = 0) ; template -void computeCentroidFaces(typename PFP::MAP& map, const VertexAttribute& position, FaceAttribute& face_centroid, const FunctorSelect& select = allDarts) ; +void computeCentroidFaces(typename PFP::MAP& map, + const VertexAttribute& position, FaceAttribute& face_centroid, + const FunctorSelect& select = allDarts, unsigned int thread = 0) ; template -void computeNeighborhoodCentroidVertices(typename PFP::MAP& map, const VertexAttribute& position, VertexAttribute& vertex_centroid, const FunctorSelect& select = allDarts) ; +void computeNeighborhoodCentroidVertices(typename PFP::MAP& map, + const VertexAttribute& position, VertexAttribute& vertex_centroid, + const FunctorSelect& select = allDarts, unsigned int thread = 0) ; + + +namespace Parallel +{ +template +void computeCentroidVolumes(typename PFP::MAP& map, + const VertexAttribute& position, VolumeAttribute& vol_centroid, + const FunctorSelect& select = allDarts, unsigned int nbth = 0, unsigned int current_thread = 0) ; + +template +void computeCentroidFaces(typename PFP::MAP& map, + const VertexAttribute& position, FaceAttribute& face_centroid, + const FunctorSelect& select = allDarts, unsigned int nbth = 0, unsigned int current_thread = 0) ; + +template +void computeNeighborhoodCentroidVertices(typename PFP::MAP& map, + const VertexAttribute& position, VertexAttribute& vertex_centroid, + const FunctorSelect& select = allDarts, unsigned int nbth = 0, unsigned int current_thread = 0) ; +} } // namespace Geometry diff --git a/include/Algo/Geometry/centroid.hpp b/include/Algo/Geometry/centroid.hpp index bdb9cef53698fb4b62ed708f3bdf70563efdc886..df7a4fbdbd21522a96fc98e480c3679d3cc97bbd 100644 --- a/include/Algo/Geometry/centroid.hpp +++ b/include/Algo/Geometry/centroid.hpp @@ -27,6 +27,7 @@ #include "Topology/generic/cellmarker.h" #include "Topology/generic/traversorCell.h" #include "Topology/generic/traversor3.h" +#include "Algo/Parallel/parallel_foreach.h" namespace CGoGN @@ -39,12 +40,12 @@ namespace Geometry { template -EMB volumeCentroidGen(typename PFP::MAP& map, Dart d, const EMBV& attributs) +EMB volumeCentroidGen(typename PFP::MAP& map, Dart d, const EMBV& attributs, unsigned int thread) { EMB center = AttribOps::zero() ; unsigned int count = 0 ; - Traversor3WV tra(map,d); + Traversor3WV tra(map,d,false,thread); for (Dart d = tra.begin(); d != tra.end(); d = tra.next()) { center += attributs[d]; @@ -86,29 +87,126 @@ EMB vertexNeighborhoodCentroidGen(typename PFP::MAP& map, Dart d, const EMBV& at } template -void computeCentroidVolumes(typename PFP::MAP& map, const VertexAttribute& position, VolumeAttribute& vol_centroid, const FunctorSelect& select) +void computeCentroidVolumes(typename PFP::MAP& map, const VertexAttribute& position, VolumeAttribute& vol_centroid, const FunctorSelect& select, unsigned int thread) { - TraversorW t(map, select) ; + TraversorW t(map, select,thread) ; for(Dart d = t.begin(); d != t.end(); d = t.next()) - vol_centroid[d] = volumeCentroid(map, d, position) ; + vol_centroid[d] = volumeCentroid(map, d, position,thread) ; } template -void computeCentroidFaces(typename PFP::MAP& map, const VertexAttribute& position, FaceAttribute& face_centroid, const FunctorSelect& select) +void computeCentroidFaces(typename PFP::MAP& map, const VertexAttribute& position, FaceAttribute& face_centroid, const FunctorSelect& select, unsigned int thread) { - TraversorF t(map, select) ; + TraversorF t(map, select,thread) ; for(Dart d = t.begin(); d != t.end(); d = t.next()) face_centroid[d] = faceCentroid(map, d, position) ; } template -void computeNeighborhoodCentroidVertices(typename PFP::MAP& map, const VertexAttribute& position, VertexAttribute& vertex_centroid, const FunctorSelect& select) +void computeNeighborhoodCentroidVertices(typename PFP::MAP& map, const VertexAttribute& position, VertexAttribute& vertex_centroid, const FunctorSelect& select, unsigned int thread) { - TraversorV t(map, select) ; + TraversorV t(map, select, thread) ; for(Dart d = t.begin(); d != t.end(); d = t.next()) vertex_centroid[d] = vertexNeighborhoodCentroid(map, d, position) ; } + + +namespace Parallel +{ +template +class FunctorComputeCentroidVolumes: public FunctorMapThreaded +{ + const VertexAttribute& m_position; + VolumeAttribute& m_vol_centroid; +public: + FunctorComputeCentroidVolumes( typename PFP::MAP& map, const VertexAttribute& position, VolumeAttribute& vol_centroid): + FunctorMapThreaded(map), m_position(position), m_vol_centroid(vol_centroid) + { } + + void parallelDo(Dart d, unsigned int threadID) + { + m_vol_centroid[d] = volumeCentroid(this->m_map, d, m_position,threadID) ; + } +}; + + +template +void computeCentroidVolumes(typename PFP::MAP& map, + const VertexAttribute& position, VolumeAttribute& vol_centroid, + const FunctorSelect& select, unsigned int nbth, unsigned int current_thread) +{ + FunctorComputeCentroidVolumes funct(map,position,vol_centroid); + Algo::Parallel::foreach_cell(map, funct, true, nbth, true, select, current_thread); +} + + +template +class FunctorComputeCentroidFaces: public FunctorMapThreaded +{ + const VertexAttribute& m_position; + FaceAttribute& m_fcentroid; +public: + FunctorComputeCentroidFaces( typename PFP::MAP& map, const VertexAttribute& position, FaceAttribute& fcentroid): + FunctorMapThreaded(map), m_position(position), m_fcentroid(fcentroid) + { } + + void parallelDo(Dart d, unsigned int threadID) + { + m_fcentroid[d] = faceCentroid(this->m_map, d, m_position) ; + } +}; + + +template +void computeCentroidFaces(typename PFP::MAP& map, + const VertexAttribute& position, FaceAttribute& face_centroid, + const FunctorSelect& select, unsigned int nbth, unsigned int current_thread) +{ + FunctorComputeCentroidFaces funct(map,position,face_centroid); + Algo::Parallel::foreach_cell(map, funct, true, nbth, false, select, current_thread); +} + + +template +class FunctorComputeNeighborhoodCentroidVertices: public FunctorMapThreaded +{ + const VertexAttribute& m_position; + VertexAttribute& m_vcentroid; +public: + FunctorComputeNeighborhoodCentroidVertices( typename PFP::MAP& map, const VertexAttribute& position, VertexAttribute& vcentroid): + FunctorMapThreaded(map), m_position(position), m_vcentroid(vcentroid) + { } + + void parallelDo(Dart d, unsigned int threadID) + { + m_vcentroid[d] = vertexNeighborhoodCentroid(this->m_map, d, m_position) ; + } +}; + +template +void computeNeighborhoodCentroidVertices(typename PFP::MAP& map, + const VertexAttribute& position, VertexAttribute& vertex_centroid, + const FunctorSelect& select, unsigned int nbth, unsigned int current_thread) +{ + FunctorComputeNeighborhoodCentroidVertices funct(map,position,vertex_centroid); + Algo::Parallel::foreach_cell(map, funct, true, nbth, false, select, current_thread); +} + +} + + + + + + + + + + + + + } // namespace Geometry } // namespace Algo diff --git a/include/Algo/Geometry/curvature.h b/include/Algo/Geometry/curvature.h index dce9d1e525f5410193310e7a7bf3f6bd927aa536..a2425dcf3b8a7e53665f4a2d46006b80b8ffcaec 100644 --- a/include/Algo/Geometry/curvature.h +++ b/include/Algo/Geometry/curvature.h @@ -101,7 +101,7 @@ void computeCurvatureVertices_NormalCycles( VertexAttribute& Kmax, VertexAttribute& Kmin, VertexAttribute& Knormal, - const FunctorSelect& select = allDarts) ; + const FunctorSelect& select = allDarts, unsigned int thread=0) ; template void computeCurvatureVertex_NormalCycles( @@ -115,10 +115,29 @@ void computeCurvatureVertex_NormalCycles( VertexAttribute& kmin, VertexAttribute& Kmax, VertexAttribute& Kmin, - VertexAttribute& Knormal) ; + VertexAttribute& Knormal, unsigned int thread=0) ; } // namespace Geometry +namespace Parallel +{ +template +void computeCurvatureVertices_NormalCycles( + typename PFP::MAP& map, + typename PFP::REAL radius, + const VertexAttribute& position, + const VertexAttribute& normal, + const EdgeAttribute& edgeangle, + VertexAttribute& kmax, + VertexAttribute& kmin, + VertexAttribute& Kmax, + VertexAttribute& Kmin, + VertexAttribute& Knormal, + const FunctorSelect& select = allDarts, unsigned int nbth = 0, unsigned int current_thread=0) ; + +} + + } // namespace Algo } // namespace CGoGN diff --git a/include/Algo/Geometry/curvature.hpp b/include/Algo/Geometry/curvature.hpp index 7f6a70281855a8fc1bde28f9ef58f308015bfc50..179c8d1aa5a3ab094c983bbbcc51c8b6da625344 100644 --- a/include/Algo/Geometry/curvature.hpp +++ b/include/Algo/Geometry/curvature.hpp @@ -289,11 +289,11 @@ void computeCurvatureVertices_NormalCycles( VertexAttribute& Kmax, VertexAttribute& Kmin, VertexAttribute& Knormal, - const FunctorSelect& select) + const FunctorSelect& select, unsigned int thread) { TraversorV t(map, select) ; for(Dart d = t.begin(); d != t.end(); d = t.next()) - computeCurvatureVertex_NormalCycles(map, d, radius, position, normal, edgeangle, kmax, kmin, Kmax, Kmin, Knormal) ; + computeCurvatureVertex_NormalCycles(map, d, radius, position, normal, edgeangle, kmax, kmin, Kmax, Kmin, Knormal,thread) ; } template @@ -308,12 +308,12 @@ void computeCurvatureVertex_NormalCycles( VertexAttribute& kmin, VertexAttribute& Kmax, VertexAttribute& Kmin, - VertexAttribute& Knormal) + VertexAttribute& Knormal, unsigned int thread) { typedef typename PFP::VEC3 VEC3 ; typedef typename PFP::REAL REAL ; - Algo::Selection::Collector_WithinSphere neigh(map, position, radius) ; + Algo::Selection::Collector_WithinSphere neigh(map, position, radius, thread) ; neigh.collectAll(dart) ; neigh.computeArea() ; @@ -379,6 +379,73 @@ void computeCurvatureVertex_NormalCycles( dirNormal *= -1; // change orientation } + +namespace Parallel +{ + +template +class FunctorComputeCurvatureVertices_NormalCycles: public FunctorMapThreaded +{ + typename PFP::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( typename PFP::MAP& map, + typename PFP::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(normal) + { } + + void parallelDo(Dart d, unsigned int threadID) + { + computeCurvatureVertex_NormalCycles(map, d, radius, position, normal, edgeangle, kmax, kmin, Kmax, Kmin, Knormal,threadID) ; + } +}; + +template +void computeCurvatureVertices_NormalCycles( + typename PFP::MAP& map, + typename PFP::REAL radius, + const VertexAttribute& position, + const VertexAttribute& normal, + const EdgeAttribute& edgeangle, + VertexAttribute& kmax, + VertexAttribute& kmin, + VertexAttribute& Kmax, + VertexAttribute& Kmin, + VertexAttribute& Knormal, + const FunctorSelect& select, unsigned int nbth, unsigned int current_thread) +{ + FunctorComputeCurvatureVertices_NormalCycles funct(map, radius, position, normal, edgeangle, kmax, kmin, Kmax, Kmin, Knormal); + Algo::Parallel::foreach_cell(map, funct, true, nbth, true, select, current_thread); +} + +} + + + } // namespace Geometry } // namespace Algo diff --git a/include/Algo/Geometry/normal.h b/include/Algo/Geometry/normal.h index fe168b9ddcf74d82c6e2d259180a313077bf420a..b466d9877339f1af80b4b9e846482a3dec6d0af8 100644 --- a/include/Algo/Geometry/normal.h +++ b/include/Algo/Geometry/normal.h @@ -27,6 +27,7 @@ #include "Geometry/basic.h" + namespace CGoGN { @@ -54,6 +55,7 @@ typename PFP::VEC3 vertexBorderNormal(typename PFP::MAP& map, Dart d, const Vert template void computeNormalFaces(typename PFP::MAP& map, const VertexAttribute& position, FaceAttribute& face_normal, const FunctorSelect& select = allDarts, unsigned int thread = 0) ; + /** * compute normals of vertices * @param map the map on which we work @@ -65,12 +67,26 @@ void computeNormalFaces(typename PFP::MAP& map, const VertexAttribute void computeNormalVertices(typename PFP::MAP& map, const VertexAttribute& position, VertexAttribute& normal, const FunctorSelect& select = allDarts, unsigned int thread = 0) ; + +namespace Parallel +{ +template +void computeNormalVertices(typename PFP::MAP& map, const VertexAttribute& position, VertexAttribute& normal, const FunctorSelect& select = allDarts, unsigned int nbth = 0, unsigned int current_thread = 0) ; + + +template +void computeNormalFaces(typename PFP::MAP& map, const VertexAttribute& position, FaceAttribute& face_normal, const FunctorSelect& select = allDarts, unsigned int nbth = 0, unsigned int thread = 0) ; + +} + + template typename PFP::REAL computeAngleBetweenNormalsOnEdge(typename PFP::MAP& map, Dart d, VertexAttribute& position) ; template void computeAnglesBetweenNormalsOnEdges(typename PFP::MAP& map, const VertexAttribute& position, EdgeAttribute& angles, const FunctorSelect& select = allDarts, unsigned int thread = 0) ; + } // namespace Geometry } // namespace Algo diff --git a/include/Algo/Geometry/normal.hpp b/include/Algo/Geometry/normal.hpp index 04f71ded565f12232f1010c51bccda4e0d1d0aac..f8f997793d2b90d4a39c0f3b3cfa3e84dddc6899 100644 --- a/include/Algo/Geometry/normal.hpp +++ b/include/Algo/Geometry/normal.hpp @@ -28,6 +28,8 @@ #include "Topology/generic/traversorCell.h" #include "Topology/generic/traversor2.h" +#include "Algo/Parallel/parallel_foreach.h" + #include namespace CGoGN @@ -163,6 +165,62 @@ void computeNormalVertices(typename PFP::MAP& map, const VertexAttribute(map, d, position) ; } + + +namespace Parallel +{ + +template +class FunctorComputeNormalVertices: public FunctorMapThreaded +{ + const VertexAttribute& m_position; + VertexAttribute& m_normal; +public: + FunctorComputeNormalVertices( typename PFP::MAP& map, const VertexAttribute& position, VertexAttribute& normal): + FunctorMapThreaded(map), m_position(position), m_normal(normal) + { } + + void parallelDo(Dart d, unsigned int threadID) + { + m_normal[d] = vertexNormal(this->m_map, d, m_position) ; + } +}; + +template +void computeNormalVertices(typename PFP::MAP& map, const VertexAttribute& position, VertexAttribute& normal, const FunctorSelect& select, unsigned int nbth, unsigned int current_thread) +{ + FunctorComputeNormalVertices funct(map,position,normal); + Algo::Parallel::foreach_cell(map, funct, true, nbth, false, select, current_thread); +} + + +template +class FunctorComputeNormalFaces: public FunctorMapThreaded +{ + const VertexAttribute& m_position; + FaceAttribute& m_normal; +public: + FunctorComputeNormalFaces( typename PFP::MAP& map, const VertexAttribute& position, FaceAttribute& normal): + FunctorMapThreaded(map), m_position(position), m_normal(normal) + { } + + void parallelDo(Dart d, unsigned int threadID) + { + m_normal[d] = faceNormal(this->m_map, d, m_position) ; + } +}; + +template +void computeNormalFaces(typename PFP::MAP& map, const VertexAttribute& position, FaceAttribute& normal, const FunctorSelect& select, unsigned int nbth, unsigned int current_thread) +{ + FunctorComputeNormalFaces funct(map,position,normal); + Algo::Parallel::foreach_cell(map, funct, true, nbth, false, select, current_thread); +} + +} + + + template typename PFP::REAL computeAngleBetweenNormalsOnEdge(typename PFP::MAP& map, Dart d, const VertexAttribute& position) { diff --git a/include/Algo/Geometry/volume.h b/include/Algo/Geometry/volume.h index ba492ca6df7a656ebc9b65ca759d91b4f596b6c4..c00f67653fcf86964c2fbeb2f800156c4bb22117 100644 --- a/include/Algo/Geometry/volume.h +++ b/include/Algo/Geometry/volume.h @@ -43,10 +43,18 @@ template typename PFP::REAL tetrahedronVolume(typename PFP::MAP& map, Dart d, const VertexAttribute& position) ; template -typename PFP::REAL convexPolyhedronVolume(typename PFP::MAP& map, Dart d, const VertexAttribute& position) ; +typename PFP::REAL convexPolyhedronVolume(typename PFP::MAP& map, Dart d, const VertexAttribute& position, unsigned int thread=0) ; template -typename PFP::REAL totalVolume(typename PFP::MAP& map, const VertexAttribute& position, const FunctorSelect& select = allDarts) ; +typename PFP::REAL totalVolume(typename PFP::MAP& map, const VertexAttribute& position, const FunctorSelect& select = allDarts, unsigned int thread = 0) ; + + +namespace Parallel +{ +template +typename PFP::REAL totalVolume(typename PFP::MAP& map, const VertexAttribute& position, const FunctorSelect& select = allDarts, unsigned int nbth = 0, unsigned int current_thread = 0) ; + +} } // namespace Geometry diff --git a/include/Algo/Geometry/volume.hpp b/include/Algo/Geometry/volume.hpp index 2f29eb5001409b7f7b9163023ebb5e5918bc9e37..283de46764184d9647043b6a0119cb5dd854ea30 100644 --- a/include/Algo/Geometry/volume.hpp +++ b/include/Algo/Geometry/volume.hpp @@ -58,18 +58,18 @@ typename PFP::REAL tetrahedronVolume(typename PFP::MAP& map, Dart d, const Verte } template -typename PFP::REAL convexPolyhedronVolume(typename PFP::MAP& map, Dart d, const VertexAttribute& position) +typename PFP::REAL convexPolyhedronVolume(typename PFP::MAP& map, Dart d, const VertexAttribute& position, unsigned int thread) { typedef typename PFP::VEC3 VEC3; - if(Modelisation::Tetrahedralization::isTetrahedron(map,d)) + if(Modelisation::Tetrahedralization::isTetrahedron(map,d,thread)) return tetrahedronVolume(map,d,position) ; else { typename PFP::REAL vol = 0 ; - VEC3 vCentroid = Algo::Geometry::volumeCentroid(map, d, position) ; + VEC3 vCentroid = Algo::Geometry::volumeCentroid(map, d, position, thread) ; - DartMarkerStore mark(map); // Lock a marker + DartMarkerStore mark(map,thread); // Lock a marker std::vector visitedFaces ; visitedFaces.reserve(100) ; @@ -115,15 +115,69 @@ typename PFP::REAL convexPolyhedronVolume(typename PFP::MAP& map, Dart d, const } template -float totalVolume(typename PFP::MAP& map, const VertexAttribute& position, const FunctorSelect& select) +typename PFP::REAL totalVolume(typename PFP::MAP& map, const VertexAttribute& position, const FunctorSelect& select, unsigned int thread) { typename PFP::REAL vol = 0 ; - TraversorW t(map, select) ; + TraversorW t(map, select, thread) ; for(Dart d = t.begin(); d != t.end(); d = t.next()) - vol += convexPolyhedronVolume(map, d, position) ; + vol += convexPolyhedronVolume(map, d, position,thread) ; return vol ; } + +namespace Parallel +{ + +template +class FunctorTotalVolume: public FunctorMapThreaded +{ + const VertexAttribute& m_position; + typename PFP::REAL m_vol; +public: + FunctorTotalVolume( typename PFP::MAP& map, const VertexAttribute& position): + FunctorMapThreaded(map), m_position(position), m_vol(0.0) + { } + + void parallelDo(Dart d, unsigned int threadID) + { + m_vol += convexPolyhedronVolume(this->m_map, d, m_position,threadID) ; + } + + typename PFP::REAL getVol() const + { + return m_vol; + } +}; + + + +template +typename PFP::REAL totalVolume(typename PFP::MAP& map, const VertexAttribute& position, const FunctorSelect& select, unsigned int nbth, unsigned int current_thread) +{ + if (nbth==0) + nbth = Algo::Parallel::optimalNbThreads(); + + + std::vector*> functs; + for (unsigned int i=0; i < nbth; ++i) + { + functs.push_back(new FunctorTotalVolume(map,position)); + } + + typename PFP::REAL total=0.0; + + Algo::Parallel::foreach_cell(map, functs, nbth, true, select, current_thread); + + for (unsigned int i=0; i < nbth; ++i) + { + total += reinterpret_cast*>(functs[i])->getVol(); + delete functs[i]; + } + return total; +} + +} + } // namespace Geometry } // namespace Algo diff --git a/include/Algo/Modelisation/tetrahedralization.h b/include/Algo/Modelisation/tetrahedralization.h index 11ac8f5b21ae45d0362834a28611c81120c02643..35a209240572a16e97e06597f55df979db7d9fc8 100644 --- a/include/Algo/Modelisation/tetrahedralization.h +++ b/include/Algo/Modelisation/tetrahedralization.h @@ -70,7 +70,7 @@ Dart splitVertex(typename PFP::MAP& map, std::vector& vd); * @param a dart from the volume */ template -bool isTetrahedron(typename PFP::MAP& the_map, Dart d); +bool isTetrahedron(typename PFP::MAP& the_map, Dart d, unsigned int thread=0); /** * test if a mesh (or submesh) is a tetrahedral mesh diff --git a/include/Algo/Modelisation/tetrahedralization.hpp b/include/Algo/Modelisation/tetrahedralization.hpp index eacd899127fd6591189b484bb5363e8c32c97f5f..ea2ef5cf33f6b5a2eed4d5e8d3865c18cd63dec5 100644 --- a/include/Algo/Modelisation/tetrahedralization.hpp +++ b/include/Algo/Modelisation/tetrahedralization.hpp @@ -216,12 +216,12 @@ Dart splitVertex(typename PFP::MAP& map, std::vector& vd) ************************************************************************************************/ template -bool isTetrahedron(typename PFP::MAP& the_map, Dart d) +bool isTetrahedron(typename PFP::MAP& the_map, Dart d, unsigned int thread) { unsigned int nbFaces = 0; //Test the number of faces end its valency - Traversor3WF travWF(the_map, d); + Traversor3WF travWF(the_map, d, false, thread); for(Dart dit = travWF.begin() ; dit != travWF.end(); dit = travWF.next()) { //increase the number of faces diff --git a/include/Algo/Parallel/cgogn_thread.h b/include/Algo/Parallel/cgogn_thread.h new file mode 100644 index 0000000000000000000000000000000000000000..d01494883b4d2422e926c5eb09f70bc29a36b17d --- /dev/null +++ b/include/Algo/Parallel/cgogn_thread.h @@ -0,0 +1,78 @@ +/******************************************************************************* +* 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 __PARALLEL_THREAD__ +#define __PARALLEL_THREAD__ + +namespace CGoGN +{ + +namespace Algo +{ + +namespace Parallel +{ + +/** + * Class to encapsulate algorithm in a boost thread + * Usage: + * - Define a class MyCGoGNThread that inherit from CGoGNThread + * - call with boost::thread cgt1(MyCGoGNThread(map,1, ...); + * - wait to finish: cgt1.join(); + * + * TODO: write a CGoGNThread version of "all" algorithm + */ +template +class CGoGNThread +{ +protected: + MAP& m_map; + unsigned int m_threadId; + + unsigned int tid() + { + return m_threadId; + } + +public: + CGoGNThread(MAP& map, unsigned int th): + m_map(map), m_threadId(th) {} + + virtual ~CGoGNThread() {} + + /** + * to implement with algo to execute (use m_threadId) + */ + virtual void operator()()=0; + + +}; + + +} // namespace Parallel + +} // namespace Algo + +} // namespace CGoGN + +#endif diff --git a/include/Algo/Render/GL2/explodeVolumeRender.hpp b/include/Algo/Render/GL2/explodeVolumeRender.hpp index f9856e05d35be5307c202894e18f9ae6eac1b2f7..a332fbf665fea8be0b7a8a87ef80c6540a99517c 100644 --- a/include/Algo/Render/GL2/explodeVolumeRender.hpp +++ b/include/Algo/Render/GL2/explodeVolumeRender.hpp @@ -88,7 +88,7 @@ void ExplodeVolumeRender::updateData(typename PFP::MAP& map, const VertexAttribu typedef typename PFP::REAL REAL; VolumeAutoAttribute centerVolumes(map, "centerVolumes"); - Algo::Geometry::computeCentroidVolumes(map, positions, centerVolumes, good); + Algo::Geometry::Parallel::computeCentroidVolumes(map, positions, centerVolumes, good); std::vector buffer; buffer.reserve(16384); @@ -180,7 +180,7 @@ void ExplodeVolumeRender::updateData(typename PFP::MAP& map, const VertexAttribu typedef typename PFP::REAL REAL; VolumeAutoAttribute centerVolumes(map, "centerVolumes"); - Algo::Geometry::computeCentroidVolumes(map, positions, centerVolumes, good); + Algo::Geometry::Parallel::computeCentroidVolumes(map, positions, centerVolumes, good); std::vector buffer; buffer.reserve(16384); diff --git a/include/Algo/Render/GL2/topo3Render.hpp b/include/Algo/Render/GL2/topo3Render.hpp index 2071fda430a3237dd4d518316f010e3d4f8b3713..e0f290855dfe0fa683506c4e85842d9e204e78fb 100644 --- a/include/Algo/Render/GL2/topo3Render.hpp +++ b/include/Algo/Render/GL2/topo3Render.hpp @@ -81,7 +81,8 @@ void Topo3Render::updateDataMap3(typename PFP::MAP& mapx, const VertexAttribute< CellMarker cmv(mapx); VolumeAutoAttribute centerVolumes(mapx, "centerVolumes"); - Algo::Geometry::computeCentroidVolumes(mapx, positions, centerVolumes, allDarts); + Algo::Geometry::Parallel::computeCentroidVolumes(mapx, positions, centerVolumes, allDarts,3); + // debut phi1 DartAutoAttribute fv1(mapx); @@ -335,7 +336,7 @@ void Topo3Render::updateDataGMap3(typename PFP::MAP& mapx, const VertexAttribute // compute center of each volumes VolumeAutoAttribute centerVolumes(mapx, "centerVolumes"); - Algo::Geometry::computeCentroidVolumes(mapx, positions, centerVolumes, good); + Algo::Geometry::Parallel::computeCentroidVolumes(mapx, positions, centerVolumes, good); // beta1 DartAutoAttribute fv1(mapx); diff --git a/include/Algo/Selection/collector.h b/include/Algo/Selection/collector.h index f39d8be6aef6a2588bb56c1ecea237466037c264..d16be99cad88db4054d00d8810efc9ee980e6a25 100644 --- a/include/Algo/Selection/collector.h +++ b/include/Algo/Selection/collector.h @@ -145,13 +145,15 @@ protected: const VertexAttribute& position; typename PFP::REAL radius; typename PFP::REAL area; + unsigned int m_thread; public: - Collector_WithinSphere(typename PFP::MAP& m, const VertexAttribute& p, typename PFP::REAL r = 0) : + Collector_WithinSphere(typename PFP::MAP& m, const VertexAttribute& p, typename PFP::REAL r = 0, unsigned int thread=0) : Collector(m), position(p), radius(r), - area(0) + area(0), + m_thread(thread) {} inline void setRadius(typename PFP::REAL r) { radius = r; } inline typename PFP::REAL getRadius() const { return radius; } diff --git a/include/Algo/Selection/collector.hpp b/include/Algo/Selection/collector.hpp index 78f5cfd8f4a1bf1b4f092b99e761cd34a04ad73d..ac6bb9462f2547e37598eb248781871cd35257fa 100644 --- a/include/Algo/Selection/collector.hpp +++ b/include/Algo/Selection/collector.hpp @@ -149,9 +149,9 @@ void Collector_WithinSphere::collectAll(Dart d) this->insideFaces.reserve(32); this->border.reserve(32); - CellMarkerStore vm(this->map); // mark the collected inside-vertices - CellMarkerStore em(this->map); // mark the collected inside-edges + border-edges - CellMarkerStore fm(this->map); // mark the collected inside-faces + border-faces + CellMarkerStore vm(this->map, m_thread); // mark the collected inside-vertices + CellMarkerStore em(this->map, m_thread); // mark the collected inside-edges + border-edges + CellMarkerStore fm(this->map, m_thread); // mark the collected inside-faces + border-faces this->insideVertices.push_back(this->centerDart); vm.mark(this->centerDart); @@ -211,8 +211,8 @@ void Collector_WithinSphere::collectBorder(Dart d) this->border.reserve(128); this->insideVertices.reserve(128); - CellMarkerStore vm(this->map); // mark the collected inside-vertices - CellMarkerStore em(this->map); // mark the collected inside-edges + border-edges + CellMarkerStore vm(this->map, m_thread); // mark the collected inside-vertices + CellMarkerStore em(this->map, m_thread); // mark the collected inside-edges + border-edges this->insideVertices.push_back(this->centerDart); vm.mark(this->centerDart);