1 /*=========================================================================
2 Program: vv http://www.creatis.insa-lyon.fr/rio/vv
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
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.
13 It is distributed under dual licence
15 - BSD See included LICENSE.txt file
16 - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
17 ===========================================================================*/
18 #include <itkImageToVTKImageFilter.h>
20 //--------------------------------------------------------------------
21 template<class TItkImageType>
22 void vvImage::AddItkImage(TItkImageType *input)
24 // Update input before conversion to enable exceptions thrown by the ITK pipeline.
25 // Otherwise, vtkImageImport catches the exception for us.
28 // Convert from ITK object to VTK object
29 mImageDimension = TItkImageType::ImageDimension;
30 typedef itk::ImageToVTKImageFilter <TItkImageType> ConverterType;
31 typename ConverterType::Pointer converter = ConverterType::New();
32 mItkToVtkConverters.push_back(dynamic_cast< itk::ProcessObject *>(converter.GetPointer()));
33 converter->SetInput(input);
35 mVtkImages.push_back( converter->GetOutput() );
37 // Account for direction in transform. The offset is already accounted for
38 // in the VTK image coordinates, no need to put it in the transform.
39 vtkSmartPointer<vtkMatrix4x4> matrix = vtkSmartPointer<vtkMatrix4x4>::New();
41 for(unsigned int i=0; i<input->GetImageDimension(); i++) {
42 for(unsigned int j=0; j<input->GetImageDimension(); j++) {
43 (*matrix)[i][j] = input->GetDirection()[i][j];
44 // Direction is used around the image origin in ITK
45 (*matrix)[i][3] -= (*matrix)[i][j] * input->GetOrigin()[j];
47 (*matrix)[i][3] += input->GetOrigin()[i];
50 // GetDirection provides the forward transform, vtkImageReslice wants the inverse
53 mTransform->SetMatrix(matrix);
55 //--------------------------------------------------------------------