Skip to content

Commit

Permalink
[fitting] Add convertToGlobalBasis in DistWeightFunc
Browse files Browse the repository at this point in the history
  • Loading branch information
nmellado committed Jul 10, 2024
1 parent 6cee05d commit 88a95cd
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Ponca/src/Fitting/algebraicSphere.h
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ class AlgebraicSphere : public T
}

Scalar b = Scalar(1.)/m_uq;
return (Scalar(-0.5)*b)*m_ul + Base::m_w.basisCenter();
return Base::m_w.convertToGlobalBasis((Scalar(-0.5)*b)*m_ul);
}

//! \brief State indicating when the sphere has been normalized
Expand Down
4 changes: 2 additions & 2 deletions Ponca/src/Fitting/algebraicSphere.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ AlgebraicSphere<DataPoint, _WFunctor, T>::project(const VectorType& _q) const
{
t = - (norm - sqrt(norm*norm - Scalar(4) * m_uq * potential)) / (Scalar(2) * m_uq * norm);
}
return Base::m_w.basisCenter() + lq + t * grad;
return Base::m_w.convertToGlobalBasis( lq + t * grad );
}

template < class DataPoint, class _WFunctor, typename T>
Expand All @@ -53,7 +53,7 @@ AlgebraicSphere<DataPoint, _WFunctor, T>::projectDescent( const VectorType& _q,
delta = -(m_uc + proj.dot(m_ul) + m_uq * proj.squaredNorm())*min(ilg,Scalar(1.));
proj += dir*delta;
}
return proj + Base::m_w.basisCenter();
return Base::m_w.convertToGlobalBasis( proj );
}

template < class DataPoint, class _WFunctor, typename T>
Expand Down
2 changes: 1 addition & 1 deletion Ponca/src/Fitting/covariancePlaneFit.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ CovariancePlaneFitImpl<DataPoint, _WFunctor, T>::tangentPlaneToWorld (const Vect
if (ignoreTranslation)
return Base::m_solver.eigenvectors().transpose().inverse() * _lq;
else {
return Base::m_solver.eigenvectors().transpose().inverse() * _lq + Base::m_w.basisCenter();
return Base::m_w.convertToGlobalBasis(Base::m_solver.eigenvectors().transpose().inverse() * _lq);
}
}

Expand Down
2 changes: 1 addition & 1 deletion Ponca/src/Fitting/linePrimitive.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ PONCA_FITTING_DECLARE_DEFAULT_TYPES
PONCA_MULTIARCH inline VectorType project (const VectorType& _q) const
{
// Project on the normal vector and add the offset value
return EigenBase::projection(Base::m_w.convertToLocalBasis(_q)) + Base::m_w.basisCenter();
return Base::m_w.convertToGlobalBasis(EigenBase::projection(Base::m_w.convertToLocalBasis(_q)));
}
}; //class Line

Expand Down
2 changes: 1 addition & 1 deletion Ponca/src/Fitting/mean.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ namespace Ponca {
/// Defined as \f$ b(\mathbf{x}) = \frac{\sum_i w_\mathbf{x}(\mathbf{p_i}) \mathbf{p_i}}{\sum_i w_\mathbf{x}(\mathbf{p_i})} \f$,
/// where \f$\left[\mathbf{p_i} \in \text{neighborhood}(\mathbf{x})\right]\f$ are all the point samples in \f$\mathbf{x}\f$'s neighborhood
PONCA_MULTIARCH inline VectorType barycenter() const {
return barycenterLocal() + Base::m_w.basisCenter();
return Base::m_w.convertToGlobalBasis( barycenterLocal() );
}

protected:
Expand Down
2 changes: 1 addition & 1 deletion Ponca/src/Fitting/plane.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class Plane : public T,
PONCA_MULTIARCH inline VectorType project (const VectorType& _q) const
{
// Project on the normal vector and add the offset value
return EigenBase::projection(Base::m_w.convertToLocalBasis(_q)) + Base::m_w.basisCenter();
return Base::m_w.convertToGlobalBasis(EigenBase::projection(Base::m_w.convertToLocalBasis(_q)));
}

//! \brief Scalar field gradient direction at the evaluation point
Expand Down
11 changes: 9 additions & 2 deletions Ponca/src/Fitting/weightFunc.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,18 @@ class DistWeightFunc
m_p = _evalPos;
}

/// \todo add convertToGlobalBasis, and remove this function
/// \brief Get access to basis center location in global coordinate system
PONCA_MULTIARCH inline const VectorType& basisCenter() const { return m_p; }

/*!
* \brief Convert query from global to local coordinate system
* \brief Convert position from local to global coordinate system
* @param _q Position in local coordinate
* @return Position expressed independently of the local basis center
*/
PONCA_MULTIARCH inline VectorType convertToGlobalBasis(const VectorType& _q) const;

/*!
* \brief Convert query from global to local coordinate system (used internally(
* @param _q Query in global coordinate
* @return Query expressed relatively to the basis center
*/
Expand Down
7 changes: 7 additions & 0 deletions Ponca/src/Fitting/weightFunc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@
*/


template <class DataPoint, class WeightKernel>
typename DistWeightFunc<DataPoint, WeightKernel>::VectorType
DistWeightFunc<DataPoint, WeightKernel>::convertToGlobalBasis(const VectorType& _q) const
{
return _q + m_p;
}

template <class DataPoint, class WeightKernel>
typename DistWeightFunc<DataPoint, WeightKernel>::VectorType
DistWeightFunc<DataPoint, WeightKernel>::convertToLocalBasis(const VectorType& _q) const
Expand Down

0 comments on commit 88a95cd

Please sign in to comment.