Add bounding boxes to actors

This commit is contained in:
nsubiron 2018-10-16 21:17:40 +02:00
parent 050467e109
commit 23470ad4fb
4 changed files with 64 additions and 1 deletions

View File

@ -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};
}

View File

@ -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 <https://opensource.org/licenses/MIT>.
#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

View File

@ -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());
}

View File

@ -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))