From 2a7bb9e15a63beadd3c7065a0e5e13b58e906480 Mon Sep 17 00:00:00 2001 From: Axel Date: Tue, 11 Feb 2020 17:25:09 +0100 Subject: [PATCH] Removed RoadObject. Adding RoadInfoSignals. --- .../carla/opendrive/parser/ObjectParser.cpp | 2 +- .../carla/opendrive/parser/SignalParser.cpp | 68 +++--- LibCarla/source/carla/road/LaneValidity.h | 30 +++ LibCarla/source/carla/road/Map.cpp | 4 +- LibCarla/source/carla/road/MapBuilder.cpp | 225 +++++++++--------- LibCarla/source/carla/road/MapBuilder.h | 62 +++-- LibCarla/source/carla/road/MapData.h | 3 + LibCarla/source/carla/road/ObjectSet.h | 53 ----- LibCarla/source/carla/road/Road.cpp | 24 -- LibCarla/source/carla/road/Road.h | 29 --- LibCarla/source/carla/road/RoadTypes.h | 5 +- .../source/carla/road/{signal => }/Signal.h | 63 +++-- ...dObjectCrosswalk.h => RoadInfoCrosswalk.h} | 10 +- .../carla/road/element/RoadInfoSignal.h | 69 ++++++ .../carla/road/element/RoadInfoVisitor.h | 4 + .../source/carla/road/element/RoadObject.h | 43 ---- .../carla/road/element/RoadObjectIterator.h | 105 -------- .../carla/road/element/RoadObjectVisitor.h | 33 --- LibCarla/source/carla/road/general/Validity.h | 45 ---- .../carla/road/signal/SignalDependency.h | 50 ---- .../carla/road/signal/SignalReference.h | 57 ----- 21 files changed, 321 insertions(+), 663 deletions(-) create mode 100644 LibCarla/source/carla/road/LaneValidity.h delete mode 100644 LibCarla/source/carla/road/ObjectSet.h rename LibCarla/source/carla/road/{signal => }/Signal.h (71%) rename LibCarla/source/carla/road/element/{RoadObjectCrosswalk.h => RoadInfoCrosswalk.h} (90%) create mode 100644 LibCarla/source/carla/road/element/RoadInfoSignal.h delete mode 100644 LibCarla/source/carla/road/element/RoadObject.h delete mode 100644 LibCarla/source/carla/road/element/RoadObjectIterator.h delete mode 100644 LibCarla/source/carla/road/element/RoadObjectVisitor.h delete mode 100644 LibCarla/source/carla/road/general/Validity.h delete mode 100644 LibCarla/source/carla/road/signal/SignalDependency.h delete mode 100644 LibCarla/source/carla/road/signal/SignalReference.h diff --git a/LibCarla/source/carla/opendrive/parser/ObjectParser.cpp b/LibCarla/source/carla/opendrive/parser/ObjectParser.cpp index 04150a02a..620898a1b 100644 --- a/LibCarla/source/carla/opendrive/parser/ObjectParser.cpp +++ b/LibCarla/source/carla/opendrive/parser/ObjectParser.cpp @@ -7,7 +7,7 @@ #include "carla/opendrive/parser/ObjectParser.h" #include "carla/road/MapBuilder.h" -#include "carla/road/element/RoadObjectCrosswalk.h" +#include "carla/road/element/RoadInfoCrosswalk.h" #include "carla/road/Road.h" #include diff --git a/LibCarla/source/carla/opendrive/parser/SignalParser.cpp b/LibCarla/source/carla/opendrive/parser/SignalParser.cpp index af59967c9..27f87fcb5 100644 --- a/LibCarla/source/carla/opendrive/parser/SignalParser.cpp +++ b/LibCarla/source/carla/opendrive/parser/SignalParser.cpp @@ -14,44 +14,40 @@ namespace carla { namespace opendrive { namespace parser { - using RoadID = uint32_t; - using SignalID = uint32_t; - using DependencyID = uint32_t; - - template static void AddValidity( - pugi::xml_node parent_node, - const std::string &node_name, - const RoadID roadID, - const SignalID &signalID, - T &&function) { + road::element::RoadInfoSignal* signal_reference, + pugi::xml_node parent_node, + const std::string &node_name, + road::MapBuilder &map_builder) { for (pugi::xml_node validity_node = parent_node.child(node_name.c_str()); validity_node; validity_node = validity_node.next_sibling("validity")) { - const auto from_lane = static_cast(validity_node.attribute("fromLane").as_int()); - const auto to_lane = static_cast(validity_node.attribute("toLane").as_int()); - log_debug("Added validity to signal ", signalID, ":", from_lane, to_lane); - function(roadID, signalID, from_lane, to_lane); + const auto from_lane = validity_node.attribute("fromLane").as_int(); + const auto to_lane = validity_node.attribute("toLane").as_int(); + map_builder.AddValidityToSignalReference(signal_reference, from_lane, to_lane); } } void SignalParser::Parse( const pugi::xml_document &xml, carla::road::MapBuilder &map_builder) { + // Extracting the OpenDRIVE const pugi::xml_node opendrive_node = xml.child("OpenDRIVE"); const std::string validity = "validity"; for (pugi::xml_node road_node = opendrive_node.child("road"); road_node; road_node = road_node.next_sibling("road")) { - const RoadID road_id = static_cast(road_node.attribute("id").as_int()); + + road::RoadId road_id = road_node.attribute("id").as_uint(); + const pugi::xml_node signals_node = road_node.child("signals"); for (pugi::xml_node signal_node = signals_node.child("signal"); signal_node; signal_node = signal_node.next_sibling("signal")) { const double s_position = signal_node.attribute("s").as_double(); const double t_position = signal_node.attribute("t").as_double(); - const SignalID signal_id = static_cast(signal_node.attribute("id").as_int()); + const road::SignId signal_id = signal_node.attribute("id").value(); const std::string name = signal_node.attribute("name").value(); const std::string dynamic = signal_node.attribute("dynamic").value(); const std::string orientation = signal_node.attribute("orientation").value(); @@ -88,7 +84,9 @@ namespace parser { hOffset, pitch, roll); - map_builder.AddSignal(road_id, + + carla::road::Road *road = map_builder.GetRoad(road_id); + auto signal_reference = map_builder.AddSignal(road, signal_id, s_position, t_position, @@ -107,45 +105,39 @@ namespace parser { hOffset, pitch, roll); - AddValidity(signal_node, "validity", road_id, signal_id, - ([&map_builder](auto &&... args) - { map_builder.AddValidityToSignal(args...); - })); + AddValidity(signal_reference, signal_node, "validity", map_builder); for (pugi::xml_node dependency_node = signal_node.child("dependency"); dependency_node; dependency_node = dependency_node.next_sibling("validity")) { - const DependencyID dependency_id = dependency_node.attribute("id").as_uint(); + const std::string dependency_id = dependency_node.attribute("id").value(); const std::string dependency_type = dependency_node.attribute("type").value(); log_debug("Added dependency to signal ", signal_id, ":", dependency_id, dependency_type); - map_builder.AddDependencyToSignal(road_id, signal_id, dependency_id, dependency_type); + map_builder.AddDependencyToSignal(signal_id, dependency_id, dependency_type); } } - for (pugi::xml_node signalreference_node = signals_node.child("signalReference"); - signalreference_node; - signalreference_node = signalreference_node.next_sibling("signalReference")) { - const double s_position = signalreference_node.attribute("s").as_double(); - const double t_position = signalreference_node.attribute("t").as_double(); - const SignalID signal_reference_id = signalreference_node.attribute("id").as_uint(); + for (pugi::xml_node signal_reference_node = signals_node.child("signalReference"); + signal_reference_node; + signal_reference_node = signal_reference_node.next_sibling("signalReference")) { + const double s_position = signal_reference_node.attribute("s").as_double(); + const double t_position = signal_reference_node.attribute("t").as_double(); + const road::SignId signal_id = signal_reference_node.attribute("id").value(); const std::string signal_reference_orientation = - signalreference_node.attribute("orientation").value(); + signal_reference_node.attribute("orientation").value(); log_debug("Road: ", road_id, "Added SignalReference ", s_position, t_position, - signal_reference_id, signal_reference_orientation); - map_builder.AddSignalReference(road_id, - signal_reference_id, + carla::road::Road *road = map_builder.GetRoad(road_id); + auto signal_reference = map_builder.AddSignalReference( + road, + signal_id, s_position, t_position, signal_reference_orientation); - AddValidity(signalreference_node, validity, road_id, signal_reference_id, - ([&map_builder](const RoadID &road_id, const SignalID &signal_id, const int16_t from_lane, - const int16_t to_lane) - { map_builder.AddValidityToSignalReference(road_id, signal_id, from_lane, to_lane); - })); + AddValidity(signal_reference, signal_reference_node, "validity", map_builder); } } } diff --git a/LibCarla/source/carla/road/LaneValidity.h b/LibCarla/source/carla/road/LaneValidity.h new file mode 100644 index 000000000..b57c77944 --- /dev/null +++ b/LibCarla/source/carla/road/LaneValidity.h @@ -0,0 +1,30 @@ +// Copyright (c) 2019 Computer Vision Center (CVC) at the Universitat Autonoma +// de Barcelona (UAB). +// +// This work is licensed under the terms of the MIT license. +// For a copy; see . + +#pragma once + +#include "carla/NonCopyable.h" +#include +#include +#include "carla/road/RoadTypes.h" + +namespace carla { +namespace road { + + struct LaneValidity { + public: + + LaneValidity(LaneId from_lane, LaneId to_lane) + : _from_lane(from_lane), _to_lane(to_lane) {} + + road::LaneId _from_lane; + + road::LaneId _to_lane; + + }; + +} // road +} // carla diff --git a/LibCarla/source/carla/road/Map.cpp b/LibCarla/source/carla/road/Map.cpp index 73e9c0dd1..2d71cdedc 100644 --- a/LibCarla/source/carla/road/Map.cpp +++ b/LibCarla/source/carla/road/Map.cpp @@ -12,7 +12,7 @@ #include "carla/road/element/RoadInfoLaneWidth.h" #include "carla/road/element/RoadInfoMarkRecord.h" #include "carla/road/element/RoadInfoLaneOffset.h" -#include "carla/road/element/RoadObjectCrosswalk.h" +#include "carla/road/element/RoadInfoCrosswalk.h" #include "carla/road/element/RoadInfoElevation.h" #include "carla/geom/Math.h" @@ -419,7 +419,7 @@ namespace road { for (const auto &pair : _data.GetRoads()) { const auto &road = pair.second; - std::vector crosswalks = road.GetObjects(); + std::vector crosswalks = road.GetInfos(); if (crosswalks.size() > 0) { for (auto crosswalk : crosswalks) { // waypoint only at start position diff --git a/LibCarla/source/carla/road/MapBuilder.cpp b/LibCarla/source/carla/road/MapBuilder.cpp index 1941634c5..348141b8d 100644 --- a/LibCarla/source/carla/road/MapBuilder.cpp +++ b/LibCarla/source/carla/road/MapBuilder.cpp @@ -19,14 +19,11 @@ #include "carla/road/element/RoadInfoMarkRecord.h" #include "carla/road/element/RoadInfoMarkTypeLine.h" #include "carla/road/element/RoadInfoSpeed.h" +#include "carla/road/element/RoadInfoSignal.h" #include "carla/road/element/RoadInfoVisitor.h" -#include "carla/road/element/RoadObjectCrosswalk.h" -#include "carla/road/element/RoadObjectVisitor.h" +#include "carla/road/element/RoadInfoCrosswalk.h" #include "carla/road/InformationSet.h" -#include "carla/road/general/Validity.h" -#include "carla/road/signal/Signal.h" -#include "carla/road/signal/SignalReference.h" -#include "carla/road/signal/SignalDependency.h" +#include "carla/road/Signal.h" #include #include @@ -40,16 +37,13 @@ namespace road { CreatePointersBetweenRoadSegments(); + SolveSignalReferences(); + for (auto &&info : _temp_road_info_container) { DEBUG_ASSERT(info.first != nullptr); info.first->_info = InformationSet(std::move(info.second)); } - for (auto &&info : _temp_road_object_container) { - DEBUG_ASSERT(info.first != nullptr); - info.first->_objects = ObjectSet(std::move(info.second)); - } - for (auto &&info : _temp_lane_info_container) { DEBUG_ASSERT(info.first != nullptr); info.first->_info = InformationSet(std::move(info.second)); @@ -57,7 +51,6 @@ namespace road { // remove temporal already used information _temp_road_info_container.clear(); - _temp_road_object_container.clear(); _temp_lane_info_container.clear(); // _map_data is a memeber of MapBuilder so you must especify if @@ -96,8 +89,8 @@ namespace road { const double length, const std::vector points) { DEBUG_ASSERT(road != nullptr); - auto cross = std::make_unique(s, name, t, zOffset, hdg, pitch, roll, std::move(orientation), width, length, std::move(points)); - _temp_road_object_container[road].emplace_back(std::move(cross)); + auto cross = std::make_unique(s, name, t, zOffset, hdg, pitch, roll, std::move(orientation), width, length, std::move(points)); + _temp_road_info_container[road].emplace_back(std::move(cross)); } // called from lane parser @@ -233,66 +226,101 @@ namespace road { _temp_lane_info_container[lane].emplace_back(std::make_unique(s, max)); } - void MapBuilder::AddSignal( - const uint32_t road_id, - const uint32_t 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) { - auto signals = _map_data.GetRoad(road_id).getSignals(); - DEBUG_ASSERT(signals != nullptr); - signals->emplace(signal_id, - signal::Signal(road_id, signal_id, s, t, name, dynamic, - orientation, zOffset, country, type, subtype, value, unit, height, width, - text, hOffset, pitch, roll)); - } - void MapBuilder::AddValidityToLastAddedSignal( - const uint32_t road_id, - const uint32_t signal_id, - const int32_t from_lane, - const int32_t to_lane) { - _map_data.GetRoad(road_id).GetSignal(signal_id)->AddValidity(general::Validity(signal_id, from_lane, - to_lane)); - } + element::RoadInfoSignal* MapBuilder::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) { + _temp_signal_container[signal_id] = std::make_shared( + signal_id, + s, + t, + name, + dynamic, + orientation, + zOffset, + country, + type, + subtype, + value, + unit, + height, + width, + text, + hOffset, + pitch, + roll); - // build road objects - carla::road::Road *MapBuilder::AddRoad( - const RoadId road_id, - const std::string name, - const double length, - const JuncId junction_id, - const RoadId predecessor, - const RoadId successor) { + return AddSignalReference(road, signal_id, s, t, orientation); + } - // add it - auto road = &(_map_data._roads.emplace(road_id, Road()).first->second); + element::RoadInfoSignal* MapBuilder::AddSignalReference( + Road* road, + const SignId signal_id, + const double s_position, + const double t_position, + const std::string signal_reference_orientation) { - // set road data - road->_map_data = &_map_data; - road->_id = road_id; - road->_name = name; - road->_length = length; - road->_junction_id = junction_id; - (junction_id != -1) ? road->_is_junction = true : road->_is_junction = false; - road->_successor = successor; - road->_predecessor = predecessor; + _temp_road_info_container[road].emplace_back(std::make_unique( + signal_id, s_position, t_position, signal_reference_orientation)); + return static_cast(_temp_road_info_container[road].back().get()); + } - return road; + void MapBuilder::AddValidityToSignalReference( + element::RoadInfoSignal* signal_reference, + const LaneId from_lane, + const LaneId to_lane) { + signal_reference->_validities.emplace_back(LaneValidity(from_lane, to_lane)); + } + + void MapBuilder::AddDependencyToSignal( + const SignId signal_id, + const std::string dependency_id, + const std::string dependency_type) { + _temp_signal_container[signal_id]->_dependencies.emplace_back( + SignalDependency(dependency_id, dependency_type)); + } + + // build road objects + carla::road::Road *MapBuilder::AddRoad( + const RoadId road_id, + const std::string name, + const double length, + const JuncId junction_id, + const RoadId predecessor, + const RoadId successor) + { + + // add it + auto road = &(_map_data._roads.emplace(road_id, Road()).first->second); + + // set road data + road->_map_data = &_map_data; + road->_id = road_id; + road->_name = name; + road->_length = length; + road->_junction_id = junction_id; + (junction_id != -1) ? road->_is_junction = true : road->_is_junction = false; + road->_successor = successor; + road->_predecessor = predecessor; + + return road; } carla::road::LaneSection *MapBuilder::AddRoadSection( @@ -390,7 +418,7 @@ namespace road { } void MapBuilder::AddRoadGeometrySpiral( - carla::road::Road * road, + Road * road, const double s, const double x, const double y, @@ -414,7 +442,7 @@ namespace road { } void MapBuilder::AddRoadGeometryPoly3( - carla::road::Road * road, + Road * road, const double s, const double x, const double y, @@ -441,7 +469,7 @@ namespace road { } void MapBuilder::AddRoadGeometryParamPoly3( - carla::road::Road * road, + Road * road, const double s, const double x, const double y, @@ -506,51 +534,6 @@ namespace road { _map_data.GetJunction(junction_id)->GetConnection(connection_id)->AddLaneLink(from, to); } - void MapBuilder::AddValidityToSignal( - const uint32_t road_id, - const uint32_t signal_id, - const int32_t from_lane, - const int32_t to_lane) { - DEBUG_ASSERT(_map_data.GetRoad(road_id).GetSignal(signal_id) != nullptr); - _map_data.GetRoad(road_id).GetSignal(signal_id)->AddValidity(general::Validity(signal_id, from_lane, - to_lane)); - } - - void MapBuilder::AddValidityToSignalReference( - const uint32_t road_id, - const uint32_t signal_reference_id, - const int32_t from_lane, - const int32_t to_lane) { - DEBUG_ASSERT(_map_data.GetRoad(road_id).GetSignalRef(signal_reference_id) != nullptr); - _map_data.GetRoad(road_id).GetSignalRef(signal_reference_id)->AddValidity(general::Validity( - signal_reference_id, from_lane, to_lane)); - } - - void MapBuilder::AddSignalReference( - const uint32_t road_id, - const uint32_t signal_reference_id, - const double s_position, - const double t_position, - const std::string signal_reference_orientation) { - DEBUG_ASSERT(_map_data.GetRoad(road_id).getSignalReferences() != nullptr); - _map_data.GetRoad(road_id).getSignalReferences()->emplace(signal_reference_id, - signal::SignalReference(road_id, signal_reference_id, s_position, t_position, - signal_reference_orientation)); - } - - void MapBuilder::AddDependencyToSignal( - const RoadId road_id, - const SignId signal_id, - const uint32_t dependency_id, - const std::string dependency_type) { - DEBUG_ASSERT(_map_data.GetRoad(road_id).GetSignal(signal_id) != nullptr); - _map_data.GetRoad(road_id).GetSignal(signal_id)->AddDependency(signal::SignalDependency( - road_id, - signal_id, - dependency_id, - dependency_type)); - } - Lane *MapBuilder::GetLane( const RoadId road_id, const LaneId lane_id, @@ -743,6 +726,14 @@ namespace road { } } + void MapBuilder::SolveSignalReferences() { + for(auto signal_reference : _temp_signal_reference_container){ + signal_reference->_signal = + _temp_signal_container[signal_reference->_signal_id]; + } + _map_data._signals = std::move(_temp_signal_container); + } + void MapBuilder::CreateJunctionBoundingBoxes(Map &map) { for (auto &junctionpair : map._data.GetJunctions()) { auto* junction = map.GetJunction(junctionpair.first); diff --git a/LibCarla/source/carla/road/MapBuilder.h b/LibCarla/source/carla/road/MapBuilder.h index 0e7898be6..2cbbd8f48 100644 --- a/LibCarla/source/carla/road/MapBuilder.h +++ b/LibCarla/source/carla/road/MapBuilder.h @@ -7,7 +7,8 @@ #pragma once #include "carla/road/Map.h" -#include "carla/road/element/RoadObjectCrosswalk.h" +#include "carla/road/element/RoadInfoCrosswalk.h" +#include "carla/road/element/RoadInfoSignal.h" #include @@ -150,8 +151,8 @@ namespace road { // const double t); // Signal methods - void AddSignal( - const RoadId road_id, + element::RoadInfoSignal* AddSignal( + Road* road, const SignId signal_id, const double s, const double t, @@ -171,12 +172,23 @@ namespace road { const double pitch, const double roll); - void AddValidityToLastAddedSignal( - const RoadId road_id, + element::RoadInfoSignal* AddSignalReference( + Road* road, const SignId signal_id, + const double s_position, + const double t_position, + const std::string signal_reference_orientation); + + void AddValidityToSignalReference( + element::RoadInfoSignal* signal_reference, const LaneId from_lane, const LaneId to_lane); + void AddDependencyToSignal( + const SignId signal_id, + const std::string dependency_id, + const std::string dependency_type); + // called from junction parser void AddJunction( const JuncId id, @@ -305,31 +317,6 @@ namespace road { const double max, const std::string unit); - void AddValidityToSignal( - const RoadId road_id, - const SignId signal_id, - const LaneId from_lane, - const LaneId to_lane); - - void AddValidityToSignalReference( - const RoadId road_id, - const SignId signal_reference_id, - const LaneId from_lane, - const LaneId to_lane); - - void AddSignalReference( - const RoadId road_id, - const SignId signal_reference_id, - const double s_position, - const double t_position, - const std::string signal_reference_orientation); - - void AddDependencyToSignal( - const RoadId road_id, - const SignId signal_id, - const uint32_t dependency_id, - const std::string dependency_type); - Road *GetRoad( const RoadId road_id); @@ -352,6 +339,9 @@ namespace road { /// Create the bounding boxes of each junction void CreateJunctionBoundingBoxes(Map &map); + /// Solves the signal references in the road + void SolveSignalReferences(); + /// Return the pointer to a lane object. Lane *GetEdgeLanePointer(RoadId road_id, bool from_start, LaneId lane_id); @@ -370,13 +360,15 @@ namespace road { /// Map to temporary store all the road and lane infos until the map is /// built, so they can be added all together. std::unordered_map>> - _temp_road_info_container; - - std::unordered_map>> - _temp_road_object_container; + _temp_road_info_container; std::unordered_map>> - _temp_lane_info_container; + _temp_lane_info_container; + + std::unordered_map> + _temp_signal_container; + + std::vector _temp_signal_reference_container; }; diff --git a/LibCarla/source/carla/road/MapData.h b/LibCarla/source/carla/road/MapData.h index c62c36c13..5d578191d 100644 --- a/LibCarla/source/carla/road/MapData.h +++ b/LibCarla/source/carla/road/MapData.h @@ -14,6 +14,7 @@ #include "carla/road/Road.h" #include "carla/road/RoadTypes.h" #include "carla/road/element/RoadInfo.h" +#include "carla/road/Signal.h" #include @@ -80,6 +81,8 @@ namespace road { std::unordered_map _roads; std::unordered_map _junctions; + + std::unordered_map> _signals; }; } // namespace road diff --git a/LibCarla/source/carla/road/ObjectSet.h b/LibCarla/source/carla/road/ObjectSet.h deleted file mode 100644 index c7e7edfec..000000000 --- a/LibCarla/source/carla/road/ObjectSet.h +++ /dev/null @@ -1,53 +0,0 @@ -// Copyright (c) 2019 Computer Vision Center (CVC) at the Universitat Autonoma -// de Barcelona (UAB). -// -// This work is licensed under the terms of the MIT license. -// For a copy, see . - -#pragma once - -#include "carla/NonCopyable.h" -#include "carla/road/RoadElementSet.h" -#include "carla/road/element/RoadObject.h" -#include "carla/road/element/RoadObjectIterator.h" - -#include -#include - -namespace carla { -namespace road { - - class ObjectSet : private MovableNonCopyable { - public: - - ObjectSet() = default; - - ObjectSet(std::vector> &&vec) - : _road_set(std::move(vec)) {} - - /// Return all objects given a type from the start of the road - template - std::vector GetObjects() const { - std::vector vec; - auto it = element::MakeRoadObjectIterator(_road_set.GetAll()); - for (; !it.IsAtEnd(); ++it) { - vec.emplace_back(&*it); - } - return vec; - } - - /// Returns single object given a type and a distance (s) from - /// the start of the road - template - const T *GetObject(const double s) const { - auto it = element::MakeRoadObjectIterator(_road_set.GetReverseSubset(s)); - return it.IsAtEnd() ? nullptr : &*it; - } - - private: - - RoadElementSet> _road_set; - }; - -} // road -} // carla diff --git a/LibCarla/source/carla/road/Road.cpp b/LibCarla/source/carla/road/Road.cpp index 1bdfba325..f229ee4ff 100644 --- a/LibCarla/source/carla/road/Road.cpp +++ b/LibCarla/source/carla/road/Road.cpp @@ -155,30 +155,6 @@ namespace road { return nullptr; } - carla::road::signal::Signal *Road::GetSignal(const SignId id) { - auto search = _signals.find(id); - if (search != _signals.end()) { - return &search->second; - } - return nullptr; - } - - carla::road::signal::SignalReference *Road::GetSignalRef(const SignRefId id) { - const auto search = _sign_ref.find(id); - if (search != _sign_ref.end()) { - return &search->second; - } - return nullptr; - } - - std::unordered_map *Road::getSignals() { - return &_signals; - } - - std::unordered_map *Road::getSignalReferences() { - return &_sign_ref; - } - element::DirectedPoint Road::GetDirectedPointIn(const double s) const { const auto clamped_s = geom::Math::Clamp(s, 0.0, _length); const auto geometry = _info.GetInfo(clamped_s); diff --git a/LibCarla/source/carla/road/Road.h b/LibCarla/source/carla/road/Road.h index 2a723df97..16aba4744 100644 --- a/LibCarla/source/carla/road/Road.h +++ b/LibCarla/source/carla/road/Road.h @@ -10,7 +10,6 @@ #include "carla/ListView.h" #include "carla/NonCopyable.h" #include "carla/road/InformationSet.h" -#include "carla/road/ObjectSet.h" #include "carla/road/Junction.h" #include "carla/road/LaneSection.h" #include "carla/road/LaneSectionMap.h" @@ -18,9 +17,6 @@ #include "carla/road/RoadTypes.h" #include "carla/road/element/Geometry.h" #include "carla/road/element/RoadInfo.h" -#include "carla/road/element/RoadObject.h" -#include "carla/road/signal/Signal.h" -#include "carla/road/signal/SignalReference.h" #include #include @@ -77,14 +73,6 @@ namespace road { const geom::CubicPolynomial &GetElevationOn(const double s) const; - carla::road::signal::Signal *GetSignal(const SignId id); - - carla::road::signal::SignalReference *GetSignalRef(const SignRefId id); - - std::unordered_map *getSignals(); - - std::unordered_map *getSignalReferences(); - /// Returns a directed point on the center of the road (lane 0), /// with the corresponding laneOffset and elevation records applied, /// on distance "s". @@ -120,16 +108,6 @@ namespace road { return _info.GetInfos(); } - template - const T *GetObject(const double s) const { - return _objects.GetObject(s); - } - - template - std::vector GetObjects() const { - return _objects.GetObjects(); - } - auto GetLaneSections() const { return MakeListView( iterator::make_map_values_const_iterator(_lane_sections.begin()), @@ -211,13 +189,6 @@ namespace road { std::vector _nexts; std::vector _prevs; - - std::unordered_map _signals; - - std::unordered_map _sign_ref; - - ObjectSet _objects; - }; } // road diff --git a/LibCarla/source/carla/road/RoadTypes.h b/LibCarla/source/carla/road/RoadTypes.h index ab4cb748d..5b40d1026 100644 --- a/LibCarla/source/carla/road/RoadTypes.h +++ b/LibCarla/source/carla/road/RoadTypes.h @@ -7,6 +7,7 @@ #pragma once #include +#include namespace carla { namespace road { @@ -21,9 +22,7 @@ namespace road { using ObjId = uint32_t; - using SignId = uint32_t; - - using SignRefId = uint32_t; + using SignId = std::string; using ConId = uint32_t; diff --git a/LibCarla/source/carla/road/signal/Signal.h b/LibCarla/source/carla/road/Signal.h similarity index 71% rename from LibCarla/source/carla/road/signal/Signal.h rename to LibCarla/source/carla/road/Signal.h index 53ff230e9..c114f163c 100644 --- a/LibCarla/source/carla/road/signal/Signal.h +++ b/LibCarla/source/carla/road/Signal.h @@ -6,24 +6,33 @@ #pragma once +#include "carla/Memory.h" #include "carla/NonCopyable.h" #include "carla/road/RoadTypes.h" -#include "carla/road/general/Validity.h" -#include "carla/road/signal/SignalDependency.h" +#include "carla/road/LaneValidity.h" #include #include namespace carla { namespace road { -namespace signal { + + struct SignalDependency { + public: + + SignalDependency( std::string dependency_id, std::string type) + : _dependency_id(dependency_id), _type(type) {} + + std::string _dependency_id; + + std::string _type; + + }; class Signal : private MovableNonCopyable { public: - Signal( - road::RoadId road_id, - road::SignId signal_id, + SignId signal_id, double s, double t, std::string name, @@ -41,8 +50,7 @@ namespace signal { double hOffset, double pitch, double roll) - : _road_id(road_id), - _signal_id(signal_id), + : _signal_id(signal_id), _s(s), _t(t), _name(name), @@ -61,46 +69,55 @@ namespace signal { _pitch(pitch), _roll(roll) {} - void AddValidity(general::Validity &&validity) { + void AddValidity(LaneValidity &&validity) { _validities.push_back(std::move(validity)); } - void AddDependency(signal::SignalDependency &&dependency) { + void AddDependency(SignalDependency &&dependency) { _dependencies.push_back(std::move(dependency)); } - private: + SignId _signal_id; -#if defined(__clang__) -# pragma clang diagnostic push -# pragma clang diagnostic ignored "-Wunused-private-field" -#endif - road::RoadId _road_id; - road::SignId _signal_id; double _s; + double _t; + std::string _name; + std::string _dynamic; + std::string _orientation; + double _zOffset; + std::string _country; + std::string _type; + std::string _subtype; + double _value; + std::string _unit; + double _height; + double _width; + std::string _text; + double _hOffset; + double _pitch; + double _roll; - std::vector _validities; - std::vector _dependencies; -#if defined(__clang__) -# pragma clang diagnostic pop -#endif + + std::vector _validities; + + std::vector _dependencies; + }; -} // object } // road } // carla diff --git a/LibCarla/source/carla/road/element/RoadObjectCrosswalk.h b/LibCarla/source/carla/road/element/RoadInfoCrosswalk.h similarity index 90% rename from LibCarla/source/carla/road/element/RoadObjectCrosswalk.h rename to LibCarla/source/carla/road/element/RoadInfoCrosswalk.h index abd6e5dc3..3b9029dc0 100644 --- a/LibCarla/source/carla/road/element/RoadObjectCrosswalk.h +++ b/LibCarla/source/carla/road/element/RoadInfoCrosswalk.h @@ -6,7 +6,7 @@ #pragma once -#include "carla/road/element/RoadObject.h" +#include "carla/road/element/RoadInfo.h" namespace carla { namespace road { @@ -19,10 +19,10 @@ namespace element { CrosswalkPoint(double _u, double _v, double _z) : u(_u), v(_v), z(_z) {}; }; - class RoadObjectCrosswalk final : public RoadObject { + class RoadInfoCrosswalk final : public RoadInfo { public: - RoadObjectCrosswalk( + RoadInfoCrosswalk( const double s, const std::string name, const double t, @@ -34,7 +34,7 @@ namespace element { const double width, const double length, const std::vector points) - : RoadObject(s), + : RoadInfo(s), _name(name), _t(t), _zOffset(zOffset), @@ -46,7 +46,7 @@ namespace element { _length(length), _points(points) {} - void AcceptVisitor(RoadObjectVisitor &v) final { + void AcceptVisitor(RoadInfoVisitor &v) final { v.Visit(*this); } diff --git a/LibCarla/source/carla/road/element/RoadInfoSignal.h b/LibCarla/source/carla/road/element/RoadInfoSignal.h new file mode 100644 index 000000000..b87add585 --- /dev/null +++ b/LibCarla/source/carla/road/element/RoadInfoSignal.h @@ -0,0 +1,69 @@ +// Copyright (c) 2020 Computer Vision Center (CVC) at the Universitat Autonoma +// de Barcelona (UAB). +// +// This work is licensed under the terms of the MIT license. +// For a copy, see . + +#pragma once + +#include "carla/road/Signal.h" +#include "carla/road/element/RoadInfo.h" + +namespace carla { +namespace road { +namespace element { + + class RoadInfoSignal final : public RoadInfo { + public: + + RoadInfoSignal( + SignId signal_id, + std::shared_ptr &signal, + double s, + double t, + std::string orientation) + : _signal_id(signal_id), + _signal(signal), + _s(s), + _t(t), + _orientation(orientation) {} + + RoadInfoSignal( + SignId signal_id, + double s, + double t, + std::string orientation) + : _signal_id(signal_id), + _s(s), + _t(t), + _orientation(orientation) {} + + void AcceptVisitor(RoadInfoVisitor &v) final { + v.Visit(*this); + } + + const std::shared_ptr& GetSignal() const { + return _signal; + } + + + + private: + friend MapBuilder; + + SignId _signal_id; + + std::shared_ptr _signal; + + double _s; + + double _t; + + std::string _orientation; + + std::vector _validities; + }; + +} // namespace element +} // namespace road +} // namespace carla diff --git a/LibCarla/source/carla/road/element/RoadInfoVisitor.h b/LibCarla/source/carla/road/element/RoadInfoVisitor.h index 218e55c54..b6fc0df56 100644 --- a/LibCarla/source/carla/road/element/RoadInfoVisitor.h +++ b/LibCarla/source/carla/road/element/RoadInfoVisitor.h @@ -25,6 +25,8 @@ namespace element { class RoadInfoMarkRecord; class RoadInfoMarkTypeLine; class RoadInfoSpeed; + class RoadInfoCrosswalk; + class RoadInfoSignal; class RoadInfoVisitor { public: @@ -52,6 +54,8 @@ namespace element { virtual void Visit(RoadInfoMarkRecord &) {} virtual void Visit(RoadInfoMarkTypeLine &) {} virtual void Visit(RoadInfoSpeed &) {} + virtual void Visit(RoadInfoCrosswalk &) {} + virtual void Visit(RoadInfoSignal &) {} }; } // namespace element diff --git a/LibCarla/source/carla/road/element/RoadObject.h b/LibCarla/source/carla/road/element/RoadObject.h deleted file mode 100644 index ca10a2e52..000000000 --- a/LibCarla/source/carla/road/element/RoadObject.h +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright (c) 2017 Computer Vision Center (CVC) at the Universitat Autonoma -// de Barcelona (UAB). -// -// This work is licensed under the terms of the MIT license. -// For a copy, see . - -#pragma once - -#include "carla/road/element/RoadObjectVisitor.h" -#include "carla/NonCopyable.h" - -#include -#include -#include - -namespace carla { -namespace road { -namespace element { - - class RoadObject : private NonCopyable { - public: - - virtual ~RoadObject() = default; - - virtual void AcceptVisitor(RoadObjectVisitor &) = 0; - - /// Distance from road's start location. - double GetDistance() const { - return _s; - } - - protected: - - RoadObject(double distance = 0.0) : _s(distance) {} - - private: - - double _s; - }; - -} // namespace element -} // namespace road -} // namespace carla diff --git a/LibCarla/source/carla/road/element/RoadObjectIterator.h b/LibCarla/source/carla/road/element/RoadObjectIterator.h deleted file mode 100644 index 01ff555e5..000000000 --- a/LibCarla/source/carla/road/element/RoadObjectIterator.h +++ /dev/null @@ -1,105 +0,0 @@ -// Copyright (c) 2019 Computer Vision Center (CVC) at the Universitat Autonoma -// de Barcelona (UAB). -// -// This work is licensed under the terms of the MIT license. -// For a copy, see . - -#pragma once - -#include "carla/Debug.h" -#include "carla/road/element/RoadObjectVisitor.h" - -#include -#include - -namespace carla { -namespace road { -namespace element { - - template - class RoadObjectIterator : private RoadObjectVisitor { - public: - - static_assert(std::is_same, typename IT::value_type>::value, "Not compatible."); - - using value_type = T; - using difference_type = typename IT::difference_type; - using pointer = T *; - using reference = T &; - - RoadObjectIterator(IT begin, IT end) - : _it(begin), - _end(end) { - _success = false; - for (; !IsAtEnd(); ++_it) { - DEBUG_ASSERT((*_it) != nullptr); - (*_it)->AcceptVisitor(*this); - if (_success) { - break; - } - } - } - - RoadObjectIterator &operator++() { - _success = false; - while (!_success) { - ++_it; - if (IsAtEnd()) { - break; - } - DEBUG_ASSERT((*_it) != nullptr); - (*_it)->AcceptVisitor(*this); - } - return *this; - } - - reference operator*() const { - DEBUG_ASSERT((*_it) != nullptr); - return static_cast(**_it); - } - - pointer operator->() const { - DEBUG_ASSERT((*_it) != nullptr); - return static_cast(_it->get()); - } - - bool operator!=(const RoadObjectIterator &rhs) const { - return _it != rhs._it; - } - - bool operator==(const RoadObjectIterator &rhs) const { - return !((*this) != rhs); - } - - bool IsAtEnd() const { - return _it == _end; - } - - private: - - void Visit(T &) { - _success = true; - } - - IT _it; - - IT _end; - - bool _success; - }; - - template - static auto MakeRoadObjectIterator(const Container &c) { - auto begin = std::begin(c); - auto end = std::end(c); - return RoadObjectIterator(begin, end); - } - - template - static auto MakeRoadObjectIterator(IT begin, IT end) { - return RoadObjectIterator(begin, end); - } - -} // namespace element -} // namespace road -} // namespace carla diff --git a/LibCarla/source/carla/road/element/RoadObjectVisitor.h b/LibCarla/source/carla/road/element/RoadObjectVisitor.h deleted file mode 100644 index ea3cc555e..000000000 --- a/LibCarla/source/carla/road/element/RoadObjectVisitor.h +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright (c) 2017 Computer Vision Center (CVC) at the Universitat Autonoma -// de Barcelona (UAB). -// -// This work is licensed under the terms of the MIT license. -// For a copy, see . - -#pragma once - -namespace carla { -namespace road { -namespace element { - - class RoadObject; - class RoadObjectCrosswalk; - - class RoadObjectVisitor { - public: - - RoadObjectVisitor() = default; - virtual ~RoadObjectVisitor() = default; - - RoadObjectVisitor(const RoadObjectVisitor &) = default; - RoadObjectVisitor(RoadObjectVisitor &&) = default; - - RoadObjectVisitor &operator=(const RoadObjectVisitor &) = default; - RoadObjectVisitor &operator=(RoadObjectVisitor &&) = default; - - virtual void Visit(RoadObjectCrosswalk &) {} - }; - -} // namespace element -} // namespace road -} // namespace carla diff --git a/LibCarla/source/carla/road/general/Validity.h b/LibCarla/source/carla/road/general/Validity.h deleted file mode 100644 index 14ef802cc..000000000 --- a/LibCarla/source/carla/road/general/Validity.h +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright (c) 2019 Computer Vision Center (CVC) at the Universitat Autonoma -// de Barcelona (UAB). -// -// This work is licensed under the terms of the MIT license. -// For a copy; see . - -#pragma once - -#include "carla/NonCopyable.h" -#include -#include -#include "carla/road/RoadTypes.h" - -namespace carla { -namespace road { -namespace general { - - class Validity : private MovableNonCopyable { - public: - - Validity( - uint32_t parent_id, - road::LaneId from_lane, - road::LaneId to_lane) - : _parent_id(parent_id), - _from_lane(from_lane), - _to_lane(to_lane) {} - - private: - -#if defined(__clang__) -# pragma clang diagnostic push -# pragma clang diagnostic ignored "-Wunused-private-field" -#endif - uint32_t _parent_id; - road::LaneId _from_lane; - road::LaneId _to_lane; -#if defined(__clang__) -# pragma clang diagnostic pop -#endif - }; - -} // general -} // road -} // carla diff --git a/LibCarla/source/carla/road/signal/SignalDependency.h b/LibCarla/source/carla/road/signal/SignalDependency.h deleted file mode 100644 index e9bb1d549..000000000 --- a/LibCarla/source/carla/road/signal/SignalDependency.h +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright (c) 2019 Computer Vision Center (CVC) at the Universitat Autonoma -// de Barcelona (UAB). -// -// This work is licensed under the terms of the MIT license. -// For a copy; see . - -#pragma once - -#include "carla/NonCopyable.h" -#include "carla/road/RoadTypes.h" -#include "carla/road/general/Validity.h" - -#include -#include - -namespace carla { -namespace road { -namespace signal { - - class SignalDependency : private MovableNonCopyable { - public: - - SignalDependency( - road::RoadId road_id, - road::SignId signal_id, - uint32_t dependency_id, - std::string type) - : _road_id(road_id), - _signal_id(signal_id), - _dependency_id(dependency_id), - _type(type) {} - - private: - -#if defined(__clang__) -# pragma clang diagnostic push -# pragma clang diagnostic ignored "-Wunused-private-field" -#endif - road::RoadId _road_id; - road::SignId _signal_id; - uint32_t _dependency_id; - std::string _type; -#if defined(__clang__) -# pragma clang diagnostic pop -#endif - }; - -} // object -} // road -} // carla diff --git a/LibCarla/source/carla/road/signal/SignalReference.h b/LibCarla/source/carla/road/signal/SignalReference.h deleted file mode 100644 index 71aeb5be8..000000000 --- a/LibCarla/source/carla/road/signal/SignalReference.h +++ /dev/null @@ -1,57 +0,0 @@ -// Copyright (c) 2019 Computer Vision Center (CVC) at the Universitat Autonoma -// de Barcelona (UAB). -// -// This work is licensed under the terms of the MIT license. -// For a copy; see . - -#pragma once - -#include "carla/NonCopyable.h" -#include -#include -#include "carla/road/RoadTypes.h" -#include "carla/road/general/Validity.h" - -namespace carla { -namespace road { -namespace signal { - - class SignalReference : private MovableNonCopyable { - public: - - SignalReference( - road::RoadId road_id, - road::SignId id, - double s, - double t, - std::string orientation) - : _road_id(road_id), - _signal_id(id), - _s(s), - _t(t), - _orientation(orientation) {} - - void AddValidity(general::Validity &&validity) { - _validities.push_back(std::move(validity)); - } - - private: - -#if defined(__clang__) -# pragma clang diagnostic push -# pragma clang diagnostic ignored "-Wunused-private-field" -#endif - road::RoadId _road_id; - road::SignId _signal_id; - double _s; - double _t; - std::string _orientation; - std::vector _validities; -#if defined(__clang__) -# pragma clang diagnostic pop -#endif - }; - -} // object -} // road -} // carla