vgl_fit_plane_3d.h
Go to the documentation of this file.
1 // This is core/vgl/algo/vgl_fit_plane_3d.h
2 #ifndef vgl_fit_plane_3d_h_
3 #define vgl_fit_plane_3d_h_
4 //:
5 // \file
6 // \brief Fits a plane to a set of 3D points
7 // \author Gamze D. Tunali
8 // \date December 18, 2006
9 //
10 // By using the plane formula ax+by+cz+d=0, linear equations are derived
11 // and solved for the parameters (a, b, c, d)
12 //
13 // \verbatim
14 // Modifications
15 // none
16 // \endverbatim
17 
18 #include <vector>
19 #include <iosfwd>
20 #include <vgl/vgl_homg_point_3d.h>
21 #include <vgl/vgl_homg_plane_3d.h>
22 #ifdef _MSC_VER
23 # include <vcl_msvc_warnings.h>
24 #endif
25 
26 template <class T>
27 class vgl_fit_plane_3d
28 {
29  // Data Members--------------------------------------------------------------
30  protected:
31  std::vector<vgl_homg_point_3d<T> > points_;
33 
34  public:
35 
36  // Constructors/Initializers/Destructors-------------------------------------
37 
38  vgl_fit_plane_3d() = default;
39 
40  vgl_fit_plane_3d(std::vector<vgl_homg_point_3d<T> > points);
41 
42  ~vgl_fit_plane_3d() = default;
43 
44  // Operations---------------------------------------------------------------
45 
46  //: add a point to point set
47  void add_point(vgl_homg_point_3d<T> const &p);
48  void add_point(const T x, const T y, const T z);
49 
50  //: clear internal data
51  void clear();
52 
53  //:fits a plane to the stored points
54  // report issues over an ostream if declared
55  bool fit(const T error_marg, std::ostream* outstream=nullptr);
56 
57  //:fits a plane returning the smallest singular value
58  //:of the data scatter matrix decomposition, a measure
59  //:of variance in the direction of the plane normal
60  T fit(std::ostream* outstream=nullptr);
61 
62  // Data Access---------------------------------------------------------------
63 
64  std::vector<vgl_homg_point_3d<T> >& get_points(){return points_;}
65 
66  //: first fit() should be called to get the plane computed
68 };
69 
70 #define VGL_FIT_PLANE_3D_INSTANTIATE(T) extern "please include vgl/algo/vgl_fit_plane_3d.hxx first"
71 
72 #endif // vgl_fit_plane_3d_h_
homogeneous plane in 3D projective space
point in projective 3D space
vgl_homg_plane_3d< T > plane_
void clear()
clear internal data.
Represents a homogeneous 3D point.
Definition: vgl_fwd.h:9
~vgl_fit_plane_3d()=default
bool fit(const T error_marg, std::ostream *outstream=nullptr)
fits a plane to the stored points.
void add_point(vgl_homg_point_3d< T > const &p)
add a point to point set.
std::vector< vgl_homg_point_3d< T > > & get_points()
vgl_homg_plane_3d< T > & get_plane()
first fit() should be called to get the plane computed.
std::vector< vgl_homg_point_3d< T > > points_
vgl_fit_plane_3d()=default