CARLA
OpticalFlowCamera.cpp
Go to the documentation of this file.
1 #include "Carla.h"
3 #include "HAL/IConsoleManager.h"
4 
6 
8 
10 {
11  return UActorBlueprintFunctionLibrary::MakeCameraDefinition(TEXT("optical_flow"));
12 }
13 
14 AOpticalFlowCamera::AOpticalFlowCamera(const FObjectInitializer &ObjectInitializer)
15  : Super(ObjectInitializer)
16 {
17  Enable16BitFormat(true);
19  TEXT("Material'/Carla/PostProcessingMaterials/PhysicLensDistortion.PhysicLensDistortion'"));
21  TEXT("Material'/Carla/PostProcessingMaterials/VelocityMaterial.VelocityMaterial'"));
22 }
23 
24 void AOpticalFlowCamera::PostPhysTick(UWorld *World, ELevelTick TickType, float DeltaSeconds)
25 {
26  auto CVarForceOutputsVelocity = IConsoleManager::Get().FindConsoleVariable(TEXT("r.BasePassForceOutputsVelocity"));
27  int32 OldValue = CVarForceOutputsVelocity->GetInt();
28  CVarForceOutputsVelocity->Set(1);
29 
30  std::function<TArray<float>(void *, uint32)> Conversor = [](void *Data, uint32 Size)
31  {
32  TArray<float> IntermediateBuffer;
33  int32 Count = Size / sizeof(FFloat16Color);
34  DEBUG_ASSERT(Count * sizeof(FFloat16Color) == Size);
35  FFloat16Color *Buf = reinterpret_cast<FFloat16Color *>(Data);
36  IntermediateBuffer.Reserve(Count * 2);
37  for (int i=0; i<Count; ++i)
38  {
39  float x = (Buf->R.GetFloat() - 0.5f) * 4.f;
40  float y = (Buf->G.GetFloat() - 0.5f) * 4.f;
41  IntermediateBuffer.Add(x);
42  IntermediateBuffer.Add(y);
43  ++Buf;
44  }
45  return IntermediateBuffer;
46  };
47  FPixelReader::SendPixelsInRenderThread<AOpticalFlowCamera, float>(*this, true, Conversor);
48 
49  CVarForceOutputsVelocity->Set(OldValue);
50 }
void PostPhysTick(UWorld *World, ELevelTick TickType, float DeltaSeconds) override
AOpticalFlowCamera(const FObjectInitializer &ObjectInitializer)
bool AddPostProcessingMaterial(const FString &Path)
Load the UMaterialInstanceDynamic at the given Path and append it to the list of shaders with Weight...
A definition of a Carla Actor with all the variation and attributes.
static T Get(carla::rpc::Response< T > &response)
#define DEBUG_ASSERT(predicate)
Definition: Debug.h:66
static FActorDefinition GetSensorDefinition()
static FActorDefinition MakeCameraDefinition(const FString &Id, bool bEnableModifyingPostProcessEffects=false)
void Enable16BitFormat(bool Enable=false)