OSG读取Tif格式的高程数据
生活随笔
收集整理的這篇文章主要介紹了
OSG读取Tif格式的高程数据
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
讀取
使用OSG讀取Tif格式的高程數據其實非常簡單,使用osg::HeightField就行。
osg::ref_ptr<osg::HeightField> heightMap =osgDB::readHeightFieldFile("underWater.tif.gdal");//以.gdal結尾,調用gdal讀取著色
1)可以將高程數據生成圖片(可以用QImage實現),直接然后對數據進行貼圖顯示,
2)也可以對頂點數據進行著色實現。
全部代碼
//********************* //測試OSG讀取Tif高程數據進行著色 //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結尾,調用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;//添加到葉子節點中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(); }總結
以上是生活随笔為你收集整理的OSG读取Tif格式的高程数据的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 文库资源下载
- 下一篇: CRC校验算法及C++程序实现