grid_rasterization.h
Go to the documentation of this file.
1 #ifndef SLAM_CTOR_CORE_GRID_RASTERIZATION_H
2 #define SLAM_CTOR_CORE_GRID_RASTERIZATION_H
3 
4 #include <vector>
5 
6 #include "../geometry_utils.h"
7 #include "regular_squares_grid.h"
8 
9 // FIXME: GridRasterizedRectangle{grid, grid.world_cell_bounds(cell)}
10 // != { cell }
11 // WA: GridRasterizedRectangle{grid, grid.world_cell_bounds(cell), false}
12 // == { cell }
14  // TODO: make iterable
15 public:
16  /* IDEA:
17  *
18  * auto left_bot = grid.world_to_cell(area.left(), area.bot());
19  * auto right_top = grid.world_to_cell(area.right(), area.top());
20  * for (int y = left_bot.y; y <= right_top.y; ++y) {
21  * for (int x = left_bot.x; x <= right_top.x; ++x) {
22  * // action
23  * }
24  * }
25  */
27  const LightWeightRectangle &r,
28  bool include_border = true) {
29  double offset = include_border ? 0 : 1e-9;
30  bool area_is_infin = r.area() == RegularSquaresGrid::Dbl_Inf,
31  area_is_empty = r.area() == 0;
32  double scale = grid.scale();
33  if (!area_is_empty && !area_is_infin) {
34  _lb = grid.world_to_cell(r.left() + offset, r.bot() + offset, scale);
35  _rt = grid.world_to_cell(r.right() - offset, r.top() - offset, scale);
36  } else if (area_is_empty) {
37  // TODO: do not pass scale as an argument. This causes slight slow down.
38  // Find out the reason.
39  _rt = _lb = grid.world_to_cell(r.left(), r.bot());
40  } else if (area_is_infin) {
41  _lb = grid.internal2external({0, 0});
42  _rt = grid.internal2external({grid.width() - 1, grid.height() - 1});
43  } else {
44  assert("BUG: rectangle area is both empty and infinite");
45  }
46  _y = _lb.y;
47  _x = _lb.x;
48  }
49 
50  bool has_next() {
51  //NB: aligned top/right border is a part of a nearby cell
52  // according to implemented geometry
53  return _x <= _rt.x && _y <= _rt.y;
54  }
55 
57  auto area_id = RegularSquaresGrid::Coord{_x, _y};
58  ++_y;
59  if (_rt.y < _y) {
60  _y = _lb.y;
61  ++_x;
62  }
63  return area_id;
64  }
65 
66  auto to_vector() && {
67  auto result = std::vector<RegularSquaresGrid::Coord>{};
68  while (has_next()) { result.push_back(next()); }
69  return result;
70  }
71 
72 private:
74  int _x, _y;
75 };
76 
77 #endif
static constexpr double Dbl_Inf
Coord world_to_cell(const Point2D &pt) const
RegularSquaresGrid::Coord _lb
RegularSquaresGrid::Coord next()
Coord internal2external(const Coord &coord) const
virtual int height() const
RegularSquaresGrid::Coord _rt
virtual double scale() const
virtual int width() const
GridRasterizedRectangle(const RegularSquaresGrid &grid, const LightWeightRectangle &r, bool include_border=true)


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