]> Creatis software - clitk.git/blobdiff - tools/clitkWriteDicomSeriesGenericFilter.txx
Merge branch 'master' of git.creatis.insa-lyon.fr:clitk
[clitk.git] / tools / clitkWriteDicomSeriesGenericFilter.txx
index d49c51e567b9ac836ddd6cb817df51195b4dbf79..6f09ba9ea4fb48aef5b3b673b49c955a0dbfac40 100644 (file)
@@ -82,10 +82,10 @@ WriteDicomSeriesGenericFilter<args_info_type>::UpdateWithDim(std::string PixelTy
     if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and signed short..." << std::endl;
     UpdateWithDimAndPixelType<Dimension, signed short>();
   }
-  //    else if(PixelType == "unsigned_short"){
-  //       if (m_Verbose) std::cout  << "Launching filter in "<< Dimension <<"D and unsigned_short..." << std::endl;
-  //       UpdateWithDimAndPixelType<Dimension, unsigned short>();
-  //     }
+  else if(PixelType == "unsigned_short"){
+    if (m_Verbose) std::cout  << "Launching filter in "<< Dimension <<"D and unsigned_short..." << std::endl;
+    UpdateWithDimAndPixelType<Dimension, unsigned short>();
+  }
 
   else if (PixelType == "unsigned_char") {
     if (m_Verbose) std::cout  << "Launching filter in "<< Dimension <<"D and unsigned_char..." << std::endl;
@@ -96,6 +96,10 @@ WriteDicomSeriesGenericFilter<args_info_type>::UpdateWithDim(std::string PixelTy
   //       if (m_Verbose) std::cout  << "Launching filter in "<< Dimension <<"D and signed_char..." << std::endl;
   //       UpdateWithDimAndPixelType<Dimension, signed char>();
   //     }
+  else if (PixelType == "double") {
+    if (m_Verbose) std::cout  << "Launching filter in "<< Dimension <<"D and double..." << std::endl;
+    UpdateWithDimAndPixelType<Dimension, double>();
+  }
   else {
     if (m_Verbose) std::cout  << "Launching filter in "<< Dimension <<"D and float..." << std::endl;
     UpdateWithDimAndPixelType<Dimension, float>();
@@ -196,10 +200,15 @@ WriteDicomSeriesGenericFilter<args_info_type>::UpdateWithDimAndPixelType()
       }
     }
 
-    filter->Update();
-    input = filter->GetOutput();
+    try {
+      filter->Update();
+      input = filter->GetOutput();
+    } catch( itk::ExceptionObject & excp ) {
+    std::cerr << "Error: Exception thrown while resampling!!" << std::endl;
+    std::cerr << excp << std::endl;
+    }
   }
-
+  
   //   In some cases, due to resampling approximation issues, 
   //   the number of slices in the MHD file may be different (smaller)
   //   from the number of files in the template dicom directory. 
@@ -208,6 +217,9 @@ WriteDicomSeriesGenericFilter<args_info_type>::UpdateWithDimAndPixelType()
   //   in verbose mode
   const RegionType volumeRegion = input->GetLargestPossibleRegion();
   const SizeType& volumeSize = volumeRegion.GetSize();
+  if (m_Verbose) {
+    std::cout << volumeRegion << volumeSize << std::endl;
+  }
   if (Dimension == 3 && volumeSize[2] < numberOfFilenames) {
     if (m_Verbose)
       std::cout << "Warning: The number of files in " << m_ArgsInfo.inputDir_arg << " (" << filenames_in.size() << " files) is greater than the number of slices in MHD (" << volumeSize[2] << " slices). Using only " << volumeSize[2] << " files." << std::endl;
@@ -222,20 +234,16 @@ WriteDicomSeriesGenericFilter<args_info_type>::UpdateWithDimAndPixelType()
   const std::vector<DictionaryType*>* dictionary = reader->GetMetaDataDictionaryArray();
 
   // Get keys
-  unsigned int numberOfKeysGiven=0;
-  if(m_ArgsInfo.midP_flag && m_ArgsInfo.key_given)
-    std::cerr<<"Error: both keys and midP option are given"<<std::endl;
-  else if (m_ArgsInfo.midP_flag)
-    numberOfKeysGiven=1;
-  else
-    numberOfKeysGiven=m_ArgsInfo.key_given;
+  unsigned int numberOfKeysGiven=m_ArgsInfo.key_given;
 
   for (unsigned int i = 0; i < numberOfKeysGiven; i++) {
     std::string entryId(m_ArgsInfo.key_arg[i]  );
     std::string value( m_ArgsInfo.tag_arg[i] );
+    std::cout << entryId << " " << value << std::endl;
     for(unsigned int fni = 0; fni<numberOfFilenames; fni++)
       itk::EncapsulateMetaData<std::string>( *((*dictionary)[fni]), entryId, value );
   }
+  
 
   // Output directory and filenames
   itksys::SystemTools::MakeDirectory( m_ArgsInfo.outputDir_arg ); // create if it doesn't exist