vgl_fit_quadric_3d.h
Go to the documentation of this file.
1 // This is core/vgl/algo/vgl_fit_quadric_3d.h
2 #ifndef vgl_fit_quadric_3d_h_
3 #define vgl_fit_quadric_3d_h_
4 //:
5 // \file
6 // \brief Fits a quadric surface to a set of 3D points
7 // \author Joseph L. Mundy
8 // \date July 7, 2017
9 //
10 // Variousl algorithms for quadric fitting
11 // 1) Taubin method - first order approximation to Euclidean distance from point to quadric
12 // Normalization by the gradient of the algebraic distance.Formulation as generalized Eigensystem.
13 // (G. Taubin, Estimation of Planar Curves, Surfaces,
14 // and Nonplanar Space Curves,Defined by Implicit Equations with Applications
15 // to Edge and Range Image Segmentation IEEE PAMI, v13, No. 11, 1991.)
16 //
17 //
18 // 2) Alliare method - the normalizing constraint is a quadratic form that restricts the quadric class
19 // in terms of the invariants of the upper 3x3 matrix of the quadratic form.
20 // Formulation as generalized Eigensystem.
21 // (Type-Constrained Robust Fitting of Quadrics with Application to the 3D Morphological
22 // Characterization of Saddle-Shaped Articular Surfaces, S. Allaire et al,
23 // Proc.International Conference on Computer Vision , 2007.)
24 //
25 // \verbatim
26 // Modifications
27 // none
28 // \endverbatim
29 #include <vector>
30 #include <iosfwd>
31 #include <vgl/vgl_point_3d.h>
32 #include <vgl/vgl_homg_point_3d.h>
33 #include <vgl/vgl_quadric_3d.h>
34 #ifdef _MSC_VER
35 # include <vcl_msvc_warnings.h>
36 #endif
37 
38 template <class T>
40 {
41  // Data Members--------------------------------------------------------------
42  protected:
43  //: fit an ellipsoid using the linear Allaire method
44  // returns the average distance from the points to the quadric
45  std::vector<vgl_homg_point_3d<T> > points_;
48 
49  public:
50 
51  // Constructors/Initializers/Destructors-------------------------------------
52 
53  vgl_fit_quadric_3d() = default;
54 
55  vgl_fit_quadric_3d(std::vector<vgl_point_3d<T> > points);
56 
57  ~vgl_fit_quadric_3d() = default;
58 
59  // Operations---------------------------------------------------------------
60 
61  //: add a point to point set
62  void add_point(vgl_point_3d<T> const &p);
63  void add_point(const T x, const T y, const T z);
64 
65  //: clear internal data
66  void clear();
67 
68  //: fit a general quadric to the stored points using the linear Taubin method.
69  // No restriction on type.
70  // returns the average distance from the points to the quadric.
71  // error conditions are reported on outstream, if defined.
72  T fit_linear_Taubin(std::ostream* outstream=nullptr);
73 
74  //: fit an ellipsoid using the linear Allaire method
75  // returns the average distance from the points to the ellipsoid
76  // error conditions are reported on outstream, if defined.
77  T fit_ellipsoid_linear_Allaire(std::ostream* outstream=nullptr);
78 
79  //: fit a quadric class from the set{ hyperboloid_of_one_sheets,
80  // hyperboloid_of_two_sheets, real_elliptic_cone,
81  // hyperbolic_paraboloid, hyperbolic_cylinder}
82  // returns the average distance from the points to the ellipsoid
83  // error conditions are reported on outstream, if defined.
84  T fit_saddle_shaped_quadric_linear_Allaire(std::ostream* outstream=nullptr);
85 
86  // Data Access---------------------------------------------------------------
87 
88  std::vector<vgl_point_3d<T> > get_points() const;
89 
90  //: The fit computed by the Taubin method
92  //: The fit computed by the Allaire method
94 };
95 
96 #define VGL_FIT_QUADRIC_3D_INSTANTIATE(T) extern "please include vgl/algo/vgl_fit_quadric_3d.hxx first"
97 
98 #endif // vgl_fit_quadric_3d_h_
point in projective 3D space
void clear()
clear internal data.
std::vector< vgl_point_3d< T > > get_points() const
vgl_quadric_3d< T > & quadric_Allaire_fit()
The fit computed by the Allaire method.
vgl_fit_quadric_3d()=default
A 2nd order algebraic surface in 3-d.
vgl_quadric_3d< T > quadric_Taubin_
a point in 3D nonhomogeneous space
T fit_ellipsoid_linear_Allaire(std::ostream *outstream=nullptr)
fit an ellipsoid using the linear Allaire method.
T fit_saddle_shaped_quadric_linear_Allaire(std::ostream *outstream=nullptr)
fit a quadric class from the set{ hyperboloid_of_one_sheets,.
void add_point(vgl_point_3d< T > const &p)
add a point to point set.
vgl_quadric_3d< T > & quadric_Taubin_fit()
The fit computed by the Taubin method.
std::vector< vgl_homg_point_3d< T > > points_
fit an ellipsoid using the linear Allaire method.
~vgl_fit_quadric_3d()=default
T fit_linear_Taubin(std::ostream *outstream=nullptr)
fit a general quadric to the stored points using the linear Taubin method.
vgl_quadric_3d< T > quadric_Allaire_