From 88a95cdda420de0283566d03c2e875b4e2d3191e Mon Sep 17 00:00:00 2001 From: Nicolas Mellado Date: Wed, 10 Jul 2024 18:12:17 +0200 Subject: [PATCH] [fitting] Add convertToGlobalBasis in DistWeightFunc --- Ponca/src/Fitting/algebraicSphere.h | 2 +- Ponca/src/Fitting/algebraicSphere.hpp | 4 ++-- Ponca/src/Fitting/covariancePlaneFit.hpp | 2 +- Ponca/src/Fitting/linePrimitive.h | 2 +- Ponca/src/Fitting/mean.h | 2 +- Ponca/src/Fitting/plane.h | 2 +- Ponca/src/Fitting/weightFunc.h | 11 +++++++++-- Ponca/src/Fitting/weightFunc.hpp | 7 +++++++ 8 files changed, 23 insertions(+), 9 deletions(-) diff --git a/Ponca/src/Fitting/algebraicSphere.h b/Ponca/src/Fitting/algebraicSphere.h index c827852b1..9c5af85ab 100644 --- a/Ponca/src/Fitting/algebraicSphere.h +++ b/Ponca/src/Fitting/algebraicSphere.h @@ -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 diff --git a/Ponca/src/Fitting/algebraicSphere.hpp b/Ponca/src/Fitting/algebraicSphere.hpp index 06c95c9ee..9730a6355 100644 --- a/Ponca/src/Fitting/algebraicSphere.hpp +++ b/Ponca/src/Fitting/algebraicSphere.hpp @@ -26,7 +26,7 @@ AlgebraicSphere::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> @@ -53,7 +53,7 @@ AlgebraicSphere::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> diff --git a/Ponca/src/Fitting/covariancePlaneFit.hpp b/Ponca/src/Fitting/covariancePlaneFit.hpp index d587fb886..f253df644 100644 --- a/Ponca/src/Fitting/covariancePlaneFit.hpp +++ b/Ponca/src/Fitting/covariancePlaneFit.hpp @@ -40,7 +40,7 @@ CovariancePlaneFitImpl::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); } } diff --git a/Ponca/src/Fitting/linePrimitive.h b/Ponca/src/Fitting/linePrimitive.h index ce0363b01..60e0f2581 100644 --- a/Ponca/src/Fitting/linePrimitive.h +++ b/Ponca/src/Fitting/linePrimitive.h @@ -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 diff --git a/Ponca/src/Fitting/mean.h b/Ponca/src/Fitting/mean.h index 681f3ecb7..880b57f08 100644 --- a/Ponca/src/Fitting/mean.h +++ b/Ponca/src/Fitting/mean.h @@ -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: diff --git a/Ponca/src/Fitting/plane.h b/Ponca/src/Fitting/plane.h index 19a25946b..064471ce9 100644 --- a/Ponca/src/Fitting/plane.h +++ b/Ponca/src/Fitting/plane.h @@ -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 diff --git a/Ponca/src/Fitting/weightFunc.h b/Ponca/src/Fitting/weightFunc.h index 1886ed0f9..5fcdb56a6 100644 --- a/Ponca/src/Fitting/weightFunc.h +++ b/Ponca/src/Fitting/weightFunc.h @@ -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 */ diff --git a/Ponca/src/Fitting/weightFunc.hpp b/Ponca/src/Fitting/weightFunc.hpp index a64832296..9f60f5ea4 100644 --- a/Ponca/src/Fitting/weightFunc.hpp +++ b/Ponca/src/Fitting/weightFunc.hpp @@ -5,6 +5,13 @@ */ +template +typename DistWeightFunc::VectorType +DistWeightFunc::convertToGlobalBasis(const VectorType& _q) const +{ + return _q + m_p; +} + template typename DistWeightFunc::VectorType DistWeightFunc::convertToLocalBasis(const VectorType& _q) const