Is there any function to extract the indices generated from a cropbox

南笙酒味 提交于 2020-01-25 07:56:05

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!