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_NAV_GRID_MESSAGE_UTILS_H
00036 #define NAV_GRID_PUB_SUB_NAV_GRID_MESSAGE_UTILS_H
00037 
00038 #include <nav_2d_utils/conversions.h>
00039 #include <nav_2d_msgs/NavGridOfChars.h>
00040 #include <nav_2d_msgs/NavGridOfCharsUpdate.h>
00041 #include <nav_2d_msgs/NavGridOfDoubles.h>
00042 #include <nav_2d_msgs/NavGridOfDoublesUpdate.h>
00043 #include <nav_grid_iterators/whole_grid.h>
00044 #include <nav_grid_iterators/sub_grid.h>
00045 #include <nav_core2/bounds.h>
00046 
00047 namespace nav_grid_pub_sub
00048 {
00058 template<typename ROSMsgType, typename NumericType>
00059 ROSMsgType toMsg(const nav_grid::NavGrid<NumericType>& grid, const ros::Time& stamp)
00060 {
00061   const nav_grid::NavGridInfo& info = grid.getInfo();
00062 
00063   ROSMsgType msg;
00064   msg.stamp = stamp;
00065   msg.info = nav_2d_utils::toMsg(info);
00066   msg.data.resize(info.width * info.height);
00067 
00068   unsigned int data_index = 0;
00069   for (const nav_grid::Index& index : nav_grid_iterators::WholeGrid(info))
00070   {
00071     msg.data[data_index++] = grid(index);
00072   }
00073   return msg;
00074 }
00075 
00081 template<typename ROSMsgType, typename NumericType>
00082 ROSMsgType toUpdate(const nav_grid::NavGrid<NumericType>& grid, const nav_core2::UIntBounds& bounds,
00083                     const ros::Time& stamp)
00084 {
00085   ROSMsgType update;
00086   update.stamp = stamp;
00087   update.bounds = nav_2d_utils::toMsg(bounds);
00088   update.data.resize(bounds.getWidth() * bounds.getHeight());
00089 
00090   unsigned int data_index = 0;
00091   const nav_grid::NavGridInfo& info = grid.getInfo();
00092   for (const nav_grid::Index& index : nav_grid_iterators::SubGrid(&info, bounds))
00093   {
00094     update.data[data_index++] = grid(index);
00095   }
00096   return update;
00097 }
00098 
00102 inline nav_2d_msgs::NavGridOfChars toMsg(const nav_grid::NavGrid<unsigned char>& grid,
00103                                          const ros::Time& stamp = ros::Time(0))
00104 {
00105   return toMsg<nav_2d_msgs::NavGridOfChars>(grid, stamp);
00106 }
00107 
00111 inline nav_2d_msgs::NavGridOfDoubles toMsg(const nav_grid::NavGrid<double>& grid, const ros::Time& stamp = ros::Time(0))
00112 {
00113   return toMsg<nav_2d_msgs::NavGridOfDoubles>(grid, stamp);
00114 }
00115 
00119 inline nav_2d_msgs::NavGridOfDoubles toMsg(const nav_grid::NavGrid<float>& grid, const ros::Time& stamp = ros::Time(0))
00120 {
00121   return toMsg<nav_2d_msgs::NavGridOfDoubles>(grid, stamp);
00122 }
00123 
00127 inline nav_2d_msgs::NavGridOfCharsUpdate toUpdate(const nav_grid::NavGrid<unsigned char>& grid,
00128         const nav_core2::UIntBounds& bounds, const ros::Time& stamp = ros::Time(0))
00129 {
00130   return toUpdate<nav_2d_msgs::NavGridOfCharsUpdate>(grid, bounds, stamp);
00131 }
00132 
00136 inline nav_2d_msgs::NavGridOfDoublesUpdate toUpdate(const nav_grid::NavGrid<double>& grid,
00137         const nav_core2::UIntBounds& bounds, const ros::Time& stamp = ros::Time(0))
00138 {
00139   return toUpdate<nav_2d_msgs::NavGridOfDoublesUpdate>(grid, bounds, stamp);
00140 }
00141 
00145 inline nav_2d_msgs::NavGridOfDoublesUpdate toUpdate(const nav_grid::NavGrid<float>& grid,
00146         const nav_core2::UIntBounds& bounds, const ros::Time& stamp = ros::Time(0))
00147 {
00148   return toUpdate<nav_2d_msgs::NavGridOfDoublesUpdate>(grid, bounds, stamp);
00149 }
00150 
00151 
00152 }  
00153 
00154 #endif  // NAV_GRID_PUB_SUB_NAV_GRID_MESSAGE_UTILS_H