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

osg点云加载与渲染

目录

效果

laslib 关键代码

完整代码


效果

las点云读取使用了laslib这个库。

laslib 关键代码

{// 这里演示读取一个 .txt 点云文件const char* lasfile = path.c_str();std::ifstream ifs;ifs.open(lasfile, std::ios::in | std::ios::binary);liblas::ReaderFactory f;liblas::Reader reader = f.CreateWithStream(ifs);liblas::Header const & header = reader.GetHeader();int count = header.GetPointRecordsCount();int i = 0;while (reader.ReadNextPoint() && i < 10){liblas::Point const& p = reader.GetPoint();double time = p.GetTime();double x = p.GetX();double y = p.GetY();double z = p.GetZ();float intensity = p.GetIntensity();liblas::Color color = p.GetColor();coords->push_back(osg::Vec3(x, y, z));colors->push_back(osg::Vec4(color.GetRed(), color.GetGreen(), color.GetBlue(), 1.0f));cloudNum++;}ifs.close();}

完整代码

osg::ref_ptr<osg::Vec3Array> coords = new osg::Vec3Array();// 创建颜色osg::ref_ptr<osg::Vec4Array> colors = new osg::Vec4Array();/读取点云文件//int cloudNum = 0;{// 这里演示读取一个 .txt 点云文件const char* lasfile = path.c_str();std::ifstream ifs;ifs.open(lasfile, std::ios::in | std::ios::binary);liblas::ReaderFactory f;liblas::Reader reader = f.CreateWithStream(ifs);liblas::Header const & header = reader.GetHeader();int count = header.GetPointRecordsCount();int i = 0;while (reader.ReadNextPoint() && i < 10){liblas::Point const& p = reader.GetPoint();double time = p.GetTime();double x = p.GetX();double y = p.GetY();double z = p.GetZ();float intensity = p.GetIntensity();liblas::Color color = p.GetColor();coords->push_back(osg::Vec3(x, y, z));colors->push_back(osg::Vec4(color.GetRed(), color.GetGreen(), color.GetBlue(), 1.0f));cloudNum++;}ifs.close();}/读取点云文件////创建几何体osg::ref_ptr<osg::Geometry> geometry = new osg::Geometry();// 设置顶点数组geometry->setVertexArray(coords.get());geometry->setColorArray(colors.get());geometry->setColorBinding(osg::Geometry::BIND_PER_VERTEX);osg::Vec3Array *normals = new osg::Vec3Array;normals->push_back(osg::Vec3(0.0f, 1.0f, 0.0f));// geometry->setNormalArray(normals);// geometry->setNormalBinding(osg::Geometry::BIND_OVERALL);// 设置关联方式geometry->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::POINTS, 0, cloudNum));// 添加到叶节点osg::ref_ptr<osg::Geode> geode = new osg::Geode();osg::ref_ptr<osg::Group> root = new osg::Group();geode->addDrawable(geometry.get());root->addChild(geode.get());

http://www.lryc.cn/news/225950.html

相关文章:

  • 后端架构选择:构建安全强大的知识付费小程序平台
  • 第四节(2):修改WORD中表格数据的方案
  • Qt中对Udp数据打包发送和接收
  • 回调地狱 与 Promise(JavaScript)
  • 【Android】UI开发中的一些小细节笔记
  • 第十三章《搞懂算法:神经网络是怎么回事》笔记
  • SpringBoot不同环境加载不同配置文件(dev,sit,uat)
  • 2023.11.8 hadoop学习-概述,hdfs dfs的shell命令
  • Azure 机器学习 - 使用自动化机器学习训练计算机视觉模型的数据架构
  • STM32F4X SDIO(九) 例程讲解-SD卡擦除、读写
  • 【机器学习范式】监督学习,无监督学习,强化学习, 半监督学习,自监督学习,迁移学习,对比分析+详解与示例代码
  • JUC包下面的四大天王+线程池部分知识
  • AGV系统控制位置管理功能
  • JavaScript从入门到精通系列第三十三篇:详解正则表达式语法(二)
  • 由于找不到 d3dx9_43.dll,无法继续执行代码。重新安装程序可能会解决此问题
  • AI全栈大模型工程师(二十一)LangChain和SemanticKernel怎么选
  • npm install 报错 chromedriver 安装失败的解决办法
  • C语言--每日五道选择题--Day6
  • element-ui 封装 表格
  • 数据的使用、表关系的创建、Django框架的请求生命周期流程图
  • Python基础教程:类--继承和方法的重写
  • Three.js提供了多种类型的灯光
  • 精通Nginx(10)-负载均衡
  • Hls学习(一)
  • Maven打包引入本地依赖包
  • Docker常用命令及部署微服务项目
  • okhttp添加公共参数
  • 基于SpringBoot的SSMP整合案例(开启日志与分页查询条件查询功能实现)
  • android studio 修改图标
  • pytorch学习之第二课之预测温度