CARLA
 
载入中...
搜索中...
未找到
CachedSimpleWaypoint.cpp
浏览该文件的文档.
1// Copyright (c) 2021 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
8
9namespace carla {
10namespace traffic_manager {
11
12 using SimpleWaypointPtr = std::shared_ptr<SimpleWaypoint>; // 定义一个智能指针类型,用于简单路径点
13
15 this->waypoint_id = simple_waypoint->GetId(); // 获取并设置路径点的ID
16
17 this->road_id = simple_waypoint->GetWaypoint()->GetRoadId(); // 获取并设置道路ID
18 this->section_id = simple_waypoint->GetWaypoint()->GetSectionId(); // 获取并设置路段ID
19 this->lane_id = simple_waypoint->GetWaypoint()->GetLaneId(); // 获取并设置车道ID
20 this->s = static_cast<float>(simple_waypoint->GetWaypoint()->GetDistance()); // 获取并设置距离
21
22 // 获取下一个路径点的ID并保存到列表中
23 for (auto &wp : simple_waypoint->GetNextWaypoint()) {
24 this->next_waypoints.push_back(wp->GetId());
25 }
26
27 // 获取前一个路径点的ID并保存到列表中
28 for (auto &wp : simple_waypoint->GetPreviousWaypoint()) {
29 this->previous_waypoints.push_back(wp->GetId());
30 }
31
32 // 如果有左侧路径点,则获取其ID
33 if (simple_waypoint->GetLeftWaypoint() != nullptr) {
34 this->next_left_waypoint = simple_waypoint->GetLeftWaypoint()->GetId();
35 }
36 // 如果有右侧路径点,则获取其ID
37 if (simple_waypoint->GetRightWaypoint() != nullptr) {
38 this->next_right_waypoint = simple_waypoint->GetRightWaypoint()->GetId();
39 }
40
41 this->geodesic_grid_id = simple_waypoint->GetGeodesicGridId(); // 获取并设置测地网格ID
42 this->is_junction = simple_waypoint->CheckJunction(); // 检查是否为交叉口
43 this->road_option = static_cast<uint8_t>(simple_waypoint->GetRoadOption()); // 获取道路选项并转换为uint8_t类型
44 }
45
46 void CachedSimpleWaypoint::Write(std::ofstream &out_file) {
47 // 写入路径点ID
48 WriteValue<uint64_t>(out_file, this->waypoint_id);
49
50 // 写入道路ID、路段ID、车道ID和距离
51 WriteValue<uint32_t>(out_file, this->road_id);
52 WriteValue<uint32_t>(out_file, this->section_id);
53 WriteValue<int32_t>(out_file, this->lane_id);
54 WriteValue<float>(out_file, this->s);
55
56 // 写入下一个路径点的数量和ID
57 uint16_t total_next = static_cast<uint16_t>(this->next_waypoints.size());
58 WriteValue<uint16_t>(out_file, total_next);
59 for (auto &id : this->next_waypoints) {
60 WriteValue<uint64_t>(out_file, id);
61 }
62
63 // 写入前一个路径点的数量和ID
64 uint16_t total_previous = static_cast<uint16_t>(this->previous_waypoints.size());
65 WriteValue<uint16_t>(out_file, total_previous);
66 for (auto &id : this->previous_waypoints) {
67 WriteValue<uint64_t>(out_file, id);
68 }
69
70 // 写入左侧和右侧路径点的ID
71 WriteValue<uint64_t>(out_file, this->next_left_waypoint);
72 WriteValue<uint64_t>(out_file, this->next_right_waypoint);
73
74 // 写入测地网格ID
75 WriteValue<int32_t>(out_file, this->geodesic_grid_id);
76
77 // 写入是否为交叉口的布尔值
78 WriteValue<bool>(out_file, this->is_junction);
79
80 // 写入道路选项
81 WriteValue<uint8_t>(out_file, this->road_option);
82 }
83
84 void CachedSimpleWaypoint::Read(std::ifstream &in_file) {
85 // 从文件中读取路径点ID
86 ReadValue<uint64_t>(in_file, this->waypoint_id);
87
88 // 从文件中读取道路ID、路段ID、车道ID和距离
89 ReadValue<uint32_t>(in_file, this->road_id);
90 ReadValue<uint32_t>(in_file, this->section_id);
91 ReadValue<int32_t>(in_file, this->lane_id);
92 ReadValue<float>(in_file, this->s);
93
94 // 从文件中读取下一个路径点的数量和ID
95 uint16_t total_next;
96 ReadValue<uint16_t>(in_file, total_next);
97 for (uint16_t i = 0; i < total_next; i++) {
98 uint64_t id;
99 ReadValue<uint64_t>(in_file, id);
100 this->next_waypoints.push_back(id);
101 }
102
103 // 从文件中读取前一个路径点的数量和ID
104 uint16_t total_previous;
105 ReadValue<uint16_t>(in_file, total_previous);
106 for (uint16_t i = 0; i < total_previous; i++) {
107 uint64_t id;
108 ReadValue<uint64_t>(in_file, id);
109 this->previous_waypoints.push_back(id);
110 }
111
112 // 从文件中读取左侧和右侧路径点的ID
113 ReadValue<uint64_t>(in_file, this->next_left_waypoint); // 从文件中读取左侧路径点的ID
114ReadValue<uint64_t>(in_file, this->next_right_waypoint); // 从文件中读取右侧路径点的ID
115
116// geo_grid_id
117ReadValue<int32_t>(in_file, this->geodesic_grid_id); // 从文件中读取测地网格ID
118
119// is_junction
120ReadValue<bool>(in_file, this->is_junction); // 从文件中读取是否为交叉口的布尔值
121
122// road_option
123ReadValue<uint8_t>(in_file, this->road_option); // 从文件中读取道路选项
124
125void CachedSimpleWaypoint::Read(const std::vector<uint8_t>& content, unsigned long& start) {
126 ReadValue<uint64_t>(content, start, this->waypoint_id); // 从字节数组中读取路径点ID
127
128 // road_id, section_id, lane_id, s
129 ReadValue<uint32_t>(content, start, this->road_id); // 从字节数组中读取道路ID
130 ReadValue<uint32_t>(content, start, this->section_id); // 从字节数组中读取路段ID
131 ReadValue<int32_t>(content, start, this->lane_id); // 从字节数组中读取车道ID
132 ReadValue<float>(content, start, this->s); // 从字节数组中读取距离
133
134 // list_of_next
135 uint16_t total_next; // 定义变量来存储下一个路径点的数量
136 ReadValue<uint16_t>(content, start, total_next); // 从字节数组中读取下一个路径点的数量
137 for (uint16_t i = 0; i < total_next; i++) { // 遍历每个下一个路径点
138 uint64_t id; // 定义变量来存储路径点ID
139 ReadValue<uint64_t>(content, start, id); // 从字节数组中读取路径点ID
140 this->next_waypoints.push_back(id); // 将路径点ID添加到列表中
141 }
142
143 // list_of_previous
144 uint16_t total_previous; // 定义变量来存储前一个路径点的数量
145 ReadValue<uint16_t>(content, start, total_previous); // 从字节数组中读取前一个路径点的数量
146 for (uint16_t i = 0; i < total_previous; i++) { // 遍历每个前一个路径点
147 uint64_t id; // 定义变量来存储路径点ID
148 ReadValue<uint64_t>(content, start, id); // 从字节数组中读取路径点ID
149 this->previous_waypoints.push_back(id); // 将路径点ID添加到列表中
150 }
151
152 // left, right
153 ReadValue<uint64_t>(content, start, this->next_left_waypoint); // 从字节数组中读取左侧路径点的ID
154 ReadValue<uint64_t>(content, start, this->next_right_waypoint); // 从字节数组中读取右侧路径点的ID
155
156 // geo_grid_id
157 ReadValue<int32_t>(content, start, this->geodesic_grid_id); // 从字节数组中读取测地网格ID
158
159 // is_junction
160 ReadValue<bool>(content, start, this->is_junction); // 从字节数组中读取是否为交叉口的布尔值
161
162 // road_option
163 ReadValue<uint8_t>(content, start, this->road_option); // 从字节数组中读取道路选项
164}
165
166} // namespace traffic_manager
167} // namespace carla
void Read(const std::vector< uint8_t > &content, unsigned long &start)
void Write(std::ofstream &out_file)
std::shared_ptr< SimpleWaypoint > SimpleWaypointPtr
CARLA模拟器的主命名空间。
Definition Carla.cpp:139