Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #ifndef NAV_GRID_PUB_SUB_COST_INTERPRETATION_H
00036 #define NAV_GRID_PUB_SUB_COST_INTERPRETATION_H
00037
00038 #include <nav_grid/nav_grid.h>
00039 #include <nav_grid_iterators/whole_grid.h>
00040 #include <vector>
00041
00042 namespace nav_grid_pub_sub
00043 {
00047 inline unsigned char interpretCost(unsigned char original_value,
00048 const std::vector<unsigned char>& cost_interpretation_table)
00049 {
00050 if (original_value < cost_interpretation_table.size())
00051 {
00052 return cost_interpretation_table[original_value];
00053 }
00054 else
00055 {
00056 return original_value;
00057 }
00058 }
00059
00063 inline void applyInterpretation(nav_grid::NavGrid<unsigned char>& grid,
00064 const std::vector<unsigned char>& cost_interpretation_table)
00065 {
00066 for (const nav_grid::Index& index : nav_grid_iterators::WholeGrid(grid.getInfo()))
00067 {
00068 grid.setValue(index, interpretCost(grid(index), cost_interpretation_table));
00069 }
00070 }
00071
00082 template<typename NumericType>
00083 inline unsigned char interpretValue(const NumericType value, const NumericType min_value,
00084 const NumericType denominator, const NumericType unknown_value)
00085 {
00086 if (value == unknown_value)
00087 {
00088 return -1;
00089 }
00090 else
00091 {
00092 double ratio = (value - min_value) / denominator;
00093 return static_cast<unsigned char>(ratio * 100.0);
00094 }
00095 }
00096
00097 }
00098
00099 #endif // NAV_GRID_PUB_SUB_COST_INTERPRETATION_H