From: Vivien Delmon Date: Tue, 3 May 2011 14:44:00 +0000 (+0200) Subject: Prevent vv from instantiated 4D vvImage. X-Git-Tag: v1.2.0~4 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=d5a2dc4d106f7c63c7f3a42b47e7466b7eb4fe0f;p=clitk.git Prevent vv from instantiated 4D vvImage. * 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. --- diff --git a/common/vvFromITK.h b/common/vvFromITK.h index c089816..d4232b1 100644 --- a/common/vvFromITK.h +++ b/common/vvFromITK.h @@ -28,48 +28,97 @@ /**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 vvImage::Pointer vvImageFromITK(typename itk::Image::Pointer input, bool time_sequence=false) + +template +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::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 FilterType; - - //extract the 3D slices and put them in a std::vector - 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 FilterType; + + //extract the 3D slices and put them in a std::vector + 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(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(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(input); } return vv_image; + } +}; + +template +struct vvImageFromITK_Impl<4u, PixelType> +{ + static vvImage::Pointer Do (typename itk::Image::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 FilterType; + + //extract the 3D slices and put them in a std::vector + 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(filter->GetOutput()); + } + vv_image->SetTimeSpacing(input->GetSpacing()[3]); + vv_image->SetTimeOrigin(input->GetOrigin()[3]); + return vv_image; + } +}; + +template vvImage::Pointer vvImageFromITK(typename itk::Image::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::Do(input, time_sequence); } //------------------------------------------------------------------------------