osg显示点云
来源:互联网 发布:软件企业 认定 2016 编辑:程序博客网 时间:2024/05/17 07:45
利用pcl读取点云,osg显示,相比pcl中的vtk显示,osg显示点云稍微复杂一些。
#include <osgViewer/Viewer>#include <osgViewer/ViewerEventHandlers>#include <osg/Node>#include <osg/Geode>#include <osg/Geometry>#include <osgDB/ReaderWriter>#include <osgDB/ReadFile>#include <osgDB/WriteFile>#include <osgGA/StateSetManipulator>#include <osgUtil/Optimizer>#include <osgUtil/DelaunayTriangulator>#include <pcl/io/ply_io.h>#include <pcl/point_types.h>#include <iostream>int main(){ osg::ref_ptr<osgViewer::Viewer> viewer = new osgViewer::Viewer() ; viewer->addEventHandler(new osgGA::StateSetManipulator(viewer->getCamera()->getOrCreateStateSet())) ; osg::ref_ptr<osg::Group> root = new osg::Group() ; //创建顶点数组 osg::ref_ptr<osg::Vec3Array> coords = new osg::Vec3Array() ; osg::ref_ptr<osg::Vec4Array> color = new osg::Vec4Array() ; pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>) ; if (pcl::io::loadPLYFile("3-1-2.ply" , *cloud) == -1) { std::cout<<"读取点云失败!\n" ; return -1 ; } int nums = cloud->size() ; std::cout<<"点云数据:"<<nums<<std::endl ; int k = 0 ; for (int i = 0 ; i < nums ; ++i) { coords->push_back(osg::Vec3(cloud->points[i].x , cloud->points[i].y , cloud->points[i].z)) ; color->push_back(osg::Vec4(1.0f , 0.0f , 0.0f , 0.3f)) ; k++ ; } //创建几何体 osg::ref_ptr<osg::Geometry> geometry = new osg::Geometry() ; //设置顶点数组 geometry->setVertexArray(coords.get()) ; geometry->setColorArray(color.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 , k)) ; //设置关联方式 //添加到叶节点 osg::ref_ptr<osg::Geode> geode = new osg::Geode() ; geode->addDrawable(geometry.get()) ; root->addChild(geode.get()) ; //优化场景数据 osgUtil::Optimizer optimizer ; optimizer.optimize(root.get()) ; viewer->setSceneData(root.get()) ; viewer->realize() ; viewer->run() ; return 1 ;}
工程下载附带点云
0 0
- osg显示点云
- osg显示点云
- OSG+Duilib显示osg
- osg 绘制图像,单个点或小对象无法显示
- OSG-Win32窗口显示osg
- osg如何显示文字
- OSG简化几何体显示
- osg汉字显示
- OSG设置半透明显示
- osg 网格显示球体
- osg 透明度显示方式
- OSG球表面点计算
- 应用MFC框架显示OSG
- OSG 显示文字与 HUD
- OSG和osgearth显示中文
- OSG和osgearth显示中文
- OSG和osgearth显示中文
- OSG中LabelControl中文显示
- V4L2研究之camera 一
- 《测控原理》20160607
- 剑指offer-32从1到n整数出现1的次数
- 【EhCache】Java缓存框架使用EhCache结合Spring AOP
- Eclipse下使用findbugs进行代码审查
- osg显示点云
- javascript理解之变量作用域与闭包
- 160.[Leetcode]Intersection of Two Linked Lists
- Ubuntu安装g++
- 推荐系统-协同过滤
- QMap类和QHash类
- 无锁哈希表的实现
- 李航《统计学习方法》第二章 感知机
- java cmd 打开带密压缩文件 穷举解压