contrib/mul/mfpf/mfpf_mr_point_finder_builder.h
Go to the documentation of this file.
00001 #ifndef mfpf_mr_point_finder_builder_h_
00002 #define mfpf_mr_point_finder_builder_h_
00003 //:
00004 // \file
00005 // \author Tim Cootes
00006 // \brief Builder for mfpf_mr_point_finder objects.
00007 
00008 #include <mfpf/mfpf_point_finder_builder.h>
00009 #include <vgl/vgl_fwd.h>
00010 #include <vcl_cassert.h>
00011 #include <vcl_iosfwd.h>
00012 
00013 class vimt_image_pyramid;
00014 class mfpf_mr_point_finder;
00015 class mfpf_pose;
00016 
00017 //: Builder for mfpf_mr_point_finder objects.
00018 // Contains a set of mfpf_point_finder_builders,
00019 // each designed to work at a different resolution.
00020 class mfpf_mr_point_finder_builder
00021 {
00022  protected:
00023 
00024   //: Set of cost function objects.
00025   vcl_vector<mfpf_point_finder_builder*> builders_;
00026 
00027   //: Delete all the builders
00028   void delete_all();
00029 
00030  public:
00031 
00032   //: Dflt ctor
00033   mfpf_mr_point_finder_builder();
00034 
00035   //: Copy ctor
00036   mfpf_mr_point_finder_builder(const mfpf_mr_point_finder_builder&);
00037 
00038   //: Copy operator
00039   //  Required to deal with correct cloning of builders
00040   mfpf_mr_point_finder_builder& operator=(const mfpf_mr_point_finder_builder&);
00041 
00042   //: Destructor
00043   virtual ~mfpf_mr_point_finder_builder();
00044 
00045   //: Number of builders
00046   unsigned size() const { return builders_.size(); }
00047 
00048   //: Builder at level L
00049   const mfpf_point_finder_builder& builder(unsigned L) const
00050   { assert (L<builders_.size()); return *builders_[L]; }
00051 
00052   //: Builder at level L
00053   mfpf_point_finder_builder& builder(unsigned L)
00054   { assert (L<builders_.size()); return *builders_[L]; }
00055 
00056   //: Set number of builders. Any existing builders are retained
00057   void set_n_levels(unsigned n);
00058 
00059   //: Define builders.  Clone of each taken
00060   void set(const vcl_vector<mfpf_point_finder_builder*>& builders);
00061 
00062   //: Set up n builders, with step size step0*scale_step^L
00063   //  Takes clones of builder and sets up step sizes.
00064   //  Top level search parameters retained.
00065   //  Finer res models have search area and scale/angle
00066   //  ranges set to allow efficient refinement.
00067   void set(const mfpf_point_finder_builder& builder,
00068            unsigned n, double step0, double scale_step);
00069 
00070   //: Set up multiple builders to cover patch of size wi x wj
00071   //  Patch defined in world co-ords.  Selects suitable scales
00072   //  and levels so that region is covered and at any given
00073   //  level the model width (in number of samples) is in the range
00074   //  [min_n_samples,max_n_samples].
00075   //  \param base_pixel_width Pixel width in base image
00076   void set_size_and_levels(
00077                 const mfpf_point_finder_builder& builder0,
00078                 double wi, double wj,
00079                 double scale_step,
00080                 int min_n_samples,
00081                 int max_n_samples,
00082                 double base_pixel_width=1.0);
00083 
00084   //: Define region size in world co-ordinates
00085   //  Sets up ROI in each model to cover given box (in world coords),
00086   //  with ref point at centre.
00087   //  Assumes that models exist and have step size defined.
00088   void set_region_size(double wi, double wj);
00089 
00090   //: Select best level for building model using u as basis
00091   //  Selects pyramid level with pixel sizes best matching
00092   //  the model pixel size at given basis vector u.
00093   unsigned image_level(unsigned i,
00094                        const vgl_vector_2d<double>& u,
00095                        const vimt_image_pyramid& im_pyr) const;
00096 
00097   //: Initialise building
00098   // Must be called before any calls to add_example(...)
00099   void clear(unsigned n_egs);
00100 
00101   //: Get sample image at specified point for level L of the point_finder hierarchy
00102   void get_sample_vector(const vimt_image_pyramid& image_pyr,
00103                          const vgl_point_2d<double>& p,
00104                          const vgl_vector_2d<double>& u,
00105                          unsigned L,
00106                          vcl_vector<double>& v);
00107 
00108   //: Add one example to the model
00109   void add_example(const vimt_image_pyramid& image_pyr,
00110                    const vgl_point_2d<double>& p,
00111                    const vgl_vector_2d<double>& u);
00112 
00113   //: Build object from the data supplied in add_example()
00114   void build(mfpf_mr_point_finder&);
00115 
00116   //: Version number for I/O
00117   short version_no() const;
00118 
00119   //: Name of the class
00120   virtual vcl_string is_a() const;
00121 
00122   //: Print class to os
00123   virtual void print_summary(vcl_ostream& os) const;
00124 
00125   //: Save class to binary file stream
00126   virtual void b_write(vsl_b_ostream& bfs) const;
00127 
00128   //: Load class from binary file stream
00129   virtual void b_read(vsl_b_istream& bfs);
00130 };
00131 
00132 //: Stream output operator for class reference
00133 vcl_ostream& operator<<(vcl_ostream& os,const mfpf_mr_point_finder_builder& b);
00134 
00135 //: Binary file stream output operator for class reference
00136 void vsl_b_write(vsl_b_ostream& bfs, const mfpf_mr_point_finder_builder& b);
00137 
00138 //: Binary file stream input operator for class reference
00139 void vsl_b_read(vsl_b_istream& bfs, mfpf_mr_point_finder_builder& b);
00140 
00141 #endif // mfpf_mr_point_finder_builder_h_