Image HeightField

1、将osg::Image转换成osg::HeightField

src\osgEarth\ImageToHeighFieldConvter

例子:

ImageToHeighFieldConvter conv;

osg::Image* image = osgDB::readImageFile("img.tif");

osg::HeightField* hf = conv.convert( image );

2、下面这个函数是夹在一张高程图片,再贴上纹理

osg::Node* createHeightField(std::string heightFile, std::string texFile) {

    osg::Image* heightMap = osgDB::readImageFile(heightFile);

    osg::HeightField* heightField = new osg::HeightField();
    heightField->allocate(heightMap->s(), heightMap->t());
    heightField->setOrigin(osg::Vec3(-heightMap->s() / 2, -heightMap->t() / 2, 0));
    heightField->setXInterval(1.0f);
    heightField->setYInterval(1.0f);
    heightField->setSkirtHeight(1.0f);

    for (int r = 0; r < heightField->getNumRows(); r++) {
        for (int c = 0; c < heightField->getNumColumns(); c++) {
            heightField->setHeight(c, r, ((*heightMap->data(c, r)) / 255.0f) * 80.0f);
        }
    }

    osg::Geode* geode = new osg::Geode();
    geode->addDrawable(new osg::ShapeDrawable(heightField));

    osg::Texture2D* tex = new osg::Texture2D(osgDB::readImageFile(texFile));
    tex->setFilter(osg::Texture2D::MIN_FILTER,osg::Texture2D::LINEAR_MIPMAP_LINEAR);
    tex->setFilter(osg::Texture2D::MAG_FILTER,osg::Texture2D::LINEAR);
    tex->setWrap(osg::Texture::WRAP_S, osg::Texture::REPEAT);
    tex->setWrap(osg::Texture::WRAP_T, osg::Texture::REPEAT);
    geode->getOrCreateStateSet()->setTextureAttributeAndModes(0, tex);

    return geode;
}

原文链接: https://www.cnblogs.com/coolbear/archive/2013/06/09/3128613.html

欢迎关注

微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍

原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/91742

非原创文章文中已经注明原地址,如有侵权,联系删除

关注公众号【高性能架构探索】,第一时间获取最新文章

转载文章受原作者版权保护。转载请注明原作者出处!

(0)
上一篇 2023年2月10日 上午1:19
下一篇 2023年2月10日 上午1:19

相关推荐