global-vg-pyramid-maker.h

Go to the documentation of this file.
00001 // Copyright 2007, Massachusetts Institute of Technology.
00002 // The use of this code is permitted for research only. There is
00003 // absolutely no warranty for this software.
00004 //
00005 // Author: John Lee (jjl@mit.edu)
00006 //
00007 // TODO(jjl): global_used_bins is no longer needed.
00008 
00009 #ifndef PYRAMIDS_GLOBAL_VG_PYRAMID_MAKER_H
00010 #define PYRAMIDS_GLOBAL_VG_PYRAMID_MAKER_H
00011 
00012 #include <vector>
00013 #include <iostream>
00014 #include <set>
00015 #include "pyramids/vg-pyramid-maker.h"
00016 #include "point_set/point-set-list.h"
00017 #include "util/sparse-vector.h"
00018 #include "histograms/multi-resolution-histogram.h"
00019 #include "util/distance-computer.h"
00020 #include "clustering/hierarchical-clusterer.h"
00021 #include "util/tree-node.h"
00022 #include "util/tree.cc"
00023 
00024 namespace libpmk {
00025 
00028 class GlobalVGPyramidMaker : public VGPyramidMaker {
00029  public:
00030    GlobalVGPyramidMaker(const HierarchicalClusterer& clusterer,
00031                         const DistanceComputer& distance_computer);
00032    ~GlobalVGPyramidMaker();
00033 
00035 
00044    void Preprocess(const PointSetList& point_sets);
00045 
00046    virtual MultiResolutionHistogram* MakePyramid(const PointSet& point_set);
00047 
00049 
00053    void ReadFromStream(istream& input_stream);
00054 
00056 
00059    void ReadFromFile(const char* filename);
00060 
00062 
00066    void WriteToStream(ostream& output_stream) const;
00067 
00069 
00072    void WriteToFile(const char* filename) const;
00073 
00074  protected:
00076 
00083    virtual pair<LargeIndex, vector<double> >
00084       GetMembershipPath(const Feature& f);
00085 
00086  private:
00087    class IndexNode : public TreeNode {
00088    public:
00089       IndexNode() : TreeNode() {}
00090       IndexNode(const LargeIndex& index) : TreeNode(index) {}
00091       virtual ~IndexNode() { }
00092 
00093       virtual void Combine(const TreeNode& other) {
00094          const set<int>& other_indices = 
00095             static_cast<const IndexNode&>(other).indices_;
00096          for (set<int>::iterator iter = other_indices.begin();
00097               iter != other_indices.end(); ++iter) {
00098             indices_.insert(*iter);
00099          }
00100       }
00101 
00102       const set<int>& GetIndices() const {
00103          return indices_;
00104       }
00105 
00106       void AddIndex(int index) {
00107          indices_.insert(index);
00108       }
00109       
00110    protected:
00111       virtual void ReadData(istream& input_stream) {
00112          int32_t size;
00113          input_stream.read((char *)&size, sizeof(int32_t));
00114          for (int ii = 0; ii < size; ++ii) {
00115             int32_t index;
00116             input_stream.read((char *)&index, sizeof(int32_t));
00117             indices_.insert((int)index);
00118          }
00119       }
00120       
00121       virtual void WriteData(ostream& output_stream) const {
00122          int32_t size = (int32_t)indices_.size();
00123          output_stream.write((char *)&size, sizeof(int32_t));
00124          for (set<int>::iterator iter = indices_.begin();
00125               iter != indices_.end(); ++iter) {
00126             int32_t index = *iter;
00127             output_stream.write((char *)&index, sizeof(int32_t));
00128          }
00129       }
00130       
00131    private:
00132       set<int> indices_;
00133    };
00134 
00135 
00136    auto_ptr<MultiResolutionHistogram> global_pyramid_;
00137    vector<vector<bool> > global_used_bins_;
00138    bool preprocessed_;
00139 };
00140 }  // namespace libpmk
00141 
00142 #endif  // PYRAMIDS_GLOBAL_VG_PYRAMID_MAKER_H

Generated on Wed May 2 11:17:12 2007 for libpmk by  doxygen 1.5.1