distance.h
Go to the documentation of this file.
00001 #ifndef VOCABULARY_TREE_DISTANCE_H
00002 #define VOCABULARY_TREE_DISTANCE_H
00003 
00004 #include <stdint.h>
00005 #include <Eigen/Core>
00006 
00007 namespace vt {
00008 namespace distance {
00009 
00021 template<typename T>
00022 struct Accumulator
00023 {
00024   typedef T type;
00025 };
00026 
00028 template<> struct Accumulator<uint8_t>  { typedef uint32_t type; };
00029 template<> struct Accumulator<uint16_t> { typedef uint32_t type; };
00030 template<> struct Accumulator<int8_t>   { typedef int32_t type; };
00031 template<> struct Accumulator<int16_t>  { typedef int32_t type; };
00032 // Have noticed loss of precision when computing sum-squared-error with many input features.
00033 template<> struct Accumulator<float>    { typedef double type; };
00035 
00042 template<class Feature>
00043 struct L2
00044 {
00045   typedef typename Feature::value_type value_type;
00046   typedef typename Accumulator<value_type>::type result_type;
00047 
00048   result_type operator()(const Feature& a, const Feature& b) const
00049   {
00050     result_type result = result_type();
00051     for (size_t i = 0; i < a.size(); ++i) {
00052       result_type diff = a[i] - b[i];
00053       result += diff*diff;
00054     }
00055     return result;
00056   }
00057 };
00060 
00062 template<typename Scalar, int Rows, int Cols, int Options, int MaxRows, int MaxCols>
00063 struct L2< Eigen::Matrix<Scalar, Rows, Cols, Options, MaxRows, MaxCols> >
00064 {
00065   typedef Eigen::Matrix<Scalar, Rows, Cols, Options, MaxRows, MaxCols> feature_type;
00066   typedef Scalar value_type;
00067   typedef typename Accumulator<Scalar>::type result_type;
00068 
00069   result_type operator()(const feature_type& a, const feature_type& b) const
00070   {
00071     return (a - b).squaredNorm();
00072   }
00073 };
00074 
00075 } } //namespace vt::distance
00076 
00077 #endif


vocabulary_tree
Author(s): Patrick Mihelich
autogenerated on Thu Jan 2 2014 12:12:26