如何使点云中的拾取点更大/更大胆

时间:2016-09-22 06:03:42

标签: 3d point-cloud-library point-clouds

我想创建一个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();}

1 个答案:

答案 0 :(得分:1)

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

  1. 使用https://azure.microsoft.com/en-us/documentation/articles/cloud-services-choose-me/获取拾取点的索引,从云中获取点并更改其RGB颜色(如果有很多点,这可能不容易可视化 )。
  2. 获取点的坐标,然后调用PCLVisualizer的getPointIndex方法在该坐标处添加一个球体(我认为会更好)。