core/vgl/algo/vgl_fit_conics_2d.h
Go to the documentation of this file.
00001 // This is core/vgl/algo/vgl_fit_conics_2d.h
00002 #ifndef vgl_fit_conics_2d_h_
00003 #define vgl_fit_conics_2d_h_
00004 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00005 #pragma interface
00006 #endif
00007 //:
00008 // \file
00009 // \brief Fits a contiguous set of conic segments to a sampled curve
00010 // \author J.L. Mundy
00011 // \date June 18, 2005
00012 //
00013 //  The parameters are:
00014 //  -  min_length - the smallest number of points to fit with a conic
00015 //  -  tol - the threshold on mean square distance from points to the conic
00016 //  -  line_thresh - threshold for preferring a line over a conic
00017 //
00018 //  A conic segment is incrementally fit to the curve until the tolerance
00019 //  is exceeded. When the tolerance is exceeded, the conic segment is
00020 //  output and a new conic fit is started.
00021 //
00022 // \verbatim
00023 //  Modifications
00024 //   none
00025 // \endverbatim
00026 #include <vcl_vector.h>
00027 #include <vgl/vgl_point_2d.h>
00028 #include <vgl/vgl_conic_segment_2d.h>
00029 
00030 template <class T>
00031 class vgl_fit_conics_2d
00032 {
00033   // Data Members--------------------------------------------------------------
00034  protected:
00035   vcl_vector<vgl_point_2d<T> > curve_;
00036   vcl_vector<vgl_conic_segment_2d<T> > segs_;
00037   unsigned int min_length_;
00038   T tol_;
00039  public:
00040 
00041   // Constructors/Initializers/Destructors-------------------------------------
00042 
00043   vgl_fit_conics_2d(const unsigned min_length = 10,
00044                     const T tol = 0.01);
00045 
00046   ~vgl_fit_conics_2d() {}
00047 
00048   // Operations----------------------------------------------------------------
00049 
00050   //: set parameters
00051   void set_min_fit_length(const unsigned min_fit_length){min_length_ = min_fit_length;}
00052   void set_rms_error_tol(const T rms_error_tol){tol_ = rms_error_tol;}
00053 
00054   //: add a point to the curve
00055   void add_point(vgl_point_2d<T> const &p);
00056   void add_point(const T x, const T y);
00057 
00058   //: add an entire curve
00059   void add_curve(vcl_vector<vgl_point_2d<T> > const & curve){curve_=curve;}
00060 
00061   //: clear internal data
00062   void clear();
00063 
00064   //: the fitting method
00065   bool fit();
00066 
00067   // Data Access---------------------------------------------------------------
00068   vcl_vector<vgl_point_2d<T> >& get_points(){return curve_;}
00069   vcl_vector<vgl_conic_segment_2d<T> >& get_conic_segs(){return segs_;}
00070 
00071  protected:
00072   //: output a conic that fits from start to end
00073   void output(const unsigned start_index, const unsigned end_index,
00074               vgl_conic<T> const& conic);
00075 };
00076 
00077 #define VGL_FIT_CONICS_2D_INSTANTIATE(T) extern "please include vgl/algo/vgl_fit_conics_2d.txx first"
00078 
00079 #endif // vgl_fit_conics_2d_h_