]> Creatis software - clitk.git/commitdiff
*** empty log message ***
authorbouilhol <bouilhol>
Thu, 7 Apr 2011 18:18:04 +0000 (18:18 +0000)
committerbouilhol <bouilhol>
Thu, 7 Apr 2011 18:18:04 +0000 (18:18 +0000)
vv/scripts/create_mhd_4D.sh

index ae3f5fa4711e094613353e4c2f835e8e6f66eeb4..e3b4c1bcde9123a09cb462634a43d6d6094704f6 100755 (executable)
@@ -1,6 +1,24 @@
 #!/bin/sh
 
 
+write_mhd_4D()
+{
+  cat $orig | sed "s/NDims = .*/NDims = 4/
+                 s/TransformMatrix = .*/TransformMatrix = 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1/
+                 /Offset/ s/.*/& 0/
+                 /CenterOfRotation/ s/.*/& 0/
+                 s/AnatomicalOrientation = .*/AnatomicalOrientation = ????/
+                 /ElementSpacing/ s/.*/& 1/
+                 /DimSize/ s/.*/& $nbph/
+                 s/ElementDataFile = .*/ElementDataFile = LIST/" > "$1/$file_name_4D"
+  
+  for ph in $listph
+  do
+    ph=`basename $ph`
+    echo "$ph" >> "$1/$file_name_4D"
+  done
+}
+
 #################################################
 # create_mhd_4D        argument : repertoire   #
 #################################################
@@ -10,13 +28,15 @@ then
   exit 1
 fi
 
-nb_phase_file=`find $1 -iname "*[0-99].[0-9].mhd" | wc -l`
+nb_phase_file=`find $1 -iname "*[0-99].[0-9].mhd" -o -iname "*[0-99]*\]*.mhd" | wc -l`
 if [ $nb_phase_file = 0 ]
 then
   echo "Error: no phase found"
   exit 1
 fi
 
+########## CT #########
+
 list_pattern=""
 list_phase_file=`find $1 -iname "*[0-99].[0-9].mhd"`
 for phase_file in $list_phase_file
@@ -24,13 +44,13 @@ do
   phase_file_name=`basename $phase_file`
   if [[ ! -z `echo "$phase_file_name" | grep ","` ]]
   then
-    preffix=`echo $phase_file_name | sed "s/,_.*/,_/"`
+    prefix=`echo $phase_file_name | sed "s/,_.*/,_/"`
   else
-    preffix="NONE"
+    prefix="NONE"
   fi
-  if [[ -z `echo "$list_pattern" | grep "$preffix"` ]]
+  if [[ -z `echo "$list_pattern" | grep "$prefix"` ]]
   then
-    list_pattern="$list_pattern $preffix"
+    list_pattern="$list_pattern $prefix"
   fi
 done
 
@@ -55,19 +75,47 @@ do
   orig=`echo -e "$orig0\n$orig1" | head -n 1`
   listph="$listph0 $listph1"
 
-  cat $orig | sed "s/NDims = .*/NDims = 4/
-                 s/TransformMatrix = .*/TransformMatrix = 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1/
-                 /Offset/ s/.*/& 0/
-                 /CenterOfRotation/ s/.*/& 0/
-                 s/AnatomicalOrientation = .*/AnatomicalOrientation = ????/
-                 /ElementSpacing/ s/.*/& 1/
-                 /DimSize/ s/.*/& $nbph/
-                 s/ElementDataFile = .*/ElementDataFile = LIST/" > "$1/${pattern}_4D.mhd"
+  file_name_4D="${pattern}_4D.mhd"
+
+  write_mhd_4D $1
+
+done
+
+
+############ PET ###########
+
+list_pattern=""
+list_phase_file=`find $1 -iname "*[0-99]*\]*.mhd"`
+for phase_file in $list_phase_file
+do
+  phase_file_name=`basename $phase_file`
+  if [[ ! -z `echo "$phase_file_name" | grep "[0-99]-.*\]"` ]]
+  then
+    prefix=`echo $phase_file_name | sed "s/.*[0-99]-/-/;s/\]_.*//"`
+  else
+    prefix="NONE"
+  fi
+  if [[ -z `echo "$list_pattern" | grep -- "$prefix"` ]]
+  then
+    list_pattern="$list_pattern $prefix"
+  fi
+done
+
   
-  for ph in $listph
-  do
-    ph=`basename $ph`
-    echo "$ph" >> "$1/${pattern}_4D.mhd"
-  done
+for pattern in $list_pattern
+do
+
+  if [ "$pattern" = "NONE" ]
+  then
+    pattern=""
+  fi
+
+  nbph=`find $1 -iname "*[0-99]${pattern}\]*.mhd" | wc -l`
+  orig=`find $1 -iname "*[0-99]${pattern}\]*.mhd" | sort | head -n 1`
+  listph=`find $1 -iname "*[0-99]${pattern}\]*.raw" | sort`
+  
+  file_name_4D=`basename "$orig" | sed "s/[0-99]${pattern}\]/${pattern}\]/;s/_.mhd/_4D.mhd/"`
+
+  write_mhd_4D $1
 
 done