scenario_simulator_v2 C++ API
occupancy_grid_builder.hpp
Go to the documentation of this file.
1 // Copyright 2015 TIER IV, Inc. All rights reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef SIMPLE_SENSOR_SIMULATOR__SENSOR_SIMULATION__OCCUPANCY_GRID__OCCUPANCY_GRID_BUILDER_HPP_
16 #define SIMPLE_SENSOR_SIMULATOR__SENSOR_SIMULATION__OCCUPANCY_GRID__OCCUPANCY_GRID_BUILDER_HPP_
17 
18 #include <Eigen/Core>
19 #include <geometry_msgs/msg/point.hpp>
20 #include <geometry_msgs/msg/pose.hpp>
22 #include <vector>
23 
25 {
30 {
31  using MarkerCounterType = int16_t;
32  using MarkerGridType = std::vector<MarkerCounterType>;
33  using OccupancyGridType = std::vector<int8_t>;
34  using PointType = geometry_msgs::msg::Point;
35  using PoseType = geometry_msgs::msg::Pose;
37  using PolygonType = std::vector<PointType>;
38 
39 public:
41  double resolution, size_t height, size_t width, int8_t occupied_cost = 100,
42  int8_t invisible_cost = 50);
43 
44  const double resolution;
45  const size_t height;
46  const size_t width;
47  const int8_t occupied_cost;
48  const int8_t invisible_cost;
49 
54  auto add(const PrimitiveType & primitive) -> void;
55 
60  auto reset(const PoseType & origin) -> void;
61 
65  auto build() -> void;
66 
70  auto get() const -> const OccupancyGridType &;
71 
72 private:
76  PoseType origin_;
77 
81  MarkerCounterType primitive_count_ = 0;
82 
87  MarkerGridType occupied_grid_;
88 
93  MarkerGridType invisible_grid_;
94 
99  OccupancyGridType values_;
100 
105  std::vector<int32_t> min_cols_, max_cols_;
106 
112  inline auto addPolygon(MarkerGridType & grid, const PolygonType & convex_hull) -> void;
113 
119  inline auto transformToGrid(const PointType & world_point) const -> PointType;
120 
126  inline auto transformToPixel(const PointType & grid_point) const -> PointType;
127 
135  inline auto makePoint(double x, double y, double z = 0) const -> PointType;
136 
142  inline auto makeOccupiedArea(const PrimitiveType & primitive) const -> PolygonType;
143 
149  inline auto makeInvisibleArea(const PolygonType & occupied_polygon) const -> PolygonType;
150 };
151 } // namespace simple_sensor_simulator
152 
153 #endif // SIMPLE_SENSOR_SIMULATOR__SENSOR_SIMULATION__OCCUPANCY_GRID__OCCUPANCY_GRID_BUILDER_HPP_
grid
Definition: occupancy_grid_builder.hpp:30
const int8_t invisible_cost
Definition: occupancy_grid_builder.hpp:48
auto reset(const PoseType &origin) -> void
Reset all internal state.
Definition: occupancy_grid_builder.cpp:303
const int8_t occupied_cost
Definition: occupancy_grid_builder.hpp:47
auto build() -> void
Build occupancy grid.
Definition: occupancy_grid_builder.cpp:276
const double resolution
Definition: occupancy_grid_builder.hpp:44
const size_t height
Definition: occupancy_grid_builder.hpp:45
OccupancyGridBuilder(double resolution, size_t height, size_t width, int8_t occupied_cost=100, int8_t invisible_cost=50)
Definition: occupancy_grid_builder.cpp:23
const size_t width
Definition: occupancy_grid_builder.hpp:46
auto get() const -> const OccupancyGridType &
Definition: occupancy_grid_builder.cpp:301
auto add(const PrimitiveType &primitive) -> void
Mark invisible area and occupied area of primitive.
Definition: occupancy_grid_builder.cpp:255
Definition: constants.hpp:19
Definition: cache.hpp:27