Go to the documentation of this file.00001 #ifndef OPENTISSUE_CORE_CONTAINERS_GRID_UTIL_GRID_COORD_TO_IDX_H
00002 #define OPENTISSUE_CORE_CONTAINERS_GRID_UTIL_GRID_COORD_TO_IDX_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 {
00033 template <typename grid_type, typename vector3_type>
00034 inline void coord2idx( grid_type const & grid, vector3_type const & point, size_t & i, size_t & j, size_t & k )
00035 {
00036 using std::floor;
00037
00038 typedef typename vector3_type::value_type real_type;
00039
00040 real_type const & dx = grid.dx();
00041 real_type const & dy = grid.dy();
00042 real_type const & dz = grid.dz();
00043 real_type const & mx = grid.min_coord( 0 );
00044 real_type const & my = grid.min_coord( 1 );
00045 real_type const & mz = grid.min_coord( 2 );
00046
00047 real_type xval = ( point( 0 ) - mx ) / dx;
00048 i = static_cast<size_t>( floor( xval ) );
00049 if ( ( xval - i ) > .5 )
00050 ++i;
00051 real_type yval = ( point( 1 ) - my ) / dy;
00052 j = static_cast<size_t>( floor( yval ) );
00053 if ( ( yval - j ) > .5 )
00054 ++j;
00055 real_type zval = ( point( 2 ) - mz ) / dz;
00056 k = static_cast<size_t>( floor( zval ) );
00057 if ( ( zval - k ) > .5 )
00058 ++k;
00059 }
00060
00061 }
00062 }
00063
00064
00065 #endif