diff --git a/Docs/python_api.md b/Docs/python_api.md index 89d9b3b5e..73970bac6 100644 --- a/Docs/python_api.md +++ b/Docs/python_api.md @@ -174,6 +174,7 @@ - `get_spawn_points()` - `get_waypoint(location, project_to_road=True)` - `get_topology()` +- `generate_waypoints(distance)` - `to_opendrive()` - `save_to_disk(path=self.name)` diff --git a/LibCarla/source/carla/client/Map.cpp b/LibCarla/source/carla/client/Map.cpp index 464a28aa0..534a4a95e 100644 --- a/LibCarla/source/carla/client/Map.cpp +++ b/LibCarla/source/carla/client/Map.cpp @@ -69,6 +69,16 @@ namespace client { return result; } + std::vector> Map::GenerateWaypoints(double distance) const { + std::vector> result; + const auto waypoints = road::WaypointGenerator::GenerateAll(*_map, distance); + result.reserve(waypoints.size()); + for (const auto &waypoint : waypoints) { + result.emplace_back(SharedPtr(new Waypoint{shared_from_this(), waypoint})); + } + return result; + } + std::vector Map::CalculateCrossedLanes( const geom::Location &origin, const geom::Location &destination) const { diff --git a/LibCarla/source/carla/client/Map.h b/LibCarla/source/carla/client/Map.h index 7d691ef53..8546aaeb7 100644 --- a/LibCarla/source/carla/client/Map.h +++ b/LibCarla/source/carla/client/Map.h @@ -48,6 +48,8 @@ namespace client { TopologyList GetTopology() const; + std::vector> GenerateWaypoints(double distance) const; + std::vector CalculateCrossedLanes( const geom::Location &origin, const geom::Location &destination) const; diff --git a/PythonAPI/source/libcarla/Map.cpp b/PythonAPI/source/libcarla/Map.cpp index 0108ef4e8..eda1abc1d 100644 --- a/PythonAPI/source/libcarla/Map.cpp +++ b/PythonAPI/source/libcarla/Map.cpp @@ -49,6 +49,16 @@ static auto GetTopology(const carla::client::Map &self) { return result; } +static auto GenerateWaypoints(const carla::client::Map &self, double distance) { + namespace py = boost::python; + auto waypoints = self.GenerateWaypoints(distance); + py::list result; + for (auto &&waypoint : waypoints) { + result.append(waypoint); + } + return result; +} + void export_map() { using namespace boost::python; namespace cc = carla::client; @@ -69,6 +79,7 @@ void export_map() { .def("get_spawn_points", CALL_RETURNING_COPY(cc::Map, GetRecommendedSpawnPoints)) .def("get_waypoint", &cc::Map::GetWaypoint, (arg("location"), arg("project_to_road")=true)) .def("get_topology", &GetTopology) + .def("generate_waypoints", &GenerateWaypoints) .def("to_opendrive", CALL_RETURNING_COPY(cc::Map, GetOpenDrive)) .def("save_to_disk", &SaveOpenDriveToDisk, (arg("path")="")) .def(self_ns::str(self_ns::self))