#!/bin/bash

# ========== Params ==========
experiment_dir="/mnt/c/Users/DerFu/Documents/khronos/data/strandmon_gt"                      # Which experiment to evaluate.
evaluation_config=$(rospack find khronos_eval)/config/evaluate_reconciliation.yaml           # Which evaluation config to use.
gt_mesh_file="/home/amock/datasets/khronos/Khronos_Evaluation/ground_truth/strandmon/gt_background.ply" # Ground truth mesh file to use.
force_recompute=false                                                                        # Force recomputation if results already exist.

# ========== Which actions to perform ==========
run_reconciliation=true
run_evaluation_mesh=true

# ========== Automatic params ==========
output_dir="$experiment_dir/reconciliation"

# ========== Script ==========
# Autogenerated arguments.
exec_dir=$(catkin_find --first-only --without-underlays --libexec khronos_eval)

# Run reconciliation.
if [[ $run_reconciliation == true ]]; then
    echo "----- Running Reconciliation -----"
    eval $exec_dir/exp_reconcile $evaluation_config $experiment_dir $output_dir $force_recompute
fi

# Clear existing eval files if needed.
if [[ $run_evaluation_mesh == true ]]; then
    echo "----- Running Mesh Evaluation -----"
    runs=$(find $output_dir -maxdepth 1 -type d)
    for run in $runs; do
        output_file_name="$run/mesh_metrics.csv"
        if [ -f "$output_file_name" ] && [$force_recompute == true]; then
            echo "Force recompute: Clearing '$output_file_name'."
            rm $output_file_name
        fi
    done

    # Evaluate all runs.
    dsg_files=$(find $output_dir -name *dsg_with_mesh.sparkdsg)
    eval $exec_dir/evaluate_meshes $evaluation_config $gt_mesh_file ${dsg_files}
    echo "Finished evaluation of '$experiment_dir'."
fi
