echo "Copying inputs"
LOCALMACRODIR=$(mktemp -d)
-trap "rm -rf ${LOCALMACRODIR} ; exit 1" 1 2 3 15
+trap "mv output ${OUTPUTDIR}/output.${PBS_JOBID%%.*} ; rm -r ${LOCALMACRODIR} ; exit 1" 1 2 3 15
cd ${LOCALMACRODIR}
cp -r -L "${MACRODIR}"/{data,mac} .
mkdir output
echo " ${indent}merged ${count} files"
}
+doseMerger="mergeDosePerEnegryFile.sh"
+test -x "./mergeDosePerEnergyFile.sh" && doseMerger="./mergeDosePerEnergyFile.sh"
+
+function merge_dose {
+local merged="$1"
+shift
+echo " ${indent}entering dose merger"
+echo " ${indent}merger is ${doseMerger}"
+echo " ${indent}creating ${merged}"
+local count=0
+start_bar $#
+while test $# -gt 0
+do
+ local partial="$1"
+ shift
+ let count++
+
+ if test ! -f "${merged}"
+ then
+ update_bar ${count} "copying first partial result ${partial}"
+ cp "${partial}" "${merged}"
+ continue
+ fi
+
+ update_bar ${count} "adding ${partial}"
+ ${doseMerger} -i "${merged}" -j "${partial}" -o "${merged}" 2> /dev/null > /dev/null || warning "error while calling ${doseMerger}"
+done
+end_bar
+echo " ${indent}merged ${count} files"
+}
+
txtImageMerger="clitkMergeAsciiDoseActor"
test -f "./clitkMergeAsciiDoseActor" && txtImageMerger="./clitkMergeAsciiDoseActor"
return
fi
+ if test "${firstpartialoutputextension}" == "txt" && grep -qs 'energydose' "${firstpartialoutputfile}"
+ then
+ echo "${indent}this is a dose file"
+ local mergedfile="${outputdir}/$(basename "${firstpartialoutputfile}")"
+ merge_dose "${mergedfile}" ${partialoutputfiles} || error "error while merging"
+ return
+ fi
+
+
+
if test "${firstpartialoutputextension}" == "txt" && grep -qs 'Resol' "${firstpartialoutputfile}"
then
local resol="$(sed -nr '/Resol/s/^.*=\s+\((.+)\)\s*$/\1/p' "${firstpartialoutputfile}")"
--- /dev/null
+#!/bin/bash
+set -u
+
+function usage {
+ echo "$0 -i <file1> -j <file2> -o <result>"
+ exit 1
+}
+
+if [ $# != 6 ]
+then
+ usage
+fi
+
+IN1=$2
+IN2=$4
+RESULT=$6
+
+test -f ${IN1} && test -f ${IN2} || usage
+
+TMP="$(mktemp)"
+echo "merging dose file"
+for PARAM in `awk '$1 == "#" {print $3}' ${IN1}`
+do
+ echo "merging ${PARAM}"
+ V1=`awk -v P=${PARAM} '$3 == P {print $4}' ${IN1} `
+ V2=`awk -v P=${PARAM} '$3 == P {print $4}' ${IN2} `
+ V1=`echo ${V1} | sed -e 's/[eE]+*/\*10\^/'`
+ V2=`echo ${V2} | sed -e 's/[eE]+*/\*10\^/'`
+ R=`echo "scale=30; ${V1} + ${V2}" | bc -l`
+ test -z "${R}" && continue
+ echo "# energydose ${PARAM} ${R}" >> ${TMP}
+done
+mv -f ${TMP} ${RESULT}
return GetRotationMatrix3D(rotationParameters);
}
+//--------------------------------------------------------------------
+itk::Matrix<double, 4, 4> ReadMatrix3D(std::string fileName)
+{
+ // read input matrix
+ std::ifstream is;
+ openFileForReading(is, fileName);
+ std::vector<double> nb;
+ double x;
+ skipComment(is);
+ is >> x;
+ while (is && !is.eof()) {
+ nb.push_back(x);
+ skipComment(is);
+ is >> x;
+ }
+
+ if(nb.size() != 16)
+ itkGenericExceptionMacro(<< "Could not read 4x4 matrix in " << fileName);
+
+ //copy it to the matrix
+ itk::Matrix<double, 4, 4> matrix;
+ unsigned int index=0;
+ for (unsigned int i=0;i<4;i++)
+ for (unsigned int j=0;j<4;j++)
+ matrix[i][j]=nb[index++];
+ return matrix;
+}
+
}
return matrix;
}
- inline itk::Matrix<double, 4, 4> ReadMatrix3D(std::string fileName)
- {
- // read input matrix
- std::ifstream is;
- openFileForReading(is, fileName);
- std::vector<double> nb;
- double x;
- skipComment(is);
- is >> x;
- while (!is.eof()) {
- nb.push_back(x);
- skipComment(is);
- is >> x;
- }
-
- //copy it to the matrix
- itk::Matrix<double, 4, 4> matrix;
- unsigned int index=0;
- for (unsigned int i=0;i<4;i++)
- for (unsigned int j=0;j<4;j++)
- matrix[i][j]=nb[index++];
- return matrix;
- }
+ itk::Matrix<double, 4, 4> ReadMatrix3D(std::string fileName);
inline vtkMatrix4x4* ReadVTKMatrix3D(std::string fileName) {
// read input matrix
if(f.is_open()) {
f.close();
- itk::Matrix<double, 4, 4> itkMat = clitk::ReadMatrix3D(filename);
+ itk::Matrix<double, 4, 4> itkMat;
+ itkMat.SetIdentity();
+ try {
+ itkMat = clitk::ReadMatrix3D(filename);
+ }
+ catch (itk::ExceptionObject & err) {
+ itkWarningMacro(<< "Found " << filename
+ << " but this is not a 4x4 matrix so it is ignored.");
+ }
vtkSmartPointer<vtkMatrix4x4> matrix = vtkSmartPointer<vtkMatrix4x4>::New();
matrix->Identity();