Agrarsense
DataCapture.h
Go to the documentation of this file.
1// Copyright (c) 2024 FrostBit Software Lab at the Lapland University of Applied Sciences
2//
3// This work is licensed under the terms of the MIT license.
4// For a copy, see <https://opensource.org/licenses/MIT>.
5
6#pragma once
7
8#include "CoreMinimal.h"
9#include "GameFramework/Actor.h"
10
11#include "DataCapture.generated.h"
12
13class ASensor;
14class ACamera;
15class ALidar;
16
17USTRUCT(Blueprintable)
18struct AGRARSENSE_API FCaptureData
19{
20 GENERATED_BODY()
21
22 UPROPERTY(VisibleAnywhere, BlueprintReadWrite)
23 TArray<ASensor*> Sensors;
24
25 UPROPERTY(VisibleAnywhere, BlueprintReadWrite)
26 TArray<ACamera*> Cameras;
27
28 UPROPERTY(VisibleAnywhere, BlueprintReadWrite)
29 TArray<ALidar*> Lidars;
30
31 UPROPERTY(VisibleAnywhere, BlueprintReadWrite)
32 TArray<FTransform> CapturePositions;
33
34 /*
35 * If true, captures additional photos at the same location with different yaw rotations (e.g., 360 view without top/bottom).
36 */
37 UPROPERTY(VisibleAnywhere, BlueprintReadWrite)
38 bool CaptureRotatedViews = false;
39
40 /*
41 * Use can give dataCapture json locations in either World locations or GPS locations.
42 */
43 UPROPERTY(VisibleAnywhere, BlueprintReadWrite)
44 bool UseGPSLocation = false;
45
46 UPROPERTY(VisibleAnywhere, BlueprintReadOnly)
47 int32 CurrentCaptureIndex = 0;
48
49 /*
50 * Due to some issues with capturing data in the same frame as moving it,
51 * we may want to keep the sensor in the same position for a few frames.
52 */
53 UPROPERTY(VisibleAnywhere, BlueprintReadOnly)
54 int32 FramesToKeepInSamePosition = 4;
55
56 UPROPERTY(VisibleAnywhere, BlueprintReadOnly)
57 bool UseHeightAboveGround = false;
58};
59
60UENUM(BlueprintType)
61enum class ECaptureStep : uint8
62{
67};
68
69/*
70* This Actor automates the process of gathering synthetic camera and lidar data.
71* The capture logic is a bit convoluted because the camera and lidar sensors
72* may not capture the scene correctly if they move and capture in the same frame.
73* Usage:
74* 1) Spawn any Camera or Lidar sensor.
75* 2) Spawn this Actor and call SetupPhotoCapture with FCaptureData struct.
76*/
77UCLASS()
78class AGRARSENSE_API ADataCapture : public AActor
79{
80 GENERATED_BODY()
81
82public:
83
84 ADataCapture(const FObjectInitializer& ObjectInitializer);
85
86 UFUNCTION(BlueprintCallable)
87 void SetupDataCapture(FCaptureData NewCaptureData);
88
89protected:
90
91 virtual void BeginPlay() override;
92
93 virtual void Tick(float DeltaTime) override;
94
95 virtual void EndPlay(const EEndPlayReason::Type EndPlayReason) override;
96
97private:
98
99 /*
100 * Capture one Image each frame and move to next position next frame.
101 */
102 void Capture();
103
104 void UpdatePositions(const FTransform& Transform);
105
106 void CaptureDataNow();
107
108 void DestroySensors();
109
110 void ComputeAndSetZFromGround(FTransform& Transform);
111
113
115
116 int32 FrameCounter = 0;
117
118 bool NeedsPositionUpdate = true;
119};
ECaptureStep
Definition: DataCapture.h:62
@ WaitingAfterPositionUpdate
@ WaitingForPositionUpdate
Definition: Camera.h:53
FCaptureData CaptureData
Definition: DataCapture.h:112
Definition: Lidar.h:35
virtual void BeginPlay() override
Definition: Lidar.cpp:56
virtual void EndPlay(const EEndPlayReason::Type EndPlayReason) override
Definition: Lidar.cpp:116
Definition: Sensor.h:45