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

Experiments on Constant Weight functions #144

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
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
93 changes: 93 additions & 0 deletions Ponca/src/Fitting/weightFunc.h
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,99 @@ class DistWeightFunc

};// class DistWeightFunc


/*!
\brief Weighting function that set uniform weight to all samples

In contrast to DistWeightFunc with ConstantWeight, it does not check for scale range.
It still performs local basis conversion to maintain computation accuracy
*/
template <class DataPoint>
class NoWeightFunc
{
public:
/*! \brief Scalar type from DataPoint */
using Scalar = typename DataPoint::Scalar;
/*! \brief Vector type from DataPoint */
using VectorType = typename DataPoint::VectorType;
/*! \brief Matrix type from DataPoint */
using MatrixType = typename DataPoint::MatrixType;
/*! \brief Return type of the method #w() */
using WeightReturnType = PONCA_MULTIARCH_CU_STD_NAMESPACE(pair)<Scalar, VectorType>;

/*!
\brief Constructor that defines the current evaluation scale
*/
PONCA_MULTIARCH inline NoWeightFunc(const Scalar& /*_t*/ = Scalar(0) ) : m_p(VectorType::Zero()){ }

/*!
* \brief Initialization method, called by the fitting procedure
* @param _evalPos Basis center
*/
PONCA_MULTIARCH inline void init( const VectorType& _evalPos = VectorType::Zero() ) { m_p = _evalPos; }

PONCA_MULTIARCH inline const VectorType& basisCenter() const
{ return m_p; }

/// \brief Convert query from global to local coordinate system
PONCA_MULTIARCH inline VectorType convertToLocalBasis(const VectorType& _q) const
{ return _q - m_p; }

/*!
\brief Compute the weight of the given query, which is always $1$
\param _q Query in global coordinate
*/
PONCA_MULTIARCH inline WeightReturnType w(const VectorType& _q,
const DataPoint& /*attributes*/) const
{ return {Scalar(1),_q}; }


/*!
\brief First order derivative in space (for each spatial dimension \f$\mathsf{x})\f$, which are always $0$
\param _q Query in global coordinate
*/
PONCA_MULTIARCH inline VectorType spacedw(const VectorType& /*_q*/,
const DataPoint& /*attributes*/) const
{ return VectorType::Zeros(); }


/*!
\brief Second order derivative in space (for each spatial dimension \f$\mathsf{x})\f$, which are always $0$
\param _q Query in global coordinate
*/
PONCA_MULTIARCH inline MatrixType spaced2w(const VectorType& /*_q*/,
const DataPoint& /*attributes*/) const
{ return MatrixType::Zeros(); }

/*!
\brief First order derivative in scale \f$t\f$, which are always $0$
\param _q Query in global coordinate
*/
PONCA_MULTIARCH inline Scalar scaledw(const VectorType& /*_q*/,
const DataPoint& /*attributes*/) const
{ return Scalar(0); }

/*!
\brief Second order derivative in scale \f$t\f$, which are always $0$
\param _q Query in global coordinate
*/
PONCA_MULTIARCH inline Scalar scaled2w(const VectorType& /*_q*/,
const DataPoint& /*attributes*/) const
{ return Scalar(0); }

/*!
\brief Cross derivative in scale \f$t\f$ and in space (for each spatial dimension \f$\mathsf{x})\f$, which are
always $0$
\param _q Query in global coordinate
*/
PONCA_MULTIARCH inline VectorType scaleSpaced2w(const VectorType& /*_q*/,
const DataPoint& /*attributes*/) const
{ return VectorType::Zeros(); }

private:
VectorType m_p; /*!< \brief basis center */
};// class DistWeightFunc

#include "weightFunc.hpp"

}// namespace Ponca
12 changes: 11 additions & 1 deletion tests/src/fit_plane.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <Ponca/src/Fitting/meanPlaneFit.h>
#include <Ponca/src/Fitting/weightFunc.h>
#include <Ponca/src/Fitting/weightKernel.h>
#include <Ponca/SpatialPartitioning>

#include <vector>

Expand Down Expand Up @@ -93,6 +94,9 @@ void testFunction(bool _bUnoriented = false, bool _bAddPositionNoise = false, bo
if ( _bAddPositionNoise) // relax a bit the testing threshold
epsilon = Scalar(0.01*MAX_NOISE);
// Test for each point if the fitted plane correspond to the theoretical plane

KdTreeDense<DataPoint> tree(vectorPoints);

#ifdef DEBUG
#pragma omp parallel for
#endif
Expand All @@ -102,7 +106,7 @@ void testFunction(bool _bUnoriented = false, bool _bAddPositionNoise = false, bo
Fit fit;
fit.setWeightFunc(WeightFunc(analysisScale));
fit.init(vectorPoints[i].pos());
fit.compute(vectorPoints);
fit.computeWithIds(tree.range_neighbors(vectorPoints[i].pos(),analysisScale),vectorPoints);

auto ret = fit.getCurrentState();

Expand Down Expand Up @@ -136,12 +140,15 @@ void callSubTests()

typedef DistWeightFunc<Point, SmoothWeightKernel<Scalar> > WeightSmoothFunc;
typedef DistWeightFunc<Point, ConstantWeightKernel<Scalar> > WeightConstantFunc;
typedef NoWeightFunc<Point> WeightConstantFunc2;

typedef Basket<Point, WeightSmoothFunc, CovariancePlaneFit> CovFitSmooth;
typedef Basket<Point, WeightConstantFunc, CovariancePlaneFit> CovFitConstant;
typedef Basket<Point, WeightConstantFunc2, CovariancePlaneFit> CovFitConstant2;

typedef Basket<Point, WeightSmoothFunc, MeanPlaneFit> MeanFitSmooth;
typedef Basket<Point, WeightConstantFunc, MeanPlaneFit> MeanFitConstant;
typedef Basket<Point, WeightConstantFunc2, MeanPlaneFit> MeanFitConstant2;

// test if conflicts are detected
//! [Conflicting type]
Expand All @@ -159,8 +166,10 @@ void callSubTests()
//Test with perfect plane
CALL_SUBTEST(( testFunction<Point, CovFitSmooth, WeightSmoothFunc, true>() ));
CALL_SUBTEST(( testFunction<Point, CovFitConstant, WeightConstantFunc, true>() ));
CALL_SUBTEST(( testFunction<Point, CovFitConstant2, WeightConstantFunc2, true>() ));
CALL_SUBTEST(( testFunction<Point, MeanFitSmooth, WeightSmoothFunc, false>() ));
CALL_SUBTEST(( testFunction<Point, MeanFitConstant, WeightConstantFunc, false>() ));
CALL_SUBTEST(( testFunction<Point, MeanFitConstant2, WeightConstantFunc2, false>() ));
// Check if fitting conflict is detected
CALL_SUBTEST(( testFunction<Point, Hybrid1, WeightConstantFunc, false>(false, false, false, true) ));
CALL_SUBTEST(( testFunction<Point, Hybrid2, WeightConstantFunc, false>(false, false, false, true) ));
Expand All @@ -172,6 +181,7 @@ void callSubTests()
{
CALL_SUBTEST(( testFunction<Point, CovFitSmooth, WeightSmoothFunc, true>(false, true, true) ));
CALL_SUBTEST(( testFunction<Point, CovFitConstant, WeightConstantFunc, true>(false, true, true) ));
CALL_SUBTEST(( testFunction<Point, CovFitConstant2, WeightConstantFunc2, true>(false, true, true) ));
}
cout << "Ok!" << endl;
}
Expand Down
Loading