Rename WaypointInfoRoadMark to LaneMarking

This commit is contained in:
nsubiron 2019-03-30 12:22:49 +01:00
parent 3ac4f14900
commit 6d62bec3c3
10 changed files with 259 additions and 245 deletions

View File

@ -267,13 +267,6 @@
- `to_opendrive()`
- `save_to_disk(path=self.name)`
## `carla.LaneChange`
- `NONE`
- `Right`
- `Left`
- `Both`
## `carla.LaneType`
- `NONE`
@ -299,9 +292,16 @@
- `OnRamp`
- `Any`
## `carla.RoadMarkColor`
## `carla.LaneChange`
- `Standard`
- `NONE`
- `Right`
- `Left`
- `Both`
## `carla.LaneMarkingColor`
- `Standard = White`
- `Blue`
- `Green`
- `Red`
@ -309,7 +309,7 @@
- `Yellow`
- `Other`
## `carla.LaneMarking`
## `carla.LaneMarkingType`
- `NONE`
- `Other`
@ -323,7 +323,7 @@
- `Grass`
- `Curb`
## `carla.WaypointInfoRoadMark`
## `carla.LaneMarking`
- `type -> carla.LaneMarking`
- `color -> carla.RoadMarkColor`
@ -342,8 +342,8 @@
- `s`
- `lane_change -> carla.LaneChange`
- `lane_type -> carla.LaneType`
- `right_road_mark -> carla.WaypointInfoRoadMark`
- `left_road_mark -> carla.WaypointInfoRoadMark`
- `right_lane_marking -> carla.LaneMarking`
- `left_lane_marking -> carla.LaneMarking`
- `next(distance) -> list(carla.Waypoint)`
- `get_right_lane() -> carla.Waypoint`
- `get_left_lane() -> carla.Waypoint`

View File

@ -32,7 +32,7 @@ namespace client {
return _parent->GetMap().GetLaneType(_waypoint);
}
std::vector<SharedPtr<Waypoint>> Waypoint::Next(double distance) const {
std::vector<SharedPtr<Waypoint>> Waypoint::GetNext(double distance) const {
auto waypoints = _parent->GetMap().GetNext(_waypoint, distance);
std::vector<SharedPtr<Waypoint>> result;
result.reserve(waypoints.size());
@ -42,7 +42,7 @@ namespace client {
return result;
}
SharedPtr<Waypoint> Waypoint::Right() const {
SharedPtr<Waypoint> Waypoint::GetRight() const {
auto right_lane_waypoint =
_parent->GetMap().GetRight(_waypoint);
if (right_lane_waypoint.has_value()) {
@ -51,7 +51,7 @@ namespace client {
return nullptr;
}
SharedPtr<Waypoint> Waypoint::Left() const {
SharedPtr<Waypoint> Waypoint::GetLeft() const {
auto left_lane_waypoint =
_parent->GetMap().GetLeft(_waypoint);
if (left_lane_waypoint.has_value()) {
@ -60,6 +60,20 @@ namespace client {
return nullptr;
}
boost::optional<road::element::LaneMarking> Waypoint::GetRightLaneMarking() const {
if (_mark_record.first != nullptr) {
return road::element::LaneMarking(*_mark_record.first);
}
return boost::optional<road::element::LaneMarking>{};
}
boost::optional<road::element::LaneMarking> Waypoint::GetLeftLaneMarking() const {
if (_mark_record.first != nullptr) {
return road::element::LaneMarking(*_mark_record.second);
}
return boost::optional<road::element::LaneMarking>{};
}
template <typename EnumT>
static EnumT operator&(EnumT lhs, EnumT rhs) {
return static_cast<EnumT>(
@ -74,22 +88,8 @@ namespace client {
static_cast<typename std::underlying_type<EnumT>::type>(rhs));
}
boost::optional<road::element::WaypointInfoRoadMark> Waypoint::GetRightRoadMark() const {
if (_mark_record.first != nullptr) {
return road::element::WaypointInfoRoadMark(*_mark_record.first);
}
return boost::optional<road::element::WaypointInfoRoadMark>{};
}
boost::optional<road::element::WaypointInfoRoadMark> Waypoint::GetLeftRoadMark() const {
if (_mark_record.first != nullptr) {
return road::element::WaypointInfoRoadMark(*_mark_record.second);
}
return boost::optional<road::element::WaypointInfoRoadMark>{};
}
road::element::WaypointInfoRoadMark::LaneChange Waypoint::GetLaneChange() const {
using lane_change_type = road::element::WaypointInfoRoadMark::LaneChange;
road::element::LaneMarking::LaneChange Waypoint::GetLaneChange() const {
using lane_change_type = road::element::LaneMarking::LaneChange;
const auto lane_change_right_info = _mark_record.first;
lane_change_type c_right;

View File

@ -6,13 +6,13 @@
#pragma once
#include "carla/geom/Transform.h"
#include "carla/Memory.h"
#include "carla/NonCopyable.h"
#include "carla/geom/Transform.h"
#include "carla/road/Lane.h"
#include "carla/road/element/LaneMarking.h"
#include "carla/road/element/RoadInfoMarkRecord.h"
#include "carla/road/element/Waypoint.h"
#include "carla/road/element/WaypointInformationTypes.h"
#include "carla/road/Lane.h"
#include <boost/optional.hpp>
@ -62,17 +62,17 @@ namespace client {
road::Lane::LaneType GetType() const;
std::vector<SharedPtr<Waypoint>> Next(double distance) const;
std::vector<SharedPtr<Waypoint>> GetNext(double distance) const;
SharedPtr<Waypoint> Right() const;
SharedPtr<Waypoint> GetRight() const;
SharedPtr<Waypoint> Left() const;
SharedPtr<Waypoint> GetLeft() const;
boost::optional<road::element::WaypointInfoRoadMark> GetRightRoadMark() const;
boost::optional<road::element::LaneMarking> GetRightLaneMarking() const;
boost::optional<road::element::WaypointInfoRoadMark> GetLeftRoadMark() const;
boost::optional<road::element::LaneMarking> GetLeftLaneMarking() const;
road::element::WaypointInfoRoadMark::LaneChange GetLaneChange() const;
road::element::LaneMarking::LaneChange GetLaneChange() const;
private:

View File

@ -23,13 +23,13 @@ namespace element {
const bool origin_is_offroad,
const bool destination_is_offroad) {
if (origin_is_offroad != destination_is_offroad) {
return { LaneMarking::Solid };
return { LaneMarking::Type::Solid };
} else if (lane_id_origin == lane_id_destination) {
return {};
} else if (lane_id_origin * lane_id_destination < 0) {
return { LaneMarking::Solid };
return { LaneMarking::Type::Solid };
} else {
return { LaneMarking::Broken };
return { LaneMarking::Type::Broken };
}
}

View File

@ -0,0 +1,98 @@
// 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 <https://opensource.org/licenses/MIT>.
#include "carla/road/element/LaneMarking.h"
#include "carla/Exception.h"
#include "carla/StringUtil.h"
#include "carla/road/element/RoadInfoMarkRecord.h"
namespace carla {
namespace road {
namespace element {
static LaneMarking::Type GetType(std::string str) {
StringUtil::ToLower(str);
if (str == "broken") {
return LaneMarking::Type::Broken;
} else if (str == "solid") {
return LaneMarking::Type::Solid;
} else if (str == "solid solid") {
return LaneMarking::Type::SolidSolid;
} else if (str == "solid broken") {
return LaneMarking::Type::SolidBroken;
} else if (str == "broken solid") {
return LaneMarking::Type::BrokenSolid;
} else if (str == "broken broken") {
return LaneMarking::Type::BrokenBroken;
} else if (str == "botts dots") {
return LaneMarking::Type::BottsDots;
} else if (str == "grass") {
return LaneMarking::Type::Grass;
} else if (str == "curb") {
return LaneMarking::Type::Curb;
} else if (str == "none") {
return LaneMarking::Type::None;
} else {
return LaneMarking::Type::Other;
}
}
static LaneMarking::Color GetColor(std::string str) {
StringUtil::ToLower(str);
if (str == "standard") {
return LaneMarking::Color::Standard;
} else if (str == "blue") {
return LaneMarking::Color::Blue;
} else if (str == "green") {
return LaneMarking::Color::Green;
} else if (str == "red") {
return LaneMarking::Color::Red;
} else if (str == "white") {
return LaneMarking::Color::White;
} else if (str == "yellow") {
return LaneMarking::Color::Yellow;
} else {
return LaneMarking::Color::Other;
}
}
static LaneMarking::LaneChange GetLaneChange(RoadInfoMarkRecord::LaneChange lane_change) {
switch (lane_change) {
case RoadInfoMarkRecord::LaneChange::Increase:
return LaneMarking::LaneChange::Right;
case RoadInfoMarkRecord::LaneChange::Decrease:
return LaneMarking::LaneChange::Left;
case RoadInfoMarkRecord::LaneChange::Both:
return LaneMarking::LaneChange::Both;
default:
return LaneMarking::LaneChange::None;
}
}
LaneMarking::LaneMarking(Type in_type)
: type(in_type) {
switch (type) {
case Type::Broken:
lane_change = LaneChange::Both;
break;
case Type::Solid:
lane_change = LaneChange::None;
break;
default:
throw_exception(std::runtime_error("lane type not supported"));
}
}
LaneMarking::LaneMarking(const RoadInfoMarkRecord &info)
: type(GetType(info.GetType())),
color(GetColor(info.GetColor())),
lane_change(GetLaneChange(info.GetLaneChange())),
width(info.GetWidth()) {}
} // namespace element
} // namespace road
} // namespace carla

View File

@ -6,27 +6,65 @@
#pragma once
#include <cstdint>
namespace carla {
namespace road {
namespace element {
enum class LaneMarking {
Other,
Broken,
Solid,
// (for double solid line)
SolidSolid,
// (from inside to outside, exception: center lane -from left to right)
SolidBroken,
// (from inside to outside, exception: center lane -from left to right)
BrokenSolid,
// (from inside to outside, exception: center lane -from left to right)
BrokenBroken,
BottsDots,
// (meaning a grass edge)
Grass,
Curb,
None
class RoadInfoMarkRecord;
struct LaneMarking {
enum class Type {
Other,
Broken,
Solid,
// (for double solid line)
SolidSolid,
// (from inside to outside, exception: center lane -from left to right)
SolidBroken,
// (from inside to outside, exception: center lane -from left to right)
BrokenSolid,
// (from inside to outside, exception: center lane -from left to right)
BrokenBroken,
BottsDots,
// (meaning a grass edge)
Grass,
Curb,
None
};
enum class Color : uint8_t {
Standard = 0u, // (equivalent to "white")
Blue = 1u,
Green = 2u,
Red = 3u,
White = Standard,
Yellow = 4u,
Other = 5u
};
/// Can be used as flags.
enum class LaneChange : uint8_t {
None = 0x00, // 00
Right = 0x01, // 01
Left = 0x02, // 10
Both = 0x03 // 11
};
/// @todo Temporary constructor until LaneCrossingCalculator is fixed.
LaneMarking(Type type);
explicit LaneMarking(const RoadInfoMarkRecord &info);
Type type = Type::None;
Color color = Color::Standard;
LaneChange lane_change = LaneChange::None;
double width = 0.0;
};
} // namespace element

View File

@ -1,76 +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 <https://opensource.org/licenses/MIT>.
#include "carla/road/element/WaypointInformationTypes.h"
#include "carla/StringUtil.h"
#include "carla/road/element/RoadInfoMarkRecord.h"
namespace carla {
namespace road {
namespace element {
WaypointInfoRoadMark::WaypointInfoRoadMark(const RoadInfoMarkRecord &info) {
const auto &t = StringUtil::ToLowerCopy(info.GetType());
const auto &c = StringUtil::ToLowerCopy(info.GetColor());
const auto &lc = info.GetLaneChange();
if (t == "broken") {
type = LaneMarking::Broken;
} else if (t == "solid") {
type = LaneMarking::Solid;
} else if (t == "solid solid") {
type = LaneMarking::SolidSolid;
} else if (t == "solid broken") {
type = LaneMarking::SolidBroken;
} else if (t == "broken solid") {
type = LaneMarking::BrokenSolid;
} else if (t == "broken broken") {
type = LaneMarking::BrokenBroken;
} else if (t == "botts dots") {
type = LaneMarking::BottsDots;
} else if (t == "grass") {
type = LaneMarking::Grass;
} else if (t == "curb") {
type = LaneMarking::Curb;
} else if (t == "none") {
type = LaneMarking::None;
} else {
type = LaneMarking::Other;
}
if (c == "standard") {
color = WaypointInfoRoadMark::Color::Standard;
} else if (c == "blue") {
color = WaypointInfoRoadMark::Color::Blue;
} else if (c == "green") {
color = WaypointInfoRoadMark::Color::Green;
} else if (c == "red") {
color = WaypointInfoRoadMark::Color::Red;
} else if (c == "white") {
color = WaypointInfoRoadMark::Color::White;
} else if (c == "yellow") {
color = WaypointInfoRoadMark::Color::Yellow;
} else {
color = WaypointInfoRoadMark::Color::Other;
}
if (lc == RoadInfoMarkRecord::LaneChange::Increase) {
lane_change = LaneChange::Right;
} else if (lc == RoadInfoMarkRecord::LaneChange::Decrease) {
lane_change = LaneChange::Left;
} else if (lc == RoadInfoMarkRecord::LaneChange::Both) {
lane_change = LaneChange::Both;
} else if (lc == RoadInfoMarkRecord::LaneChange::None) {
lane_change = LaneChange::None;
}
width = info.GetWidth();
}
} // namespace element
} // namespace road
} // namespace carla

View File

@ -1,48 +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 <https://opensource.org/licenses/MIT>.
#pragma once
#include "carla/road/element/LaneMarking.h"
#include <cstdint>
namespace carla {
namespace road {
namespace element {
class RoadInfoMarkRecord;
struct WaypointInfoRoadMark {
WaypointInfoRoadMark(const RoadInfoMarkRecord &info);
LaneMarking type = LaneMarking::None;
enum class Color : uint8_t {
Standard = 0u, // (equivalent to "white")
Blue = 1u,
Green = 2u,
Red = 3u,
White = Standard,
Yellow = 4u,
Other = 5u
} color = Color::Standard;
/// Can be used as flags
enum class LaneChange : uint8_t {
None = 0x00, // 00
Right = 0x01, // 01
Left = 0x02, // 10
Both = 0x03 // 11
} lane_change = LaneChange::None;
double width = 0.0;
};
} // namespace element
} // namespace road
} // namespace carla

View File

@ -8,7 +8,7 @@
#include <carla/PythonUtil.h>
#include <carla/client/Map.h>
#include <carla/client/Waypoint.h>
#include <carla/road/element/WaypointInformationTypes.h>
#include <carla/road/element/LaneMarking.h>
#include <ostream>
#include <fstream>
@ -55,25 +55,6 @@ static carla::geom::GeoLocation ToGeolocation(
return self.GetGeoReference().Transform(location);
}
template <typename T>
static boost::python::object OptionalToPythonObject(const T opt) {
namespace py = boost::python;
if (opt.has_value()) {
return py::object(opt.value());
}
return py::object();
}
static boost::python::object MakeRightWaypointInfoRoadMark(
const carla::client::Waypoint &self) {
return OptionalToPythonObject(self.GetRightRoadMark());
}
static boost::python::object MakeLeftWaypointInfoRoadMark(
const carla::client::Waypoint &self) {
return OptionalToPythonObject(self.GetLeftRoadMark());
}
void export_map() {
using namespace boost::python;
namespace cc = carla::client;
@ -81,6 +62,10 @@ void export_map() {
namespace cg = carla::geom;
namespace cre = carla::road::element;
// ===========================================================================
// -- Enums ------------------------------------------------------------------
// ===========================================================================
enum_<cr::Lane::LaneType>("LaneType")
.value("NONE", cr::Lane::LaneType::None) // None is reserved in Python3
.value("Driving", cr::Lane::LaneType::Driving)
@ -106,6 +91,40 @@ void export_map() {
.value("Any", cr::Lane::LaneType::Any)
;
enum_<cre::LaneMarking::LaneChange>("LaneChange")
.value("NONE", cre::LaneMarking::LaneChange::None)
.value("Right", cre::LaneMarking::LaneChange::Right)
.value("Left", cre::LaneMarking::LaneChange::Left)
.value("Both", cre::LaneMarking::LaneChange::Both)
;
enum_<cre::LaneMarking::Color>("LaneMarkingColor")
.value("Standard", cre::LaneMarking::Color::Standard)
.value("Blue", cre::LaneMarking::Color::Blue)
.value("Green", cre::LaneMarking::Color::Green)
.value("Red", cre::LaneMarking::Color::Red)
.value("White", cre::LaneMarking::Color::White)
.value("Yellow", cre::LaneMarking::Color::Yellow)
.value("Other", cre::LaneMarking::Color::Other)
;
enum_<cre::LaneMarking::Type>("LaneMarkingType")
.value("NONE", cre::LaneMarking::Type::None)
.value("Other", cre::LaneMarking::Type::Other)
.value("Broken", cre::LaneMarking::Type::Broken)
.value("Solid", cre::LaneMarking::Type::Solid)
.value("SolidSolid", cre::LaneMarking::Type::SolidSolid)
.value("SolidBroken", cre::LaneMarking::Type::SolidBroken)
.value("BrokenSolid", cre::LaneMarking::Type::BrokenSolid)
.value("BrokenBroken", cre::LaneMarking::Type::BrokenBroken)
.value("BottsDots", cre::LaneMarking::Type::BottsDots)
.value("Grass", cre::LaneMarking::Type::Grass)
.value("Curb", cre::LaneMarking::Type::Curb)
;
// ===========================================================================
// -- Map --------------------------------------------------------------------
// ===========================================================================
class_<cc::Map, boost::noncopyable, boost::shared_ptr<cc::Map>>("Map", no_init)
.def(init<std::string, std::string>((arg("name"), arg("xodr_content"))))
.add_property("name", CALL_RETURNING_COPY(cc::Map, GetName))
@ -119,42 +138,15 @@ void export_map() {
.def(self_ns::str(self_ns::self))
;
enum_<cre::WaypointInfoRoadMark::LaneChange>("LaneChange")
.value("NONE", cre::WaypointInfoRoadMark::LaneChange::None) // None is reserved in Python3
.value("Right", cre::WaypointInfoRoadMark::LaneChange::Right)
.value("Left", cre::WaypointInfoRoadMark::LaneChange::Left)
.value("Both", cre::WaypointInfoRoadMark::LaneChange::Both)
;
// ===========================================================================
// -- Helper objects ---------------------------------------------------------
// ===========================================================================
enum_<cre::WaypointInfoRoadMark::Color>("RoadMarkColor")
.value("Standard", cre::WaypointInfoRoadMark::Color::Standard)
.value("Blue", cre::WaypointInfoRoadMark::Color::Blue)
.value("Green", cre::WaypointInfoRoadMark::Color::Green)
.value("Red", cre::WaypointInfoRoadMark::Color::Red)
.value("White", cre::WaypointInfoRoadMark::Color::White)
.value("Yellow", cre::WaypointInfoRoadMark::Color::Yellow)
.value("Other", cre::WaypointInfoRoadMark::Color::Other)
;
enum_<cre::LaneMarking>("LaneMarking")
.value("NONE", cre::LaneMarking::None) // None is reserved in Python3
.value("Other", cre::LaneMarking::Other)
.value("Broken", cre::LaneMarking::Broken)
.value("Solid", cre::LaneMarking::Solid)
.value("SolidSolid", cre::LaneMarking::SolidSolid)
.value("SolidBroken", cre::LaneMarking::SolidBroken)
.value("BrokenSolid", cre::LaneMarking::BrokenSolid)
.value("BrokenBroken", cre::LaneMarking::BrokenBroken)
.value("BottsDots", cre::LaneMarking::BottsDots)
.value("Grass", cre::LaneMarking::Grass)
.value("Curb", cre::LaneMarking::Curb)
;
class_<cre::WaypointInfoRoadMark>("WaypointInfoRoadMark", no_init)
.add_property("type", &cre::WaypointInfoRoadMark::type)
.add_property("color", &cre::WaypointInfoRoadMark::color)
.add_property("lane_change", &cre::WaypointInfoRoadMark::lane_change)
.add_property("width", &cre::WaypointInfoRoadMark::width)
class_<cre::LaneMarking>("LaneMarking", no_init)
.add_property("type", &cre::LaneMarking::type)
.add_property("color", &cre::LaneMarking::color)
.add_property("lane_change", &cre::LaneMarking::lane_change)
.add_property("width", &cre::LaneMarking::width)
;
class_<cc::Waypoint, boost::noncopyable, boost::shared_ptr<cc::Waypoint>>("Waypoint", no_init)
@ -168,11 +160,11 @@ void export_map() {
.add_property("s", &cc::Waypoint::GetDistance)
.add_property("lane_change", &cc::Waypoint::GetLaneChange)
.add_property("lane_type", &cc::Waypoint::GetType)
.add_property("right_road_mark", &MakeRightWaypointInfoRoadMark)
.add_property("left_road_mark", &MakeLeftWaypointInfoRoadMark)
.def("next", CALL_RETURNING_LIST_1(cc::Waypoint, Next, double), (args("distance")))
.def("get_right_lane", &cc::Waypoint::Right)
.def("get_left_lane", &cc::Waypoint::Left)
.add_property("right_lane_marking", CALL_RETURNING_OPTIONAL(cc::Waypoint, GetRightLaneMarking))
.add_property("left_lane_marking", CALL_RETURNING_OPTIONAL(cc::Waypoint, GetLeftLaneMarking))
.def("next", CALL_RETURNING_LIST_1(cc::Waypoint, GetNext, double), (args("distance")))
.def("get_right_lane", &cc::Waypoint::GetRight)
.def("get_left_lane", &cc::Waypoint::GetLeft)
.def(self_ns::str(self_ns::self))
;
}

View File

@ -78,6 +78,16 @@
return result; \
}
#define CALL_RETURNING_OPTIONAL(cls, fn) +[](const cls &self) { \
auto optional = self.fn(); \
return optional.has_value() ? boost::python::object(*optional) : boost::python::object(); \
}
#define CALL_RETURNING_OPTIONAL_1(cls, fn, T1_) +[](const cls &self, T1_) { \
auto optional = self.fn(std::forward<T1_>(t1)); \
return optional.has_value() ? boost::python::object(*optional) : boost::python::object(); \
}
template <typename T>
static void PrintListItem_(std::ostream &out, const T &item) {
out << item;