Commit 7cb42175 authored by Kenneth Vanhoey's avatar Kenneth Vanhoey

clamping for cos_angle function

parent 52c137ae
......@@ -59,13 +59,24 @@ void sigmaBilateral(typename PFP::MAP& map, const VertexAttribute<typename PFP::
sigmaS = 2.5f * ( sumAngles / float(nbEdges) ) ;
}
/**
* \brief Function applying a bilateral filter smoothing on the mesh.
* \param map the map of the mesh
* \param positionIn the current positions container of the mesh
* \param positionOut the smoothed positions after the function call
* \param normal the normals
*/
template <typename PFP>
void filterBilateral(typename PFP::MAP& map, const VertexAttribute<typename PFP::VEC3, typename PFP::MAP>& position, VertexAttribute<typename PFP::VEC3, typename PFP::MAP>& position2, const VertexAttribute<typename PFP::VEC3, typename PFP::MAP>& normal)
void filterBilateral(
typename PFP::MAP& map,
const VertexAttribute<typename PFP::VEC3,typename PFP::MAP>& positionIn,
VertexAttribute<typename PFP::VEC3,typename PFP::MAP>& positionOut,
const VertexAttribute<typename PFP::VEC3,typename PFP::MAP>& normal)
{
typedef typename PFP::VEC3 VEC3 ;
float sigmaC, sigmaS ;
sigmaBilateral<PFP>(map, position, normal, sigmaC, sigmaS) ;
sigmaBilateral<PFP>(map, positionIn, normal, sigmaC, sigmaS) ;
TraversorV<typename PFP::MAP> t(map) ;
for(Dart d = t.begin(); d != t.end(); d = t.next())
......@@ -80,7 +91,7 @@ void filterBilateral(typename PFP::MAP& map, const VertexAttribute<typename PFP:
Traversor2VE<typename PFP::MAP> te(map, d) ;
for(Dart it = te.begin(); it != te.end(); it = te.next())
{
VEC3 vec = Algo::Surface::Geometry::vectorOutOfDart<PFP>(map, it, position) ;
VEC3 vec = Algo::Surface::Geometry::vectorOutOfDart<PFP>(map, it, positionIn) ;
float h = normal_d * vec ;
float t = vec.norm() ;
float wcs = exp( ( -1.0f * (t * t) / (2.0f * sigmaC * sigmaC) ) + ( -1.0f * (h * h) / (2.0f * sigmaS * sigmaS) ) ) ;
......@@ -88,10 +99,10 @@ void filterBilateral(typename PFP::MAP& map, const VertexAttribute<typename PFP:
normalizer += wcs ;
}
position2[d] = position[d] + ((sum / normalizer) * normal_d) ;
positionOut[d] = positionIn[d] + ((sum / normalizer) * normal_d) ;
}
else
position2[d] = position[d] ;
positionOut[d] = positionIn[d] ;
}
}
......
This diff is collapsed.
......@@ -76,9 +76,11 @@ Vector<DIM,T> isobarycenter(const Vector<DIM,T>& v1, const Vector<DIM,T>& v2, co
template <typename VEC>
typename VEC::DATA_TYPE cos_angle(const VEC& a, const VEC& b)
{
typename VEC::DATA_TYPE na2 = a.norm2() ;
typename VEC::DATA_TYPE nb2 = b.norm2() ;
return (a * b) / sqrt(na2 * nb2) ;
typename VEC::DATA_TYPE na2 = a.norm2() ;
typename VEC::DATA_TYPE nb2 = b.norm2() ;
typename VEC::DATA_TYPE res = (a * b) / sqrt(na2 * nb2) ;
return res > 1.0 ? 1.0 : (res < -1.0 ? -1.0 : res) ;
}
// angle formed by 2 vectors
......
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