diff --git a/CHANGELOG b/CHANGELOG index 90967bf80..9ccc6144f 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -10,6 +10,10 @@ Current head (v.1.2 RC) - Bug-fixes and code improvements - [fitting] Use variadic template for basket extensions (#85) + - [fitting] Fix current status issue (#108) + +-Docs + - [fitting] Clarify documentation on FIT_RESULT (#108) -------------------------------------------------------------------------------- v.1.1 RC diff --git a/Ponca/src/Fitting/covarianceFit.hpp b/Ponca/src/Fitting/covarianceFit.hpp index aaddb9e73..f228ed001 100644 --- a/Ponca/src/Fitting/covarianceFit.hpp +++ b/Ponca/src/Fitting/covarianceFit.hpp @@ -35,11 +35,11 @@ FIT_RESULT CovarianceFitBase::finalize () { // handle specific configurations - // With less than 3 neighbors the fitting is undefined - if(Base::finalize() != STABLE || Base::getNumNeighbors() < 3) - { + if(Base::finalize() != STABLE) + return Base::m_eCurrentState; + // With less than Dim neighbors the fitting is undefined + if(Base::getNumNeighbors() < DataPoint::Dim) return Base::m_eCurrentState = UNDEFINED; - } // Center the covariance on the centroid auto centroid = Base::barycenter(); diff --git a/Ponca/src/Fitting/covarianceLineFit.h b/Ponca/src/Fitting/covarianceLineFit.h index 9e4db6cd8..273e3b66d 100644 --- a/Ponca/src/Fitting/covarianceLineFit.h +++ b/Ponca/src/Fitting/covarianceLineFit.h @@ -50,8 +50,10 @@ class CovarianceLineFitImpl : public T PONCA_MULTIARCH inline FIT_RESULT finalize() { static const int smallestEigenValue = DataPoint::Dim - 1; - if (Base::finalize() == STABLE) + if (Base::finalize() == STABLE) { + if (Base::line().isValid()) Base::m_eCurrentState = CONFLICT_ERROR_FOUND; Base::setLine(Base::barycenter(), Base::m_solver.eigenvectors().col(smallestEigenValue).normalized()); + } return Base::m_eCurrentState; } }; diff --git a/Ponca/src/Fitting/enums.h b/Ponca/src/Fitting/enums.h index a461f7be3..799ceb1e5 100644 --- a/Ponca/src/Fitting/enums.h +++ b/Ponca/src/Fitting/enums.h @@ -9,18 +9,16 @@ namespace Ponca { /*! - Enum corresponding to the state of a fitting method (and what the finalize function can return + Enum corresponding to the state of a fitting method (and what the finalize function returns) */ enum FIT_RESULT : unsigned char { - /*! \brief The fitting is stable an ready to use (and having more than 6 - neighbours)*/ + /*! \brief The fitting is stable and ready to use*/ STABLE = 0, - /*! \brief The fitting is ready to use but it can be unstable (and - having between 3 and 6 neighbors)*/ + /*! \brief The fitting is ready to use but it is considered + as unstable (if the number of neighbors is low for example)*/ UNSTABLE = 1, - /*! \brief The fitting is undefined, you can't use it for valid results - (and having less than 3 neighbors)*/ + /*! \brief The fitting is undefined, you can't use it for valid results*/ UNDEFINED = 2, /*! \brief The fitting procedure needs to analyse the neighborhood another time*/ diff --git a/Ponca/src/Fitting/orientedSphereFit.hpp b/Ponca/src/Fitting/orientedSphereFit.hpp index e65422509..764996b18 100644 --- a/Ponca/src/Fitting/orientedSphereFit.hpp +++ b/Ponca/src/Fitting/orientedSphereFit.hpp @@ -41,12 +41,14 @@ OrientedSphereFitImpl::finalize () PONCA_MULTIARCH_STD_MATH(abs); // Compute status - if(Base::finalize() != STABLE || Base::getNumNeighbors() < 3) + if(Base::finalize() != STABLE) return Base::m_eCurrentState; + if(Base::getNumNeighbors() < DataPoint::Dim) + return Base::m_eCurrentState = UNDEFINED; if (Base::algebraicSphere().isValid()) Base::m_eCurrentState = CONFLICT_ERROR_FOUND; else - Base::m_eCurrentState = Base::getNumNeighbors() < 6 ? UNSTABLE : STABLE; + Base::m_eCurrentState = Base::getNumNeighbors() < 2*DataPoint::Dim ? UNSTABLE : STABLE; // 1. finalize sphere fitting Scalar epsilon = Eigen::NumTraits::dummy_precision(); diff --git a/Ponca/src/Fitting/primitive.h b/Ponca/src/Fitting/primitive.h index 4a970e2de..51653886a 100644 --- a/Ponca/src/Fitting/primitive.h +++ b/Ponca/src/Fitting/primitive.h @@ -120,9 +120,7 @@ class PrimitiveBase PONCA_FITTING_APIDOC_FINALIZE PONCA_MULTIARCH inline FIT_RESULT finalize(){ // handle specific configurations - // We need to have at least one neighbor to compute the mean if (m_sumW == Scalar(0.) || m_nbNeighbors < 1) { - init( m_w.basisCenter() ); return m_eCurrentState = UNDEFINED; } return m_eCurrentState = STABLE; diff --git a/Ponca/src/Fitting/sphereFit.hpp b/Ponca/src/Fitting/sphereFit.hpp index 009bf93dd..7d0ec6a5f 100644 --- a/Ponca/src/Fitting/sphereFit.hpp +++ b/Ponca/src/Fitting/sphereFit.hpp @@ -41,12 +41,14 @@ FIT_RESULT SphereFitImpl::finalize () { // Compute status - if(Base::finalize() != STABLE || Base::getNumNeighbors() < 3) + if(Base::finalize() != STABLE) + return Base::m_eCurrentState; + if(Base::getNumNeighbors() < DataPoint::Dim) return Base::m_eCurrentState = UNDEFINED; if (Base::algebraicSphere().isValid()) Base::m_eCurrentState = CONFLICT_ERROR_FOUND; else - Base::m_eCurrentState = Base::getNumNeighbors() < 6 ? UNSTABLE : STABLE; + Base::m_eCurrentState = Base::getNumNeighbors() < 2*DataPoint::Dim ? UNSTABLE : STABLE; MatrixA matC; matC.setIdentity(); diff --git a/Ponca/src/Fitting/unorientedSphereFit.hpp b/Ponca/src/Fitting/unorientedSphereFit.hpp index 5104a9811..6800dec96 100644 --- a/Ponca/src/Fitting/unorientedSphereFit.hpp +++ b/Ponca/src/Fitting/unorientedSphereFit.hpp @@ -90,12 +90,14 @@ UnorientedSphereFitImpl::finalize () constexpr int Dim = DataPoint::Dim; // Compute status - if(Base::finalize() != STABLE || Base::getNumNeighbors() < 3) + if(Base::finalize() != STABLE) return Base::m_eCurrentState; + if(Base::getNumNeighbors() < DataPoint::Dim) + return Base::m_eCurrentState = UNDEFINED; if (Base::algebraicSphere().isValid()) Base::m_eCurrentState = CONFLICT_ERROR_FOUND; else - Base::m_eCurrentState = Base::getNumNeighbors() < 6 ? UNSTABLE : STABLE; + Base::m_eCurrentState = Base::getNumNeighbors() < 2*DataPoint::Dim ? UNSTABLE : STABLE; // 1. finalize sphere fitting Scalar invSumW = Scalar(1.) / Base::getWeightSum();