public async override void SubscribeToFixationDataAsync() { // Initialize Fixation data stream. var fixationDataStream = Host.Streams.CreateFixationDataStream(); fixationDataStream.Next += (o, fixation) => { // Converting Tobii Core FixationData to EyeX GazeData Format System.Drawing.Rectangle resolution = Screen.PrimaryScreen.Bounds; GazeData.FixationData fixationData = new GazeData.FixationData { Type = nameof(Globals.Constants.GazeDataTypes.FIXATIONS), Timestamp = (long)fixation.Data.Timestamp, X_Median = (fixation.Data.X / 3840), Y_Median = (fixation.Data.Y / 2160), EventType = Enum.GetName(typeof(FixationDataEventType), fixation.Data.EventType).ToUpper() }; if (!double.IsNaN(fixation.Data.X)) { GazeDataProcessor.ProcessFixationData(fixationData); } //if (fixationData.EventType == FixationDataEventType.Begin) //{ // Globals.Globals.fixationCount += 1; //} }; }
public async override void SubscribeToGazeDataAsync() { var gazePointDataStream = Host.Streams.CreateGazePointDataStream(); gazePointDataStream.GazePoint((x, y, ts) => handleGazeData(x, y, ts)); void handleGazeData(double x, double y, double ts) { // Converting Tobii Core GazeData to EyeX GazeData Format GazeData.GazeData gazeData = new GazeData.GazeData { Type = nameof(GazeDataTypes.GAZEPOINTS), Timestamp = (long)ts, X_Median = x / 3840, Y_Median = y / 2160 }; GazeDataProcessor.ProcessGazeData(gazeData); switch (Settings.Default.FixationAlgorithm) { // Use implemented IDT Algorithm case "IDT": GazeDataProcessor.ProcessFixationData(null, gazeData); break; // Use Tobii Core Default Fixation Alogrithm default: SubscribeToFixationDataAsync(); break; } } }
/// <summary> /// Retrieves Tobii Pro Api Gaze Data and sends it further to the Data Processor /// </summary> /// <returns></returns> public async override void SubscribeToGazeDataAsync() { EyeTracker.GazeDataReceived += (sender, gazeDataEventArgs) => { // Converting Tobii Pro GazeData to EyeX GazeData Format GazeData.GazeData gazeData = new GazeData.GazeData { Type = nameof(GazeDataTypes.GAZEPOINTS), PupilDiameter_Left = gazeDataEventArgs.LeftEye.Pupil.PupilDiameter, PupilDiameter_Right = gazeDataEventArgs.RightEye.Pupil.PupilDiameter, Timestamp = gazeDataEventArgs.SystemTimeStamp, Y_Left = gazeDataEventArgs.LeftEye.GazePoint.PositionOnDisplayArea.Y, Y_Right = gazeDataEventArgs.RightEye.GazePoint.PositionOnDisplayArea.Y, X_Left = gazeDataEventArgs.LeftEye.GazePoint.PositionOnDisplayArea.X, X_Right = gazeDataEventArgs.RightEye.GazePoint.PositionOnDisplayArea.X, }; // Map 3D Eye Coordinates var originR = gazeDataEventArgs.RightEye.GazeOrigin.PositionInTrackBoxCoordinates; var originL = gazeDataEventArgs.LeftEye.GazeOrigin.PositionInTrackBoxCoordinates; gazeData.GazeOrigin_X_Median = (originR.X + originL.X) / 2.0; gazeData.GazeOrigin_Y_Median = (originR.Y + originL.Y) / 2.0; gazeData.GazeOrigin_Y_Median = (originR.Z + originL.Z) / 2.0; gazeData.X_3D_Median = gazeDataEventArgs.RightEye.GazePoint.PositionInUserCoordinates.X; gazeData.Y_3D_Median = gazeDataEventArgs.RightEye.GazePoint.PositionInUserCoordinates.Y; gazeData.Z_3D_Median = gazeDataEventArgs.RightEye.GazePoint.PositionInUserCoordinates.Z; // Map Validity Values gazeData.GazePointValidity_Left = gazeDataEventArgs.LeftEye.GazePoint.Validity == Validity.Valid ? true : false; gazeData.GazePointValidity_Right = gazeDataEventArgs.RightEye.GazePoint.Validity == Validity.Valid ? true : false; gazeData.PupilValidity_Left = gazeDataEventArgs.LeftEye.Pupil.Validity == Validity.Valid ? true : false; gazeData.PupilValidity_Right = gazeDataEventArgs.RightEye.Pupil.Validity == Validity.Valid ? true : false; // Compute Median Gaze Points gazeData.Y_Median = (gazeData.Y_Left + gazeData.Y_Right) / 2; gazeData.X_Median = (gazeData.X_Left + gazeData.X_Right) / 2; if (!double.IsNaN(gazeData.X_Median)) { GazeDataProcessor.ProcessGazeData(gazeData); GazeDataProcessor.ProcessFixationData(null, gazeData); } }; }