CEDRIC  Revision_backup-2009-02
GroundDistances.h
Go to the documentation of this file.
1 /******************************************************************************
2  *
3  * Copyright (C) 2008 Max Hermann
4  *
5  * This file is part of the "CEDRIC Event Display" application.
6  *
7  *****************************************************************************/
8 
9 #ifndef REDUKT_GROUNDDISTANCES
10 #define REDUKT_GROUNDDISTANCES
11 
12 #include "EarthMoversDistance.h" // for class GroundDistance
13 #include "Feature.h" // for class AbstractFeature
14 #include <cmath> // for fabs(), pow(), sqrt()
15 #include <algorithm> // for min()
16 
18 template<int P>
19 struct GroundDistance_Lp: public GroundDistance<AbstractFeature>
20 {
21  float distance( const AbstractFeature& f1, const AbstractFeature& f2 ) const
22  {
23  int d = std::min( f1.dim(), f2.dim() );
24  float dist = 0.f;
25 
26  for( int i=0; i < d; ++i )
27  dist += std::pow( fabs(f1[i]-f2[i]), P );
28 
29  return std::pow( dist, 1.0/P );
30  }
31 };
32 
34 template<>
36 {
37  int d = std::min( f1.dim(), f2.dim() );
38  float dist = 0.f;
39 
40  for( int i=0; i < d; ++i )
41  dist += std::fabs( f1[i] - f2[i] );
42 
43  return dist;
44 }
45 
47 template<>
49 {
50  int d = std::min( f1.dim(), f2.dim() );
51  float dist = 0.f;
52 
53  for( int i=0; i < d; ++i )
54  dist += std::fabs( f1[i]*f1[i] - f2[i]*f2[i] );
55 
56  return std::sqrt(dist);
57 }
58 
59 #endif // REDUKT_GROUNDDISTANCES
L_p ground distance template between AbstractFeature types for use with EarthMoversDistance.
Definition: GroundDistances.h:19
float distance(const AbstractFeature &f1, const AbstractFeature &f2) const
Definition: GroundDistances.h:21
virtual int dim() const =0
Definition: Feature.h:16
Interface for distance functions to use with EarthMoversDistance.
Definition: EarthMoversDistance.h:14