3

I'm trying to create a simple application using QT to display point clouds. However the PCL visualizer crashes at

pviz.addPointCloud<pcl::PointXYZ>(cloud_xyz,"cloud1");

Is there are initializations that I am missing?

#include <QApplication>
#include <pcl/point_cloud.h>
#include <pcl/point_types.h>
#include <pcl/visualization/pcl_visualizer.h>

#include <iostream>

#include <thread>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

    pcl::visualization::PCLVisualizer pviz ("test_viz");
    pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_xyz (new pcl::PointCloud<pcl::PointXYZ>);
    for (float y = -0.5f; y <= 0.5f; y += 0.01f)
    {
        for (float z = -0.5f; z <= 0.5f; z += 0.01f)
        {
            pcl::PointXYZ point;
            point.x = 2.0f - y;
            point.y = y;
            point.z = z;
            cloud_xyz->points.push_back (point);
        }
    }
    cloud_xyz->width = cloud_xyz->points.size ();
    cloud_xyz->height = 1;
    std::cerr<<"Cloud Gen";
    pviz.addPointCloud<pcl::PointXYZ>(cloud_xyz,"cloud1");
     std::cerr<<"Cloud Add";
    pviz.setBackgroundColor(0, 0, 0.1);
    pviz.initCameraParameters();
    return a.exec();
}

The is just a demo program, hence I just want to add the point cloud and I haven't kept it in a loop or a separate thread.

Exa
  • 4,020
  • 7
  • 43
  • 60
  • @Exa could you help me out? – Leroy Francisco Pereira Apr 03 '17 at 09:59
  • I'm not familiar with PCL Visualizer unfortunately. I saw some reports on errors when using VS2015 and this method, but didn't find a solution. – Exa Apr 03 '17 at 10:19
  • The solution is not to use PCL visualizer, but to directly render it using VTK. – Leroy Francisco Pereira Apr 07 '17 at 12:35
  • There is not nearly enough information to answer the question. @Leroy Francisco Pereira is correct. You should be using a VTK widget and linking the interactor and renderer to the visualizer. But getting PCL compiled and linked properly IS HARD. It's like 6 different libraries that need to be compiled and linked with a compatable QT build. The are hundreds of things that could be wrong. – 8bitwide Sep 09 '17 at 03:33
  • But if you wanted this example to work, you would need pviz.Spin() somwhere. But that can't be in your main thread unless you want it to block. You do need to use a VTKWidget in side a QGUI application to get what you want. there seems to be so much wrong with this lol. – 8bitwide Sep 09 '17 at 03:36
  • @Exa, I have gotten PCL 1.8 working with visual studio 2015. I basically had to build and link all the libraries individually. It works well, I haven't run into any impassible errors. – 8bitwide Sep 09 '17 at 03:47
  • same problem with pcl1.8, vtk5.8 and ubuntu14.04 – Liang Xiao Mar 22 '18 at 04:09

0 Answers0