Go to the documentation of this file.00001 #ifndef OPENTISSUE_CORE_CONTAINERS_GRID_UTIL_GRID_COMPUTE_SIGN_FUNCTION_H
00002 #define OPENTISSUE_CORE_CONTAINERS_GRID_UTIL_GRID_COMPUTE_SIGN_FUNCTION_H
00003
00004
00005
00006
00007
00008
00009
00010 #include <OpenTissue/configuration.h>
00011
00012 #include <cmath>
00013
00014 namespace OpenTissue
00015 {
00016 namespace grid
00017 {
00018
00019 template < typename grid_type >
00020 inline void compute_sign_function( grid_type const & phi, grid_type & S0 )
00021 {
00022 using std::sqrt;
00023
00024 typedef typename grid_type::value_type real_type;
00025 typedef typename grid_type::const_index_iterator const_iterator;
00026 typedef typename grid_type::index_iterator iterator;
00027
00028 S0.create(phi.min_coord(),phi.max_coord(),phi.I(),phi.J(),phi.K());
00029
00030
00031 real_type delta = phi.dx()*phi.dx() + phi.dy()*phi.dy() + phi.dz()*phi.dz();
00032 const_iterator begin = phi.begin();
00033 const_iterator end = phi.end();
00034
00035 for ( const_iterator idx = begin;idx!=end;++idx)
00036 {
00037 size_t i = idx.i();
00038 size_t j = idx.j();
00039 size_t k = idx.k();
00040 real_type c = phi( i,j,k );
00041 S0( i,j,k ) = c / ( sqrt( c * c + delta ) );
00042 }
00043 }
00044
00045 }
00046 }
00047
00048
00049 #endif