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 vvImageToITK_h
19 #define vvImageToITK_h
23 #include <itkJoinSeriesImageFilter.h>
24 #include "itkVTKImageToImageFilter.h"
26 ///Converts the vv image to itk, handling the 4D problem
27 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
29 assert(Dim < 5 && Dim > 1); // We don't handle anything higher than 4-dimensional (for the moment :-p)
30 assert(vv_image->GetVTKImages().size() > 0); //we assume there is something to convert
31 typedef itk::Image< PixelType, Dim > OutputImageType;
32 std::vector<typename itk::Image<PixelType,Dim>::ConstPointer> result;
34 typedef itk::Image< PixelType, Dim > ConnectorImageType;
35 typedef itk::VTKImageToImageFilter<ConnectorImageType> ConnectorType;
36 for (unsigned int i = 0; i < vv_image->GetVTKImages().size(); i++)
38 typename ConnectorType::Pointer connector = ConnectorType::New();
39 connector->SetInput(vv_image->GetVTKImages()[i]);
41 result.push_back(connector->GetOutput());
46 ///Converts the vv image to itk, handling the 4D problem
47 template<class ImageType> typename ImageType::ConstPointer vvImageToITK(vvImage::Pointer vv_image) ///Converts the vv image to itk, handling the 4D problem
49 const unsigned int Dim=ImageType::ImageDimension;
50 assert(Dim < 5 && Dim > 0); // We don't handle anything higher than 4-dimensional (for the moment :-p)
51 typedef ImageType OutputImageType;
55 typedef itk::Image< typename ImageType::PixelType, 3 > ConnectorImageType;
56 typedef itk::VTKImageToImageFilter<ConnectorImageType> ConnectorType;
57 typedef itk::JoinSeriesImageFilter<ConnectorImageType,OutputImageType> FilterType;
60 typename FilterType::Pointer filter = FilterType::New();
61 filter->SetOrigin(vv_image->GetOrigin()[3]);
62 filter->SetSpacing(vv_image->GetSpacing()[3]);
64 for (int i = 0; i < vv_image->GetSize()[3]; i++)
66 typename ConnectorType::Pointer connector = ConnectorType::New();
67 connector->SetInput(vv_image->GetVTKImages()[i]);
69 filter->PushBackInput(connector->GetOutput());
72 return filter->GetOutput();
76 assert(!vv_image->IsTimeSequence()); //This case isn't implemented
77 typedef ImageType ConnectorImageType;
78 typedef itk::VTKImageToImageFilter <ConnectorImageType> ConnectorType;
79 typename ConnectorType::Pointer connector = ConnectorType::New();
80 connector->SetInput(vv_image->GetVTKImages()[0]);
83 return connector->GetOutput();
87 ///Converts a single time frame of a vv image to itk.
88 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
90 assert(Dim < 4 && Dim > 0);
91 typedef itk::Image< PixelType, Dim > OutputImageType;
92 typedef itk::Image< PixelType, Dim > ConnectorImageType;
93 typedef itk::VTKImageToImageFilter <ConnectorImageType> ConnectorType;
94 typename ConnectorType::Pointer connector = ConnectorType::New();
95 connector->SetInput(vv_image->GetVTKImages()[frame]);
97 return connector->GetOutput();