grid_map_patcher.h
Go to the documentation of this file.
1 #ifndef SLAM_CTOR_UTILS_DG_GRID_MAP_PATCHER_INCLUDED
2 #define SLAM_CTOR_UTILS_DG_GRID_MAP_PATCHER_INCLUDED
3 
4 #include <istream>
5 #include <string>
6 #include <vector>
7 #include <cmath>
8 #include <tuple>
9 
10 #include "../../core/maps/grid_map.h"
11 
13 private:
14 
15  struct GridMapPatch {
16  GridMapPatch(const DiscretePoint2D &c, const Occupancy &occ)
17  : coord{c}, occupancy{occ} {}
20  };
21 
22  using GMPatches = std::vector<GridMapPatch>;
23 
24 public:
25 
26  template<typename MapType>
27  void apply_text_raster(MapType &dst_map, std::istream &src_raster,
28  const DiscretePoint2D &dst_offset,
29  int w_zoom = 1, int h_zoom = 1) {
30  apply_text_raster(dst_map, src_raster, false, dst_offset, w_zoom, h_zoom);
31  }
32 
33  template<typename MapType>
34  void apply_text_raster(MapType &dst_map, std::istream &src_raster,
35  int w_zoom = 1, int h_zoom = 1) {
36  apply_text_raster(dst_map, src_raster, true, {}, w_zoom, h_zoom);
37  }
38 
39 private: // methods
40 
42  return Occupancy{ch == ' ' ? 0.0 : 1.0, 1.0};
43  }
44 
45  template<typename MapType>
46  void apply_text_raster(MapType &dst_map, std::istream &src_raster,
47  bool autoalign, const DiscretePoint2D &dst_offset,
48  int w_zoom, int h_zoom) {
49  assert(0 < w_zoom && 0 < h_zoom);
50  auto patches = patches_by_text_raster(src_raster, w_zoom, h_zoom);
51  auto offset = autoalign ? DiscretePoint2D{-w_zoom * _curr_raster_w / 2,
52  h_zoom * _curr_raster_h / 2}
53  : dst_offset;
54  apply_patches(dst_map, offset, patches);
55  }
56 
57  GMPatches patches_by_text_raster(std::istream &raster,
58  int w_scale, int h_scale) {
59  GMPatches patches;
61 
62  auto world_coord = DiscretePoint2D{0, 0};
63  std::string raw_map_row;
64  while (raster.good()) {
65  std::getline(raster, raw_map_row);
66  if (raw_map_row.size() == 0) {
67  break; // Stop at empty line
68  }
69 
70  for (int row_i = 0; row_i < h_scale; ++row_i) {
71  world_coord.x = 0;
72  for (auto ch : raw_map_row) {
73  auto occupancy = char_to_occupancy(ch);
74  for (int col_i = 0; col_i < w_scale; ++col_i) {
75  patches.emplace_back(world_coord, occupancy);
76  world_coord.x += 1;
77  }
78  }
79  world_coord.y -= 1;
80  } // for row_i
81  _curr_raster_w = std::max(_curr_raster_w,
82  static_cast< int>(raw_map_row.size()));
83  _curr_raster_h += 1;
84  } // while (raster)
85  return patches;
86  }
87 
88  template<typename MapType>
89  void apply_patches(MapType &dst_map,
90  const DiscretePoint2D &offset, const GMPatches &patches) {
91 
92  auto aoo = AreaOccupancyObservation{true, Occupancy{0, 0},
93  Point2D{0, 0}, 1 /* quality */};
94  for (auto &upd_req : patches) {
95  aoo.occupancy = upd_req.occupancy;
96  dst_map.update(upd_req.coord + offset, aoo);
97  }
98  }
99 
100 private: // fields
102 };
103 
104 #endif
GMPatches patches_by_text_raster(std::istream &raster, int w_scale, int h_scale)
GridMapPatch(const DiscretePoint2D &c, const Occupancy &occ)
void apply_patches(MapType &dst_map, const DiscretePoint2D &offset, const GMPatches &patches)
std::vector< GridMapPatch > GMPatches
void apply_text_raster(MapType &dst_map, std::istream &src_raster, const DiscretePoint2D &dst_offset, int w_zoom=1, int h_zoom=1)
void apply_text_raster(MapType &dst_map, std::istream &src_raster, int w_zoom=1, int h_zoom=1)
void apply_text_raster(MapType &dst_map, std::istream &src_raster, bool autoalign, const DiscretePoint2D &dst_offset, int w_zoom, int h_zoom)
Occupancy char_to_occupancy(char ch)


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