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

TRTK::FitLine3D< T > Class Template Reference

Estimates the parameters of a line in 3D space from a set of points lying on the line. More...

#include <FitLine3D.hpp>

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

List of all members.

Public Types

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

Public Member Functions

 FitLine3D ()
 Constructs an empty FitLine3D object.
 FitLine3D (const std::vector< Coordinate< T > > &points)
 Constructs a FitLine3D object.
 FitLine3D (const std::vector< Vector3T > &points)
 Constructs a FitLine3D object.
 FitLine3D (const std::vector< Vector4T, Eigen::aligned_allocator< Vector4T > > &points)
 Constructs an FitLine3D object.
virtual ~FitLine3D ()
 Destructs the FitLine3D object.
unsigned getNumberPointsRequired () const
 Returns the minimum number of data points required to compute a model.
void compute ()
 Runs the fitting algorithm.
getRMS () const
 Returns the root mean square error.
const Coordinate< T > & getDirectionVector () const
 Returns the direction vector of the line.
Coordinate< T > getNormalVector () const
 Returns a normal vector.
const Coordinate< T > & getPointOnLineSegment () const
 Returns a point on the line.
getDistanceFromOrigin () const
 Returns the shortest distance between the line and the origin.
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< Vector3T > &)
 Sets the point set.
void setPoints (const std::vector< Vector4T, Eigen::aligned_allocator< Vector4T > > &)
 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::FitLine3D< T >

Estimates the parameters of a line in 3D space from a set of points lying on the line.

Template Parameters:
Tscalar type of the coordinates

This class allows estimating the direction vector, normal vector, et cetera of a line from a given set of points. The points may be erroneous since a principal component analysis (PCA) is performed; it is assumed, that the line propagates in the direction of largest variance.

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

 #include <iostream>

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

 using namespace std;
 using namespace TRTK;
 using namespace TRTK::Tools;

 int main()
 {
     typedef Coordinate<double> Coordinate;

     // Construct some points lying on a line.

     vector<Coordinate> points;

     Coordinate direction_vector = Coordinate(4, 0, 3);
     Coordinate point_on_line = Coordinate(1, 3, -1);

     for (int i = 0; i < 100; ++i)
     {
         Coordinate point = point_on_line + rand(-10.0, 10.0) * direction_vector;

         // Add some noise.

         point.x() += 0.1 * randn();
         point.y() += 0.1 * randn();
         point.z() += 0.1 * randn();

         points.push_back(point);
     }

     // Estimate the line parameters.

     FitLine3D<double> fitLine3D(points);
     fitLine3D.compute();

     cout << "The direction vector is: " << fitLine3D.getDirectionVector() << endl;
     cout << "A point on the line is: " << fitLine3D.getPointOnLineSegment() << endl;
     cout << "The distance from the origin is: " << fitLine3D.getDistanceFromOrigin() << endl;

     return 0;
 }

Output:

 The direction vector is: (0.800062, 0.000370052, 0.599917)
 A point on the line is: (2.81097, 3.00661, 0.351312)
 The distance from the origin is: 3.31798
Author:
Christoph Haenisch, Fabian Killus
Version:
0.4.1
Date:
last changed on 2013-08-20

Definition at line 115 of file FitLine3D.hpp.


Constructor & Destructor Documentation

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

Constructs an empty FitLine3D object.

Template Parameters:
Tscalar type of the coordinates

Definition at line 163 of file FitLine3D.hpp.

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

Constructs a FitLine3D object.

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

Definition at line 179 of file FitLine3D.hpp.

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

Constructs a FitLine3D object.

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

Definition at line 195 of file FitLine3D.hpp.

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

Constructs an FitLine3D object.

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

Definition at line 213 of file FitLine3D.hpp.

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

Destructs the FitLine3D object.

Template Parameters:
Tscalar type of the coordinates

Definition at line 227 of file FitLine3D.hpp.


Member Function Documentation

template<class T >
void TRTK::FitLine3D< 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 line, an error object is thrown and its error code is set to WRONG_POINT_SIZE.
See also:
setPoints(), getPointOnLineSegment() and getGradient()

Implements TRTK::Fit3D< T >.

Definition at line 246 of file FitLine3D.hpp.

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

Returns the direction vector of the line.

Template Parameters:
Tscalar type of the coordinates

Definition at line 319 of file FitLine3D.hpp.

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

Returns the shortest distance between the line and the origin.

Template Parameters:
Tscalar type of the coordinates

Definition at line 396 of file FitLine3D.hpp.

template<class T >
T TRTK::FitLine3D< 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 3D coordinate.

Implements TRTK::Fit3D< T >.

Definition at line 442 of file FitLine3D.hpp.

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

Returns a normal vector.

Template Parameters:
Tscalar type of the coordinates

The normal is defined such that starting at the origin and running along the normal yields a point on the line.

Definition at line 334 of file FitLine3D.hpp.

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

Returns a point on the line.

Template Parameters:
Tscalar type of the coordinates

Definition at line 480 of file FitLine3D.hpp.

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

Returns the root mean square error.

Template Parameters:
Tscalar type of the coordinates

Implements TRTK::Fit3D< T >.

Definition at line 492 of file FitLine3D.hpp.

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

Sets the point set.

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

Definition at line 187 of file Fit3D.hpp.

template<class T >
void TRTK::Fit3D< 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 3D or 4D homogeneous coordinates.
Exceptions:
ErrorObjIf there are any coordinates other than 3D or 4D coordinates, an error object is thrown and its error code is set to WRONG_POINT_SIZE.

Implements TRTK::Fit< T >.

Definition at line 135 of file Fit3D.hpp.

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

Sets the point set.

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

Definition at line 168 of file Fit3D.hpp.


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