如何在点云中制作选取的点 bigger/bold

how to make the picked point in point cloud bigger/bold

我想制作一个 PCL Visualiser,用户可以在其中单击它时看到点云中的点的坐标。我实现了那部分,但现在的问题是用户没有得到他选择的点的任何响应所以我想让选择的点更大或者如果可能的话有颜色。

我正在使用 PointCloudLibrary 提供的 PCLVisualizer 和 PointPickingEvent 头文件。

    void pointPickingOccured( const pcl::visualization::PointPickingEvent &event,void* viewer_void)
{
    float x,y,z;
    event.getPoint(x,y,z);
    std::cout << "X: " << x << " Y: " << y << " Z: " << z << std::endl;
}

boost::shared_ptr<pcl::visualization::PCLVisualizer> simpleVis (pcl::PointCloud<pcl::PointXYZ>::ConstPtr cloud)
{
  boost::shared_ptr<pcl::visualization::PCLVisualizer> viewer (new pcl::visualization::PCLVisualizer ("3D Viewer"));
  viewer->setBackgroundColor (0, 0, 0);
  viewer->addPointCloud<pcl::PointXYZ> (cloud, filename);
  viewer->setPointCloudRenderingProperties (pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 1, filename);
  viewer->addCoordinateSystem (1.0);
  viewer->initCameraParameters ();
  viewer->registerMouseCallback (mouseEventOccurred, (void*)&viewer);
  viewer->registerPointPickingCallback(pointPickingOccured, (void*)&viewer);
  viewer->spin();
  return (viewer);

//新代码

void pointPickingOccured( const pcl::visualization::PointPickingEvent &event,void* viewer_void)
{
    float x,y,z;
    event.getPoint(x,y,z);
    pointIndex = event.getPointIndex();
    std::cout <<"Point No. " << pointIndex <<" ";
    std::cout << "X: " << x << " Y: " << y << " Z: " << z << std::endl;

    viewer->updateSphere(cloud->points[pointIndex], 0.03, 255, 0, 0, "pt");
    viewer->spinOnce (100);
    boost::this_thread::sleep (boost::posix_time::microseconds (100000));
}


void simpleVis (pcl::PointCloud<pcl::PointXYZ>::ConstPtr cloud)
{
  viewer->setBackgroundColor (0, 0, 0);
  viewer->addPointCloud<pcl::PointXYZ> (cloud, filename);
  viewer->setPointCloudRenderingProperties (pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 1, filename);
  viewer->registerPointPickingCallback(pointPickingOccured, (void*)&viewer);
  viewer->addCoordinateSystem (1.0);
  viewer->initCameraParameters ();
  viewer->addSphere(cloud->points[pointIndex], 0.03, "pt", 0); viewer->spin();}

由于您使用的是 PCLVisualizer,如果我理解您的问题,您有两个选择:

  1. 使用getPointIndex获取所选点的索引,从云端获取点并更改其RGB颜色(如果有很多点,这可能不容易可视化).
  2. 像你一样获取点的坐标,然后调用PCLVisualizer的addSphere方法在该坐标处添加一个球体(我认为这样会更好 ).