00001 #ifndef osl_fit_lines_h 00002 #define osl_fit_lines_h 00003 // .NAME osl_fit_lines 00004 // .INCLUDE osl/osl_fit_lines.h 00005 // .FILE osl_fit_lines.cxx 00006 // 00007 // .SECTION Description 00008 // Definition of a class for fitting lines to Canny edge data 00009 // using orthogonal regression and incremental fitting. 00010 // The input data comes from a DigitalCurve pointed to by an edge. 00011 // If a fit is found the DigitalCurve is replaced by suitable 00012 // ImplicitDigitalLine, and the topology adjusted. 00013 // 00014 // .SECTION Author: 00015 // Charlie Rothwell - 29/1/94 00016 // GE Corporate Research and Development 00017 // 00018 // .SECTION Modifications: 00019 // 20/4/95 CAR: The main call to IncrementalFittoList now has the 00020 // optional flags which enables/disables fitting to curves 00021 // with previously defined geometries which are not 00022 // DigitalCurves. Refitting is the default option. 00023 // 00024 // JLM - Jan 1996 Changed curves_ type from DigitalCurve 00025 // to Curve to reflect restructuring of 00026 // ImplicitDigitalLine, ImplicitDigitalEllipse 00027 // 00028 // 27/3/96 CAR: Introduction of pre-conditioning of the data points 00029 // prior to fitting. For OrthogRegress for normalization 00030 // information. 00031 // Jan 97 DMR: Added a function that will perform simple 00032 // (non-incremental) fitting which can be used in 00033 // conjunction with the breaklines code. Also added 00034 // code to fit using mean absolute error as cutoff. 00035 // 6 June 97: In method IncrementalFittoList corrected protection 00036 // count ( Dorin Ungureanu) 00037 // JLM - Dec 97 Moved some member variables to osl_fit_lines_params 00038 // added group processing. Retained old constructors 00039 // and methods for compatibility 00040 // capes Aug 1999 Added ignore_end_edgels parameter which allows user to 00041 // crop a small number of edgels from the ends of a segment 00042 // before fitting the line. Avoids fitting to the garbage edgels 00043 // which are curving away from the line. 00044 //----------------------------------------------------------------------------- 00045 #include <vcl_list.h> 00046 #include <osl/osl_fit_lines_params.h> 00047 #include <osl/osl_topology.h> 00048 #include <osl/osl_canny_port.h> 00049 #include <osl/osl_OrthogRegress.h> 00050 00051 class osl_fit_lines : public osl_fit_lines_params 00052 { 00053 public: 00054 osl_fit_lines(osl_fit_lines_params const & params, double scale=1.0, double x0=0.0, double y0=0.0); 00055 ~osl_fit_lines(); 00056 00057 inline void SetSqrOrMean(bool sm) { use_square_fit_ = sm; } 00058 inline void SetMinFitLength(unsigned int l) { min_fit_length_ = l; } 00059 inline void SetThreshold(double th) { threshold_ = th; } 00060 inline void SetTheta(double theta) { theta_ = theta; } 00061 inline void SetIgnoreEndEdgels(unsigned int ignore) {ignore_end_edgels_ = ignore; } 00062 00063 // NB. these have the undesirable behaviour of deleting the given edges. 00064 // beware of future changes. use at own risk. complain to fsm 00065 void incremental_fit_to_list(vcl_list<osl_edge *> *in, 00066 vcl_list<osl_edge *> *out); 00067 void simple_fit_to_list(vcl_list<osl_edge *> *in, 00068 vcl_list<osl_edge *> *out); 00069 00070 //private: 00071 void SquareIncrementalFit(vcl_list<osl_edgel_chain*> *curves_, osl_edge*); 00072 void MeanIncrementalFit(vcl_list<osl_edgel_chain*> *curves_, osl_edge*); 00073 void OutputLine(vcl_list<osl_edgel_chain*> *curves_, int,int, osl_edgel_chain*,float); 00074 void MergeLines(vcl_list<osl_edgel_chain*> *curves_); 00075 static float MyGetCost(osl_OrthogRegress const *, int, int, osl_edgel_chain *); 00076 private: 00077 osl_OrthogRegress *data_; 00078 int old_finish_; 00079 }; 00080 00081 #endif // osl_fit_lines_h