public void StartGazeDataStreams(GazePointCallback gazePointCallback, FixationCallback fixationCallback, EyePositionCallback eyePositionCallback) { if (gazePointCallback != null) { if (gazePointDataStream == null) { gazePointDataStream = eyeXHost.CreateGazePointDataStream(Tobii.EyeX.Framework.GazePointDataMode.Unfiltered); } gazePointDataStream.Next += InvokeGazePointEvent; GazePointEvent += gazePointCallback; GazePointEvent += RecordGazePoint; } if (fixationCallback != null) { if (fixationDataStream == null) { fixationDataStream = eyeXHost.CreateFixationDataStream(FixationDataMode.Sensitive); } fixationDataStream.Next += InvokeFixationEvent; FixationEvent += fixationCallback; FixationEvent += RecordFixation; } if (eyePositionCallback != null) { if (eyePositionDataStream == null) { eyePositionDataStream = eyeXHost.CreateEyePositionDataStream(); } eyePositionDataStream.Next += InvokeEyePositionEvent; EyePositionEvent += eyePositionCallback; EyePositionEvent += RecordEyePosition; } }
public void StartGazeDataStreams( GazePointCallback gazePointCallback, string gazePointDataFilePath, FixationCallback fixationCallback, string fixationsDataFilePath, EyePositionCallback eyePositionCallback, string eyePositionDataFilePath) { isGazePointDataRecording = false; isFixationDataRecording = false; isEyePositionDataRecording = false; GazePointEvent = null; if (gazePointDataFilePath != null) { GazePointEvent += gazePointCallback; //Load gaze point data using (var sr = File.OpenText(gazePointDataFilePath)) { //Heading var line = sr.ReadLine(); var columns = line.Split(','); int gazeXIndex = columns.ToList().IndexOf("gazeX"); int gazeYIndex = columns.ToList().IndexOf("gazeY"); int gazeTimestampIndex = columns.ToList().IndexOf("gazeTimestamp"); while (!sr.EndOfStream) { line = sr.ReadLine(); var columnValues = line.Split(',').Select(x => Double.Parse(x)).ToArray();; gazePoints.Enqueue(new GazePointEventArgs(columnValues[gazeXIndex], columnValues[gazeYIndex], columnValues[gazeTimestampIndex])); } } } FixationEvent = null; if (fixationsDataFilePath != null) { FixationEvent += fixationCallback; //Load fixation data using (var sr = File.OpenText(fixationsDataFilePath)) { //Heading var line = sr.ReadLine(); var columns = line.Split(','); int fixationEventTypeIndex = columns.ToList().IndexOf("fixationEventType"); int fixationXIndex = columns.ToList().IndexOf("fixationX"); int fixationYIndex = columns.ToList().IndexOf("fixationY"); int fixationTimestampIndex = columns.ToList().IndexOf("fixationTimestamp"); while (!sr.EndOfStream) { line = sr.ReadLine(); var columnValues = line.Split(',').ToArray(); Enum.TryParse(columnValues[fixationEventTypeIndex], out FixationDataEventType eventType); fixations.Enqueue(new FixationEventArgs(eventType, Double.Parse(columnValues[fixationXIndex]), Double.Parse(columnValues[fixationYIndex]), Double.Parse(columnValues[fixationTimestampIndex]) )); } } } if (eyePositionDataFilePath != null) { EyePositionEvent += eyePositionCallback; //Load eye position data using (var sr = File.OpenText(eyePositionDataFilePath)) { //Heading var line = sr.ReadLine(); var columns = line.Split(','); int leftIsValidIndex = columns.ToList().IndexOf("leftIsValid"); int leftNormalisedIsValidIndex = columns.ToList().IndexOf("leftNormalisedIsValid"); int rightIsValidIndex = columns.ToList().IndexOf("rightIsValid"); int rightNormalisedIsValidIndex = columns.ToList().IndexOf("rightNormalisedIsValid"); int eyePositionTimestampIndex = columns.ToList().IndexOf("eyePositionTimestamp"); while (!sr.EndOfStream) { line = sr.ReadLine(); var columnValues = line.Split(',').ToArray(); Func <int, EyePosition> ParseEyePositionBlock = i => new EyePosition( Boolean.Parse(columnValues[i]), Double.Parse(columnValues[i + 1]), Double.Parse(columnValues[i + 2]), Double.Parse(columnValues[i + 3]) ); eyePositions.Enqueue(new EyePositionEventArgs( ParseEyePositionBlock(leftIsValidIndex), ParseEyePositionBlock(leftNormalisedIsValidIndex), ParseEyePositionBlock(rightIsValidIndex), ParseEyePositionBlock(rightNormalisedIsValidIndex), Double.Parse(columnValues[eyePositionTimestampIndex]) )); } } } replayTimer = new Timer(); replayTimer.Interval = 16;//ms replayTimer.Tick += (s, e) => { if (gazePoints.TryDequeue(out GazePointEventArgs gp)) { GazePointEvent.Invoke(s, gp); } if (fixations.TryDequeue(out FixationEventArgs f)) { FixationEvent.Invoke(s, f); } if (eyePositions.TryDequeue(out EyePositionEventArgs ep)) { EyePositionEvent.Invoke(s, ep); } if (gazePoints.Count() == 0 && fixations.Count() == 0 && eyePositions.Count() == 0) { replayTimer.Stop(); replayTimer.Enabled = false; replayTimer.Dispose(); } }; replayTimer.Start(); replayTimer.Enabled = true; }