From 3d88342bae079b4b6fb0a8859c689c50dab32789 Mon Sep 17 00:00:00 2001 From: Markus Vieth Date: Sun, 5 Nov 2023 18:30:13 +0100 Subject: [PATCH] Fix VoxelGridOcclusionEstimation tool - call Update() on vtk classes, otherwise the shown window is empty - use the filtered cloud instead of whole input cloud, otherwise processing is very slow for larger clouds - use the fixed RenderWindowInteractor --- tools/voxel_grid_occlusion_estimation.cpp | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/tools/voxel_grid_occlusion_estimation.cpp b/tools/voxel_grid_occlusion_estimation.cpp index 897c7f20e1f..b2409585b95 100644 --- a/tools/voxel_grid_occlusion_estimation.cpp +++ b/tools/voxel_grid_occlusion_estimation.cpp @@ -43,6 +43,7 @@ #include #include #include +#include #include #include #include @@ -79,6 +80,7 @@ getCuboid (double minX, double maxX, double minY, double maxY, double minZ, doub { vtkSmartPointer < vtkCubeSource > cube = vtkSmartPointer::New (); cube->SetBounds (minX, maxX, minY, maxY, minZ, maxZ); + cube->Update (); return cube->GetOutput (); } @@ -99,6 +101,7 @@ getVoxelActors (pcl::PointCloud& voxelCenters, treeWireframe->AddInputData (getCuboid (x - s, x + s, y - s, y + s, z - s, z + s)); } + treeWireframe->Update (); vtkSmartPointer < vtkLODActor > treeActor = vtkSmartPointer::New (); @@ -119,6 +122,7 @@ displayBoundingBox (Eigen::Vector3f& min_b, Eigen::Vector3f& max_b, { vtkSmartPointer < vtkAppendPolyData > treeWireframe = vtkSmartPointer::New (); treeWireframe->AddInputData (getCuboid (min_b[0], max_b[0], min_b[1], max_b[1], min_b[2], max_b[2])); + treeWireframe->Update(); vtkSmartPointer < vtkActor > treeActor = vtkSmartPointer::New (); @@ -218,17 +222,19 @@ int main (int argc, char** argv) (*occ_centroids)[i] = point; } + // we use the filtered cloud because it contains exactly one point per occupied voxel (avoids drawing the same voxel box multiple times) + CloudT filtered_cloud = vg.getFilteredPointCloud(); CloudT::Ptr cloud_centroids (new CloudT); - cloud_centroids->width = input_cloud->size (); + cloud_centroids->width = filtered_cloud.size (); cloud_centroids->height = 1; cloud_centroids->is_dense = false; - cloud_centroids->points.resize (input_cloud->size ()); + cloud_centroids->points.resize (filtered_cloud.size ()); - for (std::size_t i = 0; i < input_cloud->size (); ++i) + for (std::size_t i = 0; i < filtered_cloud.size (); ++i) { - float x = (*input_cloud)[i].x; - float y = (*input_cloud)[i].y; - float z = (*input_cloud)[i].z; + float x = filtered_cloud[i].x; + float y = filtered_cloud[i].y; + float z = filtered_cloud[i].z; Eigen::Vector3i c = vg.getGridCoordinates (x, y, z); Eigen::Vector4f xyz = vg.getCentroidCoordinate (c); PointT point; @@ -254,7 +260,7 @@ int main (int argc, char** argv) vtkSmartPointer::New(); renderWindow->AddRenderer (renderer); vtkSmartPointer renderWindowInteractor = - vtkSmartPointer::New(); + vtkSmartPointer::Take (vtkRenderWindowInteractorFixNew ()); renderWindowInteractor->SetRenderWindow (renderWindow); // Add the actors to the renderer, set the background and size