From 13408338a1ef8779be07f538aacb787683aa5ddb Mon Sep 17 00:00:00 2001 From: Simon Rit Date: Thu, 23 Jun 2011 13:16:58 +0200 Subject: [PATCH] Account for itk origin when using itk direction to build vv transform --- common/vvImage.txx | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/common/vvImage.txx b/common/vvImage.txx index 6e89076..90eeb02 100644 --- a/common/vvImage.txx +++ b/common/vvImage.txx @@ -26,21 +26,27 @@ void vvImage::AddItkImage(TItkImageType *input) input->Update(); // Convert from ITK object to VTK object - mImageDimension = TItkImageType::ImageDimension; + mImageDimension = TItkImageType::ImageDimension; typedef itk::ImageToVTKImageFilter ConverterType; typename ConverterType::Pointer converter = ConverterType::New(); mItkToVtkConverters.push_back(dynamic_cast< itk::ProcessObject *>(converter.GetPointer())); converter->SetInput(input); converter->Update(); mVtkImages.push_back( converter->GetOutput() ); - + // Account for direction in transform. The offset is already accounted for // in the VTK image coordinates, no need to put it in the transform. vtkSmartPointer matrix = vtkSmartPointer::New(); matrix->Identity(); - for(unsigned int j=0; jGetImageDimension(); j++) - for(unsigned int i=0; iGetImageDimension(); i++) + for(unsigned int i=0; iGetImageDimension(); i++) { + for(unsigned int j=0; jGetImageDimension(); 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]; + } + mTransform->SetMatrix(matrix); } //-------------------------------------------------------------------- -- 2.47.1