Skip to content

Commit

Permalink
Merge pull request #108 from ThibaultLejemble/fix-status
Browse files Browse the repository at this point in the history
Fix fit status (issue #100)
  • Loading branch information
nmellado authored Oct 4, 2023
2 parents 2e948d6 + 23eed66 commit 75c4b16
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 20 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions Ponca/src/Fitting/covarianceFit.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ FIT_RESULT
CovarianceFitBase<DataPoint, _WFunctor, T>::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();
Expand Down
4 changes: 3 additions & 1 deletion Ponca/src/Fitting/covarianceLineFit.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
};
Expand Down
12 changes: 5 additions & 7 deletions Ponca/src/Fitting/enums.h
Original file line number Diff line number Diff line change
Expand Up @@ -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*/
Expand Down
6 changes: 4 additions & 2 deletions Ponca/src/Fitting/orientedSphereFit.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,14 @@ OrientedSphereFitImpl<DataPoint, _WFunctor, T>::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<Scalar>::dummy_precision();
Expand Down
2 changes: 0 additions & 2 deletions Ponca/src/Fitting/primitive.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 4 additions & 2 deletions Ponca/src/Fitting/sphereFit.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,14 @@ FIT_RESULT
SphereFitImpl<DataPoint, _WFunctor, T>::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();
Expand Down
6 changes: 4 additions & 2 deletions Ponca/src/Fitting/unorientedSphereFit.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,14 @@ UnorientedSphereFitImpl<DataPoint, _WFunctor, T>::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();
Expand Down

0 comments on commit 75c4b16

Please sign in to comment.