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