CARLA
Loading...
Searching...
No Matches
InstanceSegmentationCamera.cpp
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
8#include "Carla.h"
10
11#include <util/ue-header-guard-begin.h>
12#include "Components/SceneCaptureComponent2D.h"
13#include <util/ue-header-guard-end.h>
14
19
21 const FObjectInitializer &ObjectInitializer)
22 : Super(ObjectInitializer)
23{
24 AddPostProcessingMaterial(TEXT("Material'/Carla/PostProcessingMaterials/PhysicLensDistortion.PhysicLensDistortion'"));
25 AddPostProcessingMaterial(TEXT("Material'/Game/Carla/PostProcessMaterials/M_InstanceSegmentationSensorMaterial'"));
26
27 // TODO: Setup OnActorSpawnHandler so we can refresh components
28 // World->AddOnActorSpawnedHandler(FOnActorSpawned::FDelegate::CreateRaw(this, &AInstanceSegmentationCamera::OnActorSpawned));
29}
30
32{
33 Super::SetUpSceneCaptureComponent(SceneCapture);
34 // This sensor's post-process material samples the segmentation ID buffer;
35 // ask the renderer to run the segmentation pass for this capture (it is
36 // skipped for every capture that does not opt in).
37 SceneCapture.bRequiresSegmentationPass = true;
38}
39
40void AInstanceSegmentationCamera::PostPhysTick(UWorld *World, ELevelTick TickType, float DeltaSeconds)
41{
42 TRACE_CPUPROFILER_EVENT_SCOPE(AInstanceSegmentationCamera::PostPhysTick);
43 Super::PostPhysTick(World, TickType, DeltaSeconds);
44
45 auto CaptureContext = MakeCaptureContext(*this);
46 ImageUtil::ReadSensorImageDataAsyncFColor(*this, [this, CaptureContext](
47 TArrayView<const FColor> Pixels,
48 FIntPoint Size) -> bool
49 {
50 SendDataToClient(*this, Pixels, CaptureContext);
51 return true;
52 });
53}
void SetUpSceneCaptureComponent(USceneCaptureComponent2D &SceneCapture) override
static FActorDefinition GetSensorDefinition()
void PostPhysTick(UWorld *World, ELevelTick TickType, float DeltaSeconds) override
AInstanceSegmentationCamera(const FObjectInitializer &ObjectInitializer)
static void SendDataToClient(SensorType &&Sensor, TArrayView< ElementType > SensorData, const FSensorCaptureContext &CaptureContext)
static FSensorCaptureContext MakeCaptureContext(const ASensor &Sensor)
Call on the game thread right after CaptureScene().
bool AddPostProcessingMaterial(const FString &Path)
Load the UMaterialInstanceDynamic at the given Path and append it to the list of shaders with Weight.
static FActorDefinition MakeCameraDefinition(const FString &Id, bool bEnableModifyingPostProcessEffects=false)
bool ReadSensorImageDataAsyncFColor(AShaderBasedSensor &Sensor, ReadImageDataAsyncCallbackFColor &&Callback)
A definition of a Carla Actor with all the variation and attributes.