core/vgl/algo/vgl_fit_plane_3d.h
Go to the documentation of this file.
00001 // This is core/vgl/algo/vgl_fit_plane_3d.h
00002 #ifndef vgl_fit_plane_3d_h_
00003 #define vgl_fit_plane_3d_h_
00004 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00005 #pragma interface
00006 #endif
00007 //:
00008 // \file
00009 // \brief Fits a plane to a set of 3D points
00010 // \author Gamze D. Tunali
00011 // \date December 18, 2006
00012 //
00013 //
00014 //  By using the plane formula ax+by+cz+d=0, linear equations are derived
00015 //  and solved for the paramaters (a, b, c, d)
00016 //
00017 // \verbatim
00018 //  Modifications
00019 //   none
00020 // \endverbatim
00021 
00022 #include <vcl_vector.h>
00023 #include <vgl/vgl_homg_point_3d.h>
00024 #include <vgl/vgl_homg_plane_3d.h>
00025 
00026 template <class T>
00027 class vgl_fit_plane_3d
00028 {
00029   // Data Members--------------------------------------------------------------
00030  protected:
00031   vcl_vector<vgl_homg_point_3d<T> > points_;
00032   vgl_homg_plane_3d<T> plane_;
00033 
00034  public:
00035 
00036   // Constructors/Initializers/Destructors-------------------------------------
00037 
00038    vgl_fit_plane_3d() {}
00039 
00040    vgl_fit_plane_3d(vcl_vector<vgl_homg_point_3d<T> > points);
00041 
00042   ~vgl_fit_plane_3d() {}
00043 
00044   // Operations---------------------------------------------------------------
00045 
00046   //: add a point to point set
00047   void add_point(vgl_homg_point_3d<T> const &p);
00048   void add_point(const T x, const T y, const T z);
00049 
00050   //: clear internal data
00051   void clear();
00052 
00053   //:fits a plane to the stored points
00054   bool fit(const T error_marg);
00055 
00056   // Data Access---------------------------------------------------------------
00057 
00058   vcl_vector<vgl_homg_point_3d<T> >& get_points(){return points_;}
00059 
00060   //: first fit() should be called to get the plane computed
00061   vgl_homg_plane_3d<T>& get_plane() {return plane_;}
00062 };
00063 
00064 #define VGL_FIT_PLANE_3D_INSTANTIATE(T) extern "please include vgl/algo/vgl_fit_plane_3d.txx first"
00065 
00066 #endif // vgl_fit_plane_3d_h_