]> Creatis software - clitk.git/commitdiff
VF supported (SR)
authorGauthier Bouilhol <bouilhol@creatis.insa-lyon.fr>
Fri, 31 Aug 2012 13:06:15 +0000 (15:06 +0200)
committerGauthier Bouilhol <bouilhol@creatis.insa-lyon.fr>
Fri, 31 Aug 2012 13:06:15 +0000 (15:06 +0200)
tools/clitkSplitImageGenericFilter.cxx
tools/clitkSplitImageGenericFilter.h

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;