Question

I've this TOF-sensor and I want to visualize the sensor's data as a point-cloud in Qt. I converted the data into a pcl::PointCloud and now I want to visualize it.

The API of the sensor would emit a picture whenever one was created. And I would send it to the QVTKWidget to visualize it. And I tried it with this snippet of code (which I got from here):

pcl::visualization::PCLVisualizer pvis ("test_vis", false); 
// 'false' prevents PCLVisualizer's own window to pop up

pvis.addPointCloud<pcl::PointXYZ>(pc); // pc is my point cloud

vtkSmartPointer<vtkRenderWindow> renderWindow = pvis.getRenderWindow();
widget.SetRenderWindow(renderWindow);

But it seems like this is only meant to visualize one steady point-cloud and not a changing sequence of point-clouds.

Question: Is there any way to update the cloud_xyz whenever my sensor emits a new picture?

Was it helpful?

Solution

OK, after some trying, here is my solution:

in my VTKPointCloudWidget which inherits from QVTKWidget:

pcl::visualization::PCLVisualizer vis ("vis", false); 

VTKPointCloudWidget::VTKPointCloudWidget(QWidget *parent) : QVTKWidget(parent)
{
   this->resize(500, 500);
   pcl::PointCloud<pcl::PointXYZ>::Ptr pc (new pcl::PointCloud<pcl::PointXYZ>);

   vis.addPointCloud<pcl::PointXYZ>(pc);
   vtkSmartPointer<vtkRenderWindow> renderWindow = vis.getRenderWindow();
   this->SetRenderWindow(renderWindow);
   this->show();
}

and whenever a new sensor image is emitted, it is sent to:

void VTKPointCloudWidget::showPointCloud(SensorPicture pic)
{   
   // converts the sensor image to a point cloud
   pcl::PointCloud<pcl::PointXYZ>::Ptr pc = cvtSP2PC(pic);

   pc->width = pic.width;
   pc->height = pic.height;

   vis.updatePointCloud<pcl::PointXYZ>(pc); 

   this->update();
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top