]> Creatis software - clitk.git/commitdiff
Prevent vv from instantiated 4D vvImage.
authorVivien Delmon <vivien.delmon@creatis.insa-lyon.fr>
Tue, 3 May 2011 14:44:00 +0000 (16:44 +0200)
committerVivien Delmon <vivien.delmon@creatis.insa-lyon.fr>
Tue, 3 May 2011 14:44:00 +0000 (16:44 +0200)
* itk4 introduced some concept checking on image dimensions leading to
  compilation error on code instantiated but never used. Adding 4D
  specialized version of vvFromITK avoid these instantiations.

common/vvFromITK.h

index c089816ad785085026eb9a594ef3ad6d476df808..d4232b1be5f4d0604895edbb473bc081c3ccf514 100644 (file)
 /**Converts the itk image to vv, handling the 4D problem
  * The time_sequence boolean specifies that the image is to be interpreted as a time sequence,
  * even if its dim is < 4. */
-template<unsigned int Dim, class PixelType> vvImage::Pointer vvImageFromITK(typename itk::Image<PixelType,Dim>::Pointer input, bool time_sequence=false)
+
+template<unsigned int Dim, class PixelType>
+struct vvImageFromITK_Impl
 {
-    assert(Dim < 5 && Dim > 0); // We don't handle anything higher than 4-dimensional (for the moment :-p)
+  static vvImage::Pointer Do (typename itk::Image<PixelType,Dim>::Pointer input, bool time_sequence=false)
+  {
     vvImage::Pointer vv_image=vvImage::New();
     typedef itk::Image< PixelType, Dim > InputImageType;
-
-    if (Dim == 4 || time_sequence) //The time sequence case: create a series of VTK images
+    if (time_sequence) //The time sequence case: create a series of VTK images
     {
-        typedef itk::Image< PixelType,  Dim - 1 >    ItkImageType;
-        typedef itk::ExtractImageFilter<InputImageType, ItkImageType> FilterType;
-
-        //extract the 3D slices and put them in a std::vector<vtkImageData*>
-        input->UpdateOutputInformation();
-        typename InputImageType::RegionType inputRegion = input->GetLargestPossibleRegion();
-        typename InputImageType::SizeType inputSize = inputRegion.GetSize();
-        typename InputImageType::IndexType start = inputRegion.GetIndex();
-        typename InputImageType::SizeType extractedRegionSize = inputSize;
-        typename InputImageType::RegionType extractedRegion;
-        extractedRegionSize[Dim - 1] = 0;
-        extractedRegion.SetSize(extractedRegionSize);
-
-        for (unsigned int i = 0; i < inputSize[Dim - 1]; i++) {
-            start[Dim - 1] = i;
-            extractedRegion.SetIndex(start);
-
-            typename FilterType::Pointer filter = FilterType::New();
+      typedef itk::Image< PixelType,  Dim - 1 >    ItkImageType;
+      typedef itk::ExtractImageFilter<InputImageType, ItkImageType> FilterType;
+
+      //extract the 3D slices and put them in a std::vector<vtkImageData*>
+      input->UpdateOutputInformation();
+      typename InputImageType::RegionType inputRegion = input->GetLargestPossibleRegion();
+      typename InputImageType::SizeType inputSize = inputRegion.GetSize();
+      typename InputImageType::IndexType start = inputRegion.GetIndex();
+      typename InputImageType::SizeType extractedRegionSize = inputSize;
+      typename InputImageType::RegionType extractedRegion;
+      extractedRegionSize[Dim - 1] = 0;
+      extractedRegion.SetSize(extractedRegionSize);
+
+      for (unsigned int i = 0; i < inputSize[Dim - 1]; i++) {
+        start[Dim - 1] = i;
+        extractedRegion.SetIndex(start);
+
+        typename FilterType::Pointer filter = FilterType::New();
 #if ITK_VERSION_MAJOR == 4
-            filter->SetDirectionCollapseToSubmatrix();
+        filter->SetDirectionCollapseToSubmatrix();
 #endif
-            filter->SetExtractionRegion(extractedRegion);
-            filter->SetInput(input);
-            filter->ReleaseDataFlagOn();
-            vv_image->AddItkImage<ItkImageType>(filter->GetOutput());
-        }
-        vv_image->SetTimeSpacing(input->GetSpacing()[Dim-1]);
-        vv_image->SetTimeOrigin(input->GetOrigin()[Dim-1]);
+        filter->SetExtractionRegion(extractedRegion);
+        filter->SetInput(input);
+        filter->ReleaseDataFlagOn();
+        vv_image->AddItkImage<ItkImageType>(filter->GetOutput());
+      }
+      vv_image->SetTimeSpacing(input->GetSpacing()[Dim-1]);
+      vv_image->SetTimeOrigin(input->GetOrigin()[Dim-1]);
     }
     else //Dim == 1,2,3 and not time_sequence
     {
         vv_image->AddItkImage<InputImageType>(input);
     }
     return vv_image;
+  }
+};
+
+template<class PixelType>
+struct vvImageFromITK_Impl<4u, PixelType>
+{
+  static vvImage::Pointer Do (typename itk::Image<PixelType,4u>::Pointer input, bool time_sequence=false)
+  {
+    vvImage::Pointer vv_image=vvImage::New();
+    typedef itk::Image< PixelType, 4 > InputImageType;
+
+    typedef itk::Image< PixelType, 3 >    ItkImageType;
+    typedef itk::ExtractImageFilter<InputImageType, ItkImageType> FilterType;
+
+    //extract the 3D slices and put them in a std::vector<vtkImageData*>
+    input->UpdateOutputInformation();
+    typename InputImageType::RegionType inputRegion = input->GetLargestPossibleRegion();
+    typename InputImageType::SizeType inputSize = inputRegion.GetSize();
+    typename InputImageType::IndexType start = inputRegion.GetIndex();
+    typename InputImageType::SizeType extractedRegionSize = inputSize;
+    typename InputImageType::RegionType extractedRegion;
+    extractedRegionSize[3] = 0;
+    extractedRegion.SetSize(extractedRegionSize);
+
+    for (unsigned int i = 0; i < inputSize[3]; i++) {
+      start[3] = i;
+      extractedRegion.SetIndex(start);
+
+      typename FilterType::Pointer filter = FilterType::New();
+#if ITK_VERSION_MAJOR == 4
+      filter->SetDirectionCollapseToSubmatrix();
+#endif
+      filter->SetExtractionRegion(extractedRegion);
+      filter->SetInput(input);
+      filter->ReleaseDataFlagOn();
+      vv_image->AddItkImage<ItkImageType>(filter->GetOutput());
+    }
+    vv_image->SetTimeSpacing(input->GetSpacing()[3]);
+    vv_image->SetTimeOrigin(input->GetOrigin()[3]);
+    return vv_image;
+  }
+};
+
+template<unsigned int Dim, class PixelType> vvImage::Pointer vvImageFromITK(typename itk::Image<PixelType,Dim>::Pointer input, bool time_sequence=false)
+{
+    assert(Dim < 5 && Dim > 0); // We don't handle anything higher than 4-dimensional (for the moment :-p)
+    return vvImageFromITK_Impl<Dim, PixelType>::Do(input, time_sequence);
 }
 //------------------------------------------------------------------------------