0

If I understand documentation right one can find points in a cloud inside space normal to a defined poly by using pcl::ExtractPolygonalPrismData.

I dont use pcl::isPointIn2DPolygon because my polygon is on x-z plane. So I want to test along y-axis.enter image description here green: pointcloud ; red: polygon vertices

testcode:

//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";

Unfortunately inPrism->indices is empty, but I expect the top left points.(0.5,0.5)(1.5,0.5)(0.5,1.5)(1.5,1.5)

Pj Toopmuch
  • 115
  • 10

1 Answers1

0

I have to change line :

searchPrism.setHeightLimits (0, -10);

to

searchPrism.setHeightLimits (-10, 0);

Can someone explain this?

Pj Toopmuch
  • 115
  • 10