ReadResult result;
osg::ref_ptr<osgDB::ReaderWriter> reader = osgDB::Registry::instance()->getReaderWriterForExtension("tif");
std::string name("D:\\gd.tif");
osgDB::ReaderWriter::Options* opt= NULL;
osgDB::ReaderWriter::ReadResult rr = reader->readImage(name, opt); if (rr.validImage())
{
result = ReadResult(rr.takeImage());
result.getImage()->setName("nameNoUse.tif");
} if (result.succeeded())
{
result.getObject();
result.metadata();
osg::ref_ptr<osg::Image> image = result.getImage(); osgEarth::ImageToHeightFieldConverter conv;
osg::HeightField* hf = conv.convert(image.get()); for (unsigned col = ; col < hf->getNumColumns(); ++col)
{
for (unsigned row = ; row < hf->getNumRows(); ++row)
{
float height = hf->getHeight(col, row);
if (height < 1.0)
{
float newh = cos(height*3.141593f);
//float rf = rand()% 500;
hf->setHeight(col, row, -* newh);
}
else// if(height > 1)
{
//height = 100;//下断点看看
}
}
} osg::Image* newimage = conv.convert(hf);
std::string nameofnew("D:\\gd2.tif");
reader->writeImage(*newimage, nameofnew); }

如题

加SB的“平滑”功能

float fBegin = 0.1;
//float fEnd = 0.000001;
float fLowestValue = 1000.0;
int fWide = 100.0; ReadResult result;
osg::ref_ptr<osgDB::ReaderWriter> reader = osgDB::Registry::instance()->getReaderWriterForExtension("tif");
std::string name("D:\\gd.tif");
osgDB::ReaderWriter::Options* opt= NULL;
osgDB::ReaderWriter::ReadResult rr = reader->readImage(name, opt); if (rr.validImage())
{
result = ReadResult(rr.takeImage());
result.getImage()->setName("guandao.tif");
} if (result.succeeded())
{
result.getObject();
result.metadata();
osg::ref_ptr<osg::Image> image = result.getImage(); osgEarth::ImageToHeightFieldConverter conv;
osg::HeightField* hf = conv.convert(image.get()); int *fFlag = new int[hf->getNumColumns()*hf->getNumRows()]; for (unsigned col = ; col < hf->getNumColumns(); ++col)
{
for (unsigned row = ; row < hf->getNumRows(); ++row)
{
fFlag[col*hf->getNumRows() + row] = ;
float height = hf->getHeight(col, row);
if (height < fBegin)
{
fFlag[col*hf->getNumRows() + row] = ;
hf->setHeight(col, row, -fLowestValue);
/*
float newh = -1000.0;
if(height > 0.00001)
newh = 0.1 - (0.1 - height)/ (0.1-0.00001)*1000.0;
hf->setHeight(col, row, newh);*/
}
}
} for (int i = ; i < hf->getNumColumns()*hf->getNumRows(); i++)
{
if (fFlag[i] == )//如果这值在海面以下
{
bool isNearSide = false;
int nowX = i/hf->getNumRows();
int nowY = i%hf->getNumRows();
for (int j = ; j <= fWide; j++)
{
//从离此值最近的值开始找附近的岸边,往外延伸
//向东南西北四个方向找,没层都遍历一圈
for ( int x = ;x <= j;x++ )
{
//如果找到有岸边
int fDifValueX = x;
int fDifValueY = j - x;
int realX = nowX - fDifValueX;
if (realX > )
{
int realY = nowY - fDifValueY;
if (realY > )
{
if (fFlag[realX*hf->getNumRows() + realY] == )//如果是岸边
isNearSide = true;
}
realY = nowY + fDifValueY;
if (realY < hf->getNumRows())
{
if (fFlag[realX*hf->getNumRows() + realY] == )//如果是岸边
isNearSide = true;
}
} realX = nowX + fDifValueX;
if (realX < hf->getNumColumns())
{
int realY = nowY - fDifValueY;
if (realY > )
{
if (fFlag[realX*hf->getNumRows() + realY] == )//如果是岸边
isNearSide = true;
}
realY = nowY + fDifValueY;
if (realY < hf->getNumRows())
{
if (fFlag[realX*hf->getNumRows() + realY] == )//如果是岸边
isNearSide = true;
}
}
} //查找这个范围内是否有值,如果有值则用此值
if (isNearSide)
{
float fRealHeight = fBegin - j * fLowestValue / fWide;
hf->setHeight((i / hf->getNumRows()), (i % hf->getNumRows()), fRealHeight);
break;//退出当前寻找的延伸
}
}
}
} osg::Image* newimage = conv.convert(hf);
std::string nameofnew("D:\\gd2.tif");
reader->writeImage(*newimage, nameofnew);
delete[]fFlag;
}

[原][osg][osgearth]简单的通过osgDB,读取高程tif,修改高程tif的更多相关文章

  1. [原][osg][osgearth]我眼中的osgearth

    看了一下,OE生成的可执行文件 除了osg库和第三方库 OE生产最多的dll就是 osgdb_osgearth_XXXX.dll了 这些都是为了通过osgDB机制加载earth的数据用的. 所以,我觉 ...

  2. [原][OSG][osgEarth]osgEarth例子程序简介

    1.osgearth_graticule:生成经纬线. 2.osgearth_annotation:各类标注(点.线.面.模型.文本等). 3.osgearth_city:加载一个城市三维模型,可以浏 ...

  3. [原][osg][osgEarth][粒子特效]关于粒子特效库在osgEarth中,位置摆放问题,跟踪节点移动问题

    首先粒子在地球上位置摆放很简单: //传入的经纬度坐标 osg::Vec3d geoPoint; const SpatialReference* latLong = SpatialReference: ...

  4. [原][osg][osgEarth]EarthManipulator关于oe漫游器的handle部分解读以及修改(仿照谷歌,修改oe漫游器中focal(视角切换)功能 续 二)

    bool EarthManipulator::handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa) ...

  5. [原][osg][osgEarth]osg::Matrix 父子节点的变化关系

    //osg::Matrix offsetmatrix 计算出子节点在父节点下的绝对坐标 //osg::Matrix offposition 用来计算当前节点相对父节点的位置 osg::Matrix o ...

  6. [原][osg][osgEarth]关于在OE中使用物理引擎的调研

    关于物理引擎旋转的一些整理 参考文档 http://blog.wolfire.com/2010/03/Comparing-ODE-and-Bullet 介绍ODE和bullet的利弊 http://s ...

  7. [原][osg][OSGEARTH]OE的关闭打开自动计算裁剪面被OE的海洋ocean影响

    在osgEarthUtil 下 Ocean.cpp 的  traverse函数中: // we don't want the ocean participating in the N/F calcul ...

  8. [原][osg][osgearth]倾斜摄影2.文件格式分析:OSGB

    倾斜摄影三维模型格式包含:*.osgb,*.dae等 文件格式包含:*.xml, *.desc, *.lfp等 例如:LocaSpace Viewer软件把osgb分块模型文件建立索引生成一个lfp文 ...

  9. [原][osg][osgearth]倾斜摄影1.介绍

    总体介绍: 倾斜摄影就是将拍好的数据,三角网格化再附上贴图. 目前流行处理软件: Street Factory.PIX4DMapper.smart3D 后期开发平台:超图 Skyline smart3 ...

随机推荐

  1. iOS 设计模式-委托模式

    委托是指给一个对象提供机会对另一对象中的变化做出反应或者相应另一个对象的行为.其基本思想是协同解决问题. Delegate的使用场合 对象A内部发生了一些事情,想通知对象B 对象B想监听对象A内部发生 ...

  2. Java的jdk1.6与jre1.8中存在的差异

    一般来说: jdk每一个版本都是向后兼容的,说以低版本的代码是可以运行在高版本的虚拟机上的.而反过来则不可以,用1.6的编译器编辑的字节码文件是不可以运行在1.5版本的虚拟机上的. 但是今天我用Sun ...

  3. php深入学习

    关于PHP程序员解决问题的能力 http://rango.swoole.com/archives/340 深入理解PHP内核 by xuhong大牛 http://www.php-internals. ...

  4. 004-ubuntu安装配置SSH服务

    一.ssh安装. 1.# sudo apt-get -y install openssh-server. 2.在/etc/ssh/sshd_config文件中添加一句:PermitRootLogin ...

  5. python学习第一次

    一,安装python 官网下载地址:https://www.python.org/downloads/windows/ 我下载的是最新的: Download Windows x86 web-based ...

  6. pycharm中内看内建函数的定义

    鼠标方法在内建函数上,Ctrl+B,看内建函数的定义 如果想要看内置函数的具体实现细节,可以到python的lib目录下C:\Python27\Lib\,或者python的官网上 如果要看非内建的函数 ...

  7. 查看.mobileprovision 详细信息

    .mobileprovision 用诸如sublime 等工具是无法打开. 可以通过shell命令查看: security cms -D -i 某某.mobileprovision

  8. 精力管理 | 迅速恢复精力的N个技巧,四个关键词以及自我管理的方法和工具列表

    精力管理 | 迅速恢复精力的N个技巧,所谓坚持,是坚定的“持有”,这个“持”字很值得琢磨——不是扛.不是顶,而是“持”这样一个半放松的状态.如果你没做好自己该做的事情,如果你自己没有成长起来,随着年龄 ...

  9. tomcat性能调优 大赞

    从“第三天”的性能测试一节中,我们得知了决定性能测试的几个重要指标,它们是: ü 吞吐量 ü Responsetime ü Cpuload ü MemoryUsage 我 们也在第三天的学习中对Apa ...

  10. 深入浅出JVM

    这篇文章简要解析了JVM的内部结构.下面这幅图展示了一个典型的JVM(符合JVM Specification Java SE 7 Edition)所具备的关键内部组件. 上图展示的所有这些组件都将在下 ...