0

如果我正确理解文档,则可以使用 pcl::ExtractPolygonalPrismData 在与定义的多边形垂直的空间内的云中找到点。

我不使用 pcl::isPointIn2DPolygon 因为我的多边形在 xz 平面上。所以我想沿着y轴测试。在此处输入图像描述 绿色:点云;红色:多边形顶点

测试代码:

//create pointcloud on y=1 plane
std::vector<pcl::PointXYZ, Eigen::aligned_allocator<pcl::PointXYZ> > testpoints;
for(int i=0;i<5;i++){
    float x=i+0.5;
    for(int j=0;j<5;j++){
        float z=j+0.5;
        testpoints.push_back(pcl::PointXYZ(x,1.0,z));
    }
}

pcl::PointCloud<pcl::PointXYZ>::Ptr pointCloud (new pcl::PointCloud<pcl::PointXYZ> ());

pointCloud->points=testpoints;
pointCloud->width=testpoints.size();
pointCloud->height=1;
//create polygon points on y=0 plane
std::vector<pcl::PointXYZ, Eigen::aligned_allocator<pcl::PointXYZ> > pcl_polygon;
pcl_polygon.push_back(pcl::PointXYZ(0 , 0 , 0));
pcl_polygon.push_back(pcl::PointXYZ(2 , 0 , 0));
pcl_polygon.push_back(pcl::PointXYZ(2 , 0 , 2));
pcl_polygon.push_back(pcl::PointXYZ(0 , 0 , 2));

pcl::PointCloud<pcl::PointXYZ>::Ptr hullCloud (new pcl::PointCloud<pcl::PointXYZ> ());
hullCloud->points=pcl_polygon;
hullCloud->width=4;
hullCloud->height=1;

pcl::ConvexHull<pcl::PointXYZ> pclHull;
pclHull.setInputCloud (hullCloud);

pcl::PointCloud<pcl::PointXYZ>::Ptr output_hull (new pcl::PointCloud<pcl::PointXYZ>);
pclHull.reconstruct (*output_hull);

if (pclHull.getDimension () != 2){
    PCL_ERROR ("The input cloud does not represent a planar surface.\n");
    return;
}

pcl::PointIndices::Ptr inPrism (new pcl::PointIndices);

pcl::ExtractPolygonalPrismData<pcl::PointXYZ> searchPrism;
searchPrism.setInputCloud (pointCloud);
searchPrism.setInputPlanarHull (output_hull);
searchPrism.setHeightLimits (0, 10);
searchPrism.segment (*inPrism);

qDebug() << inPrism->indices.size() + " this is empty";

不幸的是 inPrism->indices 是空的,但我希望左上角的点。(0.5,0.5)(1.5,0.5)(0.5,1.5)(1.5,1.5)

4

1 回答 1

0

我必须换行:

searchPrism.setHeightLimits (0, -10);

searchPrism.setHeightLimits (-10, 0);

有人可以解释一下吗?

于 2021-06-17T09:07:25.823 回答