output.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014-2018, the neonavigation authors
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * * Neither the name of the copyright holder nor the names of its
14  * contributors may be used to endorse or promote products derived from
15  * this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27  * POSSIBILITY OF SUCH DAMAGE.
28  */
29 
30 #ifndef COSTMAP_CSPACE_COSTMAP_3D_LAYER_OUTPUT_H
31 #define COSTMAP_CSPACE_COSTMAP_3D_LAYER_OUTPUT_H
32 
33 #include <memory>
34 
35 #include <costmap_cspace_msgs/CSpace3D.h>
36 #include <costmap_cspace_msgs/CSpace3DUpdate.h>
37 #include <geometry_msgs/PolygonStamped.h>
38 #include <nav_msgs/OccupancyGrid.h>
39 
41 
42 namespace costmap_cspace
43 {
45 {
46 public:
47  using Ptr = std::shared_ptr<Costmap3dLayerOutput>;
48  using Callback = boost::function<bool(const CSpace3DMsg::Ptr, const costmap_cspace_msgs::CSpace3DUpdate::Ptr)>;
49 
50 protected:
53 
54 public:
56  {
57  }
59  {
60  cb_ = cb;
61  }
62  void setMapMetaData(const costmap_cspace_msgs::MapMetaData3D& info)
63  {
64  }
65 
66 protected:
67  int getRangeMax() const
68  {
69  return 0;
70  }
71  bool updateChain(const bool output)
72  {
73  auto update_msg = generateUpdateMsg();
74  if (cb_ && output)
75  return cb_(map_, update_msg);
76  return true;
77  }
79  const nav_msgs::OccupancyGrid::ConstPtr& map,
80  const UpdatedRegion& region)
81  {
82  }
83  costmap_cspace_msgs::CSpace3DUpdate::Ptr generateUpdateMsg()
84  {
85  costmap_cspace_msgs::CSpace3DUpdate::Ptr update_msg(new costmap_cspace_msgs::CSpace3DUpdate);
86  update_msg->header = map_->header;
87  map_->header.stamp = region_.stamp_;
88 
89  UpdatedRegion region = region_;
90  region.normalize(map_->info.width, map_->info.height);
91 
92  UpdatedRegion region_merged = region;
93  region_merged.merge(region_prev_);
94  region_prev_ = region;
96 
97  if (region.width_ == 0 || region.height_ == 0)
98  {
99  return nullptr;
100  }
101 
102  update_msg->x = region_merged.x_;
103  update_msg->y = region_merged.y_;
104  update_msg->width = region_merged.width_;
105  update_msg->height = region_merged.height_;
106  update_msg->yaw = region_merged.yaw_;
107  update_msg->angle = region_merged.angle_;
108  update_msg->data.resize(update_msg->width * update_msg->height * update_msg->angle);
109  if ((update_msg->x == 0) && (update_msg->y == 0) && (update_msg->yaw == 0) &&
110  (update_msg->width == map_->info.width) && (update_msg->height == map_->info.height) &&
111  (update_msg->angle == map_->info.angle))
112  {
113  CSpace3DMsg::copyCells(*update_msg, 0, 0, 0, *map_, 0, 0, 0, update_msg->data.size());
114  return update_msg;
115  }
116  for (unsigned int k = 0; k < update_msg->angle; ++k)
117  {
118  for (unsigned int j = 0; j < update_msg->height; ++j)
119  {
120  CSpace3DMsg::copyCells(*update_msg, 0, j, k,
121  *map_, update_msg->x, update_msg->y + j, update_msg->yaw + k, update_msg->width);
122  }
123  }
124  return update_msg;
125  }
126 };
127 } // namespace costmap_cspace
128 
129 #endif // COSTMAP_CSPACE_COSTMAP_3D_LAYER_OUTPUT_H
void normalize(const int full_width, const int full_height)
Definition: base.h:178
boost::function< bool(const CSpace3DMsg::Ptr, const costmap_cspace_msgs::CSpace3DUpdate::Ptr)> Callback
Definition: output.h:48
void merge(const UpdatedRegion &region)
Definition: base.h:132
costmap_cspace_msgs::CSpace3DUpdate::Ptr generateUpdateMsg()
Definition: output.h:83
void loadConfig(XmlRpc::XmlRpcValue config)
Definition: output.h:55
static void copyCells(CSpace3DMsg &to, const int &to_x, const int &to_y, const int &to_yaw, const CSpace3DMsg &from, const int &from_x, const int &from_y, const int &from_yaw, const int &copy_cell_num)
Definition: base.h:80
void setMapMetaData(const costmap_cspace_msgs::MapMetaData3D &info)
Definition: output.h:62
std::shared_ptr< Costmap3dLayerBase > Ptr
Definition: base.h:255
void updateCSpace(const nav_msgs::OccupancyGrid::ConstPtr &map, const UpdatedRegion &region)
Definition: output.h:78
void setHandler(Callback cb)
Definition: output.h:58
bool updateChain(const bool output)
Definition: output.h:71


costmap_cspace
Author(s): Atsushi Watanabe
autogenerated on Wed May 12 2021 02:20:29