diff --git a/2d/CMakeLists.txt b/2d/CMakeLists.txt index 8bd5411e446..437d23fb471 100644 --- a/2d/CMakeLists.txt +++ b/2d/CMakeLists.txt @@ -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() diff --git a/CMakeLists.txt b/CMakeLists.txt index 9422d97ba90..e847142108a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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() diff --git a/apps/3d_rec_framework/CMakeLists.txt b/apps/3d_rec_framework/CMakeLists.txt index ec6c56d8fa7..aea22fb66bf 100644 --- a/apps/3d_rec_framework/CMakeLists.txt +++ b/apps/3d_rec_framework/CMakeLists.txt @@ -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? diff --git a/apps/CMakeLists.txt b/apps/CMakeLists.txt index c4ef60c6f92..1a559687842 100644 --- a/apps/CMakeLists.txt +++ b/apps/CMakeLists.txt @@ -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") diff --git a/apps/cloud_composer/CMakeLists.txt b/apps/cloud_composer/CMakeLists.txt index d70e4bb5439..0dfdedb1e9e 100644 --- a/apps/cloud_composer/CMakeLists.txt +++ b/apps/cloud_composer/CMakeLists.txt @@ -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? diff --git a/apps/modeler/CMakeLists.txt b/apps/modeler/CMakeLists.txt index 7b1d14b5804..1cc01c9851d 100644 --- a/apps/modeler/CMakeLists.txt +++ b/apps/modeler/CMakeLists.txt @@ -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? diff --git a/apps/src/render_views_tesselated_sphere.cpp b/apps/src/render_views_tesselated_sphere.cpp index e329551b696..57487a1205b 100644 --- a/apps/src/render_views_tesselated_sphere.cpp +++ b/apps/src/render_views_tesselated_sphere.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #include @@ -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 cells_com = polydata_->GetPolys(); double center[3], p1_com[3], p2_com[3], p3_com[3], totalArea_com = 0; @@ -95,7 +102,12 @@ pcl::apps::RenderViewsTesselatedSphere::generateViews() // * Compute area of the mesh ////////////////////////////// vtkSmartPointer 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);) { @@ -363,7 +375,12 @@ pcl::apps::RenderViewsTesselatedSphere::generateViews() polydata->BuildCells(); vtkSmartPointer 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);) { diff --git a/cmake/pcl_find_vtk.cmake b/cmake/pcl_find_vtk.cmake new file mode 100644 index 00000000000..6e5813069ca --- /dev/null +++ b/cmake/pcl_find_vtk.cmake @@ -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() + +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}") +if(WITH_QT) + message("VTK_MODULES_ENABLED is: ${VTK_MODULES_ENABLED}") + 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() diff --git a/examples/keypoints/CMakeLists.txt b/examples/keypoints/CMakeLists.txt index 133bfed82af..a7ac3c68491 100644 --- a/examples/keypoints/CMakeLists.txt +++ b/examples/keypoints/CMakeLists.txt @@ -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 diff --git a/examples/outofcore/CMakeLists.txt b/examples/outofcore/CMakeLists.txt index aed932e9b50..7fb93b42e9c 100644 --- a/examples/outofcore/CMakeLists.txt +++ b/examples/outofcore/CMakeLists.txt @@ -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) diff --git a/examples/segmentation/CMakeLists.txt b/examples/segmentation/CMakeLists.txt index 5e672fd8213..ca35a832c2d 100644 --- a/examples/segmentation/CMakeLists.txt +++ b/examples/segmentation/CMakeLists.txt @@ -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 diff --git a/examples/stereo/CMakeLists.txt b/examples/stereo/CMakeLists.txt index 518d104942b..853090b74ca 100644 --- a/examples/stereo/CMakeLists.txt +++ b/examples/stereo/CMakeLists.txt @@ -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 diff --git a/examples/surface/CMakeLists.txt b/examples/surface/CMakeLists.txt index ec9f030d610..0ff87a34dd7 100644 --- a/examples/surface/CMakeLists.txt +++ b/examples/surface/CMakeLists.txt @@ -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 diff --git a/gpu/kinfu/tools/CMakeLists.txt b/gpu/kinfu/tools/CMakeLists.txt index 8ef3d920df0..5733516170e 100644 --- a/gpu/kinfu/tools/CMakeLists.txt +++ b/gpu/kinfu/tools/CMakeLists.txt @@ -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() diff --git a/gpu/kinfu_large_scale/tools/CMakeLists.txt b/gpu/kinfu_large_scale/tools/CMakeLists.txt index 9df2535a5c8..4e10ce821ae 100644 --- a/gpu/kinfu_large_scale/tools/CMakeLists.txt +++ b/gpu/kinfu_large_scale/tools/CMakeLists.txt @@ -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() diff --git a/gpu/people/tools/CMakeLists.txt b/gpu/people/tools/CMakeLists.txt index 3d45dbc42a7..d47fb301c53 100644 --- a/gpu/people/tools/CMakeLists.txt +++ b/gpu/people/tools/CMakeLists.txt @@ -6,8 +6,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() diff --git a/io/CMakeLists.txt b/io/CMakeLists.txt index f2349710020..d3576576c0e 100644 --- a/io/CMakeLists.txt +++ b/io/CMakeLists.txt @@ -331,10 +331,25 @@ endif() set(LIB_NAME "pcl_${SUBSYS_NAME}") add_definitions(${VTK_DEFINES}) + PCL_ADD_LIBRARY(${LIB_NAME} COMPONENT ${SUBSYS_NAME} SOURCES ${srcs} ${incs} ${compression_incs} ${impl_incs} ${OPENNI_INCLUDES} ${OPENNI2_INCLUDES}) + target_include_directories(${LIB_NAME} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include") -link_directories(${VTK_LINK_DIRECTORIES}) -target_link_libraries("${LIB_NAME}" pcl_common pcl_io_ply ${VTK_LIBRARIES}) + +target_link_libraries("${LIB_NAME}" pcl_common pcl_io_ply) + +if(VTK_FOUND) + if(${VTK_VERSION} VERSION_LESS 9.0) + link_directories(${VTK_LINK_DIRECTORIES}) + target_link_libraries("${LIB_NAME}" ${VTK_LIBRARIES}) + else() + target_link_libraries("${LIB_NAME}" + VTK::IOImage + VTK::IOGeometry + VTK::IOPLY) + endif() +endif() + if(PNG_FOUND) target_link_libraries("${LIB_NAME}" ${PNG_LIBRARIES}) endif() diff --git a/io/src/vtk_lib_io.cpp b/io/src/vtk_lib_io.cpp index 37e9df4cc7c..35b42d9b724 100644 --- a/io/src/vtk_lib_io.cpp +++ b/io/src/vtk_lib_io.cpp @@ -343,7 +343,11 @@ pcl::io::vtk2mesh (const vtkSmartPointer& poly_data, pcl::PolygonMe // Now handle the polygons mesh.polygons.resize (nr_polygons); +#ifdef VTK_CELL_ARRAY_V2 + vtkIdType const *cell_points; +#else vtkIdType* cell_points; +#endif vtkIdType nr_cell_points; vtkCellArray * mesh_polygons = poly_data->GetPolys (); mesh_polygons->InitTraversal (); diff --git a/outofcore/tools/CMakeLists.txt b/outofcore/tools/CMakeLists.txt index 53c63e3940a..37ca2079bf1 100644 --- a/outofcore/tools/CMakeLists.txt +++ b/outofcore/tools/CMakeLists.txt @@ -13,8 +13,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") set(srcs outofcore_viewer.cpp diff --git a/people/CMakeLists.txt b/people/CMakeLists.txt index 4778e2f1c53..66cfede8969 100644 --- a/people/CMakeLists.txt +++ b/people/CMakeLists.txt @@ -8,8 +8,6 @@ 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}") include_directories("${CMAKE_CURRENT_SOURCE_DIR}/include") endif() diff --git a/surface/CMakeLists.txt b/surface/CMakeLists.txt index e5e42311389..6ab1917f084 100644 --- a/surface/CMakeLists.txt +++ b/surface/CMakeLists.txt @@ -4,7 +4,7 @@ set(SUBSYS_DEPS common search kdtree octree) set(build TRUE) PCL_SUBSYS_OPTION(build "${SUBSYS_NAME}" "${SUBSYS_DESC}" ON) -PCL_SUBSYS_DEPEND(build "${SUBSYS_NAME}" DEPS ${SUBSYS_DEPS} OPT_DEPS qhull) +PCL_SUBSYS_DEPEND(build "${SUBSYS_NAME}" DEPS ${SUBSYS_DEPS} EXT_DEPS vtk OPT_DEPS qhull) PCL_ADD_DOC("${SUBSYS_NAME}") @@ -149,19 +149,32 @@ set(impl_incs ) set(LIB_NAME "pcl_${SUBSYS_NAME}") + include_directories( "${CMAKE_CURRENT_SOURCE_DIR}/include" "${CMAKE_CURRENT_SOURCE_DIR}" ) -include_directories(SYSTEM - ${VTK_INCLUDE_DIRS} -) -link_directories(${VTK_LIBRARY_DIRS}) PCL_ADD_LIBRARY(${LIB_NAME} COMPONENT ${SUBSYS_NAME} SOURCES ${srcs} ${incs} ${impl_incs} ${VTK_SMOOTHING_INCLUDES} ${POISSON_INCLUDES} ${OPENNURBS_INCLUDES} ${ON_NURBS_INCLUDES}) -target_link_libraries("${LIB_NAME}" pcl_common pcl_search pcl_kdtree pcl_octree ${VTK_LIBRARIES} ${ON_NURBS_LIBRARIES}) + +target_link_libraries("${LIB_NAME}" pcl_common pcl_search pcl_kdtree pcl_octree ${ON_NURBS_LIBRARIES}) + +if(VTK_FOUND) + if(${VTK_VERSION} VERSION_LESS 9.0) + include_directories(SYSTEM ${VTK_INCLUDE_DIRS}) + link_directories(${VTK_LIBRARY_DIRS}) + target_link_libraries("${LIB_NAME}" ${VTK_LIBRARIES}) + else() + target_link_libraries("${LIB_NAME}" VTK::CommonDataModel + VTK::CommonExecutionModel + VTK::FiltersModeling + VTK::FiltersCore) + endif() +endif() + if(QHULL_FOUND) target_link_libraries("${LIB_NAME}" ${QHULL_LIBRARIES}) endif() + PCL_MAKE_PKGCONFIG(${LIB_NAME} COMPONENT ${SUBSYS_NAME} DESC ${SUBSYS_DESC} PCL_DEPS ${SUBSYS_DEPS}) # Install include files @@ -178,6 +191,7 @@ endif() if(VTK_FOUND AND NOT ANDROID) PCL_ADD_INCLUDES("${SUBSYS_NAME}" "${SUBSYS_NAME}/vtk_smoothing" ${VTK_SMOOTHING_INCLUDES}) endif() + if(WIN32) target_link_libraries("${LIB_NAME}" Rpcrt4.lib) endif() diff --git a/surface/src/vtk_smoothing/vtk_utils.cpp b/surface/src/vtk_smoothing/vtk_utils.cpp index cbd8059358f..756b8cce1ab 100644 --- a/surface/src/vtk_smoothing/vtk_utils.cpp +++ b/surface/src/vtk_smoothing/vtk_utils.cpp @@ -48,6 +48,7 @@ #include #include #include +#include // Support for VTK 7.1 upwards #ifdef vtkGenericDataArray_h @@ -154,7 +155,11 @@ pcl::VTKUtils::vtk2mesh (const vtkSmartPointer& poly_data, pcl::Pol } mesh.polygons.resize (nr_polygons); +#ifdef VTK_CELL_ARRAY_V2 + vtkIdType const *cell_points; +#else vtkIdType* cell_points; +#endif vtkIdType nr_cell_points; vtkCellArray * mesh_polygons = poly_data->GetPolys (); mesh_polygons->InitTraversal (); diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index 1911f7b9f40..5118dc85f5f 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -200,12 +200,18 @@ else() PCL_ADD_EXECUTABLE(pcl_obj2pcd COMPONENT ${SUBSYS_NAME} SOURCES obj2pcd.cpp) target_link_libraries(pcl_obj2pcd pcl_common pcl_io) + if(NOT (${VTK_VERSION} VERSION_LESS 9.0)) + target_link_libraries(pcl_obj2pcd VTK::FiltersCore) + endif() PCL_ADD_EXECUTABLE(pcl_obj2ply COMPONENT ${SUBSYS_NAME} SOURCES obj2ply.cpp) target_link_libraries(pcl_obj2ply pcl_common pcl_io) PCL_ADD_EXECUTABLE(pcl_vtk2pcd COMPONENT ${SUBSYS_NAME} SOURCES vtk2pcd.cpp) target_link_libraries(pcl_vtk2pcd pcl_common pcl_io) + if(NOT (${VTK_VERSION} VERSION_LESS 9.0)) + target_link_libraries(pcl_vtk2pcd VTK::FiltersCore) + endif() if(BUILD_visualization) PCL_ADD_EXECUTABLE(pcl_obj_rec_ransac_model_opps COMPONENT ${SUBSYS_NAME} SOURCES obj_rec_ransac_model_opps.cpp) diff --git a/tools/mesh_sampling.cpp b/tools/mesh_sampling.cpp index 23f98d7c1d0..d427c180cc3 100644 --- a/tools/mesh_sampling.cpp +++ b/tools/mesh_sampling.cpp @@ -87,7 +87,11 @@ randPSurface (vtkPolyData * polydata, std::vector * cumulativeAreas, dou double A[3], B[3], C[3]; vtkIdType npts = 0; +#ifdef VTK_CELL_ARRAY_V2 + vtkIdType const *ptIds = nullptr; +#else vtkIdType *ptIds = nullptr; +#endif polydata->GetCellPoints (el, npts, ptIds); polydata->GetPoint (ptIds[0], A); polydata->GetPoint (ptIds[1], B); @@ -138,7 +142,12 @@ uniform_sampling (vtkSmartPointer polydata, std::size_t n_samples, double p1[3], p2[3], p3[3], totalArea = 0; std::vector cumulativeAreas (cells->GetNumberOfCells (), 0); - vtkIdType npts = 0, *ptIds = nullptr; + vtkIdType npts = 0; +#ifdef VTK_CELL_ARRAY_V2 + vtkIdType const *ptIds = nullptr; +#else + vtkIdType *ptIds = nullptr; +#endif std::size_t cellId = 0; for (cells->InitTraversal (); cells->GetNextCell (npts, ptIds); cellId++) { diff --git a/visualization/CMakeLists.txt b/visualization/CMakeLists.txt index 990a5f5b2bc..1849cdcc8f9 100644 --- a/visualization/CMakeLists.txt +++ b/visualization/CMakeLists.txt @@ -134,14 +134,37 @@ endif() set(LIB_NAME "pcl_${SUBSYS_NAME}") PCL_ADD_LIBRARY(${LIB_NAME} COMPONENT ${SUBSYS_NAME} SOURCES ${srcs} ${incs} ${common_incs} ${impl_incs} ${common_impl_incs} ${vtk_incs}) -target_include_directories("${LIB_NAME}" SYSTEM PUBLIC ${VTK_INCLUDE_DIRS}) - # apple workaround (continued) if(APPLE) target_link_libraries("${LIB_NAME}" "-framework Cocoa") endif() -target_link_libraries("${LIB_NAME}" pcl_common pcl_io pcl_kdtree ${VTK_LIBRARIES} ${OPENGL_LIBRARIES}) +target_link_libraries("${LIB_NAME}" pcl_common pcl_io pcl_kdtree ${OPENGL_LIBRARIES}) + +if(${VTK_VERSION} VERSION_LESS 9.0) + target_include_directories("${LIB_NAME}" SYSTEM PUBLIC ${VTK_INCLUDE_DIRS}) + target_link_libraries("${LIB_NAME}" ${VTK_LIBRARIES}) +else() + #Some libs are referenced through depending on IO + target_link_libraries("${LIB_NAME}" + VTK::ChartsCore + VTK::CommonColor + VTK::CommonDataModel + VTK::FiltersExtraction + VTK::FiltersGeneral + VTK::FiltersModeling + VTK::FiltersSources + VTK::IOImage + VTK::IOPLY + VTK::ImagingSources + VTK::InteractionStyle + VTK::RenderingAnnotation + VTK::RenderingContext2D + VTK::RenderingFreeType + VTK::RenderingLOD + VTK::RenderingOpenGL2 + VTK::ViewsContext2D) +endif() set(EXT_DEPS "") if(WITH_OPENNI) @@ -171,6 +194,12 @@ PCL_ADD_INCLUDES("${SUBSYS_NAME}" "${SUBSYS_NAME}/impl" ${impl_incs}) PCL_ADD_INCLUDES("${SUBSYS_NAME}" "${SUBSYS_NAME}/common/impl" ${common_impl_incs}) PCL_ADD_INCLUDES("${SUBSYS_NAME}" "${SUBSYS_NAME}/vtk" ${vtk_incs}) +if(NOT (${VTK_VERSION} VERSION_LESS 9.0)) + vtk_module_autoinit(TARGETS "${LIB_NAME}" + MODULES VTK::RenderingOpenGL2 + VTK::RenderingFreeType) +endif() + if(BUILD_TESTS) add_subdirectory(test) endif() diff --git a/visualization/include/pcl/visualization/common/actor_map.h b/visualization/include/pcl/visualization/common/actor_map.h index 8434d670939..e03aa1805b9 100644 --- a/visualization/include/pcl/visualization/common/actor_map.h +++ b/visualization/include/pcl/visualization/common/actor_map.h @@ -43,6 +43,7 @@ #include #include +#include #include #include diff --git a/visualization/include/pcl/visualization/impl/pcl_visualizer.hpp b/visualization/include/pcl/visualization/impl/pcl_visualizer.hpp index 4b4900e3808..bf8e3d3230a 100644 --- a/visualization/include/pcl/visualization/impl/pcl_visualizer.hpp +++ b/visualization/include/pcl/visualization/impl/pcl_visualizer.hpp @@ -1701,8 +1701,32 @@ pcl::visualization::PCLVisualizer::addPolygonMesh ( { // Create polys from polyMesh.polygons vtkSmartPointer cell_array = vtkSmartPointer::New (); - vtkIdType *cell = cell_array->WritePointer (vertices.size (), vertices.size () * (max_size_of_polygon + 1)); int idx = 0; + +#ifdef VTK_CELL_ARRAY_V2 + if (!lookup.empty ()) + { + for (std::size_t i = 0; i < vertices.size (); ++i, ++idx) + { + std::size_t n_points = vertices[i].vertices.size (); + cell_array->InsertNextCell (n_points); + for (std::size_t j = 0; j < n_points; j++, ++idx) + cell_array->InsertCellPoint (lookup[vertices[i].vertices[j]]); + } + } + else + { + for (std::size_t i = 0; i < vertices.size (); ++i, ++idx) + { + std::size_t n_points = vertices[i].vertices.size (); + cell_array->InsertNextCell (n_points); + for (std::size_t j = 0; j < n_points; j++, ++idx) + cell_array->InsertCellPoint (vertices[i].vertices[j]); + } + } +#else + vtkIdType *cell = cell_array->WritePointer (vertices.size (), vertices.size () * (max_size_of_polygon + 1)); + if (!lookup.empty ()) { for (std::size_t i = 0; i < vertices.size (); ++i, ++idx) @@ -1727,6 +1751,7 @@ pcl::visualization::PCLVisualizer::addPolygonMesh ( //cell_array->InsertCellPoint (vertices[i].vertices[j]); } } +#endif vtkSmartPointer polydata; allocVtkPolyData (polydata); cell_array->GetData ()->SetNumberOfValues (idx); @@ -1878,8 +1903,36 @@ pcl::visualization::PCLVisualizer::updatePolygonMesh ( // Update the cells cells = vtkSmartPointer::New (); - vtkIdType *cell = cells->WritePointer (verts.size (), verts.size () * (max_size_of_polygon + 1)); int idx = 0; + +#ifdef VTK_CELL_ARRAY_V2 + if (!lookup.empty ()) + { + for (std::size_t i = 0; i < verts.size (); ++i, ++idx) + { + std::size_t n_points = verts[i].vertices.size (); + cells->InsertNextCell (n_points); + for (std::size_t j = 0; j < n_points; j++, ++idx) + { + cells->InsertCellPoint (lookup[verts[i].vertices[j]]); + + } + } + } + else + { + for (std::size_t i = 0; i < verts.size (); ++i, ++idx) + { + std::size_t n_points = verts[i].vertices.size (); + cells->InsertNextCell (n_points); + for (std::size_t j = 0; j < n_points; j++, ++idx) + { + cells->InsertCellPoint(verts[i].vertices[j]); + } + } + } +#else + vtkIdType *cell = cells->WritePointer (verts.size (), verts.size () * (max_size_of_polygon + 1)); if (!lookup.empty ()) { for (std::size_t i = 0; i < verts.size (); ++i, ++idx) @@ -1900,6 +1953,7 @@ pcl::visualization::PCLVisualizer::updatePolygonMesh ( *cell = verts[i].vertices[j]; } } +#endif cells->GetData ()->SetNumberOfValues (idx); cells->Squeeze (); // Set the the vertices diff --git a/visualization/include/pcl/visualization/interactor_style.h b/visualization/include/pcl/visualization/interactor_style.h index 0f166b75dd2..a1f17238e0e 100644 --- a/visualization/include/pcl/visualization/interactor_style.h +++ b/visualization/include/pcl/visualization/interactor_style.h @@ -51,6 +51,8 @@ #include #endif #include +#include +#include class vtkRendererCollection; class vtkLegendScaleActor; diff --git a/visualization/src/cloud_viewer.cpp b/visualization/src/cloud_viewer.cpp index b0b32a1af2d..83fa99bbafa 100644 --- a/visualization/src/cloud_viewer.cpp +++ b/visualization/src/cloud_viewer.cpp @@ -40,6 +40,9 @@ #include #include +#include +#include + #include #include diff --git a/visualization/src/interactor_style.cpp b/visualization/src/interactor_style.cpp index 4740577cfbf..f2efbdfd96d 100644 --- a/visualization/src/interactor_style.cpp +++ b/visualization/src/interactor_style.cpp @@ -36,6 +36,7 @@ * */ +#include #include #include #include @@ -137,7 +138,7 @@ pcl::visualization::PCLVisualizerInteractorStyle::saveCameraParameters (const st { FindPokedRenderer (Interactor->GetEventPosition ()[0], Interactor->GetEventPosition ()[1]); - ofstream ofs_cam (file.c_str ()); + std::ofstream ofs_cam (file.c_str ()); if (!ofs_cam.is_open ()) { return (false); diff --git a/visualization/src/pcl_visualizer.cpp b/visualization/src/pcl_visualizer.cpp index 0d6f9a44065..45bd2956c30 100644 --- a/visualization/src/pcl_visualizer.cpp +++ b/visualization/src/pcl_visualizer.cpp @@ -3160,8 +3160,33 @@ pcl::visualization::PCLVisualizer::updatePolygonMesh ( // Update the cells cells = vtkSmartPointer::New (); - vtkIdType *cell = cells->WritePointer (verts.size (), verts.size () * (max_size_of_polygon + 1)); int idx = 0; + +#ifdef VTK_CELL_ARRAY_V2 + if (!lookup.empty ()) + { + for (std::size_t i = 0; i < verts.size (); ++i, ++idx) + { + std::size_t n_points = verts[i].vertices.size (); + cells->InsertNextCell(n_points); + for (std::size_t j = 0; j < n_points; j++, ++idx) + cells->InsertCellPoint(lookup[verts[i].vertices[j]]); + } + } + else + { + for (std::size_t i = 0; i < verts.size (); ++i, ++idx) + { + std::size_t n_points = verts[i].vertices.size (); + cells->InsertNextCell(n_points); + for (std::size_t j = 0; j < n_points; j++, ++idx) + { + cells->InsertCellPoint(verts[i].vertices[j]); + } + } + } +#else + vtkIdType *cell = cells->WritePointer (verts.size (), verts.size () * (max_size_of_polygon + 1)); if (!lookup.empty ()) { for (std::size_t i = 0; i < verts.size (); ++i, ++idx) @@ -3182,6 +3207,7 @@ pcl::visualization::PCLVisualizer::updatePolygonMesh ( *cell = verts[i].vertices[j]; } } +#endif cells->GetData ()->SetNumberOfValues (idx); cells->Squeeze (); // Set the the vertices @@ -3552,7 +3578,12 @@ pcl::visualization::PCLVisualizer::renderViewTesselatedSphere ( //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 cells_com = polydata->GetPolys (); double center[3], p1_com[3], p2_com[3], p3_com[3], totalArea_com = 0; @@ -3611,7 +3642,12 @@ pcl::visualization::PCLVisualizer::renderViewTesselatedSphere ( // * Compute area of the mesh ////////////////////////////// vtkSmartPointer 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);) @@ -3830,7 +3866,12 @@ pcl::visualization::PCLVisualizer::renderViewTesselatedSphere ( polydata->BuildCells (); vtkSmartPointer 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);)