]> Creatis software - clitk.git/commitdiff
Merge branch 'master' of git://git.creatis.insa-lyon.fr/clitk
authorBenoît Presles <benoit.presles@netcourrier.com>
Tue, 4 Sep 2012 07:24:19 +0000 (09:24 +0200)
committerBenoît Presles <benoit.presles@netcourrier.com>
Tue, 4 Sep 2012 07:24:19 +0000 (09:24 +0200)
itk/clitkComposeVFFilter.h
itk/clitkComposeVFFilter.txx
itk/clitkInvertVFFilter.txx
tools/clitkDicom2Image.cxx
tools/clitkImageStatisticsGenericFilter.txx
tools/clitkSplitImageGenericFilter.cxx
tools/clitkSplitImageGenericFilter.h
tools/clitkVectorImageToImageFilter.h
tools/clitkVectorImageToImageFilter.txx
tools/clitkWriteDicomSeries.ggo
tools/clitkWriteDicomSeriesGenericFilter.txx

index d66d819b0c750b4a82447bd52877d09ce690030e..cf1ada2c77678ea0336d8f0662bd6fceec5ad88e 100644 (file)
@@ -75,7 +75,11 @@ namespace clitk
 
     //========================================================================================
     //Threaded execution should implement generate threaded data
-    void ThreadedGenerateData(const OutputImageRegionType& outputRegionForThread, int threadId );
+#if ITK_VERSION_MAJOR >= 4
+  void ThreadedGenerateData(const OutputImageRegionType& outputRegionForThread, itk::ThreadIdType threadId );
+#else
+  void ThreadedGenerateData(const OutputImageRegionType& outputRegionForThread, int threadId );
+#endif
   
     bool m_Verbose;
     PixelType m_EdgePaddingValue;
index 7103a1025c40f95828e477823d8c2f2c0fc9554b..a50ca26a38ee2556751e7af18c7a8913e852546a 100644 (file)
@@ -35,8 +35,13 @@ namespace clitk
 
   //=========================================================================================================================
   //update the output for the outputRegionForThread
+#if ITK_VERSION_MAJOR >= 4
+  template<class InputImageType, class OutputImageType> 
+  void ComposeVFFilter<InputImageType, OutputImageType>::ThreadedGenerateData(const OutputImageRegionType& outputRegionForThread, itk::ThreadIdType threadId )
+#else
   template<class InputImageType, class OutputImageType> 
   void ComposeVFFilter<InputImageType, OutputImageType>::ThreadedGenerateData(const OutputImageRegionType& outputRegionForThread, int threadId )
+#endif
   {
  
     //Get pointer to the output
index 684b35545add887b43a3827a6efd9ce8d71577d0..b74958fb597a83dc9b3f559936973b340ee6874d 100644 (file)
@@ -75,7 +75,11 @@ protected:
 
   //the actual processing
   void BeforeThreadedGenerateData();
+#if ITK_VERSION_MAJOR >= 4
+  void ThreadedGenerateData(const OutputImageRegionType& outputRegionForThread, itk::ThreadIdType threadId );
+#else
   void ThreadedGenerateData(const OutputImageRegionType& outputRegionForThread, int threadId );
+#endif
 
   //member data
   typename  WeightsImageType::Pointer m_Weights;
@@ -113,7 +117,11 @@ void HelperClass1<InputImageType, OutputImageType>::BeforeThreadedGenerateData()
 //=========================================================================================================================
 //update the output for the outputRegionForThread
 template<class InputImageType, class OutputImageType>
+#if ITK_VERSION_MAJOR >= 4
+void HelperClass1<InputImageType, OutputImageType>::ThreadedGenerateData(const OutputImageRegionType& outputRegionForThread, itk::ThreadIdType threadId )
+#else
 void HelperClass1<InputImageType, OutputImageType>::ThreadedGenerateData(const OutputImageRegionType& outputRegionForThread, int threadId )
+#endif
 {
   //std::cout << "HelperClass1::ThreadedGenerateData - IN" << std::endl;
   //Get pointer to the input
@@ -285,8 +293,11 @@ protected:
 
 
   //the actual processing
+#if ITK_VERSION_MAJOR >= 4
+  void ThreadedGenerateData(const OutputImageRegionType& outputRegionForThread, itk::ThreadIdType threadId );
+#else
   void ThreadedGenerateData(const OutputImageRegionType& outputRegionForThread, int threadId );
-
+#endif
 
   //member data
   typename     WeightsImageType::Pointer m_Weights;
@@ -311,7 +322,11 @@ template<class InputImageType, class OutputImageType > HelperClass2<InputImageTy
 
 //=========================================================================================================================
 //update the output for the outputRegionForThread
+#if ITK_VERSION_MAJOR >= 4
+template<class InputImageType, class OutputImageType > void HelperClass2<InputImageType, OutputImageType>::ThreadedGenerateData(const OutputImageRegionType& outputRegionForThread, itk::ThreadIdType threadId )
+#else
 template<class InputImageType, class OutputImageType > void HelperClass2<InputImageType, OutputImageType>::ThreadedGenerateData(const OutputImageRegionType& outputRegionForThread, int threadId )
+#endif
 {
   //std::cout << "HelperClass2::ThreadedGenerateData - IN" << std::endl;
   
index 6410714293c69e769b12eceae618f9c26a5abf94..07a85653edc37eba8c30262676b860b5d1038207 100644 (file)
@@ -57,6 +57,8 @@ int main(int argc, char * argv[])
   for(unsigned int i=0; i<args_info.inputs_num; i++) {
     //std::cout << "Reading <" << input_files[i] << std::endl;
 #if GDCM_MAJOR_VERSION == 2
+    if (args_info.verbose_flag)
+      std::cout << "Using GDCM-2.x" << std::endl;
     gdcm::Reader hreader;
     hreader.SetFileName(input_files[i].c_str());
     hreader.Read();
@@ -72,6 +74,8 @@ int main(int argc, char * argv[])
       exit(0);
     }
 #else
+    if (args_info.verbose_flag)
+      std::cout << "Not using GDCM-2.x" << std::endl;
   gdcm::File *header = new gdcm::File();
   header->SetFileName(input_files[i]);
   header->SetMaxSizeLoadEntry(16384); // required ?
index d1b0d4c4abf845ce98e50054e8d259093523e37a..a0d2abfc609e101ece56b5b1e6606f13939f0064 100644 (file)
@@ -48,20 +48,28 @@ namespace clitk
       if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and signed short..." << std::endl;
       UpdateWithDimAndPixelType<Dimension, signed short, Components>(); 
     }
-    //    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, Components>(); 
+    }
     
     else if (PixelType == "unsigned_char"){ 
       if (m_Verbose) std::cout  << "Launching filter in "<< Dimension <<"D and unsigned_char..." << std::endl;
       UpdateWithDimAndPixelType<Dimension, unsigned char, Components>();
     }
     
+//     else if (PixelType == "unsigned_int"){ 
+//       if (m_Verbose) std::cout  << "Launching filter in "<< Dimension <<"D and unsigned_int..." << std::endl;
+//       UpdateWithDimAndPixelType<Dimension, unsigned int, Components>();
+//     }
     //     else if (PixelType == "char"){ 
     //       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, Components>(); 
+    }
     else {
       if (m_Verbose) std::cout  << "Launching filter in "<< Dimension <<"D and float..." << std::endl;
       UpdateWithDimAndPixelType<Dimension, float, Components>();
index 5a5e246e8c6eb81d11bf3d872c1cf3ba64ff94cb..55bf7a80716517e18324637901f70eee5be1bc10 100644 (file)
@@ -36,13 +36,54 @@ clitk::SplitImageGenericFilter::SplitImageGenericFilter():
 }
 //--------------------------------------------------------------------
 
-
 //--------------------------------------------------------------------
 template<unsigned int Dim>
 void clitk::SplitImageGenericFilter::InitializeImageType()
 {
   ADD_DEFAULT_IMAGE_TYPES(Dim);
-  //ADD_VEC_IMAGE_TYPE(Dim, 3,float);
+  ADD_VEC_IMAGE_TYPE(Dim, 3,float);
+}
+//--------------------------------------------------------------------
+
+//--------------------------------------------------------------------
+template <class ImageType>
+typename clitk::SplitImageGenericFilter::PngConversion<ImageType>::OutputPngImagePointer
+clitk::SplitImageGenericFilter::PngConversion<ImageType>::Do(double window,
+                                                             double level,
+                                                             ImagePointer input)
+{
+  static const unsigned int PixelDimension = itk::PixelTraits<typename ImageType::PixelType>::Dimension;
+  return this->Do(window, level, input, static_cast< PixelDimType<PixelDimension> *>(NULL) );
+}
+//--------------------------------------------------------------------
+
+//--------------------------------------------------------------------
+template <class ImageType>
+template<unsigned int Dim>
+typename clitk::SplitImageGenericFilter::PngConversion<ImageType>::OutputPngImagePointer
+clitk::SplitImageGenericFilter::PngConversion<ImageType>::Do(double window,
+                                                             double level,
+                                                             ImagePointer input,
+                                                             PixelDimType<Dim> *)
+{
+  clitkExceptionMacro("Png conversion is not implemented for vector fields");
+  return NULL;
+}
+//--------------------------------------------------------------------
+
+//--------------------------------------------------------------------
+template <class ImageType>
+typename clitk::SplitImageGenericFilter::PngConversion<ImageType>::OutputPngImagePointer
+clitk::SplitImageGenericFilter::PngConversion<ImageType>::Do(double window,
+                                                             double level,
+                                                             ImagePointer input,
+                                                             PixelDimType<1> *)
+{
+  typedef itk::IntensityWindowingImageFilter< ImageType, OutputPngImageType > CastFilterType;
+  typename CastFilterType::Pointer cast = CastFilterType::New();
+  cast->SetWindowLevel(window, level);
+  cast->SetInput(input);
+  return cast->GetOutput();
 }
 //--------------------------------------------------------------------
 
@@ -80,13 +121,11 @@ void clitk::SplitImageGenericFilter::UpdateWithInputImageType()
     filter->SetExtractionRegion(extracted_region);
     filter->Update();
     if(this->m_Png){
-      typedef itk::Image< unsigned char, ImageType::ImageDimension-1 > OutputPngImageType;
-      typedef itk::IntensityWindowingImageFilter< OutputImageType, OutputPngImageType > CastFilterType;
-      typename CastFilterType::Pointer cast = CastFilterType::New();
-      cast->SetWindowLevel(this->m_Window, this->m_Level);
-      cast->SetInput(filter->GetOutput());
+      PngConversion<OutputImageType> png;
       SetOutputFilename(base_filename+"_"+ss.str()+".png");
-      SetNextOutput<OutputPngImageType>(cast->GetOutput());
+      typename PngConversion<OutputImageType>::OutputPngImagePointer output;
+      output = png.Do(this->m_Window, this->m_Level, filter->GetOutput());
+      this->template SetNextOutput<typename PngConversion<OutputImageType>::OutputPngImageType>(output);
     }
     else {
       SetOutputFilename(base_filename+"_"+ss.str()+".mhd");
index dfdd0e747724310b81d6f816ee10dd743c137e30..4b6d676219bdd58d03d796400b6d81eee8a0ae02 100644 (file)
@@ -67,6 +67,23 @@ namespace clitk {
     void UpdateWithInputImageType();
 
   protected:  
+    template <class ImageType>
+    class PngConversion
+    {
+    public:
+      typedef typename ImageType::Pointer ImagePointer;
+      typedef itk::Image< unsigned char, ImageType::ImageDimension > OutputPngImageType;
+      typedef typename OutputPngImageType::Pointer OutputPngImagePointer;
+      OutputPngImagePointer Do(double window, double level, ImagePointer input);
+    private:
+      template<unsigned int> struct PixelDimType {};
+      template<unsigned int Dim> OutputPngImagePointer Do(double window,
+                                                          double level,
+                                                          ImagePointer input,
+                                                          PixelDimType<Dim> *);
+      OutputPngImagePointer Do(double window, double level, ImagePointer input, PixelDimType<1> *);
+    };
+
     template<unsigned int Dim> void InitializeImageType();
     int  mSplitDimension;
     bool m_Verbose;
index cf5946e3849e4adac4fd5ed3d74a3c02422f33d5..e2971f4e1962a34fb6aea5067dcfbb0b7b7e46ba 100644 (file)
@@ -86,7 +86,11 @@ namespace clitk
     //----------------------------------------  
     // Update
     //----------------------------------------  
+#if ITK_VERSION_MAJOR >= 4
+    void ThreadedGenerateData(const OutputImageRegionType & outputRegionForThread, itk::ThreadIdType threadId );
+#else
     void ThreadedGenerateData(const OutputImageRegionType & outputRegionForThread, int threadId );
+#endif
    
     //----------------------------------------  
     // Data members
index 909a42290e3a84ba556889972f24d5f93eceb718..539e8dced07cb13b989d63b654b8f7444a8617d5 100644 (file)
@@ -47,7 +47,11 @@ namespace clitk
   //-------------------------------------------------------------------
   template<class InputImageType, class  OutputImageType> 
   void 
+#if ITK_VERSION_MAJOR >= 4
+  VectorImageToImageFilter<InputImageType, OutputImageType>::ThreadedGenerateData(const OutputImageRegionType & outputRegionForThread, itk::ThreadIdType threadId)
+#else
   VectorImageToImageFilter<InputImageType, OutputImageType>::ThreadedGenerateData(const OutputImageRegionType & outputRegionForThread, int threadId)
+#endif
   {
     // Iterators
     typename OutputImageType::Pointer output=this->GetOutput();
index ef7a9eb77cfb97419c81766da014e2906a595142..f6bccde1ad9563bda2d9a10d8a75896928d44dbb 100644 (file)
@@ -11,5 +11,4 @@ option "inputDir"     d       "Input dicom directory"           string        yes
 option "outputDir"     o       "Output dicom directory"          string        yes 
 option "key"           k       "Keys of tags to modify"          string        no multiple default="0008|103e"
 option "tag"           t       "Tags values"                    string         no multiple default="MIDPOSITION"
-option "midP"          m       "Modify tags using defaults, for  MidPosition"  flag    off
 option "useSizeAsReference"            s       "Use the size of the dicom image as reference for an occasional resampling"     flag    off
\ No newline at end of file
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