激光雷达,需要用到点云的实时显示,记录如下:
simpleVis(pcl::PointCloud<PointT>::ConstPtr cloud, pcl::PointCloud<PointT>::ConstPtr cloud2) {
boost::shared_ptr<pcl::visualization::PCLVisualizer> 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<PointT> single_color0(cloud, 255, 0, 255);
viewer->addPointCloud<PointT>(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<PointT> single_color(cloud, 0, 255, 0);
viewer->addPointCloud<PointT>(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<pcl::visualization::PCLVisualizer> viewer;
//点云实时显示
viewer = simpleVis(cloud1, cloud1);
while (!viewer->wasStopped())
{
…
pcl::visualization::PointCloudColorHandlerCustom<PointT> add_color1(cloud_cluster, rand() % 255, rand() % 255, rand() % 255);//添加随机颜色
//更新到窗口sample cloud0
viewer->updatePointCloud<pcl::PointXYZ>(cloud_cluster, add_color1, “sample cloud0”);
viewer->spinOnce(100);
}
注意:
viewer->spinOnce(100);
一定要记得放在合适的位置,否则无法显示
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。