]> Creatis software - clitk.git/blob - common/vvToITK.h
Removed vtkGridTransform and turned off vtkImageReslice with a define
[clitk.git] / common / vvToITK.h
1 /*=========================================================================
2   Program:   vv                     http://www.creatis.insa-lyon.fr/rio/vv
3
4   Authors belong to: 
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
8
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.
12
13   It is distributed under dual licence
14
15   - BSD        See included LICENSE.txt file
16   - CeCILL-B   http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
17   ======================================================================-====*/
18
19 #ifndef VVIMAGETOITK_H
20 #define VVIMAGETOITK_H
21
22 // std
23 #include <vector>
24
25 // vv
26 #include "vvImage.h"
27
28 // itk
29 #include <itkImage.h>
30 #include <itkJoinSeriesImageFilter.h>
31 #include "itkVTKImageToImageFilter.h"
32
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
36 {
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;
41
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++)
45     {
46       typename ConnectorType::Pointer connector = ConnectorType::New();
47       connector->SetInput(vv_image->GetVTKImages()[i]);
48       connector->Update();
49       result.push_back(connector->GetOutput());
50     }
51   return result;
52 }
53 //--------------------------------------------------------------------
54
55
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
59 {
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;
63
64   if (Dim==4)
65     {
66       typedef itk::Image< typename ImageType::PixelType,  3 >    ConnectorImageType;
67       typedef itk::VTKImageToImageFilter<ConnectorImageType> ConnectorType;
68       typedef itk::JoinSeriesImageFilter<ConnectorImageType,OutputImageType> FilterType;
69
70
71       typename FilterType::Pointer filter = FilterType::New();
72       filter->SetOrigin(vv_image->GetOrigin()[3]);
73       filter->SetSpacing(vv_image->GetSpacing()[3]);
74
75       for (int i = 0; i < vv_image->GetSize()[3]; i++)
76         {
77           typename ConnectorType::Pointer connector = ConnectorType::New();
78           connector->SetInput(vv_image->GetVTKImages()[i]);
79           connector->Update();
80           filter->PushBackInput(connector->GetOutput());
81         }
82       filter->Update();
83       return filter->GetOutput();
84     }
85   else //Dim == 1,2,3
86     {
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]);
92
93       connector->Update();
94       return connector->GetOutput();
95     }
96 }
97 //--------------------------------------------------------------------
98
99
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
103 {
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]);
110   connector->Update();
111   return connector->GetOutput();
112 }
113 //--------------------------------------------------------------------
114
115
116 //--------------------------------------------------------------------
117 template<unsigned int Dim, class PixelType> 
118 typename itk::Image<PixelType,Dim>::ConstPointer 
119 ItkImageFromVtk(vtkImageData * input)
120 {
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);
126   connector->Update();
127   return connector->GetOutput();
128 }
129 //--------------------------------------------------------------------
130
131
132
133 #endif