Repository navigation
ENH: GetInverseTransform() returns concrete type for 3D transforms (resolves #6686, supersedes #6685) - #6689
Conversation
6b42cdf to
d0b9c86
Compare
dzenanz
left a comment
There was a problem hiding this comment.
Looks good. One possible caveat, absence of which was triggering compile errors when I was doing KernelTransform inverse.
This comment was marked as low quality.
This comment was marked as low quality.
d0b9c86 to
4d8cd5d
Compare
|
Force-push = test coverage only, no source/logic change. Added |
751d4b2 to
cc6e608
Compare
|
Two force-pushes just landed: first = plain rebase onto current main (resolves the migration-guide conflict with the merged NiftiImageIO section, keeping both); second = the comment reword only (@dzenanz's note). CI re-running on the new HEAD. |
cc6e608 to
3c43e8a
Compare
The 2D transform family (Rigid2D, Euler2D, Similarity2D, and centered variants) already overrides GetInverseTransform() to return the same concrete type via Superclass::InvertTransform(*this). Their 3D counterparts inherited the MatrixOffsetTransformBase implementation, which deduces the parent type and returns a base-typed inverse. Add the same one-line override to the 3D rigid/versor/similarity classes and to FixedCenterOfRotationAffineTransform and ScaleLogarithmicTransform so the inverse preserves the concrete type. The inherited GetInverse() already re-extracts constrained parameters through the virtual ComputeMatrixParameters(), so no new inverse math is required. Extend itkTestTransformGetInverse to assert the inverse preserves the concrete type, exempting BSplineTransform (no closed-form inverse, null) and AzimuthElevationToCartesianTransform (nonlinear, affine inverse). Addresses InsightSoftwareConsortium#6686. Co-Authored-By: Dženan Zukić <[email protected]>
…guide Document the ITK 6 behavior change where GetInverseTransform() returns the concrete transform type for the 3D rigid/versor/similarity family and for FixedCenterOfRotationAffineTransform and ScaleLogarithmicTransform. Addresses InsightSoftwareConsortium#6686. Co-Authored-By: Dženan Zukić <[email protected]>
|
Two force-pushes: first = the comment fix (@dzenanz — condensed the block, no more "this PR" phrasing); second = plain rebase onto current main. |
3c43e8a to
13ebaff
Compare
Co-authored-by: Dženan Zukić <[email protected]>
0375e07
into
InsightSoftwareConsortium:main
Makes
GetInverseTransform()return the concrete transform type for the 3D rigid/versor/similarity family and forFixedCenterOfRotationAffineTransformandScaleLogarithmicTransform, matching the behavior the 2D family already had. Resolves #6686 and supersedes #6685 (the failing repro by @dzenanz, whose type assertion this PR generalizes, satisfies, and extends).Root cause and fix
Transform::InvertTransform(const TTransform&)doesTTransform::New(), deducingTTransformfrom the static type at the call site.MatrixOffsetTransformBase::GetInverseTransform()callsInvertTransform(*this)where*thisis statically the base, so every derived class that did not overrideGetInverseTransform()inherited a parent-typed inverse.The 2D family (
Rigid2DTransform,Euler2DTransform,Similarity2DTransform, centered variants) already overrides it withreturn Superclass::InvertTransform(*this);. This PR adds the same one-line override to the 3D counterparts. The inheritedGetInverse()already re-extracts the constrained parameters through the virtualComputeMatrixParameters(), so no new inverse math is needed.Classes fixed:
Euler3DTransform,QuaternionRigidTransform,Similarity3DTransform,VersorRigid3DTransform,VersorTransform,FixedCenterOfRotationAffineTransform,ScaleLogarithmicTransform.Unlike the 2D siblings, these classes did not re-export
InverseTransformBasePointer, so each override also addsusing typename Superclass::InverseTransformBasePointer;(unqualified names from a template-dependent base are not found by two-phase lookup).Intentionally exempt
BSplineTransform— no closed-form global inverse;GetInverseTransform()returnsnullptr.AzimuthElevationToCartesianTransform— nonlinear; its inverse is an affine approximation.The test marks both as
expectSameType = false.Test and local verification
itkTestTransformGetInversenow asserts the inverse preserves the concrete type (parameterizedexpectSameType, default true).ITKTransformTestDriveragainstmain; test exits 0 with the fix, all 28 instantiations pass.Euler3DTransformoverride reproducesERROR: GetInverseTransform() did not preserve concrete type for Euler3DTransform; got MatrixOffsetTransformBaseand exit 1.pre-commit run --all-filesclean.Migration and downstream impact
Added a section to
Documentation/docs/migration_guides/itk_6_migration_guide.md.A survey of ~280 downstream ITK-consumer repositories found no code that breaks: every consumer either uses the inverse through the base pointer or upcasts it to an ancestor type, both of which a more-derived object still satisfies. The one real downstream effect is serialization: an inverse written to disk now records the derived class name (e.g.
Euler3DTransform_double_3_3), so byte/string-compared transform baselines in downstream projects may need regeneration. Factory-based readers load either form.PR Checklist