pcl实时显示

激光雷达,需要用到点云的实时显示,记录如下:

simpleVis(pcl::PointCloud::ConstPtr cloud, pcl::PointCloud::ConstPtr cloud2) {
    boost::shared_ptr viewer(new pcl::visualization::PCLVisualizer("3D Viewer"));
    viewer->initCameraParameters();

    int v1(0);
    viewer->createViewPort(0.0, 0.0, 0.5, 1.0, v1);
    viewer->setBackgroundColor(0, 0, 0, v1);
    viewer->addText("Radius: 0.01", 10, 10, "v1 text", v1);
    pcl::visualization::PointCloudColorHandlerCustom single_color0(cloud, 255, 0, 255);
    viewer->addPointCloud(cloud, single_color0, "sample cloud0", v1);

    int v2(0);
    viewer->createViewPort(0.5, 0.0, 1.0, 1.0, v2);
    viewer->setBackgroundColor(0.3, 0.3, 0.3, v2);
    viewer->addText("Radius: 0.1", 10, 10, "v2 text", v2);
    pcl::visualization::PointCloudColorHandlerCustom single_color(cloud, 0, 255, 0);
    viewer->addPointCloud(cloud, single_color, "sample cloud", v2);

    viewer->setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 1, "sample cloud0");
    viewer->addCoordinateSystem(1.0);

    return (viewer);
}

调用的时候

boost::shared_ptr viewer;
//点云实时显示
viewer = simpleVis(cloud1, cloud1);
while (!viewer->wasStopped())
{
    …
pcl::visualization::PointCloudColorHandlerCustom add_color1(cloud_cluster, rand() % 255, rand() % 255, rand() % 255);//添加随机颜色
//更新到窗口sample cloud0
    viewer->updatePointCloud(cloud_cluster, add_color1, “sample cloud0”);
    viewer->spinOnce(100);
}

注意:

viewer->spinOnce(100);

一定要记得放在合适的位置,否则无法显示

你可能感兴趣的:(c/c++)