Estimates the parameters of a 3D sphere from a set of points lying on the surface. More...
#include <FitSphere.hpp>
Inheritance diagram for TRTK::FitSphere< T >:
Collaboration diagram for TRTK::FitSphere< T >: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::VectorXT | VectorXT |
| Column vector of arbitrary size 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. | |
| typedef super::Matrix3T | Matrix3T |
| 3 x 3 matrix with value type T. | |
Public Member Functions | |
| FitSphere () | |
| Constructs an empty FitSphere object. | |
| FitSphere (const std::vector< Coordinate< T > > &points) | |
| Constructs a FitSphere object. | |
| FitSphere (const std::vector< Vector3T > &points) | |
| Constructs a FitSphere object. | |
| FitSphere (const std::vector< Vector4T, Eigen::aligned_allocator< Vector4T > > &points) | |
| Constructs an FitSphere object. | |
| virtual | ~FitSphere () |
| Destructs the FitSphere object. | |
| void | compute () |
| Runs the fitting algorithm. | |
| const Coordinate< T > & | getCenterPoint () const |
| Returns the center point. | |
| T | getDistanceTo (const Coordinate< T > &point) const |
| Returns the shortest distance from the given point to the sphere. | |
| unsigned | getNumberPointsRequired () const |
| Returns the minimum number of data points required to compute a model. | |
| T | getRadius () const |
| Returns the radius of the sphere. | |
| T | getRMS () const |
| Returns the root mean square error. | |
| 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 3D sphere from a set of points lying on the surface.
| T | scalar type of the coordinates |
This class allows estimating the center point and the radius of a 3D sphere whose surface points are known. The points may be erroneous since a least square fitting is done. If \( (x_i, y_i, z_i)^T \) are the data points, \( (x_0, y_0, z_0)^T \) the center point, and \( r \) the radius, then FitSphere tries to minimize the sum of the squared residuals as shown below:
\[ (x_0, y_0, z_0, r) := \arg\min_{(x_0, y_0, z_0, r)} \sum_{i=1}^N \left[(x_i - x_0)^2 + (y_i - y_0)^2 + (z_i - z_0)^2 - r^2 \right]^2 \]
Here is an more elaborate example to see how to use the class:
#include <cstdlib> #include <iostream> #include <TRTK/FitSphere.hpp> #include <TRTK/Tools.hpp> using namespace std; using namespace TRTK; using namespace TRTK::Tools; int main() { double pi = 3.1415926535; vector<Coordinate<double> > surfacePoints; // Construct some points lying on a sphere. double radius = 7; Coordinate<double> centerPoint = Coordinate<double>(1, 8, 5); for (double theta = 0.0; theta < 2.0 * pi; theta += pi/10) { for (double phi = 0.0; phi < 2.0 * pi; phi += pi/10) { // Convert the speherical coordinates into cartesian coordinates // and add some noise. double x = radius * sin(theta) * cos(phi) + 0.1 * randn(); double y = radius * sin(theta) * sin(phi) + 0.1 * randn(); double z = radius * cos(theta) + 0.1 * randn(); Coordinate<double> point = centerPoint + Coordinate<double>(x, y, z); surfacePoints.push_back(point); } } // Estimate the parameters of the sphere. FitSphere<double> fitSphere(surfacePoints); fitSphere.compute(); cout << "Center point: " << fitSphere.getCenterPoint() << endl; cout << "Radius: " << fitSphere.getRadius() << endl; return 0; }
Output:
Center point: (0.998629, 8.00457, 5.0021) Radius: 7.00053
Definition at line 126 of file FitSphere.hpp.
| TRTK::FitSphere< T >::FitSphere | ( | ) |
Constructs an empty FitSphere object.
| T | scalar type of the coordinates |
Definition at line 173 of file FitSphere.hpp.
| TRTK::FitSphere< T >::FitSphere | ( | const std::vector< Coordinate< T > > & | points ) |
Constructs a FitSphere object.
| T | scalar type of the coordinates |
| [in] | points | Points lying on the surface of a sphere. The points can be 3D or 4D homogeneous coordinates. |
Definition at line 189 of file FitSphere.hpp.
| TRTK::FitSphere< T >::FitSphere | ( | const std::vector< Vector3T > & | points ) |
Constructs a FitSphere object.
| T | scalar type of the coordinates |
| [in] | points | Points lying on the surface of a sphere. |
Definition at line 205 of file FitSphere.hpp.
| TRTK::FitSphere< T >::FitSphere | ( | const std::vector< Vector4T, Eigen::aligned_allocator< Vector4T > > & | points ) |
Constructs an FitSphere object.
| T | scalar type of the coordinates |
| [in] | points | Points lying on the surface of a sphere. The points are assumed to be homogeneous coordinates, whose forth coordinate entry is equal to one. |
Definition at line 223 of file FitSphere.hpp.
| TRTK::FitSphere< T >::~FitSphere | ( | ) | [virtual] |
Destructs the FitSphere object.
| T | scalar type of the coordinates |
Definition at line 237 of file FitSphere.hpp.
| void TRTK::FitSphere< T >::compute | ( | ) | [virtual] |
Runs the fitting algorithm.
| T | scalar type of the coordinates |
There must be at least 4 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 256 of file FitSphere.hpp.
| const Coordinate< T > & TRTK::FitSphere< T >::getCenterPoint | ( | ) | const |
Returns the center point.
| T | scalar type of the coordinates |
Definition at line 364 of file FitSphere.hpp.
| T TRTK::FitSphere< T >::getDistanceTo | ( | const Coordinate< T > & | point ) | const [virtual] |
Returns the shortest distance from the given point to the sphere.
| T | scalar type of the coordinates |
| [in] | point | A 3D coordinate. |
Implements TRTK::Fit3D< T >.
Definition at line 378 of file FitSphere.hpp.
| T TRTK::FitSphere< T >::getRadius | ( | ) | const |
Returns the radius of the sphere.
| T | scalar type of the coordinates |
Definition at line 400 of file FitSphere.hpp.
| T TRTK::FitSphere< T >::getRMS | ( | ) | const [virtual] |
Returns the root mean square error.
| T | scalar type of the coordinates |
Implements TRTK::Fit3D< T >.
Definition at line 412 of file FitSphere.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