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  Road* road,
177  const SignId signal_id,
178  const double s_position,
179  const double t_position,
180  const std::string signal_reference_orientation);
181 
183  element::RoadInfoSignal* signal_reference,
184  const LaneId from_lane,
185  const LaneId to_lane);
186 
188  const SignId signal_id,
189  const std::string dependency_id,
190  const std::string dependency_type);
191 
192  // called from junction parser
193  void AddJunction(
194  const JuncId id,
195  const std::string name);
196 
197  void AddConnection(
198  const JuncId junction_id,
199  const ConId connection_id,
200  const RoadId incoming_road,
201  const RoadId connecting_road);
202 
203  void AddLaneLink(
204  const JuncId junction_id,
205  const ConId connection_id,
206  const LaneId from,
207  const LaneId to);
208 
210  const JuncId junction_id,
211  std::set<ContId>&& controllers);
212 
213  void AddRoadSection(
214  const RoadId road_id,
215  const SectionId section_index,
216  const double s,
217  const double a,
218  const double b,
219  const double c,
220  const double d);
221 
222  void SetRoadLaneLink(
223  const RoadId road_id,
224  const SectionId section_index,
225  const LaneId lane_id,
226  const Lane::LaneType lane_type,
227  const bool lane_level,
228  const LaneId predecessor,
229  const LaneId successor);
230 
231  // called from lane parser
232  void CreateLaneAccess(
233  Lane *lane,
234  const double s,
235  const std::string restriction);
236 
237  void CreateLaneBorder(
238  Lane *lane,
239  const double s,
240  const double a,
241  const double b,
242  const double c,
243  const double d);
244 
245  void CreateLaneHeight(
246  Lane *lane,
247  const double s,
248  const double inner,
249  const double outer);
250 
251  void CreateLaneMaterial(
252  Lane *lane,
253  const double s,
254  const std::string surface,
255  const double friction,
256  const double roughness);
257 
258  void CreateSectionOffset(
259  Road *road,
260  const double s,
261  const double a,
262  const double b,
263  const double c,
264  const double d);
265 
266  void CreateLaneRule(
267  Lane *lane,
268  const double s,
269  const std::string value);
270 
272  Lane *lane,
273  const double s,
274  const double forward,
275  const double back,
276  const double left,
277  const double right);
278 
279  void CreateLaneWidth(
280  Lane *lane,
281  const double s,
282  const double a,
283  const double b,
284  const double c,
285  const double d);
286 
287  void CreateRoadMark(
288  Lane *lane,
289  const int road_mark_id,
290  const double s,
291  const std::string type,
292  const std::string weight,
293  const std::string color,
294  const std::string material,
295  const double width,
296  const std::string lane_change,
297  const double height,
298  const std::string type_name,
299  const double type_width);
300 
302  Lane *lane,
303  const int road_mark_id,
304  const double length,
305  const double space,
306  const double tOffset,
307  const double s,
308  const std::string rule,
309  const double width);
310 
311  void CreateRoadSpeed(
312  Road *road,
313  const double s,
314  const std::string type,
315  const double max,
316  const std::string unit);
317 
318  void CreateLaneSpeed(
319  Lane *lane,
320  const double s,
321  const double max,
322  const std::string unit);
323 
324  Road *GetRoad(
325  const RoadId road_id);
326 
327  Lane *GetLane(
328  const RoadId road_id,
329  const LaneId lane_id,
330  const double s);
331 
332  // Called from ControllerParser
333  void CreateController(
334  const ContId controller_id,
335  const std::string controller_name,
336  const uint32_t controller_sequence,
337  const std::set<road::SignId>&& signals
338  );
339 
340 
341 
342  void SetGeoReference(const geom::GeoLocation &geo_reference) {
343  _map_data._geo_reference = geo_reference;
344  }
345 
346  private:
347 
349 
350  /// Create the pointers between RoadSegments based on the ids.
352 
353  /// Create the bounding boxes of each junction
354  void CreateJunctionBoundingBoxes(Map &map);
355 
356  geom::Transform ComputeSignalTransform(std::unique_ptr<Signal> &signal, MapData &data);
357 
358  /// Solves the signal references in the road
360 
361  /// Solve the references between Controllers and Juntions
363 
364  /// Compute the conflicts of the roads (intersecting roads)
366 
367  /// Generates a default validity field for signal references with missing validity record in OpenDRIVE
369 
370  /// Removes signal references with lane validity equal to [0,0]
371  /// as they have no effect on any road
373 
374  /// Checks signals overlapping driving lanes and emits a warning
375  void CheckSignalsOnRoads(Map &map);
376 
377  /// Return the pointer to a lane object.
378  Lane *GetEdgeLanePointer(RoadId road_id, bool from_start, LaneId lane_id);
379 
380  /// Return a list of pointers to all lanes from a lane (using road and
381  /// junction info).
382  std::vector<Lane *> GetLaneNext(
383  RoadId road_id,
384  SectionId section_id,
385  LaneId lane_id);
386 
387  std::vector<std::pair<RoadId, LaneId>> GetJunctionLanes(
388  JuncId junction_id,
389  RoadId road_id,
390  LaneId lane_id);
391 
392  /// Map to temporary store all the road and lane infos until the map is
393  /// built, so they can be added all together.
394  std::unordered_map<Road *, std::vector<std::unique_ptr<element::RoadInfo>>>
396 
397  std::unordered_map<Lane *, std::vector<std::unique_ptr<element::RoadInfo>>>
399 
400  std::unordered_map<SignId, std::unique_ptr<Signal>>
402 
403  std::vector<element::RoadInfoSignal*> _temp_signal_reference_container;
404 
405  };
406 
407 } // namespace road
408 } // namespace carla
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:487
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:567
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:282
std::unordered_map< SignId, std::unique_ptr< Signal > > _temp_signal_container
Definition: MapBuilder.h:401
Lane * GetEdgeLanePointer(RoadId road_id, bool from_start, LaneId lane_id)
Return the pointer to a lane object.
Definition: MapBuilder.cpp:573
void AddJunctionController(const JuncId junction_id, std::set< ContId > &&controllers)
Definition: MapBuilder.cpp:553
void ComputeJunctionRoadConflicts(Map &map)
Compute the conflicts of the roads (intersecting roads)
Definition: MapBuilder.cpp:896
void CreateJunctionBoundingBoxes(Map &map)
Create the bounding boxes of each junction.
Definition: MapBuilder.cpp:800
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:868
void GenerateDefaultValiditiesForSignalReferences()
Generates a default validity field for signal references with missing validity record in OpenDRIVE...
Definition: MapBuilder.cpp:903
void SolveSignalReferencesAndTransforms()
Solves the signal references in the road.
Definition: MapBuilder.cpp:764
void AddDependencyToSignal(const SignId signal_id, const std::string dependency_id, const std::string dependency_type)
Definition: MapBuilder.cpp:308
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:99
void CreateSectionOffset(Road *road, const double s, const double a, const double b, const double c, const double d)
Definition: MapBuilder.cpp:404
Lane * GetLane(const RoadId road_id, const LaneId lane_id, const double s)
Definition: MapBuilder.cpp:560
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:436
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:595
void AddValidityToSignalReference(element::RoadInfoSignal *signal_reference, const LaneId from_lane, const LaneId to_lane)
Definition: MapBuilder.cpp:301
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:415
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:342
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:352
void SetGeoReference(const geom::GeoLocation &geo_reference)
Definition: MapBuilder.h:342
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:544
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...
Definition: MapBuilder.cpp:970
std::vector< element::RoadInfoSignal * > _temp_signal_reference_container
Definition: MapBuilder.h:403
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:752
void CreatePointersBetweenRoadSegments()
Create the pointers between RoadSegments based on the ids.
Definition: MapBuilder.cpp:698
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:786
void AddJunction(const JuncId id, const std::string name)
Definition: MapBuilder.cpp:530
void AddConnection(const JuncId junction_id, const ConId connection_id, const RoadId incoming_road, const RoadId connecting_road)
Definition: MapBuilder.cpp:534
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:394
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:661
std::unordered_map< Lane *, std::vector< std::unique_ptr< element::RoadInfo > > > _temp_lane_info_container
Definition: MapBuilder.h:398
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:395
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:460
void AddRoadGeometryLine(carla::road::Road *road, const double s, const double x, const double y, const double hdg, const double length)
Definition: MapBuilder.cpp:375
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:317
geom::GeoLocation _geo_reference
Definition: MapData.h:92