8#include "CoreMinimal.h"
11#include "Engine/TextureRenderTarget2D.h"
12#include "Kismet/KismetSystemLibrary.h"
13#include "Delegates/IDelegateInstance.h"
14#include "Materials/MaterialInstanceDynamic.h"
15#include "Components/SceneCaptureComponent2D.h"
16#include "Engine/Texture2D.h"
17#include "FrameGrabber.h"
18#include "Materials/Material.h"
24#include "ROSIntegration/Public/sensor_msgs/Image.h"
26#include "Camera.generated.h"
28class AGeoReferencingSystem;
62 ACamera(
const FObjectInitializer& ObjectInitializer);
83 UFUNCTION(BlueprintCallable)
90 UFUNCTION(BlueprintCallable, BlueprintPure)
93 return CameraParameters;
101 void AddPostProcessingMaterial(
const FString& Path,
float Weight = 1.0f);
107 void RemovePostProcessingMaterial(UMaterial* Material);
113 UFUNCTION(BlueprintCallable)
114 USceneCaptureComponent2D* GetCaptureComponent2D()
const
116 return CaptureComponent2D;
123 UFUNCTION(BlueprintCallable)
124 UTextureRenderTarget2D* GetCaptureRenderTarget2D()
const
126 return CaptureRenderTarget;
133 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category =
"FrameGrabber")
134 TEnumAsByte<ETextureRenderTargetFormat> TextureFormat = ETextureRenderTargetFormat::RTF_RGBA8;
140 UPROPERTY(BlueprintAssignable)
141 FCameraDelegate_OnWindowClosed OnCameraWindowClosed;
147 UPROPERTY(BlueprintAssignable)
148 FCameraDelegate_OnWindowResized OnCameraWindowResized;
153 UFUNCTION(BlueprintCallable)
154 void AddWidgetToWindow(UWidget* WidgetToAdd);
159 UFUNCTION(BlueprintCallable)
160 void RemoveWidgetFromWindow(UWidget* WidgetToRemove);
165 UFUNCTION(BlueprintCallable)
166 void SetShadowRendering(
bool RenderShadows);
171 void DisableShowFlags();
176 UFUNCTION(BlueprintCallable)
177 void SetTemporalAA(
bool SetTemporal);
182 UFUNCTION(BlueprintCallable)
183 void ResizeCamera(int32 Width = 1280, int32 Height = 720);
185 UFUNCTION(BlueprintCallable)
186 void AddHiddenActor(AActor* Actor);
191 UFUNCTION(BlueprintCallable)
192 void SaveCurrentFrameToDisk()
194 if (!CameraParameters.SaveImageToDisk)
196 SaveCurrentFrameToDiskRequested =
true;
200 UFUNCTION(BlueprintCallable)
201 int32 GetCameraWidth()
const
206 UFUNCTION(BlueprintCallable)
207 int32 GetCameraHeight()
const
212 UFUNCTION(BlueprintCallable)
213 void SetUseGimbal(
bool UseGimbal)
215 AllowGimbal = UseGimbal;
223 return StructToString(CameraParameters);
230 virtual void EndPlay(
const EEndPlayReason::Type EndPlayReason)
override;
235 bool UseParallelLateTick =
true;
238 void PreActorTick(UWorld*
World, ELevelTick TickType,
float DeltaSeconds);
240 void UpdateCameraStabilization();
243 void EndOfFrame(UWorld*
World, ELevelTick TickType,
float DeltaSeconds);
244 void PixelReadEndOfFrame(UWorld*
World, ELevelTick TickType,
float DeltaSeconds);
247 void EndOfFrameParellel(
float DeltaTime);
252 virtual void AddProcessingToFrameBuffer(TArray<FColor>& buffer);
254 void ApplyGammaCorrectionLUT(TArray<FColor>& Buffer);
262 void SendImageDataToROS(
const TArray<FColor>& FrameBuffer, int32 Width, int32 Height);
265 void HidePrimitiveComponent(UPrimitiveComponent* PrimitiveComponent);
273 void SaveImageToDisk(const TArray<FColor> FrameBuffer, int32 Width, int32 Height);
275 void SaveCameraMetaDataToDisk(const FString& ImageName);
277 void CreateLogFile() override;
284 FString CameraName = "Camera ";
286 FString FilePrefix = "Data/Camera_";
289 UTextureRenderTarget2D* CaptureRenderTarget =
nullptr;
291 UPROPERTY(VisibleAnywhere)
292 USceneCaptureComponent2D* CaptureComponent2D =
nullptr;
298 UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "FrameGrabber")
299 UTexture2D* CaptureFrameTexture;
305 TWeakObjectPtr<UMaterialInstanceDynamic> IceMaterialInstance;
307 TWeakObjectPtr<UMaterial> PhysicLensDistortion;
309 TSharedPtr<ROSMessages::sensor_msgs::Image> ImageMsg;
311 bool UseReadPixels = false;
315 FRotator SensorSetRotation;
316 bool AllowGimbal = true;
323 void StartFrameGrabber();
328 void ReleaseFrameGrabber();
333 void FrameGrabberCapture();
338 void ReadPixelsCapture();
344 void OnWindowClosed(const TSharedRef<SWindow>& Window);
349 TSharedPtr<FFrameGrabber>FrameGrabber;
359 bool ShouldSimulate(const
float DeltaSeconds);
364 UPROPERTY(VisibleAnywhere, Category = "Sensor")
374 AGeoReferencingSystem* GeoReferencingSystem =
nullptr;
376 bool ParametersChanged = false;
378 FOnWindowClosed OnWindowClosedDelegate;
380 int32 ImageWidth = 1280;
381 int32 ImageHeight = 720;
383 bool SaveCurrentFrameToDiskRequested = false;
385 bool ShouldSimulateCamera = true;
387 float CameraFrameRate = 0.0f;
388 float FrameRateTimer = 0.0f;
390 int32 ImageNumber = 0;
392 uint8* BGR8Buffer =
nullptr;
394 int32 CurrentBufferSize = 0;
DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FCameraDelegate_OnWindowResized, ACamera *, Camera, FCameraBaseParameters, Params)
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FCameraDelegate_OnWindowClosed, ACamera *, Camera)
virtual ESensorTypes GetSensorType() const override
virtual FString GetParametersAsString() const override
FDelegateHandle OnPostTickDelegate
FDelegateHandle OnPreTickDelegate
virtual void BeginPlay() override
virtual void EndPlay(const EEndPlayReason::Type EndPlayReason) override