Main Page | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members

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 <vcl_vector.h>
00015 #include <vcl_string.h>
00016 #include <vcl_memory.h>
00017 #include <vnl/vnl_vector.h>
00018 #include <vsl/vsl_binary_io.h>
00019 #include <mbl/mbl_data_wrapper.h>
00020 
00021 //=======================================================================
00022 
00023 class vpdfl_pdf_base;
00024 
00025 
00026 //: Base for classes to build vpdfl_pdf_base objects
00027 //
00028 // Design Notes:
00029 //
00030 // Models are passed to builder, rather than being created
00031 // by builder, for efficiency when used in mixture models.
00032 // (During building they'd have to be recreated at every
00033 // iteration, which is expensive).
00034 class vpdfl_builder_base
00035 {
00036  public:
00037   //: Dflt ctor
00038   vpdfl_builder_base() {}
00039 
00040   //: Destructor
00041   virtual ~vpdfl_builder_base() {}
00042 
00043   //: Create empty model
00044   virtual vpdfl_pdf_base* new_model() const = 0;
00045 
00046   //: Define lower threshold on variance for built models
00047   virtual void set_min_var(double min_var) =0;
00048 
00049   //: Get lower threshold on variance for built models
00050   virtual double min_var() const =0;
00051 
00052   //: Build default model with given mean
00053   virtual void build(vpdfl_pdf_base& model,
00054                      const vnl_vector<double>& mean) const = 0;
00055 
00056   //: Build model from data
00057   virtual void build(vpdfl_pdf_base& model,
00058                      mbl_data_wrapper<vnl_vector<double> >& data) const = 0;
00059 
00060   //: Build model from weighted data
00061   virtual void weighted_build(vpdfl_pdf_base& model,
00062                               mbl_data_wrapper<vnl_vector<double> >& data,
00063                               const vcl_vector<double>& wts) const = 0;
00064 
00065   //: Version number for I/O
00066   short version_no() const;
00067 
00068   //: Name of the class
00069   virtual vcl_string is_a() const;
00070 
00071   //: Does the name of the class match the argument?
00072   virtual bool is_class(vcl_string const& s) const;
00073 
00074   //: Create a copy on the heap and return base class pointer
00075   virtual vpdfl_builder_base* clone() const = 0;
00076 
00077   //: Print class to os
00078   virtual void print_summary(vcl_ostream& os) const = 0;
00079 
00080   //: Save class to binary file stream
00081   virtual void b_write(vsl_b_ostream& bfs) const = 0;
00082 
00083   //: Load class from binary file stream
00084   virtual void b_read(vsl_b_istream& bfs) = 0;
00085 
00086   //: Create a vpdfl_builder_base object given a config steram
00087   // \throw mbl_exception if parse error.
00088   static vcl_auto_ptr<vpdfl_builder_base> new_builder_from_stream(vcl_istream &is);
00089 
00090   //: Read initialisation settings from a stream.
00091   // \throw mbl_exception_parse_error if the parse fails.
00092   virtual void config_from_stream(vcl_istream & is);
00093 
00094   //: Create a vpdfl_builder_base object given a config stream (recursive style)
00095   //  Creates object, then uses config_from_stream(is) to set up internals
00096   // \throw vcl_runtime_exception if parse error.
00097   static vcl_auto_ptr<vpdfl_builder_base> new_pdf_builder_from_stream(vcl_istream &);
00098 
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

Generated on Thu Jan 10 14:43:32 2008 for contrib/mul/vpdfl by  doxygen 1.4.4