contrib/mul/mipa/mipa_vector_normaliser.h
Go to the documentation of this file.
00001 #ifndef mipa_vector_normaliser_h_
00002 #define mipa_vector_normaliser_h_
00003 
00004 //:
00005 // \file
00006 // \author Martin Roberts
00007 // \brief Base class for normalisation algorithms for image feature vectors
00008 
00009 #include <vcl_string.h>
00010 #include <vcl_memory.h>
00011 #include <vcl_iosfwd.h>
00012 #include <vsl/vsl_fwd.h>
00013 #include <vnl/vnl_fwd.h>
00014 class mbl_read_props_type;
00015 
00016 //: Base class for normalisation algorithms for image texture vectors
00017 //  Initial vector is processed to normalise it in some way.
00018 
00019 class mipa_vector_normaliser
00020 {
00021  public:
00022 
00023   virtual ~mipa_vector_normaliser() {}
00024 
00025   //: Normalise the sample.
00026   virtual void normalise(vnl_vector<double>& sample) const=0;
00027 
00028   //: Normalise the sample, preserving the direction of each nfeatures-sized sub-vector.
00029   // The default implementation assumes that this direction would be preserved anyway.
00030   virtual void normalise(vnl_vector<double>& sample,
00031                          unsigned /*nfeatures*/) const { normalise(sample); }
00032 
00033   //: Name of the class
00034   virtual vcl_string is_a() const = 0;
00035 
00036   //: Create a copy on the heap and return base class pointer
00037   virtual mipa_vector_normaliser* clone() const = 0;
00038 
00039   //: Print class to os
00040   virtual void print_summary(vcl_ostream& /*os*/) const = 0;
00041 
00042   //: Save class to binary file stream
00043   virtual void b_write(vsl_b_ostream& /*bfs*/) const = 0;
00044 
00045   //: Load class from binary file stream
00046   virtual void b_read(vsl_b_istream& /*bfs*/) = 0;
00047 
00048   //: Create a concrete mipa_vector_normaliser-derived object, from a text specification.
00049   static vcl_auto_ptr<mipa_vector_normaliser> new_normaliser_from_stream(vcl_istream &is,
00050                                                                          const mbl_read_props_type &extra_props);
00051 
00052   //: Initialise from a text stream.
00053   // The default implementation is for attribute-less normalisers,
00054   // and throws if it finds any data in the stream.
00055   virtual void config_from_stream(
00056     vcl_istream &is, const mbl_read_props_type &extra_props);
00057 };
00058 
00059 //: Allows derived class to be loaded by base-class pointer
00060 //  A loader object exists which is invoked by calls
00061 //  of the form "vsl_b_read(bfs,base_ptr);".  This loads derived class
00062 //  objects from the disk, places them on the heap and
00063 //  returns a base class pointer.
00064 //  In order to work the loader object requires
00065 //  an instance of each derived class that might be
00066 //  found.  This function gives the model class to
00067 //  the appropriate loader.
00068 void vsl_add_to_binary_loader(const mipa_vector_normaliser& b);
00069 
00070 //: Binary file stream output operator for class reference
00071 void vsl_b_write(vsl_b_ostream& bfs, const mipa_vector_normaliser& b);
00072 
00073 //: Binary file stream input operator for class reference
00074 void vsl_b_read(vsl_b_istream& bfs, mipa_vector_normaliser& b);
00075 
00076 //: Stream output operator for class reference
00077 vcl_ostream& operator<<(vcl_ostream& os,const mipa_vector_normaliser& b);
00078 
00079 //: Stream output operator for class pointer
00080 vcl_ostream& operator<<(vcl_ostream& os,const mipa_vector_normaliser* b);
00081 
00082 //: Stream output operator for class reference
00083 void vsl_print_summary(vcl_ostream& os,const mipa_vector_normaliser& b);
00084 
00085 //: Stream output operator for class reference
00086 void vsl_print_summary(vcl_ostream& os,const mipa_vector_normaliser* b);
00087 
00088 #endif // mipa_vector_normaliser_h_
00089 
00090