[Solved] Draw and refresh PCL pointclouds in QVTK widget
-
First of all, I was not sure about if me should post this in "General and Desktop" or in "3rd Party Software".
My question concerns about PointClouds library (PCL) and QVTK widget.
I have an QVTK widget in a MainWindow widget. The method that draws my pointclouds is called each time I load a new pointcloud from disk (or a ToF camera):
@
void CamWindow::on_PointCloudChanged()
{
//pclPointCloud is declared as "pcl::PointCloudpcl::PointXYZ::Ptr pclPointCloud;". When that variable is updated, this method is called.
//pclVisorName is global std::string, with "visor" as content
//pclPointCloudName is global std::string, with "MyPointCloud" as content
pcl::visualization::PCLVisualizer localPclVisor = pcl::visualization::PCLVisualizer(pclVisorName,false);
localPclVisor.addPointCloudpcl::PointXYZ(pclPointCloud,pclPointCloudName);
//localPclVisor.setBackgroundColor(1,1,0);
vtkSmartPointer<vtkRenderWindow> localRenderWindow = localPclVisor.getRenderWindow();
ui->QvtkPointCloud->SetRenderWindow(localRenderWindow);
ui->QvtkPointCloud->update();existPclPointCloud = true;
}@
This works, but each time this method is called, the camera position, pointview and other things are reset. I want to change only pointcloud to view, without resetting positions, colors, etc. How can I achieve this?
I've tried things like:
@ std::string pclPointCloudName;
pcl::PointCloudpcl::PointXYZ::Ptr pclPointCloud;
pcl::visualization::PCLVisualizer pclVisor;
std::string pclVisorName;
vtkSmartPointer<vtkRenderWindow> renderWindow;@(declaring pointcloud representation components as global vars)
@void CamWindow::on_PointCloudChanged()
{
//pclPointCloud is declared as "pcl::PointCloudpcl::PointXYZ::Ptr pclPointCloud;". When that variable is updated, this method is called.
//pclVisorName is global std::string, with "visor" as content
//pclPointCloudName is global std::string, with "MyPointCloud" as content
if (existPclPointCloud)
{
localPclVisor.updatePointCloudpcl::PointXYZ(pclPointCloud,pclPointCloudName);
}
else
{
pcl::visualization::PCLVisualizer pclVisor = pcl::visualization::PCLVisualizer(pclVisorName,false);
pclVisor.addPointCloudpcl::PointXYZ(pclPointCloud,pclPointCloudName);
vtkSmartPointer<vtkRenderWindow> renderWindow = pclVisor.getRenderWindow();
ui->QvtkPointCloud->SetRenderWindow(renderWindow);
}
ui->QvtkPointCloud->update();existPclPointCloud = true;
}@
But this does not work... Declaring QVTK and PCL components as global variables (in MainWindow Widget) make this program to show nothing in QVTK widget!! Why?
[I've also tried several variations of this, but it appears as every PCL+VTK+QT variable must be local in method in order to work. Spent hours and hours looking and googling for docs about VTK Visualizer, QVTK methods, objects, etc with no luck]
In understand that vars and objects relatives to PCL+VTK+QT are never empty or null (as they're global in MainWindow!!)...
EDIT: My environment is Ubuntu 12.04 LTS, with Qt Creator 2.5.2, 64 bits. PCL 1.6, VTK 5.8
-
New UPDATE.
This works:
@void CamWindow::on_PointCloudChanged()
{
if (existPclPointCloud)
{
pclVisor.updatePointCloud(pclPointCloudPtr);
pclVisor.updateCamera();
ui->QvtkPointCloud->update();
}
else
{
//pclVisor = pcl::visualization::PCLVisualizer(pclVisorName,false);
pcl::visualization::PCLVisualizer localPclVisor = pcl::visualization::PCLVisualizer(pclVisorName,false);
pclVisor = localPclVisor;pclVisor.addPointCloud<pcl::PointXYZ>(pclPointCloudPtr); pclVisor.setBackgroundColor(1,0,0); renderWindow = pclVisor.getRenderWindow(); ui->QvtkPointCloud->SetRenderWindow(renderWindow); ui->QvtkPointCloud->show(); } ui->QvtkPointCloud->update(); existPclPointCloud = true;
}@
But if I use
@pclVisor = pcl::visualization::PCLVisualizer(pclVisorName,false);@
instead of
@pcl::visualization::PCLVisualizer localPclVisor = pcl::visualization::PCLVisualizer(pclVisorName,false);
pclVisor = localPclVisor;@It shows nothing... why???