1 #ifndef COSTMAP_TOOLS_H_ 2 #define COSTMAP_TOOLS_H_ 5 #include <geometry_msgs/PointStamped.h> 6 #include <geometry_msgs/PolygonStamped.h> 18 std::vector<unsigned int>
nhood4(
unsigned int idx,
22 std::vector<unsigned int> out;
27 if (idx > size_x_ * size_y_ - 1) {
28 ROS_WARN(
"Evaluating nhood for offmap point");
32 if (idx % size_x_ > 0) {
33 out.push_back(idx - 1);
35 if (idx % size_x_ < size_x_ - 1) {
36 out.push_back(idx + 1);
39 out.push_back(idx - size_x_);
41 if (idx < size_x_ * (size_y_ - 1)) {
42 out.push_back(idx + size_x_);
54 std::vector<unsigned int>
nhood8(
unsigned int idx,
58 std::vector<unsigned int> out =
nhood4(idx, costmap);
63 if (idx > size_x_ * size_y_ - 1) {
67 if (idx % size_x_ > 0 && idx >= size_x_) {
68 out.push_back(idx - 1 - size_x_);
70 if (idx % size_x_ > 0 && idx < size_x_ * (size_y_ - 1)) {
71 out.push_back(idx - 1 + size_x_);
73 if (idx % size_x_ < size_x_ - 1 && idx >= size_x_) {
74 out.push_back(idx + 1 - size_x_);
76 if (idx % size_x_ < size_x_ - 1 && idx < size_x_ * (size_y_ - 1)) {
77 out.push_back(idx + 1 + size_x_);
91 bool nearestCell(
unsigned int& result,
unsigned int start,
unsigned char val,
94 const unsigned char* map = costmap.
getCharMap();
98 if (start >= size_x * size_y) {
103 std::queue<unsigned int> bfs;
104 std::vector<bool> visited_flag(size_x * size_y,
false);
108 visited_flag[start] =
true;
111 while (!bfs.empty()) {
112 unsigned int idx = bfs.front();
116 if (map[idx] == val) {
122 for (
unsigned nbr :
nhood8(idx, costmap)) {
123 if (!visited_flag[nbr]) {
125 visited_flag[nbr] =
true;
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.
bool nearestCell(unsigned int &result, unsigned int start, unsigned char val, const costmap_2d::Costmap2D &costmap)
Find nearest cell of a specified value.
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.
unsigned int getSizeInCellsY() const
unsigned int getSizeInCellsX() const