CARLA
Toggle main menu visibility
Loading...
Searching...
No Matches
LibCarla
source
carla
trafficmanager
CachedSimpleWaypoint.cpp
Go to the documentation of this file.
1
// Copyright (c) 2026 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/trafficmanager/CachedSimpleWaypoint.h
"
8
9
namespace
carla
{
10
namespace
traffic_manager
{
11
12
using
SimpleWaypointPtr
= std::shared_ptr<SimpleWaypoint>;
13
14
CachedSimpleWaypoint::CachedSimpleWaypoint
(
const
SimpleWaypointPtr
& simple_waypoint) {
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
CachedSimpleWaypoint.h
carla::traffic_manager::CachedSimpleWaypoint::ReadValue
void ReadValue(std::ifstream &in_file, T &out_obj)
Definition
CachedSimpleWaypoint.h:52
carla::traffic_manager::CachedSimpleWaypoint::road_option
uint8_t road_option
Definition
CachedSimpleWaypoint.h:31
carla::traffic_manager::CachedSimpleWaypoint::section_id
uint32_t section_id
Definition
CachedSimpleWaypoint.h:22
carla::traffic_manager::CachedSimpleWaypoint::road_id
uint32_t road_id
Definition
CachedSimpleWaypoint.h:21
carla::traffic_manager::CachedSimpleWaypoint::s
float s
Definition
CachedSimpleWaypoint.h:24
carla::traffic_manager::CachedSimpleWaypoint::lane_id
int32_t lane_id
Definition
CachedSimpleWaypoint.h:23
carla::traffic_manager::CachedSimpleWaypoint::next_right_waypoint
uint64_t next_right_waypoint
Definition
CachedSimpleWaypoint.h:28
carla::traffic_manager::CachedSimpleWaypoint::Read
void Read(const std::vector< uint8_t > &content, unsigned long &start)
Definition
CachedSimpleWaypoint.cpp:121
carla::traffic_manager::CachedSimpleWaypoint::Write
void Write(std::ofstream &out_file)
Definition
CachedSimpleWaypoint.cpp:41
carla::traffic_manager::CachedSimpleWaypoint::waypoint_id
uint64_t waypoint_id
Definition
CachedSimpleWaypoint.h:20
carla::traffic_manager::CachedSimpleWaypoint::next_waypoints
std::vector< uint64_t > next_waypoints
Definition
CachedSimpleWaypoint.h:25
carla::traffic_manager::CachedSimpleWaypoint::previous_waypoints
std::vector< uint64_t > previous_waypoints
Definition
CachedSimpleWaypoint.h:26
carla::traffic_manager::CachedSimpleWaypoint::next_left_waypoint
uint64_t next_left_waypoint
Definition
CachedSimpleWaypoint.h:27
carla::traffic_manager::CachedSimpleWaypoint::WriteValue
void WriteValue(std::ofstream &out_file, const T &in_obj)
Definition
CachedSimpleWaypoint.h:48
carla::traffic_manager::CachedSimpleWaypoint::geodesic_grid_id
int32_t geodesic_grid_id
Definition
CachedSimpleWaypoint.h:29
carla::traffic_manager::CachedSimpleWaypoint::is_junction
bool is_junction
Definition
CachedSimpleWaypoint.h:30
carla::traffic_manager::CachedSimpleWaypoint::CachedSimpleWaypoint
CachedSimpleWaypoint()=default
carla::traffic_manager
Definition
Vehicle.h:25
carla::traffic_manager::SimpleWaypointPtr
std::shared_ptr< SimpleWaypoint > SimpleWaypointPtr
Definition
CachedSimpleWaypoint.cpp:12
carla
This file contains definitions of common data structures used in traffic manager.
Definition
SignComponent.h:21
Generated by
1.18.0