Add more attributes to waypoints

This commit is contained in:
nsubiron 2018-11-14 20:41:00 +01:00
parent 02be13d9e7
commit 4a77755208
7 changed files with 47 additions and 7 deletions

View File

@ -181,6 +181,10 @@
## `carla.Waypoint`
- `transform`
- `is_intersection`
- `lane_width`
- `road_id`
- `lane_id`
- `next(distance)`
## `carla.WeatherParameters`

View File

@ -26,6 +26,14 @@ namespace client {
return _transform;
}
bool IsIntersection() const {
return _waypoint.IsIntersection();
}
double GetLaneWidth() const {
return _waypoint.GetLaneWidth();
}
road::element::id_type GetRoadId() const {
return _waypoint.GetRoadId();
}

View File

@ -48,13 +48,11 @@ namespace road {
auto &map = waypoint._map;
const auto this_lane_id = waypoint.GetLaneId();
const auto this_road_id = waypoint.GetRoadId();
const auto *this_road = map->GetData().GetRoad(this_road_id);
DEBUG_ASSERT(this_road != nullptr);
const auto &next_lanes =
this_lane_id < 0 ?
this_road->GetNextLane(this_lane_id) :
this_road->GetPrevLane(this_lane_id);
waypoint.GetRoadSegment().GetNextLane(this_lane_id) :
waypoint.GetRoadSegment().GetPrevLane(this_lane_id);
if (next_lanes.empty()) {
log_error("lane id =", this_lane_id, " road id=", this_road_id, ": missing next lanes");
@ -80,15 +78,13 @@ namespace road {
auto &map = waypoint._map;
const auto this_lane_id = waypoint.GetLaneId();
const auto this_road_id = waypoint.GetRoadId();
const auto *this_road = map->GetData().GetRoad(this_road_id);
DEBUG_ASSERT(this_road != nullptr);
double distance_on_next_segment;
if (this_lane_id < 0) {
// road goes forward.
const auto total_distance = waypoint._dist + distance;
const auto road_length = this_road->GetLength();
const auto road_length = waypoint.GetRoadSegment().GetLength();
if (total_distance <= road_length) {
return { Waypoint(map, this_road_id, this_lane_id, total_distance) };
}

View File

@ -35,6 +35,7 @@ namespace element {
private:
int _junction_id = -1;
/// A vector of pairs where the first double represents the
/// offset from the begining of the road and the second represents the
/// lateral offest of the lane
@ -53,6 +54,10 @@ namespace element {
return _junction_id;
}
bool IsJunction() const {
return _junction_id >= 0;
}
void SetLanesOffset(double offset, double laneOffset) {
_lanes_offset.emplace_back(std::pair<double, double>(offset, laneOffset));
}

View File

@ -111,6 +111,23 @@ namespace element {
return RoadInfoList(_map->GetData().GetRoad(_road_id)->GetInfos(_dist));
}
const RoadSegment &Waypoint::GetRoadSegment() const {
const auto *road_segment = _map->GetData().GetRoad(_road_id);
DEBUG_ASSERT(road_segment != nullptr);
return *road_segment;
}
bool Waypoint::IsIntersection() const {
const auto *info = GetRoadSegment().GetInfo<RoadGeneralInfo>(_dist);
return info != nullptr ? info->IsJunction() : false;
}
double Waypoint::GetLaneWidth() const {
const auto *info = GetRoadSegment().GetInfo<RoadInfoLane>(_dist);
const auto *lane_info = info != nullptr ? info->getLane(_lane_id) : nullptr;
return lane_info != nullptr ? lane_info->_width : 0.0;
}
} // namespace element
} // namespace road
} // namespace carla

View File

@ -19,6 +19,8 @@ namespace road {
namespace element {
class RoadSegment;
class Waypoint {
public:
@ -36,6 +38,12 @@ namespace element {
RoadInfoList GetRoadInfo() const;
const RoadSegment &GetRoadSegment() const;
bool IsIntersection() const;
double GetLaneWidth() const;
private:
friend carla::road::Map;

View File

@ -65,6 +65,8 @@ void export_map() {
class_<cc::Waypoint, boost::noncopyable, boost::shared_ptr<cc::Waypoint>>("Waypoint", no_init)
.add_property("transform", CALL_RETURNING_COPY(cc::Waypoint, GetTransform))
.add_property("is_intersection", &cc::Waypoint::IsIntersection)
.add_property("lane_width", &cc::Waypoint::GetLaneWidth)
.add_property("road_id", &cc::Waypoint::GetRoadId)
.add_property("lane_id", &cc::Waypoint::GetLaneId)
.def("next", CALL_RETURNING_LIST_1(cc::Waypoint, Next, double), (args("distance")))