Go to the documentation of this file.00001 #ifndef OPENTISSUE_CORE_CONTAINERS_GRID_UTIL_RESAMPLE_H
00002 #define OPENTISSUE_CORE_CONTAINERS_GRID_UTIL_RESAMPLE_H
00003
00004
00005
00006
00007
00008
00009
00010 #include <OpenTissue/configuration.h>
00011
00012 #include <cmath>
00013
00014 #include <OpenTissue/core/containers/grid/util/grid_value_at_point.h>
00015 #include <OpenTissue/core/containers/grid/util/grid_idx2coord.h>
00016
00017 namespace OpenTissue
00018 {
00019 namespace grid
00020 {
00030 template <typename grid_type, typename real_type>
00031 inline void resample(grid_type const & M, grid_type & m, real_type factor_i, real_type factor_j, real_type factor_k)
00032 {
00033 using std::floor;
00034
00035 assert(factor_i > 0 || !"resample(): i scale factor must be positive");
00036 assert(factor_j > 0 || !"resample(): j scale factor must be positive");
00037 assert(factor_k > 0 || !"resample(): k scale factor must be positive");
00038
00039 typedef typename grid_type::math_types math_types;
00040 typedef typename math_types::vector3_type vector3_type;
00041 typedef typename grid_type::index_iterator index_iterator;
00042
00043
00044
00045
00046
00047 m.create(
00048 M.min_coord(), M.max_coord()
00049 , static_cast<size_t>( floor(M.I()/factor_i) )
00050 , static_cast<size_t>( floor(M.J()/factor_j) )
00051 , static_cast<size_t>( floor(M.K()/factor_k) )
00052 );
00053
00054 vector3_type point;
00055 for( index_iterator iter = m.begin(); iter != m.end(); ++iter )
00056 {
00057 idx2coord( iter,point );
00058 (*iter) = value_at_point( M, point );
00059 }
00060 }
00061
00062 }
00063 }
00064
00065
00066 #endif