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 COSTMAP_QUEUE_COSTMAP_QUEUE_H
00036 #define COSTMAP_QUEUE_COSTMAP_QUEUE_H
00037
00038 #include <nav_core2/costmap.h>
00039 #include <costmap_queue/map_based_queue.h>
00040 #include <nav_grid/vector_nav_grid.h>
00041 #include <algorithm>
00042 #include <limits>
00043 #include <vector>
00044
00045 namespace costmap_queue
00046 {
00051 class CellData
00052 {
00053 public:
00062 CellData(const double d, const unsigned int x, const unsigned int y, const unsigned int sx, const unsigned int sy) :
00063 distance_(d), x_(x), y_(y), src_x_(sx), src_y_(sy)
00064 {
00065 }
00066
00070 CellData() :
00071 distance_(std::numeric_limits<double>::max()), x_(0), y_(0), src_x_(0), src_y_(0)
00072 {
00073 }
00074
00075 double distance_;
00076 unsigned int x_, y_;
00077 unsigned int src_x_, src_y_;
00078 };
00079
00099 class CostmapQueue : public MapBasedQueue<CellData>
00100 {
00101 public:
00107 explicit CostmapQueue(nav_core2::Costmap& costmap, bool manhattan = false);
00108
00112 void reset() override;
00113
00119 void enqueueCell(unsigned int x, unsigned int y);
00120
00127 CellData getNextCell();
00128
00132 virtual int getMaxDistance() const { return std::max(costmap_.getWidth(), costmap_.getHeight()); }
00133
00139 virtual bool validCellToQueue(const CellData& cell) { return true; }
00140
00144 using Ptr = std::shared_ptr<CostmapQueue>;
00145 protected:
00149 void enqueueCell(unsigned int cur_x, unsigned int cur_y, unsigned int src_x, unsigned int src_y);
00150
00154 void computeCache();
00155
00156 nav_core2::Costmap& costmap_;
00157
00158
00159
00160 nav_grid::VectorNavGrid<unsigned char> seen_;
00161 bool manhattan_;
00162 protected:
00177 inline double distanceLookup(const unsigned int cur_x, const unsigned int cur_y,
00178 const unsigned int src_x, const unsigned int src_y)
00179 {
00180 unsigned int dx = std::abs(static_cast<int>(cur_x) - static_cast<int>(src_x));
00181 unsigned int dy = std::abs(static_cast<int>(cur_y) - static_cast<int>(src_y));
00182 return cached_distances_[dx][dy];
00183 }
00184 std::vector<std::vector<double> > cached_distances_;
00185 int cached_max_distance_;
00186 };
00187 }
00188
00189 #endif // COSTMAP_QUEUE_COSTMAP_QUEUE_H