Skip to content

ENH: Wrap ObjectToObjectMultiMetricv4 for Python (issue #5652, supersedes #5653)#6227

Merged
hjmjohnson merged 2 commits intoInsightSoftwareConsortium:mainfrom
hjmjohnson:wrap-multimetricv4-with-3arg-canonical
May 9, 2026
Merged

ENH: Wrap ObjectToObjectMultiMetricv4 for Python (issue #5652, supersedes #5653)#6227
hjmjohnson merged 2 commits intoInsightSoftwareConsortium:mainfrom
hjmjohnson:wrap-multimetricv4-with-3arg-canonical

Conversation

@hjmjohnson
Copy link
Copy Markdown
Member

@hjmjohnson hjmjohnson commented May 7, 2026

Wrap itk::ObjectToObjectMultiMetricv4 for Python. Supersedes #5653 — preserves every historical 2-arg template key for ImageToImageMetricv4 and its 6 derived classes (which #5653 silently broke).

Why a new PR rather than rebasing #5653

#5653 switched 7 *ImageToImageMetricv4 wraps from 2-arg (F2F2) to 3-arg (F2F2IF2) keys, silently breaking pre-existing user code (ImageRegistration{3,4,5}.py, ModifiedTime.py) and turning CI red on CDash + ARMBUILD-Python + ITK.{Linux,macOS}.Python.

This PR registers BOTH keys: canonical 3-arg + 2-arg alias resolving to the same SWIG class via two add_python_config_template() entries. itkTemplate.__add__ keys on the template-arg string and parameter tuple, so duplicate-registration warnings don't fire. No wrap-generator core changes.

Commits
  1. ENH: Add Python wrapping for ObjectToObjectMultiMetricv4 (author: @thewtex) — new itkObjectToObjectMultiMetricv4.wrap for (F,2), (F,3), (D,2), (D,3); 7 metric wrap files extended with the canonical-3-arg + 2-arg-alias pattern; new itkObjectToObjectMultiMetricv4Test.py.
  2. ENH: Add itk.as_metric_base helper for AddMetric upcasts — SWIG can't auto-upcast across POINTER_WITH_2_SUPERCLASSES, so callers need an explicit upcast through the _Superclass typedef. Helper introspects template params and does it.
Local validation
  • pre-commit run --all-files clean
  • 52/52 tests in ctest -R 'Metricv4Python|ImageToImageMetric|ModifiedTime' (no regressions)
  • New itkObjectToObjectMultiMetricv4PythonTest exercises both 2-arg and 3-arg keys + AddMetric for MeanSquares, Mattes, mixed
  • Backward-compat: 7 derived classes' 2-arg keys all resolve

Fixes: #5652

@github-actions github-actions Bot added type:Infrastructure Infrastructure/ecosystem related changes, such as CMake or buildbots type:Enhancement Improvement of existing methods or implementation area:Python wrapping Python bindings for a class type:Testing Ensure that the purpose of a class is met/the results on a wide set of test cases are correct area:Registration Issues affecting the Registration module labels May 7, 2026
@hjmjohnson
Copy link
Copy Markdown
Member Author

hjmjohnson commented May 7, 2026

@dyollb @thewtex Fresh-start successor of #5653. Preserves the 2-arg API. Reviews welcome.

@hjmjohnson hjmjohnson marked this pull request as ready for review May 7, 2026 13:06
@greptile-apps

This comment was marked as resolved.

Comment thread Wrapping/Generators/Python/itk/support/extras.py
@hjmjohnson hjmjohnson force-pushed the wrap-multimetricv4-with-3arg-canonical branch from 2b5ede0 to 9988de2 Compare May 7, 2026 14:07
@hjmjohnson hjmjohnson requested a review from thewtex May 7, 2026 18:10
thewtex and others added 2 commits May 8, 2026 11:38
Wrap itk::ObjectToObjectMultiMetricv4 with explicit TVirtualImage so
AddMetric() resolves unambiguously. Each ImageToImageMetricv4 wrap
now registers both the canonical 3-arg key and a 2-arg alias (same
SWIG class) so existing user code keeps working.

Supersedes InsightSoftwareConsortium#3909 / InsightSoftwareConsortium#5653.

Co-Authored-By: Jon Haitz Legarreta Gorroño <jhlegarreta@users.noreply.github.com>
SWIG can't auto-upcast across POINTER_WITH_2_SUPERCLASSES. Helper
introspects the metric's wrapped template params and casts through
the canonical ImageToImageMetricv4 _Superclass typedef so callers
don't have to spell it out.
@hjmjohnson hjmjohnson force-pushed the wrap-multimetricv4-with-3arg-canonical branch from 9988de2 to ddf2710 Compare May 8, 2026 16:39
Copy link
Copy Markdown
Member

@thewtex thewtex left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🥇 !

@hjmjohnson hjmjohnson merged commit fbe52c0 into InsightSoftwareConsortium:main May 9, 2026
22 of 23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:Python wrapping Python bindings for a class area:Registration Issues affecting the Registration module type:Enhancement Improvement of existing methods or implementation type:Infrastructure Infrastructure/ecosystem related changes, such as CMake or buildbots type:Testing Ensure that the purpose of a class is met/the results on a wide set of test cases are correct

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Wrap ObjectToObjectMultiMetricv4

2 participants