Agrarsense
Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes | List of all members
APhotoCapture Class Reference

#include <PhotoCapture.h>

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

Public Member Functions

 APhotoCapture (const FObjectInitializer &ObjectInitializer)
 
void SetupPhotoCapture (FCaptureData NewCaptureData)
 

Protected Member Functions

virtual void BeginPlay () override
 
virtual void Tick (float DeltaTime) override
 
virtual void EndPlay (const EEndPlayReason::Type EndPlayReason) override
 

Private Member Functions

void Capture ()
 
void UpdateCameraPositions (const FTransform &Transform)
 
void CaptureImages ()
 
void DestroyCameras ()
 

Private Attributes

FCaptureData CaptureData
 
int32 FrameCounter = 0
 

Detailed Description

Definition at line 41 of file PhotoCapture.h.

Constructor & Destructor Documentation

◆ APhotoCapture()

APhotoCapture::APhotoCapture ( const FObjectInitializer &  ObjectInitializer)

Definition at line 10 of file PhotoCapture.cpp.

10 : Super(ObjectInitializer)
11{
12 RootComponent = CreateDefaultSubobject<USceneComponent>(TEXT("SceneRoot"));
13 PrimaryActorTick.bCanEverTick = true;
14 PrimaryActorTick.bStartWithTickEnabled = false;
15 PrimaryActorTick.TickGroup = TG_PrePhysics;
16 SetActorTickEnabled(false);
17}

Member Function Documentation

◆ BeginPlay()

void APhotoCapture::BeginPlay ( )
overrideprotectedvirtual

Definition at line 54 of file PhotoCapture.cpp.

55{
56 Super::BeginPlay();
57}

◆ Capture()

void APhotoCapture::Capture ( )
private

Definition at line 73 of file PhotoCapture.cpp.

74{
75 // A bit convoluted logic due to its not guaranteed that we can move actor
76 // and save the camera image in the same frame.
77
79 {
83 {
84 FrameCounter = 0;
86 {
89 }
90 }
91 }
92
94 {
95 // Disable tick
96 SetActorTickEnabled(false);
97
98 // Destroy this Actor with delay so Camera sensors has time to save the last images
99 FTimerHandle Handle;
100 GetWorld()->GetTimerManager().SetTimer(Handle, FTimerDelegate::CreateLambda([this]
101 {
103 Destroy();
104 }), 1.0f, false);
105 }
106}
void DestroyCameras()
void CaptureImages()
void UpdateCameraPositions(const FTransform &Transform)
int32 FrameCounter
Definition: PhotoCapture.h:75
FCaptureData CaptureData
Definition: PhotoCapture.h:73
int32 FramesToKeepInSamePosition
Definition: PhotoCapture.h:30
TArray< FTransform > CapturePositions
Definition: PhotoCapture.h:24
int32 CurrentCaptureIndex
Definition: PhotoCapture.h:27

References CaptureData, CaptureImages(), FCaptureData::CapturePositions, FCaptureData::CurrentCaptureIndex, Destroy, DestroyCameras(), FrameCounter, FCaptureData::FramesToKeepInSamePosition, and UpdateCameraPositions().

Referenced by Tick().

◆ CaptureImages()

void APhotoCapture::CaptureImages ( )
private

Definition at line 120 of file PhotoCapture.cpp.

121{
122 for (int32 i = 0; i < CaptureData.Cameras.Num(); i++)
123 {
124 ACamera* CameraPtr = CaptureData.Cameras[i];
125 if (CameraPtr)
126 {
127 CameraPtr->SaveCurrentFrameToDisk();
128 }
129 }
130}
Definition: Camera.h:52
void SaveCurrentFrameToDisk()
Definition: Camera.h:183
TArray< ACamera * > Cameras
Definition: PhotoCapture.h:21

References FCaptureData::Cameras, CaptureData, and ACamera::SaveCurrentFrameToDisk().

Referenced by Capture().

◆ DestroyCameras()

void APhotoCapture::DestroyCameras ( )
private

Definition at line 132 of file PhotoCapture.cpp.

133{
134 for (int32 i = 0; i < CaptureData.Cameras.Num(); i++)
135 {
136 ACamera* CameraPtr = CaptureData.Cameras[i];
137 if (CameraPtr)
138 {
139 CameraPtr->Destroy();
140 }
141 }
142}

References FCaptureData::Cameras, and CaptureData.

Referenced by Capture(), and SetupPhotoCapture().

◆ EndPlay()

void APhotoCapture::EndPlay ( const EEndPlayReason::Type  EndPlayReason)
overrideprotectedvirtual

Definition at line 65 of file PhotoCapture.cpp.

66{
67 Super::EndPlay(EndPlayReason);
68
69 CaptureData.Cameras.Empty();
71}

References FCaptureData::Cameras, CaptureData, and FCaptureData::CapturePositions.

◆ SetupPhotoCapture()

void APhotoCapture::SetupPhotoCapture ( FCaptureData  NewCaptureData)

Definition at line 19 of file PhotoCapture.cpp.

20{
21 CaptureData = NewCaptureData;
22
23 if (CaptureData.CapturePositions.Num() != 0 && CaptureData.Cameras.Num() != 0)
24 {
25 for (int32 i = 0; i < CaptureData.Cameras.Num(); i++)
26 {
27 ACamera* CameraPtr = CaptureData.Cameras[i];
28 if (CameraPtr)
29 {
30 FCameraBaseParameters params = CameraPtr->GetCameraParameters();
31 params.SaveImageToDisk = false;
32 params.SendDataToROS = false;
33 CameraPtr->ChangeCameraParameters(params);
34 }
35 }
36
38
39 // Enable This Actor tick with delay
40 FTimerHandle Handle;
41 GetWorld()->GetTimerManager().SetTimer(Handle, FTimerDelegate::CreateLambda([this]
42 {
44 SetActorTickEnabled(true);
45 }), 0.1f, false);
46 }
47 else
48 {
50 Destroy();
51 }
52}
void ChangeCameraParameters(FCameraBaseParameters newParameters)
Definition: Camera.cpp:50
FCameraBaseParameters GetCameraParameters()
Definition: Camera.h:90

References FCaptureData::Cameras, CaptureData, FCaptureData::CapturePositions, ACamera::ChangeCameraParameters(), Destroy, DestroyCameras(), ACamera::GetCameraParameters(), FCameraBaseParameters::SaveImageToDisk, FCameraBaseParameters::SendDataToROS, and UpdateCameraPositions().

Referenced by USimulatorJsonParser::ParseDataCapture().

◆ Tick()

void APhotoCapture::Tick ( float  DeltaTime)
overrideprotectedvirtual

Definition at line 59 of file PhotoCapture.cpp.

60{
61 Super::Tick(DeltaTime);
62 Capture();
63}

References Capture().

◆ UpdateCameraPositions()

void APhotoCapture::UpdateCameraPositions ( const FTransform &  Transform)
private

Definition at line 108 of file PhotoCapture.cpp.

109{
110 for (int32 i = 0; i < CaptureData.Cameras.Num(); i++)
111 {
112 ACamera* CameraPtr = CaptureData.Cameras[i];
113 if (CameraPtr)
114 {
115 CameraPtr->SetActorTransform(Transform);
116 }
117 }
118}

References FCaptureData::Cameras, CaptureData, and Transform.

Referenced by Capture(), and SetupPhotoCapture().

Member Data Documentation

◆ CaptureData

FCaptureData APhotoCapture::CaptureData
private

◆ FrameCounter

int32 APhotoCapture::FrameCounter = 0
private

Definition at line 75 of file PhotoCapture.h.

Referenced by Capture().


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