grid_map.h
Go to the documentation of this file.
1 #ifndef SLAM_CTOR_CORE_GRID_MAP_H
2 #define SLAM_CTOR_CORE_GRID_MAP_H
3 
4 #include <memory>
5 
6 #include "occupancy_map.h"
7 #include "regular_squares_grid.h"
8 #include "grid_cell.h"
9 
10 struct GridMapParams {
13 };
14 
15 struct MapValues {
16  static constexpr int width = 1000;
17  static constexpr int height = 1000;
18  static constexpr double meters_per_cell = 0.1;
19  static constexpr GridMapParams gmp{width, height, meters_per_cell};
20 };
21 
22 class GridMap : public OccupancyMap<RegularSquaresGrid::Coord, double>
23  , public RegularSquaresGrid {
24 public:
25  GridMap(std::shared_ptr<GridCell> prototype,
26  const GridMapParams& params = MapValues::gmp)
27  : RegularSquaresGrid{params.width_cells, params.height_cells,
28  params.meters_per_cell}
29  , _cell_prototype{prototype} {}
30 
31  std::unique_ptr<GridCell> new_cell() const {
32  return _cell_prototype->clone();
33  }
34 
35  /* == OccupancyMap API == */
36 
37  // GridCell access
38  // NB: use update/reset to modify cells instead of operator[]
39  // to prevent proxies usage in descendants that are interested in
40  // modifications.
41  void update(const Coord &area_id,
42  const AreaOccupancyObservation &aoo) override {
43  auto const_this = static_cast<const decltype(this)>(this);
44  auto &area = const_cast<GridCell&>((*const_this)[area_id]);
45  area += aoo;
46  }
47 
48  double occupancy(const Coord &area_id) const override {
49  return (*this)[area_id].occupancy().prob_occ;
50  }
51 
52  /* == Own API == */
53 
54  virtual void reset(const Coord &area_id, const GridCell &new_area) {
55  auto const_this = static_cast<const decltype(this)>(this);
56  auto &area = const_cast<GridCell&>((*const_this)[area_id]);
57  area = new_area;
58  }
59 
60  virtual const GridCell &operator[](const Coord& coord) const = 0;
61 
62  virtual void load_state(const std::vector<char>&) {}
63  virtual std::vector<char> save_state() const {
64  return std::vector<char>();
65  }
66 
67 protected:
68 
69  std::shared_ptr<GridCell> cell_prototype() const { return _cell_prototype; }
70 private: // fields
71  std::shared_ptr<GridCell> _cell_prototype;
72 };
73 
74 #endif
void update(const Coord &area_id, const AreaOccupancyObservation &aoo) override
Updates area with a given observation.
Definition: grid_map.h:41
std::unique_ptr< GridCell > new_cell() const
Definition: grid_map.h:31
static constexpr GridMapParams gmp
Definition: grid_map.h:19
std::shared_ptr< GridCell > cell_prototype() const
Definition: grid_map.h:69
double meters_per_cell
Definition: grid_map.h:12
int height_cells
Definition: grid_map.h:11
A base class for occupancy maps.
Definition: occupancy_map.h:11
virtual std::vector< char > save_state() const
Definition: grid_map.h:63
GridMap(std::shared_ptr< GridCell > prototype, const GridMapParams &params=MapValues::gmp)
Definition: grid_map.h:25
int width_cells
Definition: grid_map.h:11
virtual void load_state(const std::vector< char > &)
Definition: grid_map.h:62
std::shared_ptr< GridCell > _cell_prototype
Definition: grid_map.h:71
double occupancy(const Coord &area_id) const override
Returns known information about the occupancy of a given area.
Definition: grid_map.h:48
virtual void reset(const Coord &area_id, const GridCell &new_area)
Definition: grid_map.h:54


slam_constructor
Author(s): JetBrains Research, OSLL team
autogenerated on Mon Jun 10 2019 15:08:25