PCL学习笔记(8)——PCL CloudViewer 可视化类01

一、简介
点云视窗类CloudViewer是简单的可视化点云工具类,仅用几行代码就可以让用户查看点云;但需要注意的是该类不能用于多线程应用程序中。
如果只想使用几行代码在应用程序中可视化某些内容,请使用如下代码段:

//#include <iostream>
//#include <pcl\io\pcd_io.h>
//#include <pcl\visualization\cloud_viewer.h>
//读取数据
	pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>);
	pcl::PCDReader reader;
	if (reader.read("sofa.pcd", *cloud) < 0)
	{
		PCL_ERROR("\a->点云文件不存在!\n");
		system("pause");
		return -1;
	}
	cout << "点云number:" << cloud->points.size() << endl;

	//简单可视化
	pcl::visualization::CloudViewer viewer("Simple_Viewer");
	viewer.showCloud(cloud);
	while (!viewer.wasStopped())
	{
	}

在这里插入图片描述
输入h,显示帮助:
在这里插入图片描述

控制按钮:
帮助:
p, p:切换到基于点的表示
w, w:切换到基于线框的表示(在可用的情况下)
s, s:切换到基于表面的表示(在可用的情况下)
获取当前窗口视图的。png快照
c, c:显示当前摄像头/窗口参数
f, f:飞到点模式
e, e:退出交互程序
q, q:停止并调用VTK的TerminateApp
+/-:增加/减少整体点大小
+/- [+ ALT]:放大/缩小
g, g:显示比例栅格(开/关)
u, u:显示查找表(开/关)
o, o:在透视/平行投影之间切换(默认=透视)
r, r [+ ALT]: reset camera [to viewpoint = {0,0,0} -> center_{x, y, z}]
CTRL + s, s:保存摄像机参数
CTRL + r, r:恢复摄像机参数
ALT + s, s:开启/关闭立体声模式
ALT + f, f:在最大化窗口模式和原始大小之间切换
列出当前角色映射的所有可用的几何和颜色处理程序
ALT + 0 . .[+ CTRL]:在不同的几何处理程序之间切换(在可用的地方)
0 . .9 [+ CTRL]:切换不同的颜色处理程序(在可用的地方)
SHIFT +左键点击:选择一个点(从-use_point_picking开始)
x, x:切换鼠标左键的橡皮筋选择模式

更完整的示例:
复杂部分:
下面展示了如何在可视化线程上运行代码。PCLVisualizer 是云查看器,但它在自己的线程中运行。要访问它,您必须使用回调函数,以避免可视化并发问题。但是必须注意避免代码中的竞争条件,因为将从可视化线程调用回调。

#include <pcl/visualization/cloud_viewer.h>
#include <iostream>
#include <pcl/io/io.h>
#include <pcl/io/pcd_io.h>
    
int user_data;
    
void 
viewerOneOff (pcl::visualization::PCLVisualizer& viewer)
{
    viewer.setBackgroundColor (1.0, 0.5, 1.0);
    pcl::PointXYZ o;
    o.x = 1.0;
    o.y = 0;
    o.z = 0;
    viewer.addSphere (o, 0.25, "sphere", 0);
    std::cout << "i only run once" << std::endl;
    
}
    
void 
viewerPsycho (pcl::visualization::PCLVisualizer& viewer)
{
    static unsigned count = 0;
    std::stringstream ss;
    ss << "Once per viewer loop: " << count++;
    viewer.removeShape ("text", 0);
    viewer.addText (ss.str(), 200, 300, "text", 0);
    
    //FIXME: possible race condition here:
    user_data++;
}
    
int 
main ()
{
    pcl::PointCloud<pcl::PointXYZRGBA>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZRGBA>);
    pcl::io::loadPCDFile ("my_point_cloud.pcd", *cloud);
    
    pcl::visualization::CloudViewer viewer("Cloud Viewer");
    
    //blocks until the cloud is actually rendered
    viewer.showCloud(cloud);
    
    //use the following functions to get access to the underlying more advanced/powerful
    //PCLVisualizer
    
    //This will only get called once
    viewer.runOnVisualizationThreadOnce (viewerOneOff);
    
    //This will get called once per visualization iteration
    viewer.runOnVisualizationThread (viewerPsycho);
    while (!viewer.wasStopped ())
    {
    //you can also do cool processing here
    //FIXME: Note that this is running in a separate thread from viewerPsycho
    //and you should guard against race conditions yourself...
    user_data++;
    }
    return 0;
}

另外还可以设置viewer的属性,设置点云显示的颜色,大小等等
PCL Visualizer可视化类其他属性设置

  boost::shared_ptr<pcl::visualization::PCLVisualizer> viewer (new pcl::visualization::PCLVisualizer ("3D Viewer"));
  viewer->setBackgroundColor (0, 0, 0);

官网:
添加链接描述

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值