Skip to content

Conversation

@AlexyPellegrini
Copy link
Contributor

Brief

Python wrapping of itkVtkGlue has been removed by #4392. This PR fixes the build issue and enables it again.

Issue

The XML generations failed because the response file referencing the include directories for castxml was not generated correctly. All modules used the same .castxml.inc instead of their own <modulename>.castxml.inc. Once this is fixed, the module wraps correctly.

Why is it needed

Even though numpy enables to share an itk::Image and a vtkImageData, it does not support pipelining. Pipelining is important because some VTK and ITK filters support requesting only a subextent of a resource, enabling better performances especially for readers of formats meant to be streamed, such as OME-Zarr.

image = itk.imread(sys.argv[1], imageio=itk.OMEZarrNGFFImageIO.New())
itktovtk = itk.ImageToVTKImageFilter[type(image)].New()
itktovtk.SetInput(image)
reslice = vtkImageReslice() # vtkImageReslice may query a subextent
reslice.SetInputConnection(itktovtk.GetImporter().GetOutputPort())
#...

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)
  • Added license to new files (if any)
  • Added Python wrapping to new files (if any) as described in ITK Software Guide Section 9.5
  • Added ITK examples for all new major features (if any)

FYI @finetjul

@github-actions github-actions bot added type:Infrastructure Infrastructure/ecosystem related changes, such as CMake or buildbots area:Python wrapping Python bindings for a class area:Bridge Issues affecting the Bridge module labels Sep 1, 2025
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Thank you for contributing a pull request! 🙏

Welcome to the ITK community! 🤗👋☀️

We are glad you are here and appreciate your contribution. Please keep in mind our community participation guidelines. 📜
More support and guidance on the contribution process can be found in our contributing guide. 📖

This is an automatic message. Allow for time for the ITK community to be able to read the pull request and comment
on it.

@dzenanz dzenanz requested a review from thewtex September 1, 2025 18:48
@dzenanz
Copy link
Member

dzenanz commented Sep 1, 2025

If this is patch set is meant to be included in the release branch, make release branch the target. Otherwise please base in on a newer commit to avoid merge conflicts.

@dzenanz
Copy link
Member

dzenanz commented Sep 1, 2025

If that is a lot of work, maybe wait for a review by Matt.


#Write compile definitions and include paths to file. @CONFIG_CASTXML_INC_CONTENTS@ expanded in configure_file
set(castxml_inc_file "${WRAPPER_LIBRARY_OUTPUT_DIR}/castxml_inputs/${library_name}.castxml.inc")
set(castxml_inc_file "${WRAPPER_LIBRARY_OUTPUT_DIR}/castxml_inputs/${WRAPPER_LIBRARY_NAME}.castxml.inc")
Copy link
Member

Choose a reason for hiding this comment

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

Can a further explanation be provided as to why this is changed and why the change does not impact other libraries and modules?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ofc,

  • Why this is changed?
    BUG: Restructured python type hint generation procedure #3200 reworked the Python wrapping code, and is the reason why itkVtkGlue couldn't be wrapped anymore.
    If you take a look at this line you will see that the original code was in the itk_wrap_module macro directly, so it had access to library_name parameter. When the code has been moved to a different macro library_name became empty (because macro arguments are not real variables, so they do not outlive the macro body).
    Using WRAPPER_LIBRARY_NAME actually reverts back to the original behavior, where each module has its own include directories list, named <module-name>.castxml.inc.

  • Why the change does not impact other libraries and modules?
    Each module will have its own file, otherwise no behavior changed!

Note that this also fixes a subtle issue about incremental builds, because enabling or disabling a module with python wrapping caused all module wrapping to be rebuilt, because the .castxml.inc was modified, so all xml regenerated, and so on. With this change, the old behavior is restored, so already build modules shouldn't modify their own castxml.inc, so they won't be rebuilt for nothing!

Let me know if something is still unclear!

Copy link
Member

Choose a reason for hiding this comment

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

The information here, especially about incremental builds, deserves to be in the commit message.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I updated the commit description!

@AlexyPellegrini
Copy link
Contributor Author

If this is patch set is meant to be included in the release branch, make release branch the target. Otherwise please base in on a newer commit to avoid merge conflicts.

Indeed, I rebased on main!

@thewtex thewtex requested a review from hjmjohnson September 2, 2025 15:13
All module generated the same ".castxml.inc" file.
This caused several issues:
- Each CMake configure step repeatedly overwrote .castxml.inc,
  causing a full rebuild of all wrapping related files because
  the XML descriptions were considered out-of-date.
- Wrapping of module itkVtkGlue failed, because it requires
  additional include directories that were removed by other modules.

This change makes each module now generates its own
"<module>.castxml.inc" file.
Copy link
Member

@dzenanz dzenanz left a comment

Choose a reason for hiding this comment

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

LGTM

@hjmjohnson hjmjohnson merged commit e91d475 into InsightSoftwareConsortium:main Sep 3, 2025
16 checks passed
@dzenanz
Copy link
Member

dzenanz commented Sep 4, 2025

Thank you Alexy!

@dzenanz
Copy link
Member

dzenanz commented Sep 5, 2025

This PR broke some of the builds on the nightly dashboard. Error message (from configure step):

-- Setting build type to 'Release' as none was specified.
-- The CXX compiler identification is MSVC 19.44.35215.0
-- The C compiler identification is MSVC 19.44.35215.0
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.44.35207/bin/Hostx64/x64/cl.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.44.35207/bin/Hostx64/x64/cl.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Using MSVC's dynamic CRT (/MD and /MDd)
-- Found Git: C:/Program Files/Git/mingw64/bin/git.exe (found version "2.51.0.windows.1")
-- Performing Test C_HAS_WARNING-Wno-uninitialized

...

-- Looking for include file sys/select.h - not found
CMake Error at C:/Libs/VTK-8.2.0/CMake/vtkModuleAPI.cmake:140 (message):
  Requested modules not available:

    vtkvtksys
Call Stack (most recent call first):
  Modules/Bridge/VtkGlue/itk-module-init.cmake:93 (vtk_module_config)
  CMake/ITKModuleEnablement.cmake:436 (include)
  CMakeLists.txt:754 (include)


-- Configuring incomplete, errors occurred!

More info here: https://open.cdash.org/builds/10653427

@dzenanz
Copy link
Member

dzenanz commented Sep 5, 2025

I am working on a fix locally.

@dzenanz
Copy link
Member

dzenanz commented Sep 5, 2025

Fix in #5512. Passes configure step locally with VTK 8.2 and 9.4.

@dzenanz
Copy link
Member

dzenanz commented Sep 5, 2025

There are also some build errors on Mac: /Users/dzenan.zukic/Documents/Dashboards/vtk/Wrapping/PythonCore/PyVTKObject.h:64:37: error: unknown type name 'PyBufferProcs'.

@AlexyPellegrini
Copy link
Contributor Author

This one might be harder to tackle, ITK enables the Python limited API by default when Python version is superior to 3.11 here and PyBufferProcs structure is defined in cpython/object.h that is only included when using the "unlimited" API here.

Maybe we could enable the unlimited API just for VtkGlue module?

@dzenanz
Copy link
Member

dzenanz commented Sep 5, 2025

The point of the limited API is compatibility of later versions with 3.11. We could make options ITK_USE_PYTHON_LIMITED_API and Module_ITKVtkGlue mutually exclusive. Can you make that PR?

@hjmjohnson
Copy link
Member

Could we remove the dependence on PyBufferProcs?

@dzenanz
Copy link
Member

dzenanz commented Sep 9, 2025

There are more errors, such as this: LINK : fatal error LNK1181: cannot open input file 'vtkkwiml.lib' [T:\Dashboard\ITK-build\Modules\Bridge\VtkGlue\ITKVtkGlueHeaderTest1.vcxproj]. It also affects VTK glue test driver:

Build started at 13:46...
1>------ Build started: Project: ITKVtkGlueTestDriver, Configuration: Debug x64 ------
1>LINK : fatal error LNK1104: cannot open file 'vtkkwiml.lib'
1>Done building project "ITKVtkGlueTestDriver.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 62 up-to-date, 0 skipped ==========
========== Build completed at 13:46 and took 01.438 seconds ==========

but not ITKVtkGlue target. Indeed, there is no vtkkwiml.lib anywhere on my computer.

@AlexyPellegrini
Copy link
Contributor Author

vtkkwiml is header-only so there won't be any archive or shared library for sure. This means that the target "vtkkwiml" is not found by CMake, so it is replaced with a random "-lvtkkwiml" (or windows equivalent). I don't see any reason why this target would be undefined though. Maybe a specific VTK version in which the module wasn't renamed yet?

@dzenanz
Copy link
Member

dzenanz commented Sep 11, 2025

My local VTK was at 5e878068c23f6b87a398dbe8000424971dcb7afa. When I updated it to 9.5.1, vtkkwiml.lib error is gone.

@dzenanz
Copy link
Member

dzenanz commented Sep 11, 2025

The nightly builds (e.g. Windows11-VS2022-Static-DebugTBB) use VTK 8.2.0 built with VS 2015. They are still afflicted by vtkkwiml.lib error.

_required_vtk_libraries
${_target_prefix}IOImage
${_target_prefix}ImagingSources
${_target_prefix}kwiml
Copy link
Member

Choose a reason for hiding this comment

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

We might need special handling for this, like we do for vtksys. But critical version might be different from 8.90.0. @AlexyPellegrini

Copy link
Member

Choose a reason for hiding this comment

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

The critical version is probably much newer, as 5e87806, which is affected, is only 6 months old.

@dzenanz
Copy link
Member

dzenanz commented Sep 12, 2025

I created PR #5522, please review.

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

Labels

area:Bridge Issues affecting the Bridge module area:Python wrapping Python bindings for a class type:Infrastructure Infrastructure/ecosystem related changes, such as CMake or buildbots

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants