]> Creatis software - clitk.git/commitdiff
Merge branch 'master' of git.creatis.insa-lyon.fr:clitk
authorDavid Sarrut <david.sarrut@creatis.insa-lyon.fr>
Thu, 18 Jul 2013 08:52:25 +0000 (10:52 +0200)
committerDavid Sarrut <david.sarrut@creatis.insa-lyon.fr>
Thu, 18 Jul 2013 08:52:25 +0000 (10:52 +0200)
cluster_tools/gate_job_cluster.job
cluster_tools/gate_power_merge.sh
cluster_tools/mergeDosePerEnergyFile.sh [new file with mode: 0755]
common/clitkTransformUtilities.cxx
common/clitkTransformUtilities.h
common/vvImageReader.cxx

index 6b893b11395af8acad335a094e6d9f3b4557534e..1242dfd06fd9ecb32e4fd9c20345f225b8d35354 100644 (file)
@@ -65,7 +65,7 @@ test -d "${MACRODIR}" && test -d "${MACRODIR}/mac" || error "invalid macro"
 
 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
index 55fc1f00ce974e4a1430dc2be9f2647e641bd3f2..fc0e6aa3233fe032bf9713b1038e27315f4c9e67 100755 (executable)
@@ -165,6 +165,37 @@ end_bar
 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"
 
@@ -336,6 +367,16 @@ function merge_dispatcher {
         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}")"
diff --git a/cluster_tools/mergeDosePerEnergyFile.sh b/cluster_tools/mergeDosePerEnergyFile.sh
new file mode 100755 (executable)
index 0000000..b63c5ae
--- /dev/null
@@ -0,0 +1,33 @@
+#!/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}
index ef210d70ae3318c5dbb778557787d9d86b51677e..832d5983eed109898fe427337ec9b4f6dd0a8483 100644 (file)
@@ -67,4 +67,32 @@ itk::Matrix<double, 3, 3> GetRotationMatrix<3>(itk::Array<double> rotationParame
   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;
+}
+
 }
index cbc30b97ac806aa0cd3c91d531dc4cac082bd2e8..d3644b19206f830eab30397f2c209ef721eca6f4 100644 (file)
@@ -255,29 +255,7 @@ namespace clitk
     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
index f4f1a907214912b61b4bbe295a1c2652c6359c8e..ddc4ad3833ae2e60050fee3debd5c58e106ee4c7 100644 (file)
@@ -161,7 +161,15 @@ void vvImageReader::ReadMatImageTransform()
   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();