Return waypoints and spawn points as pure Python lists
This commit is contained in:
parent
e5c4f593d0
commit
0a06dc7db6
|
@ -9,8 +9,6 @@
|
|||
#include <carla/client/Map.h>
|
||||
#include <carla/client/Waypoint.h>
|
||||
|
||||
#include <boost/python/suite/indexing/vector_indexing_suite.hpp>
|
||||
|
||||
#include <fstream>
|
||||
|
||||
namespace carla {
|
||||
|
@ -49,37 +47,17 @@ 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;
|
||||
namespace cg = carla::geom;
|
||||
|
||||
class_<std::vector<cg::Transform>>("vector_of_transforms")
|
||||
.def(vector_indexing_suite<std::vector<cg::Transform>>())
|
||||
.def(self_ns::str(self_ns::self))
|
||||
;
|
||||
|
||||
class_<std::vector<carla::SharedPtr<cc::Waypoint>>>("vector_of_waypoints")
|
||||
.def(vector_indexing_suite<std::vector<carla::SharedPtr<cc::Waypoint>>, true>())
|
||||
.def(self_ns::str(self_ns::self))
|
||||
;
|
||||
|
||||
class_<cc::Map, boost::noncopyable, boost::shared_ptr<cc::Map>>("Map", no_init)
|
||||
.add_property("name", CALL_RETURNING_COPY(cc::Map, GetName))
|
||||
.def("get_spawn_points", CALL_RETURNING_COPY(cc::Map, GetRecommendedSpawnPoints))
|
||||
.def("get_spawn_points", CALL_RETURNING_LIST(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("generate_waypoints", CALL_RETURNING_LIST_1(cc::Map, GenerateWaypoints, double), (args("distance")))
|
||||
.def("to_opendrive", CALL_RETURNING_COPY(cc::Map, GetOpenDrive))
|
||||
.def("save_to_disk", &SaveOpenDriveToDisk, (arg("path")=""))
|
||||
.def(self_ns::str(self_ns::self))
|
||||
|
@ -89,7 +67,7 @@ void export_map() {
|
|||
.add_property("transform", CALL_RETURNING_COPY(cc::Waypoint, GetTransform))
|
||||
.add_property("road_id", &cc::Waypoint::GetRoadId)
|
||||
.add_property("lane_id", &cc::Waypoint::GetLaneId)
|
||||
.def("next", &cc::Waypoint::Next, (args("distance")))
|
||||
.def("next", CALL_RETURNING_LIST_1(cc::Waypoint, Next, double), (args("distance")))
|
||||
.def(self_ns::str(self_ns::self))
|
||||
;
|
||||
}
|
||||
|
|
|
@ -28,9 +28,29 @@
|
|||
}
|
||||
|
||||
// Convenient for const requests that need to make a copy of the returned value.
|
||||
#define CALL_RETURNING_COPY_1(cls, fn, _T1) +[](const cls &self, _T1 t1) \
|
||||
-> std::decay_t<std::result_of_t<decltype(&cls::fn)(cls*, _T1)>> { \
|
||||
return self.fn(std::forward<_T1>(t1)); \
|
||||
#define CALL_RETURNING_COPY_1(cls, fn, T1_) +[](const cls &self, T1_ t1) \
|
||||
-> std::decay_t<std::result_of_t<decltype(&cls::fn)(cls*, T1_)>> { \
|
||||
return self.fn(std::forward<T1_>(t1)); \
|
||||
}
|
||||
|
||||
// Convenient for const requests that needs to convert the return value to a
|
||||
// Python list.
|
||||
#define CALL_RETURNING_LIST(cls, fn) +[](const cls &self) { \
|
||||
boost::python::list result; \
|
||||
for (auto &&item : self.fn()) { \
|
||||
result.append(item); \
|
||||
} \
|
||||
return result; \
|
||||
}
|
||||
|
||||
// Convenient for const requests that needs to convert the return value to a
|
||||
// Python list.
|
||||
#define CALL_RETURNING_LIST_1(cls, fn, T1_) +[](const cls &self, T1_ t1) { \
|
||||
boost::python::list result; \
|
||||
for (auto &&item : self.fn(std::forward<T1_>(t1))) { \
|
||||
result.append(item); \
|
||||
} \
|
||||
return result; \
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
|
|
Loading…
Reference in New Issue