Skip to content

Commit

Permalink
BUG: ComputeInverseJacobianWithRespectToPosition didn't do inversion
Browse files Browse the repository at this point in the history
itk::MatrixOffsetTransformBase::ComputeInverseJacobianWithRespectToPosition was returning directly the matrix (the same as ComputeJacobianWithRespectToPosition). It has been corrected to return the inverse matrix.

This correction has required also the correction of a few function return and parameters' Types.
Those corrected Types were inconsistent when instantiated with InputImage and OutputImage of different dimensions.

Apparently the bug was inadvertently introduced in
61e2be7 (PERF: Improve MatrixOffset Jacobian computation performance)
and subsequently not fixed but got mixed wrong JacobianTypes in
212cae5 (PERF: Change type of Jacobian w.r. position to vnl_matrix_fixed).
  • Loading branch information
josempozo authored and dzenanz committed Dec 6, 2021
1 parent 05ae9a5 commit 9111b93
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,11 @@ class ITK_TEMPLATE_EXPORT MatrixOffsetTransformBase
using InverseTransformBaseType = typename Superclass::InverseTransformBaseType;
using InverseTransformBasePointer = typename InverseTransformBaseType::Pointer;

using InverseTransformType = MatrixOffsetTransformBase<TParametersValueType, NOutputDimensions, NInputDimensions>;
/** InverseTransformType must be a friend to allow the generation of a transformation
* from its inverse (function GetInverse). */
friend class MatrixOffsetTransformBase<TParametersValueType, NOutputDimensions, NInputDimensions>;

/** Set the transformation to an Identity
*
* This sets the matrix to identity and the Offset to null. */
Expand Down Expand Up @@ -471,7 +476,7 @@ class ITK_TEMPLATE_EXPORT MatrixOffsetTransformBase
*
*/
bool
GetInverse(Self * inverse) const;
GetInverse(InverseTransformType * inverse) const;

/** Return an inverse of this transform. */
InverseTransformBasePointer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,8 @@ MatrixOffsetTransformBase<TParametersValueType, NInputDimensions, NOutputDimensi

template <typename TParametersValueType, unsigned int NInputDimensions, unsigned int NOutputDimensions>
bool
MatrixOffsetTransformBase<TParametersValueType, NInputDimensions, NOutputDimensions>::GetInverse(Self * inverse) const
MatrixOffsetTransformBase<TParametersValueType, NInputDimensions, NOutputDimensions>::GetInverse(
InverseTransformType * inverse) const
{
if (!inverse)
{
Expand Down Expand Up @@ -446,7 +447,7 @@ typename MatrixOffsetTransformBase<TParametersValueType, NInputDimensions, NOutp
InverseTransformBasePointer
MatrixOffsetTransformBase<TParametersValueType, NInputDimensions, NOutputDimensions>::GetInverseTransform() const
{
Pointer inv = New();
auto inv = InverseTransformType::New();

return GetInverse(inv) ? inv.GetPointer() : nullptr;
}
Expand Down Expand Up @@ -604,7 +605,7 @@ void
MatrixOffsetTransformBase<TParametersValueType, NInputDimensions, NOutputDimensions>::
ComputeInverseJacobianWithRespectToPosition(const InputPointType &, InverseJacobianPositionType & jac) const
{
jac = this->GetMatrix().GetVnlMatrix();
jac = this->GetInverseMatrix().GetVnlMatrix();
}


Expand Down

0 comments on commit 9111b93

Please sign in to comment.