17#include <util/ue-header-guard-begin.h>
19#include "Async/ParallelFor.h"
21#include <util/ue-header-guard-end.h>
29 const int32 Sum = 2989 * Color.R + 5870 * Color.G + 1140 * Color.B;
30 return static_cast<float>(Sum * 0.0001);
34 : Super(ObjectInitializer)
38 TEXT(
"Material'/Carla/PostProcessingMaterials/PhysicLensDistortion.PhysicLensDistortion'"));
40 RandomEngine = CreateDefaultSubobject<URandomEngine>(TEXT(
"RandomEngine"));
45 constexpr bool bEnableModifyingPostProcessEffects =
true;
49 Cp.
Id = TEXT(
"positive_threshold");
55 Cm.
Id = TEXT(
"negative_threshold");
61 Sigma_Cp.
Id = TEXT(
"sigma_positive_threshold");
67 Sigma_Cm.
Id = TEXT(
"sigma_negative_threshold");
73 Refractory_Period.
Id = TEXT(
"refractory_period_ns");
79 Use_Log.
Id = TEXT(
"use_log");
85 Log_EPS.
Id = TEXT(
"log_eps");
90 Definition.Variations.Append({ Cp, Cm, Sigma_Cp, Sigma_Cm, Refractory_Period, Use_Log, Log_EPS });
97 Super::Set(Description);
100 "positive_threshold",
105 "negative_threshold",
110 "sigma_positive_threshold",
115 "sigma_negative_threshold",
120 "refractory_period_ns",
138 Super::PostPhysTick(World, TickType, DeltaTime);
152 TArray<FColor> RawImage;
170 DataStream.SetFrameNumber(FrameIndex);
171 auto Buffer = DataStream.PopBufferFromPool();
178 #if defined(WITH_ROS2)
180 if (ROS2->IsEnabled())
182 TRACE_CPUPROFILER_EVENT_SCOPE_STR(
"ROS2 Send");
189 if (WidthOpt.has_value())
190 W = FCString::Atoi(*WidthOpt->Value);
192 if (HeightOpt.has_value())
193 H = FCString::Atoi(*HeightOpt->Value);
195 if (FovOpt.has_value())
196 Fov = FCString::Atof(*FovOpt->Value);
197 AActor* ParentActor = GetAttachParentActor();
200 FTransform LocalTransformRelativeToParent = GetActorTransform().GetRelativeTransform(ParentActor->GetActorTransform());
201 ROS2->ProcessDataFromDVS(DataStream.GetSensorType(), StreamId, LocalTransformRelativeToParent, BufView, W, H, Fov,
this);
205 ROS2->ProcessDataFromDVS(DataStream.GetSensorType(), StreamId, DataStream.GetSensorTransform(), BufView, W, H, Fov,
this);
210 if (events.size() > 0)
212 TRACE_CPUPROFILER_EVENT_SCOPE_STR(
"ADVSCamera Stream Send");
214 DataStream.Send(*
this, BufView);
221 if (image.Num() != (this->GetImageHeight() * this->GetImageWidth()))
228 const FColor *Src = image.GetData();
233 for (int32 i = Row * Width; i < (Row + 1) * Width; ++i)
243 if (image.Num() != (this->GetImageHeight() * this->GetImageWidth()))
250 const FColor *Src = image.GetData();
254 ParallelFor(this->
GetImageHeight(), [Src, Dst, Width, LogEps](int32 Row)
256 for (int32 i = Row * Width; i < (Row + 1) * Width; ++i)
269 if (this->
last_image.Num() != (this->GetImageHeight() * this->GetImageWidth()))
288 static constexpr float tolerance = 1e-6;
304 if (std::fabs (it - itdt) > tolerance)
306 const float pol = (itdt >= it) ? +1.0 : -1.0;
313 constexpr float minimum_contrast_threshold = 0.01;
314 C = std::max(minimum_contrast_threshold, C);
316 float curr_cross = prev_cross;
317 bool all_crossings =
false;
321 curr_cross += pol * C;
323 if ((pol > 0 && curr_cross > it && curr_cross <= itdt)
324 || (pol < 0 && curr_cross < it && curr_cross >= itdt))
326 const std::uint64_t edt = (curr_cross - it) * delta_t_ns / (itdt - it);
332 if (t >= last_stamp_at_xy)
334 const std::uint64_t dt = t - last_stamp_at_xy;
349 all_crossings =
true;
351 }
while (!all_crossings);
363 std::sort(events.begin(), events.end(), [](const ::carla::sensor::data::DVSEvent& it1, const ::carla::sensor::data::DVSEvent& it2){return it1.t < it2.t;});
static float FColorToGrayScaleFloat(FColor Color)
static bool IsValid(const ACarlaWheeledVehicle *Vehicle)
std::vector<::carla::sensor::data::DVSEvent > DVSEventArray
ADVSCamera(const FObjectInitializer &ObjectInitializer)
TArray< float > prev_image
dvs::Config config
DVS simulation configuration.
void Set(const FActorDescription &ActorDescription) override
TArray< double > last_event_timestamp
Image containing time of last event in seconds.
ADVSCamera::DVSEventArray Simulation(float DeltaTime)
static FActorDefinition GetSensorDefinition()
void ImageToLogGray(const TArray< FColor > &image)
TArray< float > last_image
Images containing last (current) and previous image.
void ImageToGray(const TArray< FColor > &image)
TArray< float > ref_values
Image containing the last reference value to trigger event.
virtual void PostPhysTick(UWorld *World, ELevelTick TickType, float DeltaTime) override
std::int64_t current_time
Current time in nanoseconds.
bool ReadPixels(TArray< FColor > &BitMap) const
Use for debugging purposes only.
TObjectPtr< UTextureRenderTarget2D > CaptureRenderTarget
Render target necessary for scene capture.
void EnablePostProcessingEffects(bool Enable=true)
uint32 GetImageHeight() const
uint32 GetImageWidth() const
void WaitForRenderThreadToFinish()
Blocks until the render thread has finished all it's tasks.
auto GetToken() const
Return the token that allows subscribing to this sensor's stream.
FAsyncDataStream GetDataStream(SensorType &&Self)
Return the FDataStream associated with this sensor.
std::optional< FActorAttribute > GetAttribute(const FString Name)
URandomEngine * RandomEngine
Random Engine used to provide noise for sensor output.
bool AreClientsListening()
const UCarlaEpisode & GetEpisode() const
bool AddPostProcessingMaterial(const FString &Path)
Load the UMaterialInstanceDynamic at the given Path and append it to the list of shaders with Weight.
static uint64_t GetFrameCounter()
static int32 RetrieveActorAttributeToInt(const FString &Id, const TMap< FString, FActorAttribute > &Attributes, int32 Default)
static FActorDefinition MakeCameraDefinition(const FString &Id, bool bEnableModifyingPostProcessEffects=false)
static float RetrieveActorAttributeToFloat(const FString &Id, const TMap< FString, FActorAttribute > &Attributes, float Default)
static bool RetrieveActorAttributeToBool(const FString &Id, const TMap< FString, FActorAttribute > &Attributes, bool Default)
float GetNormalDistribution(float Mean, float StandardDeviation)
static std::shared_ptr< BufferView > CreateFrom(Buffer &&buffer)
static std::shared_ptr< ROS2 > GetInstance()
static Buffer Serialize(Sensor &sensor, Args &&... args)
Serialize the arguments provided into a Buffer by calling to the serializer registered for the given ...
Serializes a stream endpoint.
const auto & get_stream_id() const
std::shared_ptr< BufferView > SharedBufferView
constexpr std::int64_t secToNanosec(double seconds)
constexpr double nanosecToSecTrunc(std::int64_t nanoseconds)
A definition of a Carla Actor with all the variation and attributes.
A description of a Carla Actor with all its variation.
TMap< FString, FActorAttribute > Variations
User selected variations of the actor.
Definition of an actor variation.
TArray< FString > RecommendedValues
bool bRestrictToRecommended
std::uint64_t refractory_period_ns