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()