/// <summary> /// Write the Data into the gazeModel /// </summary> /// <param name="leftEye"></param> /// <param name="rightEye"></param> /// <returns></returns> public bool WriteEyeSamplesInGazeModel(SDKSampleStruct dataSample) { try { Vector2 leftEyeGaze = new Vector2((float)dataSample.leftEye.gazeX, (float)dataSample.leftEye.gazeY); Vector3 leftEyePosition = new Vector3((float)dataSample.leftEye.eyePositionX, (float)dataSample.leftEye.eyePositionY, (float)dataSample.leftEye.eyePositionZ); Vector2 rightEyeGaze = new Vector2((float)dataSample.rightEye.gazeX, (float)dataSample.rightEye.gazeY); Vector3 rightEyePosition = new Vector3((float)dataSample.rightEye.eyePositionX, (float)dataSample.rightEye.eyePositionY, (float)dataSample.rightEye.eyePositionZ); #if UNITY_EDITOR //Remove the Offset from the Topbar of the Editor leftEyeGaze.y -= 110f; rightEyeGaze.y -= 110f; #endif EyeSample leftEye = new EyeSample(leftEyeGaze, leftEyePosition, dataSample.leftEye.diam); EyeSample rightEye = new EyeSample(rightEyeGaze, rightEyePosition, dataSample.rightEye.diam); this.dataSample = new SampleData(leftEye, rightEye, dataSample.timestamp); return(true); } catch (System.Exception e) { UnityEngine.Debug.LogException(e); return(false); } }
public static EyeSample Average(EyeSample first, EyeSample second) { return(new EyeSample ( PointUtils.Average(first.GazePoint2D, second.GazePoint2D), PointUtils.Average(first.GazePoint3D, second.GazePoint3D), PointUtils.Average(first.EyePosition3D, second.EyePosition3D), (first.PupilDiameter + second.PupilDiameter) / 2 )); }
public static IObservable <EyeMovement> ClassifyMovements(this IObservable <EyeVelocity> velocities, double velocityThreshold) { return(velocities.Buffer((first, current) => ClassifyMovement(first, velocityThreshold) != ClassifyMovement(current, velocityThreshold)) .Where(b => b.Any()) .Buffer(2, 1) .Scan <IList <IList <EyeVelocity> >, EyeMovement>(null, (movement, buffers) => { var current = buffers.First(); var last = buffers.LastOrDefault(); var currentFirstSample = current.First(); DateTimeOffset startTimestamp = currentFirstSample.Eye.Timestamp; if (movement != null) { var startTicksDiff = movement.EndTimestamp - movement.Samples.Last().Eye.Timestamp; startTimestamp = startTimestamp.Subtract(startTicksDiff.Duration()); } var currentLastSample = current.Last(); DateTimeOffset endTimestamp = currentLastSample.Eye.Timestamp; if (last != null && last != current) { var endTicksDiff = (last.First().Eye.Timestamp - endTimestamp).Duration().Ticks / 2; endTimestamp = endTimestamp.Add(TimeSpan.FromTicks(endTicksDiff)); } EyeMovementType movementType = ClassifyMovement(current.First(), velocityThreshold); EyeSample averageSample = null; if (movementType == EyeMovementType.Fixation) { averageSample = EyeSampleUtils.Average(current.Select(s => s.Eye)); } return new EyeMovement(movementType, current, averageSample, startTimestamp, endTimestamp); })); }
public static double GetVisualAngle(this EyeSample sample, EyeSample from, EyeSample to) { return(EyeSampleUtils.GetVisualAngle(sample.EyePosition3D, from.GazePoint3D, to.GazePoint3D)); }