nav_grid_message_utils.h
Go to the documentation of this file.
00001 /*
00002  * Software License Agreement (BSD License)
00003  *
00004  *  Copyright (c) 2018, Locus Robotics
00005  *  All rights reserved.
00006  *
00007  *  Redistribution and use in source and binary forms, with or without
00008  *  modification, are permitted provided that the following conditions
00009  *  are met:
00010  *
00011  *   * Redistributions of source code must retain the above copyright
00012  *     notice, this list of conditions and the following disclaimer.
00013  *   * Redistributions in binary form must reproduce the above
00014  *     copyright notice, this list of conditions and the following
00015  *     disclaimer in the documentation and/or other materials provided
00016  *     with the distribution.
00017  *   * Neither the name of the copyright holder nor the names of its
00018  *     contributors may be used to endorse or promote products derived
00019  *     from this software without specific prior written permission.
00020  *
00021  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00022  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00023  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00024  *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00025  *  COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00026  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00027  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00028  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00029  *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00030  *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00031  *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00032  *  POSSIBILITY OF SUCH DAMAGE.
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 }  // namespace nav_grid_pub_sub
00153 
00154 #endif  // NAV_GRID_PUB_SUB_NAV_GRID_MESSAGE_UTILS_H


nav_grid_pub_sub
Author(s):
autogenerated on Wed Jun 26 2019 20:09:52