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 ======================================================================-====*/
19 #ifndef VVIMAGETOITK_H
20 #define VVIMAGETOITK_H
30 #include <itkJoinSeriesImageFilter.h>
31 #include "itkVTKImageToImageFilter.h"
33 //--------------------------------------------------------------------
34 ///Converts the vv image to itk, handling the 4D problem
35 template<unsigned int Dim, class PixelType> std::vector<typename itk::Image<PixelType,Dim>::ConstPointer> vvImageToITKImageVector(vvImage::Pointer vv_image) ///Converts the vv image to itk, handling the 4D problem
37 assert(Dim < 5 && Dim > 1); // We don't handle anything higher than 4-dimensional (for the moment :-p)
38 assert(vv_image->GetVTKImages().size() > 0); //we assume there is something to convert
39 typedef itk::Image< PixelType, Dim > OutputImageType;
40 std::vector<typename itk::Image<PixelType,Dim>::ConstPointer> result;
42 typedef itk::Image< PixelType, Dim > ConnectorImageType;
43 typedef itk::VTKImageToImageFilter<ConnectorImageType> ConnectorType;
44 for (unsigned int i = 0; i < vv_image->GetVTKImages().size(); i++)
46 typename ConnectorType::Pointer connector = ConnectorType::New();
47 connector->SetInput(vv_image->GetVTKImages()[i]);
49 result.push_back(connector->GetOutput());
53 //--------------------------------------------------------------------
56 //--------------------------------------------------------------------
57 ///Converts the vv image to itk, handling the 4D problem
58 template<class ImageType> typename ImageType::ConstPointer vvImageToITK(vvImage::Pointer vv_image) ///Converts the vv image to itk, handling the 4D problem
60 const unsigned int Dim=ImageType::ImageDimension;
61 assert(Dim < 5 && Dim > 0); // We don't handle anything higher than 4-dimensional (for the moment :-p)
62 typedef ImageType OutputImageType;
66 typedef itk::Image< typename ImageType::PixelType, 3 > ConnectorImageType;
67 typedef itk::VTKImageToImageFilter<ConnectorImageType> ConnectorType;
68 typedef itk::JoinSeriesImageFilter<ConnectorImageType,OutputImageType> FilterType;
71 typename FilterType::Pointer filter = FilterType::New();
72 filter->SetOrigin(vv_image->GetOrigin()[3]);
73 filter->SetSpacing(vv_image->GetSpacing()[3]);
75 for (int i = 0; i < vv_image->GetSize()[3]; i++)
77 typename ConnectorType::Pointer connector = ConnectorType::New();
78 connector->SetInput(vv_image->GetVTKImages()[i]);
80 filter->PushBackInput(connector->GetOutput());
83 return filter->GetOutput();
87 assert(!vv_image->IsTimeSequence()); //This case isn't implemented
88 typedef ImageType ConnectorImageType;
89 typedef itk::VTKImageToImageFilter <ConnectorImageType> ConnectorType;
90 typename ConnectorType::Pointer connector = ConnectorType::New();
91 connector->SetInput(vv_image->GetVTKImages()[0]);
94 return connector->GetOutput();
97 //--------------------------------------------------------------------
100 //--------------------------------------------------------------------
101 ///Converts a single time frame of a vv image to itk.
102 template<unsigned int Dim, class PixelType> typename itk::Image<PixelType,Dim>::ConstPointer vvSingleFrameToITK(vvImage::Pointer vv_image,int frame) ///Converts the vv image to itk, handling the 4D problem
104 assert(Dim < 4 && Dim > 0);
105 typedef itk::Image< PixelType, Dim > OutputImageType;
106 typedef itk::Image< PixelType, Dim > ConnectorImageType;
107 typedef itk::VTKImageToImageFilter <ConnectorImageType> ConnectorType;
108 typename ConnectorType::Pointer connector = ConnectorType::New();
109 connector->SetInput(vv_image->GetVTKImages()[frame]);
111 return connector->GetOutput();
113 //--------------------------------------------------------------------
116 //--------------------------------------------------------------------
117 template<unsigned int Dim, class PixelType>
118 typename itk::Image<PixelType,Dim>::ConstPointer
119 ItkImageFromVtk(vtkImageData * input)
121 typedef itk::Image< PixelType, Dim > OutputImageType;
122 typedef itk::Image< PixelType, Dim > ConnectorImageType;
123 typedef itk::VTKImageToImageFilter <ConnectorImageType> ConnectorType;
124 typename ConnectorType::Pointer connector = ConnectorType::New();
125 connector->SetInput(input);
127 return connector->GetOutput();
129 //--------------------------------------------------------------------