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

相关内容

热门资讯

国庆黄金周景区情况:大同古城半... 文| 芙昕 编辑 | 芙昕 国庆长假,很多人都计划着出门走走,可一到了那些热门景点,看到的往往不是山...
来大东北一共分两步:先“冷藏”... 还在被“东北=冰窖”的刻板印象吓退? 南方的“小土豆”们 别急着裹紧小棉袄 这个冬天 让“气候缓冲带...
第三届“长城之约”活动在河北涞... 11月15日,第三届"长城之约"全球推广活动暨世界文化遗产对话15日在河北省保定市涞源县启幕。 本次...
巴厘岛:时光在此停驻 (自由行... 曾几何时,世人只知巴厘岛而不知印尼。巴厘岛的美太过耀眼,以至于人们常常忘记——它只是印尼万千岛屿中最...