1 #ifndef SLAM_CTOR_CORE_PLAIN_GRID_MAP_H_INCLUDED 2 #define SLAM_CTOR_CORE_PLAIN_GRID_MAP_H_INCLUDED 21 row.push_back(prototype->clone());
38 std::vector<std::vector<std::unique_ptr<GridCell>>>
_cells;
45 static constexpr
double Expansion_Rate = 1.2;
54 ensure_inside(area_id);
59 ensure_inside(area_id);
75 size_t map_size_bytes =
w * h * _unknown_cell->serialize().size();
82 for (
auto &cell : row) {
83 ms.
append(cell->serialize());
86 #ifdef COMPRESSED_SERIALIZATION 94 void load_state(
const std::vector<char>& data)
override {
99 d >> h >>
w >>
s >> _origin.x >> _origin.y;
104 #ifdef COMPRESSED_SERIALIZATION 105 std::vector<char> map_data = Deserializer::decompress(
106 data.data() + d.
pos(), data.size() - d.
pos(),
107 w * h * _unknown_cell->serialize().size());
110 const std::vector<char> &map_data = data;
111 size_t pos = d.
pos();
115 for (
auto &row :
_cells) {
117 for (
int i = 0; i <
w; ++i) {
119 pos = cell->deserialize(map_data, pos);
120 row.push_back(std::move(cell));
132 unsigned prep_x = 0, app_x = 0, prep_y = 0, app_y = 0;
133 std::tie(prep_x, app_x) = determine_cells_nm(0, coord.x, w);
134 std::tie(prep_y, app_y) = determine_cells_nm(0, coord.y, h);
136 unsigned new_w = prep_x + w + app_x, new_h = prep_y + h + app_y;
137 #define UPDATE_DIM(dim, elem) \ 138 if (dim < new_##dim && new_##dim < Expansion_Rate * dim) { \ 139 double scale = prep_##elem / (new_##dim - dim); \ 140 prep_##elem += (Expansion_Rate * dim - new_##dim) * scale; \ 141 new_##dim = Expansion_Rate * dim; \ 142 app_##elem = new_##dim - (prep_##elem + dim); \ 150 std::vector<std::vector<std::unique_ptr<GridCell>>> new_cells{new_h};
151 for (
size_t y = 0;
y != new_h; ++
y) {
152 std::generate_n(std::back_inserter(new_cells[
y]), new_w,
153 [
this](){
return this->_unknown_cell->clone(); });
154 if (y < prep_y || prep_y + h <= y) {
continue; }
156 std::move(
_cells[y - prep_y].begin(),
_cells[y - prep_y].end(),
157 &new_cells[y][prep_x]);
160 std::swap(
_cells, new_cells);
163 _origin +=
Coord(prep_x, prep_y);
170 int min,
int val,
int max)
const {
172 unsigned prepend_nm = 0, append_nm = 0;
174 prepend_nm = min - val;
175 }
else if (max <= val) {
176 append_nm = val - max + 1;
178 return std::make_tuple(prepend_nm, append_nm);
void update(const Coord &area_id, const AreaOccupancyObservation &aoo) override
Updates area with a given observation.
Coord external2internal(const Coord &coord) const
bool ensure_inside(const Coord &c)
std::unique_ptr< GridCell > new_cell() const
const GridCell & operator[](const Coord &c) const override
PlainGridMap(std::shared_ptr< GridCell > prototype, const GridMapParams ¶ms=MapValues::gmp)
static constexpr GridMapParams gmp
Coord origin() const override
void update(const Coord &area_id, const AreaOccupancyObservation &aoo) override
Updates area with a given observation.
virtual bool has_cell(const Coord &c) const
std::tuple< unsigned, unsigned > determine_cells_nm(int min, int val, int max) const
void set_width(unsigned w)
TFSIMD_FORCE_INLINE const tfScalar & y() const
std::vector< std::vector< std::unique_ptr< GridCell > > > _cells
virtual DiscretePoint2D origin() const
bool has_internal_cell(const Coord &c) const
void append(const std::vector< char > &new_data)
#define UPDATE_DIM(dim, elem)
void set_height(unsigned h)
const GridCell & cell_internal(const Coord &ic) const
TFSIMD_FORCE_INLINE const tfScalar & x() const
bool has_cell(const Coord &) const override
std::vector< char > save_state() const override
UnboundedPlainGridMap(std::shared_ptr< GridCell > prototype, const GridMapParams ¶ms=MapValues::gmp)
TFSIMD_FORCE_INLINE const tfScalar & w() const
virtual int height() const
std::shared_ptr< GridCell > _unknown_cell
std::vector< char > result() const
void reset(const Coord &area_id, const GridCell &new_area) override
void load_state(const std::vector< char > &data) override
virtual void reset(const Coord &area_id, const GridCell &new_area)
virtual double scale() const
const GridCell & operator[](const Coord &ec) const override
virtual int width() const