CARLA
Toggle main menu visibility
Loading...
Searching...
No Matches
Unreal
CarlaUnreal
Plugins
Carla
Source
Carla
Game
Tagger.h
Go to the documentation of this file.
1
// Copyright (c) 2026 Computer Vision Center (CVC) at the Universitat Autonoma
2
// de Barcelona (UAB).
3
//
4
// This work is licensed under the terms of the MIT license.
5
// For a copy, see <https://opensource.org/licenses/MIT>.
6
7
#pragma once
8
9
#include <
util/disable-ue4-macros.h
>
10
#include <
carla/rpc/ObjectLabel.h
>
11
#include <
util/enable-ue4-macros.h
>
12
13
#include <util/ue-header-guard-begin.h>
14
#include "GameFramework/Actor.h"
15
#include "Components/PrimitiveComponent.h"
16
#include <util/ue-header-guard-end.h>
17
18
#include "Tagger.generated.h"
19
20
namespace
crp
=
carla::rpc
;
21
22
/// Sets actors' custom depth stencil value for semantic segmentation according
23
/// to their meshes.
24
///
25
/// Non-static functions present so it can be dropped into the scene for testing
26
/// purposes.
27
UCLASS()
28
class CARLA_API
ATagger
: public
AActor
29
{
30
GENERATED_BODY()
31
32
public
:
33
34
/// Set the tag of an actor.
35
///
36
/// If bTagForSemanticSegmentation true, activate the custom depth pass. This
37
/// pass is necessary for rendering the semantic segmentation. However, it may
38
/// add a performance penalty since occlusion doesn't seem to be applied to
39
/// objects having this value active.
40
static
void
TagActor
(
const
AActor
&Actor,
bool
bTagForSemanticSegmentation
);
41
42
43
/// Set the tag of every actor in level.
44
///
45
/// If bTagForSemanticSegmentation true, activate the custom depth pass. This
46
/// pass is necessary for rendering the semantic segmentation. However, it may
47
/// add a performance penalty since occlusion doesn't seem to be applied to
48
/// objects having this value active.
49
static
void
TagActorsInLevel
(UWorld &World,
bool
bTagForSemanticSegmentation
);
50
51
static
void
TagActorsInLevel
(ULevel &Level,
bool
bTagForSemanticSegmentation
);
52
53
/// Retrieve the tag of an already tagged component.
54
static
crp::CityObjectLabel
GetTagOfTaggedComponent
(
const
UPrimitiveComponent &Component);
55
56
/// Retrieve the tags of an already tagged actor. CityObjectLabel::None is
57
/// not added to the array.
58
static
void
GetTagsOfTaggedActor
(
const
AActor
&Actor, TSet<crp::CityObjectLabel> &Tags);
59
60
/// Return true if @a Component has been tagged with the given @a Tag.
61
static
bool
MatchComponent
(
const
UPrimitiveComponent &Component,
crp::CityObjectLabel
Tag)
62
{
63
return
(Tag ==
GetTagOfTaggedComponent
(Component));
64
}
65
66
/// Transform a string into a CityObjectLabel.
67
static
crp::CityObjectLabel
GetTagFromString(FString Tag);
68
69
/// Transform a tag name into a CityObjectLabel.
70
static
crp::CityObjectLabel
GetTagFromName(
const
FName &Tag);
71
72
/// Transform a CityObjectLabel into a string.
73
static
FString GetTagAsString(
crp::CityObjectLabel
Tag);
74
75
/// Method that computes the label corresponding to a folder path
76
static
crp::CityObjectLabel
GetLabelByFolderName(
const
FString &String);
77
78
/// Method that computes the label corresponding to an specific object
79
/// using the folder path in which it is stored
80
template
<
typename
T>
81
static
crp::CityObjectLabel
GetLabelByPath
(
const
T* Object)
82
{
83
if
(Object ==
nullptr
)
84
{
85
// A component whose mesh is not assigned yet (props get their mesh
86
// after SpawnActor, i.e. after the OnActorSpawned tagger delegate).
87
return
crp::CityObjectLabel::None
;
88
}
89
const
FString Path = Object->GetPathName();
90
TArray<FString> StringArray;
91
Path.ParseIntoArray(StringArray, TEXT(
"/"
),
false
);
92
if
(!Path.StartsWith(TEXT(
"/Game/"
)))
93
{
94
// Content pack (or any other mount root): same folder rule as the base
95
// content, /<Pack>/Static/<Tag>/..., i.e. the folder right after the
96
// first "Static" folder names the label. Plugin content without a
97
// "Static" folder falls through to the nearest-folder fallback below.
98
for
(int32 i = 1; i + 1 < StringArray.Num(); ++i)
99
{
100
if
(StringArray[i] == TEXT(
"Static"
))
101
{
102
const
crp::CityObjectLabel
PackLabel =
GetLabelByFolderName
(StringArray[i + 1]);
103
if
(PackLabel !=
crp::CityObjectLabel::None
)
104
{
105
return
PackLabel;
106
}
107
break
;
108
}
109
}
110
}
111
const
int32 Primary = Path.Contains(
"UE5UseOnly"
) ? 5 : 4;
112
crp::CityObjectLabel
Label =
113
(StringArray.Num() > Primary ?
GetLabelByFolderName
(StringArray[Primary]) :
crp::CityObjectLabel::None
);
114
// Fallback for content mounted outside /Game/Carla/Static/<Label>/... (e.g. plugin
115
// content such as /CarlaDigitalTwinsTool/Static/Building/...): the labelled folder
116
// nearest the asset wins. Runs only when the fixed-index lookup found nothing, so
117
// classic content keeps its exact previous labels.
118
for
(int32 i = StringArray.Num() - 2; i >= 0 && Label ==
crp::CityObjectLabel::None
; --i)
119
{
120
Label =
GetLabelByFolderName
(StringArray[i]);
121
}
122
return
Label;
123
}
124
125
/// Method that computes the label corresponding to an specific object
126
/// using the folder path in which it is stored
127
template
<
typename
T>
128
static
crp::CityObjectLabel
GetLabelByPath
(TObjectPtr<T> Object)
129
{
130
return
GetLabelByPath
(Object.Get());
131
}
132
133
//TODO: Change function name to reflect the new functionality
134
static
void
SetStencilValue(UPrimitiveComponent &Component,
const
uint32 ActorID,
135
const
crp::CityObjectLabel
&Label,
const
bool
bSetRenderCustomDepth);
136
137
static
FLinearColor GetActorLabelColor(
const
AActor
&Actor,
const
crp::CityObjectLabel
&Label);
138
139
static
bool
IsThing(
const
crp::CityObjectLabel
&Label);
140
141
ATagger
();
142
143
protected
:
144
145
#if WITH_EDITOR
146
virtual
void
PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent)
override
;
147
#endif
// WITH_EDITOR
148
149
private
:
150
151
UPROPERTY(Category =
"Tagger"
, EditAnywhere)
152
bool
bTriggerTagObjects
= false;
153
154
UPROPERTY(Category =
"Tagger"
, EditAnywhere)
155
bool
bTagForSemanticSegmentation
= false;
156
157
};
ObjectLabel.h
AActor
ATagger::GetLabelByPath
static crp::CityObjectLabel GetLabelByPath(TObjectPtr< T > Object)
Method that computes the label corresponding to an specific object using the folder path in which it ...
Definition
Tagger.h:128
ATagger::GetTagsOfTaggedActor
static void GetTagsOfTaggedActor(const AActor &Actor, TSet< crp::CityObjectLabel > &Tags)
Retrieve the tags of an already tagged actor.
Definition
Tagger.cpp:221
ATagger::GetLabelByFolderName
static crp::CityObjectLabel GetLabelByFolderName(const FString &String)
Method that computes the label corresponding to a folder path.
Definition
Tagger.cpp:28
ATagger::GetTagOfTaggedComponent
static crp::CityObjectLabel GetTagOfTaggedComponent(const UPrimitiveComponent &Component)
Retrieve the tag of an already tagged component.
Definition
Tagger.cpp:213
ATagger::bTriggerTagObjects
bool bTriggerTagObjects
Definition
Tagger.h:152
ATagger::MatchComponent
static bool MatchComponent(const UPrimitiveComponent &Component, crp::CityObjectLabel Tag)
Return true if Component has been tagged with the given Tag.
Definition
Tagger.h:61
ATagger::ATagger
ATagger()
Definition
Tagger.cpp:313
ATagger::GetLabelByPath
static crp::CityObjectLabel GetLabelByPath(const T *Object)
Method that computes the label corresponding to an specific object using the folder path in which it ...
Definition
Tagger.h:81
ATagger::bTagForSemanticSegmentation
bool bTagForSemanticSegmentation
Definition
Tagger.h:155
ATagger::TagActor
static void TagActor(const AActor &Actor, bool bTagForSemanticSegmentation)
Set the tag of an actor.
Definition
Tagger.cpp:130
ATagger::TagActorsInLevel
static void TagActorsInLevel(UWorld &World, bool bTagForSemanticSegmentation)
Set the tag of every actor in level.
Definition
Tagger.cpp:177
disable-ue4-macros.h
enable-ue4-macros.h
carla::rpc
Definition
DebugShapeDrawer.h:11
carla::rpc::CityObjectLabel
CityObjectLabel
Definition
ObjectLabel.h:16
carla::rpc::CityObjectLabel::None
@ None
Definition
ObjectLabel.h:17
Generated by
1.18.0