Skip to content
Snippets Groups Projects
distancet.h 1.79 KiB
Newer Older
  • Learn to ignore specific revisions
  • #ifndef DISTANCET_H
    #define DISTANCET_H
    
    #include "calcul.h"
    
    
    	euklid = 1,
    	manhattan = 2,
    	csiChroma = 3,
    	csiChord = 4
    };
    
    
    ///Contains pointer to currently used distance function which is internally used for 
    
    struct distancet {
    
    	///Contains currently used distance. 
    	union DISTANCE {
    		DISTANCE_classic classic;			///< classic distance (calculated from two vectors)
    		DISTANCE_csiChroma csiChroma;		///< chroma distance (cover song identification)
    
    		DISTANCE_csiChord csiChord;			///< chord distance (cover song identification)
    
    	} dist;									///< pointer to distance function
    
    	int type;								///< distance type
    
    	///Default constructor
    
    	//distancet() {}
    
    	///Initialization constructor
    	///@param[in] type_ distance type
    	distancet(int type_) : dist(), type(0)
    	{
    		switch (type_)
    		{
    
    			case distanceType::euklid: dist.classic = calcul::distanceDtwEuklid;	
    
    			case distanceType::manhattan: dist.classic = calcul::distanceDtwManhattan;
    
    			case distanceType::csiChroma: dist.csiChroma = calcul::distanceDtwCsiChroma;
    
    			case distanceType::csiChord: dist.csiChord = calcul::distanceDtwCsiChord;
    
    		}
    	}
    
    	///Calculates distance based on distance type.
    	///@param[in] input data
    	///@param[in] i index
    	///@param[in] j index
    	///@return distance between two time series points.
    
    	double getDistance(inputMethod const &input, unsigned i, unsigned j) const
    
    	{
    		unsigned row = i - 1;
    		unsigned col = j - 1;
    
    		if (type == 1)
    
    			return dist.classic(input.A[row], input.B[col]);
    
    		else if (type == 2)
    
    			return dist.csiChroma(input.A[row], input.B[col], 0.07);
    
    			return dist.csiChord(input.A[row], input.B[col], input.A2[row], input.B2[col]);
    
    #endif //DISTANCET_H