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::PointCloud<pcl::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.addPointCloud<pcl::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::PointCloud<pcl::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::PointCloud<pcl::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.updatePointCloud<pcl::PointXYZ>(pclPointCloud,pclPointCloudName);
}
else
{
pcl::visualization::PCLVisualizer pclVisor = pcl::visualization::PCLVisualizer(pclVisorName,false);
pclVisor.addPointCloud<pcl::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]
I understand that vars and objects relatives to PCL+VTK+QT are never empty or null (as they're global in MainWindow!!)...
My environment is Ubuntu 12.04 LTS, with Qt Creator 2.5.2, 64 bits. PCL 1.6, VTK 5.8