11 #include "Components/SkeletalMeshComponent.h" 12 #include "Components/StaticMeshComponent.h" 13 #include "Engine/SkeletalMesh.h" 14 #include "Engine/StaticMesh.h" 15 #include "EngineUtils.h" 16 #include "PhysicsEngine/PhysicsAsset.h" 23 return static_cast<typename std::underlying_type<T>::type
>(label);
27 if (String ==
"Building")
return crp::CityObjectLabel::Buildings;
28 else if (String ==
"Fence")
return crp::CityObjectLabel::Fences;
29 else if (String ==
"Pedestrian")
return crp::CityObjectLabel::Pedestrians;
30 else if (String ==
"Pole")
return crp::CityObjectLabel::Poles;
32 else if (String ==
"Road")
return crp::CityObjectLabel::Roads;
33 else if (String ==
"RoadLine")
return crp::CityObjectLabel::RoadLines;
34 else if (String ==
"SideWalk")
return crp::CityObjectLabel::Sidewalks;
36 else if (String ==
"Vegetation")
return crp::CityObjectLabel::Vegetation;
38 else if (String ==
"Wall")
return crp::CityObjectLabel::Walls;
39 else if (String ==
"Sky")
return crp::CityObjectLabel::Sky;
40 else if (String ==
"Ground")
return crp::CityObjectLabel::Ground;
41 else if (String ==
"Bridge")
return crp::CityObjectLabel::Bridge;
42 else if (String ==
"RailTrack")
return crp::CityObjectLabel::RailTrack;
43 else if (String ==
"GuardRail")
return crp::CityObjectLabel::GuardRail;
45 else if (String ==
"Static")
return crp::CityObjectLabel::Static;
46 else if (String ==
"Dynamic")
return crp::CityObjectLabel::Dynamic;
47 else if (String ==
"Water")
return crp::CityObjectLabel::Water;
48 else if (String ==
"Terrain")
return crp::CityObjectLabel::Terrain;
55 const bool bSetRenderCustomDepth) {
56 Component.SetCustomDepthStencilValue(
CastEnum(Label));
57 Component.SetRenderCustomDepth(
58 bSetRenderCustomDepth &&
64 return (Label == crp::CityObjectLabel::Pedestrians ||
72 uint32
id = Actor.GetUniqueID();
77 FLinearColor
Color(0.0f, 0.0f, 0.0f, 1.0f);
79 Color.G = ((
id & 0x00ff) >> 0) / 255.0f;
80 Color.B = ((
id & 0xff00) >> 8) / 255.0f;
92 #ifdef CARLA_TAGGER_EXTRA_LOG 93 UE_LOG(LogCarla, Log, TEXT(
"Actor: %s"), *Actor.GetName());
94 #endif // CARLA_TAGGER_EXTRA_LOG 97 TArray<UStaticMeshComponent *> StaticMeshComponents;
98 Actor.GetComponents<UStaticMeshComponent>(StaticMeshComponents);
99 for (UStaticMeshComponent *Component : StaticMeshComponents) {
102 #ifdef CARLA_TAGGER_EXTRA_LOG 103 UE_LOG(LogCarla, Log, TEXT(
" + StaticMeshComponent: %s"), *Component->GetName());
104 UE_LOG(LogCarla, Log, TEXT(
" - Label: \"%s\""), *
GetTagAsString(Label));
105 #endif // CARLA_TAGGER_EXTRA_LOG 107 if(!Component->IsVisible() || !Component->GetStaticMesh())
114 TArray<USceneComponent *> AttachedComponents = Component->GetAttachChildren();
115 for (USceneComponent *SceneComponent : AttachedComponents) {
116 UTaggedComponent *TaggedSceneComponent = Cast<UTaggedComponent>(SceneComponent);
117 if (
IsValid(TaggedSceneComponent)) {
118 TaggedComponent = TaggedSceneComponent;
119 #ifdef CARLA_TAGGER_EXTRA_LOG 120 UE_LOG(LogCarla, Log, TEXT(
" - Found Tag"));
121 #endif // CARLA_TAGGER_EXTRA_LOG 127 if (!TaggedComponent) {
128 TaggedComponent = NewObject<UTaggedComponent>(Component);
129 TaggedComponent->SetupAttachment(Component);
130 TaggedComponent->RegisterComponent();
131 #ifdef CARLA_TAGGER_EXTRA_LOG 132 UE_LOG(LogCarla, Log, TEXT(
" - Added Tag"));
133 #endif // CARLA_TAGGER_EXTRA_LOG 138 #ifdef CARLA_TAGGER_EXTRA_LOG 139 UE_LOG(LogCarla, Log, TEXT(
" - Color: %s"), *Color.ToString());
140 #endif // CARLA_TAGGER_EXTRA_LOG 143 TaggedComponent->MarkRenderStateDirty();
147 TArray<USkeletalMeshComponent *> SkeletalMeshComponents;
148 Actor.GetComponents<USkeletalMeshComponent>(SkeletalMeshComponents);
149 for (USkeletalMeshComponent *Component : SkeletalMeshComponents) {
152 #ifdef CARLA_TAGGER_EXTRA_LOG 153 UE_LOG(LogCarla, Log, TEXT(
" + SkeletalMeshComponent: %s"), *Component->GetName());
154 UE_LOG(LogCarla, Log, TEXT(
" - Label: \"%s\""), *
GetTagAsString(Label));
155 #endif // CARLA_TAGGER_EXTRA_LOG 157 if(!Component->IsVisible() || !Component->GetSkeletalMeshRenderData())
164 TArray<USceneComponent *> AttachedComponents = Component->GetAttachChildren();
165 for (USceneComponent *SceneComponent : AttachedComponents) {
166 UTaggedComponent *TaggedSceneComponent = Cast<UTaggedComponent>(SceneComponent);
167 if (
IsValid(TaggedSceneComponent)) {
168 TaggedComponent = TaggedSceneComponent;
169 #ifdef CARLA_TAGGER_EXTRA_LOG 170 UE_LOG(LogCarla, Log, TEXT(
" - Found Tag"));
171 #endif // CARLA_TAGGER_EXTRA_LOG 177 if (!TaggedComponent) {
178 TaggedComponent = NewObject<UTaggedComponent>(Component);
179 TaggedComponent->SetupAttachment(Component);
180 TaggedComponent->RegisterComponent();
181 #ifdef CARLA_TAGGER_EXTRA_LOG 182 UE_LOG(LogCarla, Log, TEXT(
" - Added Tag"));
183 #endif // CARLA_TAGGER_EXTRA_LOG 188 #ifdef CARLA_TAGGER_EXTRA_LOG 189 UE_LOG(LogCarla, Log, TEXT(
" - Color: %s"), *Color.ToString());
190 #endif // CARLA_TAGGER_EXTRA_LOG 193 TaggedComponent->MarkRenderStateDirty();
200 for (TActorIterator<AActor> it(&World); it; ++it) {
201 TagActor(**it, bTagForSemanticSegmentation);
208 TagActor(*Actor, bTagForSemanticSegmentation);
214 TArray<UPrimitiveComponent *> Components;
216 for (
auto *Component : Components) {
217 if (Component !=
nullptr) {
229 #define CARLA_GET_LABEL_STR(lbl) case crp::CityObjectLabel:: lbl : return TEXT(#lbl); 254 #undef CARLA_GET_LABEL_STR 264 PrimaryActorTick.bCanEverTick =
false;
268 void ATagger::PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent)
270 Super::PostEditChangeProperty(PropertyChangedEvent);
271 if (PropertyChangedEvent.Property) {
278 #endif // WITH_EDITOR
static void SetStencilValue(UPrimitiveComponent &Component, const crp::CityObjectLabel &Label, const bool bSetRenderCustomDepth)
sensor::data::Color Color
static crp::CityObjectLabel GetLabelByPath(const T *Object)
Method that computes the label corresponding to an specific object using the folder path in which it ...
static crp::CityObjectLabel GetTagOfTaggedComponent(const UPrimitiveComponent &Component)
Retrieve the tag of an already tagged component.
static void GetTagsOfTaggedActor(const AActor &Actor, TSet< crp::CityObjectLabel > &Tags)
Retrieve the tags of an already tagged actor.
static bool IsValid(const ACarlaWheeledVehicle *Vehicle)
static auto CastEnum(T label)
static void TagActorsInLevel(UWorld &World, bool bTagForSemanticSegmentation)
Set the tag of every actor in level.
carla::SharedPtr< cc::Actor > Actor
static FString GetTagAsString(crp::CityObjectLabel Tag)
Retrieve the tags of an already tagged actor.
bool bTagForSemanticSegmentation
#define CARLA_GET_LABEL_STR(lbl)
static FLinearColor GetActorLabelColor(const AActor &Actor, const crp::CityObjectLabel &Label)
static void TagActor(const AActor &Actor, bool bTagForSemanticSegmentation)
Set the tag of an actor.
static bool IsThing(const crp::CityObjectLabel &Label)
static crp::CityObjectLabel GetLabelByFolderName(const FString &String)
Method that computes the label corresponding to a folder path.
void SetColor(FLinearColor color)