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;
61 ACamera(
const FObjectInitializer& ObjectInitializer);
82 UFUNCTION(BlueprintCallable)
89 UFUNCTION(BlueprintCallable, BlueprintPure)
92 return CameraParameters;
100 void AddPostProcessingMaterial(
const FString& Path,
float Weight = 1.0f);
106 void RemovePostProcessingMaterial(UMaterial* Material);
112 UFUNCTION(BlueprintCallable)
113 USceneCaptureComponent2D* GetCaptureComponent2D()
const
115 return CaptureComponent2D;
122 UFUNCTION(BlueprintCallable)
123 UTextureRenderTarget2D* GetCaptureRenderTarget2D()
const
125 return CaptureRenderTarget;
132 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category =
"FrameGrabber")
133 TEnumAsByte<ETextureRenderTargetFormat> TextureFormat = ETextureRenderTargetFormat::RTF_RGBA8;
139 UPROPERTY(BlueprintAssignable)
140 FCameraDelegate_OnWindowClosed OnCameraWindowClosed;
146 UPROPERTY(BlueprintAssignable)
147 FCameraDelegate_OnWindowResized OnCameraWindowResized;
152 UFUNCTION(BlueprintCallable)
153 void AddWidgetToWindow(UWidget* WidgetToAdd);
158 UFUNCTION(BlueprintCallable)
159 void RemoveWidgetFromWindow(UWidget* WidgetToRemove);
164 UFUNCTION(BlueprintCallable)
165 void SetShadowRendering(
bool RenderShadows);
170 UFUNCTION(BlueprintCallable)
171 void SetTemporalAA(
bool SetTemporal);
176 UFUNCTION(BlueprintCallable)
177 void ResizeCamera(
int Width = 1280,
int Height = 720);
182 UFUNCTION(BlueprintCallable)
183 void SaveCurrentFrameToDisk()
185 if (!CameraParameters.SaveImageToDisk)
187 SaveCurrentFrameToDiskRequested =
true;
191 UFUNCTION(BlueprintCallable)
192 int GetCameraWidth()
const
197 UFUNCTION(BlueprintCallable)
198 int GetCameraHeight()
const
208 return StructToString(CameraParameters);
213 virtual void BeginPlay()
override;
215 virtual void EndPlay(
const EEndPlayReason::Type EndPlayReason)
override;
220 bool UseParallelLateTick =
true;
223 virtual void PreActorTick(UWorld* World, ELevelTick TickType,
float DeltaSeconds);
226 virtual void EndOfFrame(UWorld* World, ELevelTick TickType,
float DeltaSeconds);
227 virtual void EndOfFrameParellel(
float DeltaTime);
232 virtual void AddProcessingToFrameBuffer(TArray<FColor>& buffer);
240 virtual void SendImageDataToROS(
const TArray<FColor>& FrameBuffer, int32 Width, int32 Height);
243 void HidePrimitiveComponent(UPrimitiveComponent* PrimitiveComponent);
251 void SaveImageToDisk(const TArray<FColor> FrameBuffer, int32 Width, int32 Height);
253 void SaveCameraMetaDataToDisk(const FString& ImageName);
255 void CreateLogFile() override;
262 FString CameraName = "Camera ";
264 FString FilePrefix = "Data/Camera_";
267 UTextureRenderTarget2D* CaptureRenderTarget =
nullptr;
269 UPROPERTY(VisibleAnywhere)
270 USceneCaptureComponent2D* CaptureComponent2D =
nullptr;
276 UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "FrameGrabber")
277 UTexture2D* CaptureFrameTexture;
283 TWeakObjectPtr<UMaterialInstanceDynamic> IceMaterialInstance;
285 TWeakObjectPtr<UMaterial> PhysicLensDistortion;
292 void StartFrameGrabber();
297 void ReleaseFrameGrabber();
302 void FrameGrabberCapture();
308 void OnWindowClosed(const TSharedRef<SWindow>& Window);
313 TSharedPtr<FFrameGrabber>FrameGrabber;
323 bool ShouldSimulate(const
float DeltaSeconds);
329 UPROPERTY(VisibleAnywhere, Category = "Sensor")
335 AGeoReferencingSystem* GeoReferencingSystem =
nullptr;
337 bool ParametersChanged = false;
339 FOnWindowClosed OnWindowClosedDelegate;
341 TSharedPtr<ROSMessages::sensor_msgs::Image> ImageMsg;
343 int ImageWidth = 1280;
344 int ImageHeight = 720;
346 bool SaveCurrentFrameToDiskRequested = false;
348 bool ShouldSimulateCamera = true;
350 float CameraFrameRate = 0.0f;
351 float FrameRateTimer = 0.0f;
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