if [ $# -lt 2 ]; then 
cat<<EOF
This program is used to display 3D raw image file with labels on it using Display,
	sample usage:
	Display3Draw RawImg RawLabel  [size_z size_x size_y res_z res_x res_y]

	the parameters inside [] are optional but if you want input them,
	please give the same order(even only part of the parameters are given

EOF

echo 'display3Draw_withlabel RawImg RawLabel [size_z size_x size_y res_z res_x res_y]' 
exit
fi

TmpImgFile="${TMPDIR:=/tmp}/Display3Draw$$.mnc"
TmpLabelFile="${TMPDIR:=/tmp}/Display3Draw$$-1.mnc"

imgFile="$1"
labelFile="$2"

if [ $# -ge 3 ]; then
size_z="$3"
else
size_z=124
fi

if [ $# -ge 4 ]; then
size_x="$4"
else
size_x=256
fi

if [ $# -ge 5 ]; then
size_z="$5"
else
size_y=256
fi

if [ $# -ge 6 ]; then
res_z="$6"
else
res_z=1.5
fi

if [ $# -ge 7 ]; then
res_x="$7"
else
res_x=0.9375
fi

if [ $# -ge 8 ]; then
res_y="$8"
else
res_y=0.9375 
fi

echo "Generating '${imgFile}.mnc' with z,x,y of ${size_z},${size_x},${size_y}."
rawtominc -transverse -byte -obyte -clobber -mri -zstep ${res_z} -xstep ${res_x} -ystep ${res_y} -input ${imgFile} ${TmpImgFile} ${size_z} ${size_x} ${size_y}
echo "Generating '${labelFile}.mnc' with z,x,y of ${size_z},${size_x},${size_y}."
rawtominc -transverse -byte -obyte -clobber -scan_range -mri -zstep ${res_z} -xstep ${res_x} -ystep ${res_y} -input ${labelFile} ${TmpLabelFile} ${size_z} ${size_x} ${size_y}

Display ${TmpImgFile} -label ${TmpLabelFile} 
trap 'rm -f ${TmpImgFile} ${TmpLabelFile} >/dev/null 2>&1' 0
trap "exit 2" 1 2 3 13 15
