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