目标:(八十二)中的问题162
图层在创建完成后,需要添加到osgEarth::Map中,添加过程中会执行图层的打开操作。每个图层只打开一次,打开过的图层就不再打开了。
osgEarth/TerrainLayer.cpp
const Status&
TerrainLayer::open()
{
if ( !_openCalled )
{
// Call base class
if (VisibleLayer::open().isError())
return getStatus();
// Create an L2 mem cache that sits atop the main cache, if necessary.
// For now: use the same L2 cache size at the driver.
int l2CacheSize = options().driver()->L2CacheSize().get();
// See if it was overridden with an env var.
char const* l2env = ::getenv( "OSGEARTH_L2_CACHE_SIZE" );
if ( l2env )
{
l2CacheSize = as<int>( std::string(l2env), 0 );
OE_INFO << LC << "L2 cache size set from environment = " << l2CacheSize << "\n";
}
// Env cache-only mode also disables the L2 cache.
char const* noCacheEnv = ::getenv( "OSGEARTH_MEMORY_PROFILE" );
if ( noCacheEnv )
{
l2CacheSize = 0;
}
// Initialize the l2 cache if it's size is > 0
if ( l2CacheSize > 0 )
{
_memCache = new MemCache( l2CacheSize );
}
// create the unique cache ID for the cache bin.
//std::string cacheId;
if (options().cacheId().isSet() && !options().cacheId()->empty())
{
// user expliticy set a cacheId in the terrain layer options.
// this appears to be a NOP; review for removal -gw
_runtimeCacheId = options().cacheId().get();
}
else
{
// system will generate a cacheId from the layer configuration.
Config hashConf = options().getConfig();
// remove non-data properties.
hashConf.remove("name");
hashConf.remove("enabled");
hashConf.remove("cacheid");
hashConf.remove("cache_only");
hashConf.remove("cache_enabled");
hashConf.remove("cache_policy");
hashConf.remove("visible");
hashConf.remove("l2_cache_size");
OE_DEBUG << "hashConfFinal = " << hashConf.toJSON(true) << std::endl;
unsigned hash = osgEarth::hashString(hashConf.toJSON());
_runtimeCacheId = Stringify() << std::hex << std::setw(8) << std::setfill('0') << hash;
}
// Now that we know the cache ID, establish the cache settings for this Layer.
// Start by cloning whatever CacheSettings were inherited in the read options
// (typically from the Map).
CacheSettings* oldSettings = CacheSettings::get(_readOptions.get());
_cacheSettings = oldSettings ? new CacheSettings(*oldSettings) : new CacheSettings();
// Store for further propagation!
_cacheSettings->store(_readOptions.get());
// Integrate a cache policy from this Layer's options:
_cacheSettings->integrateCachePolicy(options().cachePolicy());
// If you created the layer with a pre-created tile source, it will already by set.
if (!_tileSource.valid())
{
osg::ref_ptr<TileSource> ts;
// as long as we're not in cache-only mode, try to create the TileSource.
if (_cacheSettings->cachePolicy()->isCacheOnly())
{
OE_INFO << LC << "Opening in cache-only mode\n";
}
else if (isTileSourceExpected())
{
// Initialize the tile source once and only once.
ts = createAndOpenTileSource();
}
// All good
if (ts.valid() && !_tileSource.valid())
{
_tileSource = ts.release();
}
}
else
{
// User supplied the tile source, so attempt to initialize it:
_tileSource = createAndOpenTileSource();
}
// Finally, open and activate a caching bin for this layer if it
// hasn't already been created.
if (_cacheSettings->isCacheEnabled() && _cacheSettings->getCacheBin() == 0L)
{
CacheBin* bin = _cacheSettings->getCache()->addBin(_runtimeCacheId);
if (bin)
{
_cacheSettings->setCacheBin(bin);
OE_INFO << LC << "Cache bin is [" << bin->getID() << "]\n";
}
}
OE_INFO << LC << _cacheSettings->toString() << "\n";
// Done!
_openCalled = true;
}
return getStatus();
}
打开过程主要包括以下内容:
1、执行基类的打开操作,主要是做一些属性的赋值。
2、设置二级缓存大小,默认是16,还可以从环境变量中获取该大小。
3、如果二级缓存大小大于0,则创建二级缓存,即osgEarth::MemCache。
4、设置缓存ID,可以是已有的缓存ID,也可以是当前新生成的缓存ID。
5、从读配置中获取缓存配置信息,读配置从osgEarth::Map中继承而来。
6、建立与图层对应的瓦片源,这个瓦片源其实就是对 应于各种具体的图源(比如谷歌、百度、高德等)。根据earth文件中配置的驱动创建瓦片源。如果驱动是gdal则创建GDALTileSource,如果是TMS则创建,如果是WMS则创建WMSSource,如果是xyz则创建XYZSource,创建过程采用插件方式根据驱动名找相应的插件。还会设置该瓦片源的Profile和SpatialReference。
osgEarth/TerrainLayer.cpp
TileSource*
TerrainLayer::createTileSource()
{
return TileSourceFactory::create(options().driver().get());
}
图层->瓦片源->Profile->SpatialReference
设置瓦片缓存策略,这里有四种策略
osgEarth/CachePolicy
enum Usage
{
USAGE_READ_WRITE = 0, // read/write to the cache if one exists.
USAGE_CACHE_ONLY = 1, // treat the cache as the ONLY source of data.
USAGE_READ_ONLY = 2, // read from the cache, but don't write new data to it.
USAGE_NO_CACHE = 3 // neither read from or write to the cache
};
设置缓存和缓存设置的缓存体cachebin。这个缓存体就是以后读写缓存文件的负责人,读写都是调用它的相关函数。需要注意的是,设置缓存体时,是把缓存区放入到了一个map容器中,但此容器中只有这一个缓存体,不会因为新增加一个缓存文件而创建一个与其配套的缓存体。读写原理是根据key来生成对应的文件名称,缓存体通过该名称来读写缓存文件。
osgEarth/TerrainLayer.cpp
TileSource*
TerrainLayer::createAndOpenTileSource()
{
CacheBin* bin = _cacheSettings->getCache()->addBin(_runtimeCacheId);
if (bin)
{
_cacheSettings->setCacheBin(bin);
OE_INFO << LC << "Cache bin is [" << bin->getID() << "]\n";
}
}
这里的_runtimeCacheId是这样的:
osgEarth/TerrainLayer.cpp
const Status&
TerrainLayer::open()
{
unsigned hash = osgEarth::hashString(hashConf.toJSON());
_runtimeCacheId = Stringify() << std::hex << std::setw(8) << std::setfill('0') << hash;
}
7、设置缓存体cachebin。如果上一步没有设置,这一步进行设置。
待继续分析列表:
9、earth文件中都有哪些options((九)中问题)
10、如何根据earth文件options创建不同的地理信息引擎节点((九)中问题)
11、rex地理信息引擎的四梁八柱((九)中问题)
12、osgEarth::TerrainEngineNode中setMap方法作用((十二)中问题)
13、RexTerrainEngineNode中_mapFrame的作用((十二)中问题)
14、地形变形(Terrain morphing)((十二)中问题)
15、地球瓦片过期门限的含义((十二)中问题)
16、高分辨率优先的含义((十二)中问题)
17、OSGEARTH_DEBUG_NORMALS环境变量的作用((十二)中问题)
18、活跃瓦片寄存器的作用((十二)中问题)
19、资源释放器子节点的作用((十二)中问题)
20、共享几何图形池子节点的作用((十二)中问题)
21、分页瓦片加载器子节点的作用((十二)中问题)
22、分页瓦片卸载器子节点的作用((十二)中问题)
23、栅格化器子节点的作用((十二)中问题)
24、地形子节点的作用((十二)中问题)
25、绑定渲染器的作用((十二)中问题)
26、地图回调函数的作用((十二)中问题)
27、如何将地图图层添加到rex引擎中((十二)中问题)
28、选择信息的作用((十二)中问题)
29、瓦片包围盒修改回调函数的作用((十二)中问题)
30、刷新rex引擎((十二)中问题)
31、刷新边界作用((十二)中问题)
32、osgEarth::Metrics类的意义((十四)中问题)
33、请求合并队列_mergeQueue((十四)中问题)
34、分页瓦片加载器在更新遍历时对请求处理过程((十四)中问题)
35、分页瓦片加载器在更新遍历时对已处理请求裁剪过程((十四)中问题)
36、已处理的请求队列_requests((十四)中问题)
37、DatabasePager中的_fileRequestQueue和_httpRequestQueue((十六)中问题)
38、瓦片请求的生成到处理过程详解((十六)中问题)
39、瓦片节点TileNode的创建过程((十七)中问题)
40、request请求加载瓦片优先级的含义((十七)中问题)
41、request的_internalHandle的作用((十七)中问题)
42、DatabaseRequest中_objectCache含义((十七)中问题)
42、osgEarth的多线程分析((十七)中问题)
43、osgEarth的缓存及其结构((十七)中问题)
44、DatabaseThread从缓存加载数据过程((十七)中问题)
45、DatabaseThread从文件加载数据过程((十七)中问题)
46、决定创建TileNode的时机条件((十七)中问题)
47、TerrainEngineNode的createTileModel过程详解((十七)中问题)
48、DatabaseThread中CompileSet的含义((十七)中问题)
48、PagerLoader的traverse过程详解((十七)中问题)
49、DatabaseThread的run过程详解((十七)中问题)
50、LoadTileData的invoke过程详解((十七)中问题)
51、TileNode的cull过程详解((十七)中问题)
52、遮罩生成器osgEarth::Drivers::RexTerrainEngine::MaskGenerator((十八)中问题)
53、RexTerrainEngineNode::traverse过程详解((十八)中问题)
54、TileNode节点下的场景树分析((十八)中问题)
55、地形瓦片大小尺寸和LOD的关系((十八)中问题)
56、TileNode的_tileKeyValue作用((十八)中问题)
57、TileNode的_morphConstants作用((十八)中问题)
58、TileNode的_stitchNormalMap作用((十八)中问题)
59、TileNode的_renderModel作用((十八)中问题)
60、初始化高程栅格过程详解((十八)中问题)
61、LoadTileData中的CreateTileModelFilter作用((十八)中问题)
62、TileNode节点何时会从场景树中移除((十八)中问题)
63、osgEarth::Map的Profile创建过程((二十)中问题)
64、osgEarth::TerrainTileModelFactory添加颜色层和影像层的区别((二十一)中问题)
65、osgEarth::PatchLayer修补层的作用((二十一)中问题)
66、osgEarth::TerrainLayer中的_memCache(osgEarth::MemCache)详解((二十一)中问题)
67、osgEarth::Layer::RenderType图层渲染类型的作用((二十一)中问题)
68、osgEarth::TerrainLayer中TileSource的作用((二十一)中问题)
69、earth文件没有设置高程图层会不会有默认高程层(高程均为0)((二十一)中问题)
70、TerrainTileModelFactory::addColorLayers过程详解((二十一)中问题)
71、TerrainTileModelFactory::addElevation过程详解((二十一)中问题)
72、osgearth中可能用到的几个全局实例对象(osgDB::Registry osgEarth::Registry osg::Timer osg::DisplaySetting)((二十三)中问题)
73、osgEarth::Map::addLayer过程详解((二十三)中问题)
74、TileNode::setDirty过程详解((二十三)中问题)
75、请求四个状态的含义(IDLE RUNNING MERGING FINISHED)((二十三)中问题)
76、什么时候删除TileNode节点,不会一直增加吧((二十三)中问题)
77、寄存器中请求状态活动记录的含义Registry::instance()->endActivity( req->getName() )((二十三)中问题)
78、瓦片TileNode的生命周期流程详解((二十三)中问题)
79、rex引擎如何将瓦片构造成地球形状((二十五)中问题)
80、高程、影像文件格式详解((二十五)中问题)
81、TileNode的merge过程详解((二十六)中问题)
82、osgEarth支持的空间参考坐标系详解(osgEarth::SpatialReference、osgEarth::CubeSpatialReference、osgEarth::TangentPlaneSpatialReference)((二十九)中问题)
83、osgEarth地球椭球体ellipsoid 大地基准面datum 地图投影Projection详解((二十九)中问题)
84、空间参考坐标系和坐标系统类型的关系(geocentric projected)((二十九)中问题)
85、proj4是什么((二十九)中问题)
86、为什么要删除设置过的垂直水准面((二十九)中问题)
87、osgEarth如何对投影坐标系和大地坐标系进行显示处理的((二十九)中问题)
88、TileNode的节点构成,一个surface、tilenode((三十)中问题)
89、MapFram和MapInfo的关系((三十)中问题)
90、ModifyBoundingBoxCallback的使用时机和场合((三十)中问题)
91、MapFrame为什么要单独存放高程层_elevationLayers,而不是放在图层_layers中((三十)中问题)
92、MapFrame和Map中高程池的作用osg::ref_ptr<ElevationPool> _elevationPool((三十)中问题)
93、osgEarth::Drivers::RexTerrainEngine::TileDrawable分析((三十)中问题)
94、请求读取地理信息失败会如何处理((三十二)中问题)
95、RexTerrainEngineNode的遍历过程详解((三十三)中问题)
96、osgEarth::Drivers::RexTerrainEngine::TerrainCuller的apply过程详解((三十三)中问题)
97、RexTerrainEngineNode的updateState过程详解 设置了很多着色器变量((三十三)中问题)
98、什么时候分配opengl资源((三十三)中问题)
99、TileNode释放opengl资源过程releaseGLObjects详解((三十三)中问题)
100、最近一次遍历的帧号和时间是怎么设置呢(在渲染遍历里),怎么就不会再渲染遍历该瓦片节点了((三十三)中问题)
101、osg::State和osg::StateSet的关系((三十四)中问题)
102、osgEarth::SpatialReference和osgEarth::Profile的关系((三十六)中问题)
103、osgEarth的Geographic、Geodetic、Geocentric和Project的关系((三十六)中问题)
104、TileNode绘制过程详解((三十七)中问题)
105、如何控制父子TileNode节点的显隐((三十七)中问题)
106、GeometryPool的createGeometry过程详解((三十七)中问题)
107、TileNode如何从地图中提取与其分辨率相适应的图像数据((三十七)中问题)
108、如何定制椭球体并进行椭球体间坐标转换((四十五)中问题)
109、Horizon Cull是什么意思((四十五)中问题)
110、osgEarth::Drivers::RexTerrainEngine::DrawState的作用((四十五)中问题)
111、osgEarth的线程分析((四十五)中问题)
112、从osgEarth到osg到Opengl((四十五)中问题)
113、osg::Program与osgEarth::VirtualProgram的关系((四十五)中问题)
114、rex引擎shader文件中的#pragma vp_entryPoint vp_location等含义((四十五)中问题)
115、rex引擎的着色器如何区分顶点和片段((四十五)中问题)
116、osg::Program是如何对着色器及其变量进行管理的((四十五)中问题)
117、osg的窗口是如何与opengl集成的((四十五)中问题)
118、osg是如何实现opengl的初始化的((四十五)中问题)
119、CGCS2000余WGS84坐标系的比较((四十六)中问题)
120、着色器代码文件到着色器程序的过程((五十一)中问题)
121、osgEarth::VirtualProgram默认出现在哪些位置((五十一)中问题)
122、rex引擎默认的几个着色器功能分析((五十一)中问题)
123、osgEarth::TileRasterizer功能详解((五十二)中问题)
124、osgEarth::ImageLayer如何使用VirtualProgram((五十二)中问题)
125、osgEarth::ShaderFactory osgEarth::ShaderLoader关系((五十四)中问题)
126、osgEarth::URI和osgEarth::URIContext的作用((五十四)中问题)
127、RexTerrainEngineNode中_renderBindings的作用((五十四)中问题)
128、Rex引擎如何给shader文件中的uniform变量赋值((五十四)中问题)
129、osgEarth中多个着色器的源代码的编译链接过程((五十四)中问题)
130、osgEarth::ShaderFactory osgEarth::ShaderLoader关系((五十四)中问题)
131、TileNode与DrawTileCommand的关系((五十五)中问题)
132、如何提取出指定范围的高程网格((五十五)中问题)
133、从earth文件加载高层图层的过程((五十五)中问题)
134、TerrainTileModel与TileRenderModel的关系((五十五)中问题)
135、EngineContext的作用((五十五)中问题)
136、几个uniformmap的关系((五十五)中问题)
137、DrawTileCommand中的采样器((五十五)中问题)
138、TileNode中的_surface(SurfaceNode)作用是什么((五十五)中问题)
139、stateset中的adduniform、setTextureAttribute等最后是如何反应到opengl上的((五十五)中问题)
140、状态树和渲染树的关系((五十五)中问题)
141、TileRenderModel中的RenderingPass和RenderBindings((五十五)中问题)
142、高程瓦片的绘制过程((五十五)中问题)
143、如何从高程影像变成高程网格((七十一)中问题)
144、osg::StateSet中的_binMode作用((七十二)中问题)
145、rex的瓦片高程影像和高程文件中的影像尺寸如何对应((七十二)中问题)
146、osgEarth::TerrainLayerOptions高程层选项中参数的含义((七十二)中问题)
147、从高程文件读取的高程信息如何填充rex的高程瓦片((七十二)中问题)
148、地图下载器实现原理((七十二)中问题)
149、RexTerrainEngineNode和TerrainCuller中_terrain的关系((七十二)中问题)
150、TileNodeRegistry和LayerDrawable中_tiles的关系((七十二)中问题)
151、rex引擎中绘制瓦片的调度过程原理((七十二)中问题)
152、晕眩图的制作与实现((七十八)中问题)
153、如何将高层场保存为tif、MBTiles等((七十八)中问题)
154、如何将tif和MBTiles进行格式转换((七十八)中问题)
155、如何加载百度、高德、谷歌、微软的在线地图((七十八)中问题)
156、osgEarth运行起来为什么很占CPU资源((七十九)中问题)
157、wmts与xyz、quadtree、tms的关系((七十九)中问题)
158、获取的高程图像为什么除了设置纹理还要设置栅格((八十)中问题)
159、rex引擎创建图层的过程((八十一)中问题)
160、如何设置高度单位(m、km等)((八十二)中问题)
161、网络资源加载失败还会不会继续加载((八十二)中问题)
162、rex引擎打开图层的过程((八十二)中问题)
163、osgEarth::MemCache详解((八十二)中问题)
164、OGR与GDAL的关系((八十二)中问题)
165、osgEarth::Map的cache创建过程((八十三)中问题)
166、osgEarth跨平台的头文件包含设置((八十三)中问题)