Skip to content

Commit

Permalink
BUG: SetIdentity must retain FixedParameters
Browse files Browse the repository at this point in the history
When setting a transform to represent an Identity
mapping, it is crucial that the stationary component
of the transform is preserved.

```python
tfm.SetCenter( [1,2,3] );
tfm.SetIdentity();
out=tfm.GetCenter();
assert( out == [1,2,3] );
```

===============

Add test demonstrating change in fixed paramers

When applying SetIdentity(), the fixed parameters should not be modified.
The fixed paramers represent the stationary component of the transform
and setting the transform back to an identity should not modify the
stationary components.
  • Loading branch information
hjmjohnson committed Feb 28, 2024
1 parent 1b01d5c commit f427be5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ template <typename TParametersValueType, unsigned int VInputDimension, unsigned
void
MatrixOffsetTransformBase<TParametersValueType, VInputDimension, VOutputDimension>::SetIdentity()
{
// Fixed parameters must be preserved when setting the transform to identity
const auto tmp_fixed_parameters = this->GetFixedParameters();
m_Matrix.SetIdentity();
m_MatrixMTime.Modified();
m_Offset.Fill(OutputVectorValueType{});
Expand All @@ -104,6 +106,7 @@ MatrixOffsetTransformBase<TParametersValueType, VInputDimension, VOutputDimensio
m_InverseMatrix.SetIdentity();
m_InverseMatrixMTime = m_MatrixMTime;
this->Modified();
this->SetFixedParameters(tmp_fixed_parameters);
}


Expand Down
17 changes: 17 additions & 0 deletions Modules/Core/Transform/test/itkEuler3DTransformGTest.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,20 @@ TEST(Euler3DTransform, SetFixedParametersThrowsWhenSizeIsLessThanInputSpaceDimen
ASSERT_THROW(transform->SetFixedParameters(fixedParameters), itk::ExceptionObject);
}
}

TEST(Euler3DTransform, TestSetGetCenterAfterSetIdentity)
{
using EulerTransformType = itk::Euler3DTransform<>;

auto eulerTransform = EulerTransformType::New();

// Testing preservation of the center of rotation
auto eulerTransformWithCenter = EulerTransformType::New();
const itk::Point<double, 3> centerOfRotation({ 200, 400, 300 });
eulerTransformWithCenter->SetCenter(centerOfRotation);
EXPECT_EQ(eulerTransformWithCenter->GetCenter(), centerOfRotation);
eulerTransformWithCenter->SetIdentity();
// The center of rotation should be preserved when the transform is set to identity.
// Reseting a transform to identity should not affect the FixedParameters.
EXPECT_EQ(eulerTransformWithCenter->GetCenter(), centerOfRotation);
}

0 comments on commit f427be5

Please sign in to comment.