0

I am trying to visualize pointclouds on my qt widget.Following is a snippet of my code.This code can display the point clouds from a .pcd file. I am looking to visualize real time point clouds on qt

void MainWindow::imageShowLIDAR()
{
    //std::cout << "carico file" << std::endl;

    std::cout << "imageshow lidar initiated" << std::endl;

    cloud_pcl.reset (new PointCloudT);
    cloud_pcl->resize (200);
    red   = 128;
    green = 128;
    blue  = 128;
    pcl::io::loadPCDFile("/home/pcl1.pcd", *cloud_pcl);
    for (auto& point: *cloud_pcl)
  {
    //point.x = 1024 * rand () / (RAND_MAX + 1.0f);
    //point.y = 1024 * rand () / (RAND_MAX + 1.0f);
    //point.z = 1024 * rand () / (RAND_MAX + 1.0f);

    point.r = red;
    point.g = green;
    point.b = blue;
  }
    viewer_pcl.reset(new pcl::visualization::PCLVisualizer("viewer_pcl", false));
    //Set viewer settings
    viewer_pcl->addCoordinateSystem(3.0, "coordinate");
    viewer_pcl->setShowFPS(false);
    viewer_pcl->setBackgroundColor(0.0, 0.0, 0.0, 0);
    //viewer_pcl->setCameraPosition(0.0, 0.0, 30.0, 0.0, 1.0, 0.0, 0);
    ui.LIDAR_Widget->SetRenderWindow(viewer_pcl->getRenderWindow());
    viewer_pcl->setupInteractor(ui.LIDAR_Widget->GetInteractor(), ui.LIDAR_Widget->GetRenderWindow());
    viewer_pcl->addPointCloud (cloud_pcl, "cloud");
    viewer_pcl->resetCamera ();
    ui.LIDAR_Widget->update();
}

I have succedded in displaying a .pcd file but i would like to stream real time pointclouds on my widgets. I am new to this and moving ahead very gradually. Will highly appreciate any sort of suggestions. Thank you.

Zaid khan
  • 11
  • 1

1 Answers1

0

So, your point cloud should be generated outside of the visualization function and then you can give a point cloud object as parameter to function to be shown. I am not familiar with pcl framework, but you can get a simple idea.

void MainWindow::imageShowLIDAR(pcl::PointCloud &cloud_pcl)
{    
    viewer_pcl.reset(new pcl::visualization::PCLVisualizer("viewer_pcl", false));
    //Set viewer settings
    viewer_pcl->addCoordinateSystem(3.0, "coordinate");
    viewer_pcl->setShowFPS(false);
    viewer_pcl->setBackgroundColor(0.0, 0.0, 0.0, 0);
    //viewer_pcl->setCameraPosition(0.0, 0.0, 30.0, 0.0, 1.0, 0.0, 0);
    ui.LIDAR_Widget->SetRenderWindow(viewer_pcl->getRenderWindow());
    viewer_pcl->setupInteractor(ui.LIDAR_Widget->GetInteractor(), ui.LIDAR_Widget->GetRenderWindow());
    viewer_pcl->addPointCloud (cloud_pcl, "cloud");
    viewer_pcl->resetCamera ();
    ui.LIDAR_Widget->update();
}

This function should take a point cloud object then visualize it. Now the stream part starts;

 void MainWindow::stream()
 {   
     while (streamContinue) {
            // you should generate point cloud to be shown
            preConditions(); // if you want to check some condiitons before visualization
            pcl::PointCLoud res = ...;
            imageShowLIDAR(res);
            emit postConditions(); // if you want to check some results
     }
  }
  • Thank you for your comment but i still dont get how to read the point clouds from **sensor_msgs/PointCloud2** and store it into my pointer **cloud_pcl** – Zaid khan Apr 26 '23 at 08:00