contrib/mul/vpdfl/vpdfl_builder_base.h
Go to the documentation of this file.
00001 // This is mul/vpdfl/vpdfl_builder_base.h
00002 #ifndef vpdfl_builder_base_h
00003 #define vpdfl_builder_base_h
00004 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00005 #pragma interface
00006 #endif
00007 //:
00008 // \file
00009 // \author Tim Cootes
00010 // \date 12-Apr-2001
00011 // \brief Base for classes to build vpdfl_pdf_base objects.
00012 
00013 
00014 #include <vnl/vnl_vector.h>
00015 #include <mbl/mbl_data_wrapper.h>
00016 #include <vsl/vsl_binary_io.h>
00017 #include <vcl_vector.h>
00018 #include <vcl_string.h>
00019 #include <vcl_memory.h>
00020 #include <vcl_iosfwd.h>
00021 
00022 //=======================================================================
00023 
00024 class vpdfl_pdf_base;
00025 
00026 
00027 //: Base for classes to build vpdfl_pdf_base objects
00028 //
00029 // Design Notes:
00030 //
00031 // Models are passed to builder, rather than being created
00032 // by builder, for efficiency when used in mixture models.
00033 // (During building they'd have to be recreated at every
00034 // iteration, which is expensive).
00035 class vpdfl_builder_base
00036 {
00037  public:
00038   //: Dflt ctor
00039   vpdfl_builder_base() {}
00040 
00041   //: Destructor
00042   virtual ~vpdfl_builder_base() {}
00043 
00044   //: Create empty model
00045   virtual vpdfl_pdf_base* new_model() const = 0;
00046 
00047   //: Define lower threshold on variance for built models
00048   virtual void set_min_var(double min_var) =0;
00049 
00050   //: Get lower threshold on variance for built models
00051   virtual double min_var() const =0;
00052 
00053   //: Build default model with given mean
00054   virtual void build(vpdfl_pdf_base& model,
00055                      const vnl_vector<double>& mean) const = 0;
00056 
00057   //: Build model from data
00058   virtual void build(vpdfl_pdf_base& model,
00059                      mbl_data_wrapper<vnl_vector<double> >& data) const = 0;
00060 
00061   //: Build model from weighted data
00062   virtual void weighted_build(vpdfl_pdf_base& model,
00063                               mbl_data_wrapper<vnl_vector<double> >& data,
00064                               const vcl_vector<double>& wts) const = 0;
00065 
00066   //: Version number for I/O
00067   short version_no() const;
00068 
00069   //: Name of the class
00070   virtual vcl_string is_a() const;
00071 
00072   //: Does the name of the class match the argument?
00073   virtual bool is_class(vcl_string const& s) const;
00074 
00075   //: Create a copy on the heap and return base class pointer
00076   virtual vpdfl_builder_base* clone() const = 0;
00077 
00078   //: Print class to os
00079   virtual void print_summary(vcl_ostream& os) const = 0;
00080 
00081   //: Save class to binary file stream
00082   virtual void b_write(vsl_b_ostream& bfs) const = 0;
00083 
00084   //: Load class from binary file stream
00085   virtual void b_read(vsl_b_istream& bfs) = 0;
00086 
00087   //: Create a vpdfl_builder_base object given a config stream
00088   // \throw mbl_exception if parse error.
00089   static vcl_auto_ptr<vpdfl_builder_base> new_builder_from_stream(vcl_istream &is);
00090 
00091   //: Read initialisation settings from a stream.
00092   // \throw mbl_exception_parse_error if the parse fails.
00093   virtual void config_from_stream(vcl_istream & is);
00094 
00095   //: Create a vpdfl_builder_base object given a config stream (recursive style)
00096   //  Creates object, then uses config_from_stream(is) to set up internals
00097   // \throw vcl_runtime_exception if parse error.
00098   static vcl_auto_ptr<vpdfl_builder_base> new_pdf_builder_from_stream(vcl_istream &);
00099 };
00100 
00101 //: Allows derived class to be loaded by base-class pointer
00102 //  A loader object exists which is invoked by calls
00103 //  of the form "bfs>>base_ptr;".  This loads derived class
00104 //  objects from the disk, places them on the heap and
00105 //  returns a base class pointer.
00106 //  In order to work the loader object requires
00107 //  an instance of each derived class that might be
00108 //  found.  This function gives the model class to
00109 //  the appropriate loader.
00110 void vsl_add_to_binary_loader(const vpdfl_builder_base& b);
00111 
00112 //: Binary file stream output operator for class reference
00113 void vsl_b_write(vsl_b_ostream& bfs, const vpdfl_builder_base& b);
00114 
00115 //: Binary file stream input operator for class reference
00116 void vsl_b_read(vsl_b_istream& bfs, vpdfl_builder_base& b);
00117 
00118 //: Stream output operator for class reference
00119 void vsl_print_summary(vcl_ostream& os,const vpdfl_builder_base& b);
00120 
00121 //: Stream output operator for class pointer
00122 void vsl_print_summary(vcl_ostream& os,const vpdfl_builder_base* b);
00123 
00124 //: Stream output operator for class reference
00125 vcl_ostream& operator<<(vcl_ostream& os,const vpdfl_builder_base& b);
00126 
00127 //: Stream output operator for class pointer
00128 vcl_ostream& operator<<(vcl_ostream& os,const vpdfl_builder_base* b);
00129 
00130 #endif // vpdfl_builder_base_h