ad_map_access
Intersection.hpp
Go to the documentation of this file.
1 // ----------------- BEGIN LICENSE BLOCK ---------------------------------
2 //
3 // Copyright (C) 2018-2021 Intel Corporation
4 //
5 // SPDX-License-Identifier: MIT
6 //
7 // ----------------- END LICENSE BLOCK -----------------------------------
12 #pragma once
13 
14 #include <map>
15 #include <memory>
16 #include <sstream>
17 #include <string>
18 #include <vector>
23 #include "ad/map/lane/Types.hpp"
24 #include "ad/map/match/Types.hpp"
25 #include "ad/map/point/Types.hpp"
27 
29 namespace ad {
31 namespace map {
33 namespace intersection {
34 
39 
43 typedef std::shared_ptr<Intersection> IntersectionPtr;
44 
48 typedef std::shared_ptr<Intersection const> IntersectionConstPtr;
49 
66 {
67 public:
78 
85  static std::vector<IntersectionPtr> getIntersectionsForRoute(route::FullRoute const &route);
86 
97 
100 
103 
106 
108  lane::LaneIdSet const &lanesOnRoute() const;
109 
112 
114  lane::LaneIdSet const &incomingLanesOnRoute() const;
115 
117  lane::LaneIdSet const &outgoingLanesOnRoute() const;
118 
121 
124 
127 
129  lane::LaneIdSet const &internalLanesWithHigherPriority() const;
130 
132  lane::LaneIdSet const &internalLanesWithLowerPriority() const;
133 
135  lane::LaneIdSet const &incomingLanes() const;
136 
138  lane::LaneIdSet const &outgoingLanes() const;
139 
142  lane::LaneIdSet const &incomingLanesWithLowerPriority() const;
143 
147  lane::LaneIdSet const &incomingLanesWithHigherPriority() const;
148 
151 
154 
157 
159  lane::LaneIdSet const &crossingLanes() const;
160 
163 
166 
168  void updateRouteCounters(route::RoutePlanningCounter newRoutePlanningCounter,
169  route::SegmentCounter newRouteSegmentCounter);
170 
177 
186  physics::Distance objectInterpenetrationDistanceWithIntersection(match::Object const &object) const;
187 
192 
197 
202 
207 
212 
217 
222 
227 
232 
238  bool objectRouteCrossesIntersectionRoute(route::FullRoute const &objectRoute) const;
239 
246  bool objectRouteFromSameArmAsIntersectionRoute(route::FullRoute const &objectRoute) const;
247 
254  bool objectRouteOppositeToIntersectionRoute(route::FullRoute const &objectRoute) const;
255 
262  bool objectRouteCrossesLanesWithHigherPriority(route::FullRoute const &objectRoute) const;
263 
267  physics::Speed getSpeedLimit() const;
268 
275 
276 private:
283  bool isSolidTrafficLight(landmark::LandmarkId trafficLightId);
284 
291  landmark::TrafficLightType extractTrafficLightType(landmark::LandmarkId trafficLightId);
292 
319  Intersection(route::FullRoute const &route,
320  route::RoadSegmentList::const_iterator const &lastSegmentBeforeIntersection,
321  route::RoadSegmentList::const_iterator const &firstSegmentWithinIntersection);
322  Intersection() = delete;
323 
324  IntersectionType mIntersectionType{IntersectionType::Unknown};
325 
327  route::RoutePlanningCounter mRoutePlanningCounter;
328 
330  route::SegmentCounter mSegmentCountFromDestination;
331 
333  lane::LaneIdSet mLanesOnRoute;
334 
336  point::ParaPointList mParaPointsOnRoute;
337 
339  lane::LaneIdSet mIncomingLanesOnRoute;
340 
342  point::ParaPointList mIncomingParaPointsOnRoute;
343 
345  lane::LaneIdSet mInternalLanesWithHigherPriority;
346 
349  lane::LaneIdSet mInternalLanesWithLowerPriority;
350 
352  lane::LaneIdSet mInternalLanesFromSameIntersectionArm;
353 
355  lane::LaneIdSet mIncomingLanes;
356 
358  point::ParaPointList mIncomingParaPoints;
359 
361  lane::LaneIdSet mOutgoingLanesOnRoute{};
362 
364  point::ParaPointList mOutgoingParaPointsOnRoute;
365 
367  point::ParaPointList mIncomingParaPointsWithHigherPriority;
368 
370  lane::LaneIdSet mIncomingLanesWithHigherPriority;
371 
373  point::ParaPointList mIncomingParaPointsWithLowerPriority;
374 
376  lane::LaneIdSet mIncomingLanesWithLowerPriority;
377 
379  lane::LaneIdSet mCrossingLanes;
380 
382  std::map<TurnDirection, lane::LaneIdSet> mIntersectionArms;
383 
384  landmark::LandmarkIdSet mTrafficLightIds;
385 
386  TurnDirection mTurnDirection{TurnDirection::Unknown};
387 
389  physics::Speed mSpeedLimit;
390 
391  void extractRightOfWayAndCollectTrafficLights(route::LaneInterval const &laneInterval,
392  lane::LaneIdSet const &successors,
393  lane::LaneId &toLaneId);
394 
395  void extractIncomingLanes();
396  void extractCrossingLanes();
397  void extractLanesWithHigherPriority();
398  void extractLanesWithLowerPriority();
399  void extractLanesFromSameIntersectionArm();
400  void calculateParaPoints();
401 
408  void calculateEnteringProrityParaPoints();
409 
437  void orderIntersectionArmsAndExtractTurnDirection();
438 
464  void adjustLanesForHasWay();
465 
486  void adjustLanesForYield();
487 
516  void adjustPriorityToRight();
517 
523  void adjustLanesForTrafficLight();
524 
531  bool turnDirectionCrossesStraightTraffic() const;
532 
534  void collectTrafficLights(lane::LaneId fromLaneId, lane::LaneId toLaneId, bool useSuccessor);
535 
536  lane::LaneIdSet successorsOnRouteLeavingIntersection(route::FullRoute const &route,
537  route::RoadSegmentList::const_iterator const &roadSegmentIt,
538  route::LaneSegment const &laneSegment);
539 
540  bool segmentLeavesIntersectionOnRoute(route::FullRoute const &route,
541  route::RoadSegmentList::const_iterator const &roadSegmentIt,
542  lane::LaneId laneId);
543 
544  lane::LaneIdSet successorsOnRouteLeavingIntersection(route::LaneSegment const &laneSegment);
545 
546  void calculateSpeedLimit();
547 
556  void addLaneAndSuccessorsToInternalLanesWithHigherPriority(lane::LaneId const &lanes,
557  TurnDirection const restrictToOutgoingIntersectionArm
559 
568  void addLaneAndSuccessorsToInternalLanesWithHigherPriority(lane::LaneIdSet const &lanes,
569  TurnDirection const restrictToOutgoingIntersectionArm
571 
580  void addLaneAndSuccessorsToInternalLanesWithHigherPriorityIfCrossing(
581  lane::LaneId const &lanes, TurnDirection const restrictToOutgoingIntersectionArm = TurnDirection::Unknown);
582 
591  void addLaneAndSuccessorsToInternalLanesWithHigherPriorityIfCrossing(
592  lane::LaneIdSet const &lanes, TurnDirection const restrictToOutgoingIntersectionArm = TurnDirection::Unknown);
593 
602  bool outgoingIntersectionArmCanBeReached(lane::LaneId const laneId, TurnDirection const outgoingIntersectionArm);
603 };
604 
605 } // namespace intersection
606 } // namespace map
607 } // namespace ad
608 
609 namespace std {
610 
620 std::ostream &operator<<(std::ostream &os, ::ad::map::intersection::Intersection const &intersection);
621 
625 static inline std::string to_string(::ad::map::intersection::Intersection const &intersection)
626 {
627  stringstream sstream;
628  sstream << intersection;
629  return sstream.str();
630 }
631 } // namespace std
ad::map::intersection::Intersection::incomingParaPoints
const point::ParaPointList & incomingParaPoints() const
ad
namespace ad
Definition: GeometryStoreItem.hpp:28
ad::map::route::RouteIterator
struct defining iterator information on a route
Definition: RouteOperation.hpp:41
ad::map::intersection::Intersection::getRoutePlanningCounter
route::RoutePlanningCounter getRoutePlanningCounter() const
ad::map::intersection::Intersection::outgoingParaPoints
const point::ParaPointList & outgoingParaPoints() const
ad::map::intersection::Intersection::objectRouteOppositeToIntersectionRoute
bool objectRouteOppositeToIntersectionRoute(route::FullRoute const &objectRoute) const
ad::map::intersection::Intersection::objectOnIncomingLane
bool objectOnIncomingLane(match::MapMatchedObjectBoundingBox const &object) const
ad::map::intersection::Intersection::intersectionType
IntersectionType intersectionType() const
Types.hpp
ad::map::intersection::Intersection::applicableTrafficLights
const landmark::LandmarkIdSet & applicableTrafficLights() const
return all traffic lights that are relevant for following the route
ad::map::intersection::Intersection
Logical representation of an intersection along the route.
Definition: Intersection.hpp:65
ad::map::intersection::Intersection::internalLanesWithHigherPriority
const lane::LaneIdSet & internalLanesWithHigherPriority() const
ad::map::intersection::Intersection::objectRouteCrossesLanesWithHigherPriority
bool objectRouteCrossesLanesWithHigherPriority(route::FullRoute const &objectRoute) const
ad::map::intersection::Intersection::objectOnLaneWithHigherPriority
bool objectOnLaneWithHigherPriority(match::MapMatchedObjectBoundingBox const &object) const
ad::map::intersection::Intersection::outgoingParaPointsOnRoute
const point::ParaPointList & outgoingParaPointsOnRoute() const
ad::map::intersection::Intersection::getIntersectionStartOnRoute
route::RouteParaPoint getIntersectionStartOnRoute() const
CoreIntersection.hpp
ad::map::match::Object
DataType Object.
Definition: Object.hpp:43
ad::map::route::SegmentCounter
uint64_t SegmentCounter
DataType SegmentCounter.
Definition: SegmentCounter.hpp:41
ad::map::landmark::LandmarkId
DataType LandmarkId.
Definition: LandmarkId.hpp:66
ad::map::route::LaneSegment
DataType LaneSegment.
Definition: LaneSegment.hpp:53
TurnDirection.hpp
ad::map::intersection::Intersection::objectOnIncomingLaneWithLowerPriority
bool objectOnIncomingLaneWithLowerPriority(match::MapMatchedObjectBoundingBox const &object) const
ad::map::intersection::Intersection::getRouteSegmentCountFromDestination
route::SegmentCounter getRouteSegmentCountFromDestination() const
ad::map::route::RoutePlanningCounter
uint64_t RoutePlanningCounter
DataType RoutePlanningCounter.
Definition: RoutePlanningCounter.hpp:39
ad::map::intersection::Intersection::objectOnInternalLaneWithLowerPriority
bool objectOnInternalLaneWithLowerPriority(match::MapMatchedObjectBoundingBox const &object) const
ad::map::intersection::Intersection::paraPointsOnRoute
const point::ParaPointList & paraPointsOnRoute() const
std::to_string
std::string to_string(::ad::map::access::GeometryStoreItem const &value)
overload of the std::to_string for GeometryStoreItem
Definition: GeometryStoreItem.hpp:183
ad::map::intersection::TurnDirection::Unknown
@ Unknown
ad::map::intersection::Intersection::objectRouteCrossesIntersectionRoute
bool objectRouteCrossesIntersectionRoute(route::FullRoute const &objectRoute) const
ad::map::intersection::Intersection::lanesOnRoute
const lane::LaneIdSet & lanesOnRoute() const
ad::map::intersection::Intersection::objectOnIntersectionRoute
bool objectOnIntersectionRoute(match::MapMatchedObjectBoundingBox const &object) const
ad::map::lane::LaneId
DataType LaneId.
Definition: LaneId.hpp:66
ad::map::intersection::Intersection::outgoingLanes
const lane::LaneIdSet & outgoingLanes() const
ad::map::intersection::IntersectionPtr
std::shared_ptr< Intersection > IntersectionPtr
typedef for shared_ptr of Intersection class
Definition: Intersection.hpp:38
ad::map::point::ParaPointList
std::vector<::ad::map::point::ParaPoint > ParaPointList
DataType ParaPointList.
Definition: ParaPointList.hpp:42
ad::map::landmark::TrafficLightType
TrafficLightType
DataType TrafficLightType.
Definition: TrafficLightType.hpp:43
Types.hpp
ad::map::intersection::Intersection::objectRouteFromSameArmAsIntersectionRoute
bool objectRouteFromSameArmAsIntersectionRoute(route::FullRoute const &objectRoute) const
ad::map::intersection::Intersection::incomingLanesOnRoute
const lane::LaneIdSet & incomingLanesOnRoute() const
ad::map::intersection::IntersectionConstPtr
std::shared_ptr< Intersection const > IntersectionConstPtr
typedef for shared_ptr of const Intersection class
Definition: Intersection.hpp:48
ad::map::intersection::Intersection::incomingParaPointsWithHigherPriority
const point::ParaPointList & incomingParaPointsWithHigherPriority() const
ad::map::intersection::Intersection::incomingLanes
const lane::LaneIdSet & incomingLanes() const
ad::map::intersection::IntersectionType
IntersectionType
DataType IntersectionType.
Definition: IntersectionType.hpp:43
ad::map::intersection::Intersection::objectOnLaneWithLowerPriority
bool objectOnLaneWithLowerPriority(match::MapMatchedObjectBoundingBox const &object) const
ad::map::match::MapMatchedObjectBoundingBox
DataType MapMatchedObjectBoundingBox.
Definition: MapMatchedObjectBoundingBox.hpp:45
ad::map::intersection::TurnDirection
TurnDirection
DataType TurnDirection.
Definition: TurnDirection.hpp:43
Types.hpp
ad::map::intersection::Intersection::getSpeedLimit
physics::Speed getSpeedLimit() const
return the speed limit of this intersection
ad::map::route::RouteParaPoint
DataType RouteParaPoint.
Definition: RouteParaPoint.hpp:45
Types.hpp
ad::map::intersection::Intersection::incomingLanesWithHigherPriority
const lane::LaneIdSet & incomingLanesWithHigherPriority() const
IntersectionType.hpp
RouteOperation.hpp
ad::map::intersection::Intersection::internalLanesWithLowerPriority
const lane::LaneIdSet & internalLanesWithLowerPriority() const
ad::map::landmark::LandmarkIdSet
std::set< LandmarkId > LandmarkIdSet
Set to store landmark identifiers.
Definition: LandmarkIdSet.hpp:30
ad::map::intersection::Intersection::turnDirection
TurnDirection turnDirection() const
ad::map::intersection::Intersection::crossingLanes
const lane::LaneIdSet & crossingLanes() const
ad::map::intersection::Intersection::objectOnIncomingLaneWithHigherPriority
bool objectOnIncomingLaneWithHigherPriority(match::MapMatchedObjectBoundingBox const &object) const
ad::map::intersection::Intersection::getIntersectionForRoadSegment
static IntersectionPtr getIntersectionForRoadSegment(route::RouteIterator const &routeIterator)
retrieve the intersection for the given routeIterator
ad::map::route::FullRoute
DataType FullRoute.
Definition: FullRoute.hpp:59
ad::map::intersection::Intersection::getIntersectionsForRoute
static std::vector< IntersectionPtr > getIntersectionsForRoute(route::FullRoute const &route)
retrieve all intersections for the given route
ad::map::intersection::Intersection::onlySolidTrafficLightsOnRoute
bool onlySolidTrafficLightsOnRoute()
checks if there is just solid traffic lights on the intersection entry.
ad::map::intersection::Intersection::outgoingLanesOnRoute
const lane::LaneIdSet & outgoingLanesOnRoute() const
ad::map::intersection::Intersection::objectOnCrossingLane
bool objectOnCrossingLane(match::MapMatchedObjectBoundingBox const &object) const
ad::map::route::LaneInterval
DataType LaneInterval.
Definition: LaneInterval.hpp:51
ad::map::intersection::CoreIntersection
Definition: CoreIntersection.hpp:58
ad::map::intersection::Intersection::incomingLanesWithLowerPriority
const lane::LaneIdSet & incomingLanesWithLowerPriority() const
ad::map::intersection::Intersection::objectOnInternalLaneWithHigherPriority
bool objectOnInternalLaneWithHigherPriority(match::MapMatchedObjectBoundingBox const &object) const
ad::map::intersection::Intersection::getNextIntersectionOnRoute
static IntersectionPtr getNextIntersectionOnRoute(route::FullRoute const &route)
retrieve the next intersection for the given route
ad::map::intersection::Intersection::incomingParaPointsWithLowerPriority
const point::ParaPointList & incomingParaPointsWithLowerPriority() const
ad::map::intersection::Intersection::incomingParaPointsOnRoute
const point::ParaPointList & incomingParaPointsOnRoute() const
ad::map::intersection::Intersection::objectInterpenetrationDistanceWithIntersection
physics::Distance objectInterpenetrationDistanceWithIntersection(match::Object const &object) const
calculate and return the physics::Distance the object interpenetrates with the intersection
ad::map::intersection::Intersection::updateRouteCounters
void updateRouteCounters(route::RoutePlanningCounter newRoutePlanningCounter, route::SegmentCounter newRouteSegmentCounter)
update the route counters according to new route
ad::map::intersection::IntersectionType::Unknown
@ Unknown