2 # ---------------------------------------------------------------------
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
6 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
7 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
8 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
10 # This software is governed by the CeCILL-B license under French law and
11 # abiding by the rules of distribution of free software. You can use,
12 # modify and/ or redistribute the software under the terms of the CeCILL-B
13 # license as circulated by CEA, CNRS and INRIA at the following URL
14 # http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
15 # or in the file LICENSE.txt.
17 # As a counterpart to the access to the source code and rights to copy,
18 # modify and redistribute granted by the license, users are provided only
19 # with a limited warranty and the software's author, the holder of the
20 # economic rights, and the successive licensors have only limited
23 # The fact that you are presently reading this means that you have had
24 # knowledge of the CeCILL-B license and that you accept its terms.
25 # ------------------------------------------------------------------------
28 #include "creaVtkFromVtk4DToItk4D.h"
30 #include "itkImageLinearConstIteratorWithIndex.h"
31 #include "itkImageRegionConstIterator.h"
32 #include "itkImageRegionIterator.h"
33 #include "itkImageFileReader.h"
36 template <class TImage>
37 creaVtkFromVtk4DToItk4D<TImage>::creaVtkFromVtk4DToItk4D()
41 template <class TImage>
42 creaVtkFromVtk4DToItk4D<TImage>::~creaVtkFromVtk4DToItk4D()
46 template <class TImage>
47 void creaVtkFromVtk4DToItk4D<TImage>::SetImage4D(TImage *image)
52 template <class TImage>
53 void creaVtkFromVtk4DToItk4D<TImage>::SetImage4Dvtk(std::vector<vtkImageData*> image)
58 template <class TImage>
59 std::vector<itk::Image< unsigned char > > creaVtkFromVtk4DToItk4D<TImage>::Process()
65 typedef itk::ImageLinearConstIteratorWithIndex< TImage > ConstIteratorType;
66 const unsigned int Dimension = 4;
67 typedef unsigned char PixelType;
68 typedef itk::Image< PixelType, Dimension > ImageType;
70 ConstIteratorType inputIt( _image4D, inputRegion );
71 inputIt.SetDirection(3);
74 ImageType::RegionType outputRegion;
75 ImageType::RegionType::IndexType outputStart;
78 outputRegion.SetSize( size );
79 outputRegion.SetIndex( outputStart );
81 while( !inputIt.IsAtEnd() )
83 inputIt.GoToBeginOfLine();
85 while( !inputIt.IsAtEndOfLine() )
87 pv[count] = inputIt.Get();
93 const unsigned int Dimension = 4;
94 typedef unsigned char PixelType;
95 typedef itk::Image< PixelType, Dimension > ImageType;
96 typedef itk::ImageRegionConstIterator< ImageType > ConstIteratorType;
97 typedef itk::ImageRegionIterator< ImageType> IteratorType;
99 //typedef itk::ImageFileReader< ImageType > ReaderType;
100 //typedef itk::ImageFileWriter< ImageType > WriterType;
102 ImageType::RegionType inputRegion;
103 ImageType::RegionType::IndexType inputStart;
104 ImageType::RegionType::SizeType size;
105 inputStart[0] = ::atoi( "20" );
106 inputStart[1] = ::atoi( "70" );
107 size[0] = ::atoi( "210" );
108 size[1] = ::atoi( "140" );
109 inputRegion.SetSize( size );
110 inputRegion.SetIndex( inputStart );
112 ImageType::RegionType outputRegion;
113 ImageType::RegionType::IndexType outputStart;
118 outputRegion.SetSize( size );
119 outputRegion.SetIndex( outputStart );
122 ReaderType::Pointer reader = ReaderType::New();
123 reader->SetFileName( "foo.vtk" );
128 catch ( itk::ExceptionObject &err)
130 std::cerr << "ExceptionObject caught !" << std::endl;
131 std::cerr << err << std::endl;
135 if ( ! reader->GetOutput()->GetRequestedRegion().IsInside( inputRegion ) )
137 std::cerr << "Error" << std::endl;
138 std::cerr << "The region " << inputRegion << "is not contained within the input image region "
139 << reader->GetOutput()->GetRequestedRegion() << std::endl;
142 std::vector<ImageType::Pointer> outputImage4D;
143 for(int k = 0 ; k < image4Dvtk.size() ; k++){
144 ImageType::Pointer outputImage = ImageType::New();
145 outputImage->SetRegions( outputRegion );
146 const ImageType::SpacingType& spacing = image4Dvtk[k]->GetSpacing();
147 const ImageType::PointType& inputOrigin = image4Dvtk[k]->GetOrigin();
148 double outputOrigin[ Dimension ];
149 for(unsigned int i=0; i< Dimension; i++)
151 outputOrigin[i] = inputOrigin[i] + spacing[i] * inputStart[i];
153 outputImage->SetSpacing( spacing );
154 outputImage->SetOrigin( outputOrigin );
155 outputImage->Allocate();
157 ConstIteratorType inputIt( image4Dvtk[k], inputRegion );
158 IteratorType outputIt( outputImage, outputRegion );
160 outputIt.GoToBegin();
162 while( !outputIt.IsAtEnd() )
164 outputIt.Set( inputIt.Get() );
168 outputImage4D[k]=outputImage;
170 return outputImage4D;
172 //---------------------------------------------
174 //---------------------------------------------
176 void creaVtkFromVtk4DToItk4D::FunctionName(int& parameterA)
178 parameterA = 2 * parameterA;