contrib/mul/mfpf/mfpf_patch_data.h
Go to the documentation of this file.
00001 #ifndef mfpf_patch_data_h_
00002 #define mfpf_patch_data_h_
00003 //:
00004 // \file
00005 // \brief Defines region size, shape, and form of model to use
00006 // \author Tim Cootes
00007 
00008 #include <mfpf/mfpf_point_finder_builder.h>
00009 #include <mfpf/mfpf_region_definer.h>
00010 #include <mbl/mbl_cloneable_ptr.h>
00011 #include <vcl_iosfwd.h>
00012 
00013 //: Defines region size, shape, and form of model to use
00014 //  Object to hold information about how to set up an
00015 //  mfpf_point_finder (or multi-res. version) given sets
00016 //  of points on each image.  The position/size of the region
00017 //  is defined relative to the points.  The type of finder
00018 //  to use, and details of how to set it up are also included.
00019 //
00020 //  The main use of the object is to parse text files defining
00021 //  sets of patches for more complex models.
00022 //
00023 //  Example of text than can be parsed by set_from_stream:
00024 // \code
00025 // {
00026 //   name: Test1
00027 //   min_width: 8
00028 //   max_width: 10
00029 //   region: mfpf_region_about_lineseg: { ... }
00030 //   builder: mfpf_norm_corr2d_builder: { ... }
00031 // }
00032 // \endcode
00033 class mfpf_patch_data
00034 {
00035  protected:
00036   //: Name of this patch
00037   vcl_string name_;
00038 
00039   //: Minimum number of samples along one dimension of patch
00040   unsigned min_width_;
00041 
00042   //: Maximum number of samples along one dimension of patch
00043   unsigned max_width_;
00044 
00045   //: Object to define region given a set of points
00046   mbl_cloneable_ptr<mfpf_region_definer> definer_;
00047 
00048   //: Builder to be used for this patch
00049   mbl_cloneable_ptr<mfpf_point_finder_builder> builder_;
00050 
00051  public:
00052   //: Dflt ctor
00053   mfpf_patch_data();
00054 
00055   //: Destructor
00056   virtual ~mfpf_patch_data();
00057 
00058   //: Name of this patch
00059   vcl_string name() const { return name_; }
00060 
00061   //: Minimum number of samples along one dimension of patch
00062   unsigned min_width() const { return min_width_; }
00063 
00064   //: Maximum number of samples along one dimension of patch
00065   unsigned max_width() const { return max_width_; }
00066 
00067   //: Object to define region given a set of points
00068   mfpf_region_definer& definer() { return definer_; }
00069 
00070   //: Builder to be used for this patch
00071   mfpf_point_finder_builder& builder() { return builder_; }
00072 
00073   //: Initialise from a text stream
00074   bool set_from_stream(vcl_istream &is);
00075 
00076     //: Version number for I/O
00077   short version_no() const;
00078 
00079     //: Name of the class
00080   virtual vcl_string is_a() const;
00081 
00082     //: Print class to os
00083   virtual void print_summary(vcl_ostream& os) const;
00084 
00085     //: Save class to binary file stream
00086   virtual void b_write(vsl_b_ostream& bfs) const;
00087 
00088     //: Load class from binary file stream
00089   virtual void b_read(vsl_b_istream& bfs);
00090 };
00091 
00092 //: Stream output operator for class reference
00093 vcl_ostream& operator<<(vcl_ostream& os,const mfpf_patch_data& b);
00094 
00095 //: Binary file stream output operator for class reference
00096 void vsl_b_write(vsl_b_ostream& bfs, const mfpf_patch_data& b);
00097 
00098 //: Binary file stream input operator for class reference
00099 void vsl_b_read(vsl_b_istream& bfs, mfpf_patch_data& b);
00100 
00101 // ======= Functions for sets of mfpf_patch_data =======
00102 
00103 //: Reads in a list of mfpf_patch_data objects from a text stream
00104 //  Format: "{ region: { ... } region: { ... } .... }"
00105 //  Throws an mbl_exception_parse_error if it fails.
00106 void mfpf_read_from_stream(vcl_istream &is,
00107                            vcl_vector<mfpf_patch_data>& data);
00108 
00109 #endif // mfpf_patch_data_h_