日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

OSG读取Tif格式的高程数据

發(fā)布時間:2023/12/31 编程问答 40 豆豆
生活随笔 收集整理的這篇文章主要介紹了 OSG读取Tif格式的高程数据 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

讀取

使用OSG讀取Tif格式的高程數(shù)據(jù)其實(shí)非常簡單,使用osg::HeightField就行。

osg::ref_ptr<osg::HeightField> heightMap =osgDB::readHeightFieldFile("underWater.tif.gdal");//以.gdal結(jié)尾,調(diào)用gdal讀取

著色

1)可以將高程數(shù)據(jù)生成圖片(可以用QImage實(shí)現(xiàn)),直接然后對數(shù)據(jù)進(jìn)行貼圖顯示,
2)也可以對頂點(diǎn)數(shù)據(jù)進(jìn)行著色實(shí)現(xiàn)。


全部代碼

//********************* //測試OSG讀取Tif高程數(shù)據(jù)進(jìn)行著色 //BOO //2021年8月28日 //*******************#include <iostream> #include<osgViewer/Viewer> #include<osg/Node> #include <osgDB/ReadFile> #include <osg/ShapeDrawable> #include <osg/Material> #include <osg/Texture2D>int main() {osg::ref_ptr<osgViewer::Viewer> viewer = new osgViewer::Viewer;viewer->setUpViewInWindow(50, 50, 800, 600);osg::ref_ptr<osg::HeightField> heightMap =osgDB::readHeightFieldFile("underWater.tif.gdal");//以.gdal結(jié)尾,調(diào)用gdal讀取std::cout << heightMap->getNumRows() << " " << heightMap->getNumColumns() << std::endl;osg::ref_ptr<osg::Group> root = new osg::Group;if (heightMap != nullptr){osg::ref_ptr<osg::Geode> geode = new osg::Geode;//添加到葉子節(jié)點(diǎn)中geode->addDrawable(new osg::ShapeDrawable(heightMap));osg::ref_ptr<osg::Image> img = osgDB::readImageFile("test2.png");osg::ref_ptr<osg::Texture2D> texture = new osg::Texture2D;texture->setImage(img.get());texture->setDataVariance(osg::Object::DYNAMIC);osg::ref_ptr<osg::StateSet> stateset = new osg::StateSet();stateset->setTextureAttributeAndModes(0, texture.get(), osg::StateAttribute::ON);geode->setStateSet(stateset.get());//必須要,不知道為什么?osg::Material* material = new osg::Material;material->setAmbient(osg::Material::FRONT, osg::Vec4(0xCC / 255.0, 0x99 / 255.0, 0x33 / 255.0, 0.8f));geode->getOrCreateStateSet()->setAttributeAndModes(material, osg::StateAttribute::ON);root->addChild(geode);}viewer->setSceneData(root);return viewer->run(); }

總結(jié)

以上是生活随笔為你收集整理的OSG读取Tif格式的高程数据的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。