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

#include 
#include "basedist.hpp"

class EuclideanDist : public BaseDist {

public:
  EuclideanDist() {};

  virtual double dist(const BaseFeature *a, const BaseFeature *b) const {
    double result=.0;
    double tmp;
    unsigned int nOfBins=a->size();
    for(unsigned int i=0;ioperator[](i))-(b->operator[](i));
      tmp*=tmp;
      result+=tmp;
    }
    return result;
  }

  virtual double dist(const BaseFeature *a, const vector &b) const {
    double result=.0;
    double tmp;
    unsigned int nOfBins=a->size();
    for(unsigned int i=0;ioperator[](i))-(b[i]);
      tmp*=tmp;
      result+=tmp;
    }
    return result;
  }
  
  double dist(const BaseFeature *a, const vector &b,const vector &sigma) const {
    double result=0.0;
    double tmp;
    unsigned int nOfBins=a->size();
    double n1,n2;
    for(unsigned int i=0;i1E-8) {
        tmp/=sigma[i];
        result+=tmp;
      } 
      //       else {
      //         //        ERR << "Sigma too small: "<< sigma[i]  << endl;
      //       }
      
      // if(sigma[i]!=0) {tmp/=sigma[i];} else {DBG(DBG_MESSAGE) << "SIGMA=0" << endl;}
      // result+=tmp;
    }
    double norm=0.0;
    for(unsigned int i=0;i1E-6) {
        norm+=log(2*M_PI*sigma[i]);
      }
    }
    result+=norm;
    return result;
  }
  
  double dist(const vector &a, const vector &b,const vector &sigma) const {
    double result=.0;
    double tmp;
    unsigned int nOfBins=a.size();
    for(unsigned int i=0;i1E-6) {
        tmp/=sigma[i];
        result+=tmp;
      }
      //       if(sigma[i]!=0) {tmp/=sigma[i];} else { DBG(DBG_MESSAGE) << "SIGMA=0" << endl;}
      //       result+=tmp;
    }
    return result;
  }
  
  virtual std::string name() {
    return "euclidean";
  }
  
  
};


#endif