diff --git a/LibCarla/source/carla/client/Waypoint.h b/LibCarla/source/carla/client/Waypoint.h index dcbd41dea..f421492a7 100644 --- a/LibCarla/source/carla/client/Waypoint.h +++ b/LibCarla/source/carla/client/Waypoint.h @@ -8,8 +8,9 @@ #include "carla/Memory.h" #include "carla/NonCopyable.h" -#include "carla/road/element/Waypoint.h" #include "carla/road/element/RoadInfoMarkRecord.h" +#include "carla/road/element/Waypoint.h" +#include "carla/road/element/WaypointHash.h" namespace carla { namespace client { @@ -31,6 +32,14 @@ namespace client { ~Waypoint(); + /// Returns an unique Id identifying this waypoint. + /// + /// The Id takes into account OpenDrive's road Id, lane Id, and s distance + /// on its road segment up to half-centimetre precision. + uint64_t GetId() const { + return road::element::WaypointHash()(_waypoint); + } + const geom::Transform &GetTransform() const { return _transform; } diff --git a/LibCarla/source/carla/road/element/RoadInfo.h b/LibCarla/source/carla/road/element/RoadInfo.h index 447e776f6..1f54af34b 100644 --- a/LibCarla/source/carla/road/element/RoadInfo.h +++ b/LibCarla/source/carla/road/element/RoadInfo.h @@ -8,8 +8,9 @@ #include "carla/road/element/RoadInfoVisitor.h" -#include #include +#include +#include namespace carla { namespace road { diff --git a/LibCarla/source/carla/road/element/Waypoint.h b/LibCarla/source/carla/road/element/Waypoint.h index 85de78a5b..72bbb150d 100644 --- a/LibCarla/source/carla/road/element/Waypoint.h +++ b/LibCarla/source/carla/road/element/Waypoint.h @@ -37,6 +37,10 @@ namespace element { return _lane_id; } + double GetDistance() const { + return _dist; + } + const std::string &GetType() const; const RoadSegment &GetRoadSegment() const; diff --git a/LibCarla/source/carla/road/element/WaypointHash.cpp b/LibCarla/source/carla/road/element/WaypointHash.cpp new file mode 100644 index 000000000..63bd1ae19 --- /dev/null +++ b/LibCarla/source/carla/road/element/WaypointHash.cpp @@ -0,0 +1,27 @@ +// 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 . + +#include "carla/road/element/WaypointHash.h" + +#include "carla/road/element/Waypoint.h" + +#include + +namespace carla { +namespace road { +namespace element { + + uint64_t WaypointHash::operator()(const Waypoint &waypoint) const { + uint64_t seed = 0u; + boost::hash_combine(seed, waypoint.GetRoadId()); + boost::hash_combine(seed, waypoint.GetLaneId()); + boost::hash_combine(seed, static_cast(std::floor(waypoint.GetDistance() * 200.0))); + return seed; + } + +} // namespace element +} // namespace road +} // namespace carla diff --git a/LibCarla/source/carla/road/element/WaypointHash.h b/LibCarla/source/carla/road/element/WaypointHash.h new file mode 100644 index 000000000..73057bf45 --- /dev/null +++ b/LibCarla/source/carla/road/element/WaypointHash.h @@ -0,0 +1,31 @@ +// 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 + +namespace carla { +namespace road { +namespace element { + + class Waypoint; + + struct WaypointHash { + + using argument_type = Waypoint; + + using result_type = uint64_t; + + /// Generates an unique id for @a waypoint based on its road_id, lane_id, + /// and "s" offset. The "s" offset is truncated to half centimetre + /// precision. + uint64_t operator()(const Waypoint &waypoint) const; + }; + +} // namespace element +} // namespace road +} // namespace carla diff --git a/PythonAPI/source/libcarla/Map.cpp b/PythonAPI/source/libcarla/Map.cpp index 1083fab58..f79719ea8 100644 --- a/PythonAPI/source/libcarla/Map.cpp +++ b/PythonAPI/source/libcarla/Map.cpp @@ -78,6 +78,7 @@ void export_map() { ; class_>("Waypoint", no_init) + .add_property("id", &cc::Waypoint::GetId) .add_property("transform", CALL_RETURNING_COPY(cc::Waypoint, GetTransform)) .add_property("is_intersection", &cc::Waypoint::IsIntersection) .add_property("lane_width", &cc::Waypoint::GetLaneWidth)