Skip to content

Commit

Permalink
BUG: Disallow zero-valued determinant directions
Browse files Browse the repository at this point in the history
Disallow zero-valued determinant directions: the previous implementation
was not checking the actual method parameter values.
  • Loading branch information
jhlegarreta authored and dzenanz committed Dec 6, 2021
1 parent 17a1266 commit c4960ee
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions Modules/Core/Common/include/itkImageBase.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,12 @@ ImageBase<VImageDimension>::SetDirection(const DirectionType & direction)
{
bool modified = false;

if (vnl_determinant(direction.GetVnlMatrix()) == 0.0)
{
itkExceptionMacro("Bad direction, determinant is 0. Refusing to change direction from " << this->m_Direction
<< " to " << direction);
}

for (unsigned int r = 0; r < VImageDimension; ++r)
{
for (unsigned int c = 0; c < VImageDimension; ++c)
Expand Down Expand Up @@ -172,11 +178,6 @@ ImageBase<VImageDimension>::ComputeIndexToPhysicalPointMatrices()
scale[i][i] = this->m_Spacing[i];
}

if (vnl_determinant(this->m_Direction.GetVnlMatrix()) == 0.0)
{
itkExceptionMacro(<< "Bad direction, determinant is 0. Direction is " << this->m_Direction);
}

this->m_IndexToPhysicalPoint = this->m_Direction * scale;
this->m_PhysicalPointToIndex = m_IndexToPhysicalPoint.GetInverse();

Expand Down

0 comments on commit c4960ee

Please sign in to comment.