From 96ba571dfdd9cb4e7de6ba620245f04cba33e1a4 Mon Sep 17 00:00:00 2001 From: nsubiron Date: Wed, 17 Oct 2018 01:14:05 +0200 Subject: [PATCH] Add bounding boxes to Python API --- LibCarla/source/carla/geom/BoundingBox.h | 8 ++++ .../libcarla/{Transform.cpp => Geom.cpp} | 37 ++++++++++++++++--- PythonAPI/source/libcarla/libcarla.cpp | 4 +- 3 files changed, 41 insertions(+), 8 deletions(-) rename PythonAPI/source/libcarla/{Transform.cpp => Geom.cpp} (74%) diff --git a/LibCarla/source/carla/geom/BoundingBox.h b/LibCarla/source/carla/geom/BoundingBox.h index b1c66bb02..7360da439 100644 --- a/LibCarla/source/carla/geom/BoundingBox.h +++ b/LibCarla/source/carla/geom/BoundingBox.h @@ -33,6 +33,14 @@ namespace geom { Location location; Vector3D extent; + bool operator==(const BoundingBox &rhs) const { + return (location == rhs.location) && (extent == rhs.extent); + } + + bool operator!=(const BoundingBox &rhs) const { + return !(*this == rhs); + } + #ifdef LIBCARLA_INCLUDED_FROM_UE4 explicit BoundingBox(const AActor *AnActor) { diff --git a/PythonAPI/source/libcarla/Transform.cpp b/PythonAPI/source/libcarla/Geom.cpp similarity index 74% rename from PythonAPI/source/libcarla/Transform.cpp rename to PythonAPI/source/libcarla/Geom.cpp index 41410f1ac..938ec7f11 100644 --- a/PythonAPI/source/libcarla/Transform.cpp +++ b/PythonAPI/source/libcarla/Geom.cpp @@ -4,24 +4,32 @@ // This work is licensed under the terms of the MIT license. // For a copy, see . +#include +#include +#include #include +#include #include namespace carla { namespace geom { - std::ostream &operator<<(std::ostream &out, const Vector3D &vector3D) { - out << "Vector3D(x=" << vector3D.x + template + static void WriteVector3D(std::ostream &out, const char *name, const T &vector3D) { + out << name + << "(x=" << vector3D.x << ", y=" << vector3D.y << ", z=" << vector3D.z << ')'; + } + + std::ostream &operator<<(std::ostream &out, const Vector3D &vector3D) { + WriteVector3D(out, "Vector3D", vector3D); return out; } std::ostream &operator<<(std::ostream &out, const Location &location) { - out << "Location(x=" << location.x - << ", y=" << location.y - << ", z=" << location.z << ')'; + WriteVector3D(out, "Location", location); return out; } @@ -37,10 +45,17 @@ namespace geom { return out; } + std::ostream &operator<<(std::ostream &out, const BoundingBox &box) { + out << "BoundingBox(" << box.location << ", "; + WriteVector3D(out, "Extent", box.extent); + out << ')'; + return out; + } + } // namespace geom } // namespace carla -void export_transform() { +void export_geom() { using namespace boost::python; namespace cg = carla::geom; @@ -91,4 +106,14 @@ void export_transform() { .def("__ne__", &cg::Transform::operator!=) .def(self_ns::str(self_ns::self)) ; + + class_("BoundingBox") + .def(init( + (arg("location")=cg::Location(), arg("extent")=cg::Vector3D()))) + .def_readwrite("location", &cg::BoundingBox::location) + .def_readwrite("extent", &cg::BoundingBox::extent) + .def("__eq__", &cg::BoundingBox::operator==) + .def("__ne__", &cg::BoundingBox::operator!=) + .def(self_ns::str(self_ns::self)) + ; } diff --git a/PythonAPI/source/libcarla/libcarla.cpp b/PythonAPI/source/libcarla/libcarla.cpp index 917bd3aa5..1f21ef65a 100644 --- a/PythonAPI/source/libcarla/libcarla.cpp +++ b/PythonAPI/source/libcarla/libcarla.cpp @@ -34,9 +34,9 @@ #include "Client.cpp" #include "Control.cpp" #include "Exception.cpp" +#include "Geom.cpp" #include "Sensor.cpp" #include "SensorData.cpp" -#include "Transform.cpp" #include "Weather.cpp" #include "World.cpp" @@ -44,7 +44,7 @@ BOOST_PYTHON_MODULE(libcarla) { using namespace boost::python; PyEval_InitThreads(); scope().attr("__path__") = "libcarla"; - export_transform(); + export_geom(); export_control(); export_blueprint(); export_actor();