]> Creatis software - clitk.git/blob - common/vvImage.txx
Conversion from itk to vtk was catching exceptions for us => update itk pipeline...
[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   // Create the corresponding transformed image
30   mVtkImageReslice.push_back(vtkSmartPointer<vtkImageReslice>::New());
31   mVtkImageReslice.back()->SetInterpolationModeToLinear();
32   mVtkImageReslice.back()->AutoCropOutputOn();
33   mVtkImageReslice.back()->SetBackgroundColor(-1000,-1000,-1000,1);
34   mVtkImageReslice.back()->SetResliceTransform(mTransform);
35   mVtkImageReslice.back()->SetInput(0, converter->GetOutput());
36   mVtkImageReslice.back()->UpdateInformation();
37   mTransformedVtkImages.push_back( mVtkImageReslice.back()->GetOutput(0) );
38 }
39 //--------------------------------------------------------------------
40