Drake
branch_point.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <memory>
4 #include <string>
5 
10 
11 namespace drake {
12 namespace maliput {
13 namespace api {
14 
15 class RoadGeometry;
16 
17 
18 // Persistent identifier for a BranchPoint element.
20 
21 
22 /// A set of LaneEnds.
23 class LaneEndSet {
24  // NB: This is abstract (versus being a std::set or what not) to allow the
25  // implementation to decide on how best to handle storage/indexing/etc.
26  // E.g., it could very well be a view into a database or tiled storage or
27  // something.
28  public:
30 
31  virtual ~LaneEndSet() = default;
32 
33  /// Returns the number of LaneEnds in this set.
34  ///
35  /// Return value is non-negative.
36  int size() const { return do_size(); }
37 
38  /// Returns the LaneEnd indexed by @p index.
39  ///
40  /// @pre @p index must be >= 0 and < size().
41  const LaneEnd& get(int index) const { return do_get(index); }
42 
43  protected:
44  LaneEndSet() = default;
45 
46  private:
47  /// @name NVI implementations of the public methods.
48  /// These must satisfy the constraint/invariants of the
49  /// corresponding public methods.
50  ///@{
51  virtual int do_size() const = 0;
52 
53  virtual const LaneEnd& do_get(int index) const = 0;
54  ///@}
55 };
56 
57 
58 /// A BranchPoint is a node in the network of a RoadGeometry at which
59 /// Lanes connect to one another. A BranchPoint is a collection of LaneEnds
60 /// specifying the Lanes (and, in particular, which ends of the Lanes) are
61 /// connected at the BranchPoint.
62 ///
63 /// LaneEnds participating in a BranchPoint are grouped into two sets,
64 /// arbitrarily named "A-side" and "B-side". LaneEnds on the same "side"
65 /// have coincident into-the-lane tangent vectors, which are anti-parallel
66 /// to those of LaneEnds on the other side.
67 class BranchPoint {
68  public:
70 
71  virtual ~BranchPoint() = default;
72 
73  /// Returns the persistent identifier.
74  const BranchPointId id() const { return do_id(); }
75 
76  /// Returns the RoadGeometry to which this BranchPoint belongs.
77  const RoadGeometry* road_geometry() const { return do_road_geometry(); }
78 
79  /// Returns the set of LaneEnds on the same side as the given @p end,
80  /// e.g., the LaneEnds merging with the given @p end.
81  ///
82  /// The returned set includes the given @p end.
83  ///
84  /// @pre @p end must be connected to the BranchPoint.
85  const LaneEndSet* GetConfluentBranches(const LaneEnd& end) const {
86  return DoGetConfluentBranches(end);
87  }
88 
89  /// Returns the set of LaneEnds on the other side from the given @p end,
90  /// e.g., the LaneEnds which @p end flows into.
91  ///
92  /// @pre @p end must be connected to the BranchPoint.
93  const LaneEndSet* GetOngoingBranches(const LaneEnd& end) const {
94  return DoGetOngoingBranches(end);
95  }
96 
97  /// Returns the default ongoing branch (if any) for the given @p end.
98  /// This typically represents what would be considered "continuing
99  /// through-traffic" from @p end (e.g., as opposed to a branch executing
100  /// a turn).
101  ///
102  /// If @p end has no default-branch at this BranchPoint, the return
103  /// value will be nullopt.
104  ///
105  /// @pre @p end must be connected to the BranchPoint.
107  return DoGetDefaultBranch(end);
108  }
109 
110  /// Returns the set of LaneEnds grouped together on the "A-side".
111  const LaneEndSet* GetASide() const { return DoGetASide(); }
112 
113  /// Returns the set of LaneEnds grouped together on the "B-side".
114  const LaneEndSet* GetBSide() const { return DoGetBSide(); }
115 
116  protected:
117  BranchPoint() = default;
118 
119  private:
120  /// @name NVI implementations of the public methods.
121  /// These must satisfy the constraint/invariants of the
122  /// corresponding public methods.
123  ///@{
124  virtual const BranchPointId do_id() const = 0;
125 
126  virtual const RoadGeometry* do_road_geometry() const = 0;
127 
128  virtual const LaneEndSet* DoGetConfluentBranches(
129  const LaneEnd& end) const = 0;
130 
131  virtual const LaneEndSet* DoGetOngoingBranches(
132  const LaneEnd& end) const = 0;
133 
134  virtual optional<LaneEnd> DoGetDefaultBranch(
135  const LaneEnd& end) const = 0;
136 
137  virtual const LaneEndSet* DoGetASide() const = 0;
138 
139  virtual const LaneEndSet* DoGetBSide() const = 0;
140  ///@}
141 };
142 
143 } // namespace api
144 } // namespace maliput
145 } // namespace drake
const BranchPointId id() const
Returns the persistent identifier.
Definition: branch_point.h:74
const LaneEndSet * GetConfluentBranches(const LaneEnd &end) const
Returns the set of LaneEnds on the same side as the given end, e.g., the LaneEnds merging with the gi...
Definition: branch_point.h:85
A BranchPoint is a node in the network of a RoadGeometry at which Lanes connect to one another...
Definition: branch_point.h:67
A specific endpoint of a specific Lane.
Definition: lane_data.h:21
Definition: automotive_demo.cc:88
const LaneEndSet * GetBSide() const
Returns the set of LaneEnds grouped together on the "B-side".
Definition: branch_point.h:114
Abstract API for the geometry of a road network, including both the network topology and the geometry...
Definition: road_geometry.h:26
TypeSpecificIdentifier< class BranchPoint > BranchPointId
Definition: branch_point.h:19
const RoadGeometry * road_geometry() const
Returns the RoadGeometry to which this BranchPoint belongs.
Definition: branch_point.h:77
A set of LaneEnds.
Definition: branch_point.h:23
stx::optional< T > optional
Definition: drake_optional.h:14
optional< LaneEnd > GetDefaultBranch(const LaneEnd &end) const
Returns the default ongoing branch (if any) for the given end.
Definition: branch_point.h:106
TypeSpecificIdentifier<T> represents an identifier specifically identifying an entity of type T...
Definition: type_specific_identifier.h:38
Provides drake::optional as an alias for the appropriate implementation of std::optional or std::expe...
const LaneEndSet * GetOngoingBranches(const LaneEnd &end) const
Returns the set of LaneEnds on the other side from the given end, e.g., the LaneEnds which end flows ...
Definition: branch_point.h:93
int size() const
Returns the number of LaneEnds in this set.
Definition: branch_point.h:36
const LaneEndSet * GetASide() const
Returns the set of LaneEnds grouped together on the "A-side".
Definition: branch_point.h:111
#define DRAKE_NO_COPY_NO_MOVE_NO_ASSIGN(Classname)
DRAKE_NO_COPY_NO_MOVE_NO_ASSIGN deletes the special member functions for copy-construction, copy-assignment, move-construction, and move-assignment.
Definition: drake_copyable.h:33
Provides careful macros to selectively enable or disable the special member functions for copy-constr...