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