Skip to content

BUG: Adapt VtkGlue extent callback to VTK future-const signature#6472

Merged
hjmjohnson merged 1 commit into
InsightSoftwareConsortium:mainfrom
hjmjohnson:fix-vtk-future-const-extent-callback
Jun 18, 2026
Merged

BUG: Adapt VtkGlue extent callback to VTK future-const signature#6472
hjmjohnson merged 1 commit into
InsightSoftwareConsortium:mainfrom
hjmjohnson:fix-vtk-future-const-extent-callback

Conversation

@hjmjohnson

Copy link
Copy Markdown
Member

Fixes a compile regression in the ITK↔VTK glue: when VTK is built with VTK_USE_FUTURE_CONST=ON, vtkImageImport/vtkImageExport declare the PropagateUpdateExtent callback's extent parameter as const int *, which no longer matches ITK's int * callback type. Each assignment is bridged with a captureless-lambda adapter that matches the target setter's exact signature.

Closes #6462

Root cause

VTK commit 99e95adeae ("Added VTK_FUTURE_CONST to extents related API") wrapped the extent parameter of vtkImageImport::SetPropagateUpdateExtentCallback and vtkImageExport::GetPropagateUpdateExtentCallback in VTK_FUTURE_CONST. With VTK_USE_FUTURE_CONST=ON that macro expands to const, so the callback type becomes void (*)(void *, const int *).

ITK's itk::VTKImageExportBase / itk::VTKImageImport hardcode void (*)(void *, int *). Function-pointer types do not implicitly convert across that const difference, so both glue assignments fail to compile:

  • itkImageToVTKImageFilter.hxx — ITK exporter callback → vtkImageImport
  • itkVTKImageToImageFilter.hxxvtkImageExport callback → ITK importer
Why the fix lives in VtkGlue (and not by changing ITK's callback signature)

The const-incorrect typedef lives in Modules/Bridge/VTK (ITKVTK), which is intentionally buildable without VTK: it has no VTK headers (grep '#include [<"]vtk' is empty), declares DEPENDS ITKCommon only, and ships compiled as libITKVTK with int * baked into its ABI. The classes reproduce VTK's callback ABI by hand precisely so applications can wire ITK↔VTK without ITK itself depending on VTK.

Consequences for the fix:

  • Making ITKVTK's typedef track VTK_FUTURE_CONST (by including a VTK header, or via a CMake-injected compile definition) would either end ITKVTK's ability to build without VTK, or turn a public ITK type into a build-flag-dependent ABIint * in one build, const int * in another, for the same ITK version. That is a silent-ODR hazard for downstream consumers unless every one of them inherits the identical definition. Note also that VTK does not export VTK_USE_FUTURE_CONST as a CMake variable, so detection would require a configure-time compile probe.
  • Simply switching ITK's signature to const int * does not fix the build — it only flips the breakage to the default (non-future-const) VTK configuration, which is the common case, and is a public API/ABI change to VTKImageExportBase and subclasses.

Keeping the adaptation in Modules/Bridge/VtkGlue — the module that already depends on VTK — leaves ITKVTK's ABI unconditionally int * (one stable type, no detection, no propagation) and confines all VTK_FUTURE_CONST awareness to the lambda parameter lists. The const_cast<int *> in the import direction is safe because every implementation of the callback only reads the extent.

Test plan
  • VTK built from current master with VTK_USE_FUTURE_CONST=ON (reproduces the regression before the fix at both sites).
  • ITK configured with Module_ITKVtkGlue=ON against that VTK.
  • ITKVtkGlueTestDriver builds clean (-Wall -Wextra, no warnings) with the fix.
  • itkImageToVTKImageFilterTest, itkImageToVTKImageFilterRGBTest, itkVTKImageToImageFilterTest all pass.
  • Both VTK configurations (future-const on/off) verified compile-clean in an isolated model.

vtkImageImport and vtkImageExport apply VTK_FUTURE_CONST to the
PropagateUpdateExtent callback, so its extent parameter is const int*
when VTK is built with VTK_USE_FUTURE_CONST=ON. ITK's VTKImageExport
and VTKImageImport keep an int* signature, so the function-pointer
types are incompatible and the VtkGlue assignment fails to compile.

Bridge each assignment with a captureless lambda whose signature
matches the target setter exactly, forwarding through the existing
callback getter.

Closes InsightSoftwareConsortium#6462
@github-actions github-actions Bot added type:Bug Inconsistencies or issues which will cause an incorrect result under some or all circumstances area:Bridge Issues affecting the Bridge module labels Jun 18, 2026
@hjmjohnson hjmjohnson marked this pull request as ready for review June 18, 2026 15:10
@greptile-apps

greptile-apps Bot commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

Fixes a compile regression in the ITK↔VTK glue when VTK is built with VTK_USE_FUTURE_CONST=ON, which makes vtkImageImport/vtkImageExport declare the PropagateUpdateExtent callback's extent parameter as const int *, incompatible with ITK's int * callback type.

  • itkImageToVTKImageFilter.hxx: Replaces the direct SetPropagateUpdateExtentCallback assignment with a captureless lambda that accepts VTK_FUTURE_CONST int * and forwards to the ITK exporter's callback via a safe const_cast (the callback only reads the extent).
  • itkVTKImageToImageFilter.hxx: Mirrors the fix in the opposite direction — the lambda accepts int * (ITK's type) and forwards to VTK's callback, relying on the implicit int *const int * conversion when VTK_USE_FUTURE_CONST=ON.

Confidence Score: 4/5

The logic is correct and safe to merge; only the two in-source comments need trimming to one line each.

Both adapter lambdas are captureless (safely convertible to function pointers), the const_cast in the import direction is sound because the underlying data is non-const and only ever read by the callback, and the implicit int→const int conversion in the export direction is standard C++. The only issues are the 2-line in-source comments, which exceed ITK's prose-budget cap of one line ≤ 100 chars.

Both changed .hxx files need their 2-line comments trimmed to a single line before merging.

Important Files Changed

Filename Overview
Modules/Bridge/VtkGlue/include/itkImageToVTKImageFilter.hxx Wraps the PropagateUpdateExtent assignment in a captureless lambda to bridge VTK_FUTURE_CONST int* ↔ int*; logic is correct but the 2-line comment exceeds ITK's 1-line prose-budget cap.
Modules/Bridge/VtkGlue/include/itkVTKImageToImageFilter.hxx Same adapter-lambda pattern for the VTK→ITK direction; implicit int→const int conversion is sound, and the 2-line comment likewise exceeds the prose-budget cap.

Sequence Diagram

%%{init: {'theme': 'neutral'}}%%
sequenceDiagram
    participant VTK as vtkImageImport (VTK)
    participant Lambda as Adapter Lambda (VtkGlue)
    participant ITK as VTKImageExportBase (ITK)

    note over VTK,ITK: itkImageToVTKImageFilter direction (ITK exporter to VTK importer)
    VTK->>Lambda: "PropagateUpdateExtentCallback(userData, VTK_FUTURE_CONST int* extent)"
    Lambda->>ITK: "GetPropagateUpdateExtentCallback()(userData, const_cast int* extent)"

    note over VTK,ITK: itkVTKImageToImageFilter direction (VTK exporter to ITK importer)
    ITK->>Lambda: "PropagateUpdateExtentCallback(userData, int* extent)"
    Lambda->>VTK: GetPropagateUpdateExtentCallback()(userData, extent)
Loading
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
sequenceDiagram
    participant VTK as vtkImageImport (VTK)
    participant Lambda as Adapter Lambda (VtkGlue)
    participant ITK as VTKImageExportBase (ITK)

    note over VTK,ITK: itkImageToVTKImageFilter direction (ITK exporter to VTK importer)
    VTK->>Lambda: "PropagateUpdateExtentCallback(userData, VTK_FUTURE_CONST int* extent)"
    Lambda->>ITK: "GetPropagateUpdateExtentCallback()(userData, const_cast int* extent)"

    note over VTK,ITK: itkVTKImageToImageFilter direction (VTK exporter to ITK importer)
    ITK->>Lambda: "PropagateUpdateExtentCallback(userData, int* extent)"
    Lambda->>VTK: GetPropagateUpdateExtentCallback()(userData, extent)
Loading

Reviews (1): Last reviewed commit: "BUG: Adapt VtkGlue extent callback to VT..." | Re-trigger Greptile

Comment on lines +42 to +43
// Adapt the exporter callback to vtkImageImport's VTK_FUTURE_CONST extent
// signature; the const_cast is safe because the callback only reads the extent.

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.

P2 The in-source comment spans two lines, which exceeds ITK's prose-budget hard cap of one short line (≤ 100 chars). The same pattern appears in itkVTKImageToImageFilter.hxx. Both comments carry genuinely load-bearing content (the non-obvious const_cast safety invariant), so the information should be preserved — just condensed.

Suggested change
// Adapt the exporter callback to vtkImageImport's VTK_FUTURE_CONST extent
// signature; the const_cast is safe because the callback only reads the extent.
// VTK_FUTURE_CONST extent param; const_cast safe because callback only reads the extent.

Context Used: AGENTS.md (source)

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Comment on lines +44 to +45
// Adapt vtkImageExport's VTK_FUTURE_CONST extent callback to the importer's
// int* signature; the int* argument binds to the VTK_FUTURE_CONST parameter.

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.

P2 Same prose-budget violation as in itkImageToVTKImageFilter.hxx: the two-line comment exceeds the one-line ≤ 100-char cap.

Suggested change
// Adapt vtkImageExport's VTK_FUTURE_CONST extent callback to the importer's
// int* signature; the int* argument binds to the VTK_FUTURE_CONST parameter.
// VTK_FUTURE_CONST extent; int* binds to const int* implicitly, no cast needed.

Context Used: AGENTS.md (source)

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

@hjmjohnson hjmjohnson merged commit e957036 into InsightSoftwareConsortium:main Jun 18, 2026
22 checks passed
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 type:Bug Inconsistencies or issues which will cause an incorrect result under some or all circumstances

Projects

None yet

Development

Successfully merging this pull request may close these issues.

regression: itkImageToVTKImageFilter const difference compiler error

3 participants