Go to the documentation of this file.00001 #ifndef OPENTISSUE_CORE_CONTAINERS_GRID_UTIL_GRID_MEAN_CURVATURE_H
00002 #define OPENTISSUE_CORE_CONTAINERS_GRID_UTIL_GRID_MEAN_CURVATURE_H
00003
00004
00005
00006
00007
00008
00009
00010 #include <OpenTissue/configuration.h>
00011
00012 #include <cmath>
00013
00014 #include <OpenTissue/core/containers/grid/util/grid_gradient.h>
00015 #include <OpenTissue/core/containers/grid/util/grid_hessian.h>
00016
00017 namespace OpenTissue
00018 {
00019 namespace grid
00020 {
00021
00022 template<typename grid_type, typename real_type>
00023 inline void mean_curvature(
00024 grid_type const & grid
00025 , size_t i
00026 , size_t j
00027 , size_t k
00028 , real_type & K
00029 )
00030 {
00031 using std::min;
00032 using std::max;
00033 using std::pow;
00034
00035 typedef OpenTissue::math::Vector3<real_type> vector3_type;
00036 typedef OpenTissue::math::Matrix3x3<real_type> matrix3x3_type;
00037
00038 real_type limit_K = boost::numeric_cast<real_type>( 1. / min( grid.dx(), min( grid.dy(), grid.dz() ) ) );
00039
00040 vector3_type g;
00041 matrix3x3_type H;
00042
00043 gradient( grid, i, j, k, g );
00044 hessian( grid, i, j, k, H );
00045 real_type h = g * g;
00046
00047
00048
00049
00050 if ( h == 0 )
00051 h = 1;
00052
00053 const static real_type exponent = boost::numeric_cast<real_type>( 3. / 2. );
00054 K = ( 1.0 / pow( h, exponent ) ) * (
00055 g( 0 ) * g( 0 ) * ( H( 1, 1 ) + H( 2, 2 ) ) - 2. * g( 1 ) * g( 2 ) * H( 1, 2 ) +
00056 g( 1 ) * g( 1 ) * ( H( 0, 0 ) + H( 2, 2 ) ) - 2. * g( 0 ) * g( 2 ) * H( 0, 2 ) +
00057 g( 2 ) * g( 2 ) * ( H( 0, 0 ) + H( 1, 1 ) ) - 2. * g( 0 ) * g( 1 ) * H( 0, 1 )
00058 );
00059
00060
00061
00062 K = min( K, limit_K );
00063 K = max( K, -limit_K );
00064 }
00065
00066 template<typename grid_iterator,typename real_type>
00067 inline void mean_curvature (grid_iterator const & iter, real_type & K)
00068 {
00069 typedef typename grid_iterator::grid_type grid_type;
00070
00071 size_t i = iter.i();
00072 size_t j = iter.j();
00073 size_t k = iter.k();
00074
00075 grid_type const & grid = iter.get_grid();
00076 mean_curvature(grid, i, j, k, K);
00077 }
00078
00079 template<typename grid_iterator>
00080 inline typename grid_iterator::math_types::real_type mean_curvature( grid_iterator const & iter )
00081 {
00082 typedef typename grid_iterator::math_types::real_type real_type;
00083
00084 real_type K;
00085 mean_curvature(iter, K);
00086
00087 return K;
00088 }
00089
00090 }
00091 }
00092
00093
00094 #endif