Search code examples
rospoint-cloud-library

Passing unit8 to pcl::Passthrough


I have a customized PointXYZB with fields x, y, z, and beam in pcl. x, y, z are float and beam is unit8 with either value equals to 0 or 1. I have registered my customized PointXYZB to pcl, and I'm trying to use setFilterFieldName to filter my point cloud in terms of field beam. The following is my code. The code compiles successfully but fails to filter out the correct result based on beam. I know we can use setNegative as a workaround but I want to know why my code fails. I guess there is something wrong when casting from uint8 to double in c++ API.

#include <iostream>
#include <pcl/point_types.h>
#include <pcl/filters/passthrough.h>
    
pcl::PointCloud<PointXYZB> filter (double lower, double upper)
    {
      pcl::PointCloud<PointXYZB>::Ptr cloud (new pcl::PointCloud<PointXYZB>);
      pcl::PointCloud<PointXYZB>::Ptr cloud_filtered (new pcl::PointCloud<PointXYZB>);
    

      // Create the filtering object
      pcl::PassThrough<PointXYZB> pass;
      pass.setInputCloud (cloud);
      pass.setFilterFieldName ("beam");
      pass.setFilterLimits (lower, double);
      pass.filter (*cloud_filtered);
      return *cloud_filtered;

    }

int main() {
  pcl::PointCloud<PointXYZB> f = filter(0.0, 0.0);
  pcl::PointCloud<PointXYZB> b = filter(1.0, 1.0);
}

Solution

  • I just checked, PassThrough only works for fields of type float: https://github.com/PointCloudLibrary/pcl/blob/master/filters/include/pcl/filters/impl/passthrough.hpp#L101

    You can try ConditionalRemoval or, if your PCL version is sufficiently recent, FunctorFilter/FunctionFilter