Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix current status (issue #100) #108

Merged
merged 6 commits into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading