OSG读取Tif格式的高程数据
生活随笔
收集整理的這篇文章主要介紹了
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)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 文库资源下载
- 下一篇: CRC校验算法及C++程序实现