private void GazeInputSourcePreview_GazeMoved(GazeInputSourcePreview sender, GazeMovedPreviewEventArgs args) { _gazePosition.SetPosition(args.CurrentPoint.EyeGazePosition); if (_gazeHidPositionsParser == null) { _gazeHidPositionsParser = new GazeHidPositionsParser(args.CurrentPoint.SourceDevice); } var positions = _gazeHidPositionsParser.GetGazeHidPositions(args.CurrentPoint.HidInputReport); _leftEyePosition.SetPosition(positions.LeftEyePosition); _rightEyePosition.SetPosition(positions.RightEyePosition); _headPosition.SetPosition(positions.HeadPosition); _headRotatePosition.SetPosition(positions.HeadRotation); if (_leftEyePosition.Z == 0 && _rightEyePosition.Z == 0) { Blink?.Invoke(BlinkType.Both); } else { if (_leftEyePosition.Z == 0) { Blink?.Invoke(BlinkType.Left); } if (_rightEyePosition.Z == 0) { Blink?.Invoke(BlinkType.Right); } } GazeMoved?.Invoke(); }
private void GazeInputSourcePreview_GazeMoved(GazeInputSourcePreview sender, GazeMovedPreviewEventArgs args) { if (args.CurrentPoint.HidInputReport != null) { var hidReport = args.CurrentPoint.HidInputReport; var sourceDevice = args.CurrentPoint.SourceDevice; if (gazeHidPositionsParser == null) { gazeHidPositionsParser = new GazeHidPositionsParser(sourceDevice); } GazeHidPositions positions = gazeHidPositionsParser.GetGazeHidPositions(hidReport); if (positions.RightEyePosition != null) { double DistanceInMM = positions.RightEyePosition.Z / 10000; DistanceText.Text = "Head distance: " + DistanceInMM.ToString() + " mm"; if (DistanceInMM >= 50) { DevicesList.ItemTemplate = (DataTemplate)this.Resources["LargeDeviceTemplate"]; } else { DevicesList.ItemTemplate = (DataTemplate)this.Resources["SmallDeviceTemplate"]; } } } }
public void AddEvent(GazeMovedPreviewEventArgs ea) { _gazeEvents.Add(ea); var ellipse = new Ellipse(); ellipse.Fill = _ellipseBrush; ellipse.VerticalAlignment = VerticalAlignment.Top; ellipse.HorizontalAlignment = HorizontalAlignment.Left; ellipse.Width = 2 * DEFAULT_ELLIPSE_RADIUS; ellipse.Height = 2 * DEFAULT_ELLIPSE_RADIUS; ellipse.Margin = new Thickness(ea.CurrentPoint.EyeGazePosition.Value.X - DEFAULT_ELLIPSE_RADIUS, ea.CurrentPoint.EyeGazePosition.Value.Y - DEFAULT_ELLIPSE_RADIUS, 0, 0); _ellipses.Add(ellipse); var count = _gazeEvents.Count; if (count > 2) { var line = new Line(); line.X1 = _gazeEvents[count - 2].CurrentPoint.EyeGazePosition.Value.X; line.Y1 = _gazeEvents[count - 2].CurrentPoint.EyeGazePosition.Value.Y; line.X2 = _gazeEvents[count - 1].CurrentPoint.EyeGazePosition.Value.X; line.Y2 = _gazeEvents[count - 1].CurrentPoint.EyeGazePosition.Value.Y; line.Stroke = _ellipseBrush; line.StrokeThickness = 2; _lines.Add(line); } }
private void OnGazeInput(GazeInputSourcePreview sender, GazeMovedPreviewEventArgs ea) { if ((_imageData.TrackGaze) /*&& (_pictureRect.Contains(ea.Location)) */) { _imageData.GazeEvents.Add(ea); _trackViewer.AddEvent(ea); } }
/// <summary> /// GazeMoved handler translates the ellipse on the canvas to reflect gaze point. /// </summary> /// <param name="sender">Source of the gaze moved event</param> /// <param name="e">Event args for the gaze moved event</param> private void GazeMoved(GazeInputSourcePreview sender, GazeMovedPreviewEventArgs args) { // Update the position of the ellipse corresponding to gaze point. if (args.CurrentPoint.EyeGazePosition != null) { double gazePointX = args.CurrentPoint.EyeGazePosition.Value.X; double gazePointY = args.CurrentPoint.EyeGazePosition.Value.Y; double ellipseLeft = gazePointX - (eyeGazePositionEllipse.Width / 2.0f); double ellipseTop = gazePointY - (eyeGazePositionEllipse.Height / 2.0f); // Translate transform for moving gaze ellipse. TranslateTransform translateEllipse = new TranslateTransform { X = ellipseLeft, Y = ellipseTop }; eyeGazePositionEllipse.RenderTransform = translateEllipse; // The gaze point screen location. Point gazePoint = new Point(gazePointX, gazePointY); UIElement element = GetButtonAtGaze(gazePoint, LettersArea); if (element != focusElement) { timerGaze.Stop(); GazeRadialProgressBar.Value = 0; timerStarted = false; focusElement = element; if (focusElement != null) { MoveGazeRadialProgressBar(focusElement, LettersArea); } } // Basic hit test to determine if gaze point is on progress bar. bool hitRadialProgressBar = DoesElementContainPoint( gazePoint, GazeRadialProgressBar.Name, GazeRadialProgressBar); // Use progress bar thickness for visual feedback. if (hitRadialProgressBar) { GazeRadialProgressBar.Thickness = 10; } else { GazeRadialProgressBar.Thickness = 4; } // Mark the event handled. args.Handled = true; } }
private void GazeTrackerMoved(GazeInputSourcePreview sender, GazeMovedPreviewEventArgs args) { // Update the position of the ellipse corresponding to gaze point if (args.CurrentPoint.EyeGazePosition != null) { var gazePointX = args.CurrentPoint.EyeGazePosition.Value.X; var gazePointY = args.CurrentPoint.EyeGazePosition.Value.Y; GazeMoved(gazePointX, gazePointY); // Mark the event handled args.Handled = true; } }
private void GazeInputSourcePreview_GazeMoved(GazeInputSourcePreview sender, GazeMovedPreviewEventArgs args) { if (!ShowIntermediatePoints) { UpdateGazeHistory(args.CurrentPoint); return; } var points = args.GetIntermediatePoints(); foreach (var pt in points) { UpdateGazeHistory(pt); } }
private void GazeInputSourcePreview_GazeMoved(GazeInputSourcePreview sender, GazeMovedPreviewEventArgs args) { var point = args.CurrentPoint.EyeGazePosition; if (!point.HasValue) { return; } GazeHistory.Add(point.Value); if (GazeHistory.Count > MaxGazeHistorySize) { GazeHistory.RemoveAt(0); } }
/// <summary> /// GazeMoved handler translates the ellipse on the canvas to reflect gaze point. /// </summary> /// <param name="sender">Source of the gaze moved event</param> /// <param name="e">Event args for the gaze moved event</param> private void GazeMoved(GazeInputSourcePreview sender, GazeMovedPreviewEventArgs args) { // Update the position of the ellipse corresponding to gaze point. if (args.CurrentPoint.EyeGazePosition != null) { double gazePointX = args.CurrentPoint.EyeGazePosition.Value.X; double gazePointY = args.CurrentPoint.EyeGazePosition.Value.Y; double ellipseLeft = gazePointX - (eyeGazePositionEllipse.Width / 2.0f); double ellipseTop = gazePointY - (eyeGazePositionEllipse.Height / 2.0f) - (int)Header.ActualHeight; // Translate transform for moving gaze ellipse. TranslateTransform translateEllipse = new TranslateTransform { X = ellipseLeft, Y = ellipseTop }; eyeGazePositionEllipse.RenderTransform = translateEllipse; // The gaze point screen location. Windows.Foundation.Point gazePoint = new Windows.Foundation.Point(gazePointX, gazePointY); int rectx = ((int)gazePointX) / 100; int recty = (((int)gazePointY) / 25) - 4; string rectname = "rect" + rectx.ToString() + "_" + recty.ToString(); try { Windows.UI.Xaml.Shapes.Rectangle ele = hashtable[rectname]; // Basic hit test to determine if gaze point is on progress bar. ele.Visibility = Windows.UI.Xaml.Visibility.Collapsed; } catch (Exception e) { Console.WriteLine("IOException source: {0}, rectname {1}", e.Source, rectname); } // Mark the event handled. args.Handled = true; } }
private void OnGazeMoved( GazeInputSourcePreview provider, GazeMovedPreviewEventArgs args) { if (!_isShuttingDown) { var intermediatePoints = args.GetIntermediatePoints(); foreach (var point in intermediatePoints) { var position = point.EyeGazePosition; if (position != null) { _gazeCursor.IsGazeEntered = true; ProcessGazePoint(new TimeSpan((long)point.Timestamp * 10), position.Value); } else { // Debug.WriteLine("Null position eaten at %ld", point.Timestamp); } } } }
// -------------------- Effects Page -------------------- private void GazeMoved(GazeInputSourcePreview sender, GazeMovedPreviewEventArgs args) { ChaosControl.GetActiveControl().MoveEllipse(args.CurrentPoint.EyeGazePosition.Value.X, args.CurrentPoint.EyeGazePosition.Value.Y); }
private void GazeInputSourcePreview_GazeMoved(GazeInputSourcePreview sender, GazeMovedPreviewEventArgs args) { var sb = new StringBuilder(); sb.Append(" GazePos ("); if (args.CurrentPoint.EyeGazePosition != null) { Canvas.SetLeft(GazePositionEllipse, args.CurrentPoint.EyeGazePosition.Value.X); Canvas.SetTop(GazePositionEllipse, args.CurrentPoint.EyeGazePosition.Value.Y); sb.Append($"{args.CurrentPoint.EyeGazePosition.Value.X,6}px, {args.CurrentPoint.EyeGazePosition.Value.Y,6}px"); if (showGaze) { GazePositionEllipse.Visibility = Visibility.Visible; } else { GazePositionEllipse.Visibility = Visibility.Collapsed; } } else { GazePositionEllipse.Visibility = Visibility.Collapsed; } sb.AppendLine(")"); if (args.CurrentPoint.HidInputReport != null) { var hidReport = args.CurrentPoint.HidInputReport; var sourceDevice = args.CurrentPoint.SourceDevice; var leftEyePositionParser = new GazePositionHidParser(sourceDevice, GazeExtendedUsages.Usage_LeftEyePosition); var rightEyePositionParser = new GazePositionHidParser(sourceDevice, GazeExtendedUsages.Usage_RightEyePosition); var leftEyePosition = leftEyePositionParser.GetPosition(hidReport); var rightEyePosition = rightEyePositionParser.GetPosition(hidReport); // The return values for the left and right eye are in micrometers by default // They are references such that X and Y origin are the top left hand corner // of the calibrated display. The Z origin is the centerpoint of the display // (not the tracker). As such, there is a minor difference between the actual // sensor-to-eye distance vs the reported distance for left/right eye position. UpdateEyeData("Left", leftEyePosition, LeftEyePositionEllipse, sb); UpdateEyeData("Right", rightEyePosition, RightEyePositionEllipse, sb); if (rightEyePosition != null && leftEyePosition != null) { // calculate IPD in mm var interPupilaryDistance = (rightEyePosition.Value.X - leftEyePosition.Value.X) / 1000.0; sb.AppendLine($" IPD ({interPupilaryDistance,6:F2}mm)"); } var headPostitionParser = new GazePositionHidParser(sourceDevice, GazeExtendedUsages.Usage_HeadPosition); var headPosition = headPostitionParser.GetPosition(hidReport); if (headPosition != null) { sb.AppendLine($"HeadPosition ({headPosition.Value.X,8:F2}, {headPosition.Value.Y,8:F2}, {headPosition.Value.Z,8:F2})"); } var headRotationParser = new GazeRotationHidParser(sourceDevice, GazeExtendedUsages.Usage_HeadDirectionPoint); var headRotation = headRotationParser.GetRotation(hidReport); if (headRotation != null) { sb.AppendLine($"HeadRotation ({headRotation.Value.X,8:F2}, {headRotation.Value.Y,8:F2}, {headRotation.Value.Z,8:F2})"); } } StatusTextBlock.Text = sb.ToString(); }
private void GazeInputSourcePreview_GazeMoved(GazeInputSourcePreview sender, GazeMovedPreviewEventArgs args) { UpdateGazeHistory(args.CurrentPoint); }
private void OnGazeMoved(GazeInputSourcePreview sender, GazeMovedPreviewEventArgs args) { var points = args.GetIntermediatePoints(); if (points.Count != 1) { Log($"Grouped points reported in move, Count={points.Count}"); } foreach (var point in points) { var position = point.EyeGazePosition; var timestamp = TimeSpan.FromMilliseconds(point.Timestamp / 1000.0); if (!_isReporting) { _startTimestamp = timestamp; if (!_isEntered) { Log("Gaze report without enter"); _isEntered = true; } else if (_isFirstReportExpected && (_lastPosition.HasValue != position.HasValue || (_lastPosition.HasValue && !(_lastPosition.Value.X == position.Value.X && _lastPosition.Value.Y == position.Value.Y)))) { Log("First report after enter is inconsistent", point); } _isFirstReportExpected = false; _newPositionCount = position.HasValue ? 1 : 0; _noPositionCount = position.HasValue ? 0 : 1; _repeatPositionCount = 0; _blickCount = 0; _minDelta = TimeSpan.MaxValue; _maxDelta = TimeSpan.MinValue; _isReporting = true; _reportingTimer.Start(); } else { var delta = timestamp - _lastTimestamp; if (delta < _minDelta) { _minDelta = delta; } if (_maxDelta < delta) { _maxDelta = delta; } if (2 * _minDelta < delta) { _blickCount++; } if (_lastPosition.HasValue) { if (position.HasValue) { if (_lastPosition == position) { _repeatPositionCount++; } else { _newPositionCount++; } } else { _noPositionCount++; } } else { if (position.HasValue) { _newPositionCount++; } else { _noPositionCount++; } } } _lastPosition = position; _lastTimestamp = timestamp; _lastTickCount = TimeSpan.FromMilliseconds(Environment.TickCount); } }