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]);
93 return connector->GetOutput();
96 //--------------------------------------------------------------------
99 //--------------------------------------------------------------------
100 ///Converts a single time frame of a vv image to itk.
101 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
103 assert(Dim < 4 && Dim > 0);
104 typedef itk::Image< PixelType, Dim > OutputImageType;
105 typedef itk::Image< PixelType, Dim > ConnectorImageType;
106 typedef itk::VTKImageToImageFilter <ConnectorImageType> ConnectorType;
107 typename ConnectorType::Pointer connector = ConnectorType::New();
108 connector->SetInput(vv_image->GetVTKImages()[frame]);
110 return connector->GetOutput();
112 //--------------------------------------------------------------------
115 //--------------------------------------------------------------------
116 template<unsigned int Dim, class PixelType>
117 typename itk::Image<PixelType,Dim>::ConstPointer
118 ItkImageFromVtk(vtkImageData * input)
120 typedef itk::Image< PixelType, Dim > OutputImageType;
121 typedef itk::Image< PixelType, Dim > ConnectorImageType;
122 typedef itk::VTKImageToImageFilter <ConnectorImageType> ConnectorType;
123 typename ConnectorType::Pointer connector = ConnectorType::New();
124 connector->SetInput(input);
126 return connector->GetOutput();
128 //--------------------------------------------------------------------