Add more info to actor view, including serialized data
This commit is contained in:
parent
c7561c5ef7
commit
1f34cf33b7
|
@ -24,7 +24,8 @@ namespace rpc {
|
|||
|
||||
actor_id_type id = 0u;
|
||||
|
||||
actor_id_type parent_id;
|
||||
/// @todo parent should not be here as it may change during the simulation.
|
||||
actor_id_type parent_id = 0u;
|
||||
|
||||
ActorDescription description;
|
||||
|
||||
|
|
|
@ -83,7 +83,7 @@ bool FActorDispatcher::DestroyActor(AActor *Actor)
|
|||
UE_LOG(LogCarla, Warning, TEXT("Trying to destroy actor that is not in the registry"));
|
||||
return false;
|
||||
}
|
||||
const auto &Id = View.GetActorDescription()->Id;
|
||||
const auto &Id = View.GetActorInfo()->Description.Id;
|
||||
|
||||
// Destroy its controller if present.
|
||||
auto Pawn = Cast<APawn>(Actor);
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
// 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/Actor/ActorDescription.h"
|
||||
#include "Carla/Game/Tagger.h"
|
||||
|
||||
#include <compiler/disable-ue4-macros.h>
|
||||
#include <carla/rpc/Actor.h>
|
||||
#include <compiler/enable-ue4-macros.h>
|
||||
|
||||
/// A view over an actor and its properties.
|
||||
struct FActorInfo
|
||||
{
|
||||
public:
|
||||
|
||||
FActorDescription Description;
|
||||
|
||||
TSet<ECityObjectLabel> SemanticTags;
|
||||
|
||||
FBoundingBox BoundingBox;
|
||||
|
||||
carla::rpc::Actor SerializedData;
|
||||
};
|
|
@ -11,6 +11,7 @@
|
|||
|
||||
#include "Carla/Game/Tagger.h"
|
||||
#include "Carla/Traffic/TrafficLightBase.h"
|
||||
#include "Carla/Util/BoundingBoxCalculator.h"
|
||||
|
||||
static FActorView::ActorType FActorRegistry_GetActorType(const FActorView &View)
|
||||
{
|
||||
|
@ -32,9 +33,9 @@ static FActorView::ActorType FActorRegistry_GetActorType(const FActorView &View)
|
|||
return FActorView::ActorType::Other;
|
||||
}
|
||||
|
||||
static FString GetRelevantTagAsString(const FActorView &View)
|
||||
static FString GetRelevantTagAsString(const TSet<ECityObjectLabel> &SemanticTags)
|
||||
{
|
||||
for (auto &&Tag : View.GetSemanticTags())
|
||||
for (auto &&Tag : SemanticTags)
|
||||
{
|
||||
if ((Tag != ECityObjectLabel::None) && (Tag != ECityObjectLabel::Other))
|
||||
{
|
||||
|
@ -61,9 +62,7 @@ FActorView FActorRegistry::Register(AActor &Actor, FActorDescription Description
|
|||
}
|
||||
Ids.Emplace(&Actor, Id);
|
||||
|
||||
auto View = FActorView(Id, Actor, std::move(Description));
|
||||
ATagger::GetTagsOfTaggedActor(Actor, View.SemanticTags);
|
||||
View.Type = FActorRegistry_GetActorType(View);
|
||||
auto View = MakeView(Id, Actor, std::move(Description));
|
||||
|
||||
auto Result = ActorDatabase.emplace(Id, View);
|
||||
check(Result.second);
|
||||
|
@ -91,19 +90,44 @@ void FActorRegistry::Deregister(AActor *Actor)
|
|||
|
||||
FActorView FActorRegistry::FindOrFake(AActor *Actor) const
|
||||
{
|
||||
if (Actor == nullptr)
|
||||
{
|
||||
return {};
|
||||
}
|
||||
auto View = Find(Actor);
|
||||
if (!View.IsValid())
|
||||
{
|
||||
View.TheActor = Actor;
|
||||
ATagger::GetTagsOfTaggedActor(*Actor, View.SemanticTags);
|
||||
auto Description = MakeShared<FActorDescription>();
|
||||
Description->Id = TEXT("static.") + GetRelevantTagAsString(View);
|
||||
View.Description = Description;
|
||||
check(View.IsValid());
|
||||
return View.IsValid() ? View : MakeView(0u, *Actor, FActorDescription{});
|
||||
}
|
||||
|
||||
FActorView FActorRegistry::MakeView(
|
||||
IdType Id,
|
||||
AActor &Actor,
|
||||
FActorDescription Description) const
|
||||
{
|
||||
auto Info = MakeShared<FActorInfo>();
|
||||
Info->Description = std::move(Description);
|
||||
ATagger::GetTagsOfTaggedActor(Actor, Info->SemanticTags);
|
||||
Info->BoundingBox = UBoundingBoxCalculator::GetActorBoundingBox(&Actor);
|
||||
|
||||
if (Info->Description.Id.IsEmpty())
|
||||
{
|
||||
// This is a fake actor, let's fake the id based on their semantic tags.
|
||||
Info->Description.Id = TEXT("static.") + GetRelevantTagAsString(Info->SemanticTags);
|
||||
}
|
||||
|
||||
Info->SerializedData.id = Id;
|
||||
Info->SerializedData.description = Info->Description;
|
||||
Info->SerializedData.bounding_box = Info->BoundingBox;
|
||||
Info->SerializedData.semantic_tags.reserve(Info->SemanticTags.Num());
|
||||
for (auto &&Tag : Info->SemanticTags)
|
||||
{
|
||||
using tag_t = decltype(Info->SerializedData.semantic_tags)::value_type;
|
||||
Info->SerializedData.semantic_tags.emplace_back(static_cast<tag_t>(Tag));
|
||||
}
|
||||
auto *Sensor = Cast<ASensor>(&Actor);
|
||||
if (Sensor != nullptr)
|
||||
{
|
||||
const auto &Token = Sensor->GetToken();
|
||||
Info->SerializedData.stream_token = decltype(Info->SerializedData.stream_token)(
|
||||
std::begin(Token.data),
|
||||
std::end(Token.data));
|
||||
}
|
||||
auto View = FActorView{Id, Actor, std::move(Info)};
|
||||
View.Type = FActorRegistry_GetActorType(View);
|
||||
return View;
|
||||
}
|
||||
|
|
|
@ -109,6 +109,8 @@ public:
|
|||
/// @}
|
||||
private:
|
||||
|
||||
FActorView MakeView(IdType Id, AActor &Actor, FActorDescription Description) const;
|
||||
|
||||
TMap<IdType, AActor *> Actors;
|
||||
|
||||
TMap<AActor *, IdType> Ids;
|
||||
|
|
|
@ -6,8 +6,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "Carla/Actor/ActorDescription.h"
|
||||
#include "Carla/Game/Tagger.h"
|
||||
#include "Carla/Actor/ActorInfo.h"
|
||||
|
||||
class AActor;
|
||||
|
||||
|
@ -27,10 +26,11 @@ public:
|
|||
|
||||
FActorView() = default;
|
||||
FActorView(const FActorView &) = default;
|
||||
FActorView(FActorView &&) = default;
|
||||
|
||||
bool IsValid() const
|
||||
{
|
||||
return (TheActor != nullptr) && Description.IsValid();
|
||||
return (TheActor != nullptr) && Info.IsValid();
|
||||
}
|
||||
|
||||
IdType GetActorId() const
|
||||
|
@ -53,24 +53,19 @@ public:
|
|||
return TheActor;
|
||||
}
|
||||
|
||||
const FActorDescription *GetActorDescription() const
|
||||
const FActorInfo *GetActorInfo() const
|
||||
{
|
||||
return Description.Get();
|
||||
}
|
||||
|
||||
const TSet<ECityObjectLabel> &GetSemanticTags() const
|
||||
{
|
||||
return SemanticTags;
|
||||
return Info.Get();
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
friend class FActorRegistry;
|
||||
|
||||
FActorView(IdType ActorId, AActor &Actor, FActorDescription Description)
|
||||
FActorView(IdType ActorId, AActor &Actor, TSharedPtr<const FActorInfo> Info)
|
||||
: Id(ActorId),
|
||||
TheActor(&Actor),
|
||||
Description(MakeShared<FActorDescription>(std::move(Description))) {}
|
||||
Info(std::move(Info)) {}
|
||||
|
||||
IdType Id = 0u;
|
||||
|
||||
|
@ -78,7 +73,5 @@ private:
|
|||
|
||||
AActor *TheActor = nullptr;
|
||||
|
||||
TSharedPtr<const FActorDescription> Description = nullptr;
|
||||
|
||||
TSet<ECityObjectLabel> SemanticTags;
|
||||
TSharedPtr<const FActorInfo> Info = nullptr;
|
||||
};
|
||||
|
|
|
@ -32,6 +32,11 @@ public:
|
|||
Stream = std::move(InStream);
|
||||
}
|
||||
|
||||
auto GetToken() const
|
||||
{
|
||||
return Stream.GetToken();
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
void EndPlay(EEndPlayReason::Type EndPlayReason) override;
|
||||
|
|
Loading…
Reference in New Issue