Skip to content

ENH: make ApplyToImageMetadata available in Python wrapping - #6804

Open
dzenanz wants to merge 1 commit into
InsightSoftwareConsortium:mainfrom
dzenanz:pythonApplyToImageMetadata
Open

ENH: make ApplyToImageMetadata available in Python wrapping#6804
dzenanz wants to merge 1 commit into
InsightSoftwareConsortium:mainfrom
dzenanz:pythonApplyToImageMetadata

Conversation

@dzenanz

@dzenanz dzenanz commented Aug 25, 2026

Copy link
Copy Markdown
Member

PR Checklist

  • No API changes were made (or the changes have been approved)
  • No major design changes were made (or the changes have been approved)
  • Added test (or behavior not changed)
  • Updated API documentation (or API not changed)

@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:Core Issues affecting the Core module labels Aug 25, 2026
@dzenanz
dzenanz force-pushed the pythonApplyToImageMetadata branch 2 times, most recently from 93007ab to 74ae5e0 Compare August 25, 2026 21:05
@hjmjohnson

This comment was marked as resolved.

this->ApplyToImageMetadataInternal(image.GetPointer());
}
void
ApplyToImageMetadata(ImageBase<VInputDimension> * image) const

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Previously the function would be missing when not available, not is will always compile and produce a runtime error.

Perhaps this new method should have #ifdef SWIG || CASTXML or something similar so it's only available in an wrapped interface.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Thanks for inspiration. I was ready to abandon this.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Maybe I missed it, but what about Bradley's suggestion to use #ifdef SWIG || CASTXML?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The ITK_WRAPPING_PARSER preprocessor macro may be helpful here.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I solved that compile error by using if constexpr (VInputDimension == VOutputDimension).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think a compile time error is preferred over a runtime error when the dimensions don't match when use by C++. It appears this was the behavior before.

To restore this behavior, while still allowing this ApplyToImageMetadata method to compile for wrapping. Add the ifdef ITK_WRAPPING_PARSER guard around it.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@dzenanz can you please respond to the ITK_WRAPPING_PARSER suggestion?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Ah, I misunderstood the point. I will implement the suggestion.

@dzenanz

dzenanz commented Aug 26, 2026

Copy link
Copy Markdown
Member Author

Actions update split out into #6806.

@dzenanz
dzenanz force-pushed the pythonApplyToImageMetadata branch from 74ae5e0 to 32b44f6 Compare August 26, 2026 15:02
@dzenanz
dzenanz marked this pull request as ready for review August 26, 2026 15:30
@greptile-apps

greptile-apps Bot commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This change exposes transform metadata application to Python and adds a Python test for that behavior. The new test always requests 3D wrapped image and transform types, but its CMake registration is not limited to builds that enable dimension 3. As a result, Python wrapping builds configured without 3D support can register a test that cannot run.

T-Rex validation blocked

The direct reduced-dimension configuration check could not complete because the cmake tool is missing. The attempted configuration with ITK_WRAP_PYTHON=ON and ITK_WRAP_IMAGE_DIMS=2 exited with status 127 before CMake could generate the test manifest or run the test.

Confidence Score: 4/5

The change is not safe for Python wrapping configurations that intentionally exclude 3D image types until the test registration is gated by the available wrapped dimensions.

One non-security build-compatibility issue remains: the test registration does not match the fixed 3D types used by the test. The source relationship is clear, although the reduced-dimension build could not be configured locally because CMake is unavailable.

Files Needing Attention: Modules/Core/Transform/wrapping/test/CMakeLists.txt needs a dimension-3 wrapping guard around itkApplyToImageMetadataTest; Modules/Core/Transform/wrapping/test/itkApplyToImageMetadataTest.py establishes the test's fixed 3D dependency.

T-Rex T-Rex Logs

What T-Rex did

  • The 2D wrapping probe script was uploaded and identified as the minimal configuration probe.
  • The first blocked probe output log was uploaded, showing the attempted command, the working directory, the missing cmake failure, and exit status 127.
  • The repeated blocked probe output log was uploaded, providing corroborating evidence of the same missing cmake failure and exit status 127.

View all artifacts

T-Rex Ran code and verified through T-Rex

Reviews (1): Last reviewed commit: "ENH: make ApplyToImageMetadata available..." | Re-trigger Greptile

Comment thread Modules/Core/Transform/wrapping/test/CMakeLists.txt Outdated
@dzenanz
dzenanz force-pushed the pythonApplyToImageMetadata branch 2 times, most recently from cc5694f to 7ebba67 Compare August 26, 2026 18:01
@dzenanz

dzenanz commented Aug 26, 2026

Copy link
Copy Markdown
Member Author

This is ready for review. CI is green.

@dzenanz
dzenanz force-pushed the pythonApplyToImageMetadata branch from 7ebba67 to be7dae2 Compare August 27, 2026 17:20
@dzenanz

dzenanz commented Aug 27, 2026

Copy link
Copy Markdown
Member Author

The force-push introduces compile error in Python wrapping locally:

      C:\Misc\ITK-patches-dev\Modules\Core\Transform\include\itkTransform.h(560,3):
      could be 'enable_if<TImage::ImageDimension==2&&TImage::ImageDimension==3,void>::type itk::Transform<double,2,3>::ApplyToImageMetadata(itk::SmartPointer<T>) const'
          C:\Misc\ITK-patches-dev-py26\Wrapping\Modules\ITKTransform\itkTransformBasePython.cpp(20576,39):
          'enable_if<TImage::ImageDimension==2&&TImage::ImageDimension==3,void>::type itk::Transform<double,2,3>::ApplyToImageMetadata(itk::SmartPointer<T>) const': could not deduce template argument for 'itk::SmartPointer<T>' from 'itkImageBase2 *'
      C:\Misc\ITK-patches-dev\Modules\Core\Transform\include\itkTransform.h(554,3):
      or       'enable_if<TImage::ImageDimension==2&&TImage::ImageDimension==3,void>::type itk::Transform<double,2,3>::ApplyToImageMetadata(TImage *) const'
          C:\Misc\ITK-patches-dev-py26\Wrapping\Modules\ITKTransform\itkTransformBasePython.cpp(20576,39):
          Failed to specialize function template 'enable_if<TImage::ImageDimension==2&&TImage::ImageDimension==3,void>::type itk::Transform<double,2,3>::ApplyToImageMetadata(TImage *) const'
              C:\Misc\ITK-patches-dev-py26\Wrapping\Modules\ITKTransform\itkTransformBasePython.cpp(20576,39):
              With the following template arguments:
                  C:\Misc\ITK-patches-dev-py26\Wrapping\Modules\ITKTransform\itkTransformBasePython.cpp(20576,39):
                  'TImage=itkImageBase2'
              C:\Misc\ITK-patches-dev\Modules\Core\Transform\include\itkTransform.h(553,8):
              'std::enable_if_t<false,void>' : Failed to specialize alias template
C:\Misc\ITK-patches-dev-py26\Wrapping\Modules\ITKTransform\itkTransformBasePython.cpp(25254,40): error C2672: 'itk::Transform<double,2,3>::ApplyToImageMetadata': no matching overloaded function found
      C:\Misc\ITK-patches-dev\Modules\Core\Transform\include\itkTransform.h(560,3):
      could be 'enable_if<TImage::ImageDimension==2&&TImage::ImageDimension==3,void>::type itk::Transform<double,2,3>::ApplyToImageMetadata(itk::SmartPointer<T>) const'
          C:\Misc\ITK-patches-dev-py26\Wrapping\Modules\ITKTransform\itkTransformBasePython.cpp(25254,40):
          'enable_if<TImage::ImageDimension==2&&TImage::ImageDimension==3,void>::type itk::Transform<double,2,3>::ApplyToImageMetadata(itk::SmartPointer<T>) const': could not deduce template argument for 'itk::SmartPointer<T>' from 'itkImageBase2 *'
      C:\Misc\ITK-patches-dev\Modules\Core\Transform\include\itkTransform.h(554,3):
      or       'enable_if<TImage::ImageDimension==2&&TImage::ImageDimension==3,void>::type itk::Transform<double,2,3>::ApplyToImageMetadata(TImage *) const'
          C:\Misc\ITK-patches-dev-py26\Wrapping\Modules\ITKTransform\itkTransformBasePython.cpp(25254,40):
          Failed to specialize function template 'enable_if<TImage::ImageDimension==2&&TImage::ImageDimension==3,void>::type itk::Transform<double,2,3>::ApplyToImageMetadata(TImage *) const'
              C:\Misc\ITK-patches-dev-py26\Wrapping\Modules\ITKTransform\itkTransformBasePython.cpp(25254,40):
              With the following template arguments:
                  C:\Misc\ITK-patches-dev-py26\Wrapping\Modules\ITKTransform\itkTransformBasePython.cpp(25254,40):
                  'TImage=itkImageBase2'
              C:\Misc\ITK-patches-dev\Modules\Core\Transform\include\itkTransform.h(553,8):
              'std::enable_if_t<false,void>' : Failed to specialize alias template
C:\Misc\ITK-patches-dev-py26\Wrapping\Modules\ITKTransform\itkTransformBasePython.cpp(29932,40): error C2672: 'itk::Transform<TParametersValueType,3,2>::ApplyToImageMetadata': no matching overloaded function found
C:\Misc\ITK-patches-dev-py26\Wrapping\Modules\ITKTransform\itkTransformBasePython.cpp(29932,40): error C2672:         with
C:\Misc\ITK-patches-dev-py26\Wrapping\Modules\ITKTransform\itkTransformBasePython.cpp(29932,40): error C2672:         [
C:\Misc\ITK-patches-dev-py26\Wrapping\Modules\ITKTransform\itkTransformBasePython.cpp(29932,40): error C2672:             TParametersValueType=double
C:\Misc\ITK-patches-dev-py26\Wrapping\Modules\ITKTransform\itkTransformBasePython.cpp(29932,40): error C2672:         ]
      C:\Misc\ITK-patches-dev\Modules\Core\Transform\include\itkTransform.h(560,3):
      could be 'enable_if<TImage::ImageDimension==3&&TImage::ImageDimension==2,void>::type itk::Transform<TParametersValueType,3,2>::ApplyToImageMetadata(itk::SmartPointer<T>) const'
          with
          [
              TParametersValueType=double
          ]
          C:\Misc\ITK-patches-dev-py26\Wrapping\Modules\ITKTransform\itkTransformBasePython.cpp(29932,40):
          'enable_if<TImage::ImageDimension==3&&TImage::ImageDimension==2,void>::type itk::Transform<TParametersValueType,3,2>::ApplyToImageMetadata(itk::SmartPointer<T>) const': could not deduce template argument for 'itk::SmartPointer<T>' from 'itkImageBase3 *'
          with
          [
              TParametersValueType=double
          ]
      C:\Misc\ITK-patches-dev\Modules\Core\Transform\include\itkTransform.h(554,3):
      or       'enable_if<TImage::ImageDimension==3&&TImage::ImageDimension==2,void>::type itk::Transform<TParametersValueType,3,2>::ApplyToImageMetadata(TImage *) const'
          with
          [
              TParametersValueType=double
          ]
          C:\Misc\ITK-patches-dev-py26\Wrapping\Modules\ITKTransform\itkTransformBasePython.cpp(29932,40):
          Failed to specialize function template 'enable_if<TImage::ImageDimension==3&&TImage::ImageDimension==2,void>::type itk::Transform<TParametersValueType,3,2>::ApplyToImageMetadata(TImage *) const'
          with
          [
              TParametersValueType=double
          ]
              C:\Misc\ITK-patches-dev-py26\Wrapping\Modules\ITKTransform\itkTransformBasePython.cpp(29932,40):
              With the following template arguments:
                  C:\Misc\ITK-patches-dev-py26\Wrapping\Modules\ITKTransform\itkTransformBasePython.cpp(29932,40):
                  'TImage=itkImageBase3'
              C:\Misc\ITK-patches-dev\Modules\Core\Transform\include\itkTransform.h(553,8):
              'std::enable_if_t<false,void>' : Failed to specialize alias template

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:Core Issues affecting the Core module area:Python wrapping Python bindings for a class 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.

5 participants