CARLA
Loading...
Searching...
No Matches
Model.h
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#pragma once
8
9#include <map>
10#include <optional>
11#include <string>
12#include <vector>
13
14#include "Geometry.h"
15
16namespace twinmodel {
17
18 using Tags = std::map<std::string, std::string>;
19
20 inline const std::string *FindTag(const Tags &tags, const std::string &key) {
21 const auto it = tags.find(key);
22 return (it == tags.end()) ? nullptr : &it->second;
23 }
24
25 inline bool HasTag(const Tags &tags, const std::string &key, const std::string &value) {
26 const std::string *found = FindTag(tags, key);
27 return (found != nullptr) && (*found == value);
28 }
29
33
34 enum class Direction { Forward, Backward, Both };
35
37
38 enum class MarkingColor { White, Yellow };
39
40 enum class ContactPoint { Start, End };
41
42 enum class LinkElement { Road, Junction };
43
44 /// OpenDRIVE type/subtype follow road/SignalType.h; the crosswalk is not a
45 /// signal in CARLA but an <object type="crosswalk">.
49
50 struct SignalType {
51 const char *type = "";
52 const char *subtype = "-1";
53 bool dynamic = false;
54 };
55
57
58 struct Marking {
61 double width = 0.12;
62 std::optional<geom::LineString> geometry;
63 std::optional<int> layer;
64 };
65
66 /// One lane of a road, numbered outward from the reference line. In CARLA's
67 /// right-hand traffic the forward lanes take the negative ids.
68 struct Lane {
69 int id = 0;
71 double width = 3.25;
73 std::optional<Marking> marking;
74 std::optional<double> speed_limit;
75 /// Lane this one continues from / into on the linked road; OpenDRIVE's
76 /// <lane><link>, which is what lets a waypoint cross a road boundary.
77 std::optional<int> predecessor_lane;
78 std::optional<int> successor_lane;
80 };
81
82 struct RoadLink {
84 std::string id;
85 std::optional<ContactPoint> contact;
86 };
87
88 struct Road {
89 std::string id;
91 std::vector<Lane> lanes;
92 std::string name;
93 std::string highway;
94 std::vector<long long> osm_way_ids;
95 std::optional<std::string> junction_id;
96 std::optional<RoadLink> predecessor;
97 std::optional<RoadLink> successor;
98 std::optional<Marking> center_marking;
100 };
101
102 struct LaneLink {
103 int from_lane = 0;
104 int to_lane = 0;
105 };
106
107 struct Connection {
108 std::string id;
109 std::string incoming_road;
110 std::string connecting_road;
112 std::vector<LaneLink> lane_links;
113 };
114
115 struct Junction {
116 std::string id;
117 std::optional<geom::Polygon> polygon;
118 std::vector<Connection> connections;
119 std::vector<long long> osm_node_ids;
120 std::string name;
121 std::vector<long long> osm_way_ids;
123 };
124
125 struct Signal {
126 std::string id;
128 std::string road_id;
129 double s = 0.0;
130 double t = 0.0;
132 double heading = 0.0;
133 std::optional<double> value;
134 std::optional<std::string> controller_id;
135 std::string orientation = "+";
136 std::vector<std::pair<int, int>> validities;
137 double h_offset = 0.0;
138 std::optional<long long> osm_node_id;
140 };
141
142 struct Controller {
143 std::string id;
144 std::string junction_id;
145 std::vector<std::string> signal_ids;
146 int sequence = 0;
147 };
148
149 struct Elevation {
150 double a = 0.0;
151 double b = 0.0;
152 double c = 0.0;
153 double d = 0.0;
154 };
155
156 /// Everything the OpenDRIVE writer reads. build_lanegraph fills it from the
157 /// parsed OSM; the mesh exporter adds surfaces on top of the same roads.
159 std::string name;
160 double origin_lat = 0.0;
161 double origin_lon = 0.0;
162 std::vector<Road> roads;
163 std::vector<Junction> junctions;
164 std::vector<Signal> signals;
165 std::vector<Controller> controllers;
167
168 const Road *FindRoad(const std::string &id) const {
169 for (const Road &road : roads) {
170 if (road.id == id) {
171 return &road;
172 }
173 }
174 return nullptr;
175 }
176 };
177
178 const char *ToString(LaneType type);
179 const char *ToString(Direction direction);
180 const char *ToString(MarkingKind kind);
181 const char *ToString(MarkingColor color);
182 const char *ToString(ContactPoint point);
183
184} // namespace twinmodel
Tags tags
Definition LaneGraph.cpp:25
geom::Point point
Definition LaneGraph.cpp:41
std::map< std::string, unsigned int > road
std::vector< Point3 > Line3
bg::model::d2::point_xy< double > Point
SignalKind
OpenDRIVE type/subtype follow road/SignalType.h; the crosswalk is not a signal in CARLA but an <objec...
Definition Model.h:46
MarkingColor
Definition Model.h:38
LinkElement
Definition Model.h:42
const std::string * FindTag(const Tags &tags, const std::string &key)
Definition Model.h:20
bool HasTag(const Tags &tags, const std::string &key, const std::string &value)
Definition Model.h:25
Direction
Definition Model.h:34
std::map< std::string, std::string > Tags
Definition Model.h:18
ContactPoint
Definition Model.h:40
SignalType GetSignalType(SignalKind kind)
MarkingKind
Definition Model.h:36
const char * ToString(LaneType type)
std::vector< LaneLink > lane_links
Definition Model.h:112
ContactPoint contact_point
Definition Model.h:111
std::string connecting_road
Definition Model.h:110
std::string id
Definition Model.h:108
std::string incoming_road
Definition Model.h:109
std::string id
Definition Model.h:143
std::vector< std::string > signal_ids
Definition Model.h:145
std::string junction_id
Definition Model.h:144
std::vector< long long > osm_node_ids
Definition Model.h:119
std::optional< geom::Polygon > polygon
Definition Model.h:117
std::vector< long long > osm_way_ids
Definition Model.h:121
std::string id
Definition Model.h:116
std::string name
Definition Model.h:120
std::vector< Connection > connections
Definition Model.h:118
One lane of a road, numbered outward from the reference line.
Definition Model.h:68
LaneType type
Definition Model.h:70
Direction direction
Definition Model.h:72
std::optional< Marking > marking
Definition Model.h:73
std::optional< double > speed_limit
Definition Model.h:74
double width
Definition Model.h:71
std::optional< int > successor_lane
Definition Model.h:78
std::optional< int > predecessor_lane
Lane this one continues from / into on the linked road; OpenDRIVE's <lane><link>, which is what lets ...
Definition Model.h:77
MarkingColor color
Definition Model.h:60
std::optional< int > layer
Definition Model.h:63
MarkingKind kind
Definition Model.h:59
std::optional< geom::LineString > geometry
Definition Model.h:62
std::vector< Lane > lanes
Definition Model.h:91
std::string name
Definition Model.h:92
std::optional< RoadLink > successor
Definition Model.h:97
geom::Line3 reference_line
Definition Model.h:90
std::optional< RoadLink > predecessor
Definition Model.h:96
std::string id
Definition Model.h:89
std::optional< std::string > junction_id
Definition Model.h:95
std::string highway
Definition Model.h:93
std::vector< long long > osm_way_ids
Definition Model.h:94
std::optional< Marking > center_marking
Definition Model.h:98
const char * subtype
Definition Model.h:52
const char * type
Definition Model.h:51
std::optional< long long > osm_node_id
Definition Model.h:138
double h_offset
Definition Model.h:137
double heading
Definition Model.h:132
std::vector< std::pair< int, int > > validities
Definition Model.h:136
geom::Point position
Definition Model.h:131
std::string orientation
Definition Model.h:135
std::string road_id
Definition Model.h:128
std::string id
Definition Model.h:126
SignalKind kind
Definition Model.h:127
std::optional< std::string > controller_id
Definition Model.h:134
std::optional< double > value
Definition Model.h:133
Everything the OpenDRIVE writer reads.
Definition Model.h:158
std::vector< Signal > signals
Definition Model.h:164
std::vector< Road > roads
Definition Model.h:162
const Road * FindRoad(const std::string &id) const
Definition Model.h:168
std::vector< Controller > controllers
Definition Model.h:165
std::vector< Junction > junctions
Definition Model.h:163