Agrarsense
Public Member Functions | Private Member Functions | Private Attributes | Friends | List of all members
ADepthCamera Class Reference

#include <DepthCamera.h>

Inheritance diagram for ADepthCamera:
Inheritance graph
[legend]
Collaboration diagram for ADepthCamera:
Collaboration graph
[legend]

Public Member Functions

 ADepthCamera (const FObjectInitializer &ObjectInitializer)
 
void ChangeDepthCameraParameters (FDepthCameraParameters Parameters)
 
FDepthCameraParameters GetDepthCameraParameters ()
 
virtual ESensorTypes GetSensorType () const override
 
virtual FString GetParametersAsString () const override
 
- Public Member Functions inherited from ACamera
 ACamera (const FObjectInitializer &ObjectInitializer)
 
virtual void Init (FCameraBaseParameters parameters, bool SimulateSensor=true)
 
virtual ESensorTypes GetSensorType () const override
 
void ChangeCameraParameters (FCameraBaseParameters newParameters)
 
FCameraBaseParameters GetCameraParameters ()
 
void AddPostProcessingMaterial (const FString &Path, float Weight=1.0f)
 
void RemovePostProcessingMaterial (UMaterial *Material)
 
USceneCaptureComponent2D * GetCaptureComponent2D () const
 
UTextureRenderTarget2D * GetCaptureRenderTarget2D () const
 
void AddWidgetToWindow (UWidget *WidgetToAdd)
 
void RemoveWidgetFromWindow (UWidget *WidgetToRemove)
 
void SetShadowRendering (bool RenderShadows)
 
void SetTemporalAA (bool SetTemporal)
 
void ResizeCamera (int Width=1280, int Height=720)
 
void SaveCurrentFrameToDisk ()
 
int GetCameraWidth () const
 
int GetCameraHeight () const
 
virtual FString GetParametersAsString () const override
 
- Public Member Functions inherited from ASensor
 ASensor (const FObjectInitializer &ObjectInitializer)
 
FString ExportToJsonFile (const FString &FileName)
 
virtual ESensorTypes GetSensorType () const
 
FString GetSensorIdentifier () const
 
void SetSensorIdentifier (const FString newIdentifier)
 
FString GetSensorName () const
 
virtual FString GetParametersAsString () const
 
void SetSensorName (const FString newName)
 
virtual FString GetTopicName ()
 
UTopic * GetROSTopic () const
 
void SetSimulateSensor (bool SimulateSensor)
 
bool CanSimulateSensor () const
 
ASensorModelGetSensorModel () const
 
void SetSensorModel (ASensorModel *NewSensorModel)
 
bool IsROSConnected () const
 
UROSIntegrationGameInstance * GetROSGameInstance () const
 
virtual FString GetActorID_Implementation () const override
 
virtual FString GetActorName_Implementation () const override
 
virtual FString GetActorInformation_Implementation () const override
 
virtual void SetActorName_Implementation (const FString &NewActorName) override
 
virtual void SetActorIDAndName_Implementation (const FString &NewActorName, const FString &NewID) override
 
- Public Member Functions inherited from IActorInformation
FString GetActorID () const
 
FString GetActorName () const
 
FString GetActorInformation () const
 
void SetActorName (const FString &NewActorName)
 
void SetActorIDAndName (const FString &NewActorName, const FString &NewID)
 

Private Member Functions

void DepthInit (FDepthCameraParameters Parameters, bool SimulateSensor=true)
 
void Init (FCameraBaseParameters parameters, bool SimulateSensor=true) override
 
virtual void EndPlay (const EEndPlayReason::Type EndPlayReason) override
 
void SetupDepthMaterial (const bool UseGrayscale)
 

Private Attributes

FDepthCameraParameters DepthCameraParameters
 
TWeakObjectPtr< UMaterial > DepthEffectMaterialGrayscale
 
TWeakObjectPtr< UMaterial > DepthEffectMaterial
 

Friends

class USensorFactory
 

Additional Inherited Members

- Static Public Member Functions inherited from ASensor
static void HideComponentForAllCameras (UPrimitiveComponent *PrimitiveComponent)
 
static TMap< FString, FColor > GetSemanticColors ()
 
static TArray< TWeakObjectPtr< UPrimitiveComponent > > GetComponentsToHide ()
 
- Static Public Member Functions inherited from IActorInformation
static void SetAndValidateActorIDAndName (FString &ActorName, FString &ActorID, TWeakObjectPtr< AActor > Actor)
 
static bool DestroyActorByID (const FString &ID)
 
static AActor * GetActorByID (const FString &ID)
 
template<typename T >
static TArray< T * > GetActorsWithInterface ()
 
static void PrintAllIds ()
 
- Public Attributes inherited from ACamera
TEnumAsByte< ETextureRenderTargetFormat > TextureFormat = ETextureRenderTargetFormat::RTF_RGBA8
 
FCameraDelegate_OnWindowClosed OnCameraWindowClosed
 
FCameraDelegate_OnWindowResized OnCameraWindowResized
 
- Public Attributes inherited from ASensor
FSensorDestroy OnSensorDestroy
 
FString AttachedToComponent
 
FName AttachedToBone
 
- Protected Member Functions inherited from ACamera
virtual void BeginPlay () override
 
virtual void EndPlay (const EEndPlayReason::Type EndPlayReason) override
 
virtual void PreActorTick (UWorld *World, ELevelTick TickType, float DeltaSeconds)
 
virtual void EndOfFrame (UWorld *World, ELevelTick TickType, float DeltaSeconds)
 
virtual void EndOfFrameParellel (float DeltaTime)
 
virtual void AddProcessingToFrameBuffer (TArray< FColor > &buffer)
 
virtual void SendImageDataToROS (const TArray< FColor > &FrameBuffer, int32 Width, int32 Height)
 
void HidePrimitiveComponent (UPrimitiveComponent *PrimitiveComponent)
 
void SaveImageToDisk (const TArray< FColor > FrameBuffer, int32 Width, int32 Height)
 
void SaveCameraMetaDataToDisk (const FString &ImageName)
 
void CreateLogFile () override
 
- Protected Member Functions inherited from ASensor
virtual void BeginPlay () override
 
virtual void EndPlay (const EEndPlayReason::Type EndPlayReason) override
 
virtual void CreateROSTopic ()
 
virtual void DestroyROSTopic ()
 
virtual void CreateDataSavePath ()
 
bool IsLogFileCreated ()
 
virtual void CreateLogFile ()
 
void WriteToLogFile (const FString &Message)
 
- Static Protected Member Functions inherited from ASensor
template<typename InStructType >
static FString StructToString (const InStructType &InStruct)
 
- Protected Attributes inherited from ACamera
bool UseParallelLateTick = true
 
FDelegateHandle OnPreTickDelegate
 
FDelegateHandle OnPostTickDelegate
 
FString CameraName = "Camera "
 
FString FilePrefix = "Data/Camera_"
 
UTextureRenderTarget2D * CaptureRenderTarget = nullptr
 
USceneCaptureComponent2D * CaptureComponent2D = nullptr
 
UTexture2D * CaptureFrameTexture
 
TSharedPtr< FUnrealWindowUnrealWindow
 
FTickEntry TickEntry
 
TWeakObjectPtr< UMaterialInstanceDynamic > IceMaterialInstance
 
TWeakObjectPtr< UMaterial > PhysicLensDistortion
 
- Protected Attributes inherited from ASensor
UTopic * ROSTopic = nullptr
 
bool SendDataToROS = true
 
ULogFileLogFile = nullptr
 
FString FileSavePath
 
UROSIntegrationGameInstance * ROSInstance = nullptr
 
- Static Protected Attributes inherited from ASensor
static FPrimitiveAdded OnPrimitiveAdded
 
static const FName NiagaraPointsInt = "User.PointCount"
 
static const FName NiagaraHitPoints = "User.HitPoints"
 
static const FName NiagaraHitColors = "User.HitColors"
 
static const FName NiagaraPointsFloat = "User.Test"
 

Detailed Description

Class for Depth Camera.

See also
ACamera

Definition at line 18 of file DepthCamera.h.

Constructor & Destructor Documentation

◆ ADepthCamera()

ADepthCamera::ADepthCamera ( const FObjectInitializer &  ObjectInitializer)

Definition at line 9 of file DepthCamera.cpp.

9 : Super(ObjectInitializer)
10{
11 // Ticked by Camera base class
12 PrimaryActorTick.bCanEverTick = false;
13}

Member Function Documentation

◆ ChangeDepthCameraParameters()

void ADepthCamera::ChangeDepthCameraParameters ( FDepthCameraParameters  Parameters)

Change the Depth camera parameters.

Parameters
Parameters- The new Depth camera parameters.

Definition at line 45 of file DepthCamera.cpp.

46{
47 DepthCameraParameters = Parameters;
50}
void ChangeCameraParameters(FCameraBaseParameters newParameters)
Definition: Camera.cpp:50
void SetupDepthMaterial(const bool UseGrayscale)
Definition: DepthCamera.cpp:52
FDepthCameraParameters DepthCameraParameters
Definition: DepthCamera.h:89
FCameraBaseParameters CameraParameters

References FDepthCameraParameters::CameraParameters, ACamera::ChangeCameraParameters(), FDepthCameraParameters::ConvertToGrayscale, DepthCameraParameters, and SetupDepthMaterial().

◆ DepthInit()

void ADepthCamera::DepthInit ( FDepthCameraParameters  Parameters,
bool  SimulateSensor = true 
)
private

Initializes a new Depth Camera sensor with specified Depth camera parameters.

Parameters
parametersA FDepthCameraParameters struct.
SimulateSensorA boolean flag to indicate whether the sensor should be simulated (default is true).

Definition at line 15 of file DepthCamera.cpp.

16{
17 DepthCameraParameters = Parameters;
19}
void Init(FCameraBaseParameters parameters, bool SimulateSensor=true) override
Definition: DepthCamera.cpp:21

References FDepthCameraParameters::CameraParameters, DepthCameraParameters, and Init().

Referenced by USensorFactory::SpawnDepthCamera().

◆ EndPlay()

void ADepthCamera::EndPlay ( const EEndPlayReason::Type  EndPlayReason)
overrideprivatevirtual

Called when the camera's play ends.

Parameters
EndPlayReason- The reason for the end of play.

Reimplemented from ACamera.

Definition at line 37 of file DepthCamera.cpp.

38{
39 Super::EndPlay(EndPlayReason);
40
42 DepthEffectMaterial.Reset();
43}
TWeakObjectPtr< UMaterial > DepthEffectMaterialGrayscale
Definition: DepthCamera.h:91
TWeakObjectPtr< UMaterial > DepthEffectMaterial
Definition: DepthCamera.h:93

References DepthEffectMaterial, and DepthEffectMaterialGrayscale.

◆ GetDepthCameraParameters()

FDepthCameraParameters ADepthCamera::GetDepthCameraParameters ( )
inline

Get the current Depth camera parameters.

Returns
FDepthCameraParameters struct.

Definition at line 38 of file DepthCamera.h.

39 {
41 }

Referenced by USimulatorJsonExporter::ExportSensorToJSON().

◆ GetParametersAsString()

virtual FString ADepthCamera::GetParametersAsString ( ) const
inlineoverridevirtual

Get this sensor parameters struct fields as one string.

Reimplemented from ACamera.

Definition at line 55 of file DepthCamera.h.

56 {
58 }
static FString StructToString(const InStructType &InStruct)
Definition: Sensor.h:305

◆ GetSensorType()

virtual ESensorTypes ADepthCamera::GetSensorType ( ) const
inlineoverridevirtual

Get type of the sensor

Returns
Sensor's type

Reimplemented from ACamera.

Definition at line 47 of file DepthCamera.h.

48 {
50 }

References DepthCamera.

◆ Init()

void ADepthCamera::Init ( FCameraBaseParameters  parameters,
bool  SimulateSensor = true 
)
overrideprivatevirtual

Initializes a new Depth Camera sensor with specified parameters, overriding the base class method.

Parameters
parametersA FCameraBaseParameters struct.
SimulateSensorA boolean flag to indicate whether the sensor should be simulated (default is true).

Reimplemented from ACamera.

Definition at line 21 of file DepthCamera.cpp.

22{
23 // Set directory and camera name, defined in Camera.h
24 CameraName = "DepthCamera ";
25 FilePrefix = "Data/DepthCamera_";
26
27 // Setup Depth material
29
30 // Call Camera base class Init
31 Super::Init(parameters, SimulateSensor);
32
33 // This camera doesn't need to render shadows
34 SetShadowRendering(false);
35}
FString FilePrefix
Definition: Camera.h:264
void SetShadowRendering(bool RenderShadows)
Definition: Camera.cpp:730
FString CameraName
Definition: Camera.h:262

References ACamera::CameraName, FDepthCameraParameters::ConvertToGrayscale, DepthCameraParameters, ACamera::FilePrefix, ACamera::SetShadowRendering(), and SetupDepthMaterial().

Referenced by DepthInit().

◆ SetupDepthMaterial()

void ADepthCamera::SetupDepthMaterial ( const bool  UseGrayscale)
private

Setup which post processing material to use.

Definition at line 52 of file DepthCamera.cpp.

53{
54 // Get SceneCaptureComponent2D from the base Camera class
55 USceneCaptureComponent2D* SceneCaptureComponent = GetCaptureComponent2D();
56
57 if (SceneCaptureComponent)
58 {
59 // Determine which post-processing material to apply based on whether grayscale is used
60 if (UseGrayscale)
61 {
62 // Load and apply the grayscale material if it hasn't been loaded already
63 if (!DepthEffectMaterialGrayscale.IsValid())
64 {
65 FString Path = "/Game/Agrarsense/Materials/PostProcessingMaterials/DepthEffectMaterialGrayscale.DepthEffectMaterialGrayscale";
66 DepthEffectMaterialGrayscale = Cast<UMaterial>(StaticLoadObject(UMaterial::StaticClass(), nullptr, *Path));
67 AddPostProcessingMaterial(Path, 1.0f);
68 }
69
70 // Remove the non-grayscale material if it's currently applied
71 if (DepthEffectMaterial.IsValid())
72 {
74 DepthEffectMaterial.Reset();
75 }
76 }
77 else
78 {
79 // Load and apply the non-grayscale material if it hasn't been loaded already
80 if (!DepthEffectMaterial.IsValid())
81 {
82 FString Path = "/Game/Agrarsense/Materials/PostProcessingMaterials/DepthEffectMaterial.DepthEffectMaterial";
83 DepthEffectMaterial = Cast<UMaterial>(StaticLoadObject(UMaterial::StaticClass(), nullptr, *Path));
84 AddPostProcessingMaterial(Path, 1.0f);
85 }
86
87 // Remove the grayscale material if it's currently applied
88 if (DepthEffectMaterialGrayscale.IsValid())
89 {
92 }
93 }
94 }
95}
void AddPostProcessingMaterial(const FString &Path, float Weight=1.0f)
Definition: Camera.cpp:55
void RemovePostProcessingMaterial(UMaterial *Material)
Definition: Camera.cpp:71
USceneCaptureComponent2D * GetCaptureComponent2D() const
Definition: Camera.h:113

References ACamera::AddPostProcessingMaterial(), DepthEffectMaterial, DepthEffectMaterialGrayscale, ACamera::GetCaptureComponent2D(), and ACamera::RemovePostProcessingMaterial().

Referenced by ChangeDepthCameraParameters(), and Init().

Friends And Related Function Documentation

◆ USensorFactory

friend class USensorFactory
friend

Definition at line 62 of file DepthCamera.h.

Member Data Documentation

◆ DepthCameraParameters

FDepthCameraParameters ADepthCamera::DepthCameraParameters
private

Definition at line 89 of file DepthCamera.h.

Referenced by ChangeDepthCameraParameters(), DepthInit(), and Init().

◆ DepthEffectMaterial

TWeakObjectPtr<UMaterial> ADepthCamera::DepthEffectMaterial
private

Definition at line 93 of file DepthCamera.h.

Referenced by EndPlay(), and SetupDepthMaterial().

◆ DepthEffectMaterialGrayscale

TWeakObjectPtr<UMaterial> ADepthCamera::DepthEffectMaterialGrayscale
private

Definition at line 91 of file DepthCamera.h.

Referenced by EndPlay(), and SetupDepthMaterial().


The documentation for this class was generated from the following files: