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 UFUNCTION(BlueprintCallable)
172 void SetTemporalAA(
bool SetTemporal);
177 UFUNCTION(BlueprintCallable)
178 void ResizeCamera(
int Width = 1280,
int Height = 720);
183 UFUNCTION(BlueprintCallable)
184 void SaveCurrentFrameToDisk()
186 if (!CameraParameters.SaveImageToDisk)
188 SaveCurrentFrameToDiskRequested =
true;
192 UFUNCTION(BlueprintCallable)
193 int GetCameraWidth()
const
198 UFUNCTION(BlueprintCallable)
199 int GetCameraHeight()
const
204 UFUNCTION(BlueprintCallable)
205 void SetUseGimbal(
bool UseGimbal)
207 AllowGimbal = UseGimbal;
215 return StructToString(CameraParameters);
222 virtual void EndPlay(
const EEndPlayReason::Type EndPlayReason)
override;
227 bool UseParallelLateTick =
true;
230 virtual void PreActorTick(UWorld*
World, ELevelTick TickType,
float DeltaSeconds);
233 virtual void EndOfFrame(UWorld*
World, ELevelTick TickType,
float DeltaSeconds);
234 virtual void EndOfFrameParellel(
float DeltaTime);
239 virtual void AddProcessingToFrameBuffer(TArray<FColor>& buffer);
247 virtual void SendImageDataToROS(
const TArray<FColor>& FrameBuffer, int32 Width, int32 Height);
250 void HidePrimitiveComponent(UPrimitiveComponent* PrimitiveComponent);
258 void SaveImageToDisk(const TArray<FColor> FrameBuffer, int32 Width, int32 Height);
260 void SaveCameraMetaDataToDisk(const FString& ImageName);
262 void CreateLogFile() override;
269 FString CameraName = "Camera ";
271 FString FilePrefix = "Data/Camera_";
274 UTextureRenderTarget2D* CaptureRenderTarget =
nullptr;
276 UPROPERTY(VisibleAnywhere)
277 USceneCaptureComponent2D* CaptureComponent2D =
nullptr;
283 UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "FrameGrabber")
284 UTexture2D* CaptureFrameTexture;
290 TWeakObjectPtr<UMaterialInstanceDynamic> IceMaterialInstance;
292 TWeakObjectPtr<UMaterial> PhysicLensDistortion;
296 FRotator SensorSetRotation;
297 bool AllowGimbal = true;
304 void StartFrameGrabber();
309 void ReleaseFrameGrabber();
314 void FrameGrabberCapture();
320 void OnWindowClosed(const TSharedRef<SWindow>& Window);
325 TSharedPtr<FFrameGrabber>FrameGrabber;
335 bool ShouldSimulate(const
float DeltaSeconds);
340 UPROPERTY(VisibleAnywhere, Category = "Sensor")
350 AGeoReferencingSystem* GeoReferencingSystem =
nullptr;
352 bool ParametersChanged = false;
354 FOnWindowClosed OnWindowClosedDelegate;
356 TSharedPtr<ROSMessages::sensor_msgs::Image> ImageMsg;
358 int ImageWidth = 1280;
359 int ImageHeight = 720;
361 bool SaveCurrentFrameToDiskRequested = false;
363 bool ShouldSimulateCamera = true;
365 float CameraFrameRate = 0.0f;
366 float FrameRateTimer = 0.0f;
370 uint8* BGR8Buffer =
nullptr;
372 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