From e6a23ff101ba3b7879b36abc313320e52e26ad56 Mon Sep 17 00:00:00 2001 From: Axel Date: Wed, 14 Apr 2021 11:38:24 +0200 Subject: [PATCH] Added traffic light generation functions. --- PythonAPI/carla/source/libcarla/OSM2ODR.cpp | 10 ++++++++++ PythonAPI/carla/source/libcarla/libcarla.cpp | 10 ++++++++++ 2 files changed, 20 insertions(+) diff --git a/PythonAPI/carla/source/libcarla/OSM2ODR.cpp b/PythonAPI/carla/source/libcarla/OSM2ODR.cpp index 8f5a0fb8e..bd055f39c 100644 --- a/PythonAPI/carla/source/libcarla/OSM2ODR.cpp +++ b/PythonAPI/carla/source/libcarla/OSM2ODR.cpp @@ -17,6 +17,12 @@ namespace osm2odr { << ", elevation_layer_height=" << settings.elevation_layer_height << ")"; return out; } + void SetOsmWayTypes(OSM2ODRSettings& self, boost::python::list input) { + self.osm_highways_types = PythonLitstToVector(input); + } + void SetTLExcludedWayTypes(OSM2ODRSettings& self, boost::python::list input) { + self.tl_excluded_highways_types = PythonLitstToVector(input); + } } void export_osm2odr() { @@ -31,6 +37,10 @@ void export_osm2odr() { .add_property("elevation_layer_height", &OSM2ODRSettings::elevation_layer_height, &OSM2ODRSettings::elevation_layer_height) .add_property("proj_string", &OSM2ODRSettings::proj_string, &OSM2ODRSettings::proj_string) .add_property("center_map", &OSM2ODRSettings::center_map, &OSM2ODRSettings::center_map) + .add_property("generate_traffic_lights", &OSM2ODRSettings::generate_traffic_lights, &OSM2ODRSettings::generate_traffic_lights) + .add_property("all_junctions_with_traffic_lights", &OSM2ODRSettings::all_junctions_traffic_lights, &OSM2ODRSettings::all_junctions_traffic_lights) + .def("set_osm_way_types", &SetOsmWayTypes, arg("way_types")) + .def("set_traffic_light_excluded_way_types", &SetTLExcludedWayTypes, arg("way_types")) .def(self_ns::str(self_ns::self)) ; diff --git a/PythonAPI/carla/source/libcarla/libcarla.cpp b/PythonAPI/carla/source/libcarla/libcarla.cpp index 00a2bca99..83b344b59 100644 --- a/PythonAPI/carla/source/libcarla/libcarla.cpp +++ b/PythonAPI/carla/source/libcarla/libcarla.cpp @@ -72,6 +72,16 @@ static boost::python::object OptionalToPythonObject(OptionalT &optional) { return self.fn(std::forward(t1)); \ } +template +std::vector PythonLitstToVector(boost::python::list &input) { + std::vector result; + boost::python::ssize_t list_size = boost::python::len(input); + for (boost::python::ssize_t i = 0; i < list_size; ++i) { + result.emplace_back(boost::python::extract(input[i])); + } + return result; +} + // Convenient for const requests that needs to convert the return value to a // Python list. #define CALL_RETURNING_LIST(cls, fn) +[](const cls &self) { \