Skip to content

Commit

Permalink
Fully implement eye tracking evaluation
Browse files Browse the repository at this point in the history
  • Loading branch information
JFrit committed Apr 28, 2021
1 parent 49970ce commit 7e75003
Show file tree
Hide file tree
Showing 8 changed files with 1,559 additions and 1,540 deletions.
1,116 changes: 1,062 additions & 54 deletions Assets/Prefabs/ETAssessment.prefab

Large diffs are not rendered by default.

1,867 changes: 418 additions & 1,449 deletions Assets/Scenes/AttentionExperiment.unity

Large diffs are not rendered by default.

61 changes: 37 additions & 24 deletions Assets/Scripts/CalibrationAssessment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@
using System.Collections;

using System.Collections.Generic;
using System.Linq;
using ScriptableObjects;
using ScriptableObjects.Variables;
using UnityEngine;
using UXF;
using UnityEngine.UI;
using UnityEngine.Windows.WebCam;

[ExecuteInEditMode]
public class CalibrationAssessment : MonoBehaviour
Expand All @@ -27,20 +31,22 @@ public class CalibrationAssessment : MonoBehaviour
[NonSerialized] public Transform CurrentTargetTransform;

private bool _presentingTarget;
private float _gazeToTargetDist;
public float gazeToTargetDist;

private readonly List<int> _remainingTargets = new List<int>() {0,1,2,3,4,5,6,7,8};
private int _targetIdx;

public Text gazeErrorText;

private Block _practiceBlock;

private MeshRenderer[] _targetRenderers;
private static readonly int ColorProperty = Shader.PropertyToID("_Color");

[SerializeField] private SelectEyeTracker eyeTracker;
[SerializeField] private Camera vrCamera;
[SerializeField] private GameObject[] targets;
[SerializeField] private Tracker assessmentTracker;
[SerializeField] private SessionSettings settings;
[SerializeField] private IntVariable trialCount;
private GameObject[][] _targets2D;

public void OnValidate(){
Expand All @@ -54,22 +60,23 @@ public void OnEnable()
_targets2D[1] = new [] {targets[3], targets[4], targets[5]};
_targets2D[2] = new [] {targets[6], targets[7], targets[8]};
_targetRenderers = new MeshRenderer[targets.Length];
// _practiceBlock = Session.instance.CreateBlock();
for (var i = 0; i < targets.Length; i++)
{
_targetRenderers[i] = targets[i].GetComponent<MeshRenderer>();
_targetRenderers[i].enabled = false;
}
_targetRenderers[0].enabled = true;
_targetIdx = 0;
targetDistance = settings.stimulusDepth;
CurrentTargetTransform = GETTargTransformByIndex(0);

RepositionTargets();

if(randomizeTargetOrder){
ShuffleTargetList();
}
}

public void Start()
{
for (var i = 0; i < targets.Length; i++)
{
_targetRenderers[i] = targets[i].GetComponent<MeshRenderer>();
}
}


private void RepositionTargets(){
var halfAzRad = (azimuthWidth/2.0f) * Mathf.Deg2Rad;
var halfElRad = (elevationHeight/2.0f) * Mathf.Deg2Rad;
Expand All @@ -96,6 +103,9 @@ private void RepositionTargets(){
}

var targetBacking = transform.Find("backing");
targetBacking.GetComponent<MeshFilter>().mesh.triangles =
targetBacking.GetComponent<MeshFilter>().mesh.triangles.Reverse().ToArray();
targetBacking.gameObject.AddComponent<MeshCollider>();
targetBacking.localScale = new Vector3(targetDistance*2.0f, targetDistance*2.0f, targetDistance*2.0f);
}

Expand Down Expand Up @@ -150,7 +160,6 @@ private Transform GETTargTransformByIndex(int targetIdx){


private void RecordFixation(){
var aTrial = _practiceBlock.CreateTrial();
var mr = CurrentTargetTransform.gameObject.GetComponent<MeshRenderer>();

StartCoroutine(PresentTarget());
Expand All @@ -161,13 +170,14 @@ IEnumerator PresentTarget()
mr.material.SetColor(ColorProperty, Color.yellow);
_presentingTarget = true;

aTrial.Begin();


assessmentTracker.StartRecording();
yield return new WaitForSeconds(fixationTime);
assessmentTracker.StopRecording();

aTrial.End();
aTrial.result["trialType"] = "CalibrationAssessment";

mr.material.SetColor(ColorProperty, Color.black);
Session.instance.SaveDataTable(assessmentTracker.data, "EyeTrackerAssessmentTrial" + trialCount.value);
Debug.Log("Data recorded for target");
_presentingTarget = false;
}
}
Expand Down Expand Up @@ -224,12 +234,15 @@ private void ToggleHeadFixed(){
}
}

public void Update()
public void LateUpdate()
{
//var gazeInHead = Camera.main.transform.InverseTransformPoint(eyeInHeadTransform.position);
//_gazeToTargetDist = Vector3.Angle(CurrentTargetTransform.localPosition, gazeInHead);
_gazeToTargetDist = 0.0f;
gazeErrorText.text = _gazeToTargetDist.ToString("0.#");
if (Physics.Raycast(vrCamera.transform.position,
vrCamera.transform.TransformDirection(eyeTracker.ChosenTracker.GetLocalGazeDirection()), out var hit))
{
gazeToTargetDist = Vector3.Angle(CurrentTargetTransform.localPosition, vrCamera.transform.InverseTransformPoint(hit.point));
}

gazeErrorText.text = "Current Error: " + gazeToTargetDist.ToString("0.#") + " degrees";
}
}

6 changes: 2 additions & 4 deletions Assets/Scripts/SessionManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -168,17 +168,15 @@ public void CalibratePupilLabs()

private void CalibrationSuccessful()
{
if (_isPaused)
pauseUI.SetActive(true);
pauseUI.SetActive(true);
infoText.gameObject.SetActive(true);
infoText.text = "Calibration successful!";
infoText.color = Color.green;
}

private void CalibrationFailed()
{
if (_isPaused)
pauseUI.SetActive(true);
pauseUI.SetActive(true);
infoText.gameObject.SetActive(true);
infoText.text = "Calibration failed.\n Ensure that Pupil Capture is running with both eye cameras!";
infoText.color = Color.red;
Expand Down
5 changes: 5 additions & 0 deletions Assets/Scripts/Trial Manager/TrialManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ public class TrialManager : MonoBehaviour
// Handles the management and interleaving of staircases
public StaircaseManager StaircaseManager { get; private set; }

public void OnValidate()
{
trialCount.value = 0;
}

public void Start()
{
trialCount.value = 1;
Expand Down
2 changes: 1 addition & 1 deletion Assets/StreamingAssets/TEMPLATE.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@

"FailOnTimeout": true,

"EyeTracker": "Dummy",
"EyeTracker": "dum",
"AttentionCueType": "Feature-based",

"EnableDirectionalStaircase": true,
Expand Down
34 changes: 30 additions & 4 deletions Assets/UXF/Scripts/AssessmentTracker.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using UnityEngine;
using ScriptableObjects.Variables;
using UnityEngine;

namespace UXF
{
Expand All @@ -9,10 +10,13 @@ namespace UXF
public class AssessmentTracker : Tracker
{
private CalibrationAssessment _target;
[SerializeField] private IntVariable trialCount;

private void Start()
private void OnEnable()
{
_target = gameObject.GetComponent<CalibrationAssessment>();
SetupDescriptorAndHeader();
data = new UXFDataTable(header);
}

/// <summary>
Expand All @@ -36,7 +40,9 @@ protected override void SetupDescriptorAndHeader()
objectName + "TargetPositionZ",
objectName + "TargetLocalPositionX",
objectName + "TargetLocalPositionY",
objectName + "TargetLocalPositionZ"
objectName + "TargetLocalPositionZ",
objectName + "GazeErrorDegrees",
objectName + "TrialEvaluated"
};
}

Expand Down Expand Up @@ -66,11 +72,31 @@ protected override UXFDataRow GetCurrentValues()
(customHeader[9], position.z.ToString(format)),
(customHeader[10], localPosition.x.ToString(format)),
(customHeader[11], localPosition.y.ToString(format)),
(customHeader[12], localPosition.z.ToString(format))
(customHeader[12], localPosition.z.ToString(format)),
(customHeader[13], _target.gazeToTargetDist),
(customHeader[14], trialCount.value)
};

dataRow.AddRange(values);
return dataRow;
}

/// <summary>
/// Records a new row of data at current time. Can run independently of a running trial.
/// </summary>
public override void RecordRow()
{
UXFDataRow newRow = GetCurrentValues();
newRow.Add(("time", Time.time));
data.AddCompleteRow(newRow);
}

public override void StartRecording()
{
if (data == null)
data = new UXFDataTable(header);

recording = true;
}
}
}
8 changes: 4 additions & 4 deletions Assets/UXF/Scripts/Etc/Tracker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ public string dataName
}
}

private bool recording;
protected bool recording;

public bool Recording { get { return recording; } }

public UXFDataTable data { get; private set; } = new UXFDataTable();
public UXFDataTable data { get; protected set; } = new UXFDataTable();

/// <summary>
/// The header that will go at the top of the output file associated with this tracker
Expand Down Expand Up @@ -88,7 +88,7 @@ void FixedUpdate()
/// <summary>
/// Records a new row of data at current time.
/// </summary>
public void RecordRow()
public virtual void RecordRow()
{
if (!recording) throw new System.InvalidOperationException("Tracker measurements cannot be taken when not in a trial!");

Expand All @@ -100,7 +100,7 @@ public void RecordRow()
/// <summary>
/// Begins recording.
/// </summary>
public void StartRecording()
public virtual void StartRecording()
{
data = new UXFDataTable(header);
recording = true;
Expand Down

0 comments on commit 7e75003

Please sign in to comment.