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);
37 : _description(
std::move(description)),
41 Map::Map(std::string name, std::string xodr_content)
44 std::vector<geom::Transform>{}}, 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);
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));
101 std::vector<SharedPtr<Waypoint>> Map::GenerateWaypoints(
double distance)
const {
102 std::vector<SharedPtr<Waypoint>> result;
103 const auto waypoints = _map.GenerateWaypoints(
distance);
104 result.reserve(waypoints.size());
105 for (
const auto &waypoint : waypoints) {
111 std::vector<road::element::LaneMarking> Map::CalculateCrossedLanes(
114 return _map.CalculateCrossedLanes(origin, destination);
118 return _map.GetGeoReference();
122 return _map.GetGeoProjection();
125 std::vector<geom::Location> Map::GetAllCrosswalkZones()
const {
126 return _map.GetAllCrosswalkZones();
139 auto junction_waypoints = GetMap().GetJunctionWaypoints(
id, lane_type);
140 for (
auto &waypoint_pair : junction_waypoints) {
156 std::vector<SharedPtr<Junction>> Map::GetJunctions()
const {
157 std::vector<SharedPtr<Junction>> result;
158 for (
const auto &pair : _map.GetData().GetJunctions()) {
164 std::vector<SharedPtr<Road>> Map::GetRoads()
const {
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)) {
219 std::vector<SharedPtr<Landmark>> Map::GetAllLandmarks()
const {
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));
229 std::vector<SharedPtr<Landmark>> Map::GetLandmarksFromId(std::string
id)
const {
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));
241 std::vector<SharedPtr<Landmark>> Map::GetAllLandmarksOfType(std::string type)
const {
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>>
254 Map::GetLandmarkGroup(
const Landmark &landmark)
const {
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);
261 auto new_landmarks = GetLandmarksFromId(signal->GetSignalId());
262 result.insert(result.end(), new_landmarks.begin(), new_landmarks.end());
268 void Map::CookInMemoryMap(
const std::string& path)
const {
std::map< std::string, unsigned int > road
std::map< std::string, unsigned int > junction
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).
std::string open_drive_file
Map(rpc::MapInfo description, std::string xodr_content)
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< std::pair< SharedPtr< Waypoint >, SharedPtr< Waypoint > > > TopologyList
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...