Public Types | Public Member Functions | Public Attributes | Protected Attributes

TRTK::FitCircle< T > Class Template Reference

Estimates the parameters of a circle from a set of 2D points lying on the circle. More...

#include <FitCircle.hpp>

Inheritance diagram for TRTK::FitCircle< T >:
Collaboration diagram for TRTK::FitCircle< T >:

List of all members.

Public Types

typedef super::Vector2T Vector2T
 2D column vector with value type T.
typedef super::Vector3T Vector3T
 3D column vector with value type T.
typedef super::VectorXT VectorXT
 Column vector of arbitrary size with value type T.
typedef super::MatrixXT MatrixXT
 Matrix of arbitrary size with value type T.
typedef super::Matrix2T Matrix2T
 2 x 2 matrix with value type T.
enum  Error {
  DATA_POINTS_TOO_SIMILAR, INFINITY_NOT_AVAILABLE, NAN_NOT_AVAILABLE, NOT_ENOUGH_POINTS,
  UNKNOWN_ERROR, WRONG_POINT_SIZE
}
typedef Eigen::Array< T,
Eigen::Dynamic, 1 > 
ArrayXT
 General-purpose array of arbitrary size with value type T.
typedef Eigen::Matrix< T, 4, 1 > Vector4T
 4D column vector with value type T.
typedef Eigen::Matrix< T, 3, 3 > Matrix3T
 3 x 3 matrix with value type T.

Public Member Functions

 FitCircle ()
 Constructs an empty FitCircle object.
 FitCircle (const std::vector< Coordinate< T > > &points)
 Constructs a FitCircle object.
 FitCircle (const std::vector< Vector2T, Eigen::aligned_allocator< Vector2T > > &points)
 Constructs a FitCircle object.
 FitCircle (const std::vector< Vector3T > &points)
 Constructs a FitCircle object.
virtual ~FitCircle ()
 Destructs the FitCircle object.
void compute ()
 Estimates the parameters of the circle.
unsigned getNumberPointsRequired () const
 Returns the minimum number of data points required to compute a model.
const Coordinate< T > & getCenterPoint () const
 Returns the center point of the plane.
getDistanceTo (const Coordinate< T > &point) const
 Returns the shortest distance from the circle to the given point.
getRadius () const
 Returns the radius of the circle.
getRMS () const
 Returns the root mean square error.
void setPoints (const std::vector< Coordinate< T > > &)
 Sets the point set.
void setPoints (const std::vector< Vector2T, Eigen::aligned_allocator< Vector2T > > &)
 Sets the point set.
void setPoints (const std::vector< Vector3T > &)
 Sets the point set.

Public Attributes

EIGEN_MAKE_ALIGNED_OPERATOR_NEW
typedef T 
value_type
 Internally used value type (should be a floating point type).

Protected Attributes

MatrixXT m_points

Detailed Description

template<class T>
class TRTK::FitCircle< T >

Estimates the parameters of a circle from a set of 2D points lying on the circle.

Template Parameters:
Tscalar type of the coordinates

This class allows estimating the center point and the radius of a circle from known points on the circle. The points may be erroneous since a least square fitting is done. If \( (x_i, y_i)^T \) are the data points, \( (x_0, y_0)^T \) the center point, and \( r \) the radius, then FitCircle tries to minimize the sum of the squared residuals as shown below:

\[ (x_0, y_0, r) := \arg\min_{(x_0, y_0, r)} \sum_{i=1}^N \left[(x_i - x_0)^2 + (y_i - y_0)^2 - r^2 \right]^2 \]

Here is a more elaborate example to see how to use the class:

 #include <cstdlib>
 #include <iostream>

 #include <TRTK/FitCircle.hpp>
 #include <TRTK/Tools.hpp>

 using namespace TRTK;

 int main()
 {
     double pi = 3.1415926535;

     std::vector<Coordinate<double> > circlePoints;

     // Construct some points lying on a circle.

     double radius = 7;
     Coordinate<double> centerPoint = Coordinate<double>(4, 2);

     for (double phi = 0.0; phi < 2.0 * pi; phi += pi/10)
     {
         using std::sin;
         using std::cos;
         using Tools::randn;

         double x = radius * cos(phi) + randn(0.0, 0.1);
         double y = radius * sin(phi) + randn(0.0, 0.1);

         Coordinate<double> point = centerPoint + Coordinate<double>(x, y);

         circlePoints.push_back(point);
     }

     // Estimate the circle parameters.

     FitCircle<double> fitCircle(circlePoints);

     fitCircle.compute();

     std::cout << "Center point: " << fitCircle.getCenterPoint() << std::endl;
     std::cout << "Radius: " << fitCircle.getRadius() << std::endl;

     return 0;
 }

Output:

 Center point: (4.03589, 1.97525)
 Radius: 7.03509
Author:
Fabian Killus, Christoph Haenisch
Version:
0.2.0
Date:
last changed on 2012-03-20

Definition at line 118 of file FitCircle.hpp.


Member Enumeration Documentation

template<class T>
enum TRTK::Fit::Error [inherited]
Enumerator:
DATA_POINTS_TOO_SIMILAR 

The data points are to similar.

INFINITY_NOT_AVAILABLE 

The type T cannot represent infinity (see std::numeric_limits<T>).

NAN_NOT_AVAILABLE 

The type T cannot represent NaN (see std::numeric_limits<T>).

NOT_ENOUGH_POINTS 

More points are required to estimate the transformation.

UNKNOWN_ERROR 

An unknown error occured.

WRONG_POINT_SIZE 

One or more points have a wrong size.

Definition at line 69 of file Fit.hpp.


Constructor & Destructor Documentation

template<class T >
TRTK::FitCircle< T >::FitCircle (  )

Constructs an empty FitCircle object.

Template Parameters:
Tscalar type of the coordinates

Definition at line 164 of file FitCircle.hpp.

template<class T >
TRTK::FitCircle< T >::FitCircle ( const std::vector< Coordinate< T > > &  points )

Constructs a FitCircle object.

Template Parameters:
Tscalar type of the coordinates
Parameters:
[in]pointsPoints lying on the circle. The points can be 2D or 3D homogeneous coordinates.

Definition at line 180 of file FitCircle.hpp.

template<class T >
TRTK::FitCircle< T >::FitCircle ( const std::vector< Vector2T, Eigen::aligned_allocator< Vector2T > > &  points )

Constructs a FitCircle object.

Template Parameters:
Tscalar type of the coordinates
Parameters:
[in]pointsPoints lying on the circle.

Definition at line 196 of file FitCircle.hpp.

template<class T >
TRTK::FitCircle< T >::FitCircle ( const std::vector< Vector3T > &  points )

Constructs a FitCircle object.

Template Parameters:
Tscalar type of the coordinates
Parameters:
[in]pointsPoints lying on the circle. The points are assumed to be homogeneous coordinates, whose third coordinate entry is equal to one.

Definition at line 214 of file FitCircle.hpp.

template<class T >
TRTK::FitCircle< T >::~FitCircle (  ) [virtual]

Destructs the FitCircle object.

Template Parameters:
Tscalar type of the coordinates

Definition at line 228 of file FitCircle.hpp.


Member Function Documentation

template<class T >
void TRTK::FitCircle< T >::compute (  ) [virtual]

Estimates the parameters of the circle.

Template Parameters:
Tscalar type of the coordinates

There must be at least 3 points to perform the fitting.

Exceptions:
ErrorObjIf there are not enough points to fit the circle, an error object is thrown and its error code is set to WRONG_POINT_SIZE.
See also:
setPoints(), getCenterPoint() and getRadius()

Implements TRTK::Fit2D< T >.

Definition at line 247 of file FitCircle.hpp.

template<class T >
const Coordinate< T > & TRTK::FitCircle< T >::getCenterPoint (  ) const

Returns the center point of the plane.

Template Parameters:
Tscalar type of the coordinates

Definition at line 350 of file FitCircle.hpp.

template<class T >
T TRTK::FitCircle< T >::getDistanceTo ( const Coordinate< T > &  point ) const [virtual]

Returns the shortest distance from the circle to the given point.

Template Parameters:
Tscalar type of the coordinates
Parameters:
[in]pointA 2D coordinate.

Implements TRTK::Fit2D< T >.

Definition at line 364 of file FitCircle.hpp.

template<class T >
T TRTK::FitCircle< T >::getRadius (  ) const

Returns the radius of the circle.

Template Parameters:
Tscalar type of the coordinates

Definition at line 414 of file FitCircle.hpp.

template<class T >
T TRTK::FitCircle< T >::getRMS (  ) const [virtual]

Returns the root mean square error.

Template Parameters:
Tscalar type of the coordinates

Implements TRTK::Fit2D< T >.

Definition at line 386 of file FitCircle.hpp.

template<class T >
void TRTK::Fit2D< T >::setPoints ( const std::vector< Vector2T, Eigen::aligned_allocator< Vector2T > > &  points ) [inherited]

Sets the point set.

Template Parameters:
Tscalar type of the coordinates
Parameters:
[in]points2D coordinates.

Definition at line 163 of file Fit2D.hpp.

template<class T >
void TRTK::Fit2D< T >::setPoints ( const std::vector< Coordinate< T > > &  points ) [virtual, inherited]

Sets the point set.

Template Parameters:
Tscalar type of the coordinates
Parameters:
[in]pointsThe points can either be plain 2D or 3D homogeneous coordinates.
Exceptions:
ErrorObjIf there are any coordinates other than 2D or 3D coordinates, an error object is thrown and its error code is set to WRONG_POINT_SIZE.

Implements TRTK::Fit< T >.

Definition at line 130 of file Fit2D.hpp.

template<class T >
void TRTK::Fit2D< T >::setPoints ( const std::vector< Vector3T > &  points ) [inherited]

Sets the point set.

Template Parameters:
Tscalar type of the coordinates
Parameters:
[in]points3D homogeneous coordinates.

Definition at line 182 of file Fit2D.hpp.


The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines