Skip to content

Commit

Permalink
Fix VoxelGridOcclusionEstimation tool
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
mvieth committed Nov 5, 2023
1 parent 3541c3f commit 3d88342
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions tools/voxel_grid_occlusion_estimation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
#include <pcl/console/print.h>
#include <pcl/console/parse.h>
#include <pcl/console/time.h>
#include <pcl/visualization/vtk/vtkRenderWindowInteractorFix.h>
#include <pcl/visualization/pcl_visualizer.h>
#include <pcl/filters/voxel_grid_occlusion_estimation.h>
#include <vtkCubeSource.h>
Expand Down Expand Up @@ -79,6 +80,7 @@ getCuboid (double minX, double maxX, double minY, double maxY, double minZ, doub
{
vtkSmartPointer < vtkCubeSource > cube = vtkSmartPointer<vtkCubeSource>::New ();
cube->SetBounds (minX, maxX, minY, maxY, minZ, maxZ);
cube->Update ();
return cube->GetOutput ();
}

Expand All @@ -99,6 +101,7 @@ getVoxelActors (pcl::PointCloud<pcl::PointXYZ>& voxelCenters,

treeWireframe->AddInputData (getCuboid (x - s, x + s, y - s, y + s, z - s, z + s));
}
treeWireframe->Update ();

vtkSmartPointer < vtkLODActor > treeActor = vtkSmartPointer<vtkLODActor>::New ();

Expand All @@ -119,6 +122,7 @@ displayBoundingBox (Eigen::Vector3f& min_b, Eigen::Vector3f& max_b,
{
vtkSmartPointer < vtkAppendPolyData > treeWireframe = vtkSmartPointer<vtkAppendPolyData>::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<vtkActor>::New ();

Expand Down Expand Up @@ -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;
Expand All @@ -254,7 +260,7 @@ int main (int argc, char** argv)
vtkSmartPointer<vtkRenderWindow>::New();
renderWindow->AddRenderer (renderer);
vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =
vtkSmartPointer<vtkRenderWindowInteractor>::New();
vtkSmartPointer<vtkRenderWindowInteractor>::Take (vtkRenderWindowInteractorFixNew ());
renderWindowInteractor->SetRenderWindow (renderWindow);

// Add the actors to the renderer, set the background and size
Expand Down

0 comments on commit 3d88342

Please sign in to comment.