Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

VTK 9.0 Support #4096

Closed
wants to merge 18 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions 2d/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ set(impl_incs
)

if(${VTK_FOUND})
set(VTK_USE_FILE "${VTK_USE_FILE}" CACHE INTERNAL "VTK_USE_FILE")
include("${VTK_USE_FILE}")
set(VTK_IO_TARGET_LINK_LIBRARIES vtkCommon vtkWidgets vtkIO vtkImaging)
endif()

Expand Down
71 changes: 1 addition & 70 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -366,76 +366,7 @@ endif()
# Find VTK
option(WITH_VTK "Build VTK-Visualizations" TRUE)
if(WITH_VTK AND NOT ANDROID)
set(PCL_VTK_COMPONENTS
vtkChartsCore
vtkCommonCore
vtkCommonDataModel
vtkCommonExecutionModel
vtkFiltersCore
vtkFiltersExtraction
vtkFiltersModeling
vtkImagingCore
vtkImagingSources
vtkInteractionStyle
vtkInteractionWidgets
vtkIOCore
vtkIOGeometry
vtkIOImage
vtkIOLegacy
vtkIOPLY
vtkRenderingAnnotation
vtkRenderingLOD
vtkViewsContext2D
)
find_package(VTK COMPONENTS ${PCL_VTK_COMPONENTS})
if(VTK_FOUND AND ("${VTK_VERSION}" VERSION_LESS 6.2))
message(WARNING "The minimum required version of VTK is 6.2, but found ${VTK_VERSION}")
set(VTK_FOUND FALSE)
endif()

if(VTK_FOUND)
if(NOT DEFINED VTK_RENDERING_BACKEND)
# On old VTK versions this variable does not exist. In this case it is
# safe to assume OpenGL backend
set(VTK_RENDERING_BACKEND "OpenGL")
endif()
list(APPEND PCL_VTK_COMPONENTS vtkRenderingContext${VTK_RENDERING_BACKEND})

if(WITH_QT)
if(";${VTK_MODULES_ENABLED};" MATCHES ";vtkGUISupportQt;" AND ";${VTK_MODULES_ENABLED};" MATCHES ";vtkRenderingQt;")
set(QVTK_FOUND ON)
list(APPEND PCL_VTK_COMPONENTS vtkRenderingQt vtkGUISupportQt)
else()
unset(QVTK_FOUND)
endif()
endif()

find_package(VTK COMPONENTS ${PCL_VTK_COMPONENTS})

message(STATUS "VTK_MAJOR_VERSION ${VTK_MAJOR_VERSION}, rendering backend: ${VTK_RENDERING_BACKEND}")
if(PCL_SHARED_LIBS OR (NOT (PCL_SHARED_LIBS) AND NOT (VTK_BUILD_SHARED_LIBS)))
if(VTK_USE_FILE)
include(${VTK_USE_FILE})
endif()
message(STATUS "VTK found (include: ${VTK_INCLUDE_DIRS}, libs: ${VTK_LIBRARIES}")
if(APPLE)
option(VTK_USE_COCOA "Use Cocoa for VTK render windows" ON)
mark_as_advanced(VTK_USE_COCOA)
endif()
if(${VTK_RENDERING_BACKEND} STREQUAL "OpenGL")
set(VTK_RENDERING_BACKEND_OPENGL_VERSION "1")
message(DEPRECATION "The rendering backend OpenGL is deprecated and not available anymore since VTK 8.2."
"Please switch to the OpenGL2 backend instead, which is available since VTK 6.2."
"Support of the deprecated backend will be dropped with PCL 1.13.")
elseif(${VTK_RENDERING_BACKEND} STREQUAL "OpenGL2")
set(VTK_RENDERING_BACKEND_OPENGL_VERSION "2")
endif()
else()
set(VTK_FOUND OFF)
message("Warning: You are to build PCL in STATIC but VTK is SHARED!")
message("Warning: VTK disabled!")
endif()
endif()
include("${PCL_SOURCE_DIR}/cmake/pcl_find_vtk.cmake")
else()
set(VTK_FOUND OFF)
endif()
Expand Down
4 changes: 3 additions & 1 deletion apps/3d_rec_framework/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ if(NOT VTK_FOUND)
else()
set(DEFAULT TRUE)
set(REASON)
include("${VTK_USE_FILE}")
if(${VTK_VERSION} VERSION_LESS 9.0)
include(${VTK_USE_FILE})
endif()
endif()

# OpenNI found?
Expand Down
4 changes: 3 additions & 1 deletion apps/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ if(LIBUSB_1_FOUND)
endif()

if(VTK_FOUND)
include("${VTK_USE_FILE}")
if(${VTK_VERSION} VERSION_LESS 9.0)
include(${VTK_USE_FILE})
endif()

set(incs "include/pcl/${SUBSYS_NAME}/render_views_tesselated_sphere.h")
set(srcs "src/render_views_tesselated_sphere.cpp")
Expand Down
4 changes: 3 additions & 1 deletion apps/cloud_composer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ if(NOT VTK_FOUND)
else()
set(DEFAULT TRUE)
set(REASON)
include("${VTK_USE_FILE}")
if(${VTK_VERSION} VERSION_LESS 9.0)
include(${VTK_USE_FILE})
endif()
endif()

# QT5 Found?
Expand Down
6 changes: 4 additions & 2 deletions apps/modeler/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ if(NOT VTK_FOUND)
else()
set(DEFAULT TRUE)
set(REASON)
set(VTK_USE_FILE "${VTK_USE_FILE}" CACHE INTERNAL "VTK_USE_FILE")
include("${VTK_USE_FILE}")
if(${VTK_VERSION} VERSION_LESS 9.0)
set(VTK_USE_FILE "${VTK_USE_FILE}" CACHE INTERNAL "VTK_USE_FILE")
include("${VTK_USE_FILE}")
endif()
endif()

# QT5 Found?
Expand Down
23 changes: 20 additions & 3 deletions apps/src/render_views_tesselated_sphere.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <vtkTransformFilter.h>
#include <vtkTriangle.h>
#include <vtkWorldPointPicker.h>
#include <vtkIdTypeArray.h>

#include <array>

Expand All @@ -34,7 +35,13 @@ pcl::apps::RenderViewsTesselatedSphere::generateViews()
{
// center object
double CoM[3];
vtkIdType npts_com = 0, *ptIds_com = nullptr;
vtkIdType npts_com = 0;
#ifdef VTK_CELL_ARRAY_V2
vtkIdType const *ptIds_com = nullptr;
#else
vtkIdType *ptIds_com = nullptr;
#endif

vtkSmartPointer<vtkCellArray> cells_com = polydata_->GetPolys();

double center[3], p1_com[3], p2_com[3], p3_com[3], totalArea_com = 0;
Expand Down Expand Up @@ -95,7 +102,12 @@ pcl::apps::RenderViewsTesselatedSphere::generateViews()
// * Compute area of the mesh
//////////////////////////////
vtkSmartPointer<vtkCellArray> cells = mapper->GetInput()->GetPolys();
vtkIdType npts = 0, *ptIds = nullptr;
vtkIdType npts = 0;
#ifdef VTK_CELL_ARRAY_V2
vtkIdType const *ptIds = nullptr;
#else
vtkIdType *ptIds = nullptr;
#endif

double p1[3], p2[3], p3[3], totalArea = 0;
for (cells->InitTraversal(); cells->GetNextCell(npts, ptIds);) {
Expand Down Expand Up @@ -363,7 +375,12 @@ pcl::apps::RenderViewsTesselatedSphere::generateViews()
polydata->BuildCells();

vtkSmartPointer<vtkCellArray> cells = polydata->GetPolys();
vtkIdType npts = 0, *ptIds = nullptr;
vtkIdType npts = 0;
#ifdef VTK_CELL_ARRAY_V2
vtkIdType const *ptIds = nullptr;
#else
vtkIdType *ptIds = nullptr;
#endif

double p1[3], p2[3], p3[3], area, totalArea = 0;
for (cells->InitTraversal(); cells->GetNextCell(npts, ptIds);) {
Expand Down
136 changes: 136 additions & 0 deletions cmake/pcl_find_vtk.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
#Search for VTK
find_package(VTK NO_MODULE)

if(NOT VTK_FOUND)
return()
endif()

#Exit if version is below
if("${VTK_VERSION}" VERSION_LESS 6.2)
message(WARNING "The minimum required version of VTK is 6.2, but found ${VTK_VERSION}")
set(VTK_FOUND FALSE)
return()
endif()

#Change to use list Transform when cmake is >= 3.12
if(NOT (${VTK_VERSION} VERSION_LESS 9.0))
set(PCL_VTK_COMPONENTS
ChartsCore
CommonColor
CommonCore
CommonDataModel
CommonExecutionModel
CommonMath
CommonMisc
CommonTransforms
FiltersCore
FiltersExtraction
FiltersGeneral
FiltersGeometry
FiltersModeling
FiltersSources
ImagingCore
ImagingSources
InteractionStyle
InteractionWidgets
IOCore
IOGeometry
IOImage
IOLegacy
IOPLY
RenderingAnnotation
RenderingCore
RenderingContext2D
RenderingLOD
RenderingFreeType
RenderingOpenGL2
ViewsCore
ViewsContext2D
)
else()
set(PCL_VTK_COMPONENTS
vtkChartsCore
vtkCommonCore
vtkCommonDataModel
vtkCommonExecutionModel
vtkFiltersCore
vtkFiltersExtraction
vtkFiltersModeling
vtkImagingCore
vtkImagingSources
vtkInteractionStyle
vtkInteractionWidgets
vtkIOCore
vtkIOGeometry
vtkIOImage
vtkIOLegacy
vtkIOPLY
vtkRenderingAnnotation
vtkRenderingLOD
vtkViewsContext2D
)
endif()
Comment on lines +15 to +72
Copy link
Contributor

@SunBlack SunBlack Jun 19, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indentation of set is missing.

Is it really necessary to have two lists? I had started more than one moth ago same test (just didn't had time to continue and as this PR also exists)...

I had solved it by:

function(checkVTKComponents)
  cmake_parse_arguments(PARAM "" "MISSING_COMPONENTS" "COMPONENTS" ${ARGN})

  set(vtkMissingComponents)
  if (VTK_VERSION VERSION_GREATER "8.2")
    foreach(vtkComponent ${PARAM_COMPONENTS})
      if (NOT TARGET VTK::${vtkComponent})
        list(APPEND vtkMissingComponents ${vtkComponent})
      endif()
    endforeach()
  else()
    foreach(vtkComponent ${PARAM_COMPONENTS})
      set(vtkComponent "vtk${vtkComponent}")
      if (NOT TARGET ${vtkComponent})
        list(APPEND vtkMissingComponents ${vtkComponent})
      endif()
    endforeach()
  endif()
  set(${PARAM_MISSING_COMPONENTS} ${vtkMissingComponents} PARENT_SCOPE)
endfunction()

set(PCL_VTK_COMPONENTS
  ChartsCore
  CommonCore
  CommonDataModel
  CommonExecutionModel
  FiltersCore
  FiltersExtraction
  FiltersModeling
  ImagingCore
  ImagingSources
  InteractionStyle
  InteractionWidgets
  IOCore
  IOGeometry
  IOImage
  IOLegacy
  IOPLY
  RenderingAnnotation
  RenderingLOD
  ViewsContext2D
)

# Start with a generic call to find any VTK version we are supporting, so we retrieve
# the version of VTK. As the module names were changed from VTK 8.2 to 9.0, we don't
# search explicitly for modules. Furthermore we don't pass required minimum version 6.2
# to find_package because then it only accept versions with same major version.
find_package(VTK)
if(VTK_FOUND AND ("${VTK_VERSION}" VERSION_LESS 6.2))
  message(WARNING "The minimum required version of VTK is 6.2, but found ${VTK_VERSION}")
  set(VTK_FOUND FALSE)
  return()
endif()

# We still require vtkOpenGLExtensionManager and vtkOpenGLRenderWindow
# Before VTK 8.2 they were part of VTK compontent
# Since VTK 8.2 they were part of VTK compontent vtkOpenGLRenderWindow => "OpenGL2", vtkOpenGLExtensionManager => missing
if("${VTK_VERSION}" VERSION_LESS 8.2)
  set(VTK_RENDERING_BACKEND "OpenGL")
else()
  set(VTK_RENDERING_BACKEND "OpenGL2")
endif()

# Check if requested modules are available
checkVTKComponents(COMPONENTS ${PCL_VTK_COMPONENTS} MISSING_COMPONENTS vtkMissingComponents)
message(STATUS "${vtkMissingComponents}")
if (vtkMissingComponents)
  set(VTK_FOUND FALSE)
  message(WARNING "Missing vtk modules: ${vtkMissingComponents}")
  return()
endif()

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll look into using your snippet.

Originally it was using List transform, but that wasn't available. But an "ordinary" foreach could be used ofc.


if(NOT DEFINED VTK_RENDERING_BACKEND)
# Use OpenGL backend pre 8.1, else use OpenGL2
if(${VTK_VERSION} VERSION_LESS 8.1)
set(VTK_RENDERING_BACKEND "OpenGL")
else()
set(VTK_RENDERING_BACKEND "OpenGL2")
endif()
endif()

if(${VTK_VERSION} VERSION_LESS 9.0)
list(APPEND PCL_VTK_COMPONENTS vtkRenderingContext${VTK_RENDERING_BACKEND})
else()
list(APPEND PCL_VTK_COMPONENTS RenderingUI) # not available < 9.0 so append here.
list(APPEND PCL_VTK_COMPONENTS RenderingContext${VTK_RENDERING_BACKEND})
endif()

message("WITH_QT is:${WITH_QT}")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add a space after the colon 🙂

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was more for 'debugging' - but I guess the information is nice to have, but could probably be consolidated to a single line summerizing most of the VTK settings 😄

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There was an issue about producing a full-blown CMake configuration report for PCL, maybe it's the kind of information that could go there when it happens.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's something nice and available in 3.5 too (Ubuntu 16.04's CMake version)

@Morwenn is there a issue for this CMake reporting?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kunaltyagi I thought so but apparently it was merely a comment in issue #3603, my memory failed me. Such a summary is definitely something valuable when dealing with build issues (and especially good when users report issues, you don't have to ask again and again for the information). I didn't know that CMake had a built-in feature to report the options, that's nice.

if(WITH_QT)
message("VTK_MODULES_ENABLED is: ${VTK_MODULES_ENABLED}")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VTK 9.0 has "VTK_AVAILABLE_COMPONENTS" instead of "VTK_MODULES_ENABLED"

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for mentioning it. Saw it yesterday as well :-)

if(";${VTK_MODULES_ENABLED};" MATCHES ";vtkGUISupportQt;" AND ";${VTK_MODULES_ENABLED};" MATCHES ";vtkRenderingQt;")
set(QVTK_FOUND ON)
if(NOT (${VTK_VERSION} VERSION_LESS 9.0))
list(APPEND PCL_VTK_COMPONENTS RenderingQt GUISupportQt)
else()
list(APPEND PCL_VTK_COMPONENTS vtkRenderingQt vtkGUISupportQt)
endif()
else()
unset(QVTK_FOUND)
endif()
endif()

find_package(VTK NO_MODULE COMPONENTS ${PCL_VTK_COMPONENTS})

message(STATUS "VTK_MAJOR_VERSION ${VTK_MAJOR_VERSION}, rendering backend: ${VTK_RENDERING_BACKEND}")

if(PCL_SHARED_LIBS OR (NOT (PCL_SHARED_LIBS) AND NOT (VTK_BUILD_SHARED_LIBS)))
if(${VTK_VERSION} VERSION_LESS 9.0)
if(VTK_USE_FILE)
include(${VTK_USE_FILE})
endif()

message(STATUS "VTK found (include: ${VTK_INCLUDE_DIRS}, libs: ${VTK_LIBRARIES}")
endif()

if(APPLE)
option(VTK_USE_COCOA "Use Cocoa for VTK render windows" ON)
mark_as_advanced(VTK_USE_COCOA)
endif()

if(${VTK_RENDERING_BACKEND} STREQUAL "OpenGL")
set(VTK_RENDERING_BACKEND_OPENGL_VERSION "1")
message(DEPRECATION "The rendering backend OpenGL is deprecated and not available anymore since VTK 8.2."
"Please switch to the OpenGL2 backend instead, which is available since VTK 6.2."
"Support of the deprecated backend will be dropped with PCL 1.13.")
elseif(${VTK_RENDERING_BACKEND} STREQUAL "OpenGL2")
set(VTK_RENDERING_BACKEND_OPENGL_VERSION "2")
endif()

else()
set(VTK_FOUND OFF)
message("Warning: You are to build PCL in STATIC but VTK is SHARED!")
message("Warning: VTK disabled!")
endif()
10 changes: 6 additions & 4 deletions examples/keypoints/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ PCL_SUBSYS_DEPEND(build ${SUBSYS_NAME} DEPS visualization)

## Find VTK
if(NOT VTK_FOUND)
set(DEFAULT FALSE)
set(REASON "VTK was not found.")
set(DEFAULT FALSE)
set(REASON "VTK was not found.")
else()
set(DEFAULT TRUE)
set(REASON)
set(DEFAULT TRUE)
set(REASON)
if(${VTK_VERSION} VERSION_LESS 9.0)
include(${VTK_USE_FILE})
endif()
endif()

PCL_ADD_EXAMPLE(pcl_example_sift_keypoint_estimation FILES example_sift_keypoint_estimation.cpp
Expand Down
4 changes: 3 additions & 1 deletion examples/outofcore/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ if(NOT VTK_FOUND)
else()
set(DEFAULT TRUE)
set(REASON)
include(${VTK_USE_FILE})
if(${VTK_VERSION} VERSION_LESS 9.0)
include(${VTK_USE_FILE})
endif()
endif()

PCL_SUBSYS_DEPEND (build ${SUBSYS_NAME} DEPS outofcore io common octree filters visualization EXT_DEPS vtk)
Expand Down
5 changes: 4 additions & 1 deletion examples/segmentation/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ PCL_ADD_EXAMPLE(pcl_example_region_growing FILES example_region_growing.cpp

## Find VTK
if(VTK_FOUND)
include(${VTK_USE_FILE})
if(${VTK_VERSION} VERSION_LESS 9.0)
include(${VTK_USE_FILE})
endif()

PCL_ADD_EXAMPLE(pcl_example_supervoxels FILES example_supervoxels.cpp
LINK_WITH pcl_common pcl_features pcl_segmentation pcl_octree pcl_kdtree pcl_visualization)
PCL_ADD_EXAMPLE(pcl_example_lccp_segmentation FILES example_lccp_segmentation.cpp
Expand Down
4 changes: 3 additions & 1 deletion examples/stereo/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ if(NOT VTK_FOUND)
else()
set(DEFAULT TRUE)
set(REASON)
include(${VTK_USE_FILE})
if(${VTK_VERSION} VERSION_LESS 9.0)
include(${VTK_USE_FILE})
endif()
endif()

PCL_ADD_EXAMPLE(pcl_example_stereo_baseline FILES example_stereo_baseline.cpp
Expand Down
4 changes: 3 additions & 1 deletion examples/surface/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ if(NOT VTK_FOUND)
else()
set(DEFAULT TRUE)
set(REASON)
include(${VTK_USE_FILE})
if(${VTK_VERSION} VERSION_LESS 9.0)
include(${VTK_USE_FILE})
endif()
endif()

PCL_ADD_EXAMPLE(pcl_test_nurbs_fitting_surface
Expand Down
6 changes: 4 additions & 2 deletions gpu/kinfu/tools/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ if(NOT VTK_FOUND)
else()
set(DEFAULT TRUE)
set(REASON)
set(VTK_USE_FILE "${VTK_USE_FILE}" CACHE INTERNAL "VTK_USE_FILE")
include("${VTK_USE_FILE}")
if(${VTK_VERSION} VERSION_LESS 9.0)
set(VTK_USE_FILE ${VTK_USE_FILE} CACHE INTERNAL "VTK_USE_FILE")
include(${VTK_USE_FILE})
endif()
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/include")
endif()

Expand Down
Loading