Estimates the parameters of a 2D plane in 3D space from a set of points lying on the surface. More...
#include <FitPlane.hpp>
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. | |
T | 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. | |
T | getDistanceFromOrigin () const |
Returns the shortest distance between the plane and the origin. | |
T | 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 |
Estimates the parameters of a 2D plane in 3D space from a set of points lying on the surface.
T | scalar 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)
Definition at line 118 of file FitPlane.hpp.
enum TRTK::Fit::Error [inherited] |
TRTK::FitPlane< T >::FitPlane | ( | ) |
Constructs an empty FitPlane object.
T | scalar type of the coordinates |
Definition at line 167 of file FitPlane.hpp.
TRTK::FitPlane< T >::FitPlane | ( | const std::vector< Coordinate< T > > & | points ) |
Constructs a FitPlane object.
T | scalar type of the coordinates |
[in] | points | Points lying on the surface of a plane. The points can be 3D or 4D homogeneous coordinates. |
Definition at line 184 of file FitPlane.hpp.
TRTK::FitPlane< T >::FitPlane | ( | const std::vector< Vector3T > & | points ) |
Constructs a FitPlane object.
T | scalar type of the coordinates |
[in] | points | Points lying on the surface of a plane. |
Definition at line 201 of file FitPlane.hpp.
TRTK::FitPlane< T >::FitPlane | ( | const std::vector< Vector4T, Eigen::aligned_allocator< Vector4T > > & | points ) |
Constructs an FitPlane object.
T | scalar type of the coordinates |
[in] | points | Points 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.
TRTK::FitPlane< T >::~FitPlane | ( | ) | [virtual] |
Destructs the FitPlane object.
T | scalar type of the coordinates |
Definition at line 235 of file FitPlane.hpp.
void TRTK::FitPlane< T >::compute | ( | ) | [virtual] |
Runs the fitting algorithm.
T | scalar type of the coordinates |
There must be at least 3 surface points to perform the fitting.
ErrorObj | If there are not enough points to fit the sphere, an error object is thrown and its error code is set to WRONG_POINT_SIZE . |
Implements TRTK::Fit3D< T >.
Definition at line 254 of file FitPlane.hpp.
T TRTK::FitPlane< T >::getDistanceFromOrigin | ( | ) | const |
Returns the shortest distance between the plane and the origin.
T | scalar type of the coordinates |
Definition at line 375 of file FitPlane.hpp.
T TRTK::FitPlane< T >::getDistanceTo | ( | const Coordinate< T > & | point ) | const [virtual] |
Returns the shortest distance between the plane and the given point.
T | scalar type of the coordinates |
Implements TRTK::Fit3D< T >.
Definition at line 393 of file FitPlane.hpp.
const Coordinate< T > & TRTK::FitPlane< T >::getNormal | ( | ) | const |
Returns the normal of the plane.
T | scalar type of the coordinates |
Definition at line 426 of file FitPlane.hpp.
const Coordinate< T > & TRTK::FitPlane< T >::getPointInPlane | ( | ) | const |
Returns a point lying in the plane.
T | scalar type of the coordinates |
Definition at line 445 of file FitPlane.hpp.
T TRTK::FitPlane< T >::getRMS | ( | ) | const [virtual] |
Returns the root mean square error.
T | scalar type of the coordinates |
Implements TRTK::Fit3D< T >.
Definition at line 457 of file FitPlane.hpp.
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< 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< Vector3T > & | points ) | [inherited] |
Documentation generated by Doxygen