CARLA
Loading...
Searching...
No Matches
OpticalFlowCamera.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 "HAL/IConsoleManager.h"
13#include <util/ue-header-guard-end.h>
14
16
21
22AOpticalFlowCamera::AOpticalFlowCamera(const FObjectInitializer &ObjectInitializer)
23 : Super(ObjectInitializer)
24{
27 TEXT("Material'/Carla/PostProcessingMaterials/PhysicLensDistortion.PhysicLensDistortion'"));
29 TEXT("Material'/Carla/PostProcessingMaterials/VelocityMaterial.VelocityMaterial'"));
30}
31
32void AOpticalFlowCamera::PostPhysTick(UWorld *World, ELevelTick TickType, float DeltaSeconds)
33{
34 TRACE_CPUPROFILER_EVENT_SCOPE(AOpticalFlowCamera::PostPhysTick);
35 Super::PostPhysTick(World, TickType, DeltaSeconds);
36
38 {
39 return;
40 }
41
42 const auto CaptureContext = MakeCaptureContext(*this);
44 *this,
45 [this, CaptureContext](
46 const void* MappedPtr,
47 size_t RowPitch,
48 size_t BufferHeight,
49 EPixelFormat Format,
50 FIntPoint Extent)
51 {
52 check(sizeof(FVector2f) == sizeof(float) * 2);
53 check(RowPitch >= Extent.X);
54 check(BufferHeight >= Extent.Y);
55 // UE_LOG(LogCarla, Log, TEXT("Format=%u"), (unsigned)Format);
56 TArray<FVector2f> ImageData;
57 ImageData.Reserve(Extent.X * Extent.Y);
58 auto BasePtr = reinterpret_cast<const FFloat16Color*>(MappedPtr);
59 for (uint32 i = 0; i != Extent.Y; ++i)
60 {
61 auto Ptr = BasePtr;
62 for (uint32 j = 0; j != Extent.X; ++j)
63 {
64 FVector2f Out(
65 Ptr->R.GetFloat(),
66 Ptr->G.GetFloat());
67 Out -= FVector2f(0.5F, 0.5F);
68 Out *= 4.0F;
69 ImageData.Add(Out);
70 ++Ptr;
71 }
72 BasePtr += RowPitch;
73 }
75 *this,
76 TArrayView<FVector2f>(ImageData),
77 CaptureContext);
78 return true;
79 });
80}
static FActorDefinition GetSensorDefinition()
AOpticalFlowCamera(const FObjectInitializer &ObjectInitializer)
void PostPhysTick(UWorld *World, ELevelTick TickType, float DeltaSeconds) override
void Enable16BitFormat(bool Enable=false)
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 ReadSensorImageDataAsync(AShaderBasedSensor &Sensor, ReadImageDataAsyncCallback &&Callback)
A definition of a Carla Actor with all the variation and attributes.