From b1f8fc7d2e64a35c4effef6fdac2462a992fdd47 Mon Sep 17 00:00:00 2001 From: "Hans J. Johnson" Date: Sun, 6 Sep 2026 11:29:00 -0500 Subject: [PATCH] COMP: Detect the VTK rendering backend from imported targets VTK 9 does not define VTK_RENDERING_BACKEND, so the fallback to OpenGL2 always fired and every "STREQUAL None" guard was unconditionally true. ITKVtkGlue therefore required a rendering-enabled VTK even though its sources and tests already guard the viewer classes for the None case. The same block appears in the two export-code strings, which run at the consumer's find_package(ITK), so a downstream project re-ran the broken detection as well. All three are changed. --- Modules/Bridge/VtkGlue/CMakeLists.txt | 12 ++++++++++-- Modules/Bridge/VtkGlue/itk-module-init.cmake | 7 ++++++- .../Bridge/VtkGlue/wrapping/itkViewImage.wrap | 17 ++++++++++------- 3 files changed, 26 insertions(+), 10 deletions(-) diff --git a/Modules/Bridge/VtkGlue/CMakeLists.txt b/Modules/Bridge/VtkGlue/CMakeLists.txt index 74231aaff7e..3a3f9147773 100644 --- a/Modules/Bridge/VtkGlue/CMakeLists.txt +++ b/Modules/Bridge/VtkGlue/CMakeLists.txt @@ -85,7 +85,11 @@ set( set(VTK_DIR \"${VTK_DIR}\") find_package(VTK 9.1 NO_MODULE REQUIRED) if(NOT VTK_RENDERING_BACKEND) - set(VTK_RENDERING_BACKEND OpenGL2) + if(TARGET VTK::RenderingOpenGL2) + set(VTK_RENDERING_BACKEND OpenGL2) + else() + set(VTK_RENDERING_BACKEND None) + endif() endif() set(_target_freetypeopengl) if(TARGET VTK::RenderingFreeType\${VTK_RENDERING_BACKEND}) @@ -123,7 +127,11 @@ if(NOT ITK_BINARY_DIR) set(VTK_DIR \"${VTK_DIR}\") find_package(VTK 9.1 NO_MODULE REQUIRED) if(NOT VTK_RENDERING_BACKEND) - set(VTK_RENDERING_BACKEND OpenGL2) + if(TARGET VTK::RenderingOpenGL2) + set(VTK_RENDERING_BACKEND OpenGL2) + else() + set(VTK_RENDERING_BACKEND None) + endif() endif() set(_target_freetypeopengl) if(TARGET VTK::RenderingFreeType\${VTK_RENDERING_BACKEND}) diff --git a/Modules/Bridge/VtkGlue/itk-module-init.cmake b/Modules/Bridge/VtkGlue/itk-module-init.cmake index 550f1dce272..0873413d3a7 100644 --- a/Modules/Bridge/VtkGlue/itk-module-init.cmake +++ b/Modules/Bridge/VtkGlue/itk-module-init.cmake @@ -16,8 +16,13 @@ set(VERSION_MIN "9.1.0") find_package(VTK ${VERSION_MIN} NO_MODULE REQUIRED) +# VTK 9 omits VTK_RENDERING_BACKEND; infer rendering support from its OpenGL2 target. if(NOT VTK_RENDERING_BACKEND) - set(VTK_RENDERING_BACKEND OpenGL2) + if(TARGET VTK::RenderingOpenGL2) + set(VTK_RENDERING_BACKEND OpenGL2) + else() + set(VTK_RENDERING_BACKEND None) + endif() endif() set(_target_freetypeopengl) diff --git a/Modules/Bridge/VtkGlue/wrapping/itkViewImage.wrap b/Modules/Bridge/VtkGlue/wrapping/itkViewImage.wrap index 0b4aa6cae29..169247ea1ff 100644 --- a/Modules/Bridge/VtkGlue/wrapping/itkViewImage.wrap +++ b/Modules/Bridge/VtkGlue/wrapping/itkViewImage.wrap @@ -1,8 +1,11 @@ -itk_wrap_class("itk::ViewImage") -unique(types "${WRAP_ITK_SCALAR}") -foreach(d ${ITK_WRAP_IMAGE_DIMS}) - foreach(t ${types}) - itk_wrap_template("${ITKM_I${t}${d}}" "${ITKT_I${t}${d}}") +# itk::ViewImage needs vtkRenderWindow, absent from a rendering-free VTK. +if(NOT VTK_RENDERING_BACKEND STREQUAL "None") + itk_wrap_class("itk::ViewImage") + unique(types "${WRAP_ITK_SCALAR}") + foreach(d ${ITK_WRAP_IMAGE_DIMS}) + foreach(t ${types}) + itk_wrap_template("${ITKM_I${t}${d}}" "${ITKT_I${t}${d}}") + endforeach() endforeach() -endforeach() -itk_end_wrap_class() + itk_end_wrap_class() +endif()