Best-fit cylinder for a given set of points. More...

#include <CylinderFit.h>

Public Member Functions

 CylinderFit ()
 Construction. More...
 
float Fit ()
 Fit a cylinder into the given points. More...
 
Base::Vector3d GetAxis () const
 Returns the axis of the fitted cylinder. More...
 
Base::Vector3d GetBase () const
 Returns the base of the fitted cylinder. More...
 
float GetDistanceToCylinder (const Base::Vector3f &rcPoint) const
 Returns the distance from the point rcPoint to the fitted cylinder. More...
 
int GetNumIterations () const
 Returns the number of iterations that Fit() needed to converge. More...
 
double GetRadius () const
 Returns the radius of the fitted cylinder. More...
 
float GetStdDeviation () const
 Returns the standard deviation from the points to the fitted cylinder. More...
 
void ProjectToCylinder ()
 Projects the points onto the fitted cylinder. More...
 
void SetApproximations (const Base::Vector3d &base, const Base::Vector3d &axis)
 Set approximations before calling Fit(). More...
 
void SetApproximations (double radius, const Base::Vector3d &base, const Base::Vector3d &axis)
 Set approximations before calling Fit() More...
 
void SetConvergenceCriteria (double posConvLimit, double dirConvLimit, double vConvLimit, int maxIter)
 Set iteration convergence criteria for the fit if special values are needed. More...
 
virtual ~CylinderFit ()
 Destruction. More...
 
- Public Member Functions inherited from MeshCore::Approximation
void AddPoint (const Base::Vector3f &rcVector)
 Add point for the fit algorithm. More...
 
void AddPoints (const MeshPointArray &points)
 Add points for the fit algorithm. More...
 
void AddPoints (const std::list< Base::Vector3f > &rsPointList)
 Add points for the fit algorithm. More...
 
void AddPoints (const std::set< Base::Vector3f > &rsPointSet)
 Add points for the fit algorithm. More...
 
void AddPoints (const std::vector< Base::Vector3f > &rvPointVect)
 Add points for the fit algorithm. More...
 
 Approximation ()
 Construction. More...
 
void Clear ()
 Deletes the inserted points and frees any allocated resources. More...
 
unsigned long CountPoints () const
 Determines the number of the current added points. More...
 
bool Done () const
 Returns true if Fit() has been called for the current set of points, false otherwise. More...
 
Base::Vector3f GetGravity () const
 Returns the center of gravity of the current added points. More...
 
float GetLastResult () const
 Returns the result of the last fit. More...
 
const std::list< Base::Vector3f > & GetPoints () const
 Get all added points. More...
 
virtual ~Approximation ()
 Destroys the object and frees any allocated resources. More...
 

Protected Types

enum  SolutionD { solL = 0, solM = 1, solN = 2 }
 

Protected Member Functions

void addObservationU (double a[5], double li, double pi, Matrix5x5 &atpa, Eigen::VectorXd &atpl) const
 Computes contribution of the given observation equation on the normal equation matrices. More...
 
void ComputeApproximationsLine ()
 Compute approximations for the parameters using all points using the line fit method. More...
 
bool computeResiduals (SolutionD solDir, const Eigen::VectorXd &x, std::vector< Base::Vector3d > &residuals, double &sigma0, double vConvLimit, bool &vConverged) const
 Compute the residuals and sigma0 and check the residual convergence. More...
 
void findBestSolDirection (SolutionD &solDir)
 Checks initial parameter values and defines the best solution direction to use. More...
 
double meanXObs ()
 Compute the mean X-value of all of the points (observed/input surface points) More...
 
double meanYObs ()
 Compute the mean Y-value of all of the points (observed/input surface points) More...
 
double meanZObs ()
 Compute the mean Z-value of all of the points (observed/input surface points) More...
 
void setLowerPart (Matrix5x5 &atpa) const
 Set the lower part of the normal matrix equal to the upper part. More...
 
void setupNormalEquationMatrices (SolutionD solDir, const std::vector< Base::Vector3d > &residuals, Matrix5x5 &atpa, Eigen::VectorXd &atpl) const
 Set up the normal equations. More...
 
void setupObservation (SolutionD solDir, const Base::Vector3f &point, const Base::Vector3d &residual, double a[5], double &f0, double &qw, double b[3]) const
 Sets up contributions of given observation to the normal equation matrices. More...
 
bool updateParameters (SolutionD solDir, const Eigen::VectorXd &x)
 Update the parameters after solving the normal equations. More...
 
- Protected Member Functions inherited from MeshCore::Approximation
void GetMgcVectorArray (std::vector< Wm4::Vector3< double > > &rcPts) const
 Creates a vector of Wm4::Vector3 elements. More...
 

Detailed Description

Best-fit cylinder for a given set of points.

Doesn't expect points on any top or bottom end-planes, only points on the side surface

Member Enumeration Documentation

◆ SolutionD

Enumerator
solL 
solM 
solN 

Constructor & Destructor Documentation

◆ CylinderFit()

CylinderFit::CylinderFit ( )

Construction.

◆ ~CylinderFit()

CylinderFit::~CylinderFit ( )
virtual

Destruction.

Member Function Documentation

◆ addObservationU()

void CylinderFit::addObservationU ( double  a[5],
double  li,
double  pi,
Matrix5x5 atpa,
Eigen::VectorXd &  atpl 
) const
protected

Computes contribution of the given observation equation on the normal equation matrices.

Referenced by setupNormalEquationMatrices().

◆ ComputeApproximationsLine()

void CylinderFit::ComputeApproximationsLine ( )
protected

Compute approximations for the parameters using all points using the line fit method.

References Base::Vector3< _Precision >::DistanceToLine().

Referenced by Fit().

◆ computeResiduals()

bool CylinderFit::computeResiduals ( SolutionD  solDir,
const Eigen::VectorXd &  x,
std::vector< Base::Vector3d > &  residuals,
double &  sigma0,
double  vConvLimit,
bool vConverged 
) const
protected

Compute the residuals and sigma0 and check the residual convergence.

References setupObservation().

Referenced by Fit().

◆ findBestSolDirection()

void CylinderFit::findBestSolDirection ( SolutionD solDir)
protected

◆ Fit()

float CylinderFit::Fit ( )
virtual

◆ GetAxis()

Base::Vector3d CylinderFit::GetAxis ( ) const

Returns the axis of the fitted cylinder.

If Fit() has not been called the null vector is returned.

Referenced by MeshCore::CylinderFit::Fit().

◆ GetBase()

Base::Vector3d CylinderFit::GetBase ( ) const

Returns the base of the fitted cylinder.

If Fit() has not been called the null vector is returned.

Referenced by MeshCore::CylinderFit::Fit().

◆ GetDistanceToCylinder()

float CylinderFit::GetDistanceToCylinder ( const Base::Vector3f rcPoint) const

Returns the distance from the point rcPoint to the fitted cylinder.

If Fit() has not been called FLOAT_MAX is returned.

References Base::Vector3< _Precision >::DistanceToLine(), Base::Vector3< _Precision >::x, Base::Vector3< _Precision >::y, and Base::Vector3< _Precision >::z.

Referenced by GetStdDeviation().

◆ GetNumIterations()

int CylinderFit::GetNumIterations ( ) const

Returns the number of iterations that Fit() needed to converge.

If Fit() has not been called then zero is returned.

Referenced by MeshCore::CylinderFit::Fit().

◆ GetRadius()

double CylinderFit::GetRadius ( ) const

Returns the radius of the fitted cylinder.

If Fit() has not been called then zero is returned.

Referenced by MeshCore::CylinderFit::Fit().

◆ GetStdDeviation()

float CylinderFit::GetStdDeviation ( ) const

Returns the standard deviation from the points to the fitted cylinder.

If Fit() has not been called FLOAT_MAX is returned.

References MeshCore::Approximation::CountPoints(), and GetDistanceToCylinder().

Referenced by MeshCore::CylinderFit::Fit().

◆ meanXObs()

double CylinderFit::meanXObs ( )
protected

Compute the mean X-value of all of the points (observed/input surface points)

Referenced by findBestSolDirection().

◆ meanYObs()

double CylinderFit::meanYObs ( )
protected

Compute the mean Y-value of all of the points (observed/input surface points)

Referenced by findBestSolDirection().

◆ meanZObs()

double CylinderFit::meanZObs ( )
protected

Compute the mean Z-value of all of the points (observed/input surface points)

Referenced by findBestSolDirection().

◆ ProjectToCylinder()

void CylinderFit::ProjectToCylinder ( )

◆ SetApproximations() [1/2]

void CylinderFit::SetApproximations ( const Base::Vector3d base,
const Base::Vector3d axis 
)

Set approximations before calling Fit().

This version computes the radius using the given axis and the existing surface points.

References Base::Vector3< _Precision >::DistanceToLine(), and Base::Vector3< _Precision >::Normalize().

◆ SetApproximations() [2/2]

void CylinderFit::SetApproximations ( double  radius,
const Base::Vector3d base,
const Base::Vector3d axis 
)

Set approximations before calling Fit()

References Base::Vector3< _Precision >::Normalize().

Referenced by MeshCore::CylinderFit::Fit().

◆ SetConvergenceCriteria()

void CylinderFit::SetConvergenceCriteria ( double  posConvLimit,
double  dirConvLimit,
double  vConvLimit,
int  maxIter 
)

Set iteration convergence criteria for the fit if special values are needed.

The default values set in the constructor are suitable for most uses

◆ setLowerPart()

void CylinderFit::setLowerPart ( Matrix5x5 atpa) const
protected

Set the lower part of the normal matrix equal to the upper part.

Referenced by setupNormalEquationMatrices().

◆ setupNormalEquationMatrices()

void CylinderFit::setupNormalEquationMatrices ( SolutionD  solDir,
const std::vector< Base::Vector3d > &  residuals,
Matrix5x5 atpa,
Eigen::VectorXd &  atpl 
) const
protected

Set up the normal equations.

References addObservationU(), setLowerPart(), and setupObservation().

Referenced by Fit().

◆ setupObservation()

void CylinderFit::setupObservation ( SolutionD  solDir,
const Base::Vector3f point,
const Base::Vector3d residual,
double  a[5],
double &  f0,
double &  qw,
double  b[3] 
) const
protected

Sets up contributions of given observation to the normal equation matrices.

References solL, solM, solN, Base::Vector3< _Precision >::x, Base::Vector3< _Precision >::y, and Base::Vector3< _Precision >::z.

Referenced by computeResiduals(), and setupNormalEquationMatrices().

◆ updateParameters()

bool CylinderFit::updateParameters ( SolutionD  solDir,
const Eigen::VectorXd &  x 
)
protected

Update the parameters after solving the normal equations.

References solL, solM, and solN.

Referenced by Fit().


The documentation for this class was generated from the following files:
  • src/Mod/Mesh/App/Core/CylinderFit.h
  • src/Mod/Mesh/App/Core/CylinderFit.cpp