#!/bin/bash -xv

DATASET=$1
START_TIME=$2
VISION_LMDB=$3
LIDAR_LMDB=$4
CAMERA_INT=$5
CAMERA_EXT=$6
VIS_SENSOR=$7

LIDAR_SENSOR="VV"

NEAREST_VISION_KEY=`${ZOOX_WORKSPACE_ROOT}/bazel-bin/experimental/execution_chamber/labeltool/bin/lmdb_keys --dataset $DATASET $VISION_LMDB $VIS_SENSOR $START_TIME`
NEAREST_VISION_TS=`${ZOOX_WORKSPACE_ROOT}/bazel-bin/experimental/execution_chamber/labeltool/bin/lmdb_key_to_ts  $VIS_SENSOR $NEAREST_VISION_KEY`
VISION_ACF=${NEAREST_VISION_TS}_${VIS_SENSOR}.acf
VISION_ALFC=${NEAREST_LIDAR_TS}_${VIS_SENSOR}.alfc

NEAREST_LIDAR_KEY=`${ZOOX_WORKSPACE_ROOT}/bazel-bin/experimental/execution_chamber/labeltool/bin/lmdb_keys $LIDAR_LMDB VV $NEAREST_VISION_TS`
NEAREST_LIDAR_TS=`${ZOOX_WORKSPACE_ROOT}/bazel-bin/experimental/execution_chamber/labeltool/bin/lmdb_key_to_ts $LIDAR_SENSOR $NEAREST_LIDAR_KEY`
LIDAR_ALF=${NEAREST_LIDAR_TS}_${LIDAR_SENSOR}.alf

${ZOOX_WORKSPACE_ROOT}/bazel-bin/experimental/execution_chamber/labeltool/bin/lmdb_export $VISION_LMDB $NEAREST_VISION_KEY --outfile ${VISION_ACF} && \
${ZOOX_WORKSPACE_ROOT}/bazel-bin/experimental/execution_chamber/labeltool/bin/lmdb_export $LIDAR_LMDB $NEAREST_LIDAR_KEY --outfile ${LIDAR_ALF} && \
${ZOOX_WORKSPACE_ROOT}/bazel-bin/experimental/execution_chamber/labeltool/bin/lidar_to_cam --alf_file ${LIDAR_ALF} --acf_file ${VISION_ACF} --cam_int ${CAMERA_INT} --cam_ext ${CAMERA_EXT} --alfc_file ${VISION_ALFC} --cam_name ${VIS_SENSOR} && \
${ZOOX_WORKSPACE_ROOT}/bazel-bin/experimental/execution_chamber/labeltool/bin/showalfc --alfc_file ${VISION_ALFC} --acf_file ${VISION_ACF}
