- for(unsigned int j=0; j<input->GetImageDimension(); j++)
- for(unsigned int i=0; i<input->GetImageDimension(); i++)
- mTransform->GetMatrix()->SetElement(i,j, input->GetDirection()[i][j]);
-
- // Create the corresponding transformed image
- mVtkImageReslice.push_back(vtkSmartPointer<vtkImageReslice>::New());
- mVtkImageReslice.back()->SetInterpolationModeToLinear();
- mVtkImageReslice.back()->AutoCropOutputOn();
- mVtkImageReslice.back()->SetBackgroundColor(-1000,-1000,-1000,1);
- mVtkImageReslice.back()->SetResliceTransform(mTransform);
- mVtkImageReslice.back()->SetInput(0, converter->GetOutput());
- mVtkImageReslice.back()->UpdateInformation();
- mTransformedVtkImages.push_back( mVtkImageReslice.back()->GetOutput(0) );
+ vtkSmartPointer<vtkMatrix4x4> matrix = vtkSmartPointer<vtkMatrix4x4>::New();
+ matrix->Identity();
+ for(unsigned int i=0; i<input->GetImageDimension(); i++) {
+ for(unsigned int j=0; j<input->GetImageDimension(); j++) {
+ (*matrix)[i][j] = input->GetDirection()[i][j];
+ // Direction is used around the image origin in ITK
+ (*matrix)[i][3] -= (*matrix)[i][j] * input->GetOrigin()[j];
+ }
+ (*matrix)[i][3] += input->GetOrigin()[i];
+ }
+
+ // GetDirection provides the forward transform, vtkImageReslice wants the inverse
+ matrix->Invert();
+
+ mTransform.push_back(vtkSmartPointer<vtkTransform>::New());
+ mTransform.back()->SetMatrix(matrix);