Go to the documentation of this file.00001 #ifndef OPENTISSUE_CORE_CONTAINERS_GRID_UTIL_GRID_ENCLOSING_INDICES_H
00002 #define OPENTISSUE_CORE_CONTAINERS_GRID_UTIL_GRID_ENCLOSING_INDICES_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 {
00032 template <typename grid_type, typename vector3_type>
00033 inline void enclosing_indices(
00034 grid_type const & grid
00035 , vector3_type const & point
00036 , size_t& i0
00037 , size_t& j0
00038 , size_t& k0
00039 , size_t& i1
00040 , size_t& j1
00041 , size_t& k1
00042 )
00043 {
00044 using std::max;
00045 using std::min;
00046 using std::floor;
00047
00048 typedef typename vector3_type::value_type real_type;
00049
00050 real_type const & dx = grid.dx();
00051 real_type const & dy = grid.dy();
00052 real_type const & dz = grid.dz();
00053 size_t const & I = grid.I();
00054 size_t const & J = grid.J();
00055 size_t const & K = grid.K();
00056
00057 vector3_type range = grid.max_coord() - grid.min_coord();
00058 vector3_type diff = point - grid.min_coord();
00059
00060 diff = min( max(diff, vector3_type( real_type() ) ) , range);
00061
00062 diff(0) /= dx;
00063 diff(1) /= dy;
00064 diff(2) /= dz;
00065
00066 i0 = static_cast<size_t>( floor( diff(0) ) );
00067 j0 = static_cast<size_t>( floor( diff(1) ) );
00068 k0 = static_cast<size_t>( floor( diff(2) ) );
00069 i1 = ( i0 + 1 ) % I;
00070 j1 = ( j0 + 1 ) % J;
00071 k1 = ( k0 + 1 ) % K;
00072
00073 }
00074
00075 }
00076 }
00077
00078
00079 #endif