From 23470ad4fb51563bca51e3a5b4b461537af625d9 Mon Sep 17 00:00:00 2001 From: nsubiron Date: Tue, 16 Oct 2018 21:17:40 +0200 Subject: [PATCH] Add bounding boxes to actors --- .../source/carla/client/detail/ActorState.h | 4 ++ LibCarla/source/carla/geom/BoundingBox.h | 53 +++++++++++++++++++ LibCarla/source/carla/rpc/Actor.h | 7 ++- PythonAPI/source/libcarla/Actor.cpp | 1 + 4 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 LibCarla/source/carla/geom/BoundingBox.h diff --git a/LibCarla/source/carla/client/detail/ActorState.h b/LibCarla/source/carla/client/detail/ActorState.h index 7952e89e8..faa92fb49 100644 --- a/LibCarla/source/carla/client/detail/ActorState.h +++ b/LibCarla/source/carla/client/detail/ActorState.h @@ -31,6 +31,10 @@ namespace detail { std::string GetDisplayId() const; + const geom::BoundingBox &GetBoundingBox() const { + return _description.bounding_box; + } + World GetWorld() const { return World{_episode}; } diff --git a/LibCarla/source/carla/geom/BoundingBox.h b/LibCarla/source/carla/geom/BoundingBox.h new file mode 100644 index 000000000..b1c66bb02 --- /dev/null +++ b/LibCarla/source/carla/geom/BoundingBox.h @@ -0,0 +1,53 @@ +// 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 . + +#pragma once + +#include "carla/Debug.h" +#include "carla/MsgPack.h" +#include "carla/geom/Location.h" +#include "carla/geom/Vector3D.h" + +#ifdef LIBCARLA_INCLUDED_FROM_UE4 +# include "GameFramework/Actor.h" +#endif // LIBCARLA_INCLUDED_FROM_UE4 + +namespace carla { +namespace geom { + + class BoundingBox { + public: + + BoundingBox() = default; + + explicit BoundingBox(const Location &in_location, const Vector3D &in_extent) + : location(in_location), + extent(in_extent) {} + + explicit BoundingBox(const Vector3D &in_extent) + : extent(in_extent) {} + + Location location; + Vector3D extent; + +#ifdef LIBCARLA_INCLUDED_FROM_UE4 + + explicit BoundingBox(const AActor *AnActor) { + DEBUG_ASSERT(AnActor != nullptr); + constexpr bool bOnlyCollidingComponents = true; + FVector Origin, BoxExtent; + AnActor->GetActorBounds(bOnlyCollidingComponents, Origin, BoxExtent); + location = Location(Origin); + extent = Vector3D(1e-2f * BoxExtent.X, 1e-2f * BoxExtent.Y, 1e-2f * BoxExtent.Z); + } + +#endif // LIBCARLA_INCLUDED_FROM_UE4 + + MSGPACK_DEFINE_ARRAY(location, extent); + }; + +} // namespace geom +} // namespace carla diff --git a/LibCarla/source/carla/rpc/Actor.h b/LibCarla/source/carla/rpc/Actor.h index a5c596ca7..162ecbcf1 100644 --- a/LibCarla/source/carla/rpc/Actor.h +++ b/LibCarla/source/carla/rpc/Actor.h @@ -7,6 +7,7 @@ #pragma once #include "carla/Debug.h" +#include "carla/geom/BoundingBox.h" #include "carla/rpc/ActorDescription.h" #include "carla/streaming/Token.h" @@ -26,6 +27,8 @@ namespace rpc { ActorDescription description; + geom::BoundingBox bounding_box; + /// @todo This is only used by sensors actually. /// @name Sensor functionality /// @{ @@ -49,13 +52,15 @@ namespace rpc { Actor(FActorView View) : id(View.GetActorId()), - description(*View.GetActorDescription()) { + description(*View.GetActorDescription()), + bounding_box(View.GetActor()) { DEBUG_ASSERT(View.IsValid()); } Actor(FActorView View, const streaming::Token &StreamToken) : id(View.GetActorId()), description(*View.GetActorDescription()), + bounding_box(View.GetActor()), stream_token(StreamToken.data.begin(), StreamToken.data.end()) { DEBUG_ASSERT(View.IsValid()); } diff --git a/PythonAPI/source/libcarla/Actor.cpp b/PythonAPI/source/libcarla/Actor.cpp index 2a50908f1..b16c35008 100644 --- a/PythonAPI/source/libcarla/Actor.cpp +++ b/PythonAPI/source/libcarla/Actor.cpp @@ -30,6 +30,7 @@ void export_actor() { // work-around, force return copy to resolve Actor instead of ActorState. .add_property("id", CALL_RETURNING_COPY(cc::Actor, GetId)) .add_property("type_id", CALL_RETURNING_COPY(cc::Actor, GetTypeId)) + .add_property("bounding_box", CALL_RETURNING_COPY(cc::Actor, GetBoundingBox)) .add_property("is_alive", CALL_RETURNING_COPY(cc::Actor, IsAlive)) .def("get_world", CALL_RETURNING_COPY(cc::Actor, GetWorld)) .def("get_location", CONST_CALL_WITHOUT_GIL(cc::Actor, GetLocation))