osgEarth使用笔记3——加载倾斜摄影数据

简介: osgEarth使用笔记3——加载倾斜摄影数据

osgEarth使用笔记3——加载倾斜摄影数据

目录

1. 概述

我在《OSG加载倾斜摄影数据》这篇博文中论述了如何通过OSG生成一个整体的索引文件,通过这个索引文件来正确显示ContextCapture(Smart3D)生成的倾斜摄影模型数据。这类倾斜摄影模型数据一般都会有个元数据metadata.xml,通过这个元数据,可以将其正确显示在osgEarth的数字地球上。

2. 详论

2.1. 位置

metadata.xml中的内容一般如下所示:

SRS就是空间坐标参考的意思,ENU表示是东北天站心坐标系,站心点的经纬度坐标为(108.9594, 34.2196)。这个站心点对应的应该是倾斜摄影模型的中心点,那么思路就很简单了,只需要平移旋转这个倾斜摄影模型,使模型的中心点对应于站心点。这其实是个地心坐标系于站心坐标系转换的问题:

在osgEarth中可以不用关心这个问题,其直接封装了一个类osgEarth::GeoTransform,可以直接通过这个类的接口来加载倾斜摄影模型:

std::string filePath = "D:/Data/scene/Dayanta/Data.osgb";
osg::ref_ptr<osg::Node> node = osgDB::readNodeFile(filePath);
osg::ref_ptr<osgEarth::GeoTransform> xform = new osgEarth::GeoTransform();
xform->addChild(node);
xform->setTerrain(mapNode->getTerrain());
osgEarth::GeoPoint point(map->getSRS(), 108.9594, 34.2196, -410);                 //使用绝对高,正高
xform->setPosition(point);
osg::ref_ptr<osgEarth::ModelLayer> modelLayer = new osgEarth::ModelLayer("oblic", xform);
map->addLayer(modelLayer);

给osgEarth::GeoTransform传入的osgEarth::GeoPoint就是站心点。不过这种类型的metadata.xml似乎都没有给出准确的高程值,所以需要自己调整高程来贴地。可能因为我这里试用的倾斜摄影数据都是网上找的,不太可能给出准确的地理坐标。

2.2. 着色

另外一点要注意的是直接读取加载的倾斜摄影模型是没有颜色信息的,这点和OSG还不太一样,在帮助文档里面论述了这个问题:

所以一定要记得加上着色器渲染,否则倾斜摄影模型会变成白模:

osgEarth::Registry::shaderGenerator().run(node);

2.3. 其他

有的metadata.xml里面的内容是这样的:

这个元数据的意思是这个倾斜摄影模型是根据EPSG编号为2384的空间参考坐标系下构建的。简单查了一下这个坐标系应该是xian80高斯克吕格平面投影直角坐标系,因为是用于三维数据,所以加上一个高程形成一个三维立体直角坐标系。严格意义上来讲,是需要将地球展成这个立体直角坐标系,将这个倾斜摄影模型放置到SRSOrigin的地理位置才是最准确的。但是一般的投影东向和北向的方向是不会变的,仍然可以将SRSOrigin的地理位置当成一个站心位置,只不过这个站心位置不再是经纬度而是EPSG:2384的平面坐标值(加上高程)。

所以像这种类型的数据,只需要将SRSOrigin的地理位置值转换成经纬度值,就变成2.1中描述的情况了。

3. 结果

具体的实现代码如下:

#include <Windows.h>
#include <iostream>
#include <string>
#include <osgViewer/Viewer>
#include <osgDB/ReadFile>
#include <osgEarth/MapNode>
#include <osgEarthDrivers/gdal/GDALOptions>
#include <osgEarthDrivers/cache_filesystem/FileSystemCache>
#include <osgEarth/ImageLayer>
#include <osgEarth/Viewpoint>
#include <osgEarth/GeoTransform>
#include <osgEarth/ModelLayer>
#include <osgEarth/Registry>
#include <osgEarthUtil/EarthManipulator>
#include <gdal_priv.h>
using namespace std;
void AddModel(osg::ref_ptr<osgEarth::Map> map, osg::ref_ptr<osgEarth::MapNode> mapNode)
{
  //
  std::string filePath = "D:/Data/scene/Dayanta/Data.osgb";
  osg::ref_ptr<osg::Node> node = osgDB::readNodeFile(filePath);
  osg::ref_ptr<osgEarth::GeoTransform> xform = new osgEarth::GeoTransform();
  xform->addChild(node);
  xform->setTerrain(mapNode->getTerrain());
  osgEarth::GeoPoint point(map->getSRS(), 108.9594, 34.2196, -410);                 //使用绝对高,正高
  xform->setPosition(point);
  osg::ref_ptr<osgEarth::ModelLayer> modelLayer = new osgEarth::ModelLayer("oblic", xform);
  map->addLayer(modelLayer);
  osgEarth::Registry::shaderGenerator().run(node);
}
int main()
{   
  CPLSetConfigOption("GDAL_DATA", "D:/Work/OSGNewBuild/OpenSceneGraph-3.6.4/3rdParty/x64/gdal-data");
  
  //string wktString = "EPSG:3857";     //web墨卡托投影
  //string wktString = "EPSG:4326";     //wgs84
  osgEarth::ProfileOptions profileOpts;
  //profileOpts.srsString() = wktString;
    
  //osgEarth::Bounds bs(535139, 3365107, 545139, 3375107);
  //osgEarth::Bounds bs(73, 3, 135, 53);
  //profileOpts.bounds() = bs;
    
  //地图配置:设置缓存目录
  osgEarth::Drivers::FileSystemCacheOptions cacheOpts;
  string cacheDir =  "D:/Work/OSGNewBuild/tmp";
  cacheOpts.rootPath() = cacheDir;
  
  //
  osgEarth::MapOptions mapOpts;   
  mapOpts.cache() = cacheOpts;
  //mapOpts.coordSysType() = osgEarth::MapOptions::CSTYPE_PROJECTED;
  mapOpts.profile() = profileOpts;
  //创建地图节点
  osg::ref_ptr<osgEarth::Map> map = new osgEarth::Map(mapOpts);
  osg::ref_ptr<osgEarth::MapNode> mapNode = new osgEarth::MapNode(map);
  osgEarth::Drivers::GDALOptions gdal;
  //gdal.url() = "D:/Work/OSGNewBuild/osgearth-2.10.1/data/world.tif";
  //gdal.url() = "D:/Work/SinianGIS/bin/Resource/BlueMarbleNASA.jpg";
  gdal.url() = "D:/Work/SinianGIS/bin/Resource/baseMap.jpg";
  osg::ref_ptr<osgEarth::ImageLayer> imgLayer = new osgEarth::ImageLayer("BlueMarble", gdal);
  map->addLayer(imgLayer);
                
  AddModel(map, mapNode);
  osgViewer::Viewer viewer;
  viewer.getCamera()->setClearColor(osg::Vec4(0, 0, 0, 0));
  viewer.setSceneData(mapNode);
  
  osg::ref_ptr< osgEarth::Util::EarthManipulator> mainManipulator = new osgEarth::Util::EarthManipulator;
  viewer.setCameraManipulator(mainManipulator);
  osgEarth::Viewpoint vp;
  osgEarth::GeoPoint newPoint(map->getSRS(), 108.9594, 34.2196, 0);
  vp.focalPoint() = newPoint;
  vp.heading() = 0;
  vp.pitch() = -90;
  vp.range() = 1000;  
  mainManipulator->setViewpoint(vp);
  
  viewer.setUpViewInWindow(100, 100, 800, 600);
  return viewer.run();
}

运行结果如下:

4. 参考

  1. GNSS学习笔记-坐标转换

分类: OSG

标签: 倾斜摄影 , OSGEarth , OSG


相关文章
|
9月前
|
C++
如何在C++中实现cpp文件中引用另外一个cpp文件
如何在C++中实现cpp文件中引用另外一个cpp文件
979 0
|
存储 Cloud Native Linux
QtCreator中三种不同编译版本 debug、release、profile 的区别
QtCreator中三种不同编译版本 debug、release、profile 的区别
Cadence仿真出现Cannot Initialize Profile错误的解决方法和步骤
元器件和器件PSpice模型都准备好了,仿真原理图也画好了,但是在新建仿真配置文件的时候,提示Cannot Initialize Profile的错误。当时忘了截图了,问题解决了也没有出现这个错误。重启软件、重启电脑都没有再出现。
712 0
|
6月前
|
存储 前端开发 定位技术
osgEarth使用笔记4——加载矢量数据
osgEarth使用笔记4——加载矢量数据
267 0
|
5月前
|
移动开发 Java API
大疆无人机对接
本文介绍了大疆无人机对接第三方云平台的方案,包括设备对接和CloudAPI对接两种方式,重点讨论了CloudAPI对接。CloudAPI对接方案通过DJI Pilot 2或大疆机场将无人机与第三方云平台连接,实现低门槛接入,无需重复开发APP。方案优势在于让开发者更专注于业务开发,而非无人机功能适配。文章详细阐述了对接流程,包括环境准备、申请APPKey、对接流程、直播功能及获取无人机实时数据等内容,并提供了丰富的接口说明和技术支持资源。
2183 3
大疆无人机对接
|
8月前
|
存储 编解码 定位技术
技术心得:墨卡托投影、地理坐标系、地面分辨率、地图比例尺
技术心得:墨卡托投影、地理坐标系、地面分辨率、地图比例尺
248 0
|
6月前
|
调度 索引
OSG加载倾斜摄影数据
OSG加载倾斜摄影数据
89 0
|
6月前
|
数据采集 Java Python
Python并发编程:多线程(threading模块)
本文详细介绍了Python的threading模块,包括线程的创建、线程同步、线程池的使用,并通过多个示例展示了如何在实际项目中应用这些技术。通过学习这些内容,您应该能够熟练掌握Python中的多线程编程,提高编写并发程序的能力。 多线程编程可以显著提高程序的并发性能,但也带来了新的挑战和问题。在使用多线程时,需要注意避免死锁、限制共享资源的访问,并尽量使用线程池来管理和控制线程。
|
6月前
|
数据可视化
OSG嵌入QT的简明总结2
OSG嵌入QT的简明总结2
118 1
|
7月前
|
消息中间件 程序员 调度
如何区分进程、线程和协程?看这篇就够了!
以下是内容摘要,已简化并保持在240字符以内: 嗨,我是小米!今天聊聊进程、线程和协程: - **进程**:资源分配基本单位,独立且隔离。 - **线程**:进程内执行单元,轻量级且共享资源。 - **协程**:比线程更轻量,适合I/O密集型任务。 每种都有独特特点和适用场景,选择合适可优化性能。希望对你有所帮助!更多内容,请关注我的公众号“软件求生”。
179 1

热门文章

最新文章