osg gdal加载tif数据文件
osg加载.tif地形数据文件
- #ifdef _WIN32
- #include <Windows.h>
- #endif // _WIN32
- #include <iostream>
- //#include <math.h>
- #include <osg/Node>
- #include <osg/Group>
- #include <osgDB/ReadFile>
- #include <osgViewer/Viewer>
- #include <osg/Geode>
- #include <osg/ShapeDrawable>
- #include <osg/Material>
- #include <osg/Image>
- #include <osg/Texture2D>
- #include <osg/BoundingSphere>
- #include <osg/LineWidth>
- #include <osg/Point>
- #include <osg/TexGen>
- #include <osg/TexEnv>
- //#include <osg/TessellationHints>
- //#include <osg/NodePath>
- #include <osgGA/GUIEventHandler>
- #include <osgGA/GUIEventAdapter>
- #include <osg/PositionAttitudeTransform>
- #include <osgViewer/ViewerEventHandlers>
- #include <osg/MatrixTransform>
- #include <OpenThreads/Thread>
- #include <osg/LightSource>
- #include <osg/Light>
- #include <gdal.h>
- osg::ref_ptr<osg::Node> CreateNode()
- {
- osg::ref_ptr<osg::Group> _root = new osg::Group;
- //定义并读取高程文件
- //真实高程文件名称为:ASTGTM2_N34E110_dem.tif
- //属于特殊的tiff格式,GEOTiff
- //读取的时候使用osg的gdal插件进行读取,所以在路径后面加上了.gdal
- //.gdal后缀名只要在这里加就可以了,真实的高程文件后缀名不需要修改
- //osg::ref_ptr<osg::HeightField> heightMap = osgDB::readHeightFieldFile("E:\\OpenSourceGraph\\osgearth_install20190830\\data\\world.tif.gdal");
- osg::ref_ptr<osg::HeightField> heightMap = osgDB::readHeightFieldFile("E:\\OpenSourceGraph\\osgearth_install20190830\\data\\1\\1_0_0_5.tif.gdal");
- //创建一个叶结点对象
- osg::ref_ptr<osg::Geode> geode = new osg::Geode;
- if (heightMap != nullptr)
- {
- //由于原始数据过大,创建三维对象会失败,所以重新构造一个对象
- //相当于数据抽稀了一次。当然,可以直接把原图使用特殊工具裁了
- //创建一个新的HeightField对象,用来拷贝heightMap
- osg::ref_ptr<osg::HeightField> heightMap1 = new osg::HeightField;
- //从原对象中拷贝一些熟悉过来
- heightMap1->setOrigin(heightMap->getOrigin());
- heightMap1->setRotation(heightMap->getRotation());
- heightMap1->setSkirtHeight(heightMap->getSkirtHeight());
- //XY方向的间隔设置为原来的两倍,
- heightMap1->setXInterval(heightMap->getXInterval() * );
- heightMap1->setYInterval(heightMap->getYInterval() * );
- //设置新的高程数据量的行列数目为原来的一半
- heightMap1->allocate(heightMap->getNumColumns() / , heightMap->getNumRows() / );
- //把真实的数据值放进来
- for (size_t r = ; r < heightMap1->getNumRows(); ++r)
- {
- for (size_t c = ; c < heightMap1->getNumColumns(); ++c)
- {
- //加载的数据中XY方向的间隔是0.0002左右(经纬度偏移),3600个格子,数量级太小,高程值动辄在千级别,如果没有进行坐标转换(GPS转换成米),显示出来之后结果会严重失常。所以此处简单的给高度值除以50000(这个是按照这个tif文件来试出来的,不同高程文件可能不同)
- heightMap1->setHeight(c, r, heightMap->getHeight(c * , r * ) / );
- }
- }
- //添加到叶子节点中
- geode->addDrawable(new osg::ShapeDrawable(heightMap1));
- osg::ref_ptr<osg::Material> material = new osg::Material;
- material->setAmbient(osg::Material::FRONT_AND_BACK, osg::Vec4(1.0f, 1.0f, 1.0f, 1.0f));
- material->setDiffuse(osg::Material::FRONT_AND_BACK, osg::Vec4(1.0f, 1.0f, 1.0f, 1.0f));
- material->setSpecular(osg::Material::FRONT_AND_BACK, osg::Vec4(1.0f, 1.0f, 1.0f, 1.0f));
- material->setShininess(osg::Material::FRONT_AND_BACK, );
- osg::ref_ptr<osg::Texture2D> texture2D = new osg::Texture2D;
- //设置纹理
- osg::ref_ptr<osg::Image> image1 = osgDB::readImageFile("D:\\image_1\\arm1.jpg");
- if (image1.valid())
- {
- texture2D->setImage(image1.get());
- }
- geode->getOrCreateStateSet()->setAttributeAndModes(material.get(), osg::StateAttribute::ON);
- geode->getOrCreateStateSet()->setTextureAttributeAndModes(, texture2D, osg::StateAttribute::ON);
- }
- _root->addChild(geode.get());
- return _root.get();
- }
- osg::ref_ptr<osg::Light> createLight()
- {
- osg::ref_ptr<osg::Light> l = new osg::Light;
- l->setLightNum();//启用第几个光源 OpenGL有8个光源
- l->setDirection(osg::Vec3(, , -));//方向
- l->setPosition(osg::Vec4(10.0, 10.0, 0.0, 0.0f));//位置
- //osg::LightSource* ls = new osg::LightSource();//此处用超级指针 返回会发生错误
- //ls->setLight(l);
- return l;
- }
- int main()
- {
- osg::ref_ptr<osgViewer::Viewer> viewer1 = new osgViewer::Viewer;
- osg::ref_ptr<osg::Group> group1 = new osg::Group;
- group1->addChild(CreateNode());
- viewer1->setSceneData(group1.get());
- viewer1->setUpViewInWindow(, , , , );
- viewer1->setLight(createLight());
- return viewer1->run();
- }
osg gdal加载tif数据文件的更多相关文章
- iOS --- UIWebView的加载本地数据的三种方式
UIWebView是IOS内置的浏览器,可以浏览网页,打开文档 html/htm pdf docx txt等格式的文件. safari浏览器就是通过UIWebView做的. 服务器将MIM ...
- ios网络学习------4 UIWebView的加载本地数据的三种方式
ios网络学习------4 UIWebView的加载本地数据的三种方式 分类: IOS2014-06-27 12:56 959人阅读 评论(0) 收藏 举报 UIWebView是IOS内置的浏览器, ...
- OSG加载倾斜摄影数据
目录 1. 概述 2. 实例 2.1. 代码 2.2. 解析 3. 结果 1. 概述 ContextCapture(Smart3D)生成的倾斜摄影模型数据一般都形如如下组织结构: 在Data目录下包含 ...
- Swift - 网页控件(UIWebView)加载本地数据,文件
使用UIWebView加载本地数据或资源有如下三种方式: 1,使用loadHTMLString方法加载HTML内容 2,使用loadRequest方法加载本地资源(也可用于加载服务器资源) 3,先将内 ...
- geotrellis使用(二十三)动态加载时间序列数据
目录 前言 实现方法 总结 一.前言 今天要介绍的绝对是华丽的干货.比如我们从互联网上下载到了一系列(每天或者月平均等)的MODIS数据,我们怎么能够对比同一区域不同时间的数据情况,采用 ...
- 速战速决 (5) - PHP: 动态地创建属性和方法, 对象的复制, 对象的比较, 加载指定的文件, 自动加载类文件, 命名空间
[源码下载] 速战速决 (5) - PHP: 动态地创建属性和方法, 对象的复制, 对象的比较, 加载指定的文件, 自动加载类文件, 命名空间 作者:webabcd 介绍速战速决 之 PHP 动态地创 ...
- ajax验证表单元素规范正确与否 ajax展示加载数据库数据 ajax三级联动
一.ajax验证表单元素规范正确与否 以用ajax来验证用户名是否被占用为例 1创建表单元素<input type="text" id="t"> 2 ...
- [翻译][MVC 5 + EF 6] 7:加载相关数据
原文:Reading Related Data with the Entity Framework in an ASP.NET MVC Application 1.延迟(Lazy)加载.预先(Eage ...
- UIWebView 加载网页、文件、 html-b
UIWebView 是用来加载加载网页数据的一个框.UIWebView可以用来加载pdf word doc 等等文件 生成webview 有两种方法,1.通过storyboard 拖拽 2.通过al ...
随机推荐
- 大数据之路week07--day05 (一个基于Hadoop的数据仓库建模工具之一 HIve)
什么是Hive? 我来一个短而精悍的总结(面试常问) 1:hive是基于hadoop的数据仓库建模工具之一(后面还有TEZ,Spark). 2:hive可以使用类sql方言,对存储在hdfs上的数据进 ...
- c# DES 加密解密方法
#region 密钥 private static string key = "abcd1234"; //密钥(长度必须8位以上) #endregion #region DES加密 ...
- jmeter 压测工具安装及使用
linux下jmeter安装: 1. 下载JMeter官方网站下载最新版本: http://jmeter.apache.org/download_jmeter.cgi ,目前最新版是Apache JM ...
- 获取当前时间减去 xx时,xx分,xx秒
使用 datetime 模块来获取当前详细时间,并将当前时间减去或增加多少 import datetime # 当前时间减去两分钟 ctime = datetime.datetime.now() ...
- Oracle row_number() over() 分析函数--取出最新数据
语法格式:row_number() over(partition by 分组列 order by 排序列 desc) 一个很简单的例子 1,先做好准备 create table test1( id v ...
- leetcode 63 简单题
题目很水... 直接放代码了 int uniquePathsWithObstacles(int** obstacleGrid, int obstacleGridRowSize, int obstacl ...
- 读取中文文件到CString
CString strFileName = _T("D:\\ai\\100.json"); CFile file; file.Open(strFileName, CFile:: ...
- 自动化部署--Jenkins
自动化部署--Jenkins--简介安装(一) https://www.jianshu.com/p/b9ce206139f1 自动化部署--Jenkins--Maven构建(二) https://w ...
- element ui的table的头部自定义
<el-table-column label="级别" min-width="120" prop="clueLevel" align= ...
- mongo最大连接数查看
进入客户端 mongo 输入查看命令 db.serverStatus().connections