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 //  By using the plane formula ax+by+cz+d=0, linear equations are derived
00014 //  and solved for the parameters (a, b, c, d)
00015 //
00016 // \verbatim
00017 //  Modifications
00018 //   none
00019 // \endverbatim
00020 
00021 #include <vcl_vector.h>
00022 #include <vgl/vgl_homg_point_3d.h>
00023 #include <vgl/vgl_homg_plane_3d.h>
00024 #include <vcl_iosfwd.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   // report issues over an ostream if declared
00055   bool fit(const T error_marg, vcl_ostream* outstream=0);
00056 
00057   // Data Access---------------------------------------------------------------
00058 
00059   vcl_vector<vgl_homg_point_3d<T> >& get_points(){return points_;}
00060 
00061   //: first fit() should be called to get the plane computed
00062   vgl_homg_plane_3d<T>& get_plane() {return plane_;}
00063 };
00064 
00065 #define VGL_FIT_PLANE_3D_INSTANTIATE(T) extern "please include vgl/algo/vgl_fit_plane_3d.txx first"
00066 
00067 #endif // vgl_fit_plane_3d_h_