Go to the documentation of this file.00001 #ifndef OPENTISSUE_CORE_CONTAINERS_GRID_UTIL_GRID_VALUE_AT_POINT_H
00002 #define OPENTISSUE_CORE_CONTAINERS_GRID_UTIL_GRID_VALUE_AT_POINT_H
00003
00004
00005
00006
00007
00008
00009
00010 #include <OpenTissue/configuration.h>
00011
00012 #include <OpenTissue/core/math/math_trillinear.h>
00013 #include <OpenTissue/core/containers/grid/util/grid_enclosing_indices.h>
00014
00015 namespace OpenTissue
00016 {
00017 namespace grid
00018 {
00025 template<typename grid_type,typename vector3_type>
00026 inline typename grid_type::value_type value_at_point(grid_type const & grid, vector3_type const & point )
00027 {
00028 typedef typename grid_type::value_type value_type;
00029 typedef typename vector3_type::value_type real_type;
00030
00031
00032 const static value_type unused = grid.unused();
00033 const static value_type zero = value_type();
00034
00035 size_t i0, j0, k0, i1, j1, k1;
00036 enclosing_indices( grid, point, i0, j0, k0, i1, j1, k1 );
00037
00038 value_type d000 = grid( i0, j0, k0 );
00039 value_type d001 = grid( i1, j0, k0 );
00040 value_type d010 = grid( i0, j1, k0 );
00041 value_type d011 = grid( i1, j1, k0 );
00042 value_type d100 = grid( i0, j0, k1 );
00043 value_type d101 = grid( i1, j0, k1 );
00044 value_type d110 = grid( i0, j1, k1 );
00045 value_type d111 = grid( i1, j1, k1 );
00046
00047 size_t cnt_unused = 0;
00048
00049 #define MAGIC(val) \
00050 if ( (val) == unused) { \
00051 (val) = zero; \
00052 ++cnt_unused; \
00053 }
00054 MAGIC( d000 );
00055 MAGIC( d001 );
00056 MAGIC( d010 );
00057 MAGIC( d011 );
00058 MAGIC( d100 );
00059 MAGIC( d101 );
00060 MAGIC( d110 );
00061 MAGIC( d111 );
00062 #undef MAGIC
00063
00064 if ( cnt_unused == 8 )
00065 return unused;
00066
00067 real_type s = ( point(0) - ( i0*grid.dx() + grid.min_coord(0) ) ) / grid.dx();
00068 real_type t = ( point(1) - ( j0*grid.dy() + grid.min_coord(1) ) ) / grid.dy();
00069 real_type u = ( point(2) - ( k0*grid.dz() + grid.min_coord(2) ) ) / grid.dz();
00070 return OpenTissue::math::trillinear( d000, d001, d010, d011, d100, d101, d110, d111, s, t, u );
00071 }
00072
00073 }
00074 }
00075
00076
00077 #endif