27 static auto MakeMap(
const std::string &opendrive_contents) {
28 auto stream = std::istringstream(opendrive_contents);
30 if (!map.has_value()) {
33 return std::move(*map);
41 Map::Map(std::string name, std::string xodr_content)
45 open_drive_file = xodr_content;
48 Map::~Map() =
default;
53 int32_t lane_type)
const {
54 std::optional<road::element::Waypoint> waypoint;
55 if (project_to_road) {
56 waypoint =
_map.GetClosestWaypointOnRoad(location, lane_type);
58 waypoint =
_map.GetWaypoint(location, lane_type);
60 return waypoint.has_value() ?
69 std::optional<road::element::Waypoint> waypoint;
70 waypoint =
_map.GetWaypoint(road_id, lane_id, s);
71 return waypoint.has_value() ?
78 std::unordered_map<re::Waypoint, SharedPtr<Waypoint>> waypoints;
80 auto get_or_make_waypoint = [&](
const auto &waypoint) {
81 auto it = waypoints.find(waypoint);
82 if (it == waypoints.end()) {
83 it = waypoints.emplace(
91 auto topology =
_map.GenerateTopology();
92 result.reserve(topology.size());
93 for (
const auto &pair : topology) {
95 get_or_make_waypoint(pair.first),
96 get_or_make_waypoint(pair.second));
102 std::vector<SharedPtr<Waypoint>> result;
103 const auto waypoints =
_map.GenerateWaypoints(distance);
104 result.reserve(waypoints.size());
105 for (
const auto &waypoint : waypoints) {
114 return _map.CalculateCrossedLanes(origin, destination);
118 return _map.GetGeoReference();
122 return _map.GetGeoProjection();
126 return _map.GetAllCrosswalkZones();
139 auto junction_waypoints =
GetMap().GetJunctionWaypoints(
id, lane_type);
140 for (
auto &waypoint_pair : junction_waypoints) {
150 if (junction ==
nullptr) {
157 std::vector<SharedPtr<Junction>> result;
158 for (
const auto &pair :
_map.GetData().GetJunctions()) {
165 std::vector<SharedPtr<Road>> result;
166 const auto &roads =
_map.GetData().GetRoads();
167 result.reserve(roads.size());
168 for (
const auto &pair : roads) {
175 if (!
_map.GetData().ContainsRoad(road_id)) {
184 if (!
_map.GetData().ContainsRoad(road_id)) {
189 if (section.GetId() == section_id) {
200 if (!
_map.GetData().ContainsRoad(road_id)) {
205 if (section.GetId() == section_id) {
206 if (!section.ContainsLane(lane_id)) {
220 std::vector<SharedPtr<Landmark>> result;
221 auto signal_references =
_map.GetAllSignalReferences();
222 for(
auto* signal_reference : signal_references) {
224 new Landmark(
nullptr, shared_from_this(), signal_reference, 0));
230 std::vector<SharedPtr<Landmark>> result;
231 auto signal_references =
_map.GetAllSignalReferences();
232 for(
auto* signal_reference : signal_references) {
233 if(signal_reference->GetSignalId() ==
id) {
235 new Landmark(
nullptr, shared_from_this(), signal_reference, 0));
242 std::vector<SharedPtr<Landmark>> result;
243 auto signal_references =
_map.GetAllSignalReferences();
244 for(
auto* signal_reference : signal_references) {
245 if(signal_reference->GetSignal()->GetType() == type) {
247 new Landmark(
nullptr, shared_from_this(), signal_reference, 0));
253 std::vector<SharedPtr<Landmark>>
255 std::vector<SharedPtr<Landmark>> result;
257 for (
auto& controller_id : controllers) {
258 const auto &controller =
_map.GetControllers().at(controller_id);
259 for(
auto& signal_id : controller->GetSignals()) {
260 auto& signal =
_map.GetSignals().at(signal_id);
262 result.insert(result.end(), new_landmarks.begin(), new_landmarks.end());
Class containing a reference to RoadInfoSignal.
const road::element::RoadInfoSignal * _signal
A stretch of road over which the lane layout does not change.
A single OpenDRIVE lane, identified by (road id, lane section id, lane id).
const road::Map & GetMap() const
const geom::GeoProjection & GetGeoProjection() const
std::vector< geom::Location > GetAllCrosswalkZones() const
SharedPtr< Waypoint > GetWaypointXODR(carla::road::RoadId road_id, carla::road::LaneId lane_id, float s) const
SharedPtr< Junction > GetJunctionById(road::JuncId id) const
Returns the junction with this id, or nullptr when the map has none.
SharedPtr< Waypoint > MakeWaypoint(road::element::Waypoint waypoint) const
std::vector< std::pair< SharedPtr< Waypoint >, SharedPtr< Waypoint > > > TopologyList
SharedPtr< Junction > GetJunction(const Waypoint &waypoint) const
void CookInMemoryMap(const std::string &path) const
Cooks InMemoryMap used by the traffic manager.
std::string open_drive_file
SharedPtr< LaneSection > GetLaneSection(road::RoadId road_id, road::SectionId section_id) const
Returns the lane section, or nullptr when road or section is unknown.
SharedPtr< Lane > GetLane(road::RoadId road_id, road::SectionId section_id, road::LaneId lane_id) const
Returns the lane, or nullptr when road, section or lane is unknown.
std::vector< SharedPtr< Landmark > > GetLandmarksFromId(std::string id) const
Returns all the larndmarks in the map with a specific OpenDRIVE id.
std::vector< SharedPtr< Landmark > > GetAllLandmarksOfType(std::string type) const
Returns all the landmarks in the map of a specific type.
TopologyList GetTopology() const
const rpc::MapInfo _description
const geom::GeoLocation & GetGeoReference() const
SharedPtr< Road > GetRoad(road::RoadId road_id) const
Returns the road with this id, or nullptr when the map has none.
Map(rpc::MapInfo description, std::string xodr_content)
std::vector< SharedPtr< Landmark > > GetLandmarkGroup(const Landmark &landmark) const
Returns all the landmarks in the same group including this one.
std::vector< road::element::LaneMarking > CalculateCrossedLanes(const geom::Location &origin, const geom::Location &destination) const
SharedPtr< Waypoint > GetWaypoint(const geom::Location &location, bool project_to_road=true, int32_t lane_type=static_cast< uint32_t >(road::Lane::LaneType::Driving)) const
std::vector< SharedPtr< Junction > > GetJunctions() const
Returns every junction in the map.
std::vector< SharedPtr< Road > > GetRoads() const
Returns every road in the map.
std::vector< SharedPtr< Landmark > > GetAllLandmarks() const
Returns all the larndmarks in the map.
std::vector< SharedPtr< Waypoint > > GenerateWaypoints(double distance) const
std::vector< std::pair< SharedPtr< Waypoint >, SharedPtr< Waypoint > > > GetJunctionWaypoints(road::JuncId id, road::Lane::LaneType type) const
Returns a pair of waypoints (start and end) for each lane in the junction.
An OpenDRIVE road: a run of carriageway divided along s into lane sections, each holding the lanes.
road::JuncId GetJunctionId() const
static std::optional< road::Map > Load(const std::string &opendrive)
LaneType
Can be used as flags.
const std::set< ContId > & GetControllers() const
const Signal * GetSignal() const
static void Cook(WorldMap world_map, const std::string &path)
static auto MakeMap(const std::string &opendrive_contents)
This file contains definitions of common data structures used in traffic manager.
std::shared_ptr< T > SharedPtr
void throw_exception(const ExceptionT &e)
Templated on the static type so the thrown object keeps its dynamic type: taking a const std::excepti...