85 auto elevation = std::make_unique<RoadInfoElevation>(s, a, b, c, d);
98 auto shape = std::make_unique<RoadInfoLateralShape>(s, t, a, b, c, d);
104 const std::string name,
107 const double zOffset,
111 const std::string orientation,
114 const std::vector<road::element::CrosswalkPoint> points) {
116 auto cross = std::make_unique<RoadInfoCrosswalk>(s, name, t, zOffset, hdg, pitch, roll, std::move(orientation), width, length, std::move(points));
124 const std::string restriction) {
144 const double outer) {
152 const std::string surface,
153 const double friction,
154 const double roughness) {
163 const std::string value) {
171 const double forward,
174 const double right) {
193 const int road_mark_id,
195 const std::string type,
196 const std::string weight,
197 const std::string color,
198 const std::string material,
200 std::string lane_change,
202 const std::string type_name,
203 const double type_width,
210 if (lane_change ==
"increase") {
211 lc = RoadInfoMarkRecord::LaneChange::Increase;
212 }
else if (lane_change ==
"decrease") {
213 lc = RoadInfoMarkRecord::LaneChange::Decrease;
214 }
else if (lane_change ==
"none") {
215 lc = RoadInfoMarkRecord::LaneChange::None;
217 lc = RoadInfoMarkRecord::LaneChange::Both;
221 material, width, lc, height, type_name, type_width, is_rht));
226 const int road_mark_id,
229 const double tOffset,
231 const std::string rule,
232 const double width) {
235 for (; !it.IsAtEnd(); ++it) {
236 if (it->GetRoadMarkId() == road_mark_id) {
237 it->GetLines().emplace_back(std::make_unique<RoadInfoMarkTypeLine>(s, road_mark_id, length, space,
238 tOffset, rule, width));
249 const std::string ) {
260 const std::string name,
261 const std::string dynamic,
262 const std::string orientation,
263 const double zOffset,
264 const std::string country,
265 const std::string type,
266 const std::string subtype,
268 const std::string unit,
271 const std::string text,
272 const double hOffset,
308 signal->_using_inertial_position =
true;
321 const double zOffset,
322 const double hOffset,
329 signal->_zOffset = zOffset;
330 signal->_hOffset = hOffset;
331 signal->_pitch = pitch;
332 signal->_roll = roll;
338 const double s_position,
339 const double t_position,
340 const std::string signal_reference_orientation) {
342 const double epsilon = 0.00001;
347 signal_id,
road->GetId(), fixed_s, t_position, signal_reference_orientation));
351 return road_info_signal;
363 const std::string dependency_id,
364 const std::string dependency_type) {
374 const std::string name,
375 const std::string orientation,
376 const std::string type,
377 const double zOffset,
400 const double epsilon = 0.00001;
405 stencil_id,
road->GetId(), fixed_s, t, orientation));
409 return road_info_stencil;
415 const std::string name,
430 road->_length = length;
431 road->_junction_id = junction_id;
432 (junction_id != -1) ?
road->_is_junction =
true :
road->_is_junction =
false;
433 road->_is_rht = is_rht;
434 road->_successor = successor;
435 road->_predecessor = predecessor;
452 const int32_t lane_id,
453 const uint32_t lane_type,
454 const bool lane_level,
455 const int32_t predecessor,
456 const int32_t successor) {
460 auto *lane = &((section->
_lanes.emplace(lane_id,
Lane()).first)->second);
464 lane->_lane_section = section;
465 lane->_level = lane_level;
467 lane->_successor = successor;
468 lane->_predecessor = predecessor;
479 const double length) {
481 const geom::Location location(
static_cast<float>(
x),
static_cast<float>(
y), 0.0f);
482 auto line_geometry = std::make_unique<GeometryLine>(
489 std::move(line_geometry))));
497 const std::string ) {
520 const double curvature) {
522 const geom::Location location(
static_cast<float>(
x),
static_cast<float>(
y), 0.0f);
523 auto arc_geometry = std::make_unique<GeometryArc>(
531 std::move(arc_geometry))));
541 const double curvStart,
542 const double curvEnd) {
545 const geom::Location location(
static_cast<float>(
x),
static_cast<float>(
y), 0.0f);
546 auto spiral_geometry = std::make_unique<GeometrySpiral>(
555 std::move(spiral_geometry))));
571 const geom::Location location(
static_cast<float>(
x),
static_cast<float>(
y), 0.0f);
572 auto poly3_geometry = std::make_unique<GeometryPoly3>(
582 std::move(poly3_geometry))));
600 const std::string p_range) {
603 if(p_range ==
"arcLength"){
609 const geom::Location location(
static_cast<float>(
x),
static_cast<float>(
y), 0.0f);
610 auto parampoly3_geometry = std::make_unique<GeometryParamPoly3>(
625 std::move(parampoly3_geometry))));
634 const ConId connection_id,
635 const RoadId incoming_road,
636 const RoadId connecting_road) {
644 const ConId connection_id,
653 std::set<road::ContId>&& controllers) {
679 bool from_start =
false;
680 if (
road.IsRHT() && lane_id <= 0){
682 }
else if (!
road.IsRHT() && lane_id >= 0){
689 section =
road.GetStartSection(lane_id);
691 section =
road.GetEndSection(lane_id);
696 return section->
GetLane(lane_id);
705 std::vector<Lane *> result;
723 next_road =
road.GetSuccessor();
726 next_road =
road.GetPredecessor();
738 if (next != 0 || (lane_id == 0 && next == 0)) {
741 result.push_back(
road.GetNextLane(s, next));
743 result.push_back(
road.GetPrevLane(s, next));
746 }
else if (!next_is_junction) {
748 if (next != 0 || (lane_id == 0 && next == 0)) {
757 auto next_road_as_junction =
static_cast<JuncId>(next_road);
759 for (
auto opt : options) {
772 std::vector<std::pair<RoadId, const Lane*>> result;
781 for (
auto con :
junction->_connections) {
782 auto conn_road =
GetRoad(con.second.connecting_road);
783 auto conn_id = conn_road->_id;
785 auto road_pred = conn_road->_predecessor;
786 auto road_succ = conn_road->_successor;
788 for (
auto lane : conn_road->GetLanesAt(0)){
789 if (lane_id == lane.second->_predecessor){
790 result.push_back(std::make_pair(conn_id, lane.second));
796 for (
auto lane : conn_road->GetLanesAt(conn_road->GetLength())){
797 if (lane_id == lane.second->_successor){
798 result.push_back(std::make_pair(conn_id, lane.second));
811 for (
auto §ion :
road.second._lane_sections) {
812 for (
auto &lane : section.second._lanes) {
815 lane.second._next_lanes =
GetLaneNext(
road.first, section.second._id, lane.first);
818 for (
auto next_lane : lane.second._next_lanes) {
821 next_lane->_prev_lanes.push_back(&lane.second);
830 for (
auto §ion :
road.second._lane_sections) {
831 for (
auto &lane : section.second._lanes) {
834 for (
auto next_lane : lane.second._next_lanes) {
837 if (next_lane->GetRoad() != &
road.second) {
838 if (std::find(
road.second._nexts.begin(),
road.second._nexts.end(),
839 next_lane->GetRoad()) ==
road.second._nexts.end()) {
840 road.second._nexts.push_back(next_lane->GetRoad());
846 for (
auto prev_lane : lane.second._prev_lanes) {
849 if (prev_lane->GetRoad() != &
road.second) {
850 if (std::find(
road.second._prevs.begin(),
road.second._prevs.end(),
851 prev_lane->GetRoad()) ==
road.second._prevs.end()) {
852 road.second._prevs.push_back(prev_lane->GetRoad());
865 for (
auto §ion :
road.second._lane_sections) {
866 for (
auto &lane : section.second._lanes) {
867 std::cout <<
"\nLane: " <<
road.first <<
"_" << section.first <<
"_" << lane.first << std::endl;
868 for (
auto next_lane : lane.second._next_lanes) {
869 std::cout <<
"Next lane: " << next_lane->GetRoad()->GetId() <<
"_" << next_lane->GetLaneSection()->_id <<
"_" << next_lane->_id << std::endl;
871 for (
auto prev_lanes : lane.second._prev_lanes) {
872 std::cout <<
"Prev lane: " << prev_lanes->GetRoad()->GetId() <<
"_" << prev_lanes->GetLaneSection()->_id <<
"_" << prev_lanes->_id << std::endl;
882 point.location.y *= -1;
883 point.location.z +=
static_cast<float>(signal->_zOffset);
894 point.location.y *= -1;
895 point.location.z +=
static_cast<float>(stencil->GetZOffset());
905 signal_reference->_signal =
910 auto& signal = signal_pair.second;
911 if (signal->_using_inertial_position) {
916 transform.location = transform.location +
919 signal->_transform = transform;
930 stencil_reference->_stencil =
936 auto& stencil = stencil_pair.second;
938 stencil->_transform = transform;
947 for(
const auto& controller :
junction.second._controllers) {
950 if( it->second !=
nullptr ){
951 it->second->_junctions.insert(
junction.first);
952 for(
const auto & signal : it->second->_signals) {
954 if( signal_it->second !=
nullptr ){
955 signal_it->second->_controllers.insert(controller);
968 const int number_intervals = 10;
970 float minx = std::numeric_limits<float>::max();
971 float miny = std::numeric_limits<float>::max();
972 float minz = std::numeric_limits<float>::max();
973 float maxx = -std::numeric_limits<float>::max();
974 float maxy = -std::numeric_limits<float>::max();
975 float maxz = -std::numeric_limits<float>::max();
978 if (position.x < minx) {
981 if (position.y < miny) {
984 if (position.z < minz) {
988 if (position.x > maxx) {
991 if (position.y > maxy) {
994 if (position.z > maxz) {
999 for (
auto &waypoint_p : waypoints) {
1000 auto &waypoint_start = waypoint_p.first;
1001 auto &waypoint_end = waypoint_p.second;
1002 double interval = (waypoint_end.s - waypoint_start.s) /
static_cast<double>(number_intervals);
1003 auto next_wp = waypoint_end;
1006 get_min_max(location);
1008 next_wp = waypoint_start;
1011 get_min_max(location);
1013 for (
int i = 0; i < number_intervals; ++i) {
1014 if (interval < std::numeric_limits<double>::epsilon())
1016 auto next = map.
GetNext(next_wp, interval);
1018 next_wp = next.back();
1022 get_min_max(location);
1033 const ContId controller_id,
1034 const std::string controller_name,
1035 const uint32_t controller_sequence,
1036 const std::set<road::SignId>&& signals) {
1042 std::make_unique<Controller>(controller_id, controller_name, controller_sequence)));
1048 controller_pair.first->second->_signals = std::move(signals);
1052 for(
auto signal: signals) {
1053 auto it = signals_map.find(signal);
1054 if(it != signals_map.end()) {
1055 it->second->_controllers.insert(signal);
1062 auto&
junction = junctionpair.second;
1069 if (signal_reference->_validities.size() == 0) {
1071 auto lanes =
road->GetLanesByDistance(signal_reference->GetS());
1072 switch (signal_reference->GetOrientation()) {
1076 for (
const auto* lane : lanes) {
1077 auto lane_id = lane->GetId();
1078 if(lane_id > max_lane) {
1082 if(min_lane <= max_lane) {
1090 for (
const auto* lane : lanes) {
1091 auto lane_id = lane->GetId();
1092 if(lane_id < min_lane) {
1096 if(min_lane <= max_lane) {
1105 for (
const auto* lane : lanes) {
1106 auto lane_id = lane->GetId();
1107 if(lane_id > max_lane) {
1111 if(min_lane <= max_lane) {
1118 for (
const auto* lane : lanes) {
1119 auto lane_id = lane->GetId();
1120 if(lane_id < min_lane) {
1124 if(min_lane <= max_lane) {
1135 std::vector<element::RoadInfoSignal*> elements_to_remove;
1137 bool should_remove =
true;
1138 for (
auto & lane_validity : signal_reference->_validities) {
1139 if ( (lane_validity._from_lane != 0) ||
1140 (lane_validity._to_lane != 0)) {
1141 should_remove =
false;
1145 if (signal_reference->_validities.size() == 0) {
1146 should_remove =
false;
1148 if (should_remove) {
1149 elements_to_remove.push_back(signal_reference);
1152 for (
auto* element : elements_to_remove) {
1153 auto road_id = element->GetRoadId();
1155 road_info.erase(std::remove_if(road_info.begin(), road_info.end(),
1156 [=] (
auto& info_ptr) {
1157 return (info_ptr.get() == element);
1158 }), road_info.end());
1167 auto& signal = signal_pair.second;
1168 auto signal_position = signal->GetTransform().location;
1169 auto signal_rotation = signal->GetTransform().rotation;
1170 auto closest_waypoint_to_signal =
1175 signal->GetName().find(
"Stencil_STOP") != std::string::npos ||
1176 signal->GetName().find(
"STATIC") != std::string::npos ||
1177 signal->_using_inertial_position) {
1180 if(closest_waypoint_to_signal) {
1181 auto road_transform = map.
ComputeTransform(closest_waypoint_to_signal.value());
1182 auto distance_to_road = (road_transform.location -signal_position).Length();
1183 double lane_width = map.
GetLaneWidth(closest_waypoint_to_signal.value());
1185 int displacement_direction = 1;
1189 while(distance_to_road < (lane_width * 0.7) && iter < MaxIter && displacement_direction != 0) {
1192 signal->GetSignalId(),
1193 "overlaps a driving lane. Moving out of the road...");
1196 auto right_waypoint = map.
GetRight(closest_waypoint_to_signal.value());
1199 auto left_waypoint = map.
GetLeft(closest_waypoint_to_signal.value());
1205 displacement_direction = 1;
1207 displacement_direction = -1;
1209 displacement_direction = 0;
1214 displacement_direction = -1;
1216 displacement_direction = 1;
1218 displacement_direction = 0;
1222 geom::Vector3D displacement = 1.f*(road_transform.GetRightVector()) *
1223 static_cast<float>(abs(lane_width))*0.2f;
1224 signal_position += (displacement *
static_cast<float>(displacement_direction));
1225 signal_rotation = road_transform.rotation;
1226 closest_waypoint_to_signal =
1231 signal_position).Length();
1232 lane_width = map.
GetLaneWidth(closest_waypoint_to_signal.value());
1235 if(iter == MaxIter) {
1236 log_debug(
"Failed to find suitable place for signal.");
1239 signal->_transform.location = signal_position;
1240 signal->_transform.rotation = signal_rotation;
#define DEBUG_ASSERT(predicate)
#define RELEASE_ASSERT(pred)
std::map< std::string, unsigned int > road
std::map< std::string, unsigned int > junction
static void ToLower(WritableRangeT &str)
static constexpr T ToDegrees(T rad)
static constexpr T Clamp(T a, T min=T(0), T max=T(1))
Euler angles of a rotation in CARLA's / Unreal's left-handed frame: x forward, y right,...
Connection * GetConnection(ConId id)
std::set< ContId > _controllers
std::unordered_map< ConId, Connection > & GetConnections()
double GetDistance() const
Lane * GetLane(const LaneId id)
std::map< LaneId, Lane > _lanes
LaneType
Can be used as flags.
LaneId GetPredecessor() const
LaneId GetSuccessor() const
bool IsPositiveDirection() const
std::unordered_map< SignId, std::unique_ptr< Signal > > _temp_signal_container
Lane * GetEdgeLanePointer(RoadId road_id, LaneId lane_id)
Return the pointer to a lane object.
void AddRoadGeometryArc(carla::road::Road *road, const double s, const double x, const double y, const double hdg, const double length, const double curvature)
std::vector< element::RoadInfoStencil * > _temp_stencil_reference_container
element::RoadInfoStencil * AddStencil(Road *road, const StencilId stencil_id, const double s, const double t, const std::string name, const std::string orientation, const std::string type, const double zOffset, const double heading, const double length, const double width, const double pitch, const double roll)
void CreateController(const ContId controller_id, const std::string controller_name, const uint32_t controller_sequence, const std::set< road::SignId > &&signals)
carla::road::Lane * AddRoadSectionLane(carla::road::LaneSection *section, const LaneId lane_id, const uint32_t lane_type, const bool lane_level, const LaneId predecessor, const LaneId successor)
void SolveStencilReferencesAndTransforms()
Solves the stencil references in the road.
void AddSignalPositionRoad(const SignId signal_id, const RoadId road_id, const double s, const double t, const double zOffset, const double hOffset, const double pitch, const double roll)
void AddSignalPositionInertial(const SignId signal_id, const double x, const double y, const double z, const double hdg, const double pitch, const double roll)
void CreateRoadSpeed(Road *road, const double s, const std::string type, const double max, const std::string unit)
void DebugRoadConnections()
Debug the built connections through the terminal.
void CreateSectionOffset(Road *road, const double s, const double a, const double b, const double c, const double d)
void AddJunctionController(const JuncId junction_id, std::set< ContId > &&controllers)
carla::road::LaneSection * AddRoadSection(carla::road::Road *road, const SectionId id, const double s)
void CreateRoadMark(Lane *lane, const int road_mark_id, const double s, const std::string type, const std::string weight, const std::string color, const std::string material, const double width, const std::string lane_change, const double height, const std::string type_name, const double type_width, const bool is_rht)
void CreateLaneAccess(Lane *lane, const double s, const std::string restriction)
void AddRoadLateralShape(Road *road, const double s, const double a, const double b, const double c, const double d, const double t)
void AddRoadObjectCrosswalk(Road *road, const std::string name, const double s, const double t, const double zOffset, const double hdg, const double pitch, const double roll, const std::string orientation, const double width, const double length, const std::vector< road::element::CrosswalkPoint > points)
geom::Transform ComputeStencilTransform(std::unique_ptr< Stencil > &stencil, MapData &data)
void CreateLaneHeight(Lane *lane, const double s, const double inner, const double outer)
geom::Transform ComputeSignalTransform(std::unique_ptr< Signal > &signal, MapData &data)
Lane * GetLane(const RoadId road_id, const LaneId lane_id, const double s)
void CreateLaneBorder(Lane *lane, const double s, const double a, const double b, const double c, const double d)
std::unordered_map< StencilId, std::unique_ptr< Stencil > > _temp_stencil_container
void ComputeJunctionRoadConflicts(Map &map)
Compute the conflicts of the roads (intersecting roads)
void AddValidityToSignalReference(element::RoadInfoSignal *signal_reference, const LaneId from_lane, const LaneId to_lane)
std::optional< Map > Build()
void CreateLaneRule(Lane *lane, const double s, const std::string value)
void SolveControllerAndJuntionReferences()
Solve the references between Controllers and Juntions.
void AddRoadElevationProfile(Road *road, const double s, const double a, const double b, const double c, const double d)
void AddJunction(const JuncId id, const std::string name)
void CreateLaneSpeed(Lane *lane, const double s, const double max, const std::string unit)
std::unordered_map< Road *, std::vector< std::unique_ptr< element::RoadInfo > > > _temp_road_info_container
Map to temporary store all the road and lane infos until the map is built, so they can be added all t...
void AddLaneLink(const JuncId junction_id, const ConId connection_id, const LaneId from, const LaneId to)
void AddDependencyToSignal(const SignId signal_id, const std::string dependency_id, const std::string dependency_type)
void AddRoadGeometryParamPoly3(carla::road::Road *road, const double s, const double x, const double y, const double hdg, const double length, const double aU, const double bU, const double cU, const double dU, const double aV, const double bV, const double cV, const double dV, const std::string p_range)
void RemoveZeroLaneValiditySignalReferences()
Removes signal references with lane validity equal to [0,0] as they have no effect on any road.
void CreateRoadMarkTypeLine(Lane *lane, const int road_mark_id, const double length, const double space, const double tOffset, const double s, const std::string rule, const double width)
void CreateJunctionBoundingBoxes(Map &map)
Create the bounding boxes of each junction.
element::RoadInfoSignal * AddSignalReference(Road *road, const SignId signal_id, const double s_position, const double t_position, const std::string signal_reference_orientation)
std::unordered_map< Lane *, std::vector< std::unique_ptr< element::RoadInfo > > > _temp_lane_info_container
std::vector< element::RoadInfoSignal * > _temp_signal_reference_container
void AddRoadGeometryPoly3(carla::road::Road *road, const double s, const double x, const double y, const double hdg, const double length, const double a, const double b, const double c, const double d)
void GenerateDefaultValiditiesForSignalReferences()
Generates a default validity field for signal references with missing validity record in OpenDRIVE.
carla::road::Road * AddRoad(const RoadId road_id, const std::string name, const double length, const JuncId junction_id, const RoadId predecessor, const RoadId successor, const bool is_rht)
void AddConnection(const JuncId junction_id, const ConId connection_id, const RoadId incoming_road, const RoadId connecting_road)
element::RoadInfoSignal * AddSignal(Road *road, const SignId signal_id, const double s, const double t, const std::string name, const std::string dynamic, const std::string orientation, const double zOffset, const std::string country, const std::string type, const std::string subtype, const double value, const std::string unit, const double height, const double width, const std::string text, const double hOffset, const double pitch, const double roll)
std::vector< Lane * > GetLaneNext(RoadId road_id, SectionId section_id, LaneId lane_id)
Return a list of pointers to all lanes from a lane (using road and junction info).
void CreateLaneWidth(Lane *lane, const double s, const double a, const double b, const double c, const double d)
std::vector< std::pair< RoadId, const Lane * > > GetJunctionLanes(JuncId junction_id, RoadId road_id, LaneId lane_id)
void SolveSignalReferencesAndTransforms()
Solves the signal references in the road.
void CreateLaneVisibility(Lane *lane, const double s, const double forward, const double back, const double left, const double right)
void CreatePointersBetweenRoadSegments()
Create the pointers between RoadSegments based on the ids.
Road * GetRoad(const RoadId road_id)
void CreateLaneMaterial(Lane *lane, const double s, const std::string surface, const double friction, const double roughness)
void CheckSignalsOnRoads(Map &map)
Checks signals overlapping driving lanes and emits a warning.
void AddRoadGeometrySpiral(carla::road::Road *road, const double s, const double x, const double y, const double hdg, const double length, const double curvStart, const double curvEnd)
void AddRoadGeometryLine(carla::road::Road *road, const double s, const double x, const double y, const double hdg, const double length)
std::unordered_map< RoadId, Road > _roads
std::unordered_map< StencilId, std::unique_ptr< Stencil > > _stencils
Road & GetRoad(const RoadId id)
std::unordered_map< ContId, std::unique_ptr< Controller > > _controllers
std::unordered_map< JuncId, Junction > _junctions
bool ContainsRoad(RoadId id) const
std::unordered_map< JuncId, Junction > & GetJunctions()
Junction * GetJunction(JuncId id)
std::unordered_map< SignId, std::unique_ptr< Signal > > _signals
std::optional< Waypoint > GetLeft(Waypoint waypoint) const
Return a waypoint at the lane of waypoint's left lane.
Lane::LaneType GetLaneType(Waypoint waypoint) const
double GetLaneWidth(Waypoint waypoint) const
std::vector< Waypoint > GetNext(Waypoint waypoint, double distance) const
Return the list of waypoints at distance such that a vehicle at waypoint could drive to.
std::optional< Waypoint > GetRight(Waypoint waypoint) const
Return a waypoint at the lane of waypoint's right lane.
Junction * GetJunction(JuncId id)
std::optional< element::Waypoint > GetClosestWaypointOnRoad(const geom::Location &location, int32_t lane_type=static_cast< int32_t >(Lane::LaneType::Driving)) const
========================================================================
geom::Transform ComputeTransform(Waypoint waypoint) const
std::vector< std::pair< Waypoint, Waypoint > > GetJunctionWaypoints(JuncId id, Lane::LaneType lane_type) const
Generate waypoints of the junction.
std::unordered_map< road::RoadId, std::unordered_set< road::RoadId > > ComputeJunctionConflicts(JuncId id) const
const Lane & GetLane(Waypoint waypoint) const
========================================================================
Lane & GetLaneByDistance(double s, LaneId lane_id)
element::DirectedPoint GetDirectedPointInNoLaneOffset(const double s) const
Returns a directed point on the center of the road (lane 0), with the corresponding laneOffset and el...
static bool IsTrafficLight(const std::string &type)
LaneChange
Can be used as flags.
std::vector< LaneValidity > _validities
This file contains definitions of common data structures used in traffic manager.
static void log_debug(Args &&... args)
void AddLaneLink(LaneId from, LaneId to)
void ApplyLateralOffset(float lateral_offset)