contrib/mul/mfpf/mfpf_point_finder_builder.h
Go to the documentation of this file.
00001 #ifndef mfpf_point_finder_builder_h_
00002 #define mfpf_point_finder_builder_h_
00003 //:
00004 // \file
00005 // \brief Base for classes which build mfpf_point_finder objects.
00006 // \author Tim Cootes
00007 
00008 #include <vimt/vimt_image_2d_of.h>
00009 #include <vgl/vgl_fwd.h>
00010 
00011 #include <vsl/vsl_binary_io.h>
00012 #include <vcl_string.h>
00013 #include <vcl_memory.h>
00014 #include <vcl_iosfwd.h>
00015 
00016 class mfpf_point_finder;
00017 class mbl_read_props_type;
00018 
00019 //: Base for classes which build mfpf_point_finder objects.
00020 class mfpf_point_finder_builder
00021 {
00022  protected:
00023   //: Size of step between sample points
00024   double step_size_;
00025 
00026   //: Number of points either side of centre to search
00027   int search_ni_;
00028 
00029   //: Number of points either side of centre to search
00030   int search_nj_;
00031 
00032   //: Define N. angles (ie try at A+idA, i in [-nA,+nA])
00033   unsigned search_nA_;
00034 
00035   //: Angle step size (ie try at A+idA, i in [-nA,+nA])
00036   double search_dA_;
00037 
00038   //: Number of scales to try at
00039   unsigned search_ns_;
00040 
00041   //: Scaling factor (ie try at ((ds)^i), i in [-ns,+ns]
00042   double search_ds_;
00043 
00044   //: Return true if base class parameters are the same in b
00045   bool base_equality(const mfpf_point_finder_builder& b) const;
00046 
00047   //: Parse relevant parameters from props list
00048   void parse_base_props(mbl_read_props_type& props);
00049 
00050   //: Set base-class parameters of point finder
00051   void set_base_parameters(mfpf_point_finder& pf);
00052 
00053  public:
00054 
00055   //: Dflt ctor
00056   mfpf_point_finder_builder();
00057 
00058   //: Destructor
00059   virtual ~mfpf_point_finder_builder();
00060 
00061   //: Size of step between sample points
00062   virtual void set_step_size(double);
00063 
00064   //: Size of step between sample points
00065   double step_size() const { return step_size_; }
00066 
00067   //: Define region size in world co-ordinates
00068   //  Sets up ROI to cover given box (with samples at step_size()),
00069   //  with ref point at centre.
00070   virtual void set_region_size(double wi, double wj) = 0;
00071 
00072   //: Define search region size
00073   //  During search, samples at points on grid [-ni,ni]x[-nj,nj],
00074   //  with axes defined by u.
00075   virtual void set_search_area(unsigned ni, unsigned nj);
00076 
00077   //: Define angle search parameters
00078   void set_search_angle_range(unsigned nA, double dA);
00079 
00080   //: Define scale search parameters
00081   void set_search_scale_range(unsigned ns, double ds);
00082 
00083   int search_ni() const { return search_ni_; }
00084   int search_nj() const { return search_nj_; }
00085 
00086   //: Number of angles to search at (ie try at A+idA, i in [-nA,+nA])
00087   unsigned search_nA() const { return search_nA_; }
00088 
00089   //: Angle step size (ie try at A+idA, i in [-nA,+nA])
00090   double search_dA() const { return search_dA_; }
00091 
00092   //: Number of scales to try at
00093   unsigned search_ns() const { return search_ns_; }
00094 
00095   //: Scaling factor (ie try at ((ds)^i), i in [-ns,+ns]
00096   double search_ds() const { return search_ds_; }
00097 
00098   //: Number of dimensions in the model
00099   virtual unsigned model_dim();
00100 
00101   //: Create new finder of appropriate type on heap
00102   virtual mfpf_point_finder* new_finder() const =0;
00103 
00104   //: Initialise building
00105   // Must be called before any calls to add_example(...)
00106   virtual void clear(unsigned n_egs)=0;
00107 
00108   //: Get sample of region around specified point in image
00109   virtual void get_sample_vector(const vimt_image_2d_of<float>& image,
00110                                  const vgl_point_2d<double>& p,
00111                                  const vgl_vector_2d<double>& u,
00112                                  vcl_vector<double>& v);
00113 
00114   //: Add one example to the model
00115   virtual void add_example(const vimt_image_2d_of<float>& image,
00116                            const vgl_point_2d<double>& p,
00117                            const vgl_vector_2d<double>& u)=0;
00118 
00119   //: Build object from the data supplied in add_example()
00120   virtual void build(mfpf_point_finder&)=0;
00121 
00122   //: Initialise from a string stream
00123   virtual bool set_from_stream(vcl_istream &is);
00124 
00125   //: Version number for I/O
00126   short version_no() const;
00127 
00128   //: Name of the class
00129   virtual vcl_string is_a() const;
00130 
00131   //: Create a copy on the heap and return base class pointer
00132   virtual mfpf_point_finder_builder* clone() const = 0;
00133 
00134   //: Print class to os
00135   virtual void print_summary(vcl_ostream& os) const ;
00136 
00137   //: Save class to binary file stream
00138   virtual void b_write(vsl_b_ostream& bfs) const;
00139 
00140   //: Load class from binary file stream
00141   virtual void b_read(vsl_b_istream& bfs);
00142 
00143   //: Create a concrete object, from a text specification.
00144   static vcl_auto_ptr<mfpf_point_finder_builder> create_from_stream(vcl_istream &is);
00145 };
00146 
00147 //: Allows derived class to be loaded by base-class pointer
00148 void vsl_add_to_binary_loader(const mfpf_point_finder_builder& b);
00149 
00150 //: Binary file stream output operator for class reference
00151 void vsl_b_write(vsl_b_ostream& bfs, const mfpf_point_finder_builder& b);
00152 
00153 //: Binary file stream input operator for class reference
00154 void vsl_b_read(vsl_b_istream& bfs, mfpf_point_finder_builder& b);
00155 
00156 //: Stream output operator for class reference
00157 vcl_ostream& operator<<(vcl_ostream& os,const mfpf_point_finder_builder& b);
00158 
00159 //: Stream output operator for class pointer
00160 vcl_ostream& operator<<(vcl_ostream& os,const mfpf_point_finder_builder* b);
00161 
00162 #endif // mfpf_point_finder_builder_h_