Skip to content

ITKVtkGlue cannot configure against a rendering-free VTK; the VTK_RENDERING_BACKEND guard is dead code #6846

Description

@hjmjohnson

Summary

ITKVtkGlue cannot be configured against a VTK built without rendering, even though the module contains explicit logic intended to support exactly that. The logic is unreachable because it tests VTK_RENDERING_BACKEND, a VTK 8 variable that VTK 9 does not define.

The dead branch

Modules/Bridge/VtkGlue/itk-module-init.cmake:19

if(NOT VTK_RENDERING_BACKEND)
  set(VTK_RENDERING_BACKEND OpenGL2)
endif()

Modules/Bridge/VtkGlue/itk-module-init.cmake:44

if(NOT VTK_RENDERING_BACKEND STREQUAL "None")
  list(APPEND _required_vtk_libraries
    VTK::Rendering${VTK_RENDERING_BACKEND}
    VTK::RenderingFreeType
    ${_target_freetypeopengl}
    VTK::InteractionStyle
    VTK::InteractionWidgets)
endif()

VTK 9 does not set VTK_RENDERING_BACKEND. Confirmed against a 9.6.2 install:

$ grep -rl VTK_RENDERING_BACKEND <vtk-build>/lib/cmake/vtk-9.6/
(no matches)

So the variable is always empty, always becomes OpenGL2, and the STREQUAL "None" guard can never be false. The rendering libraries are appended unconditionally.

The same variable gates the optional C++ tests in Modules/Bridge/VtkGlue/test/CMakeLists.txt:8, so itkVtkMedianFilterTest, itkVtkConnectedComponentImageFilterTest and QuickViewTest are likewise always enabled.

This appears to have been inert since ITK began requiring VTK 9. The file's own comment states the minimum is VTK 9.1.

Reproduction

Build VTK with rendering disabled and Python wrapping on:

cmake -S VTK -B vtk-build -GNinja \
  -DVTK_ENABLE_KITS=OFF -DVTK_WRAP_PYTHON=ON \
  -DVTK_GROUP_ENABLE_Rendering=NO -DVTK_GROUP_ENABLE_Qt=NO
cmake --build vtk-build

Then configure ITK against it:

cmake -S ITK -B itk-build -GNinja \
  -DBUILD_TESTING=ON -DModule_ITKVtkGlue=ON -DVTK_DIR=<vtk-build>

Result:

CMake Error at <vtk-build>/lib/cmake/vtk-9.6/vtkModule.cmake:1348 (message):
  Failed to determine the real target for the `VTK::RenderingOpenGL2` module.
  The module name is not a CMake target.  Is there a typo? Is it missing a
  `Package::` prefix? Is a `find_package` missing a required component?
Call Stack (most recent call first):
  <vtk-build>/lib/cmake/vtk-9.6/vtkModule.cmake:3430 (_vtk_module_real_target)
  Modules/Bridge/VtkGlue/test/CMakeLists.txt:26 (vtk_module_autoinit)

The message points at vtk_module_autoinit and names a VTK-internal function, which does not suggest the actual cause.

Why this matters

Headless VTK builds are ordinary in CI containers, HPC nodes and server-side pipelines. The image-conversion half of ITKVtkGlue — itk::ImageToVTKImageFilter and itk::VTKImageToImageFilter — needs no rendering at all, and three of the module's C++ tests (itkImageToVTKImageFilterTest, itkImageToVTKImageFilterRGBTest, itkVTKImageToImageFilterTest) exercise only that path. Today none of them can be built without dragging in OpenGL, FreeType and the interaction modules.

Suggested fix

Detect the backend from imported targets rather than the removed variable:

if(TARGET VTK::RenderingOpenGL2)
  set(VTK_RENDERING_BACKEND OpenGL2)
else()
  set(VTK_RENDERING_BACKEND None)
endif()

Both existing STREQUAL "None" guards then work as written; no other changes appear necessary. _target_freetypeopengl already uses the if(TARGET ...) idiom immediately below, so this is consistent with the surrounding code.

Behaviour is unchanged for anyone whose VTK has rendering. Anyone whose VTK lacks it moves from a hard configure error to a working ITKVtkGlue without the view-related classes and tests.

I am happy to prepare the patch. It should follow #6715 (ITKVtkGlue wrapping), which is in review and touches the same module.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions