CARLA
Lane.h
Go to the documentation of this file.
1 // Copyright (c) 2020 Computer Vision Center (CVC) at the Universitat Autonoma
2 // de Barcelona (UAB).
3 //
4 // This work is licensed under the terms of the MIT license.
5 // For a copy, see <https://opensource.org/licenses/MIT>.
6 
7 #pragma once
8 
9 #include "carla/geom/Mesh.h"
10 #include "carla/geom/Transform.h"
12 #include "carla/road/RoadTypes.h"
13 
14 #include <vector>
15 #include <iostream>
16 #include <memory>
17 
18 namespace carla {
19 namespace road {
20 
21  class LaneSection;
22  class MapBuilder;
23  class Road;
24 
25  class Lane : private MovableNonCopyable {
26  public:
27 
28  /// Can be used as flags
29  enum class LaneType : int32_t {
30  None = 0x1,
31  Driving = 0x1 << 1,
32  Stop = 0x1 << 2,
33  Shoulder = 0x1 << 3,
34  Biking = 0x1 << 4,
35  Sidewalk = 0x1 << 5,
36  Border = 0x1 << 6,
37  Restricted = 0x1 << 7,
38  Parking = 0x1 << 8,
39  Bidirectional = 0x1 << 9,
40  Median = 0x1 << 10,
41  Special1 = 0x1 << 11,
42  Special2 = 0x1 << 12,
43  Special3 = 0x1 << 13,
44  RoadWorks = 0x1 << 14,
45  Tram = 0x1 << 15,
46  Rail = 0x1 << 16,
47  Entry = 0x1 << 17,
48  Exit = 0x1 << 18,
49  OffRamp = 0x1 << 19,
50  OnRamp = 0x1 << 20,
51  Any = -2 // 0xFFFFFFFE
52  };
53 
54  public:
55 
56  Lane() = default;
57 
59  LaneSection *lane_section,
60  LaneId id,
61  std::vector<std::unique_ptr<element::RoadInfo>> &&info)
62  : _lane_section(lane_section),
63  _id(id),
64  _info(std::move(info)) {
65  DEBUG_ASSERT(lane_section != nullptr);
66  }
67 
68  const LaneSection *GetLaneSection() const;
69 
70  Road *GetRoad() const;
71 
72  LaneId GetId() const;
73 
74  LaneType GetType() const;
75 
76  bool GetLevel() const;
77 
78  template <typename T>
79  const T *GetInfo(const double s) const {
80  DEBUG_ASSERT(_lane_section != nullptr);
81  return _info.GetInfo<T>(s);
82  }
83 
84  template <typename T>
85  std::vector<const T*> GetInfos() const {
86  DEBUG_ASSERT(_lane_section != nullptr);
87  return _info.GetInfos<T>();
88  }
89 
90  const std::vector<Lane *> &GetNextLanes() const {
91  return _next_lanes;
92  }
93 
94  const std::vector<Lane *> &GetPreviousLanes() const {
95  return _prev_lanes;
96  }
97 
98  LaneId GetSuccessor() const {
99  return _successor;
100  }
101 
103  return _predecessor;
104  }
105 
106  double GetDistance() const;
107 
108  double GetLength() const;
109 
110  /// Returns the total lane width given a s
111  double GetWidth(const double s) const;
112 
113  /// Checks whether the geometry is straight or not
114  bool IsStraight() const;
115 
116  geom::Transform ComputeTransform(const double s) const;
117 
118  /// Computes the location of the edges given a s
119  std::pair<geom::Vector3D, geom::Vector3D> GetCornerPositions(
120  const double s, const float extra_width = 0.f) const;
121 
122  private:
123 
124  friend MapBuilder;
125 
127 
128  LaneId _id = 0;
129 
131 
133 
134  bool _level = false;
135 
137 
139 
140  std::vector<Lane *> _next_lanes;
141 
142  std::vector<Lane *> _prev_lanes;
143  };
144 
145 } // road
146 } // carla
LaneType GetType() const
Definition: Lane.cpp:38
LaneType _type
Definition: Lane.h:132
Road * GetRoad() const
Definition: Lane.cpp:29
double GetDistance() const
Definition: Lane.cpp:46
double GetLength() const
Definition: Lane.cpp:51
This file contains definitions of common data structures used in traffic manager. ...
Definition: Carla.cpp:133
const std::vector< Lane * > & GetPreviousLanes() const
Definition: Lane.h:94
InformationSet _info
Definition: Lane.h:130
double GetWidth(const double s) const
Returns the total lane width given a s.
Definition: Lane.cpp:58
LaneId GetPredecessor() const
Definition: Lane.h:102
Lane(LaneSection *lane_section, LaneId id, std::vector< std::unique_ptr< element::RoadInfo >> &&info)
Definition: Lane.h:58
std::vector< Lane * > _next_lanes
Definition: Lane.h:140
#define DEBUG_ASSERT(predicate)
Definition: Debug.h:66
LaneSection * _lane_section
Definition: Lane.h:126
const T * GetInfo(const double s) const
Returns single info given a type and a distance (s) from the start of the road.
Inherit (privately) to suppress copy construction and assignment.
LaneId GetSuccessor() const
Definition: Lane.h:98
friend MapBuilder
Definition: Lane.h:124
LaneType
Can be used as flags.
Definition: Lane.h:29
int32_t LaneId
Definition: RoadTypes.h:19
LaneId _id
Definition: Lane.h:128
const std::vector< Lane * > & GetNextLanes() const
Definition: Lane.h:90
const T * GetInfo(const double s) const
Definition: Lane.h:79
std::vector< const T * > GetInfos() const
Return all infos given a type from the start of the road.
bool IsStraight() const
Checks whether the geometry is straight or not.
Definition: Lane.cpp:67
geom::Transform ComputeTransform(const double s) const
Definition: Lane.cpp:131
LaneId _predecessor
Definition: Lane.h:138
LaneId _successor
Definition: Lane.h:136
std::vector< Lane * > _prev_lanes
Definition: Lane.h:142
bool GetLevel() const
Definition: Lane.cpp:42
std::pair< geom::Vector3D, geom::Vector3D > GetCornerPositions(const double s, const float extra_width=0.f) const
Computes the location of the edges given a s.
Definition: Lane.cpp:206
std::vector< const T * > GetInfos() const
Definition: Lane.h:85
LaneId GetId() const
Definition: Lane.cpp:34
const LaneSection * GetLaneSection() const
Definition: Lane.cpp:25