costmap_tools.h
Go to the documentation of this file.
1 #ifndef COSTMAP_TOOLS_H_
2 #define COSTMAP_TOOLS_H_
3 
4 #include <geometry_msgs/PolygonStamped.h>
5 #include <geometry_msgs/PointStamped.h>
7 #include <boost/foreach.hpp>
8 #include <ros/ros.h>
9 
10 namespace frontier_exploration{
11 
18 std::vector<unsigned int> nhood4(unsigned int idx, const costmap_2d::Costmap2D& costmap){
19  //get 4-connected neighbourhood indexes, check for edge of map
20  std::vector<unsigned int> out;
21 
22  unsigned int size_x_ = costmap.getSizeInCellsX(), size_y_ = costmap.getSizeInCellsY();
23 
24  if (idx > size_x_ * size_y_ -1){
25  ROS_WARN("Evaluating nhood for offmap point");
26  return out;
27  }
28 
29  if(idx % size_x_ > 0){
30  out.push_back(idx - 1);
31  }
32  if(idx % size_x_ < size_x_ - 1){
33  out.push_back(idx + 1);
34  }
35  if(idx >= size_x_){
36  out.push_back(idx - size_x_);
37  }
38  if(idx < size_x_*(size_y_-1)){
39  out.push_back(idx + size_x_);
40  }
41  return out;
42 
43 }
44 
51 std::vector<unsigned int> nhood8(unsigned int idx, const costmap_2d::Costmap2D& costmap){
52  //get 8-connected neighbourhood indexes, check for edge of map
53  std::vector<unsigned int> out = nhood4(idx, costmap);
54 
55  unsigned int size_x_ = costmap.getSizeInCellsX(), size_y_ = costmap.getSizeInCellsY();
56 
57  if (idx > size_x_ * size_y_ -1){
58  return out;
59  }
60 
61  if(idx % size_x_ > 0 && idx >= size_x_){
62  out.push_back(idx - 1 - size_x_);
63  }
64  if(idx % size_x_ > 0 && idx < size_x_*(size_y_-1)){
65  out.push_back(idx - 1 + size_x_);
66  }
67  if(idx % size_x_ < size_x_ - 1 && idx >= size_x_){
68  out.push_back(idx + 1 - size_x_);
69  }
70  if(idx % size_x_ < size_x_ - 1 && idx < size_x_*(size_y_-1)){
71  out.push_back(idx + 1 + size_x_);
72  }
73 
74  return out;
75 
76 }
77 
86 bool nearestCell(unsigned int &result, unsigned int start, unsigned char val, const costmap_2d::Costmap2D& costmap){
87 
88  const unsigned char* map = costmap.getCharMap();
89  const unsigned int size_x = costmap.getSizeInCellsX(), size_y = costmap.getSizeInCellsY();
90 
91  if(start >= size_x * size_y){
92  return false;
93  }
94 
95  //initialize breadth first search
96  std::queue<unsigned int> bfs;
97  std::vector<bool> visited_flag(size_x * size_y, false);
98 
99  //push initial cell
100  bfs.push(start);
101  visited_flag[start] = true;
102 
103  //search for neighbouring cell matching value
104  while(!bfs.empty()){
105  unsigned int idx = bfs.front();
106  bfs.pop();
107 
108  //return if cell of correct value is found
109  if(map[idx] == val){
110  result = idx;
111  return true;
112  }
113 
114  //iterate over all adjacent unvisited cells
115  BOOST_FOREACH(unsigned nbr, nhood8(idx, costmap)){
116  if(!visited_flag[nbr]){
117  bfs.push(nbr);
118  visited_flag[nbr] = true;
119  }
120  }
121  }
122 
123  return false;
124 }
125 
126 }
127 #endif
std::vector< unsigned int > nhood4(unsigned int idx, const costmap_2d::Costmap2D &costmap)
Determine 4-connected neighbourhood of an input cell, checking for map edges.
Definition: costmap_tools.h:18
#define ROS_WARN(...)
bool nearestCell(unsigned int &result, unsigned int start, unsigned char val, const costmap_2d::Costmap2D &costmap)
Find nearest cell of a specified value.
Definition: costmap_tools.h:86
unsigned char * getCharMap() const
std::vector< unsigned int > nhood8(unsigned int idx, const costmap_2d::Costmap2D &costmap)
Determine 8-connected neighbourhood of an input cell, checking for map edges.
Definition: costmap_tools.h:51
unsigned int getSizeInCellsY() const
unsigned int getSizeInCellsX() const


frontier_exploration
Author(s): Paul Bovbel
autogenerated on Mon Jun 10 2019 13:25:00