CARLA
Loading...
Searching...
No Matches
MapBuilder.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 "carla/road/Map.h"
13#include "carla/road/Stencil.h"
14
15#include <optional>
16
17#include <map>
18
19namespace carla {
20namespace road {
21
22 class MapBuilder {
23 public:
24
25 std::optional<Map> Build();
26
27 // called from road parser
29 const RoadId road_id,
30 const std::string name,
31 const double length,
32 const JuncId junction_id,
33 const RoadId predecessor,
34 const RoadId successor,
35 const bool is_rht);
36
39 const SectionId id,
40 const double s);
41
44 const LaneId lane_id,
45 const uint32_t lane_type,
46 const bool lane_level,
47 const LaneId predecessor,
48 const LaneId successor);
49
50 // called from geometry parser
53 const double s,
54 const double x,
55 const double y,
56 const double hdg,
57 const double length);
58
61 const double s,
62 const double x,
63 const double y,
64 const double hdg,
65 const double length,
66 const double curvature);
67
70 const double s,
71 const double x,
72 const double y,
73 const double hdg,
74 const double length,
75 const double curvStart,
76 const double curvEnd);
77
80 const double s,
81 const double x,
82 const double y,
83 const double hdg,
84 const double length,
85 const double a,
86 const double b,
87 const double c,
88 const double d);
89
92 const double s,
93 const double x,
94 const double y,
95 const double hdg,
96 const double length,
97 const double aU,
98 const double bU,
99 const double cU,
100 const double dU,
101 const double aV,
102 const double bV,
103 const double cV,
104 const double dV,
105 const std::string p_range);
106
107 // called from profiles parser
109 Road *road,
110 const double s,
111 const double a,
112 const double b,
113 const double c,
114 const double d);
115
117 Road *road,
118 const double s,
119 const double a,
120 const double b,
121 const double c,
122 const double d,
123 const double t);
124
126 Road *road,
127 const std::string name,
128 const double s,
129 const double t,
130 const double zOffset,
131 const double hdg,
132 const double pitch,
133 const double roll,
134 const std::string orientation,
135 const double width,
136 const double length,
137 const std::vector<road::element::CrosswalkPoint> points);
138
139 // void AddRoadLateralSuperElevation(
140 // Road* road,
141 // const double s,
142 // const double a,
143 // const double b,
144 // const double c,
145 // const double d);
146
147 // void AddRoadLateralCrossfall(
148 // Road* road,
149 // const double s,
150 // const double a,
151 // const double b,
152 // const double c,
153 // const double d,
154 // const std::string side);
155
156 // void AddRoadLateralShape(
157 // Road* road,
158 // const double s,
159 // const double a,
160 // const double b,
161 // const double c,
162 // const double d,
163 // const double t);
164
165 // Signal methods
167 Road* road,
168 const SignId signal_id,
169 const double s,
170 const double t,
171 const std::string name,
172 const std::string dynamic,
173 const std::string orientation,
174 const double zOffset,
175 const std::string country,
176 const std::string type,
177 const std::string subtype,
178 const double value,
179 const std::string unit,
180 const double height,
181 const double width,
182 const std::string text,
183 const double hOffset,
184 const double pitch,
185 const double roll);
186
188 const SignId signal_id,
189 const double x,
190 const double y,
191 const double z,
192 const double hdg,
193 const double pitch,
194 const double roll);
195
197 const SignId signal_id,
198 const RoadId road_id,
199 const double s,
200 const double t,
201 const double zOffset,
202 const double hOffset,
203 const double pitch,
204 const double roll);
205
207 Road* road,
208 const SignId signal_id,
209 const double s_position,
210 const double t_position,
211 const std::string signal_reference_orientation);
212
214 element::RoadInfoSignal* signal_reference,
215 const LaneId from_lane,
216 const LaneId to_lane);
217
219 const SignId signal_id,
220 const std::string dependency_id,
221 const std::string dependency_type);
222
223 // Stencil methods
225 Road* road,
226 const StencilId stencil_id,
227 const double s,
228 const double t,
229 const std::string name,
230 const std::string orientation,
231 const std::string type,
232 const double zOffset,
233 const double heading,
234 const double length,
235 const double width,
236 const double pitch,
237 const double roll);
238
239 // called from junction parser
240 void AddJunction(
241 const JuncId id,
242 const std::string name);
243
244 void AddConnection(
245 const JuncId junction_id,
246 const ConId connection_id,
247 const RoadId incoming_road,
248 const RoadId connecting_road);
249
250 void AddLaneLink(
251 const JuncId junction_id,
252 const ConId connection_id,
253 const LaneId from,
254 const LaneId to);
255
257 const JuncId junction_id,
258 std::set<ContId>&& controllers);
259
261 const RoadId road_id,
262 const SectionId section_index,
263 const double s,
264 const double a,
265 const double b,
266 const double c,
267 const double d);
268
270 const RoadId road_id,
271 const SectionId section_index,
272 const LaneId lane_id,
273 const Lane::LaneType lane_type,
274 const bool lane_level,
275 const LaneId predecessor,
276 const LaneId successor);
277
278 // called from lane parser
279 void CreateLaneAccess(
280 Lane *lane,
281 const double s,
282 const std::string restriction);
283
284 void CreateLaneBorder(
285 Lane *lane,
286 const double s,
287 const double a,
288 const double b,
289 const double c,
290 const double d);
291
292 void CreateLaneHeight(
293 Lane *lane,
294 const double s,
295 const double inner,
296 const double outer);
297
299 Lane *lane,
300 const double s,
301 const std::string surface,
302 const double friction,
303 const double roughness);
304
306 Road *road,
307 const double s,
308 const double a,
309 const double b,
310 const double c,
311 const double d);
312
313 void CreateLaneRule(
314 Lane *lane,
315 const double s,
316 const std::string value);
317
319 Lane *lane,
320 const double s,
321 const double forward,
322 const double back,
323 const double left,
324 const double right);
325
326 void CreateLaneWidth(
327 Lane *lane,
328 const double s,
329 const double a,
330 const double b,
331 const double c,
332 const double d);
333
334 void CreateRoadMark(
335 Lane *lane,
336 const int road_mark_id,
337 const double s,
338 const std::string type,
339 const std::string weight,
340 const std::string color,
341 const std::string material,
342 const double width,
343 const std::string lane_change,
344 const double height,
345 const std::string type_name,
346 const double type_width,
347 const bool is_rht);
348
350 Lane *lane,
351 const int road_mark_id,
352 const double length,
353 const double space,
354 const double tOffset,
355 const double s,
356 const std::string rule,
357 const double width);
358
359 void CreateRoadSpeed(
360 Road *road,
361 const double s,
362 const std::string type,
363 const double max,
364 const std::string unit);
365
366 void CreateLaneSpeed(
367 Lane *lane,
368 const double s,
369 const double max,
370 const std::string unit);
371
372 Road *GetRoad(
373 const RoadId road_id);
374
375 Lane *GetLane(
376 const RoadId road_id,
377 const LaneId lane_id,
378 const double s);
379
380 // Called from ControllerParser
381 void CreateController(
382 const ContId controller_id,
383 const std::string controller_name,
384 const uint32_t controller_sequence,
385 const std::set<road::SignId>&& signals
386 );
387
388
389
390 void SetGeoReference(const geom::GeoLocation &geo_reference) {
391 _map_data._geo_reference = geo_reference;
392 }
393
394 void SetGeoProjection(const geom::GeoProjection &geo_projection) {
395 _map_data._geo_projection = geo_projection;
396 }
397
398 private:
399
401
402 /// Create the pointers between RoadSegments based on the ids.
404
405 /// Debug the built connections through the terminal.
407
408 /// Create the bounding boxes of each junction
410
411 geom::Transform ComputeSignalTransform(std::unique_ptr<Signal> &signal, MapData &data);
412
413 geom::Transform ComputeStencilTransform(std::unique_ptr<Stencil> &stencil, MapData &data);
414
415 /// Solves the signal references in the road
417
418 /// Solves the stencil references in the road
420
421 /// Solve the references between Controllers and Juntions
423
424 /// Compute the conflicts of the roads (intersecting roads)
426
427 /// Generates a default validity field for signal references with missing validity record in OpenDRIVE
429
430 /// Removes signal references with lane validity equal to [0,0]
431 /// as they have no effect on any road
433
434 /// Checks signals overlapping driving lanes and emits a warning
435 void CheckSignalsOnRoads(Map &map);
436
437 /// Return the pointer to a lane object.
439
440 /// Return a list of pointers to all lanes from a lane (using road and
441 /// junction info).
442 std::vector<Lane *> GetLaneNext(
444 SectionId section_id,
445 LaneId lane_id);
446
447 std::vector<std::pair<RoadId, const Lane *>> GetJunctionLanes(
448 JuncId junction_id,
450 LaneId lane_id);
451
452 /// Map to temporary store all the road and lane infos until the map is
453 /// built, so they can be added all together.
454 std::unordered_map<Road *, std::vector<std::unique_ptr<element::RoadInfo>>>
456
457 std::unordered_map<Lane *, std::vector<std::unique_ptr<element::RoadInfo>>>
459
460 std::unordered_map<SignId, std::unique_ptr<Signal>>
462
463 std::vector<element::RoadInfoSignal*> _temp_signal_reference_container;
464
465 std::unordered_map<StencilId, std::unique_ptr<Stencil>>
467
468 std::vector<element::RoadInfoStencil*> _temp_stencil_reference_container;
469
470 };
471
472} // namespace road
473} // namespace carla
float y
float x
float z
double heading
Definition LaneGraph.cpp:42
std::string road_id
Definition LaneGraph.cpp:39
std::map< std::string, unsigned int > road
A rigid transform in CARLA's / Unreal's left-handed frame: x forward, y right, z up,...
LaneType
Can be used as flags.
Definition road/Lane.h:29
std::unordered_map< SignId, std::unique_ptr< Signal > > _temp_signal_container
Definition MapBuilder.h:461
Lane * GetEdgeLanePointer(RoadId road_id, LaneId lane_id)
Return the pointer to a lane object.
void AddRoadGeometryArc(carla::road::Road *road, const double s, const double x, const double y, const double hdg, const double length, const double curvature)
std::vector< element::RoadInfoStencil * > _temp_stencil_reference_container
Definition MapBuilder.h:468
element::RoadInfoStencil * AddStencil(Road *road, const StencilId stencil_id, const double s, const double t, const std::string name, const std::string orientation, const std::string type, const double zOffset, const double heading, const double length, const double width, const double pitch, const double roll)
void SetGeoProjection(const geom::GeoProjection &geo_projection)
Definition MapBuilder.h:394
void CreateController(const ContId controller_id, const std::string controller_name, const uint32_t controller_sequence, const std::set< road::SignId > &&signals)
carla::road::Lane * AddRoadSectionLane(carla::road::LaneSection *section, const LaneId lane_id, const uint32_t lane_type, const bool lane_level, const LaneId predecessor, const LaneId successor)
void SolveStencilReferencesAndTransforms()
Solves the stencil references in the road.
void AddSignalPositionRoad(const SignId signal_id, const RoadId road_id, const double s, const double t, const double zOffset, const double hOffset, const double pitch, const double roll)
void AddSignalPositionInertial(const SignId signal_id, const double x, const double y, const double z, const double hdg, const double pitch, const double roll)
void CreateRoadSpeed(Road *road, const double s, const std::string type, const double max, const std::string unit)
void DebugRoadConnections()
Debug the built connections through the terminal.
void CreateSectionOffset(Road *road, const double s, const double a, const double b, const double c, const double d)
void AddJunctionController(const JuncId junction_id, std::set< ContId > &&controllers)
carla::road::LaneSection * AddRoadSection(carla::road::Road *road, const SectionId id, const double s)
void CreateRoadMark(Lane *lane, const int road_mark_id, const double s, const std::string type, const std::string weight, const std::string color, const std::string material, const double width, const std::string lane_change, const double height, const std::string type_name, const double type_width, const bool is_rht)
void CreateLaneAccess(Lane *lane, const double s, const std::string restriction)
void AddRoadLateralShape(Road *road, const double s, const double a, const double b, const double c, const double d, const double t)
void AddRoadObjectCrosswalk(Road *road, const std::string name, const double s, const double t, const double zOffset, const double hdg, const double pitch, const double roll, const std::string orientation, const double width, const double length, const std::vector< road::element::CrosswalkPoint > points)
geom::Transform ComputeStencilTransform(std::unique_ptr< Stencil > &stencil, MapData &data)
void CreateLaneHeight(Lane *lane, const double s, const double inner, const double outer)
geom::Transform ComputeSignalTransform(std::unique_ptr< Signal > &signal, MapData &data)
Lane * GetLane(const RoadId road_id, const LaneId lane_id, const double s)
void CreateLaneBorder(Lane *lane, const double s, const double a, const double b, const double c, const double d)
std::unordered_map< StencilId, std::unique_ptr< Stencil > > _temp_stencil_container
Definition MapBuilder.h:466
void ComputeJunctionRoadConflicts(Map &map)
Compute the conflicts of the roads (intersecting roads)
void AddValidityToSignalReference(element::RoadInfoSignal *signal_reference, const LaneId from_lane, const LaneId to_lane)
std::optional< Map > Build()
void CreateLaneRule(Lane *lane, const double s, const std::string value)
void SetGeoReference(const geom::GeoLocation &geo_reference)
Definition MapBuilder.h:390
void SolveControllerAndJuntionReferences()
Solve the references between Controllers and Juntions.
void AddRoadElevationProfile(Road *road, const double s, const double a, const double b, const double c, const double d)
void AddJunction(const JuncId id, const std::string name)
void CreateLaneSpeed(Lane *lane, const double s, const double max, const std::string unit)
std::unordered_map< Road *, std::vector< std::unique_ptr< element::RoadInfo > > > _temp_road_info_container
Map to temporary store all the road and lane infos until the map is built, so they can be added all t...
Definition MapBuilder.h:455
void AddLaneLink(const JuncId junction_id, const ConId connection_id, const LaneId from, const LaneId to)
void AddDependencyToSignal(const SignId signal_id, const std::string dependency_id, const std::string dependency_type)
void AddRoadGeometryParamPoly3(carla::road::Road *road, const double s, const double x, const double y, const double hdg, const double length, const double aU, const double bU, const double cU, const double dU, const double aV, const double bV, const double cV, const double dV, const std::string p_range)
void RemoveZeroLaneValiditySignalReferences()
Removes signal references with lane validity equal to [0,0] as they have no effect on any road.
void CreateRoadMarkTypeLine(Lane *lane, const int road_mark_id, const double length, const double space, const double tOffset, const double s, const std::string rule, const double width)
void AddRoadSection(const RoadId road_id, const SectionId section_index, const double s, const double a, const double b, const double c, const double d)
void CreateJunctionBoundingBoxes(Map &map)
Create the bounding boxes of each junction.
element::RoadInfoSignal * AddSignalReference(Road *road, const SignId signal_id, const double s_position, const double t_position, const std::string signal_reference_orientation)
std::unordered_map< Lane *, std::vector< std::unique_ptr< element::RoadInfo > > > _temp_lane_info_container
Definition MapBuilder.h:458
std::vector< element::RoadInfoSignal * > _temp_signal_reference_container
Definition MapBuilder.h:463
void AddRoadGeometryPoly3(carla::road::Road *road, const double s, const double x, const double y, const double hdg, const double length, const double a, const double b, const double c, const double d)
void GenerateDefaultValiditiesForSignalReferences()
Generates a default validity field for signal references with missing validity record in OpenDRIVE.
carla::road::Road * AddRoad(const RoadId road_id, const std::string name, const double length, const JuncId junction_id, const RoadId predecessor, const RoadId successor, const bool is_rht)
void AddConnection(const JuncId junction_id, const ConId connection_id, const RoadId incoming_road, const RoadId connecting_road)
element::RoadInfoSignal * AddSignal(Road *road, const SignId signal_id, const double s, const double t, const std::string name, const std::string dynamic, const std::string orientation, const double zOffset, const std::string country, const std::string type, const std::string subtype, const double value, const std::string unit, const double height, const double width, const std::string text, const double hOffset, const double pitch, const double roll)
std::vector< Lane * > GetLaneNext(RoadId road_id, SectionId section_id, LaneId lane_id)
Return a list of pointers to all lanes from a lane (using road and junction info).
void CreateLaneWidth(Lane *lane, const double s, const double a, const double b, const double c, const double d)
std::vector< std::pair< RoadId, const Lane * > > GetJunctionLanes(JuncId junction_id, RoadId road_id, LaneId lane_id)
void SolveSignalReferencesAndTransforms()
Solves the signal references in the road.
void CreateLaneVisibility(Lane *lane, const double s, const double forward, const double back, const double left, const double right)
void CreatePointersBetweenRoadSegments()
Create the pointers between RoadSegments based on the ids.
Road * GetRoad(const RoadId road_id)
void SetRoadLaneLink(const RoadId road_id, const SectionId section_index, const LaneId lane_id, const Lane::LaneType lane_type, const bool lane_level, const LaneId predecessor, const LaneId successor)
void CreateLaneMaterial(Lane *lane, const double s, const std::string surface, const double friction, const double roughness)
void CheckSignalsOnRoads(Map &map)
Checks signals overlapping driving lanes and emits a warning.
void AddRoadGeometrySpiral(carla::road::Road *road, const double s, const double x, const double y, const double hdg, const double length, const double curvStart, const double curvEnd)
void AddRoadGeometryLine(carla::road::Road *road, const double s, const double x, const double y, const double hdg, const double length)
geom::GeoProjection _geo_projection
Definition MapData.h:104
geom::GeoLocation _geo_reference
Definition MapData.h:102
std::string StencilId
Definition RoadTypes.h:27
int32_t JuncId
Definition RoadTypes.h:17
std::string ContId
Definition RoadTypes.h:31
std::string SignId
Definition RoadTypes.h:25
uint32_t RoadId
Definition RoadTypes.h:15
int32_t LaneId
Definition RoadTypes.h:19
uint32_t ConId
Definition RoadTypes.h:29
uint32_t SectionId
Definition RoadTypes.h:21
This file contains definitions of common data structures used in traffic manager.