PCLVisualizer显示点云的深层用法

以下代码均是在QT中使用QVTKOpenGLNativeWidget的简单教程以及案例-CSDN博客文章的基础上,修改按钮对应的槽函数中的程序。

1.显示文件中点云颜色属性信息,利用PointCloudColorHandlerRGBField得到每个点云对应的颜色。

复制代码
    pcl::PointCloud<pcl::PointXYZRGBA>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZRGBA>);   //创建点云指针
    QString fileName = QFileDialog::getOpenFileName(this, "Open PointCloud", ".", "Open PCD files(*.pcd)");
    if(fileName == "") return;
    pcl::io::loadPCDFile(fileName.toStdString(),*cloud);
    pcl::visualization::PointCloudColorHandlerRGBField<pcl::PointXYZRGBA> rgb(cloud); 
    view->addPointCloud<pcl::PointXYZRGBA>(cloud, "sample cloud");
    //view->setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 3, "sample cloud"); // 用于改变显示点云的尺寸
    view->resetCamera();    //视角
    ui->guiwidget->update();

2.自定义点云颜色,利用PointCloudColorHandlerCustom将整个点云进行着色。

复制代码
    pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>);   //创建点云指针
    QString fileName = QFileDialog::getOpenFileName(this, "Open PointCloud", ".", "Open PCD files(*.pcd)");
    if(fileName == "") return;
    pcl::io::loadPCDFile(fileName.toStdString(),*cloud);
    pcl::visualization::PointCloudColorHandlerCustom<pcl::PointXYZ> single_color(cloud, 255, 0, 255);
    view->addPointCloud<pcl::PointXYZ>(cloud, single_color,"sample cloud"); /添加点云时,可以指定添加到视窗中点云的PointCloudColorHandlerRGB着色处理对象。 
    view->resetCamera();    //视角
    ui->guiwidget->update();

3.用颜色区别深度,利用PointCloudColorHandlerGenericField将不同的深度值显示为不同的颜色,实现以颜色区分深度的目的;PointCloudColorHandlerCustom将点云作为整体并统一着色,PointCloudColorHandlerGenericField将点云按深度值("x"、"y"、"z"均可)的差异着以不同的颜色。

复制代码
    pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>);   //创建点云指针
    QString fileName = QFileDialog::getOpenFileName(this, "Open PointCloud", ".", "Open PCD files(*.pcd)");
    if(fileName == "") return;
    pcl::io::loadPCDFile(fileName.toStdString(),*cloud);
    pcl::visualization::PointCloudColorHandlerGenericField<pcl::PointXYZ> fildColor(cloud, "y"); // 按照y字段进行渲染
    view->addPointCloud<pcl::PointXYZ>(cloud, fildColor,"sample cloud");  //添加点云的时候,指定添加到视窗中点云的PointCloudColorHandlerRGB着色处理对象。
    view->resetCamera();    //视角
    ui->guiwidget->update();
相关推荐
鲸屿1958 分钟前
python之socket网络编程
开发语言·网络·python
没有梦想的咸鱼185-1037-166334 分钟前
基于R语言机器学习方法在生态经济学领域中的实践技术应用
开发语言·机器学习·数据分析·r语言
向上的车轮1 小时前
基于go语言的云原生TodoList Demo 项目,验证云原生核心特性
开发语言·云原生·golang
The Chosen One9851 小时前
C++ : AVL树-详解
开发语言·c++
SNAKEpc121381 小时前
QML和Qt Quick
c++·qt
PH_modest1 小时前
【Qt跬步积累】—— 初识Qt
开发语言·qt
怀旧,2 小时前
【C++】18. 红⿊树实现
开发语言·c++
xiaopengbc2 小时前
在 Python 中实现观察者模式的具体步骤是什么?
开发语言·python·观察者模式
Python大数据分析@2 小时前
python用selenium怎么规避检测?
开发语言·python·selenium·网络爬虫
ThreeAu.2 小时前
Miniconda3搭建Selenium的python虚拟环境全攻略
开发语言·python·selenium·minicoda·python环境配置