Go to the documentation of this file.00001 #ifndef OPENTISSUE_CORE_CONTAINERS_GRID_UTIL_GRID_RESCALE_RANGE_H
00002 #define OPENTISSUE_CORE_CONTAINERS_GRID_UTIL_GRID_RESCALE_RANGE_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 {
00018
00028 template <typename grid_type>
00029 inline void rescale_range(
00030 grid_type & grid
00031 , typename grid_type::value_type src_min
00032 , typename grid_type::value_type src_max
00033 , typename grid_type::value_type dst_min
00034 , typename grid_type::value_type dst_max
00035 )
00036 {
00037
00038 typedef typename grid_type::value_type value_type;
00039
00040 std::cout << "-- Normalizing from range [" << src_min << ", " << src_max
00041 << "] to range [" << dst_min << ", " << dst_max << "]" << std::endl;
00042 float src_scale = 1.0f / ( src_max - src_min );
00043 float val;
00044
00045 value_type * t = grid.data();
00046 for ( size_t i = 0; i < grid.size(); ++i, ++t )
00047 {
00048 val = static_cast<float>(*t);
00049 val = (val<src_min) ? src_min : ( (val>src_max) ? src_max : val );
00050 val = src_scale * ( val - src_min );
00051 val = dst_min + val*( dst_max - dst_min );
00052 *t = static_cast<value_type>(val);
00053 }
00054 }
00055
00056 }
00057 }
00058
00059
00060 #endif