vgl_fit_conics_2d.h
Go to the documentation of this file.
1 // This is core/vgl/algo/vgl_fit_conics_2d.h
2 #ifndef vgl_fit_conics_2d_h_
3 #define vgl_fit_conics_2d_h_
4 //:
5 // \file
6 // \brief Fits a contiguous set of conic segments to a sampled curve
7 // \author J.L. Mundy
8 // \date June 18, 2005
9 //
10 // The parameters are:
11 // - min_length - the smallest number of points to fit with a conic
12 // - tol - the threshold on mean square distance from points to the conic
13 // - line_thresh - threshold for preferring a line over a conic
14 //
15 // A conic segment is incrementally fit to the curve until the tolerance
16 // is exceeded. When the tolerance is exceeded, the conic segment is
17 // output and a new conic fit is started.
18 //
19 // \verbatim
20 // Modifications
21 // none
22 // \endverbatim
23 #include <vector>
24 #ifdef _MSC_VER
25 # include <vcl_msvc_warnings.h>
26 #endif
27 #include <vgl/vgl_point_2d.h>
29 
30 template <class T>
32 {
33  // Data Members--------------------------------------------------------------
34  protected:
35  std::vector<vgl_point_2d<T> > curve_;
36  std::vector<vgl_conic_segment_2d<T> > segs_;
37  unsigned int min_length_;
38  T tol_;
39  public:
40 
41  // Constructors/Initializers/Destructors-------------------------------------
42 
43  vgl_fit_conics_2d(const unsigned min_length = 10,
44  const T tol = 0.01);
45 
46  ~vgl_fit_conics_2d() = default;
47 
48  // Operations----------------------------------------------------------------
49 
50  //: set parameters
51  void set_min_fit_length(const unsigned min_fit_length){min_length_ = min_fit_length;}
52  void set_rms_error_tol(const T rms_error_tol){tol_ = rms_error_tol;}
53 
54  //: add a point to the curve
55  void add_point(vgl_point_2d<T> const &p);
56  void add_point(const T x, const T y);
57 
58  //: add an entire curve
59  void add_curve(std::vector<vgl_point_2d<T> > const & curve){curve_=curve;}
60 
61  //: clear internal data
62  void clear();
63 
64  //: the fitting method
65  bool fit();
66 
67  // Data Access---------------------------------------------------------------
68  std::vector<vgl_point_2d<T> >& get_points(){return curve_;}
69  std::vector<vgl_conic_segment_2d<T> >& get_conic_segs(){return segs_;}
70 
71  protected:
72  //: output a conic that fits from start to end
73  void output(const unsigned start_index, const unsigned end_index,
74  vgl_conic<T> const& conic);
75 };
76 
77 #define VGL_FIT_CONICS_2D_INSTANTIATE(T) extern "please include vgl/algo/vgl_fit_conics_2d.hxx first"
78 
79 #endif // vgl_fit_conics_2d_h_
void output(const unsigned start_index, const unsigned end_index, vgl_conic< T > const &conic)
output a conic that fits from start to end.
a point in 2D nonhomogeneous space
vgl_fit_conics_2d(const unsigned min_length=10, const T tol=0.01)
Constructor.
std::vector< vgl_point_2d< T > > curve_
std::vector< vgl_conic_segment_2d< T > > & get_conic_segs()
std::vector< vgl_point_2d< T > > & get_points()
~vgl_fit_conics_2d()=default
void add_point(vgl_point_2d< T > const &p)
add a point to the curve.
A quadratic plane curve.
Definition: vgl_conic.h:70
bool fit()
the fitting method.
std::vector< vgl_conic_segment_2d< T > > segs_
unsigned int min_length_
void set_min_fit_length(const unsigned min_fit_length)
set parameters.
void clear()
clear internal data.
void add_curve(std::vector< vgl_point_2d< T > > const &curve)
add an entire curve.
A curve segment with the geometry of a conic.
void set_rms_error_tol(const T rms_error_tol)