1 /*=========================================================================
4 Module: $RCSfile: vvToITK.h,v $
6 Date: $Date: 2010/01/06 13:32:01 $
7 Version: $Revision: 1.1 $
8 Author : Joel Schaerer (joel.schaerer@insa-lyon.fr)
11 Léon Bérard cancer center http://oncora1.lyon.fnclcc.fr
12 CREATIS-LRMN http://www.creatis.insa-lyon.fr
14 This program is free software: you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation, version 3 of the License.
18 This program is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
23 You should have received a copy of the GNU General Public License
24 along with this program. If not, see <http://www.gnu.org/licenses/>.
26 =========================================================================*/
27 #ifndef vvImageToITK_h
28 #define vvImageToITK_h
33 #include <itkJoinSeriesImageFilter.h>
34 #include "itkVTKImageToImageFilter.h"
36 ///Converts the vv image to itk, handling the 4D problem
37 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
39 assert(Dim < 5 && Dim > 1); // We don't handle anything higher than 4-dimensional (for the moment :-p)
40 assert(vv_image->GetVTKImages().size() > 0); //we assume there is something to convert
41 typedef itk::Image< PixelType, Dim > OutputImageType;
42 std::vector<typename itk::Image<PixelType,Dim>::ConstPointer> result;
44 typedef itk::Image< PixelType, Dim > ConnectorImageType;
45 typedef itk::VTKImageToImageFilter<ConnectorImageType> ConnectorType;
46 for (unsigned int i = 0; i < vv_image->GetVTKImages().size(); i++)
48 typename ConnectorType::Pointer connector = ConnectorType::New();
49 connector->SetInput(vv_image->GetVTKImages()[i]);
51 result.push_back(connector->GetOutput());
56 ///Converts the vv image to itk, handling the 4D problem
57 template<class ImageType> typename ImageType::ConstPointer vvImageToITK(vvImage::Pointer vv_image) ///Converts the vv image to itk, handling the 4D problem
59 const unsigned int Dim=ImageType::ImageDimension;
60 assert(Dim < 5 && Dim > 0); // We don't handle anything higher than 4-dimensional (for the moment :-p)
61 typedef ImageType OutputImageType;
65 typedef itk::Image< typename ImageType::PixelType, 3 > ConnectorImageType;
66 typedef itk::VTKImageToImageFilter<ConnectorImageType> ConnectorType;
67 typedef itk::JoinSeriesImageFilter<ConnectorImageType,OutputImageType> FilterType;
70 typename FilterType::Pointer filter = FilterType::New();
71 filter->SetOrigin(vv_image->GetOrigin()[3]);
72 filter->SetSpacing(vv_image->GetSpacing()[3]);
74 for (int i = 0; i < vv_image->GetSize()[3]; i++)
76 typename ConnectorType::Pointer connector = ConnectorType::New();
77 connector->SetInput(vv_image->GetVTKImages()[i]);
79 filter->PushBackInput(connector->GetOutput());
82 return filter->GetOutput();
86 assert(not vv_image->IsTimeSequence()); //This case isn't implemented
87 typedef ImageType ConnectorImageType;
88 typedef itk::VTKImageToImageFilter <ConnectorImageType> ConnectorType;
89 typename ConnectorType::Pointer connector = ConnectorType::New();
90 connector->SetInput(vv_image->GetVTKImages()[0]);
93 return connector->GetOutput();
97 ///Converts a single time frame of a vv image to itk.
98 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
100 assert(Dim < 4 && Dim > 0);
101 typedef itk::Image< PixelType, Dim > OutputImageType;
102 typedef itk::Image< PixelType, Dim > ConnectorImageType;
103 typedef itk::VTKImageToImageFilter <ConnectorImageType> ConnectorType;
104 typename ConnectorType::Pointer connector = ConnectorType::New();
105 connector->SetInput(vv_image->GetVTKImages()[frame]);
107 return connector->GetOutput();