当前位置: 首页 > web >正文

PCL实时动态加载显示点云功能以及laslib配置

最近需要3D图形化显示点云功能,网上搜了一下发现有PCL点云库的例程。但是发现这个例程是一次性加载完所有点云然后再显示的。感觉这个不太符合项目上的需求,项目上希望能够实时的像流量计一样动态显示点云。所以就把代码改动了一下,发现效果还可以。而且网上还没有类似的例子,所以就分享下希望能帮到有需要的同学。

运行效果:

完整代码:

#include <iostream>
#include <vector>
#include <ctime>
#include <pcl/point_cloud.h>
#include <pcl/octree/octree.h>
#include <boost/thread/thread.hpp>
#include <pcl/visualization/pcl_visualizer.h>#include <stdio.h>
#include <lasreader.hpp>
#include <laswriter.hpp>
#include <iostream>#include <Windows.h>
#pragma comment(lib,"winmm.lib")using namespace std;pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>);
LASreader* lasreader = nullptr;//void CALLBACK CallBackFunc(UINT uTimerID, UINT uMsg, DWORD_PTR dwUser, DWORD_PTR dw1, DWORD_PTR dw2)
//{
//	printf("CallBackFunc\n");
//}void ThreadUser() { //线程入口cout << "thread start." << endl;// 创建点云数据int i = 0;while (lasreader->read_point()) {if (!(i % 10)) {pcl::PointXYZ point;point.x = lasreader->point.get_x();point.y = lasreader->point.get_y();point.z = lasreader->point.get_z();cloud->push_back(point);}i++;}cout << "thread end." << endl;
}int main(int argc, char** argv)
{LASreadOpener lasreadopener;std::string file_name = "E:\\xyz.laz";lasreader = lasreadopener.open(file_name.c_str());if (lasreader == nullptr) {std::cerr << "File could not be opened." << std::endl;return -1;}//定时加载点云//timeSetEvent(1000, 1, CallBackFunc, (DWORD)NULL, TIME_PERIODIC);//创建子线程HANDLE h; //线程句柄h = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)ThreadUser, NULL, 1, 0); //创建子线程// 初始化点云可视化对象std::shared_ptr<pcl::visualization::PCLVisualizer>viewer(new pcl::visualization::PCLVisualizer("显示点云"));viewer->setBackgroundColor(255, 255, 255);  //设置背景颜色为白色// 对点云着色可视化设置颜色pcl::visualization::PointCloudColorHandlerCustom<pcl::PointXYZ>target_color(cloud, 0, 0, 0);ResumeThread(h);  //启动子线程// 等待直到可视化窗口关闭int cloudID = 0;while (!viewer->wasStopped()){if (cloud->size()) {viewer->addPointCloud<pcl::PointXYZ>(cloud, target_color, to_string(cloudID));//viewer->setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 1, to_string(cloudID));printf("added point sum:%d cloudId:%d\n", cloud->points.size(), cloudID);cloud->clear();cloudID++;}viewer->spinOnce(100);// 等待100毫秒后再次检查停止条件,并刷新界面//viewer->removePointCloud(to_string(cloudID - 1));}CloseHandle(h);delete lasreader; // 释放资源return (0);
}

laslib配置:

参考例子:

超详细保姆级PCL1.14.0 安装配置流程

http://www.xdnf.cn/news/2724.html

相关文章:

  • 使用Python在excel里创建柱状图
  • 如何搭建spark yarn 模式的集群集群
  • uniapp利用生命周期函数实现后台常驻示例
  • auto(x) decay copy
  • 一键叠图工具
  • 浏览器存储
  • 服务器文件同步工具有哪些?
  • 经典数仓架构深度解析与演进:从离线处理到新型架构对比
  • 实战篇:在QEMU中编写和调试VHost/Virtio驱动
  • 从数据到决策:如何使用Python进行自动驾驶数据分析
  • 利用Python打印有符号十进制数的二进制原码、反码、补码
  • 问题 ERROR: for jobmanager ‘ContainerConfig‘ 原因及解决
  • ComfyUI 学习笔记:安装篇及模型下载
  • 2025-4-27-C++ 学习 数组(2)
  • springboot项目文件上传到服务器本机,返回访问地址
  • 高级数据库对象全面解析:视图、存储过程与触发器
  • Express.js 框架教程:从入门到精通
  • 【“星瑞” O6 评测】 — llm CPU部署对比高通骁龙CPU
  • T-BOX应用 NXP S32K148控芯片搭配 SD NAND(嵌入式SD卡)存储的完美结合
  • 设计模式(状态模式)
  • 【力扣刷题实战】丢失的数字
  • vue代码规范管理
  • BeeWorks企业内部即时通讯软件支持国产化,已在鸿蒙系统上稳定运行
  • 【Altium】自定义菜单显示名称
  • C++23 std::bind_back:一种调用包装器 (P2387R3)
  • Matlab自学笔记五十二:变量名称:检查变量名称是否存在或是否与关键字冲突
  • Nacos-3.0.0适配PostgreSQL数据库
  • 互容是什么意思?
  • python+selenium实现淘宝商品数据半自动查询
  • pg数据库删除模式