Ponca  40f245e28b920cbb763a1c6282156c87c626f24c
Point Cloud Analysis library
Loading...
Searching...
No Matches
Ponca::CovarianceFitBase< DataPoint, _WFunctor, T > Class Template Reference

Procedure that compute and decompose the covariance matrix of the neighbors positions in \(3d\). More...

#include <covarianceFit.h>

+ Inheritance diagram for Ponca::CovarianceFitBase< DataPoint, _WFunctor, T >:
+ Collaboration diagram for Ponca::CovarianceFitBase< DataPoint, _WFunctor, T >:

Public Types

using Scalar = typename DataPoint::Scalar
 Alias to scalar type.
 
using VectorType = typename Base::VectorType
 Alias to vector type.
 
using WFunctor = typename Base::WFunctor
 Alias to weight function.
 
using MatrixType = typename DataPoint::MatrixType
 Alias to matrix type.
 
using Solver = Eigen::SelfAdjointEigenSolver< MatrixType >
 Solver used to analyse the covariance matrix.
 

Public Member Functions

CovarianceFitBase< DataPoint, _WFunctor, T > & covarianceFit ()
 Explicit conversion to CovarianceFitBase , to access methods potentially hidden by heritage.
 
const CovarianceFitBase< DataPoint, _WFunctor, T > & covarianceFit () const
 Explicit conversion to CovarianceFitBase , to access methods potentially hidden by heritage.
 
void init ()
 Set the evaluation position and reset the internal states.
 
bool addLocalNeighbor (Scalar w, const VectorType &localQ, const DataPoint &attributes)
 Add a neighbor to perform the fit.
 
FIT_RESULT finalize ()
 Finalize the procedure.
 
Scalar surfaceVariation () const
 Implements [13] surface variation.
 
Scalar planarity () const
 Implements the planarity [7] .
 
Scalar linearity () const
 Implements the linearity [7] .
 
Scalar sphericity () const
 Implements the sphericity [7] .
 
Scalar anisotropy () const
 Implements the anisotropy [7] .
 
Scalar eigenentropy () const
 Implements the eigenentropy [7] .
 
Scalar lambda_0 () const
 The minimun eigenvalue \( \lambda_0 \).
 
Scalar lambda_1 () const
 The second eigenvalue \( \lambda_1 \).
 
Scalar lambda_2 () const
 The maximun eigenvalue \( \lambda_2 \).
 
const Solversolver () const
 Reading access to the Solver used to analyse the covariance matrix.
 

Protected Types

enum  { Check = Base::PROVIDES_MEAN_POSITION , PROVIDES_POSITION_COVARIANCE }
 
using Base = T
 Base class of the procedure.
 

Protected Attributes

MatrixType m_cov {MatrixType::Zero()}
 Covariance matrix.
 
Solver m_solver
 Solver used to analyse the covariance matrix.
 

Detailed Description

template<class DataPoint, class _WFunctor, typename T>
class Ponca::CovarianceFitBase< DataPoint, _WFunctor, T >

Procedure that compute and decompose the covariance matrix of the neighbors positions in \(3d\).

This process is commonly used for plane fitting and local variance analysis. It is often called Principal Component Analysis (PCA) of the neighborhood, and used in Geometry Processing and Computer Vision.

See also
CovariancePlaneFit which use a similar approach for Plane estimation

Computation details

Standard PCA algorithm involves a two-steps process where the barycenter \(\mathbf{b}\) is first computed, and then the covariance matrix \(\text{C}\) (in the following, the weights are ignored for clarity but without loss of generality):

\begin{align} \mathbf{b} &= \frac{1}{n}\sum_i\mathbf{p}_i \\ \text{C} &= \frac{1}{n}\sum_i(\mathbf{p}_i-\mathbf{b})(\mathbf{p}_i-\mathbf{b})^T \end{align}

This class implements a single-pass version, where the first formulation is re-expressed as follows:

\begin{align} \text{C} &= \frac{1}{n}\sum_i (\mathbf{p}_i\mathbf{p}_i^T - \mathbf{b}\mathbf{p}_i^T - \mathbf{p}_i\mathbf{b}^T + \mathbf{b}\mathbf{b}^T) \\ &= \frac{1}{n}\sum_i (\mathbf{p}_i\mathbf{p}_i^T) - \frac{1}{n}\sum_i(\mathbf{b}\mathbf{p}_i^T) - \frac{1}{n}\sum_i(\mathbf{p}_i\mathbf{b}^T) + \frac{1}{n}\sum_i (\mathbf{b}\mathbf{b}^T) \\ &= \frac{1}{n}\sum_i (\mathbf{p}_i\mathbf{p}_i^T) - \mathbf{b}\frac{1}{n}\sum_i(\mathbf{p}_i^T) - \frac{1}{n}\sum_i(\mathbf{p}_i)\mathbf{b}^T + \frac{1}{n}\sum_i(1) \mathbf{b}\mathbf{b}^T \\ &= \frac{1}{n}\sum_i (\mathbf{p}_i\mathbf{p}_i^T) - \mathbf{b}\mathbf{b}^T - \mathbf{b}\mathbf{b}^T + \mathbf{b}\mathbf{b}^T \end{align}

Leading to a single pass where \(\text{C}\) is express by substracting two terms that can be computed independently in one run:

\[ \text{C} = \frac{1}{n}\sum_i (\mathbf{p}_i\mathbf{p}_i^T) - \mathbf{b}\mathbf{b}^T \]

All the computed features are defined for the 3 eigenvalues \( 0 < \lambda_0 \leq \lambda_1 \leq \lambda_2 \).

Warning
This class is valid only in 3D.

Definition at line 53 of file covarianceFit.h.

Member Typedef Documentation

◆ Base

template<class DataPoint , class _WFunctor , typename T >
using Ponca::CovarianceFitBase< DataPoint, _WFunctor, T >::Base = T
protected

Base class of the procedure.

Definition at line 55 of file covarianceFit.h.

◆ MatrixType

template<class DataPoint , class _WFunctor , typename T >
using Ponca::CovarianceFitBase< DataPoint, _WFunctor, T >::MatrixType = typename DataPoint::MatrixType

Alias to matrix type.

Definition at line 65 of file covarianceFit.h.

◆ Scalar

template<class DataPoint , class _WFunctor , typename T >
using Ponca::CovarianceFitBase< DataPoint, _WFunctor, T >::Scalar = typename DataPoint::Scalar

Alias to scalar type.

Definition at line 55 of file covarianceFit.h.

◆ Solver

template<class DataPoint , class _WFunctor , typename T >
using Ponca::CovarianceFitBase< DataPoint, _WFunctor, T >::Solver = Eigen::SelfAdjointEigenSolver<MatrixType>

Solver used to analyse the covariance matrix.

Definition at line 67 of file covarianceFit.h.

◆ VectorType

template<class DataPoint , class _WFunctor , typename T >
using Ponca::CovarianceFitBase< DataPoint, _WFunctor, T >::VectorType = typename Base::VectorType

Alias to vector type.

Definition at line 55 of file covarianceFit.h.

◆ WFunctor

template<class DataPoint , class _WFunctor , typename T >
using Ponca::CovarianceFitBase< DataPoint, _WFunctor, T >::WFunctor = typename Base::WFunctor

Alias to weight function.

Definition at line 55 of file covarianceFit.h.

Member Enumeration Documentation

◆ anonymous enum

template<class DataPoint , class _WFunctor , typename T >
anonymous enum
protected

Definition at line 58 of file covarianceFit.h.

Member Function Documentation

◆ addLocalNeighbor()

template<class DataPoint , class _WFunctor , typename T >
bool CovarianceFitBase::addLocalNeighbor ( Scalar  w,
const VectorType localQ,
const DataPoint &  attributes 
)
inline

Add a neighbor to perform the fit.

Returns
false if param nei is not a valid neighbour (weight = 0)

Definition at line 21 of file covarianceFit.hpp.

◆ anisotropy()

template<class DataPoint , class _WFunctor , typename T >
CovarianceFitBase< DataPoint, _WFunctor, T >::Scalar CovarianceFitBase::anisotropy ( ) const
inline

Implements the anisotropy [7] .

Anisotropy is defined as:

\[ \frac{\lambda_2 - \lambda_0}{\lambda_2} \]

Definition at line 90 of file covarianceFit.hpp.

◆ covarianceFit() [1/2]

template<class DataPoint , class _WFunctor , typename T >
CovarianceFitBase< DataPoint, _WFunctor, T > & Ponca::CovarianceFitBase< DataPoint, _WFunctor, T >::covarianceFit ( )
inline

Explicit conversion to CovarianceFitBase , to access methods potentially hidden by heritage.

Definition at line 75 of file covarianceFit.h.

◆ covarianceFit() [2/2]

template<class DataPoint , class _WFunctor , typename T >
const CovarianceFitBase< DataPoint, _WFunctor, T > & Ponca::CovarianceFitBase< DataPoint, _WFunctor, T >::covarianceFit ( ) const
inline

Explicit conversion to CovarianceFitBase , to access methods potentially hidden by heritage.

Definition at line 75 of file covarianceFit.h.

◆ eigenentropy()

template<class DataPoint , class _WFunctor , typename T >
CovarianceFitBase< DataPoint, _WFunctor, T >::Scalar CovarianceFitBase::eigenentropy ( ) const
inline

Implements the eigenentropy [7] .

Eigenentropy is defined as:

\[ - \lambda_0 * \ln{\lambda_0} - \lambda_1 * \ln{\lambda_1} - \lambda_2 * \ln{\lambda_2} \]

Definition at line 98 of file covarianceFit.hpp.

◆ finalize()

template<class DataPoint , class _WFunctor , typename T >
FIT_RESULT CovarianceFitBase::finalize ( )
inline

Finalize the procedure.

Returns
Fitting Status
Warning
Must be called be for any use of the fitting output

Definition at line 35 of file covarianceFit.hpp.

◆ init()

template<class DataPoint , class _WFunctor , typename T >
void CovarianceFitBase::init ( )
inline

Set the evaluation position and reset the internal states.

Warning
Must be called be for any computation (but after #setWeightFunc)

Definition at line 13 of file covarianceFit.hpp.

◆ lambda_0()

template<class DataPoint , class _WFunctor , typename T >
CovarianceFitBase< DataPoint, _WFunctor, T >::Scalar CovarianceFitBase::lambda_0 ( ) const
inline

The minimun eigenvalue \( \lambda_0 \).

Definition at line 107 of file covarianceFit.hpp.

◆ lambda_1()

template<class DataPoint , class _WFunctor , typename T >
CovarianceFitBase< DataPoint, _WFunctor, T >::Scalar CovarianceFitBase::lambda_1 ( ) const
inline

The second eigenvalue \( \lambda_1 \).

Definition at line 114 of file covarianceFit.hpp.

◆ lambda_2()

template<class DataPoint , class _WFunctor , typename T >
CovarianceFitBase< DataPoint, _WFunctor, T >::Scalar CovarianceFitBase::lambda_2 ( ) const
inline

The maximun eigenvalue \( \lambda_2 \).

Definition at line 121 of file covarianceFit.hpp.

◆ linearity()

template<class DataPoint , class _WFunctor , typename T >
CovarianceFitBase< DataPoint, _WFunctor, T >::Scalar CovarianceFitBase::linearity ( ) const
inline

Implements the linearity [7] .

Linearity is defined as:

\[ \frac{\lambda_2 - \lambda_1}{\lambda_2} \]

Definition at line 75 of file covarianceFit.hpp.

◆ planarity()

template<class DataPoint , class _WFunctor , typename T >
CovarianceFitBase< DataPoint, _WFunctor, T >::Scalar CovarianceFitBase::planarity ( ) const
inline

Implements the planarity [7] .

Planarity is defined as:

\[ \frac{\lambda_1 - \lambda_0}{\lambda_2} \]

Definition at line 67 of file covarianceFit.hpp.

◆ solver()

template<class DataPoint , class _WFunctor , typename T >
const Solver & Ponca::CovarianceFitBase< DataPoint, _WFunctor, T >::solver ( ) const
inline

Reading access to the Solver used to analyse the covariance matrix.

Definition at line 127 of file covarianceFit.h.

◆ sphericity()

template<class DataPoint , class _WFunctor , typename T >
CovarianceFitBase< DataPoint, _WFunctor, T >::Scalar CovarianceFitBase::sphericity ( ) const
inline

Implements the sphericity [7] .

Sphericity is defined as:

\[ \frac{\lambda_0}{\lambda_2} \]

Definition at line 83 of file covarianceFit.hpp.

◆ surfaceVariation()

template<class DataPoint , class _WFunctor , typename T >
CovarianceFitBase< DataPoint, _WFunctor, T >::Scalar CovarianceFitBase::surfaceVariation ( ) const
inline

Implements [13] surface variation.

It computes the ratio \( d \frac{\lambda_0}{\sum_i \lambda_i} \) with d the dimension of the ambient space.

Returns
0 for invalid fits

Definition at line 60 of file covarianceFit.hpp.

Member Data Documentation

◆ m_cov

template<class DataPoint , class _WFunctor , typename T >
MatrixType Ponca::CovarianceFitBase< DataPoint, _WFunctor, T >::m_cov {MatrixType::Zero()}
protected

Covariance matrix.

Definition at line 71 of file covarianceFit.h.

◆ m_solver

template<class DataPoint , class _WFunctor , typename T >
Solver Ponca::CovarianceFitBase< DataPoint, _WFunctor, T >::m_solver
protected

Solver used to analyse the covariance matrix.

Definition at line 72 of file covarianceFit.h.