contrib/mul/mbl/mbl_data_collector.h
Go to the documentation of this file.
00001 // This is mul/mbl/mbl_data_collector.h
00002 #ifndef mbl_data_collector_h_
00003 #define mbl_data_collector_h_
00004 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00005 #pragma interface
00006 #endif
00007 //:
00008 // \file
00009 // \brief Templated base class for objects which collect sets of data.
00010 // \author Tim Cootes
00011 // \author Ian Scott
00012 
00013 #include <vcl_vector.h>
00014 #include <mbl/mbl_data_collector_base.h>
00015 #include <mbl/mbl_data_wrapper.h>
00016 
00017 //: Templated base class for objects which collect sets of data.
00018 //  They are primed with the total number of samples to be presented,
00019 //  then the record() function is called with each example.
00020 //  They can return a mbl_data_wrapper<T> object to iterate through
00021 //  the saved examples.
00022 
00023 template<class T>
00024 class mbl_data_collector : public mbl_data_collector_base
00025 {
00026  public:
00027   //: Dflt ctor
00028   mbl_data_collector();
00029 
00030   //: Destructor
00031   virtual ~mbl_data_collector();
00032 
00033   //: Clear any stored data
00034   virtual void clear() =0;
00035 
00036   //: Hint about how many examples to expect
00037   virtual void set_n_samples(int n) = 0;
00038 
00039   //: Record given object
00040   virtual void record(const T& v) =0;
00041 
00042   //: Return object describing stored data
00043   virtual mbl_data_wrapper<T >& data_wrapper() = 0;
00044 };
00045 
00046 //: Copy all the data from a mbl_data_wrapper<vnl_vector<double> > into a mbl_data_collector
00047 // This function will change the position of the iterator in the mbl_data_wrapper<vnl_vector<double> >,
00048 // but will not modify any of the data
00049 // The function returns the number of objects copied.
00050 template<class T>
00051 unsigned long mbl_data_collector_copy_all(mbl_data_collector<T> &dest, mbl_data_wrapper<T> &src);
00052 
00053 
00054 //: Merge all the data from two mbl_data_wrapper-s into one mbl_data_collector
00055 // This function will change the position of the iterator in src0 and
00056 // src1, but will not modify any of the data therein. Existing vectors
00057 // in dest are preserved, as is the vector ordering within src0
00058 // and src1.  The function returns the number of vectors copied.
00059 // \param src0 The first input mbl_data_wrapper
00060 // \param src1 The second input mbl_data_wrapper
00061 // \param dest The destination mbl_data_collector
00062 // \param order If specified, this vector will contain 0 in every position
00063 // where a value from src0 has been copied into dest, and a 1
00064 // where a value from src1 has been copied into dest.
00065 template<class T>
00066 unsigned long mbl_data_collector_merge_all(mbl_data_collector<T > &dest,
00067                                            mbl_data_wrapper<T > &src0,
00068                                            mbl_data_wrapper<T > &src1,
00069                                            vcl_vector<unsigned> *order = 0);
00070 
00071 #endif // mbl_data_collector_h_