www.pudn.com > firev0.01.rar > histogram.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 __histogram_hpp
#define __histogram_hpp

#include 
#include 
#include 
#include 
#include "diag.hpp"
#include "basehisto.hpp"
#include "gzstream.hpp"
using namespace std;
namespace img {

  ///class for histograms.
  template
  class Histogram : public BaseHisto {
  public:
    ///default & standard constructor.
    /** 
     * create a Histogram with given min and max and a given number of bins.
     * @param min is the minimum of values which can be put into the histogram
     * @param max is the maximum of values which can be put into the histogram
     * @param steps is the number of bins which are contained in this histogram
     */
    Histogram(T min=0, int steps=10, T max=255) {
      min_=min;
      max_=max;
      steps_=steps;
      stepsize_=(double(max_-min_)/double(steps_));
      bins_=vector(steps_,0);
      counter_=0;
    }


    void load(string filename) {
      
      DBG(DBG_VERBOSE) << "[Histogram::load] Reading histogram from '" <> keyword >> steps_;
      DBG(DBG_TALKATIVE) << "[Histogram::load]Reading "<< keyword << endl;
      if(keyword != "steps") {
	DBG(DBG_ERROR) << "[Histogram::load]Error reading '"<> keyword >> min_;
      DBG(DBG_TALKATIVE) << "[Histogram::load]Reading "<< keyword << endl;
      if(keyword != "min") {
	DBG(DBG_ERROR) << "[Histogram::load]Error reading '"<> keyword >> max_;
      DBG(DBG_TALKATIVE) << "[Histogram::load]Reading "<< keyword << endl;
      if(keyword != "max") {
	DBG(DBG_ERROR) << "[Histogram::load]Error reading '"<> keyword >> stepsize_;
      DBG(DBG_TALKATIVE) << "[Histogram::load]Reading "<< keyword << endl;
      if(keyword != "stepsize") {
	DBG(DBG_ERROR) << "[Histogram::load]Error reading '"<(steps_);
      
      ifp >> keyword >> counter_;
      DBG(DBG_TALKATIVE) << "[Histogram::load]Reading "<< keyword << endl;
      if(keyword != "counter") {
	DBG(DBG_ERROR) << "[Histogram::load]Error reading '"<> keyword;
      DBG(DBG_TALKATIVE) << "[Histogram::load]Reading "<< keyword << endl;
      if(keyword != "bins") {
	DBG(DBG_ERROR) << "[Histogram::load]Error reading '"<> number >> content;
	if(number != i) {
	  DBG(DBG_ERROR) << "[Histogram::load]Error reading '"<(min_+(aktpos+1)*stepsize_)) && aktpos < steps_){
        ++aktpos;
      }
      if(aktpos>=steps_) aktpos=steps_-1;
      ++bins_[aktpos];
      // cout << aktpos << " " << bins_[aktpos] << " " << input << " " << min_+(aktpos)*stepsize_<< endl;
    }
    
    ///get the value of the corresponding bin.
    unsigned int count(const T &input) const {
      unsigned int aktpos=0;
      while (inputsteps_?max_:min_+no*stepsize_);
    }
    
    ///get the number of the counted events.
    const unsigned int counter() const {
      return counter_;
    }
    
    ///get the min of the histogram.
    const T& min() const {
      return min_;
    }
    
    ///get the max of the histogram.
    const T& max() const {
      return max_;
    }
    
    ///get the number of steps in this histogram.
    const unsigned int& steps() const {
      return steps_;
    }
    
    ///get the number of steps in this histogram.
    const unsigned int nOfBins() const {
      return steps_;
    }
    ///get the stepsize of this histogram.
    const double& stepsize() const {
      return stepsize_;
    }
    
  private:
    T min_, max_;
    double stepsize_;
    unsigned int steps_;
    vector bins_;
    unsigned int counter_;
  };
  
  
  /** print the histogram to a stream.
   * 
   */
  template
  ostream& operator<<(ostream& os, const Histogram & src) {
    os << "min: " << src.min() << " max: " << src.max() << " steps: " << src.steps() << " stepsize: "<< src.stepsize() << endl;
    for(unsigned int i=0;i