00001 #ifndef mfpf_dp_snake_h_ 00002 #define mfpf_dp_snake_h_ 00003 //: 00004 // \file 00005 // \author Tim Cootes 00006 // \brief Basic snake, using dynamic programming to update. 00007 00008 #include <mfpf/mfpf_point_finder.h> 00009 #include <mbl/mbl_cloneable_ptr.h> 00010 #include <vgl/vgl_point_2d.h> 00011 #include <vcl_iosfwd.h> 00012 00013 //: Basic snake, using dynamic programming to update. 00014 // Contains a single mfpf_point_finder, which is used to locate 00015 // all candidate points along a profile. 00016 class mfpf_dp_snake 00017 { 00018 protected: 00019 //: Maximum number of iterations to use during search 00020 unsigned max_its_; 00021 00022 //: Finder used to search for good points along profiles 00023 mbl_cloneable_ptr<mfpf_point_finder> finder_; 00024 00025 //: Current set of boundary points (a closed curve) 00026 vcl_vector<vgl_point_2d<double> > pts_; 00027 00028 //: Compute the average of each point and its neighbours 00029 void smooth_curve(vcl_vector<vgl_point_2d<double> >& src_pts, 00030 vcl_vector<vgl_point_2d<double> >& dest_pts); 00031 00032 public: 00033 00034 //: Dflt ctor 00035 mfpf_dp_snake(); 00036 00037 //: Destructor 00038 virtual ~mfpf_dp_snake(); 00039 00040 //: Initialise as a circle of given radius about the given centre 00041 // Clone taken of finder object 00042 void set_to_circle(const mfpf_point_finder& finder, 00043 unsigned n_points, 00044 const vgl_point_2d<double>& centre, 00045 double r); 00046 00047 //: Number of points 00048 unsigned size() const { return pts_.size(); } 00049 00050 //: Finder used to search for good points along profiles 00051 mfpf_point_finder& finder(); 00052 00053 //: Current set of boundary points (a closed curve) 00054 const vcl_vector<vgl_point_2d<double> >& points() const { return pts_; } 00055 00056 //: Perform one iteration of snake search algorithm 00057 // Return the mean movement of each point 00058 double update_step(const vimt_image_2d_of<float>& image); 00059 00060 //: Search image (running iterations until convergence) 00061 void search(const vimt_image_2d_of<float>& image); 00062 00063 //: Replace each point with the average of it and its neighbours 00064 void smooth_curve(); 00065 00066 //: Centre of gravity of points 00067 vgl_point_2d<double> cog() const; 00068 00069 //: Mean distance of points to cog() 00070 double mean_radius() const; 00071 00072 //: Compute mean and sd of distance to cog() 00073 void radius_stats(double& mean, double& sd) const; 00074 00075 //: Version number for I/O 00076 short version_no() const; 00077 00078 //: Name of the class 00079 virtual vcl_string is_a() const; 00080 00081 //: Print class to os 00082 virtual void print_summary(vcl_ostream& os) const; 00083 00084 //: Save class to binary file stream 00085 virtual void b_write(vsl_b_ostream& bfs) const; 00086 00087 //: Load class from binary file stream 00088 virtual void b_read(vsl_b_istream& bfs); 00089 }; 00090 00091 //: Stream output operator for class reference 00092 vcl_ostream& operator<<(vcl_ostream& os,const mfpf_dp_snake& b); 00093 00094 //: Binary file stream output operator for class reference 00095 void vsl_b_write(vsl_b_ostream& bfs, const mfpf_dp_snake& b); 00096 00097 //: Binary file stream input operator for class reference 00098 void vsl_b_read(vsl_b_istream& bfs, mfpf_dp_snake& b); 00099 00100 #endif // mfpf_dp_snake_h_