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(
int Width = 1280,
int Height = 720);
188 UFUNCTION(BlueprintCallable)
189 void SaveCurrentFrameToDisk()
191 if (!CameraParameters.SaveImageToDisk)
193 SaveCurrentFrameToDiskRequested =
true;
197 UFUNCTION(BlueprintCallable)
198 int GetCameraWidth()
const
203 UFUNCTION(BlueprintCallable)
204 int GetCameraHeight()
const
209 UFUNCTION(BlueprintCallable)
210 void SetUseGimbal(
bool UseGimbal)
212 AllowGimbal = UseGimbal;
220 return StructToString(CameraParameters);
227 virtual void EndPlay(
const EEndPlayReason::Type EndPlayReason)
override;
232 bool UseParallelLateTick =
true;
235 virtual void PreActorTick(UWorld*
World, ELevelTick TickType,
float DeltaSeconds);
238 virtual void EndOfFrame(UWorld*
World, ELevelTick TickType,
float DeltaSeconds);
239 virtual void EndOfFrameParellel(
float DeltaTime);
244 virtual void AddProcessingToFrameBuffer(TArray<FColor>& buffer);
252 virtual void SendImageDataToROS(
const TArray<FColor>& FrameBuffer, int32 Width, int32 Height);
255 void HidePrimitiveComponent(UPrimitiveComponent* PrimitiveComponent);
263 void SaveImageToDisk(const TArray<FColor> FrameBuffer, int32 Width, int32 Height);
265 void SaveCameraMetaDataToDisk(const FString& ImageName);
267 void CreateLogFile() override;
274 FString CameraName = "Camera ";
276 FString FilePrefix = "Data/Camera_";
279 UTextureRenderTarget2D* CaptureRenderTarget =
nullptr;
281 UPROPERTY(VisibleAnywhere)
282 USceneCaptureComponent2D* CaptureComponent2D =
nullptr;
288 UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "FrameGrabber")
289 UTexture2D* CaptureFrameTexture;
295 TWeakObjectPtr<UMaterialInstanceDynamic> IceMaterialInstance;
297 TWeakObjectPtr<UMaterial> PhysicLensDistortion;
301 FRotator SensorSetRotation;
302 bool AllowGimbal = true;
309 void StartFrameGrabber();
314 void ReleaseFrameGrabber();
319 void FrameGrabberCapture();
325 void OnWindowClosed(const TSharedRef<SWindow>& Window);
330 TSharedPtr<FFrameGrabber>FrameGrabber;
340 bool ShouldSimulate(const
float DeltaSeconds);
345 UPROPERTY(VisibleAnywhere, Category = "Sensor")
355 AGeoReferencingSystem* GeoReferencingSystem =
nullptr;
357 bool ParametersChanged = false;
359 FOnWindowClosed OnWindowClosedDelegate;
361 TSharedPtr<ROSMessages::sensor_msgs::Image> ImageMsg;
363 int32 ImageWidth = 1280;
364 int32 ImageHeight = 720;
366 bool SaveCurrentFrameToDiskRequested = false;
368 bool ShouldSimulateCamera = true;
370 float CameraFrameRate = 0.0f;
371 float FrameRateTimer = 0.0f;
373 int32 ImageNumber = 0;
375 uint8* BGR8Buffer =
nullptr;
377 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