]> Creatis software - clitk.git/blob - common/vvImage.txx
90eeb02338e21408be4854687b1ab5969ef1febc
[clitk.git] / common / vvImage.txx
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 #include <itkImageToVTKImageFilter.h>
19
20 //--------------------------------------------------------------------
21 template<class TItkImageType>
22 void vvImage::AddItkImage(TItkImageType *input)
23 {
24   // Update input before conversion to enable exceptions thrown by the ITK pipeline.
25   // Otherwise, vtkImageImport catches the exception for us.
26   input->Update();
27
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);
34   converter->Update();
35   mVtkImages.push_back( converter->GetOutput() );
36
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();
40   matrix->Identity();
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];
46     }
47     (*matrix)[i][3] += input->GetOrigin()[i];
48   }
49
50   mTransform->SetMatrix(matrix);
51 }
52 //--------------------------------------------------------------------
53