CARLA
MapBuilder.h
Go to the documentation of this file.
1 // Copyright (c) 2017 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"
12 
13 #include <boost/optional.hpp>
14 
15 #include <map>
16 
17 namespace carla {
18 namespace road {
19 
20  class MapBuilder {
21  public:
22 
23  boost::optional<Map> Build();
24 
25  // called from road parser
27  const RoadId road_id,
28  const std::string name,
29  const double length,
30  const JuncId junction_id,
31  const RoadId predecessor,
32  const RoadId successor);
33 
35  carla::road::Road *road,
36  const SectionId id,
37  const double s);
38 
40  carla::road::LaneSection *section,
41  const LaneId lane_id,
42  const uint32_t lane_type,
43  const bool lane_level,
44  const LaneId predecessor,
45  const LaneId successor);
46 
47  // called from geometry parser
49  carla::road::Road *road,
50  const double s,
51  const double x,
52  const double y,
53  const double hdg,
54  const double length);
55 
56  void AddRoadGeometryArc(
57  carla::road::Road *road,
58  const double s,
59  const double x,
60  const double y,
61  const double hdg,
62  const double length,
63  const double curvature);
64 
66  carla::road::Road *road,
67  const double s,
68  const double x,
69  const double y,
70  const double hdg,
71  const double length,
72  const double curvStart,
73  const double curvEnd);
74 
76  carla::road::Road *road,
77  const double s,
78  const double x,
79  const double y,
80  const double hdg,
81  const double length,
82  const double a,
83  const double b,
84  const double c,
85  const double d);
86 
88  carla::road::Road *road,
89  const double s,
90  const double x,
91  const double y,
92  const double hdg,
93  const double length,
94  const double aU,
95  const double bU,
96  const double cU,
97  const double dU,
98  const double aV,
99  const double bV,
100  const double cV,
101  const double dV,
102  const std::string p_range);
103 
104  // called from profiles parser
106  Road *road,
107  const double s,
108  const double a,
109  const double b,
110  const double c,
111  const double d);
112 
114  Road *road,
115  const std::string name,
116  const double s,
117  const double t,
118  const double zOffset,
119  const double hdg,
120  const double pitch,
121  const double roll,
122  const std::string orientation,
123  const double width,
124  const double length,
125  const std::vector<road::element::CrosswalkPoint> points);
126 
127  // void AddRoadLateralSuperElevation(
128  // Road* road,
129  // const double s,
130  // const double a,
131  // const double b,
132  // const double c,
133  // const double d);
134 
135  // void AddRoadLateralCrossfall(
136  // Road* road,
137  // const double s,
138  // const double a,
139  // const double b,
140  // const double c,
141  // const double d,
142  // const std::string side);
143 
144  // void AddRoadLateralShape(
145  // Road* road,
146  // const double s,
147  // const double a,
148  // const double b,
149  // const double c,
150  // const double d,
151  // const double t);
152 
153  // Signal methods
155  Road* road,
156  const SignId signal_id,
157  const double s,
158  const double t,
159  const std::string name,
160  const std::string dynamic,
161  const std::string orientation,
162  const double zOffset,
163  const std::string country,
164  const std::string type,
165  const std::string subtype,
166  const double value,
167  const std::string unit,
168  const double height,
169  const double width,
170  const std::string text,
171  const double hOffset,
172  const double pitch,
173  const double roll);
174 
176  const SignId signal_id,
177  const double x,
178  const double y,
179  const double z,
180  const double hdg,
181  const double pitch,
182  const double roll);
183 
185  const SignId signal_id,
186  const RoadId road_id,
187  const double s,
188  const double t,
189  const double zOffset,
190  const double hOffset,
191  const double pitch,
192  const double roll);
193 
195  Road* road,
196  const SignId signal_id,
197  const double s_position,
198  const double t_position,
199  const std::string signal_reference_orientation);
200 
202  element::RoadInfoSignal* signal_reference,
203  const LaneId from_lane,
204  const LaneId to_lane);
205 
207  const SignId signal_id,
208  const std::string dependency_id,
209  const std::string dependency_type);
210 
211  // called from junction parser
212  void AddJunction(
213  const JuncId id,
214  const std::string name);
215 
216  void AddConnection(
217  const JuncId junction_id,
218  const ConId connection_id,
219  const RoadId incoming_road,
220  const RoadId connecting_road);
221 
222  void AddLaneLink(
223  const JuncId junction_id,
224  const ConId connection_id,
225  const LaneId from,
226  const LaneId to);
227 
229  const JuncId junction_id,
230  std::set<ContId>&& controllers);
231 
232  void AddRoadSection(
233  const RoadId road_id,
234  const SectionId section_index,
235  const double s,
236  const double a,
237  const double b,
238  const double c,
239  const double d);
240 
241  void SetRoadLaneLink(
242  const RoadId road_id,
243  const SectionId section_index,
244  const LaneId lane_id,
245  const Lane::LaneType lane_type,
246  const bool lane_level,
247  const LaneId predecessor,
248  const LaneId successor);
249 
250  // called from lane parser
251  void CreateLaneAccess(
252  Lane *lane,
253  const double s,
254  const std::string restriction);
255 
256  void CreateLaneBorder(
257  Lane *lane,
258  const double s,
259  const double a,
260  const double b,
261  const double c,
262  const double d);
263 
264  void CreateLaneHeight(
265  Lane *lane,
266  const double s,
267  const double inner,
268  const double outer);
269 
270  void CreateLaneMaterial(
271  Lane *lane,
272  const double s,
273  const std::string surface,
274  const double friction,
275  const double roughness);
276 
277  void CreateSectionOffset(
278  Road *road,
279  const double s,
280  const double a,
281  const double b,
282  const double c,
283  const double d);
284 
285  void CreateLaneRule(
286  Lane *lane,
287  const double s,
288  const std::string value);
289 
291  Lane *lane,
292  const double s,
293  const double forward,
294  const double back,
295  const double left,
296  const double right);
297 
298  void CreateLaneWidth(
299  Lane *lane,
300  const double s,
301  const double a,
302  const double b,
303  const double c,
304  const double d);
305 
306  void CreateRoadMark(
307  Lane *lane,
308  const int road_mark_id,
309  const double s,
310  const std::string type,
311  const std::string weight,
312  const std::string color,
313  const std::string material,
314  const double width,
315  const std::string lane_change,
316  const double height,
317  const std::string type_name,
318  const double type_width);
319 
321  Lane *lane,
322  const int road_mark_id,
323  const double length,
324  const double space,
325  const double tOffset,
326  const double s,
327  const std::string rule,
328  const double width);
329 
330  void CreateRoadSpeed(
331  Road *road,
332  const double s,
333  const std::string type,
334  const double max,
335  const std::string unit);
336 
337  void CreateLaneSpeed(
338  Lane *lane,
339  const double s,
340  const double max,
341  const std::string unit);
342 
343  Road *GetRoad(
344  const RoadId road_id);
345 
346  Lane *GetLane(
347  const RoadId road_id,
348  const LaneId lane_id,
349  const double s);
350 
351  // Called from ControllerParser
352  void CreateController(
353  const ContId controller_id,
354  const std::string controller_name,
355  const uint32_t controller_sequence,
356  const std::set<road::SignId>&& signals
357  );
358 
359 
360 
361  void SetGeoReference(const geom::GeoLocation &geo_reference) {
362  _map_data._geo_reference = geo_reference;
363  }
364 
365  private:
366 
368 
369  /// Create the pointers between RoadSegments based on the ids.
371 
372  /// Create the bounding boxes of each junction
373  void CreateJunctionBoundingBoxes(Map &map);
374 
375  geom::Transform ComputeSignalTransform(std::unique_ptr<Signal> &signal, MapData &data);
376 
377  /// Solves the signal references in the road
379 
380  /// Solve the references between Controllers and Juntions
382 
383  /// Compute the conflicts of the roads (intersecting roads)
385 
386  /// Generates a default validity field for signal references with missing validity record in OpenDRIVE
388 
389  /// Removes signal references with lane validity equal to [0,0]
390  /// as they have no effect on any road
392 
393  /// Checks signals overlapping driving lanes and emits a warning
394  void CheckSignalsOnRoads(Map &map);
395 
396  /// Return the pointer to a lane object.
397  Lane *GetEdgeLanePointer(RoadId road_id, bool from_start, LaneId lane_id);
398 
399  /// Return a list of pointers to all lanes from a lane (using road and
400  /// junction info).
401  std::vector<Lane *> GetLaneNext(
402  RoadId road_id,
403  SectionId section_id,
404  LaneId lane_id);
405 
406  std::vector<std::pair<RoadId, LaneId>> GetJunctionLanes(
407  JuncId junction_id,
408  RoadId road_id,
409  LaneId lane_id);
410 
411  /// Map to temporary store all the road and lane infos until the map is
412  /// built, so they can be added all together.
413  std::unordered_map<Road *, std::vector<std::unique_ptr<element::RoadInfo>>>
415 
416  std::unordered_map<Lane *, std::vector<std::unique_ptr<element::RoadInfo>>>
418 
419  std::unordered_map<SignId, std::unique_ptr<Signal>>
421 
422  std::vector<element::RoadInfoSignal*> _temp_signal_reference_container;
423 
424  };
425 
426 } // namespace road
427 } // namespace carla
void AddSignalPositionInertial(const SignId signal_id, const double x, const double y, const double z, const double hdg, const double pitch, const double roll)
Definition: MapBuilder.cpp:282
void CreateLaneWidth(Lane *lane, const double s, const double a, const double b, const double c, const double d)
Definition: MapBuilder.cpp:164
std::string SignId
Definition: RoadTypes.h:25
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)
Definition: MapBuilder.cpp:523
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)
Definition: MapBuilder.cpp:86
void CheckSignalsOnRoads(Map &map)
Checks signals overlapping driving lanes and emits a warning.
Road * GetRoad(const RoadId road_id)
Definition: MapBuilder.cpp:603
void AddRoadElevationProfile(Road *road, const double s, const double a, const double b, const double c, const double d)
Definition: MapBuilder.cpp:74
uint32_t RoadId
Definition: RoadTypes.h:15
element::RoadInfoSignal * AddSignalReference(Road *road, const SignId signal_id, const double s_position, const double t_position, const std::string signal_reference_orientation)
Definition: MapBuilder.cpp:318
std::unordered_map< SignId, std::unique_ptr< Signal > > _temp_signal_container
Definition: MapBuilder.h:420
Lane * GetEdgeLanePointer(RoadId road_id, bool from_start, LaneId lane_id)
Return the pointer to a lane object.
Definition: MapBuilder.cpp:609
void AddJunctionController(const JuncId junction_id, std::set< ContId > &&controllers)
Definition: MapBuilder.cpp:589
void ComputeJunctionRoadConflicts(Map &map)
Compute the conflicts of the roads (intersecting roads)
Definition: MapBuilder.cpp:939
void CreateJunctionBoundingBoxes(Map &map)
Create the bounding boxes of each junction.
Definition: MapBuilder.cpp:843
boost::optional< Map > Build()
Definition: MapBuilder.cpp:38
void CreateController(const ContId controller_id, const std::string controller_name, const uint32_t controller_sequence, const std::set< road::SignId > &&signals)
Definition: MapBuilder.cpp:911
void GenerateDefaultValiditiesForSignalReferences()
Generates a default validity field for signal references with missing validity record in OpenDRIVE...
Definition: MapBuilder.cpp:946
void SolveSignalReferencesAndTransforms()
Solves the signal references in the road.
Definition: MapBuilder.cpp:800
void AddDependencyToSignal(const SignId signal_id, const std::string dependency_id, const std::string dependency_type)
Definition: MapBuilder.cpp:344
void CreateLaneRule(Lane *lane, const double s, const std::string value)
Definition: MapBuilder.cpp:144
This file contains definitions of common data structures used in traffic manager. ...
Definition: Carla.cpp:133
void CreateSectionOffset(Road *road, const double s, const double a, const double b, const double c, const double d)
Definition: MapBuilder.cpp:440
Lane * GetLane(const RoadId road_id, const LaneId lane_id, const double s)
Definition: MapBuilder.cpp:596
uint32_t SectionId
Definition: RoadTypes.h:21
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)
Definition: MapBuilder.cpp:472
int32_t JuncId
Definition: RoadTypes.h:17
void CreateLaneVisibility(Lane *lane, const double s, const double forward, const double back, const double left, const double right)
Definition: MapBuilder.cpp:152
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).
Definition: MapBuilder.cpp:631
void AddValidityToSignalReference(element::RoadInfoSignal *signal_reference, const LaneId from_lane, const LaneId to_lane)
Definition: MapBuilder.cpp:337
void AddRoadGeometryArc(carla::road::Road *road, const double s, const double x, const double y, const double hdg, const double length, const double curvature)
Definition: MapBuilder.cpp:451
void CreateLaneBorder(Lane *lane, const double s, const double a, const double b, const double c, const double d)
Definition: MapBuilder.cpp:113
carla::road::LaneSection * AddRoadSection(carla::road::Road *road, const SectionId id, const double s)
Definition: MapBuilder.cpp:378
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)
Definition: MapBuilder.cpp:388
void SetGeoReference(const geom::GeoLocation &geo_reference)
Definition: MapBuilder.h:361
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)
Definition: MapBuilder.cpp:299
LaneType
Can be used as flags.
Definition: Lane.h:29
int32_t LaneId
Definition: RoadTypes.h:19
void AddLaneLink(const JuncId junction_id, const ConId connection_id, const LaneId from, const LaneId to)
Definition: MapBuilder.cpp:580
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)
Definition: MapBuilder.cpp:207
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 RemoveZeroLaneValiditySignalReferences()
Removes signal references with lane validity equal to [0,0] as they have no effect on any road...
std::vector< element::RoadInfoSignal * > _temp_signal_reference_container
Definition: MapBuilder.h:422
void CreateLaneMaterial(Lane *lane, const double s, const std::string surface, const double friction, const double roughness)
Definition: MapBuilder.cpp:133
void CreateLaneSpeed(Lane *lane, const double s, const double max, const std::string unit)
Definition: MapBuilder.cpp:228
geom::Transform ComputeSignalTransform(std::unique_ptr< Signal > &signal, MapData &data)
Definition: MapBuilder.cpp:788
void CreatePointersBetweenRoadSegments()
Create the pointers between RoadSegments based on the ids.
Definition: MapBuilder.cpp:734
void CreateLaneHeight(Lane *lane, const double s, const double inner, const double outer)
Definition: MapBuilder.cpp:124
void SolveControllerAndJuntionReferences()
Solve the references between Controllers and Juntions.
Definition: MapBuilder.cpp:824
void AddJunction(const JuncId id, const std::string name)
Definition: MapBuilder.cpp:566
void AddConnection(const JuncId junction_id, const ConId connection_id, const RoadId incoming_road, const RoadId connecting_road)
Definition: MapBuilder.cpp:570
uint32_t ConId
Definition: RoadTypes.h:27
void CreateRoadSpeed(Road *road, const double s, const std::string type, const double max, const std::string unit)
Definition: MapBuilder.cpp:430
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)
Definition: MapBuilder.cpp:238
std::vector< std::pair< RoadId, LaneId > > GetJunctionLanes(JuncId junction_id, RoadId road_id, LaneId lane_id)
Definition: MapBuilder.cpp:697
std::unordered_map< Lane *, std::vector< std::unique_ptr< element::RoadInfo > > > _temp_lane_info_container
Definition: MapBuilder.h:417
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:414
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)
Definition: MapBuilder.cpp:175
std::string ContId
Definition: RoadTypes.h:29
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)
Definition: MapBuilder.cpp:496
void AddRoadGeometryLine(carla::road::Road *road, const double s, const double x, const double y, const double hdg, const double length)
Definition: MapBuilder.cpp:411
void CreateLaneAccess(Lane *lane, const double s, const std::string restriction)
Definition: MapBuilder.cpp:105
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)
Definition: MapBuilder.cpp:353
geom::GeoLocation _geo_reference
Definition: MapData.h:92