[原][osgearth]osgearthviewer读取earth文件,代码解析(earth文件读取的一帧)

跑osgearthviewer程序

使用一个earth文件做参数传入

跟进代码。

首先osgearthviewer程序加载earth的方式分为两种:

 

1.根据earth文件(load方式)

2.使用SDK加载(create方式)

 

我们使用earth文件是load方式,直接看load函数,定位到这个位置

    // load an earth file, and support all or our example command-line options
    // and earth file <external> tags    
    osg::Node* node = MapNodeHelper().load(arguments, &viewer);

上面的函数是用来加载earth文件的,仔细看一下这个函数

发现这个函数是通过osgDB的加载机制来实现earth文件的加载。

 

下面我们先要搞清楚的是osgDB的加载机制

 

这是osgDB读取的调用顺序

回到,我们自己的程序,我将代码调试过程截图:

 

 

这里有不少默认的属性,而我们是定位到自定义的部分:(下图)

因为,我只用了一个传入参数,所以,这个循环只执行一次,就是调用了一次readRefNodeFile文件

 

这个函数好像是管理缓存什么的,我们在函数里定位到这里:(下图)

 

这个read才是开始真正解析数据了。

  1 ReaderWriter::ReadResult Registry::read(const ReadFunctor& readFunctor)
  2 {
        
       ......关于osga和zip文件的
52 // first attempt to load the file from existing ReaderWriter's第一次尝试从现有ReaderWriter的加载文件 53 AvailableReaderWriterIterator itr(_rwList, _pluginMutex); 54 for(;itr.valid();++itr) 55 { 56 ReaderWriter::ReadResult rr = readFunctor.doRead(*itr); 57 if (readFunctor.isValid(rr)) 58 return rr; 59 else results.push_back(rr); 60 } 61 62 // check loaded archives.检查加载的档案 63 AvailableArchiveIterator aaitr(_archiveCache, _archiveCacheMutex); 64 for(;aaitr.valid();++aaitr) 65 { 66 ReaderWriter::ReadResult rr = readFunctor.doRead(*aaitr); 67 if (readFunctor.isValid(rr)) 68 return rr; 69 else 70 { 71 // don't pass on FILE_NOT_FOUND results as we don't want to prevent non archive plugins that haven't been 72 // loaded yet from getting a chance to test for the presence of the file. 73 if (rr.status()!=ReaderWriter::ReadResult::FILE_NOT_FOUND) results.push_back(rr); 74 } 75 } 76 77 // now look for a plug-in to load the file.现在寻找一个插件加载文件!!! 78 std::string libraryName = createLibraryNameForFile(readFunctor._filename); 79 if (loadLibrary(libraryName)!=NOT_LOADED) 80 { 81 for(;itr.valid();++itr) 82 { 83 ReaderWriter::ReadResult rr = readFunctor.doRead(*itr); 84 if (readFunctor.isValid(rr)) 85 return rr; 86 else results.push_back(rr); 87 } 88 } 89 90 //If the filename contains a server address and wasn't loaded by any of the plugins, try to find a plugin which supports the server 91 //protocol and supports wildcards. If not successfully use curl as a last fallback 92 if (containsServerAddress(readFunctor._filename)) 93 { 94 ReaderWriter* rw = getReaderWriterForProtocolAndExtension( 95 osgDB::getServerProtocol(readFunctor._filename), 96 osgDB::getFileExtension(readFunctor._filename) 97 ); 98 99 if (rw) 100 { 101 return readFunctor.doRead(*rw); 102 } 103 else 104 { 105 return ReaderWriter::ReadResult("Warning: Could not find the .curl plugin to read from server."); 106 } 107 } 108 109 if (results.empty()) 110 { 111 return ReaderWriter::ReadResult("Warning: Could not find plugin to read objects from file \""+readFunctor._filename+"\"."); 112 } 113 114 // sort the results so the most relevant (i.e. ERROR_IN_READING_FILE is more relevant than FILE_NOT_FOUND) results get placed at the end of the results list. 115 std::sort(results.begin(), results.end()); 116 ReaderWriter::ReadResult result = results.back(); 117 118 if (result.message().empty()) 119 { 120 switch(result.status()) 121 { 122 case(ReaderWriter::ReadResult::FILE_NOT_HANDLED): result.message() = "Warning: reading \""+readFunctor._filename+"\" not supported."; break; 123 case(ReaderWriter::ReadResult::FILE_NOT_FOUND): result.message() = "Warning: could not find file \""+readFunctor._filename+"\"."; break; 124 case(ReaderWriter::ReadResult::ERROR_IN_READING_FILE): result.message() = "Warning: Error in reading to \""+readFunctor._filename+"\"."; break; 125 default: break; 126 } 127 } 128 129 return result; 130 }

 在第一次进入次函数时

它在78行  获取了插件叫osgDB_earth.dll(osgdb_earthd.dll)

它在第83行 开始加载插件调用了doRead函数

而doRead函数就是利用osgDB的机制调用,第三方插件osgDB_Earth中的读取方式:

正式开始读取本地earth文件(为什么是本地,因为读取服务器上的似乎有另外一套处理方案)振奋人心!

readstring直接调用doRead(URI.cpp)

 但是,doRead当函数调用到加载URIReadCallback的时候,给我带来不少麻烦

这里使用的类是osgearth的Registry构造,让我一度和osgDB的Registry搞混。

调试了好久,而且由于里面加载了一个osgText::readFontFile("arial.ttf");

所以导致之前的readImplementation又被调用了一遍,非常打调试的连续性······MBD

继续在ReaderWriterOsgEarth的readNode函数中往下

一番磨难,似乎看到了胜利的曙光,进入到readNode函数中:

看到了序列化,关于序列化,我有另外一个博客,可以看下

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
osgEarth 的 121 个案例详解 osgEarth 的 121 个案例详解 ...........................................................................................................1 1. aeqd.earth.................................................................................................................................4 2. annotation.earth .......................................................................................................................5 3. annotation_dateline.earth........................................................................................................6 4. annotation_dateline_projected.earth ......................................................................................8 5. annotation_flat.earth................................................................................................................8 6. arcgisonline.earth .....................................................................................................................9 7. bing.earth................................................................................................................................10 8. boston.earth............................................................................................................................11 9. boston_buildings.earth ...........................................................................................................12 10. boston_projected.earth ..................................................................................................13 11. boston_tfs.earth..............................................................................................................14 12. boston-gpu.earth ............................................................................................................15 13. bumpmap.earth ..............................................................................................................16 14. clouds.earth ....................................................................................................................17 15. colorramp.earth ..............................................................................................................18 16. contourmap.earth ...........................................................................................................19 17. datum_override.earth.....................................................................................................20 18. day_night_mp.earth........................................................................................................21 19. day_night_rex.earth........................................................................................................21 20. detail_texture.earth ........................................................................................................21 21. errors.earth .....................................................................................................................22 22. fade_elevation.earth.......................................................................................................22 23. feature_clip_plane.earth.................................................................................................23 24. feature_country_boundaries.earth.................................................................................24 25. feature_custom_filters.earth ..........................................................................................25 26. feature_draped_lines.earth ............................................................................................26 27. feature_draped_polygons.earth .....................................................................................27 28. feature_elevation.earth ..................................................................................................28 29. feature_extrude.earth.....................................................................................................29 30. feature_geom.earth ........................................................................................................30 31. feature_gpx.earth............................................................................................................31 32. feature_inline_geometry.earth.......................................................................................32 33. feature_labels.earth........................................................................................................33 34. feature_labels_script.earth.............................................................................................35 35. feature_levels_and_selectors.earth................................................................................35 36. feature_model_scatter.earth ..........................................................................................36 37. feature_models.earth .....................................................................................................37 38. feature_occlusion_culling.earth......................................................................................38osgEarth 编辑器 SXEarth www.sxsim.com 2 39. feature_offset_polygons.earth .......................................................................................38 40. feature_overlay.earth......................................................................................................39 41. feature_poles.earth.........................................................................................................40 42. feature_population_cylinders.earth ...............................................................................40 43. feature_raster.earth ........................................................................................................41 44. feature_rasterize.earth ...................................................................................................41 45. feature_rasterize_2.earth ...............................................................................................42 46. feature_scripted_styling.earth........................................................................................43 47. feature_scripted_styling_2.earth....................................................................................43 48. feature_scripted_styling_3.earth....................................................................................43 49. feature_style_selector.earth ...........................................................................................44 50. feature_tfs.earth .............................................................................................................45 51. feature_tfs_scripting.earth .............................................................................................46 52. feature_wfs.earth............................................................................................................47 53. fractal_elevation.earth....................................................................................................47 54. gdal_multiple_files.earth ................................................................................................47 55. gdal_tiff.earth..................................................................................................................48 56. geomshader.earth ...........................................................................................................49 57. glsl.earth..........................................................................................................................50 58. glsl_filter.earth ................................................................................................................51 59. graticules.earth ...............................................................................................................52 60. hires-inset.earth..............................................................................................................53 61. intersect_filter.earth .......................................................................................................54 62. land_cover_mixed.earth .................................................................................................55 63. layer_opacity.earth .........................................................................................................55 64. ldb.earth..........................................................................................................................56 65. mapbox.earth..................................................................................................................56 66. mask.earth ......................................................................................................................57 67. mb_tiles.earth.................................................................................................................58 68. mercator_to_plate_carre.earth ......................................................................................59 69. mgrs_graticule.earth.......................................................................................................60 70. min_max_level.earth ......................................................................................................60 71. min_max_range.earth.....................................................................................................61 72. min_max_range_rex.earth..............................................................................................62 73. min_max_resolutions.earth............................................................................................62 74. multiple_heightfields.earth.............................................................................................64 75. night.earth.......................................................................................................................65 76. nodata.earth ...................................................................................................................65 77. noise.earth ......................................................................................................................68 78. normalmap.earth ............................................................................................................68 79. ocean.earth .....................................................................................................................69 80. ocean_no_elevation.earth ..............................................................................................69 81. openstreetmap.earth......................................................................................................69 82. openstreetmap_buildings.earth .....................................................................................70osgEarth 编辑器 SXEarth www.sxsim.com 3 83. openstreetmap_flat.earth...............................................................................................70 84. openstreetmap_full.earth...............................................................................................70 85. openweathermap_clouds.earth......................................................................................71 86. openweathermap_precipitation.earth ...........................................................................71 87. openweathermap_pressure.earth ..................................................................................71 88. photosphere1.earth ........................................................................................................71 89. photosphere2.earth ........................................................................................................72 90. readymap.earth...............................................................................................................73 91. readymap_flat.earth .......................................................................................................73 92. readymap_include.earth.................................................................................................74 93. readymap_template.earth..............................................................................................74 94. readymap-elevation-only.earth.......................................................................................74 95. readymap-osm.earth ......................................................................................................75 96. readymap-priority.earth..................................................................................................75 97. readymap-rex.earth ........................................................................................................75 98. roads.earth......................................................................................................................76 99. roads-flattened.earth......................................................................................................76 100. roads-test.earth...............................................................................................................76 101. scene_clamping.earth.....................................................................................................76 102. silverlining.earth..............................................................................................................78 103. simple_model.earth........................................................................................................78 104. skyview1.earth ................................................................................................................79 105. skyview2.earth ................................................................................................................80 106. splat.earth .......................................................................................................................81 107. splat-blended-with-imagery.earth ..................................................................................81 108. splat-with-mask-layer.earth.............................................................................................81 109. splat-with-multiple-zones.earth......................................................................................82 110. splat-with-rasterized-land-cover.earth............................................................................82 111. stamen_toner.earth ........................................................................................................82 112. stamen_watercolor.earth................................................................................................82 113. state_plane.earth............................................................................................................82 114. tess_screen_space.earth.................................................................................................82 115. tess-coastlines.earth .......................................................................................................82 116. tess-terrain.earth ............................................................................................................83 117. triton.earth......................................................................................................................83 118. triton_drop_shader.earth................................................................................................83 119. utm.earth ........................................................................................................................83 120. utm_graticule.earth ........................................................................................................83 121. vertical_datum.earth ......................................................................................................83 122. wms_nexrad.earth ..........................................................................................................84 123. wms-t_nexrad_animated.earth ......................................................................................84 124. 编辑问题总结....................................................................................错误!未定义书签。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值