CARLA
CachedSimpleWaypoint.cpp
Go to the documentation of this file.
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 
9 namespace carla {
10 namespace traffic_manager {
11 
12  using SimpleWaypointPtr = std::shared_ptr<SimpleWaypoint>;
13 
15  this->waypoint_id = simple_waypoint->GetId();
16 
17  this->road_id = simple_waypoint->GetWaypoint()->GetRoadId();
18  this->section_id = simple_waypoint->GetWaypoint()->GetSectionId();
19  this->lane_id = simple_waypoint->GetWaypoint()->GetLaneId();
20  this->s = static_cast<float>(simple_waypoint->GetWaypoint()->GetDistance());
21 
22  for (auto &wp : simple_waypoint->GetNextWaypoint()) {
23  this->next_waypoints.push_back(wp->GetId());
24  }
25  for (auto &wp : simple_waypoint->GetPreviousWaypoint()) {
26  this->previous_waypoints.push_back(wp->GetId());
27  }
28 
29  if (simple_waypoint->GetLeftWaypoint() != nullptr) {
30  this->next_left_waypoint = simple_waypoint->GetLeftWaypoint()->GetId();
31  }
32  if (simple_waypoint->GetRightWaypoint() != nullptr) {
33  this->next_right_waypoint = simple_waypoint->GetRightWaypoint()->GetId();
34  }
35 
36  this->geodesic_grid_id = simple_waypoint->GetGeodesicGridId();
37  this->is_junction = simple_waypoint->CheckJunction();
38  this->road_option = static_cast<uint8_t>(simple_waypoint->GetRoadOption());
39  }
40 
41  void CachedSimpleWaypoint::Write(std::ofstream &out_file) {
42 
43  WriteValue<uint64_t>(out_file, this->waypoint_id);
44 
45  // road_id, section_id, lane_id, s
46  WriteValue<uint32_t>(out_file, this->road_id);
47  WriteValue<uint32_t>(out_file, this->section_id);
48  WriteValue<int32_t>(out_file, this->lane_id);
49  WriteValue<float>(out_file, this->s);
50 
51  // list_of_next
52  uint16_t total_next = static_cast<uint16_t>(this->next_waypoints.size());
53  WriteValue<uint16_t>(out_file, total_next);
54  for (auto &id : this->next_waypoints) {
55  WriteValue<uint64_t>(out_file, id);
56  }
57 
58  // list_of_previous
59  uint16_t total_previous = static_cast<uint16_t>(this->previous_waypoints.size());
60  WriteValue<uint16_t>(out_file, total_previous);
61  for (auto &id : this->previous_waypoints) {
62  WriteValue<uint64_t>(out_file, id);
63  }
64 
65  // left, right
66  WriteValue<uint64_t>(out_file, this->next_left_waypoint);
67  WriteValue<uint64_t>(out_file, this->next_right_waypoint);
68 
69  // geo_grid_id
70  WriteValue<int32_t>(out_file, this->geodesic_grid_id);
71 
72  // is_junction
73  WriteValue<bool>(out_file, this->is_junction);
74 
75  // road_option
76  WriteValue<uint8_t>(out_file, this->road_option);
77  }
78 
79  void CachedSimpleWaypoint::Read(std::ifstream &in_file) {
80 
81  ReadValue<uint64_t>(in_file, this->waypoint_id);
82 
83  // road_id, section_id, lane_id, s
84  ReadValue<uint32_t>(in_file, this->road_id);
85  ReadValue<uint32_t>(in_file, this->section_id);
86  ReadValue<int32_t>(in_file, this->lane_id);
87  ReadValue<float>(in_file, this->s);
88 
89  // list_of_next
90  uint16_t total_next;
91  ReadValue<uint16_t>(in_file, total_next);
92  for (uint16_t i = 0; i < total_next; i++) {
93  uint64_t id;
94  ReadValue<uint64_t>(in_file, id);
95  this->next_waypoints.push_back(id);
96  }
97 
98  // list_of_previous
99  uint16_t total_previous;
100  ReadValue<uint16_t>(in_file, total_previous);
101  for (uint16_t i = 0; i < total_previous; i++) {
102  uint64_t id;
103  ReadValue<uint64_t>(in_file, id);
104  this->previous_waypoints.push_back(id);
105  }
106 
107  // left, right
108  ReadValue<uint64_t>(in_file, this->next_left_waypoint);
109  ReadValue<uint64_t>(in_file, this->next_right_waypoint);
110 
111  // geo_grid_id
112  ReadValue<int32_t>(in_file, this->geodesic_grid_id);
113 
114  // is_junction
115  ReadValue<bool>(in_file, this->is_junction);
116 
117  // road_option
118  ReadValue<uint8_t>(in_file, this->road_option);
119  }
120 
121  void CachedSimpleWaypoint::Read(const std::vector<uint8_t>& content, unsigned long& start) {
122  ReadValue<uint64_t>(content, start, this->waypoint_id);
123 
124  // road_id, section_id, lane_id, s
125  ReadValue<uint32_t>(content, start, this->road_id);
126  ReadValue<uint32_t>(content, start, this->section_id);
127  ReadValue<int32_t>(content, start, this->lane_id);
128  ReadValue<float>(content, start, this->s);
129 
130  // list_of_next
131  uint16_t total_next;
132  ReadValue<uint16_t>(content, start, total_next);
133  for (uint16_t i = 0; i < total_next; i++) {
134  uint64_t id;
135  ReadValue<uint64_t>(content, start, id);
136  this->next_waypoints.push_back(id);
137  }
138 
139  // list_of_previous
140  uint16_t total_previous;
141  ReadValue<uint16_t>(content, start, total_previous);
142  for (uint16_t i = 0; i < total_previous; i++) {
143  uint64_t id;
144  ReadValue<uint64_t>(content, start, id);
145  this->previous_waypoints.push_back(id);
146  }
147 
148  // left, right
149  ReadValue<uint64_t>(content, start, this->next_left_waypoint);
150  ReadValue<uint64_t>(content, start, this->next_right_waypoint);
151 
152  // geo_grid_id
153  ReadValue<int32_t>(content, start, this->geodesic_grid_id);
154 
155  // is_junction
156  ReadValue<bool>(content, start, this->is_junction);
157 
158  // road_option
159  ReadValue<uint8_t>(content, start, this->road_option);
160  }
161 
162 } // namespace traffic_manager
163 } // namespace carla
This file contains definitions of common data structures used in traffic manager. ...
Definition: Carla.cpp:133
void Read(const std::vector< uint8_t > &content, unsigned long &start)
std::shared_ptr< SimpleWaypoint > SimpleWaypointPtr