CARLA
Loading...
Searching...
No Matches
ShowOnlyFilter.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
12
13#include <util/ue-header-guard-begin.h>
14#include "CoreMinimal.h"
15#include "UObject/WeakObjectPtr.h"
16#include <util/ue-header-guard-end.h>
17
18class AActor;
19class UCarlaEpisode;
21class UWorld;
22
23/// Show-only ("render layer") filter shared by every scene-capture camera.
24///
25/// Selected through three blueprint attributes:
26///
27/// show_only_tags comma separated CARLA semantic label names
28/// ("Car,Truck,Bus,Motorcycle,Bicycle,Pedestrians").
29/// shadow_catcher_tags same format; actors carrying these labels are
30/// rendered too so they can receive the cast shadows
31/// of the show-only actors ("Roads,Sidewalks").
32/// show_only_actor_ids comma separated CARLA actor ids, added to the list
33/// whatever their labels.
34///
35/// When show_only_tags or show_only_actor_ids is non-empty the capture
36/// components switch to PRM_UseShowOnlyList and their ShowOnlyActors list is
37/// the set of world actors carrying at least one of the labels (any
38/// primitive component, ATagger label tag or custom-depth stencil), plus the
39/// id list. Everything else is neither rendered nor casts shadows into the
40/// capture (the renderer filters shadow casters through the same list), so
41/// the empty pixels carry only the sky / atmosphere in colour captures,
42/// stencil 0 in the segmentation captures and the far plane in depth.
43///
44/// The actor scan runs only when the world's actor count changes (spawn or
45/// destroy) so newly spawned vehicles show up on the next capture; every
46/// other tick costs one integer compare plus copying the cached list into
47/// the capture components.
48struct CARLA_API FCarlaShowOnlyFilter
49{
51
52 /// Parse a comma separated list of label names into @a OutLabels using the
53 /// tagger's own name mapping. Returns false and fills @a OutUnknown with
54 /// the tokens that map to no label (they are skipped).
55 static bool ParseLabels(const FString &CommaSeparated, TSet<Label> &OutLabels, FString &OutUnknown);
56
57 void SetShowOnlyTags(const FString &CommaSeparated);
58
59 void SetShadowCatcherTags(const FString &CommaSeparated);
60
61 void SetShowOnlyActorIds(const FString &CommaSeparated);
62
63 bool IsEnabled() const
64 {
65 return ShowOnlyTags.Num() > 0 || ActorIds.Num() > 0;
66 }
67
68 const TSet<Label> &GetShowOnlyTags() const { return ShowOnlyTags; }
69 const TSet<Label> &GetShadowCatcherTags() const { return ShadowCatcherTags; }
70 const TSet<uint32> &GetShowOnlyActorIds() const { return ActorIds; }
71
72 /// Rebuild the cached actor list if the world changed since the last call.
73 /// Cheap when nothing changed. @a Episode may be null (ids are then
74 /// ignored).
75 void Refresh(UWorld *World, const UCarlaEpisode *Episode);
76
77 /// Push the current list into @a Capture (or restore full-scene rendering
78 /// when the filter is disabled).
79 void ApplyTo(USceneCaptureComponent2D &Capture) const;
80
81 /// Force a rescan on the next Refresh.
82 void MarkDirty() { bDirty = true; }
83
84 int32 GetCachedActorCount() const { return CachedActors.Num(); }
85
86private:
87
88 void Rescan(UWorld *World, const UCarlaEpisode *Episode);
89
90 TSet<Label> ShowOnlyTags;
91 TSet<Label> ShadowCatcherTags;
92 TSet<uint32> ActorIds;
93
94 TArray<TWeakObjectPtr<AActor>> CachedActors;
95 int32 LastActorCount = -1;
96 bool bDirty = true;
97};
A simulation episode.
Show-only ("render layer") filter shared by every scene-capture camera.
TArray< TWeakObjectPtr< AActor > > CachedActors
int32 GetCachedActorCount() const
const TSet< Label > & GetShowOnlyTags() const
TSet< Label > ShadowCatcherTags
const TSet< uint32 > & GetShowOnlyActorIds() const
const TSet< Label > & GetShadowCatcherTags() const
TSet< Label > ShowOnlyTags
TSet< uint32 > ActorIds
void MarkDirty()
Force a rescan on the next Refresh.