[原][osgearth]API加载earth文件的解析
参考:http://blog.csdn.net/cccstudyer/article/details/17691893
通过\src\osgEarthDrivers\earth\ReaderWriterOsgEarth.cpp文件
ReaderWriterEarth类,用来解析“earth”文件
在文件225行的readNode函数
virtual ReadResult readNode(std::istream& in, const osgDB::Options* readOptions) const
{
// pull the URI context from the options structure (since we're reading
// from an "anonymous" stream here)
URIContext uriContext( readOptions ); osg::ref_ptr<XmlDocument> doc = XmlDocument::load( in, uriContext );
if ( !doc.valid() )
return ReadResult::ERROR_IN_READING_FILE; Config docConf = doc->getConfig(); // support both "map" and "earth" tag names at the top level
Config conf;
if ( docConf.hasChild( "map" ) )
conf = docConf.child( "map" );
else if ( docConf.hasChild( "earth" ) )
conf = docConf.child( "earth" ); osg::ref_ptr<osg::Node> node; if ( !conf.empty() )
{
// see if we were given a reference URI to use:
std::string refURI = uriContext.referrer(); if ( conf.value("version") == "" )
{
OE_INFO << LC << "Detected a version 1.x earth file" << std::endl;
EarthFileSerializer1 ser;
node = ser.deserialize( conf, refURI );
} else
{
if ( conf.value("version") != "" )
OE_DEBUG << LC << "No valid earth file version; assuming version='2'" << std::endl; // attempt to parse a "default options" JSON string:
std::string defaultConfStr;
if ( readOptions )
{
defaultConfStr = readOptions->getPluginStringData("osgEarth.defaultOptions");
if ( !defaultConfStr.empty() )
{
Config optionsConf("options");
if (optionsConf.fromJSON(defaultConfStr))
{
//OE_NOTICE << "\n\nOriginal = \n" << conf.toJSON(true) << "\n";
Config* original = conf.mutable_child("options");
if ( original )
{
recursiveUniqueKeyMerge(optionsConf, *original);
}
if ( !optionsConf.empty() )
{
conf.set("options", optionsConf);
}
//OE_NOTICE << "\n\nMerged = \n" << conf.toJSON(true) << "\n";
}
}
} EarthFileSerializer2 ser;
node = ser.deserialize( conf, refURI );
}
} MapNode* mapNode = MapNode::get(node.get());
if (mapNode)
{
// If the user passed in a cache object, apply it to the map now
CacheSettings* cacheSettings = CacheSettings::get(readOptions);
if (cacheSettings && cacheSettings->getCache())
{
mapNode->getMap()->setCache( cacheSettings->getCache() );
OE_INFO << LC << "Applied user-supplied cache to the Map\n";
}
} return ReadResult(node.get());
}
};
看到65行的读取调用
进入\src\osgEarthDrivers\earth\EarthFileSerializer2.cpp文件
EarthFileSerializer2类的deserialize函数
void addImageLayer(const Config& conf, Map* map)
{
ImageLayerOptions options( conf );
options.name() = conf.value("name");
ImageLayer* layer = new ImageLayer(options);
map->addLayer(layer);
if (layer->getStatus().isError())
OE_WARN << LC << "Layer \"" << layer->getName() << "\" : " << layer->getStatus().toString() << std::endl;
} void addElevationLayer(const Config& conf, Map* map)
{
ElevationLayerOptions options( conf );
options.name() = conf.value( "name" );
ElevationLayer* layer = new ElevationLayer(options);
map->addLayer(layer);
if (layer->getStatus().isError())
OE_WARN << LC << "Layer \"" << layer->getName() << "\" : " << layer->getStatus().toString() << std::endl;
} void addModelLayer(const Config& conf, Map* map)
{
ModelLayerOptions options( conf );
options.name() = conf.value( "name" );
options.driver() = ModelSourceOptions( conf );
ModelLayer* layer = new ModelLayer(options);
map->addLayer(layer);
if (layer->getStatus().isError())
OE_WARN << LC << "Layer \"" << layer->getName() << "\" : " << layer->getStatus().toString() << std::endl;
} void addMaskLayer(const Config& conf, Map* map)
{
MaskLayerOptions options(conf);
options.name() = conf.value( "name" );
options.driver() = MaskSourceOptions(options);
MaskLayer* layer = new MaskLayer(options);
map->addLayer(layer);
if (layer->getStatus().isError())
OE_WARN << LC << "Layer \"" << layer->getName() << "\" : " << layer->getStatus().toString() << std::endl;
} // support for "special" extension names (convenience and backwards compat)
Extension* createSpecialExtension(const Config& conf)
{
// special support for the default sky extension:
if (conf.key() == "sky" && !conf.hasValue("driver"))
return Extension::create("sky_simple", conf); if (conf.key() == "ocean" && !conf.hasValue("driver"))
return Extension::create("ocean_simple", conf); return 0L;
} bool addLayer(const Config& conf, Map* map)
{
std::string name = conf.key();
Layer* layer = Layer::create(name, conf);
if (layer)
{
map->addLayer(layer);
if (layer->getStatus().isError())
OE_WARN << LC << "Layer \"" << layer->getName() << "\" : " << layer->getStatus().toString() << std::endl;
}
return layer != 0L;
} osg::Node*
EarthFileSerializer2::deserialize( const Config& conf, const std::string& referrer ) const
{
// First, pre-load any extension DLLs.
preloadExtensionLibs(conf);
preloadExtensionLibs(conf.child("extensions"));
preloadExtensionLibs(conf.child("external")); MapOptions mapOptions( conf.child( "options" ) ); // legacy: check for name/type in top-level attrs:
if ( conf.hasValue( "name" ) || conf.hasValue( "type" ) )
{
Config legacy;
if ( conf.hasValue("name") ) legacy.add( "name", conf.value("name") );
if ( conf.hasValue("type") ) legacy.add( "type", conf.value("type") );
mapOptions.mergeConfig( legacy );
} Map* map = new Map( mapOptions ); // Start a batch update of the map:
map->beginUpdate(); // Read all the elevation layers in FIRST so other layers can access them for things like clamping.
for(ConfigSet::const_iterator i = conf.children().begin(); i != conf.children().end(); ++i)
{
if ( i->key() == "elevation" || i->key() == "heightfield" )
{
addElevationLayer( *i, map );
}
} Config externalConfig;
std::vector<osg::ref_ptr<Extension> > extensions; // Read the layers in LAST (otherwise they will not benefit from the cache/profile configuration)
for(ConfigSet::const_iterator i = conf.children().begin(); i != conf.children().end(); ++i)
{
if (i->key() == "options" || i->key() == "name" || i->key() == "type" || i->key() == "version")
{
// nop - handled earlier
} else if ( i->key() == "image" )
{
addImageLayer( *i, map );
} else if ( i->key() == "model" )
{
addModelLayer( *i, map );
} else if ( i->key() == "mask" )
{
addMaskLayer( *i, map );
} else if ( i->key() == "external" || i->key() == "extensions" )
{
externalConfig = *i; for(ConfigSet::const_iterator e = i->children().begin(); e != i->children().end(); ++e)
{
Extension* extension = loadExtension(*e);
if (extension)
extensions.push_back(extension);
//addExtension( *e, mapNode.get() );
}
} else if ( !isReservedWord(i->key()) ) // plugins/extensions.
{
bool addedLayer = addLayer(*i, map); //mapNode.get()); if ( !addedLayer )
{
Extension* extension = loadExtension(*i);
if (extension)
extensions.push_back(extension);
//OE_INFO << LC << "Tried to load \"" << i->key() << "\" as a layer; now trying extension\n";
//addExtension( *i, mapNode.get() );
}
}
} // Complete the batch update of the map
map->endUpdate(); // Yes, MapOptions and MapNodeOptions share the same Config node. Weird but true.
MapNodeOptions mapNodeOptions( conf.child("options") ); // Create a map node.
osg::ref_ptr<MapNode> mapNode = new MapNode( map, mapNodeOptions ); // Apply the external conf if there is one.
if (!externalConfig.empty())
{
mapNode->externalConfig() = externalConfig;
} // Install the extensions
for (unsigned i = ; i < extensions.size(); ++i)
{
mapNode->addExtension(extensions.at(i).get());
} // return the topmost parent of the mapnode. It's possible that
// an extension added parents!
osg::Node* top = mapNode.release(); while( top->getNumParents() > )
top = top->getParent(); return top;
}
从上面可以看到
1 earth插件 map 统筹OE中所有"层"的概念,支持多层影像,高程,模型,镂空层(mask)等
2各个层相应配置的属性由指定的Option类从Config中获取,如果对应Config中有Option类指定元素相应值的配置Option将其写入
为了统筹OE各个层的属性配置,OE提供了ConfigOptions类,ConfigOptions类就是对某个Config类的封装,提供了到Config层次上的调用,例如Config赋值,拼接等
为不同层的属性配置提供了存储载体,结合上文map包含的图层有以下关系
通过这些类,可以很方便的将特定的XML节点下属性配置生成Config归类到某一个图层中,以下列出部分图层的属性(仅供参考)
MapOptions:XML<<options>>节点下配置的信息,主要是配置地形渲染时的属性;包括如下
- <elevation_interploation> 插值,nearset 最近点插值 average 最近点平均值 bilinear 线性插值, triangulate 三角面片插值
- <elevation_tile_size> 瓦片大小
- <elevation_texture_size> 纹理大小
- <overlay_wapring> 纹理装载
- <overlay_blending>混合
- <overlay_minmapping> 纹理映射
- <overlay_texture_size>
- <overlay_attach_stencil>模板
ImageLayerOptions: XML<<image>>节点下配置的信息,很明显,影像属性配置,部分属性值
- <nodata_image> 无数据显示的url
- <opacity> 透明度
- <min_range> 最小可视范围
- <max_range> 最大可视范围
- <min_level> 最小显示细节层级
- <max_level> 最大显示细节层级
- <min_resolution> 数据的最小分辨率,单位的像素
- <max_resolution>数据的最大分辨率,单位的像素
- <enable> 是否包含进map层
- <visible> 可视
ElevationLayerOptions: XML<<elevation>>or<<heightfield>>节点下配置的信息,高程层
- <min_level> 最小显示细节层级
- <max_level> 最大显示细节层级
- <min_resolution> 数据的最小分辨率,单位的像素
- <max_resolution>数据的最大分辨率,单位的像素
- <enable> 是否包含进map层
ModelLayerOptions: XML<<Model>>节点下配置的信息 模型层装载 矢量数据,模型,几何体等
- <name>
- <driver>
- <enable><span style="font-family:Arial, Helvetica, sans-serif;">是否包含进map层</span>
- <visible>是否可见
- <overLay>
MaskLayerOptions: XML<<mask>>节点配置下的信息,镂空层
一个比较特殊的节点 ext(Config); 暂且叫他功能层,XML <<external>>,它由mapNode直接读取配置信息,实现一些经常用到的功能点,例如 视点定位 <<<viewpoint>> 星空时刻设置<<sky>>等
[原][osgearth]API加载earth文件的解析的更多相关文章
- [原][译][osgearth]API加载地球(OE官方文档翻译)
原文参考:http://docs.osgearth.org/en/latest/developer/maps.html#programmatic-map-creation 本人翻译水平有限... 加载 ...
- 代码收藏系列--php--加载sql文件并解析成数组
php加载sql文件,解析成以分号分割的数组.(支持存储过程和函数提取,自动过滤注释) /** * 加载sql文件为分号分割的数组 * <br />支持存储过程和函数提取,自动过滤注释 * ...
- c#两种方式调用google地球,调用COM API以及调用GEPLUGIN 与js交互,加载kml文件,dae文件。将二维高德地图覆盖到到三维谷歌地球表面。
网络上资源很多不全面,自己在开发的时候走了不少弯路,在这里整理了最全面的google全套开发,COM交互,web端交互.封装好了各种模块功能. 直接就可以调用. 第一种方式:调用COMAPI实现调用g ...
- SharpDX之Direct2D教程II——加载位图文件和保存位图文件
本系列文章目录: SharpDX之Direct2D教程I——简单示例和Color(颜色) 绘制位图是绘制操作的不可缺少的一部分.在Direct2D中绘制位图,必须先利用WIC组件将位图加载到内存中,再 ...
- 如何在SCENEKIT使用SWIFT RUNTIME动态加载COLLADA文件
问题:今天接到一个项目,负责弄需求的美眉跟我讲能不能做一个原型能够加载Collada文件,流程如下: 用户用app下载Collada 压缩包(如内购项目) 压缩包解压 展示Collada文件里的内容 ...
- 两种动态加载JavaScript文件的方法
两种动态加载JavaScript文件的方法 第一种便是利用ajax方式,第二种是,动静创建一个script标签,配置其src属性,经过把script标签拔出到页面head来加载js,感乐趣的网友可以看 ...
- JVM加载class文件的原理
当Java编译器编译好.class文件之后,我们需要使用JVM来运行这个class文件.那么最开始的工作就是要把字节码从磁盘输入到内存中,这个过程我们叫做[加载 ].加载完成之后,我们就可以进行一系列 ...
- Android动态加载so文件
在Android中调用动态库文件(*.so)都是通过jni的方式,而且往往在apk或jar包中调用so文件时,都要将对应so文件打包进apk或jar包,工程目录下图: 以上方式的存在的问题: 1.缺少 ...
- Spire.XLS,生成Excel文件、加载Excel文件
一.组件介绍 Spire.XLS是E-iceblue开发的一套基于企业级的专业Office文档处理的组件之一,全称Spire.Office for .NET.旗下有Spire.Doc,Spire XL ...
随机推荐
- windows服务的默认启动类型和登录帐户
转自:http://www.winhelponline.com/blog/windows-7-services-default-startup-type/ Service Name Startup T ...
- CentOS7安装步骤详解
准备环境 1.虚拟机 VMware Workstation 2.Centos7-64位安装包 ( CentOS-6.7-x86_64-bin-DVD1.iso ) 开始安装 进入安装初始化界面 ...
- poj1191 棋盘分割【区间DP】【记忆化搜索】
棋盘分割 Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 16263 Accepted: 5812 Description ...
- ubuntu16.04下安装pcl点云库
安装依赖项 sudo apt-get update sudo apt-get install git build-essential linux-libc-dev sudo apt-get insta ...
- Eclipse Tomcat插件的使用
目录 Eclipse Tomcat插件的使用 Eclipse Tomcat插件的使用 我使用的Eclipse版本是:4.6.3 Eclipse已经自带Tomcat插件,不需要再自己进行安装 1.新建T ...
- Create an Index
db.collection.createIndex( { name: -1 } ) Indexes — MongoDB Manual https://docs.mongodb.com/manual/i ...
- Python的Flask框架应用调用Redis队列数据的方法
转自:http://www.jb51.net/article/86021.htm 任务异步化 打开浏览器,输入地址,按下回车,打开了页面.于是一个HTTP请求(request)就由客户端发送到服务器, ...
- Git 基本操作(二)
1. 分支操作 1.1 Fast-forward 当被合并分支(C4)位于合并分支(C2)的历史线上,此时的合并称为"fast-forward"; // hotfix 被合并到 m ...
- Ubuntu18.04下安装比特币客户端
一.下载有两种安装方式:安装包和源码 二.安装1.通过安装包安装在https://bitcoin.org/en/download下载Windows,Mac OSX,Linux对应的安装包.安装过程比较 ...
- 【Python+Selenium】猪猪练习成功版:csv文件的输入和输出(运行环境:python3.5版本)
自己实践成功的从csv文件中读取用户名密码并实际登录系统后判断是否登录成功,并将已经运行的用户名密码及运行结果输出到一个新的csv文件中~ # coding=utf-8 from selenium i ...