ray_caster_utils.h
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 /* Return the row number from offset for a row-major array
00011  */
00012 inline size_t rowFromOffset(const size_t offset, const size_t ncol)
00013 {
00014   return offset / ncol;
00015 }
00016 
00017 /* Return the column number from offset for a row-major array
00018  */
00019 inline size_t colFromOffset(const size_t offset, const size_t ncol)
00020 {
00021   return offset % ncol;
00022 }
00023 
00024 /* Return the offset from row and column number for a row-major array
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 /* Return true if the point lies in the map
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 /* Return the world coordinates of the map point at given index
00039  *
00040  * The map center is (0, 0).
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 } // namespace map_ray_caster
00055 
00056 #endif // MAP_RAY_CASTER_RAY_CASTER_UTILS_H


map_ray_caster
Author(s): Gaƫl Ecorchard
autogenerated on Thu Jun 6 2019 22:02:02