In a given point cloud, I want to remove all the points which are less than min
and greater than max
for all x
, y
and
You have found what the documentation makes clear.
PassThrough passes points in a cloud based on constraints for one particular field of the point type.
For multiple fields a different filter should be used, such as ConditionalRemoval
The following is untested, but it'll be something like this.
pcl::ConditionOr<PointT>::Ptr range_cond (new pcl::ConditionOr<PointT> ());
range_cond->addComparison (pcl::FieldComparison<PointT>::Ptr (new pcl::FieldComparison<PointT>("x", pcl::ComparisonOps::GT, minX)));
range_cond->addComparison (pcl::FieldComparison<PointT>::Ptr (new pcl::FieldComparison<PointT>("x", pcl::ComparisonOps::LT, maxX)));
range_cond->addComparison (pcl::FieldComparison<PointT>::Ptr (new pcl::FieldComparison<PointT>("y", pcl::ComparisonOps::GT, minY)));
range_cond->addComparison (pcl::FieldComparison<PointT>::Ptr (new pcl::FieldComparison<PointT>("y", pcl::ComparisonOps::LT, maxY)));
range_cond->addComparison (pcl::FieldComparison<PointT>::Ptr (new pcl::FieldComparison<PointT>("z", pcl::ComparisonOps::GT, minZ)));
range_cond->addComparison (pcl::FieldComparison<PointT>::Ptr (new pcl::FieldComparison<PointT>("z", pcl::ComparisonOps::LT, maxZ)));
pcl::ConditionalRemoval<PointT> range_filt;
range_filt.setInputCloud(body);
range_filt.setCondition (range_cond);
range_filt.filter(*bodyFiltered);
What about using pcl::CropBox
? (documentation)
pcl::CropBox<pcl::PointXYZRGBA> boxFilter;
boxFilter.setMin(Eigen::Vector4f(minX, minY, minZ, 1.0));
boxFilter.setMax(Eigen::Vector4f(maxX, maxY, maxZ, 1.0));
boxFilter.setInputCloud(body);
boxFilter.filter(*bodyFiltered);
To know why this filter takes Vector4f (and not Vector3f) see the comments below and this question.