Go to the documentation of this file.00001 #ifndef OPENTISSUE_CORE_CONTAINERS_GRID_UTIL_GRADIENT_MAGNITUDE_H
00002 #define OPENTISSUE_CORE_CONTAINERS_GRID_UTIL_GRADIENT_MAGNITUDE_H
00003
00004
00005
00006
00007
00008
00009
00010 #include <OpenTissue/configuration.h>
00011
00012 #include <OpenTissue/core/containers/grid/util/grid_gradient.h>
00013 #include <OpenTissue/core/math/math_vector3.h>
00014
00015 #include <cmath>
00016
00017 namespace OpenTissue
00018 {
00019 namespace grid
00020 {
00021
00022 template<typename grid_type, typename real_type>
00023 inline void gradient_magnitude(
00024 grid_type const & grid
00025 , size_t i
00026 , size_t j
00027 , size_t k
00028 , real_type & grad_mag
00029 )
00030 {
00031 using std::sqrt;
00032
00033 typedef OpenTissue::math::Vector3<real_type> vector3_type;
00034 vector3_type g;
00035 gradient(map,i,j,k,g);
00036 grad_mag = sqrt(g*g);
00037 }
00038
00039 template<typename grid_iterator, typename real_type>
00040 inline void gradient_magnitude (grid_iterator const & iter, real_type & grad_mag )
00041 {
00042 typedef typename grid_iterator::grid_type grid_type;
00043
00044 size_t i = iter.i();
00045 size_t j = iter.j();
00046 size_t k = iter.k();
00047
00048 grid_type const & grid = iter.get_grid();
00049
00050 gradient_magnitude(grid, i, j, k, grad_mag);
00051 }
00052
00053 template<typename grid_iterator>
00054 inline typename grid_iterator::math_types::real_type gradient_magnitude( grid_iterator const & iter )
00055 {
00056 typedef typename grid_iterator::math_types::real_type real_type;
00057
00058 real_type grad_mag;
00059
00060 gradient_magnitude(iter, grad_mag);
00061
00062 return grad_mag;
00063 }
00064
00065 }
00066 }
00067
00068
00069 #endif