-
Notifications
You must be signed in to change notification settings - Fork 43
/
EgoSensor.h
106 lines (87 loc) · 4.15 KB
/
EgoSensor.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#pragma once
#include "Carla/Sensor/DReyeVRData.h" // DReyeVR namespace
#include "Carla/Sensor/DReyeVRSensor.h" // ADReyeVRSensor
#include "Components/SceneCaptureComponent2D.h" // USceneCaptureComponent2D
#include <chrono> // timing threads
#include <cstdint>
#if USE_SRANIPAL_PLUGIN
// avoid macro conflict since SRanipal uses "ERROR" often
#ifdef ERROR
#undef ERROR
#endif
/// NOTE: Can only use SRanipal on Windows machines
#include "SRanipalEye.h" // SRanipal Module Framework
#include "SRanipalEye_Core.h" // SRanipal Eye Tracker
#include "ViveSR_Enums.h" // ViveSR::Error::WORK
// Make sure to patch sranipal before using it here!
#include "SRanipalEye_Framework.h" // StartFramework
#endif
#include "EgoSensor.generated.h"
class AEgoVehicle;
class ADReyeVRGameMode;
UCLASS()
class CARLAUE4_API AEgoSensor : public ADReyeVRSensor
{
GENERATED_BODY()
public:
AEgoSensor(const FObjectInitializer &ObjectInitializer);
void ManualTick(float DeltaSeconds); // Tick called explicitly from DReyeVR EgoVehicle
void SetEgoVehicle(class AEgoVehicle *EgoVehicle); // provide access to EgoVehicle (and by extension its camera)
void UpdateData(const DReyeVR::ConfigFileData &RecorderData, const double Per) override;
void UpdateData(const DReyeVR::CustomActorData &RecorderData, const double Per) override;
// function where replayer requests a screenshot
void TakeScreenshot() override;
bool ComputeGazeTrace(FHitResult &Hit, const ECollisionChannel TraceChannel, float TraceRadius = 0.f) const;
protected:
void BeginPlay();
void BeginDestroy();
class UWorld *World; // to get info about the world: time, frames, etc.
private:
int64_t TickCount = 0; // how many ticks have been executed
void ReadConfigVariables();
private: // eye tracker
void InitEyeTracker();
void DestroyEyeTracker();
void ComputeDummyEyeData(); // when no hardware sensor is present
void TickEyeTracker(); // tick hardware sensor
void ComputeFocusInfo();
void ComputeTraceFocusInfo(const ECollisionChannel TraceChannel, float TraceRadius = 0.f);
float MaxTraceLenM = 100.f; // maximum trace length in m
bool bDrawDebugFocusTrace = false; // draw the trace ray and hit point or not
float ComputeVergence(const FVector &L0, const FVector &LDir, const FVector &R0, const FVector &RDir) const;
#if USE_SRANIPAL_PLUGIN
SRanipalEye_Core *SRanipal; // SRanipalEye_Core.h
SRanipalEye_Framework *SRanipalFramework; // SRanipalEye_Framework.h
ViveSR::anipal::Eye::EyeData EyeData; // SRanipal_Eyes_Enums.h
bool bSRanipalEnabled; // Whether or not the framework has been loaded
#endif
struct DReyeVR::EyeTracker EyeSensorData; // data from eye tracker
struct DReyeVR::FocusInfo FocusInfoData; // data from the focus computed from eye gaze
std::chrono::time_point<std::chrono::system_clock> ChronoStartTime; // std::chrono time at BeginPlay
private: // ego=vehicle variables
void ComputeEgoVars();
TWeakObjectPtr<class AEgoVehicle> Vehicle; // the DReyeVR EgoVehicle
struct DReyeVR::EgoVariables EgoVars; // data from vehicle that is getting tracked
DReyeVR::ConfigFileData *RecordingCF = nullptr;
private: // frame capture
size_t ScreenshotCount = 0;
void ConstructFrameCapture(); // needs to be called in the constructor
void InitFrameCapture(); // needs to be called in BeginPlay
class UTextureRenderTarget2D *CaptureRenderTarget = nullptr;
class USceneCaptureComponent2D *FrameCap = nullptr;
FString FrameCapLocation; // relative to game dir
FString FrameCapFilename; // gets ${tick}.png suffix
int FrameCapWidth;
int FrameCapHeight;
bool bCaptureFrameData;
bool bRecordAllShaders;
bool bRecordAllPoses;
bool bCreatedDirectory = false;
bool bFileFormatJPG = true;
bool bFrameCapForceLinearGamma = true;
private: // foveated rendering
void TickFoveatedRender();
void ConvertToEyeTrackerSpace(FVector &inVec) const;
bool bEnableFovRender = false;
bool bUseEyeTrackingVRS = true;
};