/**------------------------------------------------------------------------
 * @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: ShapeMatching.h,v $
 * Revision 1.5  2002/06/13 21:50:06  dmac
 * Cmd line args added.
 *
 * Revision 1.4  2002/06/10 18:43:19  dmac
 * More cmd line params added.
 *
 * Revision 1.3  2002/05/17 00:26:39  dmac
 * Modification to make the code work with any kind of DAG.
 *
 * Revision 1.2  2002/03/12 18:23:07  dmac
 * ShowResults() was splited into SaveResults() and a new ShowResults()
 *
 * Revision 1.1.1.1  2002/03/10 07:38:08  dmac
 * Imported sources
 *
 *
 *-----------------------------------------------------------------------*/

#ifndef _SHAPE_MATCHER_H_
#define _SHAPE_MATCHER_H_
 
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <algorithm>
#include <string>

#include <DirWalker.h>
#include "CmdLineParser.h"

#include <LEDA/graphics/window.h>

#include <DAGDatabase.h>
#include <VisualDAG.h>
#include <ShockGraph.h>
#include <GestureGraph.h>

#include <Exceptions.h>
#include <HelperFunctions.h>
//#include <UnixFuncPrototypes.h>

#include "ViewSubsampler.h"
#include "Stats.h"

#include "InfoStructures.h"

using namespace dml;

class ShapeMatcher : public CmdLineParser
{
	typedef bool (ShapeMatcher::*DAG_ACTION)();

	MATCHINFO m_matchInfo;
	SGRECINFO m_sgInfo;

	double m_maxOcclusionRate, m_dNeigRange;
	int m_iterations, m_maxdags, m_imgstep, m_from, m_to;
	int m_nVerbose, m_saveSubsamplingInfo, m_nSplitProportion, m_nSplitByObject;

	LPCSTR m_target, m_objName, m_delobj, 
		m_createObj, m_viewDag, m_szMatrixFileName;
		
public:		
	DAG::MatchParams m_matchParams;

public:
	DAGDatabase dagDB;

public:
	bool AddObjsToDB();
	bool CreateDBIndex();
	bool Match();
	bool NodeMatch();
	bool CreateMatrix();
	bool ViewDAGs();
	bool ViewDAG();
	bool ListDAGs();
	bool ShowDBSize();
	bool CreateAffinityMatrix();
	bool PlotNodeInfo();
	bool SplitDB();
	bool MergeDB();
	bool UpdateDB();
	bool RecomputeSG();
	bool Test();
	bool ListObjectNames();
	bool DeleteObj();
	bool EnterDbgMode();
	bool DeleteDAG();
	bool ExtractDAG();
	bool DeleteObjects();
	bool ClosestNeigList();
	bool Closest9NeigList();
	bool GetNeig();
	bool ShowHelp();
	bool CheckSGGrammar();

	bool Verbose() { return m_nVerbose != 0; }

	virtual void InitOptions();
	virtual void ShowUsageExamples();

	virtual bool ExecAction(CLP_ACTION pAction)
	{
		DAG_ACTION action = (DAG_ACTION) pAction;
		return (this->*action)();
	}
	
	void SetSGComputationSyncMode() { m_matchInfo.asyncCompu = 0; }
	bool IsSGComputationSyncMode() const { return m_matchInfo.asyncCompu == 0; }
};

#endif // _SHAPE_MATCHER_H_
