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;
}

相关内容

热门资讯

穿越天山遇见四季童话:新疆深度... 穿越天山遇见四季童话:新疆深度旅行指南与秘境故事 序章:一封来自西域的情书 每年六月,当伊犁河谷的薰...
从戈壁到花海:一位新疆本地向导... 从戈壁到花海:一位新疆本地向导的四季旅行手记 在新疆生活了近二十年,我依然记得第一次被这片土地震撼的...
穿越军 - 穿越中国亲子挑战赛... 以前总带孩子去各地旅游,打卡景点、吃美食,回来之后孩子除了照片,什么都没留下,直到带他参加穿越军亲子...
2026最新山东旅行社综合实力... 随着 2026 年旅游市场持续升温,山东凭借 "一山一水一圣人" 的独特魅力和丰富的文旅资源,成为国...
二十年,再赴大熊山 人间忽晚,山河已秋。一别大熊山,已是整整二十载。 那时我匆匆登临,步履轻快,眼里只有山川壮阔、林木葱...