Commit d4ef1432 authored by Celine Michaud's avatar Celine Michaud

adding close form to compute sphere gradient all over a face

parent 6ad2639c
......@@ -230,8 +230,8 @@ public:
MULTIARCH inline Scalar distanceSegSphere(const VectorType& v0, const VectorType& v1);
//! \brief Compute the distance face sphere
MULTIARCH inline Scalar distanceFaceSphere(const VectorType& v0, const VectorType& v1, const VectorType& v2, const VectorType& n, Scalar gradient_weight, Scalar min_radius, Scalar max_radius);
MULTIARCH inline Scalar gradientFaceSphere(const VectorType& v0, const VectorType& v1, const VectorType& v2, const VectorType& n, Scalar gradient_weight, Scalar min_radius, Scalar max_radius);
MULTIARCH inline Scalar distanceFaceSphere(const VectorType& v0, const VectorType& v1, const VectorType& v2);
MULTIARCH inline Scalar gradientFaceSphere(const VectorType& v0, const VectorType& v1, const VectorType& v2, const VectorType& n0, const VectorType& n1, const VectorType& n2);
/*!
\brief Used to know if two algebraic spheres are the same
......
......@@ -143,15 +143,13 @@ AlgebraicSphere<DataPoint, _WFunctor, T>::distanceSegSphere(const VectorType& v0
template < class DataPoint, class _WFunctor, typename T>
typename DataPoint::Scalar
// https://en.wikipedia.org/wiki/Barycentric_coordinate_system
AlgebraicSphere<DataPoint, _WFunctor, T>::distanceFaceSphere(const VectorType& v0, const VectorType& v1, const VectorType& v2, const VectorType& n, Scalar gradient_weight, Scalar min_radius, Scalar max_radius)
AlgebraicSphere<DataPoint, _WFunctor, T>::distanceFaceSphere(const VectorType& v0, const VectorType& v1, const VectorType& v2)
{
VectorType v0_centered = v0 - m_p;
VectorType v1_centered = v1 - m_p;
VectorType v2_centered = v2 - m_p;
AlgebraicSphere prim;
// \TODO{ Understand what has to be centered or not }
// \TODO{ How to factorize the formula }
prim.setParameters(0.0, (1.0/6.0) * m_ul + (1.0/3.0) * m_uq * v2_centered, (1.0/12.0) * m_uq, VectorType::Zero());
Scalar residual = (1.0/12.0) * m_uq * (v1_centered - v2_centered).dot(v0_centered - v2_centered);
Scalar area = ( ( ( v1 - v0 ).cross( v2 - v0 ) ).norm() * 0.5 );
......@@ -175,33 +173,42 @@ AlgebraicSphere<DataPoint, _WFunctor, T>::distanceFaceSphere(const VectorType& v
template < class DataPoint, class _WFunctor, typename T>
typename DataPoint::Scalar
// https://en.wikipedia.org/wiki/Barycentric_coordinate_system
AlgebraicSphere<DataPoint, _WFunctor, T>::gradientFaceSphere(const VectorType& v0, const VectorType& v1, const VectorType& v2, const VectorType& n, Scalar gradient_weight, Scalar min_radius, Scalar max_radius)
AlgebraicSphere<DataPoint, _WFunctor, T>::gradientFaceSphere(const VectorType& v0, const VectorType& v1, const VectorType& v2, const VectorType& n0, const VectorType& n1, const VectorType& n2)
{
Scalar dist_gradient = 0.0;
Scalar dt = 0.01;
VectorType grad;
Scalar dt = 0.05;
VectorType grad = VectorType(0.0, 0.0, 0.0);
VectorType n = VectorType(0.0, 0.0, 0.0);
Scalar area = ( ( ( v1 - v0 ).cross( v2 - v0 ) ).norm() * 0.5 );
for (Scalar gamma2 = 0.0; gamma2 <= 1.0; gamma2 += dt) // we go through the face
{
for (Scalar gamma1 = 0.0; gamma1 <= 1.0 - gamma2; gamma1 += dt)
{
grad = m_ul + 2.0 * m_uq * (gamma1 * v0 + gamma2 * v1 + (1.0 - gamma1 - gamma2) * v2);
// gradient
grad = primitiveGradient(gamma1 * v0 + gamma2 * v1 + (1.0 - gamma1 - gamma2) * v2);
grad.normalize();
// normal
n = gamma1 * n0 + gamma2 * n1 + (1.0 - gamma1 - gamma2) * n2;
n.normalize();
//dist_gradient += gradient_weight * (1.0 - grad.dot(n));
dist_gradient += (1.0 - grad.dot(n));
}
}
return dist_gradient;
return 2.0 * area * dist_gradient;
//test
//gradient_weight = 1.0 - ((radius() - min_radius) / (max_radius - min_radius));
//gradient_weight = (radius() - min_radius) / (max_radius - min_radius);
//gradient_weight = (radius() / (max_radius - min_radius));
// adding gradient
//Scalar dist = gradient_weight * (1.0 - ( m_ul.dot(n) + 2.0 * m_uq * v2.dot(n) - 2.0 * m_uq * basisCenter().dot(n) +
// m_uq * (v0 - v2).dot(n) + m_uq * (v1 - v0).dot(n) +
// (1.0/3.0) * m_uq * (v0 + v2 - 2.0 * v1).dot(n)));
//return dist;
/*
Scalar area = ( ( ( v1 - v0 ).cross( v2 - v0 ) ).norm() * 0.5 );
Scalar dist = 2 * area * (0.5 - 0.5 * m_ul.dot(n) - (1.0/3.0) * m_uq * (v1 - v2).dot(n) - (1.0/3.0) * m_uq * (v0 - v2).dot(n) - m_uq * (v2 - basisCenter()).dot(n));
return dist;
*/
}
template < class DataPoint, class _WFunctor, typename T>
......
......@@ -69,7 +69,7 @@ public:
/* Processing */
/**************************************************************************/
/*! \copydoc Concept::FittingProcedureConcept::addNeighbor() */
MULTIARCH inline bool addNeighbor(const DataPoint &_nei);
MULTIARCH inline Scalar addNeighbor(const DataPoint &_nei);
/*! \todo */
MULTIARCH inline bool addNeighbor(const DataPoint &_nei, const Scalar w);
......
......@@ -22,7 +22,7 @@ OrientedSphereFit<DataPoint, _WFunctor, T>::init(const VectorType& _evalPos)
}
template < class DataPoint, class _WFunctor, typename T>
bool
typename OrientedSphereFit<DataPoint, _WFunctor, T>::Scalar
OrientedSphereFit<DataPoint, _WFunctor, T>::addNeighbor(const DataPoint& _nei)
{
// centered basis
......@@ -42,10 +42,10 @@ OrientedSphereFit<DataPoint, _WFunctor, T>::addNeighbor(const DataPoint& _nei)
/*! \todo Handle add of multiple similar neighbors (maybe user side)*/
++(Base::m_nbNeighbors);
return true;
return w;
}
return false;
return 0.0;
}
// TODO
......
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