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"
29 //#include "itkImage.h"
31 //#include <itkImageRegionConstIteratorWithIndex.h>
34 //#include "itkImageRegionConstIterator.h"
35 #include "itkImageRegionIterator.h"
36 // #include "itkImageFileReader.h"
39 //template <class TImage>
40 //creaVtkFromVtk4DToItk4D<TImage>::creaVtkFromVtk4DToItk4D()
41 creaVtkFromVtk4DToItk4D::creaVtkFromVtk4DToItk4D()
45 //EED template <class TImage>
46 //EED creaVtkFromVtk4DToItk4D<TImage>::~creaVtkFromVtk4DToItk4D()
47 creaVtkFromVtk4DToItk4D::~creaVtkFromVtk4DToItk4D()
51 //EED template <class TImage>
52 //EED void creaVtkFromVtk4DToItk4D<TImage>::SetImage4D(TImage *image)
54 //EED _image4D = image;
58 Image4DType::Pointer creaVtkFromVtk4DToItk4D::GetResult()
64 //EED template <class TImage>
65 //EED void creaVtkFromVtk4DToItk4D<TImage>::SetImage4Dvtk( std::vector<vtkImageData*> image)
66 void creaVtkFromVtk4DToItk4D::SetImage4Dvtk( std::vector<vtkImageData*> image)
71 //EED template <class TImage>
72 //EED std::vector<itk::Image< unsigned char > > creaVtkFromVtk4DToItk4D<TImage>::Process()
73 void creaVtkFromVtk4DToItk4D::Process()
79 typedef itk::ImageLinearConstIteratorWithIndex< TImage > ConstIteratorType;
80 const unsigned int Dimension = 4;
81 typedef unsigned char PixelType;
82 typedef itk::Image< PixelType, Dimension > ImageType;
84 ConstIteratorType inputIt( _image4D, inputRegion );
85 inputIt.SetDirection(3);
88 ImageType::RegionType outputRegion;
89 ImageType::RegionType::IndexType outputStart;
92 outputRegion.SetSize( size );
93 outputRegion.SetIndex( outputStart );
95 while( !inputIt.IsAtEnd() )
97 inputIt.GoToBeginOfLine();
99 while( !inputIt.IsAtEndOfLine() )
101 pv[count] = inputIt.Get();
110 const unsigned int Dimension = 4;
111 typedef unsigned char PixelType;
112 typedef itk::Image< PixelType, Dimension > ImageType;
113 typedef itk::ImageRegionConstIterator< ImageType > ConstIteratorType;
114 typedef itk::ImageRegionIterator< ImageType> IteratorType;
116 //typedef itk::ImageFileReader< ImageType > ReaderType;
117 //typedef itk::ImageFileWriter< ImageType > WriterType;
119 ImageType::RegionType inputRegion;
120 ImageType::RegionType::IndexType inputStart;
121 ImageType::RegionType::SizeType size;
122 inputStart[0] = ::atoi( "20" );
123 inputStart[1] = ::atoi( "70" );
124 size[0] = ::atoi( "210" );
125 size[1] = ::atoi( "140" );
126 inputRegion.SetSize( size );
127 inputRegion.SetIndex( inputStart );
129 ImageType::RegionType outputRegion;
130 ImageType::RegionType::IndexType outputStart;
135 outputRegion.SetSize( size );
136 outputRegion.SetIndex( outputStart );
140 ReaderType::Pointer reader = ReaderType::New();
141 reader->SetFileName( "foo.vtk" );
146 catch ( itk::ExceptionObject &err)
148 std::cerr << "ExceptionObject caught !" << std::endl;
149 std::cerr << err << std::endl;
153 if ( ! reader->GetOutput()->GetRequestedRegion().IsInside( inputRegion ) )
155 std::cerr << "Error" << std::endl;
156 std::cerr << "The region " << inputRegion << "is not contained within the input image region "
157 << reader->GetOutput()->GetRequestedRegion() << std::endl;
164 std::vector<ImageType::Pointer> outputImage4D;
165 for(int k = 0 ; k < _image4Dvtk.size() ; k++)
167 ImageType::Pointer outputImage = ImageType::New();
168 outputImage->SetRegions( outputRegion );
169 const ImageType::SpacingType& spacing = _image4Dvtk[k]->GetSpacing();
170 const ImageType::PointType& inputOrigin = _image4Dvtk[k]->GetOrigin();
171 double outputOrigin[ Dimension ];
172 for(unsigned int i=0; i< Dimension; i++)
174 outputOrigin[i] = inputOrigin[i] + spacing[i] * inputStart[i];
176 outputImage->SetSpacing( spacing );
177 outputImage->SetOrigin( outputOrigin );
178 outputImage->Allocate();
180 ConstIteratorType inputIt( _image4Dvtk[k], inputRegion );
181 IteratorType outputIt( outputImage, outputRegion );
183 outputIt.GoToBegin();
185 while( !outputIt.IsAtEnd() )
187 outputIt.Set( inputIt.Get() );
191 //EED outputImage4D[k]=outputImage;
193 //EED return outputImage4D;
199 // http://www.itk.org/pipermail/insight-users/2003-December/005796.html
200 // http://www.itk.org/Wiki/ITK/Examples/ImageProcessing/InvertIntensityImageFilter
204 int dimX, dimY, dimZ;
208 _image4Dvtk[0]->GetWholeExtent(ext);
209 dimX = ext[1]-ext[0]+1;
210 dimY = ext[3]-ext[2]+1;
211 dimZ = ext[5]-ext[4]+1;
212 sizeimage = dimX*dimY*dimZ;
216 typedef itk::ImageRegionIterator< Image4DType > Iterator4D;
217 // typedef itk::ImageRegionConstIterator< Image4DType > Iterator4D;
218 // typedef itk::ImageRegionConstIteratorWithIndex< Image4DType > Iterator4D;
221 _image4D = Image4DType::New();
223 Image4DType::RegionType region;
224 Image4DType::IndexType start;
230 Image4DType::SizeType size;
231 unsigned int NumRows = dimX;
232 unsigned int NumCols = dimY;
233 unsigned int NumSlices = dimZ;
234 unsigned int NumVolumes = _image4Dvtk.size();
238 size[3] = NumVolumes;
240 region.SetSize(size);
241 region.SetIndex(start);
243 _image4D->SetRegions(region);
244 _image4D->Allocate();
247 // Iterator4D it4( image4D, image4D->GetBufferedRegion() );
248 Iterator4D it4( _image4D, _image4D->GetLargestPossibleRegion() );
250 for(k = 0 ; k < _image4Dvtk.size() ; k++)
252 unsigned short * ptrVtkImage;
253 ptrVtkImage = (unsigned short *)_image4Dvtk[k]->GetScalarPointer();
254 for (i=0; i< sizeimage;i++)
256 it4.Set( *ptrVtkImage );
257 // *it4 = *ptrVtkImage;
258 // unsigned short q= it4.Get();
264 //---------------------------------------------
266 //---------------------------------------------
268 void creaVtkFromVtk4DToItk4D::FunctionName(int& parameterA)
270 parameterA = 2 * parameterA;