1 #include <itkImageToVTKImageFilter.h>
3 //--------------------------------------------------------------------
4 template<class TItkImageType>
5 void vvImage::AddItkImage(TItkImageType *input)
7 // Update input before conversion to enable exceptions thrown by the ITK pipeline.
8 // Otherwise, vtkImageImport catches the exception for us.
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);
18 mVtkImages.push_back( converter->GetOutput() );
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();
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);
29 //--------------------------------------------------------------------