Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. 3rd Party Software
  4. [Solved] Draw and refresh PCL pointclouds in QVTK widget
Forum Update on Monday, May 27th 2025

[Solved] Draw and refresh PCL pointclouds in QVTK widget

Scheduled Pinned Locked Moved 3rd Party Software
2 Posts 1 Posters 4.9k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    Bullub
    wrote on 19 Jul 2013, 06:08 last edited by
    #1

    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

    1 Reply Last reply
    0
    • B Offline
      B Offline
      Bullub
      wrote on 19 Jul 2013, 11:06 last edited by
      #2

      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???

      1 Reply Last reply
      0

      1/2

      19 Jul 2013, 06:08

      • Login

      • Login or register to search.
      1 out of 2
      • First post
        1/2
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved