www.pudn.com > firev0.01.rar > aspectratiofeature.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
*/
#ifndef __aspectratiofeature_hpp
#define __aspectratiofeature_hpp
#include "basefeature.hpp"
#include 
#include "gzstream.hpp"
#include "diag.hpp"
class AspectRatioFeature : public BaseFeature {
public:

  virtual const double operator[](const unsigned int a) const {
    if(a==0) return height_;
    else if(a==1) return width_;
    else {
      DBG(DBG_MESSAGE) << "only having 2 dimensions, why asking for the " << a << "th?" << ::std::endl;
      return 0;
    }
  }
  
  virtual const unsigned int size() const {
    return 2;
  }
  
  double &width() {
    return width_;
  }

  double &height() {
    return height_;
  }

  void save(::std::string filename) {
    ::std::ofstream ofs(filename.c_str());
    
    ofs << "# aspect ratio" << ::std::endl
        << "width " << width_ << ::std::endl
        << "height " << height_ << ::std::endl;
    
    ofs.close();
  }
  
  void load(::std::string filename) {
    igzstream ifs(filename.c_str());
    ::std::string keyword;
    while(!ifs.eof()) {
      ifs >> keyword;
      if(!ifs.eof()) {
        if(keyword=="#") {
          char devnull[1024];
          ifs.getline(devnull,1024);
        } else if( keyword=="width") {
          ifs >> width_;
        } else if( keyword=="height") {
          ifs >> height_;
        } else {
          DBG(DBG_MESSAGE) << "Unknown keyword: " << keyword << "." << ::std::endl;
        }
      }
    }
    ifs.close();
  }
            
private:
  double width_, height_;
  
};


#endif