CARLA
 
载入中...
搜索中...
未找到
LaneSection.cpp
浏览该文件的文档.
1// Copyright (c) 2017 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#include "carla/road/LaneSection.h" // 引入车道段的头文件
8#include "carla/road/Road.h" // 引入道路的头文件
9
10namespace carla { // 定义carla命名空间
11namespace road { // 定义road命名空间
12
13 double LaneSection::GetDistance() const { // 获取车道段距离的函数
14 return _s; // 返回车道段的起始距离
15 }
16
17 double LaneSection::GetLength() const { // 获取车道段长度的函数
18 const auto *road = GetRoad(); // 获取所属道路
19 DEBUG_ASSERT(road != nullptr); // 确保道路不为空
20 return road->UpperBound(_s) - _s; // 返回车道段的长度
21 }
22
23 Road *LaneSection::GetRoad() const { // 获取所属道路的函数
24 return _road; // 返回指向道路的指针
25 }
26
27 SectionId LaneSection::GetId() const { // 获取车道段ID的函数
28 return _id; // 返回车道段的ID
29 }
30
31 Lane *LaneSection::GetLane(const LaneId id) { // 根据ID获取车道的函数
32 auto search = _lanes.find(id); // 在车道映射中查找指定ID
33 if (search != _lanes.end()) { // 如果找到
34 return &search->second; // 返回对应的车道指针
35 }
36 return nullptr; // 未找到,返回空指针
37 }
38
39 const Lane *LaneSection::GetLane(const LaneId id) const { // 获取车道的常量版本
40 auto search = _lanes.find(id); // 在车道映射中查找指定ID
41 if (search != _lanes.end()) { // 如果找到
42 return &search->second; // 返回对应的车道指针
43 }
44 return nullptr; // 未找到,返回空指针
45 }
46
47 std::map<LaneId, Lane> &LaneSection::GetLanes() { // 获取所有车道的函数
48 return _lanes; // 返回车道的无序映射
49 }
50
51 const std::map<LaneId, Lane> &LaneSection::GetLanes() const { // 获取所有车道的常量版本
52 return _lanes; // 返回车道的无序映射
53 }
54
55 std::vector<Lane *> LaneSection::GetLanesOfType(Lane::LaneType lane_type) { // 获取指定类型车道的函数
56 std::vector<Lane *> drivable_lanes; // 用于存储可行驶车道的向量
57 for (auto &&lane : _lanes) { // 遍历所有车道
58 if ((static_cast<uint32_t>(lane.second.GetType()) & static_cast<uint32_t>(lane_type)) > 0) { // 检查车道类型是否匹配
59 drivable_lanes.emplace_back(&lane.second); // 如果匹配,则将车道添加到可行驶车道列表中
60 }
61 }
62 return drivable_lanes; // 返回可行驶车道的向量
63 }
64
65} // namespace road
66} // namespace carla
#define DEBUG_ASSERT(predicate)
Definition Debug.h:68
SectionId GetId() const
double GetDistance() const
Lane * GetLane(const LaneId id)
std::map< LaneId, Lane > _lanes
Definition LaneSection.h:61
std::vector< Lane * > GetLanesOfType(Lane::LaneType type)
const SectionId _id
Definition LaneSection.h:55
std::map< LaneId, Lane > & GetLanes()
LaneType
可以作为标志使用
Definition Lane.h:29
uint32_t SectionId
Definition RoadTypes.h:29
int32_t LaneId
Definition RoadTypes.h:26
CARLA模拟器的主命名空间。
Definition Carla.cpp:139