Skip to content

Commit

Permalink
COMP: Add support for building against VTK >= 8.90
Browse files Browse the repository at this point in the history
* Pass Python3_* variables required by FindPython3 CMake module
  used by VTK

* Add VTK_OVERRIDE to ctkExport because it is not defined
  in newer VTK version.

* Update ctkMacroBuildLib adding support for EXPORT_CUSTOM_CONTENT_FROM_VARIABLE
  parameter allowing to specify custom content.

Co-authored-by: Csaba Pinter <[email protected]>
Co-authored-by: Jean-Christophe Fillion-Robin <[email protected]>
  • Loading branch information
jcfr and cpinter committed Sep 30, 2020
1 parent e419cee commit 48e4a3f
Show file tree
Hide file tree
Showing 12 changed files with 240 additions and 44 deletions.
12 changes: 11 additions & 1 deletion CMake/ctkMacroBuildLib.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#! \ingroup CMakeAPI
macro(ctkMacroBuildLib)
ctkMacroParseArguments(MY
"NAME;EXPORT_DIRECTIVE;SRCS;MOC_SRCS;GENERATE_MOC_SRCS;UI_FORMS;INCLUDE_DIRECTORIES;TARGET_LIBRARIES;RESOURCES;LIBRARY_TYPE"
"NAME;EXPORT_DIRECTIVE;SRCS;MOC_SRCS;GENERATE_MOC_SRCS;UI_FORMS;INCLUDE_DIRECTORIES;TARGET_LIBRARIES;RESOURCES;LIBRARY_TYPE;EXPORT_CUSTOM_CONTENT_FROM_VARIABLE"
"ENABLE_QTTESTING"
${ARGN}
)
Expand Down Expand Up @@ -91,6 +91,16 @@ macro(ctkMacroBuildLib)
string(REGEX REPLACE "^CTK" "ctk" MY_EXPORT_HEADER_PREFIX ${MY_EXPORT_HEADER_PREFIX})
set(MY_LIBNAME ${lib_name})

set(CTK_EXPORT_CUSTOM_CONTENT "")
if(MY_EXPORT_CUSTOM_CONTENT_FROM_VARIABLE)
if(DEFINED "${MY_EXPORT_CUSTOM_CONTENT_FROM_VARIABLE}")
set(CTK_EXPORT_CUSTOM_CONTENT "// ------- Expanded from \@CTK_EXPORT_CUSTOM_CONTENT\@ -------
${${MY_EXPORT_CUSTOM_CONTENT_FROM_VARIABLE}}
// ------------------------------------------------
")
endif()
endif()

configure_file(
${CTK_SOURCE_DIR}/Libs/ctkExport.h.in
${CMAKE_CURRENT_BINARY_DIR}/${MY_EXPORT_HEADER_PREFIX}Export.h
Expand Down
13 changes: 13 additions & 0 deletions CMakeExternals/VTK.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,16 @@ mark_as_superbuild(
VARS VTK_DIR:PATH
LABELS "FIND_PACKAGE"
)

if(VTK_PYTHON_VERSION VERSION_GREATER "2.7")
# Propagate variables expected when VTK searches for python
mark_as_superbuild(
VARS
Python3_INCLUDE_DIR:PATH
Python3_ROOT_DIR:PATH
Python3_LIBRARY:FILEPATH
Python3_LIBRARY_DEBUG:FILEPATH
Python3_LIBRARY_RELEASE:FILEPATH
Python3_EXECUTABLE:FILEPATH
)
endif()
74 changes: 69 additions & 5 deletions Libs/Visualization/VTK/Core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,41 @@ project(CTKVisualizationVTKCore)
#
# 3rd party dependencies
#
include(${VTK_USE_FILE})

if(${VTK_VERSION} VERSION_LESS "8.90")
include(${VTK_USE_FILE})
else()
# VTK >= 8.90 defines VTK_MAJOR_VERSION
set(VTK_VERSION_MAJOR ${VTK_MAJOR_VERSION})

find_package(VTK
COMPONENTS
ChartsCore
CommonCore
CommonDataModel
FiltersCore
FiltersGeneral
FiltersModeling
FiltersSources
FiltersStatistics
IOLegacy
IOXML
InfovisCore
InfovisLayout
InteractionStyle
RenderingAnnotation
RenderingCore
RenderingFreeType
RenderingOpenGL2
ViewsCore
ViewsInfovis
WrappingPythonCore
ViewsContext2D
OPTIONAL_COMPONENTS
TestingRendering
)
endif()

if(NOT DEFINED VTK_RENDERING_BACKEND)
set(VTK_RENDERING_BACKEND "OpenGL")
endif()
Expand Down Expand Up @@ -62,7 +96,9 @@ if(CTK_LIB_Scripting/Python/Core AND CTK_LIB_Scripting/Python/Core_PYTHONQT_USE_
endif()

# Set VTK_LIBRARIES variable
if(${VTK_VERSION_MAJOR} GREATER 5)
if(${VTK_VERSION} VERSION_EQUAL 8.90 OR ${VTK_VERSION} VERSION_GREATER 8.90 )
# VTK_LIBRARIES is automatically set based on selected components
elseif(${VTK_VERSION_MAJOR} GREATER 5)
set(VTK_LIBRARIES
# a few of these have to be specified explicitly to workaround
# underlinked libraries from the debian VTK package
Expand Down Expand Up @@ -126,7 +162,9 @@ if(${CTK_USE_CHARTS})
vtkScalarsToColorsPreviewChart.cpp
vtkScalarsToColorsPreviewChart.h
${KIT_SRCS})
if(${VTK_VERSION_MAJOR} GREATER 5)
if(${VTK_VERSION} VERSION_EQUAL 8.90 OR ${VTK_VERSION} VERSION_GREATER 8.90 )
# VTK_LIBRARIES is automatically set based on selected components
elseif(${VTK_VERSION_MAJOR} GREATER 5)
set(VTK_LIBRARIES
vtkChartsCore
${VTK_LIBRARIES})
Expand All @@ -136,14 +174,20 @@ if(${CTK_USE_CHARTS})
${VTK_LIBRARIES})
endif()
add_definitions(-DCTK_USE_CHARTS)

if(${VTK_VERSION} VERSION_LESS "8.90")
set(VTK_LIBRARIES
vtkViewsContext2D
${VTK_LIBRARIES})
${VTK_LIBRARIES})
if(TARGET vtkRenderingContext${VTK_RENDERING_BACKEND})
list(APPEND VTK_LIBRARIES vtkRenderingContext${VTK_RENDERING_BACKEND})
endif()
endif()

endif()

if(${VTK_VERSION} VERSION_LESS "8.90")

if(CTK_LIB_Scripting/Python/Core AND CTK_LIB_Scripting/Python/Core_PYTHONQT_USE_VTK)
ctkFunctionExtractOptimizedLibrary(PYTHON_LIBRARIES PYTHON_LIBRARY)
list(APPEND VTK_LIBRARIES ${PYTHON_LIBRARY} ${PYTHONQT_LIBRARIES})
Expand All @@ -163,6 +207,18 @@ if(Q_WS_X11)
list(APPEND VTK_LIBRARIES ${X11_LIBRARIES})
endif()

endif()

# Custom export content
if(${VTK_VERSION} VERSION_LESS "8.90")
set(CTK_VTK_EXPORT_CUSTOM_CONTENT "")
else()
set(CTK_VTK_EXPORT_CUSTOM_CONTENT "#ifndef VTK_OVERRIDE
#define VTK_OVERRIDE override;
#endif
")
endif()

# Target libraries - See CMake/ctkFunctionGetTargetLibraries.cmake
# The following macro will read the target libraries from the file 'target_libraries.cmake'
ctkFunctionGetTargetLibraries(KIT_target_libraries)
Expand All @@ -173,9 +229,10 @@ ctkMacroBuildLib(
SRCS ${KIT_SRCS}
MOC_SRCS ${KIT_MOC_SRCS}
UI_FORMS ${KIT_UI_FORMS}
TARGET_LIBRARIES ${KIT_target_libraries}
TARGET_LIBRARIES ${KIT_target_libraries} ${PYTHONQT_LIBRARIES}
RESOURCES ${KIT_resources}
LIBRARY_TYPE ${CTK_LIBRARY_MODE}
EXPORT_CUSTOM_CONTENT_FROM_VARIABLE "CTK_VTK_EXPORT_CUSTOM_CONTENT"
)

if(CTK_WRAP_PYTHONQT_LIGHT)
Expand All @@ -186,6 +243,13 @@ if(CTK_WRAP_PYTHONQT_LIGHT)
)
endif()

if (NOT VTK_VERSION VERSION_LESS "8.90.0")
vtk_module_autoinit(
TARGETS ${PROJECT_NAME}
MODULES ${VTK_LIBRARIES}
)
endif()

# Plugins
#if(CTK_BUILD_QTDESIGNER_PLUGINS)
# add_subdirectory(Plugins)
Expand Down
107 changes: 86 additions & 21 deletions Libs/Visualization/VTK/Widgets/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,41 @@
project(CTKVisualizationVTKWidgets)

include(${VTK_USE_FILE})
#
# 3rd party dependencies
#

if(${VTK_VERSION} VERSION_LESS "8.90")
include(${VTK_USE_FILE})
else()
# VTK >= 8.90 defines VTK_MAJOR_VERSION
set(VTK_VERSION_MAJOR ${VTK_MAJOR_VERSION})

find_package(VTK COMPONENTS
ChartsCore
CommonCore
CommonDataModel
#Context2D
FiltersCore
FiltersGeneral
FiltersModeling
FiltersSources
GUISupportQt
ImagingStatistics
IOLegacy
IOXML
InfovisCore
InfovisLayout
InteractionStyle
RenderingContextOpenGL2
RenderingCore
RenderingFreeType
RenderingOpenGL2
ViewsCore
ViewsInfovis
OPTIONAL_COMPONENTS
TestingRendering
)
endif()

#
# See CTK/CMake/ctkMacroBuildLib.cmake for details
Expand Down Expand Up @@ -115,7 +150,9 @@ set(KIT_resources
)

# Set VTK_LIBRARIES variable
if(${VTK_VERSION_MAJOR} GREATER 5)
if(${VTK_VERSION} VERSION_EQUAL 8.90 OR ${VTK_VERSION} VERSION_GREATER 8.90 )
# VTK_LIBRARIES is automatically set based on selected components
elseif(${VTK_VERSION_MAJOR} GREATER 5)
set(VTK_LIBRARIES
vtkChartsCore
vtkCommonMath
Expand Down Expand Up @@ -170,7 +207,9 @@ if(${CTK_USE_CHARTS})
Resources/UI/ctkVTKVolumePropertyWidget.ui
Resources/UI/ctkVTKScalarsToColorsWidget.ui
${KIT_UI_FORMS})
if(${VTK_VERSION_MAJOR} GREATER 5)
if(${VTK_VERSION} VERSION_EQUAL 8.90 OR ${VTK_VERSION} VERSION_GREATER 8.90 )
# VTK_LIBRARIES is automatically set based on selected components
elseif(${VTK_VERSION_MAJOR} GREATER 5)
set(VTK_LIBRARIES
vtkChartsCore
${VTK_LIBRARIES})
Expand Down Expand Up @@ -203,38 +242,55 @@ endif()

# Prefer QVTKOpenGLWidget to QVTKWidget when using Qt5
set(_use_qvtkopenglwidget 1)
if(CTK_QT_VERSION VERSION_LESS "5"
OR VTK_VERSION VERSION_LESS "8"
OR (NOT VTK_RENDERING_BACKEND STREQUAL "OpenGL2"))
set(_use_qvtkopenglwidget 0)
if(VTK_VERSION VERSION_LESS "8.90")
if(CTK_QT_VERSION VERSION_LESS "5"
OR VTK_VERSION VERSION_LESS "8"
OR (NOT VTK_RENDERING_BACKEND STREQUAL "OpenGL2"))
set(_use_qvtkopenglwidget 0)
endif()
endif()

if(_use_qvtkopenglwidget)
add_definitions(-DCTK_USE_QVTKOPENGLWIDGET)
endif()

# Detect if QVTKOpenGLNativeWidget.h is available
set(_has_QVTKOpenGLNativeWidget_h 0)
if(_use_qvtkopenglwidget)
set(_msg "Checking if QVTKOpenGLNativeWidget.h exists")
message(STATUS "${_msg}")
foreach(include_dir IN ITEMS ${vtkGUISupportQt_INCLUDE_DIRS})
if(EXISTS "${include_dir}/QVTKOpenGLNativeWidget.h")
set(_has_QVTKOpenGLNativeWidget_h 1)
break()
if(VTK_VERSION VERSION_LESS "8.90")
set(_has_QVTKOpenGLNativeWidget_h 0)
if(_use_qvtkopenglwidget)
set(_msg "Checking if QVTKOpenGLNativeWidget.h exists")
message(STATUS "${_msg}")
foreach(include_dir IN ITEMS ${vtkGUISupportQt_INCLUDE_DIRS})
if(EXISTS "${include_dir}/QVTKOpenGLNativeWidget.h")
set(_has_QVTKOpenGLNativeWidget_h 1)
break()
endif()
endforeach()
if(_has_QVTKOpenGLNativeWidget_h)
message(STATUS "${_msg} - found")
else()
message(STATUS "${_msg} - not found")
endif()
endforeach()
if(_has_QVTKOpenGLNativeWidget_h)
message(STATUS "${_msg} - found")
else()
message(STATUS "${_msg} - not found")
endif()
endif()
else()
set(_has_QVTKOpenGLNativeWidget_h 1)
endif ()


if(_has_QVTKOpenGLNativeWidget_h)
add_definitions(-DCTK_HAS_QVTKOPENGLNATIVEWIDGET_H)
endif()

# Custom export content
if(${VTK_VERSION} VERSION_LESS "8.90")
set(CTK_VTK_EXPORT_CUSTOM_CONTENT "")
else()
set(CTK_VTK_EXPORT_CUSTOM_CONTENT "#ifndef VTK_OVERRIDE
#define VTK_OVERRIDE override;
#endif
")
endif()

ctkMacroBuildLib(
NAME ${PROJECT_NAME}
EXPORT_DIRECTIVE ${KIT_export_directive}
Expand All @@ -244,6 +300,7 @@ ctkMacroBuildLib(
TARGET_LIBRARIES ${KIT_target_libraries}
RESOURCES ${KIT_resources}
LIBRARY_TYPE ${CTK_LIBRARY_MODE}
EXPORT_CUSTOM_CONTENT_FROM_VARIABLE "CTK_VTK_EXPORT_CUSTOM_CONTENT"
)

if(_use_qvtkopenglwidget)
Expand All @@ -270,6 +327,14 @@ if(CTK_WRAP_PYTHONQT_LIGHT)
)
endif()

if(NOT VTK_VERSION VERSION_LESS "8.90.0")
vtk_module_autoinit(
TARGETS ${PROJECT_NAME}
MODULES ${VTK_LIBRARIES}
)
endif()


# Plugins
if(CTK_BUILD_QTDESIGNER_PLUGINS)
add_subdirectory(Plugins)
Expand Down
4 changes: 3 additions & 1 deletion Libs/Visualization/VTK/Widgets/Testing/Cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,9 @@ else()
endif()

ctk_add_executable_utf8(${KIT}CppTests ${Tests} ${TEST_MOC_CPP} ${TEST_UI_CPP} ${Tests_RESOURCES_SRCS})
if(${VTK_VERSION_MAJOR} GREATER 5)
if(${VTK_VERSION} VERSION_EQUAL 8.90 OR ${VTK_VERSION} VERSION_GREATER 8.90 )
set(VTK_CHARTS_LIB)
elseif(${VTK_VERSION_MAJOR} GREATER 5)
set(VTK_CHARTS_LIB vtkChartsCore)
else()
set(VTK_CHARTS_LIB vtkCharts)
Expand Down
4 changes: 4 additions & 0 deletions Libs/Visualization/VTK/Widgets/ctkVTKAbstractView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,11 @@ void ctkVTKAbstractViewPrivate::setupRendering()
}
this->RenderWindow->SetMultiSamples(nSamples);
this->RenderWindow->StereoCapableWindowOn();
#if VTK_MAJOR_VERSION >= 9 || (VTK_MAJOR_VERSION >= 8 && VTK_MINOR_VERSION >= 90)
this->VTKWidget->setRenderWindow(this->RenderWindow);
#else
this->VTKWidget->SetRenderWindow(this->RenderWindow);
#endif
}

//---------------------------------------------------------------------------
Expand Down
16 changes: 16 additions & 0 deletions Libs/Visualization/VTK/Widgets/ctkVTKChartView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,18 +85,34 @@ ctkVTKChartViewPrivate::ctkVTKChartViewPrivate(ctkVTKChartView& object)
void ctkVTKChartViewPrivate::init()
{
Q_Q(ctkVTKChartView);

#ifdef CTK_USE_QVTKOPENGLWIDGET
# if VTK_MAJOR_VERSION >= 9 || (VTK_MAJOR_VERSION >= 8 && VTK_MINOR_VERSION >= 90)
q->setRenderWindow(this->RenderWindow);
# else
q->SetRenderWindow(this->RenderWindow);
# endif
this->ContextView->SetRenderWindow(this->RenderWindow);
#endif

#if VTK_MAJOR_VERSION >= 9 || (VTK_MAJOR_VERSION >= 8 && VTK_MINOR_VERSION >= 90)
this->ContextView->SetInteractor(q->interactor());
q->setRenderWindow(this->ContextView->GetRenderWindow());
#else
this->ContextView->SetInteractor(q->GetInteractor());
q->SetRenderWindow(this->ContextView->GetRenderWindow());
#endif

// low def for now (faster)
//q->GetRenderWindow()->SetMultiSamples(0);
//vtkOpenGLContextDevice2D::SafeDownCast(this->ContextView->GetContext()->GetDevice())
// ->SetStringRendererToQt();
#ifndef Q_WS_X11
# if VTK_MAJOR_VERSION >= 9 || (VTK_MAJOR_VERSION >= 8 && VTK_MINOR_VERSION >= 90)
q->renderWindow()->SetLineSmoothing(true);
# else
q->GetRenderWindow()->SetLineSmoothing(true);
# endif
#endif
this->Chart->SetActionToButton(vtkChart::PAN, vtkContextMouseEvent::MIDDLE_BUTTON);
this->Chart->SetActionToButton(vtkChart::SELECT, vtkContextMouseEvent::RIGHT_BUTTON);
Expand Down
Loading

0 comments on commit 48e4a3f

Please sign in to comment.