问题
I've tried the pcl::cropbox and filtered a cloud based on the min and max x,y,z values given to the cropbox. I get the new cloud which contains only the point within the cropbox limits. Unfortunately I don't need a separate cloud, but need the indices which lie within the box. Note : I get the removed indices from the old cloud, but not the indices which lie inside cropbox.
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZ>);
pcl::io::loadPCDFile ("D:\ism_test.pcd", *cloud);
pcl::PointCloud<pcl::PointXYZ>::Ptr bodyFiltered (new pcl::PointCloud<pcl::PointXYZ>);
pcl::CropBox<pcl::PointXYZ> boxFilter(true);
boxFilter.setMin(Eigen::Vector4f(minX, minY, minZ, 1.0));
boxFilter.setMax(Eigen::Vector4f(maxX, maxY, maxZ, 1.0));
boxFilter.setInputCloud(cloud);
boxFilter.FilterIndices(*bodyFiltered);
pcl::IndicesConstPtr removedIndices = boxFilter.getRemovedIndices();
pcl::IndicesConstPtr actualindices = boxFilter.getIndices();
//blocks until the cloud is actually rendered
pcl::visualization::CloudViewer filteredviewer("Filtered Viewer");
filteredviewer.showCloud(bodyFiltered);
回答1:
pcl::CropBox inherited filter (std::vector< int > &indices)
so you should be able to call it to get the indices which lie within the box see here for reference
pcl::CropBox<pcl::PointXYZ> boxFilter;
...
#
std::vector<int> indices_inside;
boxFilter.filter(indices_inside);
If you need the points out side the box, you can retrieve it with std::set_difference, for example
std::vector<int> all_points(cloud.size());
std::iota(all_points.begin(), all_points.end()) // fill with 0, 1, 2, ..., n
std::vector<int> indices_inside = ...(from previous);
std::vector<int> indices_outside;
// process: indices_outside = all_points - indices_inside
std::set_difference(all_points.begin(), all_points.end(),
indices_inside.begin(), indices_inside.end(),
std::inserter(indices_outside, indices_outside.begin()));
来源:https://stackoverflow.com/questions/56597119/is-there-any-function-to-extract-the-indices-generated-from-a-cropbox