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

TRTK::FitPlane< T > Class Template Reference

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

#include <FitPlane.hpp>

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

List of all members.

Public Types

typedef super::Vector3T Vector3T
 3D column vector with value type T.
typedef super::Vector4T Vector4T
 4D column vector with value type T.
typedef super::VectorXT VectorXT
 Column vector of arbitrary size with value type T.
typedef super::Matrix3T Matrix3T
 3 x 3 matrix 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::Vector2T Vector2T
 2D column vector 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
}

Public Member Functions

 FitPlane ()
 Constructs an empty FitPlane object.
 FitPlane (const std::vector< Coordinate< T > > &points)
 Constructs a FitPlane object.
 FitPlane (const std::vector< Vector3T > &points)
 Constructs a FitPlane object.
 FitPlane (const std::vector< Vector4T, Eigen::aligned_allocator< Vector4T > > &points)
 Constructs an FitPlane object.
virtual ~FitPlane ()
 Destructs the FitPlane 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 > & getNormal () const
 Returns the normal of the plane.
const Coordinate< T > & getPointInPlane () const
 Returns a point lying in the plane.
getDistanceFromOrigin () const
 Returns the shortest distance between the plane and the origin.
getDistanceTo (const Coordinate< T > &point) const
 Returns the shortest distance between the plane and 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::FitPlane< T >

Estimates the parameters of a 2D plane in 3D space from a set of points lying on the surface.

Template Parameters:
Tscalar type of the coordinates

This class allows estimating the normal of a plane as well as a representative position of a point in the plane. The points may be erroneous since a least square fitting is done. If \( x_i \) are the data points, \( \bar{x} \) is a point in the plane and \( n \) is the normal of the plane, then FitPlane tries to minimize the following objective function:

\[ n := \arg\min_{n} \sum_{i=1}^N ( (x_i - \bar{x})^T \cdot n )^2 \]

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

 #include <iostream>

 #include "TRTK/Coordinate.hpp"
 #include "TRTK/FitPlane.hpp"
 #include "TRTK/Tools.hpp"

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

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

     vector<Coordinate> points;

     // Construct points lying on a plane.

     Coordinate v1(3, 2, 4);
     Coordinate v2(1, 0, 5);
     Coordinate origin_point(10.0, 30.0, 50.0);

     for (int i = 0; i < 100; ++i)
     {
         Coordinate point_in_plane = origin_point + rand(-10, 10) * v1 + rand(-10, 10) * v2;

         // Add some noise.

         point_in_plane += Coordinate(randn(), randn(), randn());

         points.push_back(point_in_plane);
     }

     // Estimate the plane parameters.

     FitPlane<double> fitPlane;
     fitPlane.setPoints(points);

     fitPlane.compute();

     // Print the estimated values.

     cout << "Normal vector: " << v1.cross(v2).normalize() << endl;
     cout << "Estimated normal vector: " << fitPlane.getNormal() << endl;
     cout << "Estimated center point: " << fitPlane.getPointInPlane();
 }

Output:

 Normal vector: (0.666667, -0.733333, -0.133333)
 Estimated normal vector: (-0.674243, 0.726738, 0.131331)
 Estimated center point: (9.91952, 30.2422, 47.7684)
Author:
Christoph Haenisch, Fabian Killus
Version:
0.5.0
Date:
last changed on 2012-03-19

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

Constructs an empty FitPlane object.

Template Parameters:
Tscalar type of the coordinates

Definition at line 167 of file FitPlane.hpp.

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

Constructs a FitPlane object.

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

Definition at line 184 of file FitPlane.hpp.

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

Constructs a FitPlane object.

Template Parameters:
Tscalar type of the coordinates
Parameters:
[in]pointsPoints lying on the surface of a plane.

Definition at line 201 of file FitPlane.hpp.

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

Constructs an FitPlane object.

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

Definition at line 220 of file FitPlane.hpp.

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

Destructs the FitPlane object.

Template Parameters:
Tscalar type of the coordinates

Definition at line 235 of file FitPlane.hpp.


Member Function Documentation

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

Runs the fitting algorithm.

Template Parameters:
Tscalar type of the coordinates

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

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

Implements TRTK::Fit3D< T >.

Definition at line 254 of file FitPlane.hpp.

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

Returns the shortest distance between the plane and the origin.

Template Parameters:
Tscalar type of the coordinates

Definition at line 375 of file FitPlane.hpp.

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

Returns the shortest distance between the plane and the given point.

Template Parameters:
Tscalar type of the coordinates

Implements TRTK::Fit3D< T >.

Definition at line 393 of file FitPlane.hpp.

template<class T >
const Coordinate< T > & TRTK::FitPlane< T >::getNormal (  ) const

Returns the normal of the plane.

Template Parameters:
Tscalar type of the coordinates

Definition at line 426 of file FitPlane.hpp.

template<class T >
const Coordinate< T > & TRTK::FitPlane< T >::getPointInPlane (  ) const

Returns a point lying in the plane.

Template Parameters:
Tscalar type of the coordinates

Definition at line 445 of file FitPlane.hpp.

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

Returns the root mean square error.

Template Parameters:
Tscalar type of the coordinates

Implements TRTK::Fit3D< T >.

Definition at line 457 of file FitPlane.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< 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< 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