]> Creatis software - clitk.git/blobdiff - tools/clitkDicom2Image.cxx
Debug: correct wrong flag in condition
[clitk.git] / tools / clitkDicom2Image.cxx
index e08f0def68acd476d1731cbbd1a6d722e4c2b441..aa63b0489bd50505255c2610640e8bbb4615c70e 100644 (file)
@@ -17,6 +17,7 @@
 ===========================================================================**/
 
 // clitk includes
+#include "clitkIO.h"
 #include "clitkDicom2Image_ggo.h"
 #include "clitkCommon.h"
 #include "clitkImageCommon.h"
@@ -25,7 +26,7 @@
 #include <gdcmFile.h>
 #include <vtkVersion.h>
 #include <vtkImageChangeInformation.h>
-#if GDCM_MAJOR_VERSION == 2
+#if GDCM_MAJOR_VERSION >= 2
   #include <gdcmImageHelper.h>
   #include <gdcmAttribute.h>
   #include <gdcmReader.h>
@@ -38,6 +39,8 @@ int main(int argc, char * argv[])
 {
   // init command line
   GGO(clitkDicom2Image, args_info);
+  CLITK_INIT;
+
   std::vector<std::string> input_files;
   ///if std_input is given, read the input files from stdin
   if (args_info.std_input_given) {
@@ -61,7 +64,7 @@ int main(int argc, char * argv[])
   std::map< int, std::vector<double> > theorientation;
   std::map< int, std::vector<double> > sliceLocations;
   std::map< int, std::vector<std::string> > seriesFiles;
-#if GDCM_MAJOR_VERSION == 2
+#if GDCM_MAJOR_VERSION >= 2
   if (args_info.verbose_flag)
     std::cout << "Using GDCM-2.x" << std::endl;
 #else
@@ -73,7 +76,7 @@ int main(int argc, char * argv[])
   for(unsigned int i=0; i<args_info.inputs_num; i++) {
     if (args_info.verbose_flag)
         std::cout << "Reading <" << input_files[i] << std::endl;
-#if GDCM_MAJOR_VERSION == 2
+#if GDCM_MAJOR_VERSION >= 2
     gdcm::Reader hreader;
     hreader.SetFileName(input_files[i].c_str());
     hreader.Read();
@@ -88,16 +91,19 @@ int main(int argc, char * argv[])
     series_numbers.insert(series_number);
     theorigin[series_number] = gdcm::ImageHelper::GetOriginValue(hreader.GetFile());
     theorientation[series_number] = gdcm::ImageHelper::GetDirectionCosinesValue(hreader.GetFile());
-    double n1 = theorientation[series_number][1]*theorientation[series_number][5]-
-                theorientation[series_number][2]*theorientation[series_number][4];
-    double n2 = theorientation[series_number][3]*theorientation[series_number][2]-
-                theorientation[series_number][5]*theorientation[series_number][0];
-    double n3 = theorientation[series_number][0]*theorientation[series_number][4]-
-                theorientation[series_number][1]*theorientation[series_number][3];
-    double sloc = theorigin[series_number][0]*n1+
-                  theorigin[series_number][1]*n2+
-                  theorigin[series_number][2]*n3;
-    sliceLocations[series_number].push_back(sloc);
+    if (args_info.patientSystem_flag) {
+      double n1 = theorientation[series_number][1]*theorientation[series_number][5]-
+                  theorientation[series_number][2]*theorientation[series_number][4];
+      double n2 = theorientation[series_number][3]*theorientation[series_number][2]-
+                  theorientation[series_number][5]*theorientation[series_number][0];
+      double n3 = theorientation[series_number][0]*theorientation[series_number][4]-
+                  theorientation[series_number][1]*theorientation[series_number][3];
+      double sloc = theorigin[series_number][0]*n1+
+                    theorigin[series_number][1]*n2+
+                    theorigin[series_number][2]*n3;
+      sliceLocations[series_number].push_back(sloc);
+    } else
+      sliceLocations[series_number].push_back(theorigin[series_number][2]);
     seriesFiles[series_number].push_back(input_files[i]);
 
     gdcm::Attribute<0x28, 0x100> pixel_size;
@@ -228,29 +234,15 @@ int main(int argc, char * argv[])
       std::ostringstream name;
       std::vector<std::string> directory = clitk::SplitFilename(args_info.output_arg);
       if (directory.size() == 2)
-        name << directory[0] << *sn << "_" << directory[1];
+        name << directory[0] << "/" << *sn << "_" << directory[1];
       else
         name << *sn << "_" << args_info.output_arg;
       outfile = name.str();
     }
-    //Check on transform
-    bool bId = true;
-    for(unsigned int i=0; i<4; i++) {
-      for(unsigned int j=0; j<4; j++) {
-        double elt = image->GetTransform()[0]->GetMatrix()->GetElement(i,j);
-        if(i==j && elt!=1.) {
-          bId = false;
-        }
-        if(i!=j && elt!=0.) {
-          bId = false;
-        }
-      }
-    }
     vvImageWriter::Pointer writer = vvImageWriter::New();
     writer->SetInput(image);
-    if(!bId) {
-        writer->SetSaveTransform(true);
-    }
+    if (args_info.patientSystem_flag && !image->GetTransform().empty())
+      writer->SetSaveTransform(true);
     writer->SetOutputFileName(outfile);
     writer->Update();