From f727a96168c31de8ec613a9d57273f2ad7e11a70 Mon Sep 17 00:00:00 2001 From: srit Date: Tue, 15 Mar 2011 16:59:53 +0000 Subject: [PATCH] Romulo: invert matrix in .mat to be consistent with mhd matrices handled by itk --- vv/vvImageReader.cxx | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/vv/vvImageReader.cxx b/vv/vvImageReader.cxx index 593ef70..25e235a 100644 --- a/vv/vvImageReader.cxx +++ b/vv/vvImageReader.cxx @@ -173,8 +173,27 @@ void vvImageReader::ReadMatImageTransform() for(int i=0; i<4; i++) matrix->SetElement(j,i,itkMat[j][i]); + // RP: 14/03/2011 + // For some reason, the transformation matrix given in the MHD + // file is inverted wrt the transformation given in the MAT file. + // We don't really know where the inversion takes place inside + // VTK or ITK. For what we could see in VV, the transformation + // given in the MHD file seems "more correct" than that given in + // the MAT file. For this reason, we invert the matrix read from + // the MAT file before concatenating it to the current transformation. + // Still, it would be nice to find out what happens exactly between + // VTK and ITK... + // + vtkSmartPointer inv_matrix = vtkSmartPointer::New(); + if (matrix->Determinant() == 0) + { + vtkGenericWarningMacro("Matrix in " << filename.c_str() << " cannot be inverted (determinant = 0)"); + } + else + matrix->Invert(*matrix, *inv_matrix); + mImage->GetTransform()->PostMultiply(); - mImage->GetTransform()->Concatenate(matrix); + mImage->GetTransform()->Concatenate(inv_matrix); mImage->GetTransform()->Update(); } } -- 2.47.1