00001 // This is oxl/osl/osl_fit_circle.h 00002 #ifndef osl_fit_circle_h_ 00003 #define osl_fit_circle_h_ 00004 #ifdef VCL_NEEDS_PRAGMA_INTERFACE 00005 #pragma interface 00006 #endif 00007 //: 00008 // \file 00009 // \brief least-squares fit of N points to a circle 00010 // 00011 // Fits N given points to a circle using SVD. 00012 // Derived from a program originally 00013 // written by Zhen Song and Dr. Chen, Yangquan 00014 // 00015 // error() flag is set, if an error occurs. There's a constructor 00016 // for an edgel chain as well as for an array of points, but 00017 // only the raw points of the edgels will be used. 00018 // 00019 // \author Markus Meyer (meyer@mesw.de) 00020 00021 #include <vcl_list.h> 00022 #include <vgl/vgl_point_2d.h> 00023 #include <osl/osl_edgel_chain.h> 00024 00025 class osl_fit_circle 00026 { 00027 public: 00028 //: Construct from list of 2d points of double 00029 osl_fit_circle(const vcl_list<vgl_point_2d<double> > &points); 00030 00031 //: Construct from edgel chain (use only raw edge coordinates) 00032 osl_fit_circle(const osl_edgel_chain& chain); 00033 00034 // Accessors 00035 00036 //: get center of circle as vgl_point_2d 00037 const vgl_point_2d<double>& center() const { return center_; } 00038 00039 //: Get radius of circle as double 00040 double radius() const { return radius_; } 00041 00042 //: If error() returns true, there was an error during calculation. 00043 // Normally because of wrong or insufficient input data. 00044 bool error() const { return error_; } 00045 00046 //: Returns the maximum difference between the points and the calculated circle 00047 // (length of longest tangent from point to circle) 00048 double max_diff() const { return max_diff_; } 00049 00050 //: Return the average difference between the points and the calculated circle 00051 // (average of length of tangents from points to circle) 00052 double avg_diff() const { return avg_diff_; } 00053 00054 protected: 00055 void calculate(const vcl_list<vgl_point_2d<double> > &points); 00056 00057 bool error_; // error flag 00058 double max_diff_, avg_diff_; 00059 double radius_; 00060 vgl_point_2d<double> center_; 00061 }; 00062 00063 #endif // osl_fit_circle_h_