www.pudn.com > libpmk.rar > global-vg-pyramid-maker.h, change:2007-05-27,size:2624b


// Copyright 2007, Massachusetts Institute of Technology.
// The use of this code is permitted for research only. There is
// absolutely no warranty for this software.
//
// Author: John Lee (jjl@mit.edu)
//
// TODO: add clusterer to PREPROCESS instead. persist it.
#ifndef PYRAMIDS_GLOBAL_VG_PYRAMID_MAKER_H
#define PYRAMIDS_GLOBAL_VG_PYRAMID_MAKER_H

#include <vector>
#include <iostream>
#include "pyramids/vg-pyramid-maker.h"
#include "point_set/point-set-list.h"
#include "util/sparse-vector.h"
#include "histograms/multi-resolution-histogram.h"
#include "util/distance-computer.h"
#include "clustering/hierarchical-clusterer.h"

namespace libpmk {

/// \brief Makes pyramids with bin sizes determined by a particular
/// set of points.
class GlobalVGPyramidMaker : public VGPyramidMaker {
 public:
   GlobalVGPyramidMaker(const HierarchicalClusterer& clusterer,
                        const DistanceComputer& distance_computer);
   ~GlobalVGPyramidMaker();

   /// Initialize the global bin sizes.
   /**
    * Rather than doing this every single time, you may also call
    * ReadFromStream() which will read already-preprocessed data.
    */
   void Preprocess(const PointSetList& point_sets);

   virtual MultiResolutionHistogram* MakePyramid(const PointSet& point_set);

   /// Initialize the global bin sizes.
   /**
    * Can be called in lieu of Preprocess().  Aborts if the stream is
    * bad.
    */ 
   void ReadFromStream(istream& input_stream);

   /// Initialize the global bin sizes.
   /**
    * \sa ReadFromStream
    */ 
   void ReadFromFile(const char* filename);

   /// Write the global bin sizes to a stream.
   /**
    * Requires Preprocess() or ReadFromStream() to be called first.
    * Aborts if the stream is bad.
    */ 
   void WriteToStream(ostream& output_stream) const;

   /// Write the global bin sizes to a file.
   /**
    * \sa WriteToStream
    */ 
   void WriteToFile(const char* filename) const;

 protected:
   /// Get the membership data relative to the global pyramid data.
   /**
    * This function is overridden so that only paths that were
    * present in the point sets that this was constructed with
    * can appear. Otherwise, this function does the same thing
    * as its parent VGPyramidMaker::GetMembershipPath().
    * \sa VGPyramidMaker::GetMembershipPath()
    */
   virtual pair<LargeIndex, vector<double> >
      GetMembershipPath(const Feature& f);

 private:
   auto_ptr<MultiResolutionHistogram> global_pyramid_;
   vector<vector<bool> > global_used_bins_;
   bool preprocessed_;
};
}  // namespace libpmk

#endif  // PYRAMIDS_GLOBAL_VG_PYRAMID_MAKER_H