Commit 48357051 authored by untereiner's avatar untereiner

Merge cgogn:~thery/CGoGN

parents 726113c5 038eb8d7
......@@ -81,6 +81,12 @@ protected:
GLuint m_nbLines;
Geom::Vec3f m_globalColor;
template<typename PFP>
void computeFace(typename PFP::MAP& map, Dart d, const VertexAttribute<typename PFP::VEC3>& positions,
const typename PFP::VEC3& centerFace, const typename PFP::VEC3& centerNormalFace,
std::vector<typename PFP::VEC3>& vertices, std::vector<typename PFP::VEC3>& normals);
template<typename PFP>
void updateSmooth(typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3>& positions, const VolumeAttribute<typename PFP::VEC3>& colorPerFace, const FunctorSelect& good = allDarts) ;
......
......@@ -91,6 +91,44 @@ inline ExplodeVolumeRender::~ExplodeVolumeRender()
}
template<typename PFP>
void ExplodeVolumeRender::computeFace(typename PFP::MAP& map, Dart d, const VertexAttribute<typename PFP::VEC3>& positions,
const typename PFP::VEC3& centerFace, const typename PFP::VEC3& centerNormalFace,
std::vector<typename PFP::VEC3>& vertices, std::vector<typename PFP::VEC3>& normals)
{
typedef typename PFP::VEC3 VEC3;
typedef typename PFP::REAL REAL;
normals.clear();
vertices.clear();
Dart a = d;
do
{
VEC3 v1 = positions[a] - centerFace;
v1.normalize();
Dart e = map.phi1(a);
VEC3 v2 = positions[e] - centerFace;
v2.normalize();
VEC3 N = v1^v2;
normals.push_back(N);
vertices.push_back(positions[a]);
a = e;
} while (a != d);
unsigned int nb = normals.size();
VEC3 Ntemp = normals[0];
normals[0] += normals[nb-1];
normals[0].normalize();
for (unsigned int i=1; i!=nb ; ++i)
{
VEC3 Ntemp2 = normals[i];
normals[i] += Ntemp;
normals[i].normalize();
Ntemp = Ntemp2;
}
}
template<typename PFP>
void ExplodeVolumeRender::updateSmooth(typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3>& positions, const VolumeAttribute<typename PFP::VEC3>& colorPerXXX, const FunctorSelect& good)
......@@ -110,46 +148,21 @@ void ExplodeVolumeRender::updateSmooth(typename PFP::MAP& map, const VertexAttri
bufferNormals.reserve(16384);
std::vector<VEC3> normals;
bufferNormals.reserve(20);
normals.reserve(20);
std::vector<VEC3> vertices;
bufferNormals.reserve(20);
vertices.reserve(20);
TraversorCell<typename PFP::MAP, PFP::MAP::FACE_OF_PARENT> traFace(map, good);
for (Dart d = traFace.begin(); d != traFace.end(); d = traFace.next())
{
// compute normals
normals.clear();
vertices.clear();
VEC3 centerFace = Algo::Surface::Geometry::faceCentroid<PFP>(map, d, positions);
VEC3 centerFace = Algo::Surface::Geometry::faceCentroidELW<PFP>(map, d, positions);
VEC3 centerNormalFace = Algo::Surface::Geometry::newellNormal<PFP>(map,d,positions);
Dart a = d;
do
{
VEC3 v1 = positions[a] - centerFace;
v1.normalize();
Dart e = map.phi1(a);
VEC3 v2 = positions[map.phi1(e)] - centerFace;
v2.normalize();
VEC3 N = v1^v2;
double l = N.norm();
if (l<0.01)
N = centerNormalFace;
else
{
N /= l;
if (N*centerNormalFace < 0.707)
N = centerNormalFace;
}
normals.push_back(N);
vertices.push_back(positions[e]);
a = e;
} while (a != d);
computeFace<PFP>(map,d,positions,centerFace,centerNormalFace,vertices,normals);
VEC3 volCol = colorPerXXX[d];
unsigned int nbs = vertices.size();
......@@ -272,36 +285,11 @@ void ExplodeVolumeRender::updateSmooth(typename PFP::MAP& map, const VertexAttri
for (Dart d = traFace.begin(); d != traFace.end(); d = traFace.next())
{
// compute normals
normals.clear();
vertices.clear();
VEC3 centerFace = Algo::Surface::Geometry::faceCentroid<PFP>(map, d, positions);
VEC3 centerFace = Algo::Surface::Geometry::faceCentroidELW<PFP>(map, d, positions);
VEC3 centerNormalFace = Algo::Surface::Geometry::newellNormal<PFP>(map,d,positions);
Dart a = d;
do
{
VEC3 v1 = positions[a] - centerFace;
v1.normalize();
Dart e = map.phi1(a);
VEC3 v2 = positions[map.phi1(e)] - centerFace;
v2.normalize();
VEC3 N = v1^v2;
double l = N.norm();
if (l<0.01)
N = centerNormalFace;
else
{
N /= l;
if (N*centerNormalFace < 0.707)
N = centerNormalFace;
}
normals.push_back(N);
vertices.push_back(positions[e]);
a = e;
} while (a != d);
computeFace<PFP>(map,d,positions,centerFace,centerNormalFace,vertices,normals);
unsigned int nbs = vertices.size();
// just to have more easy algo further
vertices.push_back(vertices.front());
......
......@@ -83,7 +83,7 @@ void Topo3Render::updateDataMap3(typename PFP::MAP& mapx, const VertexAttribute<
CellMarker<VOLUME> cmv(mapx);
VolumeAutoAttribute<VEC3> centerVolumes(mapx, "centerVolumes");
Algo::Volume::Geometry::Parallel::computeCentroidVolumes<PFP>(mapx, positions, centerVolumes, allDarts,3);
Algo::Volume::Geometry::Parallel::computeCentroidELWVolumes<PFP>(mapx, positions, centerVolumes, allDarts,3);
// debut phi1
......@@ -123,27 +123,21 @@ void Topo3Render::updateDataMap3(typename PFP::MAP& mapx, const VertexAttribute<
float okv = 1.0f - kv;
VEC3 vc = centerVolumes[d];
VEC3 centerFace(0, 0, 0);
VEC3 centerFace = Algo::Surface::Geometry::faceCentroidELW<PFP>(mapx,d,positions)*kv +vc*okv;
//shrink the face
float okf = 1.0f - kf;
Dart dd = d;
do
{
VEC3 P = positions[dd];
P = vc*okv + P*kv;
VEC3 P = centerFace*okf + (vc*okv + positions[dd]*kv)*kf;
vecPos.push_back(P);
centerFace += P;
dd = mapx.phi1(dd);
} while (dd != d);
centerFace /= REAL(vecPos.size());
//shrink the face
unsigned int nb = vecPos.size();
float okf = 1.0f - kf;
for (unsigned int i = 0; i < nb; ++i)
{
vecPos[i] = centerFace*okf + vecPos[i]*kf;
}
vecPos.push_back(vecPos.front()); // copy the first for easy computation on next loop
// compute position of points to use for drawing topo
......@@ -338,7 +332,7 @@ void Topo3Render::updateDataGMap3(typename PFP::MAP& mapx, const VertexAttribute
// compute center of each volumes
VolumeAutoAttribute<VEC3> centerVolumes(mapx, "centerVolumes");
Algo::Volume::Geometry::Parallel::computeCentroidVolumes<PFP>(mapx, positions, centerVolumes, good);
Algo::Volume::Geometry::Parallel::computeCentroidELWVolumes<PFP>(mapx, positions, centerVolumes, good);
// beta1
DartAutoAttribute<VEC3> fv1(mapx);
......@@ -379,27 +373,22 @@ void Topo3Render::updateDataGMap3(typename PFP::MAP& mapx, const VertexAttribute
float okv = 1.0f - kv;
VEC3 vc = centerVolumes[d];
VEC3 centerFace(0, 0, 0);
VEC3 centerFace = Algo::Surface::Geometry::faceCentroidELW<PFP>(mapx,d,positions)*kv +vc*okv;
//shrink the face
float okf = 1.0f - kf;
Dart dd = d;
do
{
VEC3 P = positions[dd];
P = vc*okv + P*kv;
VEC3 P = centerFace*okf + (vc*okv + positions[dd]*kv)*kf;
vecPos.push_back(P);
centerFace += P;
dd = mapx.phi1(dd);
} while (dd != d);
centerFace /= REAL(vecPos.size());
//shrink the face
unsigned int nb = vecPos.size();
float okf = 1.0f - kf;
for (unsigned int i = 0; i < nb; ++i)
{
vecPos[i] = centerFace*okf + vecPos[i]*kf;
}
vecPos.push_back(vecPos.front()); // copy the first for easy computation on next loop
// compute position of points to use for drawing topo
......
......@@ -31,6 +31,8 @@
#include "Topology/gmap/embeddedGMap2.h"
#include "Geometry/distances.h"
#include "Algo/Geometry/centroid.h"
namespace CGoGN
{
......@@ -117,30 +119,21 @@ void TopoRender::updateDataMap(typename PFP::MAP& mapx, const VertexAttribute<ty
Dart d = *id;
if (!mf.isMarked(d))
{
vecPos.clear();
// store the face & center
VEC3 center(0.0f,0.0f,0.0f);
VEC3 center = Algo::Surface::Geometry::faceCentroidELW<PFP>(mapx,d,positions);
float k = 1.0f - kf;
Dart dd = d;
do
{
const VEC3& P = positions[d];
vecPos.push_back(P);
center += P;
Dart e = map.phi1(d);
d = e;
} while (d != dd);
center /= REAL(vecPos.size());
//shrink the face
vecPos.push_back(center*k + positions[dd]*kf);
dd = map.phi1(dd);
} while (dd != d);
unsigned int nb = vecPos.size();
float k = 1.0f - kf;
for (unsigned int i = 0; i < nb; ++i)
{
vecPos[i] = center*k + vecPos[i]*kf;
}
vecPos.push_back(vecPos.front()); // copy the first for easy computation on next loop
k = 1.0f - ke;
for (unsigned int i = 0; i < nb; ++i)
{
......@@ -266,25 +259,17 @@ void TopoRender::updateDataGMap(typename PFP::MAP& mapx, const VertexAttribute<t
if (!mf.isMarked(d))
{
vecPos.clear();
// store the face & center
VEC3 center(0.0f,0.0f,0.0f);
VEC3 center = Algo::Surface::Geometry::faceCentroidELW<PFP>(mapx,d,positions);
float k = 1.0f - kf;
Dart dd = d;
do
{
const VEC3& P = positions[d];
vecPos.push_back(P);
center += P;
d = map.phi1(d);
} while (d != dd);
center /= REAL(vecPos.size());
vecPos.push_back(center*k + positions[dd]*kf);
dd = map.phi1(dd);
} while (dd != d);
//shrink the face
unsigned int nb = vecPos.size();
float k = 1.0f - kf;
for (unsigned int i = 0; i < nb; ++i)
{
vecPos[i] = center*k + vecPos[i]*kf;
}
vecPos.push_back(vecPos.front()); // copy the first for easy computation on next loop
k = 1.0f - ke;
......
......@@ -117,7 +117,11 @@ public:
Vector<DIM, T> operator-() const ;
Vector<DIM, T> operator*(T a) const ;
Vector<DIM, T> operator*(T a) const ;
// template <typename T2>
// Vector<DIM, T> operator*(T2 a) const ;
Vector<DIM, T> operator/(T a) const ;
......@@ -208,8 +212,8 @@ bool isNull(T x, int precision = 0) ;
template <typename T>
bool isNull2(T x, int precision = 0) ;
template <unsigned int DIM, typename T>
Vector<DIM, T> operator*(T a, const Vector<DIM, T>& v) ;
// template <unsigned int DIM, typename T>
// Vector<DIM, T> operator*(T a, const Vector<DIM, T>& v) ;
template <unsigned int DIM, typename T>
Vector<DIM, T> operator/(T a, const Vector<DIM, T>& v) ;
......@@ -222,6 +226,9 @@ T tripleProduct(const Vector<DIM, T>& v1, const Vector<DIM, T>& v2, const Vector
template <unsigned int DIM, typename T>
Vector<DIM, T> slerp(const Vector<DIM, T> &v1, const Vector<DIM, T> &v2, const T &t) ;
template <unsigned int DIM, typename T, typename T2>
Vector<DIM, T> operator*(T2 b, const Vector<DIM, T>& v);
/**********************************************/
/* SOME USEFUL TYPEDEFS */
......
......@@ -405,12 +405,13 @@ inline bool isNull2(T x, int precision)
return (isNull(x, - (precision * precision))) ;
}
template <unsigned int DIM, typename T>
inline Vector<DIM, T> operator*(T a, const Vector<DIM, T>& v)
template <unsigned int DIM, typename T, typename T2>
inline Vector<DIM, T> operator*(T2 b, const Vector<DIM, T>& v)
{
return v * a ;
return v * T(b) ;
}
template <unsigned int DIM, typename T>
inline Vector<DIM, T> operator/(T a, const Vector<DIM, T>& v)
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment