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.