Commit e9f09660 authored by Sylvain Thery's avatar Sylvain Thery

Merge branch 'problem_explode'

parents 2ccf806b 916836d9
...@@ -54,6 +54,21 @@ namespace Geometry ...@@ -54,6 +54,21 @@ 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, unsigned int thread = 0); EMB volumeCentroidGen(typename PFP::MAP& map, Dart d, const EMBV& attributs, unsigned int thread = 0);
/**
* Compute volume centroid weighted by edge length (generic version)
* Pre: closed volume & embedded vertices
* Template param:
* PFP: as usual
* EMBV: attributes vector type or cell type (VertexCell, FaceCell, ...)
* EMB: type of attribute (Geom::Vec3f) or cell type (VertexCell, FaceCell, ...)
* @param map the map
* @param d a dart of the face
* @param attributs the vector of attribute or cell
*/
template <typename PFP, typename EMBV, typename EMB>
EMB volumeCentroidELWGen(typename PFP::MAP& map, Dart d, const EMBV& attributs, unsigned int thread = 0);
/** /**
* Compute volume centroid * Compute volume centroid
* Pre: closed volume & embedded vertices * Pre: closed volume & embedded vertices
...@@ -62,11 +77,25 @@ EMB volumeCentroidGen(typename PFP::MAP& map, Dart d, const EMBV& attributs, uns ...@@ -62,11 +77,25 @@ EMB volumeCentroidGen(typename PFP::MAP& map, Dart d, const EMBV& attributs, uns
* @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, unsigned int thread = 0) inline 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, thread); return volumeCentroidGen<PFP, VertexAttribute<typename PFP::VEC3>, typename PFP::VEC3>(map, d, position, thread);
} }
/**
* Compute volume centroid weighted by edge length
* Pre: closed volume & embedded vertices
* @param map the map
* @param d a dart of the face
* @param position the vector of attribute
*/
template <typename PFP>
inline typename PFP::VEC3 volumeCentroidELW(typename PFP::MAP& map, Dart d, const VertexAttribute<typename PFP::VEC3>& position, unsigned int thread = 0)
{
return volumeCentroidELWGen<PFP, VertexAttribute<typename PFP::VEC3>, typename PFP::VEC3>(map, d, position, thread);
}
/** /**
* Compute face centroid (generic version) * Compute face centroid (generic version)
* Template param: * Template param:
...@@ -80,6 +109,19 @@ typename PFP::VEC3 volumeCentroid(typename PFP::MAP& map, Dart d, const VertexAt ...@@ -80,6 +109,19 @@ typename PFP::VEC3 volumeCentroid(typename PFP::MAP& map, Dart d, const VertexAt
template <typename PFP, typename EMBV, typename EMB> template <typename PFP, typename EMBV, typename EMB>
EMB faceCentroidGen(typename PFP::MAP& map, Dart d, const EMBV& attributs); EMB faceCentroidGen(typename PFP::MAP& map, Dart d, const EMBV& attributs);
/**
* Compute face centroid weighted by edge length (generic version)
* Template param:
* PFP: as usual
* EMBV: attributes vector type or cell type (VertexCell, FaceCell, ...)
* EMB: type of attribute (Geom::Vec3f) or cell type (VertexCell, FaceCell, ...)
* @param map the map
* @param d a dart of the face
* @param attributs the vector of attribute or cell
*/
template <typename PFP, typename EMBV, typename EMB>
EMB faceCentroidELWGen(typename PFP::MAP& map, Dart d, const EMBV& attributs);
/** /**
* Compute face centroid * Compute face centroid
* Pre: closed face & embedded vertices * Pre: closed face & embedded vertices
...@@ -93,6 +135,20 @@ typename PFP::VEC3 faceCentroid(typename PFP::MAP& map, Dart d, const VertexAttr ...@@ -93,6 +135,20 @@ typename PFP::VEC3 faceCentroid(typename PFP::MAP& map, Dart d, const VertexAttr
return faceCentroidGen<PFP, VertexAttribute<typename PFP::VEC3>, typename PFP::VEC3>(map, d, position); return faceCentroidGen<PFP, VertexAttribute<typename PFP::VEC3>, typename PFP::VEC3>(map, d, position);
} }
/**
* Compute face centroid weighted by edge length
* Pre: closed face & embedded vertices
* @param map the map
* @param d a dart of the face
* @param position the vector of attribute
*/
template <typename PFP>
typename PFP::VEC3 faceCentroidELW(typename PFP::MAP& map, Dart d, const VertexAttribute<typename PFP::VEC3>& position)
{
return faceCentroidELWGen<PFP, VertexAttribute<typename PFP::VEC3>, typename PFP::VEC3>(map, d, position);
}
/** /**
* Compute vertex neighbours centroid (generic version) * Compute vertex neighbours centroid (generic version)
* Template param: * Template param:
...@@ -118,11 +174,41 @@ typename PFP::VEC3 vertexNeighborhoodCentroid(typename PFP::MAP& map, Dart d, co ...@@ -118,11 +174,41 @@ typename PFP::VEC3 vertexNeighborhoodCentroid(typename PFP::MAP& map, Dart d, co
return vertexNeighborhoodCentroidGen<PFP, VertexAttribute<typename PFP::VEC3>, typename PFP::VEC3>(map, d, position); return vertexNeighborhoodCentroidGen<PFP, VertexAttribute<typename PFP::VEC3>, typename PFP::VEC3>(map, d, position);
} }
/**
* Compute centroid of all faces
* @param map the map
* @param position position vertex attribute
* @param face_centroid centroid face attribute
* @param select the selector
* @param thread the thread id (default 0)
*/
template <typename PFP> template <typename PFP>
void computeCentroidFaces(typename PFP::MAP& map, void computeCentroidFaces(typename PFP::MAP& map,
const VertexAttribute<typename PFP::VEC3>& position, FaceAttribute<typename PFP::VEC3>& face_centroid, const VertexAttribute<typename PFP::VEC3>& position, FaceAttribute<typename PFP::VEC3>& face_centroid,
const FunctorSelect& select = allDarts, unsigned int thread = 0) ; const FunctorSelect& select = allDarts, unsigned int thread = 0) ;
/**
* Compute centroid of all faces (Edge Length Weighted)
* @param map the map
* @param position position vertex attribute
* @param face_centroid centroid face attribute
* @param select the selector
* @param thread the thread id (default 0)
*/
template <typename PFP>
void computeCentroidELWFaces(typename PFP::MAP& map,
const VertexAttribute<typename PFP::VEC3>& position, FaceAttribute<typename PFP::VEC3>& face_centroid,
const FunctorSelect& select = allDarts, unsigned int thread = 0) ;
/**
* Compute neighborhood centroid of all vertices
* @param map the map
* @param position position vertex attribute
* @param vertex_centroid centroid vertex attribute
* @param select the selector
* @param thread the thread id (default 0)
*/
template <typename PFP> template <typename PFP>
void computeNeighborhoodCentroidVertices(typename PFP::MAP& map, void computeNeighborhoodCentroidVertices(typename PFP::MAP& map,
const VertexAttribute<typename PFP::VEC3>& position, VertexAttribute<typename PFP::VEC3>& vertex_centroid, const VertexAttribute<typename PFP::VEC3>& position, VertexAttribute<typename PFP::VEC3>& vertex_centroid,
...@@ -131,11 +217,40 @@ void computeNeighborhoodCentroidVertices(typename PFP::MAP& map, ...@@ -131,11 +217,40 @@ void computeNeighborhoodCentroidVertices(typename PFP::MAP& map,
namespace Parallel namespace Parallel
{ {
/**
* Compute centroid of all faces
* @param map the map
* @param position position vertex attribute
* @param face_centroid centroid face attribute
* @param select the selector
* @param nbth the number of threads
*/
template <typename PFP> template <typename PFP>
void computeCentroidFaces(typename PFP::MAP& map, void computeCentroidFaces(typename PFP::MAP& map,
const VertexAttribute<typename PFP::VEC3>& position, FaceAttribute<typename PFP::VEC3>& face_centroid, const VertexAttribute<typename PFP::VEC3>& position, FaceAttribute<typename PFP::VEC3>& face_centroid,
const FunctorSelect& select = allDarts, unsigned int nbth = 0) ; const FunctorSelect& select = allDarts, unsigned int nbth = 0) ;
/**
* Compute centroid of all faces (Edge Length Weighted)
* @param map the map
* @param position position vertex attribute
* @param face_centroid centroid face attribute
* @param select the selector
* @param nbth the number of threads
*/
template <typename PFP>
void computeCentroidELWFaces(typename PFP::MAP& map,
const VertexAttribute<typename PFP::VEC3>& position, FaceAttribute<typename PFP::VEC3>& face_centroid,
const FunctorSelect& select = allDarts, unsigned int nbth = 0) ;
/**
* Compute neighborhood centroid of all vertices (in parallel)
* @param map the map
* @param position position vertex attribute
* @param vertex_centroid centroid vertex attribute
* @param select the selector
* @param nbth the number of threads
*/
template <typename PFP> template <typename PFP>
void computeNeighborhoodCentroidVertices(typename PFP::MAP& map, void computeNeighborhoodCentroidVertices(typename PFP::MAP& map,
const VertexAttribute<typename PFP::VEC3>& position, VertexAttribute<typename PFP::VEC3>& vertex_centroid, const VertexAttribute<typename PFP::VEC3>& position, VertexAttribute<typename PFP::VEC3>& vertex_centroid,
...@@ -185,6 +300,11 @@ void computeCentroidVolumes(typename PFP::MAP& map, ...@@ -185,6 +300,11 @@ void computeCentroidVolumes(typename PFP::MAP& map,
const VertexAttribute<typename PFP::VEC3>& position, VolumeAttribute<typename PFP::VEC3>& vol_centroid, const VertexAttribute<typename PFP::VEC3>& position, VolumeAttribute<typename PFP::VEC3>& vol_centroid,
const FunctorSelect& select = allDarts, unsigned int thread = 0) ; const FunctorSelect& select = allDarts, unsigned int thread = 0) ;
template <typename PFP>
void computeCentroidELWVolumes(typename PFP::MAP& map,
const VertexAttribute<typename PFP::VEC3>& position, VolumeAttribute<typename PFP::VEC3>& vol_centroid,
const FunctorSelect& select = allDarts, unsigned int thread = 0) ;
/** /**
* compute centroid of all vertices * compute centroid of all vertices
* @param map the map * @param map the map
...@@ -206,6 +326,12 @@ void computeCentroidVolumes(typename PFP::MAP& map, ...@@ -206,6 +326,12 @@ void computeCentroidVolumes(typename PFP::MAP& map,
const VertexAttribute<typename PFP::VEC3>& position, VolumeAttribute<typename PFP::VEC3>& vol_centroid, const VertexAttribute<typename PFP::VEC3>& position, VolumeAttribute<typename PFP::VEC3>& vol_centroid,
const FunctorSelect& select = allDarts, unsigned int nbth = 0) ; const FunctorSelect& select = allDarts, unsigned int nbth = 0) ;
template <typename PFP>
void computeCentroidELWVolumes(typename PFP::MAP& map,
const VertexAttribute<typename PFP::VEC3>& position, VolumeAttribute<typename PFP::VEC3>& vol_centroid,
const FunctorSelect& select = allDarts, unsigned int nbth = 0) ;
template <typename PFP> template <typename PFP>
void computeNeighborhoodCentroidVertices(typename PFP::MAP& map, void computeNeighborhoodCentroidVertices(typename PFP::MAP& map,
const VertexAttribute<typename PFP::VEC3>& position, VertexAttribute<typename PFP::VEC3>& vertex_centroid, const VertexAttribute<typename PFP::VEC3>& position, VertexAttribute<typename PFP::VEC3>& vertex_centroid,
......
...@@ -59,6 +59,25 @@ EMB volumeCentroidGen(typename PFP::MAP& map, Dart d, const EMBV& attributs, uns ...@@ -59,6 +59,25 @@ EMB volumeCentroidGen(typename PFP::MAP& map, Dart d, const EMBV& attributs, uns
return center ; return center ;
} }
template <typename PFP, typename EMBV, typename EMB>
EMB volumeCentroidELWGen(typename PFP::MAP& map, Dart d, const EMBV& attributs, unsigned int thread)
{
EMB center = AttribOps::zero<EMB,PFP>();
double count=0.0;
Traversor3WE<typename PFP::MAP> t(map, d,false,thread) ;
for(Dart it = t.begin(); it != t.end();it = t.next())
{
EMB e1 = attributs[it];
EMB e2 = attributs[map.phi1(it)];
double l = (e2-e1).norm();
center += (e1+e2)*l;
count += 2.0*l ;
}
center /= double(count);
return center ;
}
template <typename PFP, typename EMBV, typename EMB> template <typename PFP, typename EMBV, typename EMB>
EMB faceCentroidGen(typename PFP::MAP& map, Dart d, const EMBV& attributs) EMB faceCentroidGen(typename PFP::MAP& map, Dart d, const EMBV& attributs)
{ {
...@@ -74,6 +93,26 @@ EMB faceCentroidGen(typename PFP::MAP& map, Dart d, const EMBV& attributs) ...@@ -74,6 +93,26 @@ EMB faceCentroidGen(typename PFP::MAP& map, Dart d, const EMBV& attributs)
return center ; return center ;
} }
template <typename PFP, typename EMBV, typename EMB>
EMB faceCentroidELWGen(typename PFP::MAP& map, Dart d, const EMBV& attributs)
{
EMB center = AttribOps::zero<EMB,PFP>();
double count=0.0;
Traversor2FE<typename PFP::MAP> t(map, d) ;
for(Dart it = t.begin(); it != t.end(); it = t.next())
{
EMB e1 = attributs[it];
EMB e2 = attributs[map.phi1(it)];
double l = (e2-e1).norm();
center += (e1+e2)*l;
count += 2.0*l ;
}
center /= double(count);
return center ;
}
template <typename PFP, typename EMBV, typename EMB> template <typename PFP, typename EMBV, typename EMB>
EMB vertexNeighborhoodCentroidGen(typename PFP::MAP& map, Dart d, const EMBV& attributs) EMB vertexNeighborhoodCentroidGen(typename PFP::MAP& map, Dart d, const EMBV& attributs)
{ {
...@@ -98,6 +137,14 @@ void computeCentroidFaces(typename PFP::MAP& map, const VertexAttribute<typename ...@@ -98,6 +137,14 @@ void computeCentroidFaces(typename PFP::MAP& map, const VertexAttribute<typename
face_centroid[d] = faceCentroid<PFP>(map, d, position) ; face_centroid[d] = faceCentroid<PFP>(map, d, position) ;
} }
template <typename PFP>
void computeCentroidELWFaces(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,thread) ;
for(Dart d = t.begin(); d != t.end(); d = t.next())
face_centroid[d] = faceCentroidELW<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, unsigned int thread) void computeNeighborhoodCentroidVertices(typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3>& position, VertexAttribute<typename PFP::VEC3>& vertex_centroid, const FunctorSelect& select, unsigned int thread)
{ {
...@@ -127,6 +174,23 @@ public: ...@@ -127,6 +174,23 @@ public:
} }
}; };
template <typename PFP>
class FunctorComputeCentroidELWFaces: public FunctorMapThreaded<typename PFP::MAP >
{
const VertexAttribute<typename PFP::VEC3>& m_position;
FaceAttribute<typename PFP::VEC3>& m_fcentroid;
public:
FunctorComputeCentroidELWFaces<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 run(Dart d, unsigned int threadID)
{
m_fcentroid[d] = faceCentroidELW<PFP>(this->m_map, d, m_position) ;
}
};
template <typename PFP> template <typename PFP>
void computeCentroidFaces(typename PFP::MAP& map, void computeCentroidFaces(typename PFP::MAP& map,
...@@ -137,6 +201,15 @@ void computeCentroidFaces(typename PFP::MAP& map, ...@@ -137,6 +201,15 @@ void computeCentroidFaces(typename PFP::MAP& map,
Algo::Parallel::foreach_cell<typename PFP::MAP,FACE>(map, funct, nbth, false, select, current_thread); Algo::Parallel::foreach_cell<typename PFP::MAP,FACE>(map, funct, nbth, false, select, current_thread);
} }
template <typename PFP>
void computeCentroidELWFaces(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)
{
FunctorComputeCentroidELWFaces<PFP> funct(map,position,face_centroid);
Algo::Parallel::foreach_cell<typename PFP::MAP,FACE>(map, funct, nbth, false, select, current_thread);
}
template <typename PFP> template <typename PFP>
class FunctorComputeNeighborhoodCentroidVertices: public FunctorMapThreaded<typename PFP::MAP > class FunctorComputeNeighborhoodCentroidVertices: public FunctorMapThreaded<typename PFP::MAP >
...@@ -195,6 +268,15 @@ void computeCentroidVolumes(typename PFP::MAP& map, const VertexAttribute<typena ...@@ -195,6 +268,15 @@ void computeCentroidVolumes(typename PFP::MAP& map, const VertexAttribute<typena
vol_centroid[d] = Surface::Geometry::volumeCentroid<PFP>(map, d, position,thread) ; vol_centroid[d] = Surface::Geometry::volumeCentroid<PFP>(map, d, position,thread) ;
} }
template <typename PFP>
void computeCentroidELWVolumes(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,thread) ;
for(Dart d = t.begin(); d != t.end(); d = t.next())
vol_centroid[d] = Surface::Geometry::volumeCentroidELW<PFP>(map, d, position,thread) ;
}
namespace Parallel namespace Parallel
{ {
template <typename PFP> template <typename PFP>
...@@ -213,6 +295,22 @@ public: ...@@ -213,6 +295,22 @@ public:
} }
}; };
template <typename PFP>
class FunctorComputeCentroidELWVolumes: public FunctorMapThreaded<typename PFP::MAP >
{
const VertexAttribute<typename PFP::VEC3>& m_position;
VolumeAttribute<typename PFP::VEC3>& m_vol_centroid;
public:
FunctorComputeCentroidELWVolumes<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 run(Dart d, unsigned int threadID)
{
m_vol_centroid[d] = Surface::Geometry::volumeCentroidELW<PFP>(this->m_map, d, m_position,threadID) ;
}
};
template <typename PFP> template <typename PFP>
void computeCentroidVolumes(typename PFP::MAP& map, void computeCentroidVolumes(typename PFP::MAP& map,
const VertexAttribute<typename PFP::VEC3>& position, VolumeAttribute<typename PFP::VEC3>& vol_centroid, const VertexAttribute<typename PFP::VEC3>& position, VolumeAttribute<typename PFP::VEC3>& vol_centroid,
...@@ -223,6 +321,16 @@ void computeCentroidVolumes(typename PFP::MAP& map, ...@@ -223,6 +321,16 @@ void computeCentroidVolumes(typename PFP::MAP& map,
} }
template <typename PFP>
void computeCentroidELWVolumes(typename PFP::MAP& map,
const VertexAttribute<typename PFP::VEC3>& position, VolumeAttribute<typename PFP::VEC3>& vol_centroid,
const FunctorSelect& select, unsigned int nbth)
{
FunctorComputeCentroidELWVolumes<PFP> funct(map,position,vol_centroid);
Algo::Parallel::foreach_cell<typename PFP::MAP,VOLUME>(map, funct, nbth, true, select);
}
template <typename PFP> template <typename PFP>
class FunctorComputeNeighborhoodCentroidVertices: public FunctorMapThreaded<typename PFP::MAP > class FunctorComputeNeighborhoodCentroidVertices: public FunctorMapThreaded<typename PFP::MAP >
{ {
...@@ -256,8 +364,6 @@ void computeNeighborhoodCentroidVertices(typename PFP::MAP& map, ...@@ -256,8 +364,6 @@ void computeNeighborhoodCentroidVertices(typename PFP::MAP& map,
} // namespace Algo } // namespace Algo
} // namespace CGoGN } // namespace CGoGN
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
#include "Topology/generic/cellmarker.h" #include "Topology/generic/cellmarker.h"
#include "Algo/Geometry/centroid.h" #include "Algo/Geometry/centroid.h"
#include "Topology/generic/autoAttributeHandler.h" #include "Topology/generic/autoAttributeHandler.h"
#include "Algo/Geometry/normal.h"
#include "Algo/Geometry/basic.h" #include "Algo/Geometry/basic.h"
namespace CGoGN namespace CGoGN
...@@ -99,7 +99,7 @@ void ExplodeVolumeRender::updateSmooth(typename PFP::MAP& map, const VertexAttri ...@@ -99,7 +99,7 @@ void ExplodeVolumeRender::updateSmooth(typename PFP::MAP& map, const VertexAttri
typedef typename PFP::REAL REAL; typedef typename PFP::REAL REAL;
VolumeAutoAttribute<VEC3> centerVolumes(map, "centerVolumes"); VolumeAutoAttribute<VEC3> centerVolumes(map, "centerVolumes");
Algo::Volume::Geometry::Parallel::computeCentroidVolumes<PFP>(map, positions, centerVolumes, good); Algo::Volume::Geometry::computeCentroidELWVolumes<PFP>(map, positions, centerVolumes, good);
std::vector<VEC3> buffer; std::vector<VEC3> buffer;
buffer.reserve(16384); buffer.reserve(16384);
...@@ -108,57 +108,97 @@ void ExplodeVolumeRender::updateSmooth(typename PFP::MAP& map, const VertexAttri ...@@ -108,57 +108,97 @@ void ExplodeVolumeRender::updateSmooth(typename PFP::MAP& map, const VertexAttri
bufferColors.reserve(16384); bufferColors.reserve(16384);
std::vector<VEC3> bufferNormals; std::vector<VEC3> bufferNormals;
bufferNormals.reserve(16384); bufferNormals.reserve(16384);
std::vector<VEC3> normals; std::vector<VEC3> normals;
bufferNormals.reserve(20); bufferNormals.reserve(20);
std::vector<VEC3> vertices;
bufferNormals.reserve(20);
TraversorCell<typename PFP::MAP, PFP::MAP::FACE_OF_PARENT> traFace(map, good); TraversorCell<typename PFP::MAP, PFP::MAP::FACE_OF_PARENT> traFace(map, good);
for (Dart d = traFace.begin(); d != traFace.end(); d = traFace.next()) for (Dart d = traFace.begin(); d != traFace.end(); d = traFace.next())
{ {
// compute normals // compute normals
normals.clear(); normals.clear();
VEC3 centerFace(0); vertices.clear();
unsigned int nbs=0; VEC3 centerFace = Algo::Surface::Geometry::faceCentroid<PFP>(map, d, positions);
VEC3 centerNormalFace = Algo::Surface::Geometry::newellNormal<PFP>(map,d,positions);
Dart a = d; Dart a = d;
do do
{ {
VEC3 v1 = Algo::Surface::Geometry::vectorOutOfDart<PFP>(map,a,positions); VEC3 v1 = positions[a] - centerFace;
v1.normalize();
Dart e = map.phi1(a); Dart e = map.phi1(a);
VEC3 v2 = Algo::Surface::Geometry::vectorOutOfDart<PFP>(map,e,positions); VEC3 v2 = positions[map.phi1(e)] - centerFace;
v2.normalize();
VEC3 N = v1^v2; VEC3 N = v1^v2;
N.normalize();
double l = N.norm();
if (l<0.01)
N = centerNormalFace;
else
{
N /= l;
if (N*centerNormalFace < 0.707)
N = centerNormalFace;
}
normals.push_back(N); normals.push_back(N);
vertices.push_back(positions[e]);
a = e; a = e;
centerFace += positions[a];
nbs++;
} while (a != d); } while (a != d);
centerFace /= float(nbs); VEC3 volCol = colorPerXXX[d];
unsigned int nbs = vertices.size();
// just to have more easy algo further
vertices.push_back(vertices.front());
normals.push_back(normals.front());
typename std::vector<VEC3>::iterator iv = vertices.begin();
typename std::vector<VEC3>::iterator in = normals.begin(); typename std::vector<VEC3>::iterator in = normals.begin();
a = d;
Dart b = map.phi1(a); if (nbs == 3)
Dart c = map.phi1(b);
// loop to cut a polygon in triangle on the fly (works only with convex faces)
do
{ {
buffer.push_back(centerVolumes[d]); buffer.push_back(centerVolumes[d]);
bufferColors.push_back(centerFace); bufferColors.push_back(centerFace);
bufferNormals.push_back(centerFace); // unsused just for fill bufferNormals.push_back(centerNormalFace); // unsused just for fill
buffer.push_back(positions[d]);
bufferColors.push_back(colorPerXXX[d]); buffer.push_back(*iv++);
bufferNormals.push_back(normals.back());
buffer.push_back(positions[b]);
bufferColors.push_back(colorPerXXX[b]);
bufferNormals.push_back(*in++); bufferNormals.push_back(*in++);
buffer.push_back(positions[c]); bufferColors.push_back(volCol);
bufferColors.push_back(colorPerXXX[c]);
buffer.push_back(*iv++);
bufferNormals.push_back(*in++);
bufferColors.push_back(volCol);