Go to the documentation of this file.00001 #ifndef OPENTISSUE_CORE_CONTAINERS_GRID_UTIL_GRID_IDX_TO_COORD_H
00002 #define OPENTISSUE_CORE_CONTAINERS_GRID_UTIL_GRID_IDX_TO_COORD_H
00003
00004
00005
00006
00007
00008
00009
00010 #include <OpenTissue/configuration.h>
00011
00012 #include <cassert>
00013
00014 namespace OpenTissue
00015 {
00016 namespace grid
00017 {
00028 template <typename grid_type, typename vector3_type>
00029 inline void idx2coord( grid_type const & grid, size_t i, size_t j, size_t k, vector3_type & point )
00030 {
00031 typedef typename vector3_type::value_type real_type;
00032 assert(i<grid.I() || !"idx2coord(): i'th index was too big");
00033 assert(j<grid.J() || !"idx2coord(): j'th index was too big");
00034 assert(k<grid.K() || !"idx2coord(): k'th index was too big");
00035
00036 real_type const & dx = grid.dx();
00037 real_type const & dy = grid.dy();
00038 real_type const & dz = grid.dz();
00039 real_type const & mx = grid.min_coord( 0 );
00040 real_type const & my = grid.min_coord( 1 );
00041 real_type const & mz = grid.min_coord( 2 );
00042
00043 point(0) = i * dx + mx;
00044 point(1) = j * dy + my;
00045 point(2) = k * dz + mz;
00046 }
00047
00055 template<typename grid_iterator,typename vector3_type>
00056 inline void idx2coord (grid_iterator const & iter, vector3_type & point )
00057 {
00058 typedef typename grid_iterator::grid_type grid_type;
00059
00060 size_t i = iter.i();
00061 size_t j = iter.j();
00062 size_t k = iter.k();
00063
00064 grid_type const & grid = iter.get_grid();
00065
00066 idx2coord(grid, i, j, k, point);
00067 }
00068
00076 template<typename grid_iterator>
00077 inline typename grid_iterator::math_types::vector3_type idx2coord (grid_iterator const & iter )
00078 {
00079 typedef typename grid_iterator::math_types::vector3_type vector3_type;
00080
00081 vector3_type point;
00082
00083 idx2coord(iter, point);
00084
00085 return point;
00086 }
00087
00088 }
00089 }
00090
00091
00092 #endif