Carma-platform v4.2.0
CARMA Platform is built on robot operating system (ROS) and utilizes open source software (OSS) that enables Cooperative Driving Automation (CDA) features to allow Automated Driving Systems to interact and cooperate with infrastructure and other vehicles through communication.
lookup_grid.hpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2022 LEIDOS.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 * use this file except in compliance with the License. You may obtain a copy of
6 * the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 * License for the specific language governing permissions and limitations under
14 * the License.
15 */
16
17#pragma once
18
19#include <unordered_set>
20#include <geometry/spatial_hash.hpp>
21#include <geometry/spatial_hash_config.hpp>
23
25{
26
36 template<class PointT>
38 {
39 protected:
40 using Hasher = autoware::common::geometry::spatial_hash::Config2d;
41 using HashIndex = autoware::common::geometry::spatial_hash::Index;
42
43
46
49
51 std::unordered_set<HashIndex> occupied_cells_;
52
54 static constexpr size_t PLACE_HOLDER_CAPACITY = 1;
55
56 public:
57
64
71 config_(config),
72 hasher_(config.min_x, config.max_x, config.min_y, config.max_y, config.cell_side_length, PLACE_HOLDER_CAPACITY)
73 {
74 double dx = config.max_x - config.min_x;
75 double dy = config.max_y - config.min_y;
76
77 double rough_cell_side_count = 0;
78
79 if (dx > dy) {
80 rough_cell_side_count = dx / config.cell_side_length;
81 } else {
82 rough_cell_side_count = dy / config.cell_side_length;
83 }
84
85 occupied_cells_.reserve(rough_cell_side_count * rough_cell_side_count);
86 }
87
94 return config_;
95 }
96
104 bool intersects(PointT point) const {
105
106 HashIndex cell = hasher_.bin(point.x, point.y, 0);
107
108 if (occupied_cells_.find(cell) != occupied_cells_.end()) {
109 return true;
110 }
111
112 return false;
113 }
114
122 HashIndex cell = hasher_.bin(point.x, point.y, 0);
123 occupied_cells_.insert(cell);
124 }
125
126 };
127
128} // approximate_intersection
LookupGrid class implements a fast occupancy grid creation and intersection data structure....
Definition: lookup_grid.hpp:38
Config get_config()
Return the current config.
Definition: lookup_grid.hpp:93
LookupGrid(Config config)
Constructor.
Definition: lookup_grid.hpp:70
static constexpr size_t PLACE_HOLDER_CAPACITY
Static placeholder value for the Autoware.Auto Hasher in use which requires this value but does not u...
Definition: lookup_grid.hpp:54
std::unordered_set< HashIndex > occupied_cells_
The set of occupied cells identified by their hash index.
Definition: lookup_grid.hpp:51
autoware::common::geometry::spatial_hash::Config2d Hasher
Definition: lookup_grid.hpp:40
LookupGrid()
Default constructor Note: This constructor is provided for convenience but users should normally use ...
Definition: lookup_grid.hpp:63
Hasher hasher_
Spatial hasher which defines the grid.
Definition: lookup_grid.hpp:48
autoware::common::geometry::spatial_hash::Index HashIndex
Definition: lookup_grid.hpp:41
void insert(PointT point)
Adds a point to the grid. The point must lie within the grid bounds. The cell which the point lies in...
bool intersects(PointT point) const
Checks if a point lies within an occupied cell of the grid.
Stuct containing the algorithm configuration values for approximate_intersection.
Definition: config.hpp:29
float32_t min_y
Maximum y dimension.
Definition: config.hpp:38
float32_t max_x
Maximum x dimension.
Definition: config.hpp:35
float32_t max_y
Maximum y dimension.
Definition: config.hpp:41
float32_t min_x
Maximum x dimension.
Definition: config.hpp:32
size_t cell_side_length
Cell size length.
Definition: config.hpp:44