00001 #ifndef OPENTISSUE_CORE_MATH_NOISE_NOISE_TURBULENCE_H 00002 #define OPENTISSUE_CORE_MATH_NOISE_NOISE_TURBULENCE_H 00003 // 00004 // OpenTissue Template Library 00005 // - A generic toolbox for physics-based modeling and simulation. 00006 // Copyright (C) 2008 Department of Computer Science, University of Copenhagen. 00007 // 00008 // OTTL is licensed under zlib: http://opensource.org/licenses/zlib-license.php 00009 // 00010 #include <OpenTissue/configuration.h> 00011 00012 #include <OpenTissue/core/math/noise/noise_improved_perlin.h> 00013 00014 00015 namespace OpenTissue 00016 { 00017 00018 namespace noise 00019 { 00020 00027 template<typename real_type_> 00028 class Turbulence 00029 { 00030 public: 00031 00032 typedef real_type_ real_type; 00033 typedef ImprovedPerlinNoise<real_type> noise_type; 00034 00035 protected: 00036 00037 unsigned int m_octaves; 00038 noise_type m_noise; 00039 00040 public: 00041 00046 Turbulence(unsigned int octaves) 00047 : m_octaves(octaves) 00048 { } 00049 00050 real_type operator()(real_type const & x,real_type const & y) const 00051 { 00052 real_type scale = static_cast<real_type>(1.0); 00053 real_type sum = 0; 00054 for(unsigned int octav = 0;octav<m_octaves;++octav) 00055 { 00056 real_type inv_scale = (1.0/scale); 00057 sum += std::fabs( m_noise(x*inv_scale,y*inv_scale)*scale ); 00058 scale *= .5; 00059 } 00060 return sum; 00061 } 00062 00063 real_type operator()(real_type const & x,real_type const & y,real_type const & z) const 00064 { 00065 real_type scale = static_cast<real_type>(1.0); 00066 real_type sum = 0; 00067 for(unsigned int octav = 0;octav<m_octaves;++octav) 00068 { 00069 real_type inv_scale = (1.0/scale); 00070 sum += std::fabs( m_noise(x*inv_scale,y*inv_scale,z*inv_scale)*scale ); 00071 scale *= .5; 00072 } 00073 return sum; 00074 } 00075 00076 }; 00077 00078 } // namespace noise 00079 00080 } // namespace OpenTissue 00081 00082 //OPENTISSUE_CORE_MATH_NOISE_NOISE_TURBULENCE_H 00083 #endif