/*! 
*   \file  CMatch.h
*   \brief Declares class to match signature of query image against the inventory.
*    
*   \details  
*   CMatch facilitates matching of an input signature against the inventory of signatures. 
*
*   \date      October 24, 2011
*   \copyright eBay Research Labs.
*/

#pragma once

#include "CInventory.h"
#include <vector>
#include <string>
#include <utility>

class CMatch
{ 
	public:
        CMatch();
		~CMatch(void);
		struct SimilarityEntry 
		{
			float             sim_;
			const CSignature* sig_;
			
			SimilarityEntry() : sig_(0), sim_(0.0) {}
			SimilarityEntry(const CSignature* sig, float  sim) : sig_(sig), sim_(sim) {}
		};

		typedef std::vector <SimilarityEntry> SimilarityRow;
		typedef std::vector < SimilarityRow > SimilarityVector;

		void  Match(int siteid, const CSignature &sigIn, 
			    std::vector < std::string > &listCategories, std::vector<int>& totalEntries, 
			    SimilarityVector &similarity, float minSimilarity=0.0F, double wtColor=0.5,
			    int queryPartID= 0, int context=0, bool complimentary = false, int maxItems = 0);
		
 private:
        int    ConvertResultCategoryIDToQueryPartID(const std::string &categoryID);
        double CalculateSimilarity(const CSignature &sigQuery, const CSignature &sigDB, double wtColor=0.5, double confStripesInQuery=0);
        double ConfidenceThatStripesExist(const CSignature &sigQuery);
        double SShapedMembership(double x, double a, double b);
        double RemapIntervalWithCentralNode(double x, double midValue);
};


/*!
*   \brief  This function is used by sort() to define logic for sorting order.
*
*   \details Sorting order is descending w.r.t. to the floating point number in pair.
*
*   \param [in]  x   First pair of integer and float.
*   \param [in]  y   Second pair of integer and float.
*/
inline bool MoreSimilar(const CMatch::SimilarityEntry &x, const CMatch::SimilarityEntry &y)
{
    return x.sim_ > y.sim_;
}
