]> Creatis software - clitk.git/blob - common/vvToITK.h
Put back and refactored manual rigid registration
[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://www.centreleonberard.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       connector->Update();
93       return connector->GetOutput();
94     }
95 }
96 //--------------------------------------------------------------------
97
98
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
102 {
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]);
109   connector->Update();
110   return connector->GetOutput();
111 }
112 //--------------------------------------------------------------------
113
114
115 //--------------------------------------------------------------------
116 template<unsigned int Dim, class PixelType> 
117 typename itk::Image<PixelType,Dim>::ConstPointer 
118 ItkImageFromVtk(vtkImageData * input)
119 {
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);
125   connector->Update();
126   return connector->GetOutput();
127 }
128 //--------------------------------------------------------------------
129
130
131
132 #endif