00001 #ifndef OPENTISSUE_CORE_MATH_NOISE_NOISE_FRACTAL_SUM_H 00002 #define OPENTISSUE_CORE_MATH_NOISE_NOISE_FRACTAL_SUM_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 00026 template<typename real_type_> 00027 class FractalSumNoise 00028 { 00029 public: 00030 00031 typedef real_type_ real_type; 00032 typedef ImprovedPerlinNoise<real_type> noise_type; 00033 00034 protected: 00035 00036 int m_octaves; 00037 noise_type m_noise; 00038 00039 public: 00040 00041 FractalSumNoise(int const & octaves) 00042 : m_octaves(octaves) 00043 { } 00044 00045 real_type operator()(real_type const & x,real_type const & y)const 00046 { 00047 real_type sum = 0; 00048 for(int i=0;i<m_octaves;++i) 00049 { 00050 int scale = (1<<i); 00051 real_type fraction = (1.0/scale); 00052 sum += fraction*m_noise(scale*x,scale*y); 00053 } 00054 return sum; 00055 } 00056 00057 real_type operator()(real_type const & x,real_type const & y,real_type const & z)const 00058 { 00059 real_type sum = 0; 00060 for(int i=0;i<m_octaves;++i) 00061 { 00062 int scale = (1<<i); 00063 real_type fraction = (1.0/scale); 00064 sum += fraction*m_noise(scale*x,scale*y,scale*z); 00065 } 00066 return sum; 00067 } 00068 00069 }; 00070 00071 } // namespace noise 00072 00073 } // namespace OpenTissue 00074 00075 //OPENTISSUE_CORE_MATH_NOISE_NOISE_FRACTAL_SUM_H 00076 #endif