00001 #ifndef OPENTISSUE_DYNAMICS_PSYS_FORCE_UTIL_PSYS_COMPUTE_PERLIN_NOISE_FORCE_FIELD_H 00002 #define OPENTISSUE_DYNAMICS_PSYS_FORCE_UTIL_PSYS_COMPUTE_PERLIN_NOISE_FORCE_FIELD_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/containers/grid/util/grid_idx2coord.h> 00013 #include <OpenTissue/core/math/noise/noise_perlin.h> 00014 00015 00016 namespace OpenTissue 00017 { 00018 namespace psys 00019 { 00020 00021 template<typename grid_type> 00022 void compute_perlin_noise_force_field( grid_type & field ) 00023 { 00024 typedef typename grid_type::index_iterator index_iterator; 00025 typedef typename grid_type::value_type vector3_type; 00026 typedef typename vector3_type::value_type real_type; 00027 00028 if(field.empty()) 00029 { 00030 std::cerr << " compute_perlin_noise_force_field(): map was empty, did you forget to call create?" << std::endl; 00031 return; 00032 } 00033 00034 00035 noise::PerlinNoise<real_type> xnoise; 00036 noise::PerlinNoise<real_type> ynoise; 00037 noise::PerlinNoise<real_type> znoise; 00038 00039 for( index_iterator iter = field.begin(); iter != field.end(); ++iter ) 00040 { 00041 vector3_type r,v; 00042 OpenTissue::grid::idx2coord(iter,r); 00043 v(0) = xnoise(r(0),r(1),r(2)); 00044 v(1) = ynoise(r(0),r(1),r(2)); 00045 v(2) = znoise(r(0),r(1),r(2)); 00046 (*iter) = v; 00047 } 00048 } 00049 00050 } // namespace psys 00051 } // namespace OpenTissue 00052 00053 // OPENTISSUE_DYNAMICS_PSYS_FORCE_UTIL_PSYS_COMPUTE_PERLIN_NOISE_FORCE_FIELD_H 00054 #endif