#!/usr/bin/env bash

set -euo pipefail

function run_cmd() {
  camera_serial="$1"
  camera_model="$2"

  data_root="/mnt/flashblade/snc_intrinsics/old_donotuse/raw_data"

  new_dir=$(find $data_root -type d -name "*$camera_serial*")
  new_file=$(find $new_dir -type f -name "*$(echo $camera_serial)_clams_input_data.pbtxt")
  data_file=$new_file
  #output_file="/mnt/flashblade/snc_intrinsics/kitt12/"$camera_serial"_"$camera_model"_intrinsics.pbtxt"
  output_file="/mnt/flashblade/snc_intrinsics/kitt11/"$camera_serial"_"$camera_model"_intrinsics.pbtxt"

  cmd="bazel run //calibration/camera_intrinsics:run_board_calibrate --config=kraken --
    --logtostderr
    --cammodelstr "$camera_model"
    --datafile "$data_file"
    --const_extrinsics=1
    --huber_thresh=100.0
    --init_pnp=false
    --verbose=true
    --kRMSPxErr=5.0
    --kInlThresholdErr=0.1
    --kMinGridCoveredPercentage=0.1
    --intrinsicsfile=$output_file"

  echo "Camera serial: $camera_serial"
  echo "Camera Model:  $camera_model"
  echo "data_file:     $data_file"
  echo "output_file:   $output_file"
  $cmd
  echo ''
}

fisheye="FovM4"
other="Poly2M4"

## KITT11 cameras
run_cmd 0052 $fisheye 
run_cmd 0020 $fisheye 
run_cmd 0035 $fisheye 
run_cmd 0051 $fisheye 

run_cmd 0046 $other
run_cmd 0043 $other
run_cmd 0039 $other
run_cmd 0044 $other
run_cmd 0048 $other
run_cmd 0041 $other
run_cmd 0047 $other
run_cmd 0045 $other
run_cmd 0049 $other
run_cmd 0040 $other
run_cmd 0038 $other
run_cmd 0050 $other

## KITT12 cameras
#run_cmd 0036 $other
#run_cmd 0023 $other
#run_cmd 0028 $fisheye
#run_cmd 0024 $other
#run_cmd 0029 $other
#
#run_cmd 0042 $other
#run_cmd 0027 $fisheye
#run_cmd 0026 $other
#run_cmd 0025 $other
#run_cmd 0031 $fisheye
#run_cmd 0030 $other
#
#run_cmd 0034 $other
#run_cmd 0003 $other
#run_cmd 0019 $fisheye
#run_cmd 0010 $other
#run_cmd 0013 $other
