Commit 6b1a4de8 authored by pieper's avatar pieper

BUG: handle special case for RotateToVolumePlane - Issue #2852

Avoid a degenerate transform by checking for null column
and replacing it with the cross product.  This can happen
when the ijkToRAS transform is not uniquely aligned with the
cardinal axes and the algorithm to determine the correspondence
between volume axes and patient axes fails.

git-svn-id: http://svn.slicer.org/Slicer4/trunk@21564 3bd1e089-480b-0410-8dfb-8563597acbee
parent a5aaabeb
......@@ -23,6 +23,7 @@ Version: $Revision: 1.2 $
#include <vtkMatrix4x4.h>
#include <vtkObjectFactory.h>
#include <vtkSmartPointer.h>
#include <vtkVector.h>
// VNL includes
#include <vnl/vnl_double_3.h>
......@@ -1925,6 +1926,44 @@ void vtkMRMLSliceNode::RotateToVolumePlane(vtkMRMLVolumeNode *volumeNode)
}
}
//
// If two colums project to the same axis, then there will be
// a column of all zeros in the SliceToRAS matrix - if this happens replace this
// with the cross product of the other columns
//
int nullColumn = -1;
for (col = 0; col < 3; col++)
{
int row;
bool isNull = true;
for (row = 0; row < 3; row++)
{
if (this->SliceToRAS->GetElement(row, col) != 0.0)
{
isNull = false;
}
}
if (isNull)
{
nullColumn = col;
}
}
if (nullColumn != -1)
{
vtkVector3<double> A(
this->SliceToRAS->GetElement(0, (nullColumn+1)%3),
this->SliceToRAS->GetElement(1, (nullColumn+1)%3),
this->SliceToRAS->GetElement(2, (nullColumn+1)%3));
vtkVector3<double> B(
this->SliceToRAS->GetElement(0, (nullColumn+2)%3),
this->SliceToRAS->GetElement(1, (nullColumn+2)%3),
this->SliceToRAS->GetElement(2, (nullColumn+2)%3));
vtkVector3<double> C = A.Cross(B);
this->SliceToRAS->SetElement(0, nullColumn, C.GetX());
this->SliceToRAS->SetElement(1, nullColumn, C.GetY());
this->SliceToRAS->SetElement(2, nullColumn, C.GetZ());
}
this->SetOrientationToReformat(); // just sets the string - indicates that this is not patient aligned
this->Modified();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment