15 #ifndef TRAFFIC_SIMULATOR__HDMAP_UTILS__CACHE_HPP_
16 #define TRAFFIC_SIMULATOR__HDMAP_UTILS__CACHE_HPP_
19 #include <geometry_msgs/msg/point.hpp>
23 #include <unordered_map>
29 struct hash<
std::tuple<lanelet::Id, lanelet::Id, bool>>
32 size_t operator()(
const std::tuple<lanelet::Id, lanelet::Id, bool> & data)
const
34 std::hash<lanelet::Id> lanelet_id_hash;
37 seed ^= lanelet_id_hash(std::get<0>(data)) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
38 seed ^= lanelet_id_hash(std::get<1>(data)) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
39 seed ^= std::hash<bool>{}(std::get<2>(data)) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
50 auto exists(lanelet::Id from, lanelet::Id to,
bool allow_lane_change)
52 std::lock_guard<std::mutex> lock(mutex_);
53 std::tuple<lanelet::Id, lanelet::Id, bool> key = {from, to, allow_lane_change};
54 return data_.find(key) != data_.end();
57 auto getRoute(
const lanelet::Id from,
const lanelet::Id to,
const bool allow_lane_change)
60 if (!
exists(from, to, allow_lane_change)) {
62 "route from : ", from,
" to : ", to, (allow_lane_change ?
" with" :
" without"),
63 " lane change does not exists on route cache.");
65 std::lock_guard<std::mutex> lock(mutex_);
66 return data_.at({from, to, allow_lane_change});
71 lanelet::Id from, lanelet::Id to,
const bool allow_lane_change,
const lanelet::Ids & route)
74 std::lock_guard<std::mutex> lock(mutex_);
75 data_[{from, to, allow_lane_change}] = route;
79 std::unordered_map<std::tuple<lanelet::Id, lanelet::Id, bool>, lanelet::Ids> data_;
87 auto exists(lanelet::Id lanelet_id) ->
bool
89 std::lock_guard<std::mutex> lock(mutex_);
90 return data_.find(lanelet_id) != data_.end();
98 std::lock_guard<std::mutex> lock(mutex_);
99 return data_.at(lanelet_id);
104 if (!
exists(lanelet_id)) {
107 std::lock_guard<std::mutex> lock(mutex_);
108 return splines_[lanelet_id];
111 auto appendData(lanelet::Id lanelet_id,
const std::vector<geometry_msgs::msg::Point> & route)
113 std::lock_guard<std::mutex> lock(mutex_);
114 data_[lanelet_id] = route;
115 splines_[lanelet_id] = std::make_shared<math::geometry::CatmullRomSpline>(route);
119 std::unordered_map<lanelet::Id, std::vector<geometry_msgs::msg::Point>> data_;
121 std::unordered_map<lanelet::Id, std::shared_ptr<math::geometry::CatmullRomSpline>> splines_;
131 std::lock_guard<std::mutex> lock(mutex_);
132 return data_.find(lanelet_id) != data_.end();
137 if (!
exists(lanelet_id)) {
140 std::lock_guard<std::mutex> lock(mutex_);
141 return data_[lanelet_id];
146 std::lock_guard<std::mutex> lock(mutex_);
147 data_[lanelet_id] = length;
151 std::unordered_map<lanelet::Id, double> data_;
auto getCenterPoints(lanelet::Id lanelet_id) -> decltype(auto)
Definition: cache.hpp:93
auto getCenterPointsSpline(lanelet::Id lanelet_id) -> decltype(auto)
Definition: cache.hpp:102
auto appendData(lanelet::Id lanelet_id, const std::vector< geometry_msgs::msg::Point > &route)
Definition: cache.hpp:111
auto exists(lanelet::Id lanelet_id) -> bool
Definition: cache.hpp:87
Definition: cache.hpp:127
auto appendData(lanelet::Id lanelet_id, double length)
Definition: cache.hpp:144
auto getLength(lanelet::Id lanelet_id)
Definition: cache.hpp:135
auto exists(lanelet::Id lanelet_id)
Definition: cache.hpp:129
auto exists(lanelet::Id from, lanelet::Id to, bool allow_lane_change)
Definition: cache.hpp:50
auto appendData(lanelet::Id from, lanelet::Id to, const bool allow_lane_change, const lanelet::Ids &route) -> void
Definition: cache.hpp:70
auto getRoute(const lanelet::Id from, const lanelet::Id to, const bool allow_lane_change) -> decltype(auto)
Definition: cache.hpp:57
#define THROW_SIMULATION_ERROR(...)
Definition: exception.hpp:60
size_t operator()(const std::tuple< lanelet::Id, lanelet::Id, bool > &data) const
Definition: cache.hpp:32