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

TRTK::FitLine< T > Class Template Reference

Estimates the parameters of a line from a set of 2D points. More...

#include <FitLine.hpp>

Inheritance diagram for TRTK::FitLine< T >:
Collaboration diagram for TRTK::FitLine< 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::Matrix2T Matrix2T
 2 x 2 matrix with value type T.
typedef super::MatrixXT MatrixXT
 Matrix of arbitrary size 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

 FitLine ()
 Constructs an empty FitLine object.
 FitLine (const std::vector< Coordinate< T > > &points)
 Constructs a FitLine object.
 FitLine (const std::vector< Vector2T, Eigen::aligned_allocator< Vector2T > > &points)
 Constructs a FitLine object.
 FitLine (const std::vector< Vector3T > &points)
 Constructs an FitLine object.
virtual ~FitLine ()
 Destructs the FitLine object.
void compute ()
 Runs the fitting algorithm.
T getRMS () const
 Returns the root mean square error.
unsigned getNumberPointsRequired () const
 Returns the minimum number of data points required to compute a model.
const Coordinate< T > & getDirectionVector () const
 Returns the direction vector of the line.
const Coordinate< T > & getNormalVector () const
 Returns the normal vector of the line.
const Coordinate< T > & getPointOnLineSegment () const
 Returns the center of the line segment.
T getSlope () const
 Returns the slope of the line.
T getYIntercept () const
 Returns y-intercept of the line.
T getXIntercept () const
 Returns the x-intercept of the line.
T getDistanceFromOrigin () const
 Returns the shortest distance from the line to the origin.
T getDistanceTo (const Coordinate< T > &point) const
 Returns the shortest distance from the line to the given point.
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::FitLine< T >

Estimates the parameters of a line from a set of 2D points.

Template Parameters:
Tscalar type of the coordinates

This class allows estimating the slope, the intercepts, the normal, et cetera of a line from a given set of points. The points may be erroneous since a least square fitting is done. If \( (x_i, y_i)^T \) are the data points, if \( m \) is the slope and if \( b \) is the y-intercept, then FitLine tries to minimize the sum of the squared residuals as shown below:

\[ (m, b) := \arg\min_{(m, b)} \sum_{i=1}^N (x_i m + b - y_i)^2 \]

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

 #include <iostream>

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

 using namespace std;
 using namespace TRTK;

 int main()
 {

     vector<Coordinate<double> > points_on_line;

     // Construct some points lying on a line and add some noise.

     double slope = 0.7;
     double y_intercept = -3;

     for (int i = -10; i < 10; ++i)
     {
         using Tools::randn;

         double x = i + randn(0.0, 0.1);
         double y = i * slope + y_intercept + randn(0.0, 0.1);

         Coordinate<double> point(x, y);

         points_on_line.push_back(point);
     }

     // Estimate the line parameters.

     FitLine<double> fitLine(points_on_line);

     fitLine.compute();

     cout << "Slope: " << fitLine.getSlope() << endl;
     cout << "Y-intercept: " << fitLine.getYIntercept() << endl;
     cout << "Direction Vector: " << fitLine.getDirectionVector() << endl;
     cout << "Distance from origin: " << fitLine.getDistanceFromOrigin() << endl;

     return 0;
 }

Output:

 Slope: 0.695251
 Y-intercept: -3.02231
 Direction Vector: (-0.82106, -0.570842)
 Distance from origin: 2.4815
Author:
Christoph Haenisch, Fabian Killus
Version:
0.6.0
Date:
last changed on 2012-03-29

Definition at line 120 of file FitLine.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::FitLine< T >::FitLine (  )

Constructs an empty FitLine object.

Template Parameters:
Tscalar type of the coordinates

Definition at line 181 of file FitLine.hpp.

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

Constructs a FitLine object.

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

Definition at line 202 of file FitLine.hpp.

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

Constructs a FitLine object.

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

Definition at line 223 of file FitLine.hpp.

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

Constructs an FitLine object.

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

Definition at line 246 of file FitLine.hpp.

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

Destructs the FitLine object.

Template Parameters:
Tscalar type of the coordinates

Definition at line 265 of file FitLine.hpp.


Member Function Documentation

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

Runs the fitting algorithm.

Template Parameters:
Tscalar type of the coordinates

There must be at least 2 known points on the line 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(), getSlope() and getYIntercept()

Implements TRTK::Fit2D< T >.

Definition at line 284 of file FitLine.hpp.

template<class T >
const Coordinate< T > & TRTK::FitLine< T >::getDirectionVector (  ) const

Returns the direction vector of the line.

Template Parameters:
Tscalar type of the coordinates

Definition at line 510 of file FitLine.hpp.

template<class T >
T TRTK::FitLine< T >::getDistanceFromOrigin (  ) const

Returns the shortest distance from the line to the origin.

Template Parameters:
Tscalar type of the coordinates

Definition at line 522 of file FitLine.hpp.

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

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

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

Implements TRTK::Fit2D< T >.

Definition at line 542 of file FitLine.hpp.

template<class T >
const Coordinate< T > & TRTK::FitLine< T >::getNormalVector (  ) const

Returns the normal vector of the line.

Template Parameters:
Tscalar type of the coordinates

Definition at line 569 of file FitLine.hpp.

template<class T >
const Coordinate< T > & TRTK::FitLine< T >::getPointOnLineSegment (  ) const

Returns the center of the line segment.

Template Parameters:
Tscalar type of the coordinates

Definition at line 498 of file FitLine.hpp.

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

Returns the root mean square error.

Template Parameters:
Tscalar type of the coordinates

Implements TRTK::Fit2D< T >.

Definition at line 581 of file FitLine.hpp.

template<class T >
T TRTK::FitLine< T >::getSlope (  ) const

Returns the slope of the line.

Template Parameters:
Tscalar type of the coordinates
Note:
If the line is parallel to the y-axis, slope is set to numeric_limits<T>::infinity().

Definition at line 620 of file FitLine.hpp.

template<class T >
T TRTK::FitLine< T >::getXIntercept (  ) const

Returns the x-intercept of the line.

Template Parameters:
Tscalar type of the coordinates
Note:
If the line is parallel to the x-axis, x-intercept is set to numeric_limits<T>::quiet_NaN().

Definition at line 635 of file FitLine.hpp.

template<class T >
T TRTK::FitLine< T >::getYIntercept (  ) const

Returns y-intercept of the line.

Template Parameters:
Tscalar type of the coordinates
Note:
If the line is parallel to the y-axis, y-intercept is set to numeric_limits<T>::quiet_NaN().

Definition at line 650 of file FitLine.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< 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.

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.


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