Go to the documentation of this file.00001 #ifndef OPENTISSUE_GPU_IMAGE_IMAGE_MAKE_NOISE_H
00002 #define OPENTISSUE_GPU_IMAGE_IMAGE_MAKE_NOISE_H
00003
00004
00005
00006
00007
00008
00009
00010 #include <OpenTissue/configuration.h>
00011
00012 #include <OpenTissue/core/math/noise/noise_improved_perlin.h>
00013
00014
00015 namespace OpenTissue
00016 {
00017 namespace image
00018 {
00019
00028 template<typename image_type>
00029 void make_noise(
00030 image_type & image
00031 , float freq=4.0f
00032 , float amplitude = 1.0f
00033 )
00034 {
00035 typedef typename image_type::value_type value_type;
00036
00037 size_t width = image.width();
00038 size_t height = image.height();
00039 size_t channels = image.channels();
00040
00041 noise::ImprovedPerlinNoise<float> f;
00042
00043 float x_scale = freq / (width-1.0);
00044 float y_scale = freq / (height-1.0);
00045
00046 for(size_t j=0;j<height;++j)
00047 for(size_t i=0;i<width;++i)
00048 {
00049 float x = x_scale*(i + 0.5);
00050 float y = y_scale*(j + 0.5);
00051 float biased = (f(x,y)+1.0)*.5;
00052 value_type value = static_cast<value_type>( biased*amplitude );
00053 for(size_t c=0;c<channels;++c)
00054 image(i,j,c) = value;
00055 }
00056 }
00057
00058 }
00059 }
00060
00061
00062 #endif