#! /bin/bash

echo " "
echo "Script for running DSO on Monocular TUM-VI dataset."
echo "--------------------------------------------------------"

export DIR_DATASET=/home/ivan/ivan/git/work_drivecast2/SLAM/datasets/tum_mono_vi
export DSO_BINARY_DIR=/home/ivan/ivan/git/work_drivecast2/SLAM/dso/build/bin
#export DIR_CORRIDOR4="$DIR_DATASET"/dataset-corridor4_512_16/dso/cam0
#export DIR_OUTDOOR4=$DIR_DATASET/dataset-outdoors4_512_16/dso/cam0

function show_help {
  echo "--------------------------------------------------------"
	echo "Example of usage: -d=dataset-corridor4_512_16 or --dataset=dataset-outdoors4_512_16. They are used to as the
	  folder names in tum-vi dataset folder. Output file doesn't change the name. Don't forget to rename and move the
	  result before the next run."
 }

if [[ ($1 == -h || $1 == --help) ]] ; then
  show_help
  exit 0
fi

for i in "$@"; do
  case "$i" in
    -d=*|--dataset=*)
      export DATASET="${i#*=}"
      export DATASET_DIR="$DIR_DATASET"/"$DATASET"
#      echo "$DATASET:"
      shift
      ;;
    -*|--*)
      echo "Unknown option $i"
      show_help
      exit 1
      ;;
    *)
      echo "Invalid usage."
      show_help
      exit 1
      ;;
  esac
done

echo "$DATASET dataset starting..."
"$DSO_BINARY_DIR"/dso_dataset files="$DATASET_DIR"/dso/cam0/images calib="$DATASET_DIR"/dso/cam0/camera.txt gamma="$DATASET_DIR"/dso/cam0/pcalib.txt vignette="$DATASET_DIR"/dso/cam0/vignette.png preset=0 mode=0

export FILENAME="${DATASET}_512_mono_dso.txt"
mv result.txt "$DATASET"/"$FILENAME"

echo "Success! Check $DATASET directory for the output file "