CARLA
 
载入中...
搜索中...
未找到
InMemoryMap.h
浏览该文件的文档.
1// Copyright (c) 2020 Computer Vision Center (CVC) at the Universitat Autonoma
2// de Barcelona (UAB).
3//
4// This work is licensed under the terms of the MIT license.
5// For a copy, see <https://opensource.org/licenses/MIT>.
6
7#pragma once
8
9#include <chrono>
10#include <memory>
11#include <unordered_map>
12#include <unordered_set>
13
14#if defined(__clang__)
15# pragma clang diagnostic push
16# pragma clang diagnostic ignored "-Wshadow"
17#endif
18#include "boost/geometry.hpp"
19#include "boost/geometry/geometries/point.hpp"
20#include "boost/geometry/index/rtree.hpp"
21#if defined(__clang__)
22# pragma clang diagnostic pop
23#endif
24
25#include "carla/client/Map.h"
27#include "carla/geom/Location.h"
28#include "carla/geom/Math.h"
29#include "carla/Memory.h"
31
35
36namespace carla {
37namespace traffic_manager {
38
39namespace cg = carla::geom;
40namespace cc = carla::client;
41namespace crd = carla::road;
42namespace bg = boost::geometry;
43namespace bgi = boost::geometry::index;
44
46 using SimpleWaypointPtr = std::shared_ptr<SimpleWaypoint>;
47 using NodeList = std::vector<SimpleWaypointPtr>;
50
51 using Point3D = bg::model::point<float, 3, bg::cs::cartesian>;
52 using Box = bg::model::box<Point3D>;
53 using SpatialTreeEntry = std::pair<Point3D, SimpleWaypointPtr>;
54
55 using SegmentId = std::tuple<crd::RoadId, crd::LaneId, crd::SectionId>;
56 using SegmentTopology = std::map<SegmentId, std::pair<std::vector<SegmentId>, std::vector<SegmentId>>>;
57 using SegmentMap = std::map<SegmentId, std::vector<SimpleWaypointPtr>>;
58 using Rtree = bgi::rtree<SpatialTreeEntry, bgi::rstar<16>>;
59
60 /// This class builds a discretized local map-cache.
61 /// Instantiate the class with the world and run SetUp() to construct the
62 /// local map.
64
65 private:
66
67 /// Object to hold the world map received by the constructor.
69 /// Structure to hold all custom waypoint objects after interpolation of
70 /// sparse topology.
72 /// Spatial quadratic R-tree for indexing and querying waypoints.
74
75 public:
76
77 InMemoryMap(WorldMap world_map);
79
80 static void Cook(WorldMap world_map, const std::string& path);
81
82 //bool Load(const std::string& filename);
83 bool Load(const std::vector<uint8_t>& content);
84
85 /// This method constructs the local map with a resolution of sampling_resolution.
86 void SetUp();
87
88 /// This method returns the closest waypoint to a given location on the map.
90
91 /// This method returns n waypoints in an delta area with a certain distance from the ego vehicle.
92 NodeList GetWaypointsInDelta(const cg::Location loc, const uint16_t n_points, const float random_sample) const;
93
94 /// This method returns the full list of discrete samples of the map in the local cache.
96
97 std::string GetMapName();
98
99 const cc::Map& GetMap() const;
100
101 private:
102 void Save(const std::string& path);
103
105 void SetUpSpatialTree();
106 void SetUpRoadOption();
107
108 /// This method is used to find and place lane change links.
109 void FindAndLinkLaneChange(SimpleWaypointPtr reference_waypoint);
110
111 NodeList GetSuccessors(const SegmentId segment_id,
112 const SegmentTopology &segment_topology,
113 const SegmentMap &segment_map);
114 NodeList GetPredecessors(const SegmentId segment_id,
115 const SegmentTopology &segment_topology,
116 const SegmentMap &segment_map);
117
118 /// Computes the segment id of a given waypoint.
119 /// The Id takes into account OpenDrive's road Id, lane Id and Section Id.
120 SegmentId GetSegmentId(const WaypointPtr &wp) const;
121 SegmentId GetSegmentId(const SimpleWaypointPtr &swp) const;
122 };
123
124} // namespace traffic_manager
125} // namespace carla
This class builds a discretized local map-cache.
Definition InMemoryMap.h:63
bool Load(const std::vector< uint8_t > &content)
WorldMap _world_map
Object to hold the world map received by the constructor.
Definition InMemoryMap.h:68
void FindAndLinkLaneChange(SimpleWaypointPtr reference_waypoint)
This method is used to find and place lane change links.
NodeList GetPredecessors(const SegmentId segment_id, const SegmentTopology &segment_topology, const SegmentMap &segment_map)
static void Cook(WorldMap world_map, const std::string &path)
SegmentId GetSegmentId(const WaypointPtr &wp) const
Computes the segment id of a given waypoint.
NodeList GetDenseTopology() const
This method returns the full list of discrete samples of the map in the local cache.
void SetUp()
This method constructs the local map with a resolution of sampling_resolution.
NodeList GetWaypointsInDelta(const cg::Location loc, const uint16_t n_points, const float random_sample) const
This method returns n waypoints in an delta area with a certain distance from the ego vehicle.
NodeList GetSuccessors(const SegmentId segment_id, const SegmentTopology &segment_topology, const SegmentMap &segment_map)
SimpleWaypointPtr GetWaypoint(const cg::Location loc) const
This method returns the closest waypoint to a given location on the map.
Rtree rtree
Spatial quadratic R-tree for indexing and querying waypoints.
Definition InMemoryMap.h:73
NodeList dense_topology
Structure to hold all custom waypoint objects after interpolation of sparse topology.
Definition InMemoryMap.h:71
void Save(const std::string &path)
int32_t JuncId
Definition RoadTypes.h:17
std::map< SegmentId, std::vector< SimpleWaypointPtr > > SegmentMap
Definition InMemoryMap.h:57
carla::SharedPtr< cc::Waypoint > WaypointPtr
Definition InMemoryMap.h:45
std::vector< SimpleWaypointPtr > NodeList
Definition InMemoryMap.h:47
bg::model::box< Point3D > Box
Definition InMemoryMap.h:52
bg::model::point< float, 3, bg::cs::cartesian > Point3D
Definition InMemoryMap.h:51
carla::SharedPtr< const cc::Map > WorldMap
Definition InMemoryMap.h:49
std::map< SegmentId, std::pair< std::vector< SegmentId >, std::vector< SegmentId > > > SegmentTopology
Definition InMemoryMap.h:56
bgi::rtree< SpatialTreeEntry, bgi::rstar< 16 > > Rtree
Definition InMemoryMap.h:58
std::shared_ptr< SimpleWaypoint > SimpleWaypointPtr
std::tuple< crd::RoadId, crd::LaneId, crd::SectionId > SegmentId
Definition InMemoryMap.h:55
std::pair< Point3D, SimpleWaypointPtr > SpatialTreeEntry
Definition InMemoryMap.h:53
This file contains definitions of common data structures used in traffic manager.
Definition Carla.cpp:133
boost::shared_ptr< T > SharedPtr
Use this SharedPtr (boost::shared_ptr) to keep compatibility with boost::python, but it would be nice...
Definition Memory.h:20