MeshCoreFit::SphereFit Class Reference

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

#include <SphereFit.h>

Public Member Functions

void ComputeApproximations ()
 Compute approximations for the parameters using all points. More...
 
float Fit ()
 Fit a sphere onto the given points. More...
 
Base::Vector3d GetCenter () const
 Returns the center of the fitted sphere. More...
 
float GetDistanceToSphere (const Base::Vector3f &rcPoint) const
 Returns the distance from the point rcPoint to the fitted sphere. More...
 
int GetNumIterations () const
 Returns the number of iterations that Fit() needed to converge. More...
 
double GetRadius () const
 Returns the radius of the fitted sphere. More...
 
float GetStdDeviation () const
 Returns the standard deviation from the points to the fitted sphere. More...
 
void ProjectToSphere ()
 Projects the points onto the fitted sphere. More...
 
void SetApproximations (double radius, const Base::Vector3d &center)
 Set approximations before calling Fit() More...
 
void SetConvergenceCriteria (double posConvLimit, double vConvLimit, int maxIter)
 Set iteration convergence criteria for the fit if special values are needed. More...
 
 SphereFit ()
 Construction. More...
 
virtual ~SphereFit ()
 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...
 
std::size_t 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...
 
virtual float Fit ()=0
 Pure virtual function to fit the geometry to the given points. 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 Member Functions

void addObservationU (double a[4], double li, double pi, Matrix4x4 &atpa, Eigen::VectorXd &atpl) const
 Computes contribution of the given observation equation on the normal equation matrices. More...
 
bool computeResiduals (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 setLowerPart (Matrix4x4 &atpa) const
 Set the lower part of the normal matrix equal to the upper part. More...
 
void setupNormalEquationMatrices (const std::vector< Base::Vector3d > &residuals, Matrix4x4 &atpa, Eigen::VectorXd &atpl) const
 Set up the normal equations. More...
 
void setupObservation (const Base::Vector3f &point, const Base::Vector3d &residual, double a[4], double &f0, double &qw, double b[3]) const
 Sets up contributions of given observation to the normal equation matrices. 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 sphere for a given set of points.

Constructor & Destructor Documentation

◆ SphereFit()

SphereFit::SphereFit ( )

Construction.

◆ ~SphereFit()

SphereFit::~SphereFit ( )
virtual

Destruction.

Member Function Documentation

◆ addObservationU()

void SphereFit::addObservationU ( double  a[4],
double  li,
double  pi,
Matrix4x4 atpa,
Eigen::VectorXd &  atpl 
) const
protected

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

Referenced by setupNormalEquationMatrices().

◆ ComputeApproximations()

void SphereFit::ComputeApproximations ( )

Compute approximations for the parameters using all points.

Referenced by MeshCore::SphereFit::Fit(), and Fit().

◆ computeResiduals()

bool SphereFit::computeResiduals ( 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().

◆ Fit()

float SphereFit::Fit ( )
virtual

Fit a sphere onto the given points.

If the fit fails FLOAT_MAX is returned.

Implements MeshCore::Approximation.

References ComputeApproximations(), computeResiduals(), MeshCore::Approximation::CountPoints(), and setupNormalEquationMatrices().

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

◆ GetCenter()

Base::Vector3d SphereFit::GetCenter ( ) const

Returns the center of the fitted sphere.

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

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

◆ GetDistanceToSphere()

float SphereFit::GetDistanceToSphere ( const Base::Vector3f rcPoint) const

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

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

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

Referenced by GetStdDeviation().

◆ GetNumIterations()

int SphereFit::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::SphereFit::Fit().

◆ GetRadius()

double SphereFit::GetRadius ( ) const

Returns the radius of the fitted sphere.

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

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

◆ GetStdDeviation()

float SphereFit::GetStdDeviation ( ) const

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

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

References MeshCore::Approximation::CountPoints(), DraftVecUtils::dist(), and GetDistanceToSphere().

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

◆ ProjectToSphere()

void SphereFit::ProjectToSphere ( )

Projects the points onto the fitted sphere.

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

◆ SetApproximations()

void SphereFit::SetApproximations ( double  radius,
const Base::Vector3d center 
)

Set approximations before calling Fit()

◆ SetConvergenceCriteria()

void SphereFit::SetConvergenceCriteria ( double  posConvLimit,
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 SphereFit::setLowerPart ( Matrix4x4 atpa) const
protected

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

Referenced by setupNormalEquationMatrices().

◆ setupNormalEquationMatrices()

void SphereFit::setupNormalEquationMatrices ( const std::vector< Base::Vector3d > &  residuals,
Matrix4x4 atpa,
Eigen::VectorXd &  atpl 
) const
protected

Set up the normal equations.

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

Referenced by Fit().

◆ setupObservation()

void SphereFit::setupObservation ( const Base::Vector3f point,
const Base::Vector3d residual,
double  a[4],
double &  f0,
double &  qw,
double  b[3] 
) const
protected

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

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

Referenced by computeResiduals(), and setupNormalEquationMatrices().


The documentation for this class was generated from the following files: