1 /*=========================================================================
2 Program: vv http://www.creatis.insa-lyon.fr/rio/vv
5 - University of LYON http://www.universite-lyon.fr/
6 - Léon Bérard cancer center http://oncora1.lyon.fnclcc.fr
7 - CREATIS CNRS laboratory http://www.creatis.insa-lyon.fr
9 This software is distributed WITHOUT ANY WARRANTY; without even
10 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11 PURPOSE. See the copyright notices for more information.
13 It is distributed under dual licence
15 - BSD See included LICENSE.txt file
16 - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
17 ======================================================================-====*/
18 #ifndef VVIMAGEFROMITK_H
19 #define VVIMAGEFROMITK_H
25 #include <itkExtractImageFilter.h>
27 //------------------------------------------------------------------------------
28 /**Converts the itk image to vv, handling the 4D problem
29 * The time_sequence boolean specifies that the image is to be interpreted as a time sequence,
30 * even if its dim is < 4. */
31 template<unsigned int Dim, class PixelType> vvImage::Pointer vvImageFromITK(typename itk::Image<PixelType,Dim>::Pointer input, bool time_sequence=false)
33 assert(Dim < 5 && Dim > 0); // We don't handle anything higher than 4-dimensional (for the moment :-p)
34 vvImage::Pointer vv_image=vvImage::New();
35 typedef itk::Image< PixelType, Dim > InputImageType;
37 if (Dim == 4 || time_sequence) //The time sequence case: create a series of VTK images
39 typedef itk::Image< PixelType, Dim - 1 > ItkImageType;
40 typedef itk::ExtractImageFilter<InputImageType, ItkImageType> FilterType;
42 //extract the 3D slices and put them in a std::vector<vtkImageData*>
43 input->UpdateOutputInformation();
44 typename InputImageType::RegionType inputRegion = input->GetLargestPossibleRegion();
45 typename InputImageType::SizeType inputSize = inputRegion.GetSize();
46 typename InputImageType::IndexType start = inputRegion.GetIndex();
47 typename InputImageType::SizeType extractedRegionSize = inputSize;
48 typename InputImageType::RegionType extractedRegion;
49 extractedRegionSize[Dim - 1] = 0;
50 extractedRegion.SetSize(extractedRegionSize);
52 for (unsigned int i = 0; i < inputSize[Dim - 1]; i++) {
54 extractedRegion.SetIndex(start);
56 typename FilterType::Pointer filter = FilterType::New();
57 filter->SetExtractionRegion(extractedRegion);
58 filter->SetInput(input);
59 filter->ReleaseDataFlagOn();
60 vv_image->AddItkImage<ItkImageType>(filter->GetOutput());
62 vv_image->SetTimeSpacing(input->GetSpacing()[Dim-1]);
63 vv_image->SetTimeOrigin(input->GetOrigin()[Dim-1]);
65 else //Dim == 1,2,3 and not time_sequence
67 vv_image->AddItkImage<InputImageType>(input);
71 //------------------------------------------------------------------------------
73 #endif //vvImageFromITK