12 #include "Components/SkeletalMeshComponent.h" 13 #include "Components/StaticMeshComponent.h" 14 #include "Engine/SkeletalMesh.h" 15 #include "Engine/StaticMesh.h" 16 #include "EngineUtils.h" 17 #include "PhysicsEngine/PhysicsAsset.h" 24 return static_cast<typename std::underlying_type<T>::type
>(label);
28 if (String ==
"Building")
return crp::CityObjectLabel::Buildings;
29 else if (String ==
"Fence")
return crp::CityObjectLabel::Fences;
30 else if (String ==
"Pedestrian")
return crp::CityObjectLabel::Pedestrians;
31 else if (String ==
"Pole")
return crp::CityObjectLabel::Poles;
33 else if (String ==
"Road")
return crp::CityObjectLabel::Roads;
34 else if (String ==
"RoadLine")
return crp::CityObjectLabel::RoadLines;
35 else if (String ==
"SideWalk")
return crp::CityObjectLabel::Sidewalks;
37 else if (String ==
"Vegetation")
return crp::CityObjectLabel::Vegetation;
38 else if (String ==
"Car")
return crp::CityObjectLabel::Car;
39 else if (String ==
"Wall")
return crp::CityObjectLabel::Walls;
40 else if (String ==
"Sky")
return crp::CityObjectLabel::Sky;
41 else if (String ==
"Ground")
return crp::CityObjectLabel::Ground;
42 else if (String ==
"Bridge")
return crp::CityObjectLabel::Bridge;
43 else if (String ==
"RailTrack")
return crp::CityObjectLabel::RailTrack;
44 else if (String ==
"GuardRail")
return crp::CityObjectLabel::GuardRail;
46 else if (String ==
"Static")
return crp::CityObjectLabel::Static;
47 else if (String ==
"Dynamic")
return crp::CityObjectLabel::Dynamic;
48 else if (String ==
"Water")
return crp::CityObjectLabel::Water;
49 else if (String ==
"Terrain")
return crp::CityObjectLabel::Terrain;
50 else if (String ==
"Truck")
return crp::CityObjectLabel::Truck;
51 else if (String ==
"Motorcycle")
return crp::CityObjectLabel::Motorcycle;
52 else if (String ==
"Bicycle")
return crp::CityObjectLabel::Bicycle;
53 else if (String ==
"Bus")
return crp::CityObjectLabel::Bus;
54 else if (String ==
"Rider")
return crp::CityObjectLabel::Rider;
55 else if (String ==
"Train")
return crp::CityObjectLabel::Train;
62 const bool bSetRenderCustomDepth) {
63 Component.SetCustomDepthStencilValue(
CastEnum(Label));
64 Component.SetRenderCustomDepth(
65 bSetRenderCustomDepth &&
71 return (Label == crp::CityObjectLabel::Pedestrians ||
73 Label == crp::CityObjectLabel::Car ||
74 Label == crp::CityObjectLabel::Train ||
75 Label == crp::CityObjectLabel::Bicycle ||
76 Label == crp::CityObjectLabel::Motorcycle ||
77 Label == crp::CityObjectLabel::Bus ||
78 Label == crp::CityObjectLabel::Rider ||
79 Label == crp::CityObjectLabel::Truck ||
85 uint32
id = Actor.GetUniqueID();
90 FLinearColor
Color(0.0f, 0.0f, 0.0f, 1.0f);
92 Color.G = ((
id & 0x00ff) >> 0) / 255.0f;
93 Color.B = ((
id & 0xff00) >> 8) / 255.0f;
105 #ifdef CARLA_TAGGER_EXTRA_LOG 106 UE_LOG(LogCarla, Log, TEXT(
"Actor: %s"), *Actor.GetName());
107 #endif // CARLA_TAGGER_EXTRA_LOG 110 TArray<UStaticMeshComponent *> StaticMeshComponents;
111 Actor.GetComponents<UStaticMeshComponent>(StaticMeshComponents);
112 for (UStaticMeshComponent *Component : StaticMeshComponents) {
114 if (Label == crp::CityObjectLabel::Pedestrians &&
115 Cast<ACarlaWheeledVehicle>(&Actor))
117 Label = crp::CityObjectLabel::Rider;
120 #ifdef CARLA_TAGGER_EXTRA_LOG 121 UE_LOG(LogCarla, Log, TEXT(
" + StaticMeshComponent: %s"), *Component->GetName());
122 UE_LOG(LogCarla, Log, TEXT(
" - Label: \"%s\""), *
GetTagAsString(Label));
123 #endif // CARLA_TAGGER_EXTRA_LOG 125 if(!Component->IsVisible() || !Component->GetStaticMesh())
132 TArray<USceneComponent *> AttachedComponents = Component->GetAttachChildren();
133 for (USceneComponent *SceneComponent : AttachedComponents) {
134 UTaggedComponent *TaggedSceneComponent = Cast<UTaggedComponent>(SceneComponent);
135 if (
IsValid(TaggedSceneComponent)) {
136 TaggedComponent = TaggedSceneComponent;
137 #ifdef CARLA_TAGGER_EXTRA_LOG 138 UE_LOG(LogCarla, Log, TEXT(
" - Found Tag"));
139 #endif // CARLA_TAGGER_EXTRA_LOG 145 if (!TaggedComponent) {
146 TaggedComponent = NewObject<UTaggedComponent>(Component);
147 TaggedComponent->SetupAttachment(Component);
148 TaggedComponent->RegisterComponent();
149 #ifdef CARLA_TAGGER_EXTRA_LOG 150 UE_LOG(LogCarla, Log, TEXT(
" - Added Tag"));
151 #endif // CARLA_TAGGER_EXTRA_LOG 156 #ifdef CARLA_TAGGER_EXTRA_LOG 157 UE_LOG(LogCarla, Log, TEXT(
" - Color: %s"), *Color.ToString());
158 #endif // CARLA_TAGGER_EXTRA_LOG 161 TaggedComponent->MarkRenderStateDirty();
165 TArray<USkeletalMeshComponent *> SkeletalMeshComponents;
166 Actor.GetComponents<USkeletalMeshComponent>(SkeletalMeshComponents);
167 for (USkeletalMeshComponent *Component : SkeletalMeshComponents) {
169 if (Label == crp::CityObjectLabel::Pedestrians &&
170 Cast<ACarlaWheeledVehicle>(&Actor))
172 Label = crp::CityObjectLabel::Rider;
175 #ifdef CARLA_TAGGER_EXTRA_LOG 176 UE_LOG(LogCarla, Log, TEXT(
" + SkeletalMeshComponent: %s"), *Component->GetName());
177 UE_LOG(LogCarla, Log, TEXT(
" - Label: \"%s\""), *
GetTagAsString(Label));
178 #endif // CARLA_TAGGER_EXTRA_LOG 180 if(!Component->IsVisible() || !Component->GetSkeletalMeshRenderData())
187 TArray<USceneComponent *> AttachedComponents = Component->GetAttachChildren();
188 for (USceneComponent *SceneComponent : AttachedComponents) {
189 UTaggedComponent *TaggedSceneComponent = Cast<UTaggedComponent>(SceneComponent);
190 if (
IsValid(TaggedSceneComponent)) {
191 TaggedComponent = TaggedSceneComponent;
192 #ifdef CARLA_TAGGER_EXTRA_LOG 193 UE_LOG(LogCarla, Log, TEXT(
" - Found Tag"));
194 #endif // CARLA_TAGGER_EXTRA_LOG 200 if (!TaggedComponent) {
201 TaggedComponent = NewObject<UTaggedComponent>(Component);
202 TaggedComponent->SetupAttachment(Component);
203 TaggedComponent->RegisterComponent();
204 #ifdef CARLA_TAGGER_EXTRA_LOG 205 UE_LOG(LogCarla, Log, TEXT(
" - Added Tag"));
206 #endif // CARLA_TAGGER_EXTRA_LOG 211 #ifdef CARLA_TAGGER_EXTRA_LOG 212 UE_LOG(LogCarla, Log, TEXT(
" - Color: %s"), *Color.ToString());
213 #endif // CARLA_TAGGER_EXTRA_LOG 216 TaggedComponent->MarkRenderStateDirty();
217 TaggedComponent->SetComponentTickEnabled(
true);
224 for (TActorIterator<AActor> it(&World); it; ++it) {
225 TagActor(**it, bTagForSemanticSegmentation);
232 TagActor(*Actor, bTagForSemanticSegmentation);
238 TArray<UPrimitiveComponent *> Components;
240 for (
auto *Component : Components) {
241 if (Component !=
nullptr) {
253 #define CARLA_GET_LABEL_STR(lbl) case crp::CityObjectLabel:: lbl : return TEXT(#lbl); 285 #undef CARLA_GET_LABEL_STR 295 PrimaryActorTick.bCanEverTick =
false;
299 void ATagger::PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent)
301 Super::PostEditChangeProperty(PropertyChangedEvent);
302 if (PropertyChangedEvent.Property) {
309 #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)