1 /*=========================================================================
5 Author : Joel Schaerer (joel.schaerer@insa-lyon.fr)
8 Léon Bérard cancer center http://oncora1.lyon.fnclcc.fr
9 CREATIS-LRMN http://www.creatis.insa-lyon.fr
11 This program is free software: you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation, version 3 of the License.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program. If not, see <http://www.gnu.org/licenses/>.
23 =========================================================================*/
24 #ifndef vvImageToITK_h
25 #define vvImageToITK_h
30 #include <itkJoinSeriesImageFilter.h>
31 #include "itkVTKImageToImageFilter.h"
33 ///Converts the vv image to itk, handling the 4D problem
34 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
36 assert(Dim < 5 && Dim > 1); // We don't handle anything higher than 4-dimensional (for the moment :-p)
37 assert(vv_image->GetVTKImages().size() > 0); //we assume there is something to convert
38 typedef itk::Image< PixelType, Dim > OutputImageType;
39 std::vector<typename itk::Image<PixelType,Dim>::ConstPointer> result;
41 typedef itk::Image< PixelType, Dim > ConnectorImageType;
42 typedef itk::VTKImageToImageFilter<ConnectorImageType> ConnectorType;
43 for (unsigned int i = 0; i < vv_image->GetVTKImages().size(); i++)
45 typename ConnectorType::Pointer connector = ConnectorType::New();
46 connector->SetInput(vv_image->GetVTKImages()[i]);
48 result.push_back(connector->GetOutput());
53 ///Converts the vv image to itk, handling the 4D problem
54 template<class ImageType> typename ImageType::ConstPointer vvImageToITK(vvImage::Pointer vv_image) ///Converts the vv image to itk, handling the 4D problem
56 const unsigned int Dim=ImageType::ImageDimension;
57 assert(Dim < 5 && Dim > 0); // We don't handle anything higher than 4-dimensional (for the moment :-p)
58 typedef ImageType OutputImageType;
62 typedef itk::Image< typename ImageType::PixelType, 3 > ConnectorImageType;
63 typedef itk::VTKImageToImageFilter<ConnectorImageType> ConnectorType;
64 typedef itk::JoinSeriesImageFilter<ConnectorImageType,OutputImageType> FilterType;
67 typename FilterType::Pointer filter = FilterType::New();
68 filter->SetOrigin(vv_image->GetOrigin()[3]);
69 filter->SetSpacing(vv_image->GetSpacing()[3]);
71 for (int i = 0; i < vv_image->GetSize()[3]; i++)
73 typename ConnectorType::Pointer connector = ConnectorType::New();
74 connector->SetInput(vv_image->GetVTKImages()[i]);
76 filter->PushBackInput(connector->GetOutput());
79 return filter->GetOutput();
83 assert(not vv_image->IsTimeSequence()); //This case isn't implemented
84 typedef ImageType ConnectorImageType;
85 typedef itk::VTKImageToImageFilter <ConnectorImageType> ConnectorType;
86 typename ConnectorType::Pointer connector = ConnectorType::New();
87 connector->SetInput(vv_image->GetVTKImages()[0]);
90 return connector->GetOutput();
94 ///Converts a single time frame of a vv image to itk.
95 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
97 assert(Dim < 4 && Dim > 0);
98 typedef itk::Image< PixelType, Dim > OutputImageType;
99 typedef itk::Image< PixelType, Dim > ConnectorImageType;
100 typedef itk::VTKImageToImageFilter <ConnectorImageType> ConnectorType;
101 typename ConnectorType::Pointer connector = ConnectorType::New();
102 connector->SetInput(vv_image->GetVTKImages()[frame]);
104 return connector->GetOutput();