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__) // 如果使用的是clang编译器
15# pragma clang diagnostic push // 保存当前诊断状态
16# pragma clang diagnostic ignored "-Wshadow" // 忽略变量遮蔽警告
17#endif
18#include "boost/geometry.hpp" // 引入Boost.Geometry库
19#include "boost/geometry/geometries/point.hpp" // 引入点几何体定义
20#include "boost/geometry/index/rtree.hpp" // 引入R树索引
21#if defined(__clang__) // 如果使用的是clang编译器
22# pragma clang diagnostic pop // 恢复之前的诊断状态
23#endif
24
25#include "carla/client/Map.h" // 引入CARLA客户端地图定义
26#include "carla/client/Waypoint.h" // 引入CARLA客户端路径点定义
27#include "carla/geom/Location.h" // 引入CARLA几何位置定义
28#include "carla/geom/Math.h" // 引入CARLA数学相关定义
29#include "carla/Memory.h" // 引入CARLA内存管理定义
30#include "carla/road/RoadTypes.h" // 引入CARLA道路类型定义
31
32#include "carla/trafficmanager/RandomGenerator.h" // 引入随机生成器定义
33#include "carla/trafficmanager/SimpleWaypoint.h" // 引入简单路径点定义
34#include "carla/trafficmanager/CachedSimpleWaypoint.h" // 引入缓存的简单路径点定义
35
36namespace carla {
37namespace traffic_manager {
38
39namespace cg = carla::geom; // 简化命名空间
40namespace cc = carla::client; // 简化客户端命名空间
41namespace crd = carla::road; // 简化道路命名空间
42namespace bg = boost::geometry; // 简化Boost.Geometry命名空间
43namespace bgi = boost::geometry::index; // 简化Boost.Geometry索引命名空间
44
45using WaypointPtr = carla::SharedPtr<cc::Waypoint>; // 定义路径点智能指针类型
46using SimpleWaypointPtr = std::shared_ptr<SimpleWaypoint>; // 定义简单路径点共享指针类型
47using NodeList = std::vector<SimpleWaypointPtr>; // 定义路径点列表类型
48using GeoGridId = crd::JuncId; // 定义地理网格ID类型
49using WorldMap = carla::SharedPtr<const cc::Map>; // 定义世界地图类型
50
51using Point3D = bg::model::point<float, 3, bg::cs::cartesian>; // 定义三维点类型
52using Box = bg::model::box<Point3D>; // 定义三维盒子类型
53using SpatialTreeEntry = std::pair<Point3D, SimpleWaypointPtr>; // 定义空间树条目类型
54
55using SegmentId = std::tuple<crd::RoadId, crd::LaneId, crd::SectionId>; // 定义段ID类型
56using SegmentTopology = std::map<SegmentId, std::pair<std::vector<SegmentId>, std::vector<SegmentId>>>; // 定义段拓扑图类型
57using SegmentMap = std::map<SegmentId, std::vector<SimpleWaypointPtr>>; // 定义段地图类型
58using Rtree = bgi::rtree<SpatialTreeEntry, bgi::rstar<16>>; // 定义R树类型
59
60/// 此类构建一个离散的本地地图缓存。
61/// 使用世界实例化该类并运行SetUp()构造本地地图。
63
64private:
65
66 /// 保存构造函数接收的世界地图对象。
68 /// 存储所有自定义路径点对象的结构,经过稀疏拓扑插值处理。
70 /// 用于索引和查询路径点的空间二维R树。
72
73public:
74
75 InMemoryMap(WorldMap world_map); // 构造函数,接收世界地图
76 ~InMemoryMap(); // 析构函数
77
78 static void Cook(WorldMap world_map, const std::string& path); // 静态方法,用于处理地图并保存到指定路径
79
80 //bool Load(const std::string& filename); // 加载地图的方法(未实现)
81 bool Load(const std::vector<uint8_t>& content); // 从字节内容加载地图的方法
82
83 /// 此方法以采样分辨率构建本地地图。
84 void SetUp();
85
86 /// 此方法返回给定位置上最近的路径点。
88
89 /// 此方法返回与自我车辆距离一定范围内的n个路径点。
90 NodeList GetWaypointsInDelta(const cg::Location loc, const uint16_t n_points, const float random_sample) const;
91
92 /// 此方法返回本地缓存中离散样本的完整列表。
94
95 std::string GetMapName(); // 获取地图名称
96
97 const cc::Map& GetMap() const; // 获取地图引用
98
99private:
100 void Save(const std::string& path); // 保存地图到指定路径
101
102 void SetUpDenseTopology(); // 设置稠密拓扑
103 void SetUpSpatialTree(); // 设置空间树
104 void SetUpRoadOption(); // 设置道路选项
105
106 /// 此方法用于查找和链接车道变更连接。
107 void FindAndLinkLaneChange(SimpleWaypointPtr reference_waypoint);
108
109 NodeList GetSuccessors(const SegmentId segment_id, // 获取后续路径点
110 const SegmentTopology &segment_topology,
111 const SegmentMap &segment_map);
112 NodeList GetPredecessors(const SegmentId segment_id, // 获取前驱路径点
113 const SegmentTopology &segment_topology,
114 const SegmentMap &segment_map);
115
116 /// 计算给定路径点的段ID。
117 /// ID考虑了OpenDrive的道路ID、车道ID和分段ID。
118 SegmentId GetSegmentId(const WaypointPtr &wp) const;
119 SegmentId GetSegmentId(const SimpleWaypointPtr &swp) const;
120};
121
122} // namespace traffic_manager
123} // namespace carla
此类构建一个离散的本地地图缓存。 使用世界实例化该类并运行SetUp()构造本地地图。
Definition InMemoryMap.h:62
bool Load(const std::vector< uint8_t > &content)
WorldMap _world_map
保存构造函数接收的世界地图对象。
Definition InMemoryMap.h:67
void FindAndLinkLaneChange(SimpleWaypointPtr reference_waypoint)
此方法用于查找和链接车道变更连接。
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
计算给定路径点的段ID。 ID考虑了OpenDrive的道路ID、车道ID和分段ID。
NodeList GetDenseTopology() const
此方法返回本地缓存中离散样本的完整列表。
void SetUp()
此方法以采样分辨率构建本地地图。
NodeList GetWaypointsInDelta(const cg::Location loc, const uint16_t n_points, const float random_sample) const
此方法返回与自我车辆距离一定范围内的n个路径点。
NodeList GetSuccessors(const SegmentId segment_id, const SegmentTopology &segment_topology, const SegmentMap &segment_map)
SimpleWaypointPtr GetWaypoint(const cg::Location loc) const
此方法返回给定位置上最近的路径点。
Rtree rtree
用于索引和查询路径点的空间二维R树。
Definition InMemoryMap.h:71
NodeList dense_topology
存储所有自定义路径点对象的结构,经过稀疏拓扑插值处理。
Definition InMemoryMap.h:69
void Save(const std::string &path)
包含客户端相关类和定义的命名空间。
Definition AtomicList.h:17
Carlaе·عܵռ
int32_t JuncId
Definition RoadTypes.h:23
std::map< SegmentId, std::vector< SimpleWaypointPtr > > SegmentMap
Definition InMemoryMap.h:57
carla::SharedPtr< cc::Waypoint > WaypointPtr
Waypoint的智能指针类型别名。
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
CARLA模拟器的主命名空间。
Definition Carla.cpp:139
boost::shared_ptr< T > SharedPtr
使用这个SharedPtr(boost::shared_ptr)以保持与boost::python的兼容性, 但未来如果可能的话,我们希望能为std::shared_ptr制作一个Python适配器。
Definition Memory.h:19