www.pudn.com > firev0.01.rar > gaborfeature.hpp


/*
This file is part of the FIRE -- Flexible Image Retrieval System

FIRE is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

FIRE is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with FIRE; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/
/**
 * @file   gaborfeature.hpp
 * @author Thomas Deselaers
 * @date   Tue Jun 24 19:16:13 2003
 * 
 * @brief Object to contain gabor features. This class will be
 * enhanced with the functions from gabor.cpp
 * 
 * 
 */
#ifndef __gaborfeature_hpp
#define __gaborfeature_hpp
#include "basefeature.hpp"
#include "gzstream.hpp"
#include "localfeature.hpp"

class GaborFeature : public LocalFeatures {
public:

  
  GaborFeature() {
    filename_="";
    loaded_=false;
  }

  GaborFeature(const ::std::string &filename) {
    filename_=filename;
    loaded_=false;
  }

  const ::std::vector &feature(const unsigned int a) {
    if(!loaded_) load();
    return *data_[a];
  }


  int nOfFeatures() {
    if(!loaded_) return -1;
    else return data_.size();
  }

  const ::std::vector< ::std::vector* > data() const {
    return data_;
  }
  
  ::std::vector< ::std::vector* > data() {
    return data_;
  }
  


  


  /** 
   * default destructor. free all memory.
   * 
   */
  virtual ~GaborFeature() {
    for(unsigned int i=0;isize()]->operator[](a%data_[0]->size());
  }
  
  /** 
   * return the total number of entries in this object.
   * 
   * 
   * @return the total number of entries on this object 
   */
  virtual const unsigned int size() const {
    return data_.size()*data_[0]->size();
  }
  

  

  /** 
   * access the j-th entry from the i-th feature.
   * 
   * 
   * @return the j-th entry from the i-th feature.
   */
  virtual const double operator()(const unsigned int i, const unsigned int j) {
    if(!loaded_) {load();}
    return data_[i]->operator[](j);
  }

  
  void free() {
    for(unsigned int i=0;i* feature;
    int pixeldim, winsize,y,x;
    int nof;
    double threshold;
    bool nocoord=false;
    if(!ifs) {
      ERR << "[gabor.cpp::loadGaborFeatures] Cannot open '" << filename << "' to read gabor features." << endl;
    } else {
      string keyword, tmp;
      while(!ifs.eof()) {
        ifs >> keyword;
        if(!ifs.eof()) {
          if(keyword=="all") {
            char devnull[1024];
            ifs.getline(devnull,1024);
          } else if (keyword=="dim") {
            ifs >> pixeldim;
          } else if (keyword=="nOfFeatures") {
            ifs >> nof;
          } else if(keyword=="withoutcoord") {
            nocoord=true;
          } else if (keyword=="threshold") {
            ifs >>threshold;
          } else if (keyword=="winsize") {
            ifs >> winsize;
          } else if (keyword=="#") {
            //comment line, skip
            char devnull[1024];
            ifs.getline(devnull,1024);
          } else if (keyword=="feature") {
            //read a feature
            if(!nocoord) {
              ifs >> y >> x;
            }
            feature=new ::std::vector(pixeldim);
            for(int i=0;i> (*feature)[i];
            }
            data_.push_back(feature);
          } else {
            cout << "[gabot.cpp::loadGaborFeatures] Unknown keyword: '" << keyword << "'." << endl;
          }
        }
      }
    }
  }
  

protected:
  vector< vector* > data_;
  ::std::string filename_;
  bool loaded_;

};


#endif