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