/* * NICE-Core - efficient algebra and computer vision methods * - libbasicvector - A simple vector library * See file License for license information. */ #ifndef __VECTOR_DISTANCE_H__ #define __VECTOR_DISTANCE_H__ #include "core/vector/ippwrapper.h" #include "core/vector/VectorT.h" namespace NICE { /** * @struct VectorDistance * @brief baseclass for vector distances */ template class VectorDistance { public: virtual ~VectorDistance(){}; inline T calculate(const VectorT& v1 , const VectorT& v2) const; inline T operator()(const VectorT& v1 , const VectorT& v2) const; protected: virtual T doCalculate(const VectorT& v1 , const VectorT& v2) const = 0; }; /** * @struct ManhattanDistance * @brief calculate the Manhattan Distance (L1 Norm) */ template class ManhattanDistance : public VectorDistance { public: virtual ~ManhattanDistance(){}; protected: T doCalculate(const VectorT& v1, const VectorT& v2) const; }; /** * @struct EuclidianDistance * @brief calculate the Euclidean Distance (L2 Norm) */ template class EuclidianDistance : public VectorDistance { public: virtual ~EuclidianDistance(){}; protected: T doCalculate(const VectorT& v1, const VectorT& v2) const; }; template<> Ipp32f EuclidianDistance::doCalculate(const VectorT& v1, const VectorT& v2) const; /** * @struct MahalanobisDistance * @brief calculate the Mahalanobis Distance */ template class MahalanobisDistance : public VectorDistance { public: //! @param matrix the mahalanobis matrix MahalanobisDistance (const MatrixT& matrix) : m_matrix(matrix) {}; virtual ~MahalanobisDistance() {}; protected: T doCalculate( const VectorT& v1, const VectorT& v2 ) const; private: MatrixT m_matrix; }; /** * @struct MaximumDistance * @brief calculate the Maximum Distance (L-inf Norm) */ template class MaximumDistance : public VectorDistance { public: virtual ~MaximumDistance(){}; protected: T doCalculate(const VectorT& v1, const VectorT& v2) const; }; /** * @struct MedianDistance * @brief calculate the Median of the absolute distances */ template class MedianDistance : public VectorDistance { public: virtual ~MedianDistance(){}; protected: T doCalculate(const VectorT& v1, const VectorT& v2) const; }; /** * @struct Chi2Distance * @brief calculate the chi^2 distance */ template class Chi2Distance : public VectorDistance { public: virtual ~Chi2Distance(){}; protected: T doCalculate(const VectorT& v1, const VectorT& v2) const; }; /** * @struct SphericalDistance * @brief calculate the distance between two sphereical angles * @note first parameter is the longitude and the second the latitude of the sphere */ template class SphericalDistance : public VectorDistance { public: virtual ~SphericalDistance(){}; protected: T doCalculate(const VectorT& v1, const VectorT& v2) const; }; /** * @struct SinDistance * @brief calculate the sinus of the in-between angle */ template class SinDistance : public VectorDistance { public: virtual ~SinDistance(){}; protected: T doCalculate(const VectorT& v1, const VectorT& v2) const; }; /** * @struct CosDistance * @brief calculates the cosinus distance */ template class CosDistance : public VectorDistance { public: virtual ~CosDistance(){}; protected: T doCalculate(const VectorT& v1, const VectorT& v2) const; }; /** * @struct KLDistance * @brief calculate the Kullback Leibler distance * @note value of the i-th entry of \c v1 and \c v2 is only calculated * if v1[i]>0 and v2[i]>0 */ template class KLDistance : public VectorDistance { public: virtual ~KLDistance(){}; protected: T doCalculate(const VectorT& v1, const VectorT& v2) const; }; /** * @struct SwappedKLDistance * @brief calculate the swapped Kullback Leibler distance */ template class SwappedKLDistance : public VectorDistance { public: SwappedKLDistance(); ~SwappedKLDistance(); protected: T doCalculate(const VectorT& v1, const VectorT& v2) const; private: KLDistance* pKLDistance; }; /** * @struct ExtendedKLDistance * @brief calculate the extended Kullback Leibler distance */ template class ExtendedKLDistance : public VectorDistance { public: ExtendedKLDistance(); ~ExtendedKLDistance(); protected: T doCalculate(const VectorT& v1, const VectorT& v2) const; private: KLDistance* pKLDistance; }; /** * @struct BhattacharyyaDistance * @brief calculate the Bhattacharyya distance */ template class BhattacharyyaDistance : public VectorDistance { public: virtual ~BhattacharyyaDistance(){}; protected: T doCalculate(const VectorT& v1, const VectorT& v2) const; }; template<> Ipp32f BhattacharyyaDistance::doCalculate(const VectorT& v1, const VectorT& v2) const; /** * @struct ScalarProductDistance * @brief calculate the scalar product distance */ template class ScalarProductDistance : public VectorDistance { public: virtual ~ScalarProductDistance(){}; protected: T doCalculate(const VectorT& v1, const VectorT& v2) const; }; } // namespace NICE //#ifdef __GNUC__ #include //#endif #endif // __VECTOR_DISTANCE_H__