Commit 4a018bd1 authored by Nicolas Mellado's avatar Nicolas Mellado

Oriented Sphere fitting:

 - Add hessian approximation
 - rename gradient and scalarfield evaluation methods
parent 3db668ae
......@@ -26,7 +26,7 @@ namespace Grenaille
\note If internally the scalar fields are stored in a local frame defined
by the evaluation position, the public methods involving a query (such as
project, evaluate, evaluateGradient) have to be defined in global
project, potential, gradient) have to be defined in global
coordinates (e.g. you don't need to convert your query in the current locale
frame).
......@@ -48,6 +48,8 @@ namespace Grenaille
typedef typename DataPoint::Scalar Scalar;
/*! \brief Vector type inherited from DataPoint*/
typedef typename DataPoint::VectorType VectorType;
/*! \brief Vector type inherited from DataPoint*/
typedef typename DataPoint::MatrixType MatrixType;
/*! \brief Weight Function*/
typedef _WFunctor WFunctor;
......@@ -137,10 +139,13 @@ namespace Grenaille
MULTIARCH inline bool isNormalized() const { return _isNormalized; }
//! \brief Value of the scalar field at the location \f$ \mathbf{q} \f$
MULTIARCH inline Scalar evaluate (const VectorType& q) const;
MULTIARCH inline Scalar potential (const VectorType& q) const;
//! \brief Approximation of the scalar field gradient at \f$ \mathbf{q} \f$
MULTIARCH inline VectorType approxGradient (const VectorType& q) const;
//! \brief Gradient of the scalar field at the location \f$ \mathbf{q} \f$
MULTIARCH inline VectorType evaluateGradient (const VectorType& q) const;
//! \brief Rough Approximation of the hessian matrix at \f$ \mathbf{q} \f$
MULTIARCH inline MatrixType approxHessian (const VectorType &q) const;
//! \brief Project a point on the sphere
MULTIARCH inline VectorType project (const VectorType& q) const;
......
......@@ -109,7 +109,7 @@ OrientedSphereFit<DataPoint, _WFunctor, T>::project( const VectorType& q ) const
{
grad = _ul+Scalar(2.)*_uq*proj;
ilg = Scalar(1.)/grad.squaredNorm();
delta = -evaluate(proj)*min(ilg,1.);
delta = -potential(proj)*min(ilg,1.);
proj += dir*delta;
}
return proj + _p;
......@@ -120,7 +120,7 @@ OrientedSphereFit<DataPoint, _WFunctor, T>::project( const VectorType& q ) const
template < class DataPoint, class _WFunctor, typename T>
typename DataPoint::Scalar
OrientedSphereFit<DataPoint, _WFunctor, T>::evaluate( const VectorType &q ) const{
OrientedSphereFit<DataPoint, _WFunctor, T>::potential( const VectorType &q ) const{
// turn to centered basis
const VectorType lq = q-_p;
......@@ -130,13 +130,19 @@ OrientedSphereFit<DataPoint, _WFunctor, T>::evaluate( const VectorType &q ) cons
template < class DataPoint, class _WFunctor, typename T>
typename DataPoint::VectorType
OrientedSphereFit<DataPoint, _WFunctor, T>::evaluateGradient( const VectorType &q ) const{
OrientedSphereFit<DataPoint, _WFunctor, T>::approxGradient( const VectorType &q ) const{
// turn to centered basis
const VectorType lq = q-_p;
const VectorType lq = q-_p;
return (_ul + Scalar(2.f) * _uq * lq).normalized();
}
template < class DataPoint, class _WFunctor, typename T>
typename DataPoint::MatrixType
OrientedSphereFit<DataPoint, _WFunctor, T>::approxHessian( const VectorType &q ) const{
// this is very approximate !!
return Scalar(2.) * _uq * MatrixType::Identity();
}
namespace internal{
......
......@@ -30,7 +30,8 @@ class MyPoint{
public:
enum {Dim = 3};
typedef double Scalar;
typedef Eigen::Matrix<Scalar, Dim, 1> VectorType;
typedef Eigen::Matrix<Scalar, Dim, 1> VectorType;
typedef Eigen::Matrix<Scalar, Dim, Dim> MatrixType;
MULTIARCH inline MyPoint(const VectorType &pos = VectorType::Zero(),
const VectorType& normal = VectorType::Zero())
......@@ -82,18 +83,21 @@ int main() {
fit.addNeighbor(*it);
fit.finalize();
cout << "Pratt normalization" << (fit.applyPrattNorm() ? " is now done." : " has already been applied.") << endl;
// Play with fitting output
cout << "The value of the scalar field at the initial point: "
cout << "Value of the scalar field at the initial point: "
<< p.transpose()
<< " is equal to " << fit.evaluate(p)
<< " is equal to " << fit.potential(p)
<< endl;
cout << "It's gradient at this place is equal to: "
<< fit.evaluateGradient(p).transpose()
cout << "It's approximated gradient at this place is equal to: "
<< fit.approxGradient(p).transpose()
<< endl;
cout << "Approximation of the Hessian matrix: " << endl
<< fit.approxHessian(p)
<< endl;
cout << "Pratt normalization" << (fit.applyPrattNorm() ? " is now done." : " has already been applied.") << endl;
cout << "Fitted Sphere: " << endl
<< "\t Tau : " << fit.tau() << endl
......
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