CARLA
Toggle main menu visibility
Loading...
Searching...
No Matches
Unreal
CarlaUnreal
Plugins
Carla
Source
Carla
Sensor
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
7
#include "
Carla/Sensor/OpticalFlowCamera.h
"
8
#include "
Carla.h
"
9
#include "
Carla/Actor/ActorBlueprintFunctionLibrary.h
"
10
11
#include <util/ue-header-guard-begin.h>
12
#include "HAL/IConsoleManager.h"
13
#include <util/ue-header-guard-end.h>
14
15
#include "
Carla/Sensor/PixelReader.h
"
16
17
FActorDefinition
AOpticalFlowCamera::GetSensorDefinition
()
18
{
19
return
UActorBlueprintFunctionLibrary::MakeCameraDefinition
(TEXT(
"optical_flow"
));
20
}
21
22
AOpticalFlowCamera::AOpticalFlowCamera
(
const
FObjectInitializer &ObjectInitializer)
23
: Super(ObjectInitializer)
24
{
25
Enable16BitFormat
(
true
);
26
AddPostProcessingMaterial
(
27
TEXT(
"Material'/Carla/PostProcessingMaterials/PhysicLensDistortion.PhysicLensDistortion'"
));
28
AddPostProcessingMaterial
(
29
TEXT(
"Material'/Carla/PostProcessingMaterials/VelocityMaterial.VelocityMaterial'"
));
30
}
31
32
void
AOpticalFlowCamera::PostPhysTick
(UWorld *World, ELevelTick TickType,
float
DeltaSeconds)
33
{
34
TRACE_CPUPROFILER_EVENT_SCOPE(
AOpticalFlowCamera::PostPhysTick
);
35
Super::PostPhysTick(World, TickType, DeltaSeconds);
36
37
if
(!
AreClientsListening
())
38
{
39
return
;
40
}
41
42
const
auto
CaptureContext =
MakeCaptureContext
(*
this
);
43
ImageUtil::ReadSensorImageDataAsync
(
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
}
74
SendDataToClient
(
75
*
this
,
76
TArrayView<FVector2f>(ImageData),
77
CaptureContext);
78
return
true
;
79
});
80
}
ActorBlueprintFunctionLibrary.h
Carla.h
OpticalFlowCamera.h
PixelReader.h
AOpticalFlowCamera::GetSensorDefinition
static FActorDefinition GetSensorDefinition()
Definition
OpticalFlowCamera.cpp:17
AOpticalFlowCamera::AOpticalFlowCamera
AOpticalFlowCamera(const FObjectInitializer &ObjectInitializer)
Definition
OpticalFlowCamera.cpp:22
AOpticalFlowCamera::PostPhysTick
void PostPhysTick(UWorld *World, ELevelTick TickType, float DeltaSeconds) override
Definition
OpticalFlowCamera.cpp:32
ASceneCaptureSensor::Enable16BitFormat
void Enable16BitFormat(bool Enable=false)
Definition
SceneCaptureSensor.h:233
ASensor::SendDataToClient
static void SendDataToClient(SensorType &&Sensor, TArrayView< ElementType > SensorData, const FSensorCaptureContext &CaptureContext)
Definition
Unreal/CarlaUnreal/Plugins/Carla/Source/Carla/Sensor/Sensor.h:233
ASensor::MakeCaptureContext
static FSensorCaptureContext MakeCaptureContext(const ASensor &Sensor)
Call on the game thread right after CaptureScene().
Definition
Unreal/CarlaUnreal/Plugins/Carla/Source/Carla/Sensor/Sensor.h:197
ASensor::AreClientsListening
bool AreClientsListening()
Definition
Unreal/CarlaUnreal/Plugins/Carla/Source/Carla/Sensor/Sensor.h:124
AShaderBasedSensor::AddPostProcessingMaterial
bool AddPostProcessingMaterial(const FString &Path)
Load the UMaterialInstanceDynamic at the given Path and append it to the list of shaders with Weight.
Definition
ShaderBasedSensor.cpp:23
UActorBlueprintFunctionLibrary::MakeCameraDefinition
static FActorDefinition MakeCameraDefinition(const FString &Id, bool bEnableModifyingPostProcessEffects=false)
Definition
ActorBlueprintFunctionLibrary.cpp:373
ImageUtil::ReadSensorImageDataAsync
bool ReadSensorImageDataAsync(AShaderBasedSensor &Sensor, ReadImageDataAsyncCallback &&Callback)
Definition
ImageUtil.cpp:473
FActorDefinition
A definition of a Carla Actor with all the variation and attributes.
Definition
Unreal/CarlaUnreal/Plugins/Carla/Source/Carla/Actor/ActorDefinition.h:20
Generated by
1.18.0