Search code examples
3dpoint-cloud-librarypoint-clouds

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


I wanted to make a PCL Visualiser where a user can see co-ordinates of the point in the point cloud when he clicks on it. I implemented that part but now the issue is the user do not get any response which point he picked so I want to make the picked point bigger or if possible coloured.

I am using PCLVisualizer and PointPickingEvent header files provided by PointCloudLibrary.

    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);

//new Code

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();}

Solution

  • Since you're using PCLVisualizer, if I understood your question, you have two options:

    1. Get the index of the picked point using getPointIndex, fetch the point from the cloud and change its RGB color (this might not be easy to visualize if there are a lot of points).
    2. Get the coordinate of the point like you did, then call the addSphere method of PCLVisualizer to add a sphere at that coordinates (I think that would be better).