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
* @param attributs the vector of attribute or cell
*/
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
......@@ -59,9 +59,9 @@ EMB volumeCentroidGen(typename PFP::MAP& map, Dart d, const EMBV& attributs);
* @param position the vector of attribute
*/
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
}
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>
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>
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
......
......@@ -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 <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>() ;
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())
{
center += attributs[d];
......@@ -86,29 +87,126 @@ EMB vertexNeighborhoodCentroidGen(typename PFP::MAP& map, Dart d, const EMBV& at
}
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())
vol_centroid[d] = volumeCentroid<PFP>(map, d, position) ;
vol_centroid[d] = volumeCentroid<PFP>(map, d, position,thread) ;
}
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())
face_centroid[d] = faceCentroid<PFP>(map, d, 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)
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())
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 Algo
......
......@@ -101,7 +101,7 @@ void computeCurvatureVertices_NormalCycles(
VertexAttribute<typename PFP::VEC3>& Kmax,
VertexAttribute<typename PFP::VEC3>& Kmin,
VertexAttribute<typename PFP::VEC3>& Knormal,
const FunctorSelect& select = allDarts) ;
const FunctorSelect& select = allDarts, unsigned int thread=0) ;
template <typename PFP>
void computeCurvatureVertex_NormalCycles(
......@@ -115,10 +115,29 @@ void computeCurvatureVertex_NormalCycles(
VertexAttribute<typename PFP::REAL>& kmin,
VertexAttribute<typename PFP::VEC3>& Kmax,
VertexAttribute<typename PFP::VEC3>& Kmin,
VertexAttribute<typename PFP::VEC3>& Knormal) ;
VertexAttribute<typename PFP::VEC3>& Knormal, unsigned int thread=0) ;
} // 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 CGoGN
......
......@@ -289,11 +289,11 @@ void computeCurvatureVertices_NormalCycles(
VertexAttribute<typename PFP::VEC3>& Kmax,
VertexAttribute<typename PFP::VEC3>& Kmin,
VertexAttribute<typename PFP::VEC3>& Knormal,
const FunctorSelect& select)
const FunctorSelect& select, unsigned int thread)
{
TraversorV<typename PFP::MAP> t(map, select) ;
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>
......@@ -308,12 +308,12 @@ void computeCurvatureVertex_NormalCycles(
VertexAttribute<typename PFP::REAL>& kmin,
VertexAttribute<typename PFP::VEC3>& Kmax,
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::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.computeArea() ;
......@@ -379,6 +379,73 @@ void computeCurvatureVertex_NormalCycles(
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 Algo
......
......@@ -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 <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) ;
/**
* compute normals of vertices
* @param map the map on which we work
......@@ -65,12 +67,26 @@ void computeNormalFaces(typename PFP::MAP& map, const VertexAttribute<typename P
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) ;
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>
typename PFP::REAL computeAngleBetweenNormalsOnEdge(typename PFP::MAP& map, Dart d, VertexAttribute<typename PFP::VEC3>& position) ;
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) ;
} // namespace Geometry
} // namespace Algo
......
......@@ -28,6 +28,8 @@
#include "Topology/generic/traversorCell.h"
#include "Topology/generic/traversor2.h"
#include "Algo/Parallel/parallel_foreach.h"
#include <cmath>
namespace CGoGN
......@@ -163,6 +165,62 @@ void computeNormalVertices(typename PFP::MAP& map, const VertexAttribute<typenam
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>
typename PFP::REAL computeAngleBetweenNormalsOnEdge(typename PFP::MAP& map, Dart d, const VertexAttribute<typename PFP::VEC3>& position)
{
......
......@@ -43,10 +43,18 @@ template <typename PFP>
typename PFP::REAL tetrahedronVolume(typename PFP::MAP& map, Dart d, const VertexAttribute<typename PFP::VEC3>& position) ;
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>
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>
typename PFP::REAL totalVolume(typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3>& position, const FunctorSelect& select = allDarts, unsigned int nbth = 0, unsigned int current_thread = 0) ;
}
} // namespace Geometry
......
......@@ -58,18 +58,18 @@ typename PFP::REAL tetrahedronVolume(typename PFP::MAP& map, Dart d, const Verte
}
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)
{
typedef typename PFP::VEC3 VEC3;
if(Modelisation::Tetrahedralization::isTetrahedron<PFP>(map,d))
if(Modelisation::Tetrahedralization::isTetrahedron<PFP>(map,d,thread))
return tetrahedronVolume<PFP>(map,d,position) ;
else
{
typename PFP::REAL vol = 0 ;
VEC3 vCentroid = Algo::Geometry::volumeCentroid<PFP>(map, d, position) ;
VEC3 vCentroid = Algo::Geometry::volumeCentroid<PFP>(map, d, position, thread) ;
DartMarkerStore mark(map); // Lock a marker
DartMarkerStore mark(map,thread); // Lock a marker
std::vector<Dart> visitedFaces ;
visitedFaces.reserve(100) ;
......@@ -115,15 +115,69 @@ typename PFP::REAL convexPolyhedronVolume(typename PFP::MAP& map, Dart d, const
}
template <typename PFP>
float totalVolume(typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3>& position, const FunctorSelect& select)
typename PFP::REAL totalVolume(typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3>& position, const FunctorSelect& select, unsigned int thread)
{
typename PFP::REAL vol = 0 ;
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())
vol += convexPolyhedronVolume<PFP>(map, d, position) ;
vol += convexPolyhedronVolume<PFP>(map, d, position,thread) ;
return vol ;
}
namespace Parallel
{
template <typename PFP>
class FunctorTotalVolume: public FunctorMapThreaded<typename PFP::MAP >
{
const VertexAttribute<typename PFP::VEC3>& m_position;
typename PFP::REAL m_vol;
public:
FunctorTotalVolume<PFP>( typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3>& position):
FunctorMapThreaded<typename PFP::MAP>(map), m_position(position), m_vol(0.0)
{ }
void parallelDo(Dart d, unsigned int threadID)
{
m_vol += convexPolyhedronVolume<PFP>(this->m_map, d, m_position,threadID) ;
}
typename PFP::REAL getVol() const
{
return m_vol;
}
};
template <typename PFP>
typename PFP::REAL totalVolume(typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3>& position, const FunctorSelect& select, unsigned int nbth, unsigned int current_thread)
{
if (nbth==0)
nbth = Algo::Parallel::optimalNbThreads();
std::vector<FunctorMapThreaded<typename PFP::MAP>*> functs;
for (unsigned int i=0; i < nbth; ++i)
{
functs.push_back(new FunctorTotalVolume<PFP>(map,position));
}
typename PFP::REAL total=0.0;
Algo::Parallel::foreach_cell<typename PFP::MAP,VOLUME>(map, functs, nbth, true, select, current_thread);
for (unsigned int i=0; i < nbth; ++i)
{
total += reinterpret_cast<FunctorTotalVolume<PFP>*>(functs[i])->getVol();
delete functs[i];
}
return total;
}
}
} // namespace Geometry
} // namespace Algo
......
......@@ -70,7 +70,7 @@ Dart splitVertex(typename PFP::MAP& map, std::vector<Dart>& vd);
* @param a dart from the volume
*/
template <typename PFP>
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
......
......@@ -216,12 +216,12 @@ Dart splitVertex(typename PFP::MAP& map, std::vector<Dart>& vd)
************************************************************************************************/
template <typename PFP>
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<typename PFP::MAP> travWF(the_map, d);
Traversor3WF<typename PFP::MAP> travWF(the_map, d, false, thread);
for(Dart dit = travWF.begin() ; dit != travWF.end(); dit = travWF.next())
{
//increase the number of faces
......
/*******************************************************************************
* 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. *
* *