pcl中visualization模块中常用于点云可视化的两个class:
1.class pcl::visualization::Cloudviewer(功能简单)
2.class pcl::visualization::PCLVisualizer(成员函数非常多,内容很丰富,为点云可视化中最重要的class)
点云可视化的情况可分为以下情况:
情况1.简单地显示单一点云
代码如下
pcl::CloudPoint<pcl::PointXYZ>::Ptr cloud(new pcl::CloudPoint<pcl::PointXYZ>);
pcl::visualization::CloudViewer viewer("simple cloud viewer.");
viewer.showCloud(cloud);
while(!viewer.wasStopped())
{
}
效果图
情况2.一个视口显示多个点云
代码如下:(我这里是利用parametric model 进行投影,具体参见pcl官网filters模块)
boost::shared_ptr< pcl::visualization::PCLVisualizer > viewer(new pcl::visualization::PCLVisualizer("project points using aparameyric model"));
viewer->setBackgroundColor(0, 0, 0); //创建窗口
int v1;
viewer->createViewPort(0.0, 0.0, 1.0, 1.0, v1);
//设置点云颜色
pcl::visualization::PointCloudColorHandlerCustom<pcl::PointXYZ> source_color(cloud, 34, 25, 133); //投影前可以随便设一个颜色
pcl::visualization::PointCloudColorHandlerCustom<pcl::PointXYZ> target_color(cloud_projected, 255, 255, 255); //投影后的设置为白色
viewer->addPointCloud<pcl::PointXYZ>(cloud, source_color, "source", v1);
viewer->addPointCloud<pcl::PointXYZ>(cloud_projected, target_color, "projected", v1);
viewer->setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 2, "source");
viewer->setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 2, "projected");
viewer->spin();
效果图
情况3:多视口显示
//5双视窗口
boost::shared_ptr<pcl::visualization::PCLVisualizer> viewer(new pcl::visualization::PCLVisualizer("filter Viewer"));
viewer->initCameraParameters();
int v1(0), v2(0);//视口编号在这里设置两个视口
//5.1原始点云窗口
viewer->createViewPort(0.0, 0.0, 0.5, 1.0, v1);
viewer->setBackgroundColor(0, 0, 0, v1);
viewer->addText("original", 10, 10, "v1 text", v1);
viewer->addPointCloud<pcl::PointXYZ>(cloud, "sample cloud1", v1);
viewer->addCoordinateSystem(1.0);
viewer->setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 2, "sample cloud1");
//5.2滤波窗口
viewer->createViewPort(0.5, 0.0, 1.0, 1.0, v2);
viewer->setBackgroundColor(0, 0, 0, v2);
viewer->addText("after filtered", 10, 10, "v2 text", v2);
viewer->addPointCloud<pcl::PointXYZ>(cloud_filter, "sample cloud2", v2);
viewer->addCoordinateSystem(1.0);
viewer->setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 2, "sample cloud2");
while (!viewer->wasStopped())
{
viewer->spinOnce(100); //刷新
boost::this_thread::sleep(boost::posix_time::microseconds(100000));
}
效果图
这里有更详细的介绍https://segmentfault.com/a/1190000006685118