#!/bin/bash
#============================================================================
#
#  Program:     DTI ToolKit (DTI-TK)
#  Module:      $RCSfile: dti_warp_to_template,v $
#  Language:    bash
#  Date:        $Date: 2011/12/21 20:39:22 $
#  Version:     $Revision: 1.1.1.1 $
#
#  Copyright (c) Gary Hui Zhang (garyhuizhang@gmail.com).
#  All rights reserverd.
#
#  DTI-TK is free software: you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation, either version 3 of the License, or
#  (at your option) any later version.
#
#  DTI-TK is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with DTI-TK.  If not, see <http://www.gnu.org/licenses/>.
#============================================================================

#
# Mapping a DTI volume from its subject space to the template space
#

#
# source PATH setting from ~.bashrc
# required for qsub to work
#
if [ -e ~/.bashrc ]
then
	. ~/.bashrc
elif [ -e ~/.bash_profile ]
then
	. ~/.bash_profile
fi

# check DTITK_ROOT variable
if [ -z "${DTITK_ROOT}" ]
then
	echo "Environment variable DTITK_ROOT is not defined"
	exit 1
fi

# source dtitk_common.sh
. ${DTITK_ROOT}/scripts/dtitk_common.sh

if [ $# -lt 5 ]
then
	echo "Mapping a DTI volume from its subject space to the template template"
	echo "Usage: `basename $0` subject target xv yv zv"
	exit 1
fi

subject=$1
target=$2
xv=$3
yv=$4
zv=$5

pref=`getTVPrefix $subject`
out=${pref}_diffeo.nii.gz
aff=${pref}.aff
df=${pref}_aff_diffeo.df.nii.gz
trans=${pref}_combined.df.nii.gz

dfRightComposeAffine -aff ${aff} -df ${df} -out ${trans}
deformationSymTensor3DVolume -in ${subject} -target ${target} -trans ${trans} -out ${out} -vsize ${xv} ${yv} ${zv}

echo "done"
echo

