/**------------------------------------------------------------------------
 * @file
 *
 * Copyright 2001 by the University of Toronto (UT).
 *
 *                       All Rights Reserved
 * 
 * Permission to copy and modify this software and its documentation 
 * only for internal use in your organization is hereby granted, 
 * provided that this notice is retained thereon and on all copies.  
 * UT makes no representations as to the suitability and operability 
 * of this software for any purpose.  It is provided "as is" without 
 * express or implied warranty.
 *
 * UT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
 * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT
 * SHALL UT BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA
 * OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
 * PERFORMANCE OF THIS SOFTWARE.
 *
 * No other rights, including for example, the right to redistribute 
 * this software and its documentation or the right to prepare 
 * derivative works, are granted unless specifically provided in a 
 * separate license agreement.
 *
 * Author: Diego Macrini
 * 
 * $Log: Matching.h,v $
 *
 *-----------------------------------------------------------------------*/

#ifndef _MATCHING_H_
#define _MATCHING_H_

#include "DAGSimilarityMemory.h"
#include "DAGMemoryDBSet.h"

#ifndef WIN32
int AsyncIndexDAG(const DAG* pQueryDag, DAGDatabase& dagDB, ShapeMatchingParams& info, STATINFO& idxSt);
double AsyncMatchDAG(const DAG* pQueryDag, const DAG* pModelDag);
#endif

DAGPtr MatchDAGs(unsigned int queryDagId, const DAGMemoryDBSet& queryMDBset,
				 const DAGMemoryDBSet& modelMDBset, 
				 const ShapeMatchingParams& info, DAGSimilarityMemory& gsm,
				 STATINFO& idxSt, STATINFO& matSt);

bool MatchDAG(const DAG* pTargetDag, DAGDatabase& dagDB, ShapeMatchingParams& info, 
			  STATINFO& idxSt, STATINFO& matSt);

void MatchDAG(const DAG* pImgDag, int firstModelID, int lastModelID, DAGDatabase& dagDB, 
			  ShapeMatchingParams& info, STATINFO& matSt);

void ProcessFile(const char* szFileName, DAGDatabase& dagDB, std::fstream& logFile, 
				 ShapeRepresentationParams& info, bool bAsyncProcessing);

void SaveResults(const DAG* pTarget, DAGDatabase& dagDB, 
				 const STATINFO& idxSt, const STATINFO& matSt, std::ostream& os);

bool ShowResults(const DAG* pTarget, const STATINFO& matSt, DAGDatabase& queryDB, 
				 DAGDatabase& modelDB, int nTgtID =-1);

double OccludeDAG(DAGPtr& ptrDag, double dMaxOcclusionRate);
//double SGNodeDistance(const SGNode& n1, const SGNode& n2);
bool AskBool(const char* szQuestion);
int AskInt(const char* szQuestion);
void OnAlarm(int param);
void MakeSquare(const char* szPPMFileName);
bool ShowMatch(const DAG* pDag1, const DAG* pDag2);
bool ShowMatch(DAGDatabase& dagDB1, int nDag1Id, DAGDatabase& dagDB2, int nDag2Id);
bool ShowShockGraphMatch(const DAG* pDag1, const DAG* pDag2, NodeMatchMap& nodeMap);
bool ShowBoneGraphMatch(const DAG* pDag1, const DAG* pDag2, NodeMatchMap& nodeMap);
bool ShowShockGraph(const DAG* pDag, int x, int y);
bool ShowBoneGraph(const DAG* pDag, int x, int y);
void AddSubsamplingInfo(ViewSubsampler& vs, const DAG* pTarget, STATINFO& matSt, int kBest);
void SaveSubsamplingInfo(ViewSubsampler& vs, String strDBFileName);
SmartArray<int> GetFarthestViews(int i, int res, double deg);
SmartArray<int> Complement128(int tgt, const int* views, int n);

#endif // _MATCHING_H_
