I am working in ROS and processing point clouds using the PCL. At one moment, when filtering my cloud with VoxelGrid, I also needed to extract the same filtered points in its twin Normals point cloud, as they are both given toghether. That's when I encountered a build problem when trying to set bool=true in the constructor of pcl::VoxelGrid<pcl::PointXYZ>, which is required to extract the filtered indices using the getRemovedIndices method.

Here my function declaration:

void voxelFilter(const pcl::PointCloud<pcl::PointXYZ>::Ptr& cloud, const pcl::PointIndices::Ptr& inliers_filtered)
  {
    ROS_INFO("Apply voxelization.");
    pcl::VoxelGrid<pcl::PointXYZ> vox(true);
    vox.setInputCloud (cloud);
    vox.setLeafSize (0.001f, 0.001f, 0.001f);
    vox.filter (*cloud);
    vox.getRemovedIndices(*inliers_filtered);
  }

Here the CMake build error:

/home/abb/catkin_ws/src/abb_vision_project/pcl_processing/src/cylinder_perception.cpp: In member function ‘void CylinderSegment::voxelFilter(const Ptr&, const Ptr&)’:
/home/abb/catkin_ws/src/abb_vision_project/pcl_processing/src/cylinder_perception.cpp:293:43: error: no matching function for call to ‘pcl::VoxelGrid<pcl::PointXYZ>::VoxelGrid(bool)’
  293 |     pcl::VoxelGrid<pcl::PointXYZ> vox(true);
      |                                           ^
In file included from /home/abb/catkin_ws/src/abb_vision_project/pcl_processing/src/cylinder_perception.cpp:7:
/usr/include/pcl-1.10/pcl/filters/voxel_grid.h:195:7: note: candidate: ‘pcl::VoxelGrid<PointT>::VoxelGrid() [with PointT = pcl::PointXYZ]’
  195 |       VoxelGrid () :
      |       ^~~~~~~~~
/usr/include/pcl-1.10/pcl/filters/voxel_grid.h:195:7: note:   candidate expects 0 arguments, 1 provided
/usr/include/pcl-1.10/pcl/filters/voxel_grid.h:177:9: note: candidate: ‘pcl::VoxelGrid<pcl::PointXYZ>::VoxelGrid(const pcl::VoxelGrid<pcl::PointXYZ>&)’
  177 |   class VoxelGrid: public Filter<PointT>
      |         ^~~~~~~~~
/usr/include/pcl-1.10/pcl/filters/voxel_grid.h:177:9: note:   no known conversion for argument 1 from ‘bool’ to ‘const pcl::VoxelGrid<pcl::PointXYZ>&’
make[2]: *** [CMakeFiles/cylinder_perception.dir/build.make:63: CMakeFiles/cylinder_perception.dir/src/cylinder_perception.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:2913: CMakeFiles/cylinder_perception.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
make: *** [Makefile:141: all] Error 2

This seems weird to me as pcl::VoxelGrid< PointT > is child of pcl::Filter< PointT > and should inherit its public member methods, as written here in the documentation .

Important note: I have no problem using pcl::VoxelGrid without the option bool=true in the constructor. Also, if the method getRemovedIndices is called without setting the initialization variable in the constructor, no build error is generated but (obviously) the indices are not extracted, as the initialization is required. Moreover, I can use other filters like pcl::PassThrough or pcl::StatisticalOutlierRemoval, which are also inheriting indirectly from pcl::Filter, and both the constructor initialization and the getRemovedIndices work without problems.

MY ENVIRONMENT: ROS Noetic, Ubuntu Focal Fossa 20.04, PCL-1.10

What am I missing? Could my PCL package be broken or needing update?

Thanks

EDIT: With the help of your comments I realized that the question was more about why and not if pcl::VoxelGrid doesn't have a constructor with the bool extract_removed_indices=true setting. Turns out it makes sense, given pcl::VoxelGrid completely changes the structure of the point cloud, without bi-univocal relation with input one, so getting filtered indices doesn't make sense. Also, even if this made sense, the Normals extracted using these filtered indicies would be wrong, as normals have meaning if and only if relative to a specific point in the space.

The right answer is using pal::UniformSampling instead, which preserves points in the cloud by not assigning directly the computed centroid of the voxel as the filtered point but choosing the point closest to the computed centroid instead. Now I am able to use getRemovedIndices()!

0

There are 0 best solutions below