CARLA
road/Map.h
Go to the documentation of this file.
1 // Copyright (c) 2020 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/geom/Mesh.h"
10 #include "carla/geom/Rtree.h"
11 #include "carla/geom/Transform.h"
12 #include "carla/NonCopyable.h"
16 #include "carla/road/MapData.h"
17 #include "carla/road/RoadTypes.h"
19 
20 #include <boost/optional.hpp>
21 
22 #include <vector>
23 
24 namespace carla {
25 namespace road {
26 
27  class Map : private MovableNonCopyable {
28  public:
29 
31 
32  /// ========================================================================
33  /// -- Constructor ---------------------------------------------------------
34  /// ========================================================================
35 
36  Map(MapData m) : _data(std::move(m)) {
37  CreateRtree();
38  }
39 
40  /// ========================================================================
41  /// -- Georeference --------------------------------------------------------
42  /// ========================================================================
43 
45  return _data.GetGeoReference();
46  }
47 
48  /// ========================================================================
49  /// -- Geometry ------------------------------------------------------------
50  /// ========================================================================
51 
52  boost::optional<element::Waypoint> GetClosestWaypointOnRoad(
53  const geom::Location &location,
54  int32_t lane_type = static_cast<int32_t>(Lane::LaneType::Driving)) const;
55 
56  boost::optional<element::Waypoint> GetWaypoint(
57  const geom::Location &location,
58  int32_t lane_type = static_cast<int32_t>(Lane::LaneType::Driving)) const;
59 
60  boost::optional<element::Waypoint> GetWaypoint(
61  RoadId road_id,
62  LaneId lane_id,
63  float s) const;
64 
66 
67  /// ========================================================================
68  /// -- Road information ----------------------------------------------------
69  /// ========================================================================
70 
71  const Lane &GetLane(Waypoint waypoint) const;
72 
73  Lane::LaneType GetLaneType(Waypoint waypoint) const;
74 
75  double GetLaneWidth(Waypoint waypoint) const;
76 
77  JuncId GetJunctionId(RoadId road_id) const;
78 
79  bool IsJunction(RoadId road_id) const;
80 
81  std::pair<const element::RoadInfoMarkRecord *, const element::RoadInfoMarkRecord *>
82  GetMarkRecord(Waypoint waypoint) const;
83 
84  std::vector<element::LaneMarking> CalculateCrossedLanes(
85  const geom::Location &origin,
86  const geom::Location &destination) const;
87 
88  /// Returns a list of locations defining 2d areas,
89  /// when a location is repeated an area is finished
90  std::vector<geom::Location> GetAllCrosswalkZones() const;
91 
92  /// Data structure for the signal search
96  double accumulated_s = 0;
97  };
98 
99  /// Searches signals from an initial waypoint until the defined distance.
100  std::vector<SignalSearchData> GetSignalsInDistance(
101  Waypoint waypoint, double distance, bool stop_at_junction = false) const;
102 
103  /// Return all RoadInfoSignal in the map
104  std::vector<const element::RoadInfoSignal*>
105  GetAllSignalReferences() const;
106 
107  /// ========================================================================
108  /// -- Waypoint generation -------------------------------------------------
109  /// ========================================================================
110 
111  /// Return the list of waypoints placed at the entrance of each drivable
112  /// successor lane; i.e., the list of each waypoint in the next road segment
113  /// that a vehicle could drive from @a waypoint.
114  std::vector<Waypoint> GetSuccessors(Waypoint waypoint) const;
115  std::vector<Waypoint> GetPredecessors(Waypoint waypoint) const;
116 
117  /// Return the list of waypoints at @a distance such that a vehicle at @a
118  /// waypoint could drive to.
119  std::vector<Waypoint> GetNext(Waypoint waypoint, double distance) const;
120  /// Return the list of waypoints at @a distance in the reversed direction
121  /// that a vehicle at @a waypoint could drive to.
122  std::vector<Waypoint> GetPrevious(Waypoint waypoint, double distance) const;
123 
124  /// Return a waypoint at the lane of @a waypoint's right lane.
125  boost::optional<Waypoint> GetRight(Waypoint waypoint) const;
126 
127  /// Return a waypoint at the lane of @a waypoint's left lane.
128  boost::optional<Waypoint> GetLeft(Waypoint waypoint) const;
129 
130  /// Generate all the waypoints in @a map separated by @a approx_distance.
131  std::vector<Waypoint> GenerateWaypoints(double approx_distance) const;
132 
133  /// Generate waypoints on each @a lane at the start of each @a road
134  std::vector<Waypoint> GenerateWaypointsOnRoadEntries(Lane::LaneType lane_type = Lane::LaneType::Driving) const;
135 
136  /// Generate waypoints at the entry of each lane of the specified road
137  std::vector<Waypoint> GenerateWaypointsInRoad(RoadId road_id, Lane::LaneType lane_type = Lane::LaneType::Driving) const;
138 
139  /// Generate the minimum set of waypoints that define the topology of @a
140  /// map. The waypoints are placed at the entrance of each lane.
141  std::vector<std::pair<Waypoint, Waypoint>> GenerateTopology() const;
142 
143  /// Generate waypoints of the junction
144  std::vector<std::pair<Waypoint, Waypoint>> GetJunctionWaypoints(JuncId id, Lane::LaneType lane_type) const;
145 
147 
148  const Junction* GetJunction(JuncId id) const;
149 
150  std::unordered_map<road::RoadId, std::unordered_set<road::RoadId>>
152 
153  /// Buids a mesh based on the OpenDRIVE
155  const double distance,
156  const float extra_width = 0.6f,
157  const bool smooth_junctions = true) const;
158 
159  std::vector<std::unique_ptr<geom::Mesh>> GenerateChunkedMesh(
160  const rpc::OpendriveGenerationParameters& params) const;
161 
162  /// Buids a mesh of all crosswalks based on the OpenDRIVE
164 
165  geom::Mesh GenerateWalls(const double distance, const float wall_height) const;
166 
167  const std::unordered_map<SignId, std::unique_ptr<Signal>>& GetSignals() const {
168  return _data.GetSignals();
169  }
170 
171  const std::unordered_map<ContId, std::unique_ptr<Controller>>& GetControllers() const {
172  return _data.GetControllers();
173  }
174 
175 #ifdef LIBCARLA_WITH_GTEST
176  MapData &GetMap() {
177  return _data;
178  }
179 #endif // LIBCARLA_WITH_GTEST
180 
181 private:
182 
183  friend MapBuilder;
185 
188 
189  void CreateRtree();
190 
191  /// Helper Functions for constructing the rtree element list
192  void AddElementToRtree(
193  std::vector<Rtree::TreeElement> &rtree_elements,
194  geom::Transform &current_transform,
195  geom::Transform &next_transform,
196  Waypoint &current_waypoint,
197  Waypoint &next_waypoint);
198 
200  std::vector<Rtree::TreeElement> &rtree_elements,
201  geom::Transform &current_transform,
202  Waypoint &current_waypoint,
203  Waypoint &next_waypoint);
204  };
205 
206 } // namespace road
207 } // namespace carla
const geom::GeoLocation & GetGeoReference() const
Definition: MapData.h:32
std::vector< element::LaneMarking > CalculateCrossedLanes(const geom::Location &origin, const geom::Location &destination) const
Definition: road/Map.cpp:416
geom::Mesh GenerateMesh(const double distance, const float extra_width=0.6f, const bool smooth_junctions=true) const
Buids a mesh based on the OpenDRIVE.
Definition: road/Map.cpp:956
Seting for map generation from opendrive without additional geometry.
const std::unordered_map< ContId, std::unique_ptr< Controller > > & GetControllers() const
Definition: MapData.h:82
std::unordered_map< road::RoadId, std::unordered_set< road::RoadId > > ComputeJunctionConflicts(JuncId id) const
Definition: road/Map.cpp:715
std::vector< Waypoint > GetPrevious(Waypoint waypoint, double distance) const
Return the list of waypoints at distance in the reversed direction that a vehicle at waypoint could d...
Definition: road/Map.cpp:554
uint32_t RoadId
Definition: RoadTypes.h:15
std::vector< std::pair< Waypoint, Waypoint > > GenerateTopology() const
Generate the minimum set of waypoints that define the topology of map.
Definition: road/Map.cpp:685
boost::optional< element::Waypoint > GetWaypoint(const geom::Location &location, int32_t lane_type=static_cast< int32_t >(Lane::LaneType::Driving)) const
Definition: road/Map.cpp:203
geom::Mesh GetAllCrosswalkMesh() const
Buids a mesh of all crosswalks based on the OpenDRIVE.
Definition: road/Map.cpp:1087
friend MapBuilder
Definition: road/Map.h:183
std::vector< geom::Location > GetAllCrosswalkZones() const
Returns a list of locations defining 2d areas, when a location is repeated an area is finished...
Definition: road/Map.cpp:422
const std::unordered_map< ContId, std::unique_ptr< Controller > > & GetControllers() const
Definition: road/Map.h:171
const Lane & GetLane(Waypoint waypoint) const
======================================================================== – Road information --------...
Definition: road/Map.cpp:785
std::vector< Waypoint > GenerateWaypointsOnRoadEntries(Lane::LaneType lane_type=Lane::LaneType::Driving) const
Generate waypoints on each lane at the start of each road.
Definition: road/Map.cpp:623
Junction * GetJunction(JuncId id)
Definition: road/Map.cpp:948
Map(MapData m)
======================================================================== – Constructor -------------...
Definition: road/Map.h:36
This file contains definitions of common data structures used in traffic manager. ...
Definition: Carla.cpp:99
std::vector< const element::RoadInfoSignal * > GetAllSignalReferences() const
Return all RoadInfoSignal in the map.
Definition: road/Map.cpp:404
void CreateRtree()
Definition: road/Map.cpp:838
int32_t JuncId
Definition: RoadTypes.h:17
geom::Mesh GenerateWalls(const double distance, const float wall_height) const
boost::optional< element::Waypoint > GetClosestWaypointOnRoad(const geom::Location &location, int32_t lane_type=static_cast< int32_t >(Lane::LaneType::Driving)) const
======================================================================== – Geometry ----------------...
Definition: road/Map.cpp:156
Inherit (privately) to suppress copy construction and assignment.
const std::unordered_map< SignId, std::unique_ptr< Signal > > & GetSignals() const
Definition: MapData.h:78
std::vector< Waypoint > GetNext(Waypoint waypoint, double distance) const
Return the list of waypoints at distance such that a vehicle at waypoint could drive to...
Definition: road/Map.cpp:521
Data structure for the signal search.
Definition: road/Map.h:93
LaneType
Can be used as flags.
Definition: Lane.h:29
int32_t LaneId
Definition: RoadTypes.h:19
geom::Transform ComputeTransform(Waypoint waypoint) const
Definition: road/Map.cpp:264
std::pair< const element::RoadInfoMarkRecord *, const element::RoadInfoMarkRecord * > GetMarkRecord(Waypoint waypoint) const
Definition: road/Map.cpp:298
std::vector< std::unique_ptr< geom::Mesh > > GenerateChunkedMesh(const rpc::OpendriveGenerationParameters &params) const
Definition: road/Map.cpp:1003
boost::optional< Waypoint > GetLeft(Waypoint waypoint) const
Return a waypoint at the lane of waypoint&#39;s left lane.
Definition: road/Map.cpp:597
Lane::LaneType GetLaneType(Waypoint waypoint) const
Definition: road/Map.cpp:272
Mesh data container, validator and exporter.
Definition: Mesh.h:42
bool IsJunction(RoadId road_id) const
Definition: road/Map.cpp:293
std::vector< Waypoint > GetPredecessors(Waypoint waypoint) const
Definition: road/Map.cpp:503
std::vector< SignalSearchData > GetSignalsInDistance(Waypoint waypoint, double distance, bool stop_at_junction=false) const
Searches signals from an initial waypoint until the defined distance.
Definition: road/Map.cpp:321
std::vector< Waypoint > GenerateWaypointsInRoad(RoadId road_id, Lane::LaneType lane_type=Lane::LaneType::Driving) const
Generate waypoints at the entry of each lane of the specified road.
Definition: road/Map.cpp:653
void AddElementToRtree(std::vector< Rtree::TreeElement > &rtree_elements, geom::Transform &current_transform, geom::Transform &next_transform, Waypoint &current_waypoint, Waypoint &next_waypoint)
Helper Functions for constructing the rtree element list.
Definition: road/Map.cpp:795
const geom::GeoLocation & GetGeoReference() const
======================================================================== – Georeference ------------...
Definition: road/Map.h:44
std::vector< Waypoint > GetSuccessors(Waypoint waypoint) const
======================================================================== – Waypoint generation -----...
Definition: road/Map.cpp:485
void AddElementToRtreeAndUpdateTransforms(std::vector< Rtree::TreeElement > &rtree_elements, geom::Transform &current_transform, Waypoint &current_waypoint, Waypoint &next_waypoint)
Definition: road/Map.cpp:816
std::vector< Waypoint > GenerateWaypoints(double approx_distance) const
Generate all the waypoints in map separated by approx_distance.
Definition: road/Map.cpp:609
const element::RoadInfoSignal * signal
Definition: road/Map.h:94
const std::unordered_map< SignId, std::unique_ptr< Signal > > & GetSignals() const
Definition: road/Map.h:167
JuncId GetJunctionId(RoadId road_id) const
Definition: road/Map.cpp:289
boost::optional< Waypoint > GetRight(Waypoint waypoint) const
Return a waypoint at the lane of waypoint&#39;s right lane.
Definition: road/Map.cpp:587
std::vector< std::pair< Waypoint, Waypoint > > GetJunctionWaypoints(JuncId id, Lane::LaneType lane_type) const
Generate waypoints of the junction.
Definition: road/Map.cpp:698
double GetLaneWidth(Waypoint waypoint) const
Definition: road/Map.cpp:276
MapData _data
Definition: road/Map.h:184