Drake
connection.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <string>
4 #include <vector>
5 
6 #include "ignition/math/Vector3.hh"
7 #include "ignition/rndf/UniqueId.hh"
8 
12 
13 namespace drake {
14 namespace maliput {
15 namespace rndf {
16 
36 class Connection {
37  public:
50  Connection(const std::string& id,
51  const std::vector<DirectedWaypoint>& waypoints, double width,
52  bool inverse_direction)
53  : id_(id),
54  waypoints_(waypoints),
55  width_(width),
56  inverse_direction_(inverse_direction) {
57  ThrowIfInvalidWaypoints(waypoints);
58  DRAKE_THROW_UNLESS(width > 0.0);
59  }
60 
63  const std::string& id() const { return id_; }
64 
68  const DirectedWaypoint& start() const { return waypoints_.front(); }
69 
73  const DirectedWaypoint& end() const { return waypoints_.back(); }
74 
77  const std::vector<DirectedWaypoint>& waypoints() const { return waypoints_; }
78 
83  void set_waypoints(const std::vector<DirectedWaypoint>& waypoints) {
84  ThrowIfInvalidWaypoints(waypoints);
85  waypoints_ = waypoints;
86  }
87 
95  void AddWaypoint(const DirectedWaypoint& waypoint, int position);
96 
99  double width() const { return width_; }
100 
105  void set_width(double width) {
106  DRAKE_THROW_UNLESS(width > 0.0);
107  width_ = width;
108  }
109 
114  bool inverse_direction() const { return inverse_direction_; }
115 
121  inverse_direction_ = inverse_direction;
122  }
123 
124  private:
125  // Throws an exception if @p waypoints doesn't hold at least two valid
126  // waypoints.
127  // @param waypoints A vector of DirectedWaypoints to check.
128  // @throws std::runtime_error When @p waypoints holds less than two valid
129  // DirectedWaypoints.
130  void ThrowIfInvalidWaypoints(
131  const std::vector<DirectedWaypoint>& waypoints) const {
132  int num_valid = 0;
133  for (const DirectedWaypoint& wp : waypoints) {
134  if (wp.id().Valid()) {
135  num_valid++;
136  if (num_valid == 2) {
137  return;
138  }
139  }
140  }
141  throw std::runtime_error("Insufficient valid waypoints.");
142  }
143 
144  // TODO(@agalbachicar) Uniqueness of the id_, when it is valid, should be
145  // verified and guaranteed.
146  // The ID.
147  std::string id_;
148  // A vector that holds the sequence of the DirectedWaypoints.
149  std::vector<DirectedWaypoint> waypoints_;
150  // The width of the connection.
151  double width_{};
152  // A boolean that tells if this connection has an inverse direction relative
153  // to another connection in the same RNDF segment and that
154  // represents the first lane in the segment.
155  bool inverse_direction_{false};
156 };
157 
158 } // namespace rndf
159 } // namespace maliput
160 } // namespace drake
void set_inverse_direction(bool inverse_direction)
Setter of inverse_direction.
Definition: connection.h:120
Provides a convenient wrapper to throw an exception when a condition is unmet.
double position
Definition: system_identification_test.cc:205
Definition: automotive_demo.cc:88
void AddWaypoint(const DirectedWaypoint &waypoint, int position)
Adds a waypoint to the DirectedWaypoint vector at position index.
Definition: connection.cc:7
STL namespace.
const DirectedWaypoint & end() const
Getter of the last item in the vector returned by waypoints().
Definition: connection.h:73
bool inverse_direction() const
Getter of inverse_direction.
Definition: connection.h:114
const std::vector< DirectedWaypoint > & waypoints() const
Getter of the DirectedWaypoint vector.
Definition: connection.h:77
#define DRAKE_THROW_UNLESS(condition)
Evaluates condition and iff the value is false will throw an exception with a message showing at leas...
Definition: drake_throw.h:23
A container that holds the information needed by a Builder to construct a Lane from a sequence of ign...
Definition: directed_waypoint.h:17
std::vector< double > vector
Definition: translator_test.cc:20
void set_waypoints(const std::vector< DirectedWaypoint > &waypoints)
Setter of the DirectedWaypoint vector.
Definition: connection.h:83
#define DRAKE_DEFAULT_COPY_AND_MOVE_AND_ASSIGN(Classname)
DRAKE_DEFAULT_COPY_AND_MOVE_AND_ASSIGN defaults the special member functions for copy-construction, copy-assignment, move-construction, and move-assignment.
Definition: drake_copyable.h:59
const DirectedWaypoint & start() const
Getter of the first item in the vector returned by waypoints().
Definition: connection.h:68
const std::string & id() const
Getter of the ID.
Definition: connection.h:63
double width() const
Getter for the width.
Definition: connection.h:99
A container that holds the information needed by a Builder to construct one or more Lane objects...
Definition: connection.h:36
Provides careful macros to selectively enable or disable the special member functions for copy-constr...
void set_width(double width)
Setter for the width.
Definition: connection.h:105