Go to the documentation of this file.00001 #ifndef MAP_RAY_CASTER_RAY_CASTER_UTILS_H
00002 #define MAP_RAY_CASTER_RAY_CASTER_UTILS_H
00003
00004 #include <cstddef>
00005
00006 #include <nav_msgs/OccupancyGrid.h>
00007
00008 namespace map_ray_caster {
00009
00010
00011
00012 inline size_t rowFromOffset(const size_t offset, const size_t ncol)
00013 {
00014 return offset / ncol;
00015 }
00016
00017
00018
00019 inline size_t colFromOffset(const size_t offset, const size_t ncol)
00020 {
00021 return offset % ncol;
00022 }
00023
00024
00025
00026 inline size_t offsetFromRowCol(const size_t row, const size_t col, const size_t ncol)
00027 {
00028 return (row * ncol) + col;
00029 }
00030
00031
00032
00033 inline bool pointInMap(const int row, const int col, const size_t nrow, const size_t ncol)
00034 {
00035 return ((0 <= col) && ((size_t) col < ncol) && (0 <= row) && ((size_t) row < nrow));
00036 }
00037
00038
00039
00040
00041
00042 inline void indexToReal(const nav_msgs::OccupancyGrid& map, const size_t index, geometry_msgs::Point32& point)
00043 {
00044 const double xcenter = (map.info.width / 2) * map.info.resolution;
00045 const double ycenter = (map.info.height / 2) * map.info.resolution;
00046 const size_t row = rowFromOffset(index, map.info.height);
00047 const size_t col = colFromOffset(index, map.info.width);
00048 const double xindex = col * map.info.resolution;
00049 const double yindex = row * map.info.resolution;
00050 point.x = xindex - xcenter;
00051 point.y = yindex - ycenter;
00052 }
00053
00054 }
00055
00056 #endif // MAP_RAY_CASTER_RAY_CASTER_UTILS_H