Agrarsense
InstanceSegmentationCamera.cpp
Go to the documentation of this file.
1// Copyright (c) 2025 FrostBit Software Lab at the Lapland University of Applied Sciences
2//
3// This work is licensed under the terms of the MIT license.
4// For a copy, see <https://opensource.org/licenses/MIT>.
5
8
9#include "Engine/World.h"
10
12
13AInstanceSegmentationCamera::AInstanceSegmentationCamera(const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer)
14{
15 // Use USceneCaptureComponent2D ReadPixels method to get pixels instead of FrameGrabber API.
16 // Otherwise ID's of instance segmentation are not correct
17 // due to sRGB conversion done by FrameGrabber.
18 UseParallelLateTick = false;
19 UseReadPixels = true;
20 PrimaryActorTick.bCanEverTick = false;
21}
22
23void AInstanceSegmentationCamera::Init(FCameraBaseParameters parameters, bool SimulateSensor)
24{
25 // Defined in Camera.h
26 CameraName = "InstanceSegmentationCamera ";
27 FilePrefix = "Data/InstanceSegmentationCamera_";
28
29 AddPostProcessingMaterial("/Game/Agrarsense/Materials/PostProcessingMaterials/M_InstanceSegmentation.M_InstanceSegmentation");
30 Super::Init(parameters, SimulateSensor);
31
32 SetShadowRendering(false);
34 SetTemporalAA(false);
35
36#ifdef InstanceSegmentationPass_EXISTS
37 // If user is using AGRARSENSE Unreal Engine fork, we can utilize this sensor
38 UWorld* World = GetWorld();
39 if (GEngine && World)
40 {
41 GEngine->Exec(World, TEXT("r.EnableSegmentationRendering 1"));
42 }
44#else
45 // else log and destroy this Actor as the user cannot use this sensor anyway.
46 SimulatorLog::Log("InstanceSegmentationCamera.cpp: This sensor is only supported with our AGRARSENSE fork of the engine.");
47 Destroy();
48#endif
49}
50
51void AInstanceSegmentationCamera::EndPlay(const EEndPlayReason::Type EndPlayReason)
52{
53 Super::EndPlay(EndPlayReason);
54
55#ifdef InstanceSegmentationPass_EXISTS
58 {
59 UWorld* World = GetWorld();
60 if (GEngine && World)
61 {
62 GEngine->Exec(World, TEXT("r.EnableSegmentationRendering 0"));
63 }
64 }
65#endif
66}
static int32 InstanceSegmentationCameraCount
bool UseParallelLateTick
Definition: Camera.h:235
void AddPostProcessingMaterial(const FString &Path, float Weight=1.0f)
Definition: Camera.cpp:61
bool UseReadPixels
Definition: Camera.h:311
FString FilePrefix
Definition: Camera.h:286
void SetShadowRendering(bool RenderShadows)
Definition: Camera.cpp:929
void SetTemporalAA(bool SetTemporal)
Definition: Camera.cpp:940
FString CameraName
Definition: Camera.h:284
void DisableShowFlags()
Definition: Camera.cpp:969
void Init(FCameraBaseParameters parameters, bool SimulateSensor=true) override
virtual void EndPlay(const EEndPlayReason::Type EndPlayReason) final override
AInstanceSegmentationCamera(const FObjectInitializer &ObjectInitializer)
static void Log(const FString &Message, bool LogToTextFile=true, bool LogToROS=true)