Skip to content

vtk9 patch #4095

@pionex

Description

@pionex

This isn't a pull request because it is not tested, but I have created a patch that at least allows PCL 1.10.1 and 1.11 to compile against VTK9 as I wanted to test out some features in the new VTK. Most of the questionable changes have to do with the cell points in meshes that others are working on. I found some comments in the code where it looked like someone had an alternative to the cell pointers, and I just went with those and it compiled, but again its untested. I just wanted to share this in case its useful to someone working on this issue.

pcl-1.10.1-vtk9-eigen3.3.90-c++17.patch.txt

Maintainer Edit:

Expanding it here for ease of view
From 00880d36d72b66c2ad1a908a5cbcd26bb457f855 Mon Sep 17 00:00:00 2001
From: Matt Middleton <mmiddleton@wynright.com>
Date: Fri, 1 May 2020 23:16:04 +1200
Subject: [PATCH] Fixes to compile with vtk9, eigen 3.3.90, and built with
 c++17

---
 CMakeLists.txt                                | 44 +++++++++----------
 io/src/vtk_lib_io.cpp                         |  2 +-
 surface/src/vtk_smoothing/vtk_utils.cpp       |  3 +-
 .../pcl/visualization/impl/pcl_visualizer.hpp | 41 ++++++++++-------
 .../pcl/visualization/interactor_style.h      |  2 +
 visualization/src/interactor_style.cpp        |  3 +-
 visualization/src/pcl_visualizer.cpp          | 31 ++++++++-----
 7 files changed, 75 insertions(+), 51 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index f0bc23967..145189a4b 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -8,7 +8,7 @@ if(POLICY CMP0074)
 endif()
 
 # Set target C++ standard and required compiler features
-set(CMAKE_CXX_STANDARD 14 CACHE STRING "The target C++ standard. PCL requires C++14 or higher.")
+set(CMAKE_CXX_STANDARD 17 CACHE STRING "The target C++ standard. PCL requires C++14 or higher.")
 set(CMAKE_CXX_STANDARD_REQUIRED ON)
 set(CMAKE_CXX_EXTENSIONS OFF)
 if(CMAKE_VERSION VERSION_LESS 3.8)
@@ -379,25 +379,25 @@ endif()
 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
+    ChartsCore
+    CommonCore
+    CommonDataModel
+    CommonExecutionModel
+    FiltersCore
+    FiltersExtraction
+    FiltersModeling
+    ImagingCore
+    ImagingSources
+    InteractionStyle
+    InteractionWidgets
+    IOCore
+    IOGeometry
+    IOImage
+    IOLegacy
+    IOPLY
+    RenderingAnnotation
+    RenderingLOD
+    ViewsContext2D
   )
   find_package(VTK COMPONENTS ${PCL_VTK_COMPONENTS})
   if(VTK_FOUND AND ("${VTK_VERSION}" VERSION_LESS 6.2))
@@ -409,9 +409,9 @@ if(WITH_VTK AND NOT ANDROID)
     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")
+      set(VTK_RENDERING_BACKEND "OpenGL2")
     endif()
-    list(APPEND PCL_VTK_COMPONENTS vtkRenderingContext${VTK_RENDERING_BACKEND})
+    list(APPEND PCL_VTK_COMPONENTS RenderingContext${VTK_RENDERING_BACKEND})
 
     if(WITH_QT)
       if(";${VTK_MODULES_ENABLED};" MATCHES ";vtkGUISupportQt;" AND ";${VTK_MODULES_ENABLED};" MATCHES ";vtkRenderingQt;")
diff --git a/io/src/vtk_lib_io.cpp b/io/src/vtk_lib_io.cpp
index 37e9df4cc..f902d0f1a 100644
--- a/io/src/vtk_lib_io.cpp
+++ b/io/src/vtk_lib_io.cpp
@@ -343,7 +343,7 @@ pcl::io::vtk2mesh (const vtkSmartPointer<vtkPolyData>& poly_data, pcl::PolygonMe
 
   // Now handle the polygons
   mesh.polygons.resize (nr_polygons);
-  vtkIdType* cell_points;
+  vtkIdType const* cell_points;
   vtkIdType nr_cell_points;
   vtkCellArray * mesh_polygons = poly_data->GetPolys ();
   mesh_polygons->InitTraversal ();
diff --git a/surface/src/vtk_smoothing/vtk_utils.cpp b/surface/src/vtk_smoothing/vtk_utils.cpp
index cbd805935..d2e59b01a 100644
--- a/surface/src/vtk_smoothing/vtk_utils.cpp
+++ b/surface/src/vtk_smoothing/vtk_utils.cpp
@@ -48,6 +48,7 @@
 #include <vtkPolyData.h>
 #include <vtkPointData.h>
 #include <vtkFloatArray.h>
+#include <vtkUnsignedCharArray.h>
 
 // Support for VTK 7.1 upwards
 #ifdef vtkGenericDataArray_h
@@ -154,7 +155,7 @@ pcl::VTKUtils::vtk2mesh (const vtkSmartPointer<vtkPolyData>& poly_data, pcl::Pol
   }
 
   mesh.polygons.resize (nr_polygons);
-  vtkIdType* cell_points;
+  vtkIdType const* cell_points;
   vtkIdType nr_cell_points;
   vtkCellArray * mesh_polygons = poly_data->GetPolys ();
   mesh_polygons->InitTraversal ();
diff --git a/visualization/include/pcl/visualization/impl/pcl_visualizer.hpp b/visualization/include/pcl/visualization/impl/pcl_visualizer.hpp
index b7bfcfc56..930c3cccf 100644
--- a/visualization/include/pcl/visualization/impl/pcl_visualizer.hpp
+++ b/visualization/include/pcl/visualization/impl/pcl_visualizer.hpp
@@ -1696,18 +1696,18 @@ pcl::visualization::PCLVisualizer::addPolygonMesh (
   {
     // Create polys from polyMesh.polygons
     vtkSmartPointer<vtkCellArray> cell_array = vtkSmartPointer<vtkCellArray>::New ();
-    vtkIdType *cell = cell_array->WritePointer (vertices.size (), vertices.size () * (max_size_of_polygon + 1));
+    //vtkIdType *cell = cell_array->WritePointer (vertices.size (), vertices.size () * (max_size_of_polygon + 1));
     int idx = 0;
     if (!lookup.empty ())
     {
       for (std::size_t i = 0; i < vertices.size (); ++i, ++idx)
       {
         std::size_t n_points = vertices[i].vertices.size ();
-        *cell++ = n_points;
-        //cell_array->InsertNextCell (n_points);
+        //*cell++ = n_points;
+        cell_array->InsertNextCell (n_points);
         for (std::size_t j = 0; j < n_points; j++, ++idx)
-          *cell++ = lookup[vertices[i].vertices[j]];
-          //cell_array->InsertCellPoint (lookup[vertices[i].vertices[j]]);
+          //*cell++ = lookup[vertices[i].vertices[j]];
+          cell_array->InsertCellPoint (lookup[vertices[i].vertices[j]]);
       }
     }
     else
@@ -1715,11 +1715,11 @@ pcl::visualization::PCLVisualizer::addPolygonMesh (
       for (std::size_t i = 0; i < vertices.size (); ++i, ++idx)
       {
         std::size_t n_points = vertices[i].vertices.size ();
-        *cell++ = n_points;
-        //cell_array->InsertNextCell (n_points);
+        //*cell++ = n_points;
+        cell_array->InsertNextCell (n_points);
         for (std::size_t j = 0; j < n_points; j++, ++idx)
-          *cell++ = vertices[i].vertices[j];
-          //cell_array->InsertCellPoint (vertices[i].vertices[j]);
+          //*cell++ = vertices[i].vertices[j];
+          cell_array->InsertCellPoint (vertices[i].vertices[j]);
       }
     }
     vtkSmartPointer<vtkPolyData> polydata;
@@ -1873,16 +1873,21 @@ pcl::visualization::PCLVisualizer::updatePolygonMesh (
 
   // Update the cells
   cells = vtkSmartPointer<vtkCellArray>::New ();
-  vtkIdType *cell = cells->WritePointer (verts.size (), verts.size () * (max_size_of_polygon + 1));
+  //vtkIdType *cell = cells->WritePointer (verts.size (), verts.size () * (max_size_of_polygon + 1));
   int idx = 0;
   if (!lookup.empty ())
   {
     for (std::size_t i = 0; i < verts.size (); ++i, ++idx)
     {
       std::size_t n_points = verts[i].vertices.size ();
-      *cell++ = n_points;
-      for (std::size_t j = 0; j < n_points; j++, cell++, ++idx)
-        *cell = lookup[verts[i].vertices[j]];
+      //*cell++ = n_points;
+      cells->InsertNextCell (n_points);
+      for (std::size_t j = 0; j < n_points; j++, ++idx)
+      {
+        //*cell = lookup[verts[i].vertices[j]];
+        cells->InsertCellPoint (lookup[verts[i].vertices[j]]);
+
+      }
     }
   }
   else
@@ -1890,9 +1895,13 @@ pcl::visualization::PCLVisualizer::updatePolygonMesh (
     for (std::size_t i = 0; i < verts.size (); ++i, ++idx)
     {
       std::size_t n_points = verts[i].vertices.size ();
-      *cell++ = n_points;
-      for (std::size_t j = 0; j < n_points; j++, cell++, ++idx)
-        *cell = verts[i].vertices[j];
+      //*cell++ = n_points;
+      cells->InsertNextCell (n_points);
+      for (std::size_t j = 0; j < n_points; j++, ++idx)
+      {
+        //*cell = verts[i].vertices[j];
+        cells->InsertCellPoint(verts[i].vertices[j]);
+      }
     }
   }
   cells->GetData ()->SetNumberOfValues (idx);
diff --git a/visualization/include/pcl/visualization/interactor_style.h b/visualization/include/pcl/visualization/interactor_style.h
index 0f166b75d..a1f17238e 100644
--- a/visualization/include/pcl/visualization/interactor_style.h
+++ b/visualization/include/pcl/visualization/interactor_style.h
@@ -51,6 +51,8 @@
 #include <boost/signals2/signal.hpp>
 #endif
 #include <vtkInteractorStyleRubberBandPick.h>
+#include <vtkRendererCollection.h>
+#include <vtkRenderWindow.h>
 
 class vtkRendererCollection;
 class vtkLegendScaleActor;
diff --git a/visualization/src/interactor_style.cpp b/visualization/src/interactor_style.cpp
index 4740577cf..f2efbdfd9 100644
--- a/visualization/src/interactor_style.cpp
+++ b/visualization/src/interactor_style.cpp
@@ -36,6 +36,7 @@
  *
  */
 
+#include <fstream>
 #include <list>
 #include <pcl/common/angles.h>
 #include <pcl/visualization/common/io.h>
@@ -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 e1966ae45..739cdc646 100644
--- a/visualization/src/pcl_visualizer.cpp
+++ b/visualization/src/pcl_visualizer.cpp
@@ -3159,16 +3159,20 @@ pcl::visualization::PCLVisualizer::updatePolygonMesh (
 
   // Update the cells
   cells = vtkSmartPointer<vtkCellArray>::New ();
-  vtkIdType *cell = cells->WritePointer (verts.size (), verts.size () * (max_size_of_polygon + 1));
+  //vtkIdType *cell = cells->WritePointer (verts.size (), verts.size () * (max_size_of_polygon + 1));
   int idx = 0;
   if (!lookup.empty ())
   {
     for (std::size_t i = 0; i < verts.size (); ++i, ++idx)
     {
       std::size_t n_points = verts[i].vertices.size ();
-      *cell++ = n_points;
-      for (std::size_t j = 0; j < n_points; j++, cell++, ++idx)
-        *cell = lookup[verts[i].vertices[j]];
+      //*cell++ = n_points;
+      cells->InsertNextCell(n_points);
+      for (std::size_t j = 0; j < n_points; j++, ++idx)
+      {
+        //*cell = lookup[verts[i].vertices[j]];
+        cells->InsertCellPoint(lookup[verts[i].vertices[j]]);
+      }
     }
   }
   else
@@ -3176,9 +3180,13 @@ pcl::visualization::PCLVisualizer::updatePolygonMesh (
     for (std::size_t i = 0; i < verts.size (); ++i, ++idx)
     {
       std::size_t n_points = verts[i].vertices.size ();
-      *cell++ = n_points;
-      for (std::size_t j = 0; j < n_points; j++, cell++, ++idx)
-        *cell = verts[i].vertices[j];
+      //*cell++ = n_points;
+      cells->InsertNextCell(n_points);
+      for (std::size_t j = 0; j < n_points; j++, ++idx)
+      {
+        //*cell = verts[i].vertices[j];
+        cells->InsertCellPoint(verts[i].vertices[j]);
+      }
     }
   }
   cells->GetData ()->SetNumberOfValues (idx);
@@ -3551,7 +3559,8 @@ pcl::visualization::PCLVisualizer::renderViewTesselatedSphere (
 
   //center object
   double CoM[3];
-  vtkIdType npts_com = 0, *ptIds_com = nullptr;
+  vtkIdType npts_com = 0;
+  vtkIdType const *ptIds_com = nullptr;
   vtkSmartPointer<vtkCellArray> cells_com = polydata->GetPolys ();
 
   double center[3], p1_com[3], p2_com[3], p3_com[3], totalArea_com = 0;
@@ -3610,7 +3619,8 @@ pcl::visualization::PCLVisualizer::renderViewTesselatedSphere (
   // * Compute area of the mesh
   //////////////////////////////
   vtkSmartPointer<vtkCellArray> cells = mapper->GetInput ()->GetPolys ();
-  vtkIdType npts = 0, *ptIds = nullptr;
+  vtkIdType npts = 0;
+  vtkIdType const *ptIds = nullptr;
 
   double p1[3], p2[3], p3[3], totalArea = 0;
   for (cells->InitTraversal (); cells->GetNextCell (npts, ptIds);)
@@ -3829,7 +3839,8 @@ pcl::visualization::PCLVisualizer::renderViewTesselatedSphere (
     polydata->BuildCells ();
 
     vtkSmartPointer<vtkCellArray> cells = polydata->GetPolys ();
-    vtkIdType npts = 0, *ptIds = nullptr;
+    vtkIdType npts = 0;
+    vtkIdType const *ptIds = nullptr;
 
     double p1[3], p2[3], p3[3], area, totalArea = 0;
     for (cells->InitTraversal (); cells->GetNextCell (npts, ptIds);)
-- 
2.17.1

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions