]> Creatis software - clitk.git/blob - common/vvImage.txx
43631f6138adfbac36fcab5fcc5704a1a73f6dae
[clitk.git] / common / vvImage.txx
1 #include <itkImageToVTKImageFilter.h>
2
3 //--------------------------------------------------------------------
4 template<class TItkImageType>
5 void vvImage::AddItkImage(TItkImageType *input)
6 {
7   // Update input before conversion to enable exceptions thrown by the ITK pipeline.
8   // Otherwise, vtkImageImport catches the exception for us.
9   input->Update();
10
11   // Convert from ITK object to VTK object
12   mImageDimension = TItkImageType::ImageDimension; 
13   typedef itk::ImageToVTKImageFilter <TItkImageType> ConverterType;
14   typename ConverterType::Pointer converter = ConverterType::New();
15   mItkToVtkConverters.push_back(dynamic_cast< itk::ProcessObject *>(converter.GetPointer()));
16   converter->SetInput(input);
17   converter->Update();
18   mVtkImages.push_back( converter->GetOutput() );
19   
20   // Account for direction in transform. The offset is already accounted for
21   // in the VTK image coordinates, no need to put it in the transform.
22   vtkSmartPointer<vtkMatrix4x4> matrix = vtkSmartPointer<vtkMatrix4x4>::New();
23   matrix->Identity();
24   for(unsigned int j=0; j<input->GetImageDimension(); j++)
25     for(unsigned int i=0; i<input->GetImageDimension(); i++)
26       (*matrix)[i][j] = input->GetDirection()[i][j];
27   mTransform->SetMatrix(matrix);
28 }
29 //--------------------------------------------------------------------
30