查看: 3879|回复: 4

求问:使用osgearth动态加载海量地形和纹理问题

[复制链接]

该用户从未签到

发表于 2011-8-10 21:23:04 | 显示全部楼层 |阅读模式
关于使用osgearth的addelevationlayer和addimagelayer方法来动态、实时加载大量地形及配套纹理数据时出现了问题。
我写了一个线程,每隔10s左右检测一下指定目录,如果发现新的地形和纹理数据,就用以上方法加载进map,地形和纹理数据都是tif格式,具体线程中的代码如下:
virtual void run()
{
_done = false;
_dirty = true;
do
{
YieldCurrentThread();
addNewTerrainModel();
OpenThreads::Thread::microSleep(10000000);
} while( !_done );
}

void addNewTerrainModel( )
{
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_mutex);

ostringstream ostrfile,ostrname;
ostrname<<fileformat<<index;
string strDEMFile, strImgFile;
ostrfile<<strDataDir<<"\\"<<fileformat<<index<<".tif";
BOOL bExist = PathFileExists(ostrfile.str().c_str());
if(bExist)
strDEMFile = ostrfile.str();
else
return;
ostrfile.str("");
ostrfile<<strDataDir<<"\\"<<fileformat<<index<<".tif";
bExist = PathFileExists(ostrfile.str().c_str());
if(bExist)
strImgFile = ostrfile.str();
else
return;
GDALOptions gdal;
gdal.url() = strDEMFile;
ElevationLayerOptions elevLayOpt(ostrname.str(), gdal);
map->addElevationLayer(new ElevationLayer(elevLayOpt));

gdal.url() = strImgFile;
ImageLayerOptions imgLayOpt(ostrname.str(), gdal);
map->addImageLayer(new ImageLayer(imgLayOpt));

index++;

_dirty = true;
}
但是这么做有一个缺点,就是随着数据逐步加入,程序内存占用相当厉害,最后程序就崩溃了。
我考虑给map加个缓存以提高效率,因此,我在主线程中创建map钱加入了如下代码:

TMSCacheOptions tmsopt;
tmsopt.setPath(strCacheDir);
MapOptions mapopt;
mapopt.cache() = tmsopt;
mapopt.cache()->cacheOnly() = false;
map = new osgEarth::Map(mapopt);
可是效果也不是太理想,而且,如果程序第二次运行,缓存目录中有上次缓存的文件夹,程序会直接崩溃。
有哪位研究过osgearth的请帮忙分析一下原因,或给点提示。谢谢!

该用户从未签到

发表于 2011-8-18 09:36:42 | 显示全部楼层
楼主解决没有啊,我也碰到了类似的问题,加载效率太慢,但是写成.earth文件就很快,不知是为什么?
解决的话分享下,谢谢楼主!

该用户从未签到

发表于 2011-8-18 10:11:41 | 显示全部楼层
加载原始影像高程最好先进行瓦片金字塔处理

该用户从未签到

 楼主| 发表于 2011-8-24 10:28:45 | 显示全部楼层
我已经按照网页中的预处理对数据进行了金字塔处理啊

该用户从未签到

发表于 2011-8-26 21:39:05 | 显示全部楼层
高程数据如何进行金字塔处理,有什么工具吗
您需要登录后才可以回帖 登录 | 注册

本版积分规则

OSG中国官方论坛-有您OSG在中国才更好

网站简介:osgChina是国内首个三维相关技术开源社区,旨在为国内更多的技术开发人员提供最前沿的技术资讯,为更多的三维从业者提供一个学习、交流的技术平台。

联系我们

  • 工作时间:09:00--18:00
  • 反馈邮箱:1315785073@qq.com
快速回复 返回顶部 返回列表