#!/bin/bash

# Make sure that CROHMELibDir and LgEvalDir are defined in
# your shell enviroment, e.g. by including:
#	
#	export LgEvalDir=<path_to_LgEval>
#	export CROHMELibDir=<path_to_CROHMELib>       		
#	export PATH=$PATH:$CROHMELibDir/bin:$LgEvalDir/bin
# 
# in your .bashrc file (the initialization file for bash shell). The PATH
# alteration will add the tools to your search path. 

if [ $# -lt 1 ]
then
	echo "LgEval Label graph to dot (GraphViz) converter"
	echo "Copyright (c) R. Zanibbi, H. Mouchere, 2012-2013"
	echo ""
	echo "Usage: lg2mml file1.lg [file2.lg] [graph_type]"
	echo ""
	echo "Converts a label graph file files to a .dot file,"
	echo "which can then be converted to a .pdf, .png or other"
	echo "image format using the GraphViz 'dot' program."
	echo ""
	echo "If a second .lg file is provided, then the difference"
	echo "between the first graph and ground truth (the second"
	echo "file) is visualized."
	echo ""
	echo "The graph_type argument may be one of the following:"
	echo "   - [default; no argument] a bipartite graph over strokes."
	echo "   - s : a bipartite segmentation graph (shows strokes in symbols)"
	echo "   - d : a directed acyclic graph over strokes"
	echo "   - t : a tree (NOTE: requires a valid hierachical structure)"
	exit 0
fi

BNAME=`basename $1 .lg`

if [ $# -eq 1 ]
then
	python $LgEvalDir/src/lg2dot.py $1 > $BNAME.dot
elif [ $# -eq 2 ]
then
	# Use tree output by default.
	python $LgEvalDir/src/lg2dot.py $1 $2  > $BNAME.dot
else
	python $LgEvalDir/src/lg2dot.py $1 $2 $3 > $BNAME.dot
fi

# Call dot and generate a .pdf file.
dot -Tpdf $BNAME.dot -o $BNAME.pdf 

