Commit 7044f2cf authored by Sylvain Thery's avatar Sylvain Thery

enhancement of ExplodeVolumeRender

parent 090ec7e8
......@@ -54,6 +54,21 @@ namespace Geometry
template <typename PFP, typename EMBV, typename EMB>
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
* Pre: closed volume & embedded vertices
......@@ -62,11 +77,25 @@ EMB volumeCentroidGen(typename PFP::MAP& map, Dart d, const EMBV& attributs, uns
* @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, 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);
}
/**
* 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)
* Template param:
......@@ -80,6 +109,19 @@ typename PFP::VEC3 volumeCentroid(typename PFP::MAP& map, Dart d, const VertexAt
template <typename PFP, typename EMBV, typename EMB>
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
* Pre: closed face & embedded vertices
......@@ -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);
}
/**
* 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)
* Template param:
......@@ -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);
}
/**
* 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>
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) ;
/**
* 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>
void computeNeighborhoodCentroidVertices(typename PFP::MAP& map,
const VertexAttribute<typename PFP::VEC3>& position, VertexAttribute<typename PFP::VEC3>& vertex_centroid,
......@@ -131,11 +217,40 @@ void computeNeighborhoodCentroidVertices(typename PFP::MAP& map,
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>
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) ;
/**
* 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>
void computeNeighborhoodCentroidVertices(typename PFP::MAP& map,
const VertexAttribute<typename PFP::VEC3>& position, VertexAttribute<typename PFP::VEC3>& vertex_centroid,
......@@ -185,6 +300,11 @@ 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 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
* @param map the map
......@@ -206,6 +326,12 @@ 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) ;
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>
void computeNeighborhoodCentroidVertices(typename PFP::MAP& map,
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
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>
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 ;
}
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>
EMB vertexNeighborhoodCentroidGen(typename PFP::MAP& map, Dart d, const EMBV& attributs)
{
......@@ -98,6 +137,14 @@ void computeCentroidFaces(typename PFP::MAP& map, const VertexAttribute<typename
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>
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:
}
};
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>
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);
}
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>
class FunctorComputeNeighborhoodCentroidVertices: public FunctorMapThreaded<typename PFP::MAP >
......@@ -195,6 +268,15 @@ void computeCentroidVolumes(typename PFP::MAP& map, const VertexAttribute<typena
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
{
template <typename PFP>
......@@ -212,6 +294,22 @@ public:
m_vol_centroid[d] = Surface::Geometry::volumeCentroid<PFP>(this->m_map, d, m_position,threadID) ;
}
};
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>
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>
class FunctorComputeNeighborhoodCentroidVertices: public FunctorMapThreaded<typename PFP::MAP >
{
......@@ -256,8 +364,6 @@ void computeNeighborhoodCentroidVertices(typename PFP::MAP& map,
} // namespace Algo
} // namespace CGoGN
......@@ -114,6 +114,8 @@ public:
Vector<DIM, T> operator+(const Vector<DIM, T>& v) const ;
Vector<DIM, T> operator-(const Vector<DIM, T>& v) const ;
Vector<DIM, T> operator-() const ;
Vector<DIM, T> operator*(T a) const ;
......
......@@ -210,6 +210,16 @@ inline Vector<DIM, T> Vector<DIM, T>::operator-(const Vector<DIM, T>& v) const
return res ;
}
template <unsigned int DIM, typename T>
inline Vector<DIM, T> Vector<DIM, T>::operator-() const
{
Vector<DIM, T> res ;
for (unsigned int i = 0; i < DIM; ++i)
res[i] = - m_data[i] ;
return res ;
}
template <unsigned int DIM, typename T>
inline Vector<DIM, T> Vector<DIM, T>::operator*(T a) const
{
......
// ShaderExplodeSmoothVolumes::fragmentShaderText
uniform vec4 ambient;
uniform vec4 backColor;
VARYING_FRAG vec3 normalFS;
VARYING_FRAG vec3 lightFS;
......@@ -10,10 +9,6 @@ VARYING_FRAG vec3 colorVert;
void main()
{
float lambertTerm = dot(normalize(normalFS),normalize(lightFS));
if (lambertTerm > 0.0)
gl_FragColor = ambient + vec4(colorVert*lambertTerm, 1.0);
else
gl_FragColor = ambient - backColor*lambertTerm;
float lambertTerm = abs(dot(normalize(normalFS),normalize(lightFS)));
gl_FragColor = ambient + vec4(colorVert*lambertTerm, 1.0);
}
......@@ -44,7 +44,6 @@ protected:
// uniform locations
CGoGNGLuint m_unif_ambiant;
CGoGNGLuint m_unif_backColor;
CGoGNGLuint m_unif_lightPos;
CGoGNGLuint m_unif_explodeV;
CGoGNGLuint m_unif_explodeF;
......@@ -54,7 +53,6 @@ protected:
float m_explodeV;
float m_explodeF;
Geom::Vec4f m_ambiant;
Geom::Vec4f m_backColor;
Geom::Vec3f m_light_pos;
Geom::Vec4f m_plane;
......@@ -79,13 +77,11 @@ public:
void setAmbiant(const Geom::Vec4f& ambiant);
void setBackColor(const Geom::Vec4f& backColor);
void setLightPosition(const Geom::Vec3f& lp);
void setClippingPlane(const Geom::Vec4f& plane);
void setParams(float explodeV, float explodeF, const Geom::Vec4f& ambiant, const Geom::Vec4f& diffuse, const Geom::Vec3f& lightPos, const Geom::Vec4f& plane);
void setParams(float explodeV, float explodeF, const Geom::Vec4f& ambiant, const Geom::Vec3f& lightPos, const Geom::Vec4f& plane);
unsigned int setAttributePosition(VBO* vbo);
......
......@@ -67,11 +67,10 @@ ShaderExplodeSmoothVolumes::ShaderExplodeSmoothVolumes(bool withColorPerFace, bo
m_explodeV = 0.9f;
m_explodeF = 0.9f;
m_ambiant = Geom::Vec4f(0.05f, 0.05f, 0.1f, 0.0f);
m_backColor = Geom::Vec4f(1.0f, 0.1f, 0.1f, 0.0f);
m_light_pos = Geom::Vec3f(10.0f, 10.0f, 1000.0f);
m_plane = Geom::Vec4f(0.0f, 0.0f, 1000.f, 1000000000000000000000000000.0f);
setParams(m_explodeV, m_explodeF, m_ambiant, m_backColor, m_light_pos, m_plane);
setParams(m_explodeV, m_explodeF, m_ambiant, m_light_pos, m_plane);
}
void ShaderExplodeSmoothVolumes::getLocations()
......@@ -80,7 +79,6 @@ void ShaderExplodeSmoothVolumes::getLocations()
*m_unif_explodeV = glGetUniformLocation(program_handler(),"explodeV");
*m_unif_explodeF = glGetUniformLocation(program_handler(),"explodeF");
*m_unif_ambiant = glGetUniformLocation(program_handler(),"ambient");
*m_unif_backColor = glGetUniformLocation(program_handler(),"backColor");
*m_unif_lightPos = glGetUniformLocation(program_handler(),"lightPosition");
*m_unif_plane = glGetUniformLocation(program_handler(),"plane");
unbind();
......@@ -114,7 +112,7 @@ unsigned int ShaderExplodeSmoothVolumes::setAttributeNormal(VBO* vbo)
}
void ShaderExplodeSmoothVolumes::setParams(float explV, float explF, const Geom::Vec4f& ambiant, const Geom::Vec4f& backColor, const Geom::Vec3f& lightPos, const Geom::Vec4f& plane)
void ShaderExplodeSmoothVolumes::setParams(float explV, float explF, const Geom::Vec4f& ambiant, const Geom::Vec3f& lightPos, const Geom::Vec4f& plane)
{
bind();
m_explodeV = explV;
......@@ -123,9 +121,6 @@ void ShaderExplodeSmoothVolumes::setParams(float explV, float explF, const Geom:
glUniform1f(*m_unif_explodeF, explF);
m_ambiant = ambiant;
glUniform4fv(*m_unif_ambiant, 1, ambiant.data());
m_backColor = backColor;
glUniform4fv(*m_unif_backColor, 1, backColor.data());
m_light_pos = lightPos;
glUniform3fv(*m_unif_lightPos, 1, lightPos.data());
......@@ -159,13 +154,7 @@ void ShaderExplodeSmoothVolumes::setAmbiant(const Geom::Vec4f& ambiant)
unbind();
}
void ShaderExplodeSmoothVolumes::setBackColor(const Geom::Vec4f& backColor)
{
m_backColor = backColor;
bind();
glUniform4fv(*m_unif_backColor, 1, backColor.data());
unbind();
}
void ShaderExplodeSmoothVolumes::setLightPosition(const Geom::Vec3f& lp)
{
......@@ -196,9 +185,6 @@ void ShaderExplodeSmoothVolumes::restoreUniformsAttribs()
*m_unif_ambiant = glGetUniformLocation(program_handler(),"ambient");
glUniform4fv(*m_unif_ambiant, 1, m_ambiant.data());
*m_unif_backColor = glGetUniformLocation(program_handler(),"backColor");
glUniform4fv(*m_unif_backColor, 1, m_backColor.data());
*m_unif_lightPos = glGetUniformLocation(program_handler(),"lightPosition");
glUniform3fv(*m_unif_lightPos, 1, m_light_pos.data());
......
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