Estimates the parameters of a line in 3D space from a set of points lying on the line. More...
#include <FitLine3D.hpp>
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. | |
T | 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. | |
T | getDistanceFromOrigin () const |
Returns the shortest distance between the line and 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< 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 |
Estimates the parameters of a line in 3D space from a set of points lying on the line.
T | scalar 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
Definition at line 115 of file FitLine3D.hpp.
TRTK::FitLine3D< T >::FitLine3D | ( | ) |
Constructs an empty FitLine3D object.
T | scalar type of the coordinates |
Definition at line 163 of file FitLine3D.hpp.
TRTK::FitLine3D< T >::FitLine3D | ( | const std::vector< Coordinate< T > > & | points ) |
Constructs a FitLine3D object.
T | scalar type of the coordinates |
[in] | points | Points lying on the line. The points can be 3D or 4D homogeneous coordinates. |
Definition at line 179 of file FitLine3D.hpp.
TRTK::FitLine3D< T >::FitLine3D | ( | const std::vector< Vector3T > & | points ) |
Constructs a FitLine3D object.
T | scalar type of the coordinates |
[in] | points | Points lying on the line. |
Definition at line 195 of file FitLine3D.hpp.
TRTK::FitLine3D< T >::FitLine3D | ( | const std::vector< Vector4T, Eigen::aligned_allocator< Vector4T > > & | points ) |
Constructs an FitLine3D object.
T | scalar type of the coordinates |
[in] | points | Points 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.
TRTK::FitLine3D< T >::~FitLine3D | ( | ) | [virtual] |
Destructs the FitLine3D object.
T | scalar type of the coordinates |
Definition at line 227 of file FitLine3D.hpp.
void TRTK::FitLine3D< T >::compute | ( | ) | [virtual] |
Runs the fitting algorithm.
T | scalar type of the coordinates |
There must be at least 2 known points on the line to perform the fitting.
ErrorObj | If there are not enough points to fit the line, an error object is thrown and its error code is set to WRONG_POINT_SIZE . |
Implements TRTK::Fit3D< T >.
Definition at line 246 of file FitLine3D.hpp.
const Coordinate< T > & TRTK::FitLine3D< T >::getDirectionVector | ( | ) | const |
Returns the direction vector of the line.
T | scalar type of the coordinates |
Definition at line 319 of file FitLine3D.hpp.
T TRTK::FitLine3D< T >::getDistanceFromOrigin | ( | ) | const |
Returns the shortest distance between the line and the origin.
T | scalar type of the coordinates |
Definition at line 396 of file FitLine3D.hpp.
T TRTK::FitLine3D< T >::getDistanceTo | ( | const Coordinate< T > & | point ) | const [virtual] |
Returns the shortest distance from the line to the given point.
T | scalar type of the coordinates |
[in] | point | A 3D coordinate. |
Implements TRTK::Fit3D< T >.
Definition at line 442 of file FitLine3D.hpp.
Coordinate< T > TRTK::FitLine3D< T >::getNormalVector | ( | ) | const |
Returns a normal vector.
T | scalar 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.
const Coordinate< T > & TRTK::FitLine3D< T >::getPointOnLineSegment | ( | ) | const |
Returns a point on the line.
T | scalar type of the coordinates |
Definition at line 480 of file FitLine3D.hpp.
T TRTK::FitLine3D< T >::getRMS | ( | ) | const [virtual] |
Returns the root mean square error.
T | scalar type of the coordinates |
Implements TRTK::Fit3D< T >.
Definition at line 492 of file FitLine3D.hpp.
void TRTK::Fit3D< T >::setPoints | ( | const std::vector< Vector4T, Eigen::aligned_allocator< Vector4T > > & | points ) | [inherited] |
Sets the point set.
T | scalar type of the coordinates |
[in] | points | 4D homogeneous coordinates. |
void TRTK::Fit3D< T >::setPoints | ( | const std::vector< Coordinate< T > > & | points ) | [virtual, inherited] |
Sets the point set.
T | scalar type of the coordinates |
[in] | points | The points can either be plain 3D or 4D homogeneous coordinates. |
ErrorObj | If 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 >.
void TRTK::Fit3D< T >::setPoints | ( | const std::vector< Vector3T > & | points ) | [inherited] |
Documentation generated by Doxygen