Commit 7e843f10 authored by Sylvain Thery's avatar Sylvain Thery

Add parallel version of some algorithm (just add Parallel namespace)

Corrections: add some forgotten thread parameter
parent c5be02f7
...@@ -49,7 +49,7 @@ namespace Geometry ...@@ -49,7 +49,7 @@ namespace Geometry
* @param attributs the vector of attribute or cell * @param attributs the vector of attribute or cell
*/ */
template <typename PFP, typename EMBV, typename EMB> template <typename PFP, typename EMBV, typename EMB>
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 * Compute volume centroid
...@@ -59,9 +59,9 @@ EMB volumeCentroidGen(typename PFP::MAP& map, Dart d, const EMBV& attributs); ...@@ -59,9 +59,9 @@ EMB volumeCentroidGen(typename PFP::MAP& map, Dart d, const EMBV& attributs);
* @param position the vector of attribute * @param position the vector of attribute
*/ */
template <typename PFP> template <typename PFP>
typename PFP::VEC3 volumeCentroid(typename PFP::MAP& map, Dart d, const VertexAttribute<typename PFP::VEC3>& position) typename PFP::VEC3 volumeCentroid(typename PFP::MAP& map, Dart d, const VertexAttribute<typename PFP::VEC3>& position, unsigned int thread = 0)
{ {
return volumeCentroidGen<PFP, VertexAttribute<typename PFP::VEC3>, typename PFP::VEC3>(map, d, position); return volumeCentroidGen<PFP, VertexAttribute<typename PFP::VEC3>, typename PFP::VEC3>(map, d, position, thread);
} }
/** /**
...@@ -116,13 +116,38 @@ typename PFP::VEC3 vertexNeighborhoodCentroid(typename PFP::MAP& map, Dart d, co ...@@ -116,13 +116,38 @@ typename PFP::VEC3 vertexNeighborhoodCentroid(typename PFP::MAP& map, Dart d, co
} }
template <typename PFP> template <typename PFP>
void computeCentroidVolumes(typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3>& position, VolumeAttribute<typename PFP::VEC3>& vol_centroid, const FunctorSelect& select = allDarts) ; void computeCentroidVolumes(typename PFP::MAP& map,
const VertexAttribute<typename PFP::VEC3>& position, VolumeAttribute<typename PFP::VEC3>& vol_centroid,
const FunctorSelect& select = allDarts, unsigned int thread = 0) ;
template <typename PFP> template <typename PFP>
void computeCentroidFaces(typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3>& position, FaceAttribute<typename PFP::VEC3>& face_centroid, const FunctorSelect& select = allDarts) ; void computeCentroidFaces(typename PFP::MAP& map,
const VertexAttribute<typename PFP::VEC3>& position, FaceAttribute<typename PFP::VEC3>& face_centroid,
const FunctorSelect& select = allDarts, unsigned int thread = 0) ;
template <typename PFP> template <typename PFP>
void computeNeighborhoodCentroidVertices(typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3>& position, VertexAttribute<typename PFP::VEC3>& vertex_centroid, const FunctorSelect& select = allDarts) ; void computeNeighborhoodCentroidVertices(typename PFP::MAP& map,
const VertexAttribute<typename PFP::VEC3>& position, VertexAttribute<typename PFP::VEC3>& vertex_centroid,
const FunctorSelect& select = allDarts, unsigned int thread = 0) ;
namespace Parallel
{
template <typename PFP>
void computeCentroidVolumes(typename PFP::MAP& map,
const VertexAttribute<typename PFP::VEC3>& position, VolumeAttribute<typename PFP::VEC3>& vol_centroid,
const FunctorSelect& select = allDarts, unsigned int nbth = 0, unsigned int current_thread = 0) ;
template <typename PFP>
void computeCentroidFaces(typename PFP::MAP& map,
const VertexAttribute<typename PFP::VEC3>& position, FaceAttribute<typename PFP::VEC3>& face_centroid,
const FunctorSelect& select = allDarts, unsigned int nbth = 0, unsigned int current_thread = 0) ;
template <typename PFP>
void computeNeighborhoodCentroidVertices(typename PFP::MAP& map,
const VertexAttribute<typename PFP::VEC3>& position, VertexAttribute<typename PFP::VEC3>& vertex_centroid,
const FunctorSelect& select = allDarts, unsigned int nbth = 0, unsigned int current_thread = 0) ;
}
} // namespace Geometry } // namespace Geometry
......
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
#include "Topology/generic/cellmarker.h" #include "Topology/generic/cellmarker.h"
#include "Topology/generic/traversorCell.h" #include "Topology/generic/traversorCell.h"
#include "Topology/generic/traversor3.h" #include "Topology/generic/traversor3.h"
#include "Algo/Parallel/parallel_foreach.h"
namespace CGoGN namespace CGoGN
...@@ -39,12 +40,12 @@ namespace Geometry ...@@ -39,12 +40,12 @@ namespace Geometry
{ {
template <typename PFP, typename EMBV, typename EMB> template <typename PFP, typename EMBV, typename EMB>
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<EMB,PFP>() ; EMB center = AttribOps::zero<EMB,PFP>() ;
unsigned int count = 0 ; unsigned int count = 0 ;
Traversor3WV<typename PFP::MAP> tra(map,d); Traversor3WV<typename PFP::MAP> tra(map,d,false,thread);
for (Dart d = tra.begin(); d != tra.end(); d = tra.next()) for (Dart d = tra.begin(); d != tra.end(); d = tra.next())
{ {
center += attributs[d]; center += attributs[d];
...@@ -86,29 +87,126 @@ EMB vertexNeighborhoodCentroidGen(typename PFP::MAP& map, Dart d, const EMBV& at ...@@ -86,29 +87,126 @@ EMB vertexNeighborhoodCentroidGen(typename PFP::MAP& map, Dart d, const EMBV& at
} }
template <typename PFP> template <typename PFP>
void computeCentroidVolumes(typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3>& position, VolumeAttribute<typename PFP::VEC3>& vol_centroid, const FunctorSelect& select) void computeCentroidVolumes(typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3>& position, VolumeAttribute<typename PFP::VEC3>& vol_centroid, const FunctorSelect& select, unsigned int thread)
{ {
TraversorW<typename PFP::MAP> t(map, select) ; TraversorW<typename PFP::MAP> t(map, select,thread) ;
for(Dart d = t.begin(); d != t.end(); d = t.next()) for(Dart d = t.begin(); d != t.end(); d = t.next())
vol_centroid[d] = volumeCentroid<PFP>(map, d, position) ; vol_centroid[d] = volumeCentroid<PFP>(map, d, position,thread) ;
} }
template <typename PFP> template <typename PFP>
void computeCentroidFaces(typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3>& position, FaceAttribute<typename PFP::VEC3>& face_centroid, const FunctorSelect& select) void computeCentroidFaces(typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3>& position, FaceAttribute<typename PFP::VEC3>& face_centroid, const FunctorSelect& select, unsigned int thread)
{ {
TraversorF<typename PFP::MAP> t(map, select) ; TraversorF<typename PFP::MAP> t(map, select,thread) ;
for(Dart d = t.begin(); d != t.end(); d = t.next()) for(Dart d = t.begin(); d != t.end(); d = t.next())
face_centroid[d] = faceCentroid<PFP>(map, d, position) ; face_centroid[d] = faceCentroid<PFP>(map, d, position) ;
} }
template <typename PFP> template <typename PFP>
void computeNeighborhoodCentroidVertices(typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3>& position, VertexAttribute<typename PFP::VEC3>& vertex_centroid, const FunctorSelect& select) void computeNeighborhoodCentroidVertices(typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3>& position, VertexAttribute<typename PFP::VEC3>& vertex_centroid, const FunctorSelect& select, unsigned int thread)
{ {
TraversorV<typename PFP::MAP> t(map, select) ; TraversorV<typename PFP::MAP> t(map, select, thread) ;
for(Dart d = t.begin(); d != t.end(); d = t.next()) for(Dart d = t.begin(); d != t.end(); d = t.next())
vertex_centroid[d] = vertexNeighborhoodCentroid<PFP>(map, d, position) ; vertex_centroid[d] = vertexNeighborhoodCentroid<PFP>(map, d, position) ;
} }
namespace Parallel
{
template <typename PFP>
class FunctorComputeCentroidVolumes: public FunctorMapThreaded<typename PFP::MAP >
{
const VertexAttribute<typename PFP::VEC3>& m_position;
VolumeAttribute<typename PFP::VEC3>& m_vol_centroid;
public:
FunctorComputeCentroidVolumes<PFP>( typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3>& position, VolumeAttribute<typename PFP::VEC3>& vol_centroid):
FunctorMapThreaded<typename PFP::MAP>(map), m_position(position), m_vol_centroid(vol_centroid)
{ }
void parallelDo(Dart d, unsigned int threadID)
{
m_vol_centroid[d] = volumeCentroid<PFP>(this->m_map, d, m_position,threadID) ;
}
};
template <typename PFP>
void computeCentroidVolumes(typename PFP::MAP& map,
const VertexAttribute<typename PFP::VEC3>& position, VolumeAttribute<typename PFP::VEC3>& vol_centroid,
const FunctorSelect& select, unsigned int nbth, unsigned int current_thread)
{
FunctorComputeCentroidVolumes<PFP> funct(map,position,vol_centroid);
Algo::Parallel::foreach_cell<typename PFP::MAP,VOLUME>(map, funct, true, nbth, true, select, current_thread);
}
template <typename PFP>
class FunctorComputeCentroidFaces: public FunctorMapThreaded<typename PFP::MAP >
{
const VertexAttribute<typename PFP::VEC3>& m_position;
FaceAttribute<typename PFP::VEC3>& m_fcentroid;
public:
FunctorComputeCentroidFaces<PFP>( typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3>& position, FaceAttribute<typename PFP::VEC3>& fcentroid):
FunctorMapThreaded<typename PFP::MAP>(map), m_position(position), m_fcentroid(fcentroid)
{ }
void parallelDo(Dart d, unsigned int threadID)
{
m_fcentroid[d] = faceCentroid<PFP>(this->m_map, d, m_position) ;
}
};
template <typename PFP>
void computeCentroidFaces(typename PFP::MAP& map,
const VertexAttribute<typename PFP::VEC3>& position, FaceAttribute<typename PFP::VEC3>& face_centroid,
const FunctorSelect& select, unsigned int nbth, unsigned int current_thread)
{
FunctorComputeCentroidFaces<PFP> funct(map,position,face_centroid);
Algo::Parallel::foreach_cell<typename PFP::MAP,FACE>(map, funct, true, nbth, false, select, current_thread);
}
template <typename PFP>
class FunctorComputeNeighborhoodCentroidVertices: public FunctorMapThreaded<typename PFP::MAP >
{
const VertexAttribute<typename PFP::VEC3>& m_position;
VertexAttribute<typename PFP::VEC3>& m_vcentroid;
public:
FunctorComputeNeighborhoodCentroidVertices<PFP>( typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3>& position, VertexAttribute<typename PFP::VEC3>& vcentroid):
FunctorMapThreaded<typename PFP::MAP>(map), m_position(position), m_vcentroid(vcentroid)
{ }
void parallelDo(Dart d, unsigned int threadID)
{
m_vcentroid[d] = vertexNeighborhoodCentroid<PFP>(this->m_map, d, m_position) ;
}
};
template <typename PFP>
void computeNeighborhoodCentroidVertices(typename PFP::MAP& map,
const VertexAttribute<typename PFP::VEC3>& position, VertexAttribute<typename PFP::VEC3>& vertex_centroid,
const FunctorSelect& select, unsigned int nbth, unsigned int current_thread)
{
FunctorComputeNeighborhoodCentroidVertices<PFP> funct(map,position,vertex_centroid);
Algo::Parallel::foreach_cell<typename PFP::MAP,VERTEX>(map, funct, true, nbth, false, select, current_thread);
}
}
} // namespace Geometry } // namespace Geometry
} // namespace Algo } // namespace Algo
......
...@@ -101,7 +101,7 @@ void computeCurvatureVertices_NormalCycles( ...@@ -101,7 +101,7 @@ void computeCurvatureVertices_NormalCycles(
VertexAttribute<typename PFP::VEC3>& Kmax, VertexAttribute<typename PFP::VEC3>& Kmax,
VertexAttribute<typename PFP::VEC3>& Kmin, VertexAttribute<typename PFP::VEC3>& Kmin,
VertexAttribute<typename PFP::VEC3>& Knormal, VertexAttribute<typename PFP::VEC3>& Knormal,
const FunctorSelect& select = allDarts) ; const FunctorSelect& select = allDarts, unsigned int thread=0) ;
template <typename PFP> template <typename PFP>
void computeCurvatureVertex_NormalCycles( void computeCurvatureVertex_NormalCycles(
...@@ -115,10 +115,29 @@ void computeCurvatureVertex_NormalCycles( ...@@ -115,10 +115,29 @@ void computeCurvatureVertex_NormalCycles(
VertexAttribute<typename PFP::REAL>& kmin, VertexAttribute<typename PFP::REAL>& kmin,
VertexAttribute<typename PFP::VEC3>& Kmax, VertexAttribute<typename PFP::VEC3>& Kmax,
VertexAttribute<typename PFP::VEC3>& Kmin, VertexAttribute<typename PFP::VEC3>& Kmin,
VertexAttribute<typename PFP::VEC3>& Knormal) ; VertexAttribute<typename PFP::VEC3>& Knormal, unsigned int thread=0) ;
} // namespace Geometry } // namespace Geometry
namespace Parallel
{
template <typename PFP>
void computeCurvatureVertices_NormalCycles(
typename PFP::MAP& map,
typename PFP::REAL radius,
const VertexAttribute<typename PFP::VEC3>& position,
const VertexAttribute<typename PFP::VEC3>& normal,
const EdgeAttribute<typename PFP::REAL>& edgeangle,
VertexAttribute<typename PFP::REAL>& kmax,
VertexAttribute<typename PFP::REAL>& kmin,
VertexAttribute<typename PFP::VEC3>& Kmax,
VertexAttribute<typename PFP::VEC3>& Kmin,
VertexAttribute<typename PFP::VEC3>& Knormal,
const FunctorSelect& select = allDarts, unsigned int nbth = 0, unsigned int current_thread=0) ;
}
} // namespace Algo } // namespace Algo
} // namespace CGoGN } // namespace CGoGN
......
...@@ -289,11 +289,11 @@ void computeCurvatureVertices_NormalCycles( ...@@ -289,11 +289,11 @@ void computeCurvatureVertices_NormalCycles(
VertexAttribute<typename PFP::VEC3>& Kmax, VertexAttribute<typename PFP::VEC3>& Kmax,
VertexAttribute<typename PFP::VEC3>& Kmin, VertexAttribute<typename PFP::VEC3>& Kmin,
VertexAttribute<typename PFP::VEC3>& Knormal, VertexAttribute<typename PFP::VEC3>& Knormal,
const FunctorSelect& select) const FunctorSelect& select, unsigned int thread)
{ {
TraversorV<typename PFP::MAP> t(map, select) ; TraversorV<typename PFP::MAP> t(map, select) ;
for(Dart d = t.begin(); d != t.end(); d = t.next()) for(Dart d = t.begin(); d != t.end(); d = t.next())
computeCurvatureVertex_NormalCycles<PFP>(map, d, radius, position, normal, edgeangle, kmax, kmin, Kmax, Kmin, Knormal) ; computeCurvatureVertex_NormalCycles<PFP>(map, d, radius, position, normal, edgeangle, kmax, kmin, Kmax, Kmin, Knormal,thread) ;
} }
template <typename PFP> template <typename PFP>
...@@ -308,12 +308,12 @@ void computeCurvatureVertex_NormalCycles( ...@@ -308,12 +308,12 @@ void computeCurvatureVertex_NormalCycles(
VertexAttribute<typename PFP::REAL>& kmin, VertexAttribute<typename PFP::REAL>& kmin,
VertexAttribute<typename PFP::VEC3>& Kmax, VertexAttribute<typename PFP::VEC3>& Kmax,
VertexAttribute<typename PFP::VEC3>& Kmin, VertexAttribute<typename PFP::VEC3>& Kmin,
VertexAttribute<typename PFP::VEC3>& Knormal) VertexAttribute<typename PFP::VEC3>& Knormal, unsigned int thread)
{ {
typedef typename PFP::VEC3 VEC3 ; typedef typename PFP::VEC3 VEC3 ;
typedef typename PFP::REAL REAL ; typedef typename PFP::REAL REAL ;
Algo::Selection::Collector_WithinSphere<PFP> neigh(map, position, radius) ; Algo::Selection::Collector_WithinSphere<PFP> neigh(map, position, radius, thread) ;
neigh.collectAll(dart) ; neigh.collectAll(dart) ;
neigh.computeArea() ; neigh.computeArea() ;
...@@ -379,6 +379,73 @@ void computeCurvatureVertex_NormalCycles( ...@@ -379,6 +379,73 @@ void computeCurvatureVertex_NormalCycles(
dirNormal *= -1; // change orientation dirNormal *= -1; // change orientation
} }
namespace Parallel
{
template <typename PFP>
class FunctorComputeCurvatureVertices_NormalCycles: public FunctorMapThreaded<typename PFP::MAP >
{
typename PFP::REAL m_radius;
const VertexAttribute<typename PFP::VEC3>& m_position;
const VertexAttribute<typename PFP::VEC3>& m_normal;
const EdgeAttribute<typename PFP::REAL>& m_edgeangle;
VertexAttribute<typename PFP::REAL>& m_kmax;
VertexAttribute<typename PFP::REAL>& m_kmin;
VertexAttribute<typename PFP::VEC3>& m_Kmax;
VertexAttribute<typename PFP::VEC3>& m_Kmin;
VertexAttribute<typename PFP::VEC3>& m_Knormal;
public:
FunctorComputeCurvatureVertices_NormalCycles( typename PFP::MAP& map,
typename PFP::REAL radius,
const VertexAttribute<typename PFP::VEC3>& position,
const VertexAttribute<typename PFP::VEC3>& normal,
const EdgeAttribute<typename PFP::REAL>& edgeangle,
VertexAttribute<typename PFP::REAL>& kmax,
VertexAttribute<typename PFP::REAL>& kmin,
VertexAttribute<typename PFP::VEC3>& Kmax,
VertexAttribute<typename PFP::VEC3>& Kmin,
VertexAttribute<typename PFP::VEC3>& Knormal):
FunctorMapThreaded<typename PFP::MAP>(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<PFP>(map, d, radius, position, normal, edgeangle, kmax, kmin, Kmax, Kmin, Knormal,threadID) ;
}
};
template <typename PFP>
void computeCurvatureVertices_NormalCycles(
typename PFP::MAP& map,
typename PFP::REAL radius,
const VertexAttribute<typename PFP::VEC3>& position,
const VertexAttribute<typename PFP::VEC3>& normal,
const EdgeAttribute<typename PFP::REAL>& edgeangle,
VertexAttribute<typename PFP::REAL>& kmax,
VertexAttribute<typename PFP::REAL>& kmin,
VertexAttribute<typename PFP::VEC3>& Kmax,
VertexAttribute<typename PFP::VEC3>& Kmin,
VertexAttribute<typename PFP::VEC3>& Knormal,
const FunctorSelect& select, unsigned int nbth, unsigned int current_thread)
{
FunctorComputeCurvatureVertices_NormalCycles<PFP> funct(map, radius, position, normal, edgeangle, kmax, kmin, Kmax, Kmin, Knormal);
Algo::Parallel::foreach_cell<typename PFP::MAP,VERTEX>(map, funct, true, nbth, true, select, current_thread);
}
}
} // namespace Geometry } // namespace Geometry
} // namespace Algo } // namespace Algo
......
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
#include "Geometry/basic.h" #include "Geometry/basic.h"
namespace CGoGN namespace CGoGN
{ {
...@@ -54,6 +55,7 @@ typename PFP::VEC3 vertexBorderNormal(typename PFP::MAP& map, Dart d, const Vert ...@@ -54,6 +55,7 @@ typename PFP::VEC3 vertexBorderNormal(typename PFP::MAP& map, Dart d, const Vert
template <typename PFP> template <typename PFP>
void computeNormalFaces(typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3>& position, FaceAttribute<typename PFP::VEC3>& face_normal, const FunctorSelect& select = allDarts, unsigned int thread = 0) ; void computeNormalFaces(typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3>& position, FaceAttribute<typename PFP::VEC3>& face_normal, const FunctorSelect& select = allDarts, unsigned int thread = 0) ;
/** /**
* compute normals of vertices * compute normals of vertices
* @param map the map on which we work * @param map the map on which we work
...@@ -65,12 +67,26 @@ void computeNormalFaces(typename PFP::MAP& map, const VertexAttribute<typename P ...@@ -65,12 +67,26 @@ void computeNormalFaces(typename PFP::MAP& map, const VertexAttribute<typename P
template <typename PFP> template <typename PFP>
void computeNormalVertices(typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3>& position, VertexAttribute<typename PFP::VEC3>& normal, const FunctorSelect& select = allDarts, unsigned int thread = 0) ; void computeNormalVertices(typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3>& position, VertexAttribute<typename PFP::VEC3>& normal, const FunctorSelect& select = allDarts, unsigned int thread = 0) ;
namespace Parallel
{
template <typename PFP>
void computeNormalVertices(typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3>& position, VertexAttribute<typename PFP::VEC3>& normal, const FunctorSelect& select = allDarts, unsigned int nbth = 0, unsigned int current_thread = 0) ;
template <typename PFP>
void computeNormalFaces(typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3>& position, FaceAttribute<typename PFP::VEC3>& face_normal, const FunctorSelect& select = allDarts, unsigned int nbth = 0, unsigned int thread = 0) ;
}
template <typename PFP> template <typename PFP>
typename PFP::REAL computeAngleBetweenNormalsOnEdge(typename PFP::MAP& map, Dart d, VertexAttribute<typename PFP::VEC3>& position) ; typename PFP::REAL computeAngleBetweenNormalsOnEdge(typename PFP::MAP& map, Dart d, VertexAttribute<typename PFP::VEC3>& position) ;
template <typename PFP> template <typename PFP>
void computeAnglesBetweenNormalsOnEdges(typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3>& position, EdgeAttribute<typename PFP::REAL>& angles, const FunctorSelect& select = allDarts, unsigned int thread = 0) ; void computeAnglesBetweenNormalsOnEdges(typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3>& position, EdgeAttribute<typename PFP::REAL>& angles, const FunctorSelect& select = allDarts, unsigned int thread = 0) ;
} // namespace Geometry } // namespace Geometry
} // namespace Algo } // namespace Algo
......
...@@ -28,6 +28,8 @@ ...@@ -28,6 +28,8 @@
#include "Topology/generic/traversorCell.h" #include "Topology/generic/traversorCell.h"
#include "Topology/generic/traversor2.h" #include "Topology/generic/traversor2.h"
#include "Algo/Parallel/parallel_foreach.h"
#include <cmath> #include <cmath>
namespace CGoGN namespace CGoGN
...@@ -163,6 +165,62 @@ void computeNormalVertices(typename PFP::MAP& map, const VertexAttribute<typenam ...@@ -163,6 +165,62 @@ void computeNormalVertices(typename PFP::MAP& map, const VertexAttribute<typenam
normal[d] = vertexNormal<PFP>(map, d, position) ; normal[d] = vertexNormal<PFP>(map, d, position) ;
} }
namespace Parallel
{
template <typename PFP>
class FunctorComputeNormalVertices: public FunctorMapThreaded<typename PFP::MAP >
{
const VertexAttribute<typename PFP::VEC3>& m_position;
VertexAttribute<typename PFP::VEC3>& m_normal;
public:
FunctorComputeNormalVertices<PFP>( typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3>& position, VertexAttribute<typename PFP::VEC3>& normal):
FunctorMapThreaded<typename PFP::MAP>(map), m_position(position), m_normal(normal)
{ }
void parallelDo(Dart d, unsigned int threadID)
{
m_normal[d] = vertexNormal<PFP>(this->m_map, d, m_position) ;
}
};
template <typename PFP>
void computeNormalVertices(typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3>& position, VertexAttribute<typename PFP::VEC3>& normal, const FunctorSelect& select, unsigned int nbth, unsigned int current_thread)
{
FunctorComputeNormalVertices<PFP> funct(map,position,normal);
Algo::Parallel::foreach_cell<typename PFP::MAP,VERTEX>(map, funct, true, nbth, false, select, current_thread);
}
template <typename PFP>
class FunctorComputeNormalFaces: public FunctorMapThreaded<typename PFP::MAP >
{
const VertexAttribute<typename PFP::VEC3>& m_position;
FaceAttribute<typename PFP::VEC3>& m_normal;
public:
FunctorComputeNormalFaces<PFP>( typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3>& position, FaceAttribute<typename PFP::VEC3>& normal):
FunctorMapThreaded<typename PFP::MAP>(map), m_position(position), m_normal(normal)
{ }
void parallelDo(Dart d, unsigned int threadID)
{
m_normal[d] = faceNormal<PFP>(this->m_map, d, m_position) ;
}
};
template <typename PFP>
void computeNormalFaces(typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3>& position, FaceAttribute<typename PFP::VEC3>& normal, const FunctorSelect& select, unsigned int nbth, unsigned int current_thread)
{
FunctorComputeNormalFaces<PFP> funct(map,position,normal);
Algo::Parallel::foreach_cell<typename PFP::MAP,FACE>(map, funct, true, nbth, false, select, current_thread);
}
}
template <typename PFP> template <typename PFP>
typename PFP::REAL computeAngleBetweenNormalsOnEdge(typename PFP::MAP& map, Dart d, const VertexAttribute<typename PFP::VEC3>& position) typename PFP::REAL computeAngleBetweenNormalsOnEdge(typename PFP::MAP& map, Dart d, const VertexAttribute<typename PFP::VEC3>& position)
{ {
......
...@@ -43,10 +43,18 @@ template <typename PFP> ...@@ -43,10 +43,18 @@ template <typename PFP>
typename PFP::REAL tetrahedronVolume(typename PFP::MAP& map, Dart d, const VertexAttribute<typename PFP::VEC3>& position) ; typename PFP::REAL tetrahedronVolume(typename PFP::MAP& map, Dart d, const VertexAttribute<typename PFP::VEC3>& position) ;
template <typename PFP> template <typename PFP>
typename PFP::REAL convexPolyhedronVolume(typename PFP::MAP& map, Dart d, const VertexAttribute<typename PFP::VEC3>& position) ; typename PFP::REAL convexPolyhedronVolume(typename PFP::MAP& map, Dart d, const VertexAttribute<typename PFP::VEC3>& position, unsigned int thread=0) ;
template <typename PFP> template <typename PFP>
typename PFP::REAL totalVolume(typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3>& position, const FunctorSelect& select = allDarts) ; typename PFP::REAL totalVolume(typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3>& position, const FunctorSelect& select = allDarts, unsigned int thread = 0) ;
namespace Parallel
{
template <typename PFP>