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

相关内容

热门资讯

山水皆有情!丽江两山一江的千年... 去过丽江、走过虎跳峡的人,大概率都听过哈巴雪山和金沙江的传说。很多人站在峡谷之下,望着奔腾不息的金沙...
活力中国调研行丨“殷”你而来 ... 9月12日,游客在殷墟博物馆“甲骨文展厅”内参观。位于河南省安阳市的殷墟博物馆新馆是首个全景式展现商...
浦江之夜赴美好相逢,第37届上... 9月12日晚,黄浦江畔灯火璀璨,第37届上海旅游节大巡游在外滩中山东一路上演。不少观众早早便来到外滩...
美丽中国丨秋韵紫鹊界 梯田入画... 这是9月11日拍摄的紫鹊界梯田(无人机照片)。 金秋九月,湖南省娄底市新化县紫鹊界梯田稻谷渐次成熟。...
中国之巅奏响《共同的节日》,千... 千吨阻尼器,“迎世赛、游上海旅游节”。9月13日,由上海市文化和旅游局指导推出上海旅游·会客│巅峰之...