osgEarth示例分析——osgearth_noisegen
admin
2024-03-28 15:41:16

前言

osgearth_noisegen示例,展示生成噪音图。也就是根据设置生成声音曲线,在绘制到图上。但是写入文件总是报错。

osgDB::writeImageFile 这个方法,我的理解,它就是要把输入的内容输出到二维图文件中的。并且也进行了测试,但是却行不通。

执行命令:osgearth_noisegend.exe --size 10    // 其他参数都设置默认了

代码分析

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include using namespace osgEarth;
using namespace osgEarth::Drivers;
using namespace osgEarth::Util;int usage()
{OE_WARN << "\n""osgearth_noisegen --size n             ; image dimension\n""                  --out string         ; output filename\n""                  [--frequency n]      ; default = 16\n""                  [--octaves n]        ; default = 12\n"<< std::endl;return -1;
}
/*** How to create a simple osgEarth map and display it.* 如何创建一个简单地图并展示*/
int
main(int argc, char** argv)
{osg::ArgumentParser arguments(&argc,argv);// 传入尺寸int dim;if (!arguments.read("--size", dim))return usage();// 输出文件名。// 如果设置为如下格式,则会分别报错如下:// git tif:not implemented// png jpg:write error// osg :file not handled// osgb:虽然此格式不会报错,但是生成的osgb用osgviewer.exe 却无法打开。std::string out = "out.jpg";//if (!arguments.read("--out", out))//    return usage();// 频率默认16.0double freq = 16.0;arguments.read("--frequency", freq);// 12个8度音阶??int octaves = 12;arguments.read("--octaves", octaves);// SimplexNoise 单工噪声发生器类。SimplexNoise noise;noise.setFrequency(freq);noise.setOctaves(octaves);noise.setNormalize(true);// 对声音进行归一化// 创建所需尺寸dim的可平铺图像,// 图像将在[0..1]范围内进行直方图拉伸。osg::Image* image = noise.createSeamlessImage(dim);// 将图片写入文件中osgDB::writeImageFile(*image, out);// jpg 文件写入错误// 测试wirteImageFile方法,先读取一个jpg,再保存输出jpg//osg::ref_ptr img = new osg::Image;//img = osgDB::readImageFile("D:\\FreeXGIS\\osgearth_gch\\data\\resources\\textures_us\\commercial\\1Flint_sm.jpg");//osg::ref_ptr img2 = new osg::Image;//img2->setImage(img->s(), img->t(), img->r(), img->getInternalTextureFormat(), img->getPixelFormat(), img->getDataType(), img->data(), img->getAllocationMode());//osgDB::writeImageFile(*img2, "img2.jpg");return 0;
}

相关内容

热门资讯

出境游目的地市场——中东市场分... 本文为节选内容,更多内容关注公众号:大消费市场调研 中东旅游市场迎来显著增长浪潮 据携程网最新发布的...
上有巨石擎天,下有深谷清泉,平... 你是否有那么一刻 想逃离城市的酷暑高温 钻进未被人潮占领的山林 在深谷中听山泉叮咚 在森林中看野蜂飞...
幸福河湖直通车 | 循着溪脉探... 3月21日,在市水利部门的组织下,市民代表们循着溪脉足迹,开启了一场兼具生态之美与人文之韵的幸福河湖...
部分考点发布2026普通专升本... 广州应用科技学院 广州南方学院 珠海科技学院 广州科技职业技术大学 华南农业大学珠江学院 地址:广东...
旅发大会丨走啊!带你去湘潭看仙... 春雨绵绵 雨中踏青别有趣味 🌸🌸🌸🌸 周末到哪玩? 相约去湘潭! 今天来看 湘潭四大名山...