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"]; } } } }
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(); }
public MainPage() { InitializeComponent(); DataContext = this; ShowIntermediatePoints = false; MaxGazeHistorySize = 100; rootFrame = Window.Current.Content as Frame; gazeInputSourcePreview = GazeInputSourcePreview.GetForCurrentView(); gazeInputSourcePreview.GazeMoved += GazeInputSourcePreview_GazeMoved; startTime = DateTime.Now; TimerLog.Text += "Start Time: " + startTime + "\n"; ThreadPoolTimer timer = ThreadPoolTimer.CreatePeriodicTimer((t) => { var currentTime = DateTime.Now; if ((currentTime - lastGazeTime).TotalSeconds > 10) { _ = Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { TimerLog.Text += "Timeout Triggered!\n"; TimerLog.Text += "Current Time: " + currentTime + "\n"; TimerLog.Text += "Last Time: " + lastGazeTime + "\n"; }); } }, TimeSpan.FromSeconds(2)); }
private void OnGazeExited( GazeInputSourcePreview provider, GazeExitedPreviewEventArgs args) { // Debug.WriteLine("Exited at %ld", args.CurrentPoint.Timestamp); _gazeCursor.IsGazeEntered = false; }
private void InitializeGazeTracing() { MaxGazeHistorySize = 100; gazeInputSourcePreview = GazeInputSourcePreview.GetForCurrentView(); gazeInputSourcePreview.GazeMoved += GazeInputSourcePreview_GazeMoved; }
public EyeTracker() { _gazeInputSourcePreview = GazeInputSourcePreview.GetForCurrentView(); _gazeInputSourcePreview.GazeEntered += GazeInputSourcePreview_GazeEntered; _gazeInputSourcePreview.GazeMoved += GazeInputSourcePreview_GazeMoved; _gazeInputSourcePreview.GazeExited += GazeInputSourcePreview_GazeExited; }
private void GazeExited( GazeInputSourcePreview sender, GazeExitedPreviewEventArgs args) { // Mark the event handled args.Handled = true; }
private void OnGazeInput(GazeInputSourcePreview sender, GazeMovedPreviewEventArgs ea) { if ((_imageData.TrackGaze) /*&& (_pictureRect.Contains(ea.Location)) */) { _imageData.GazeEvents.Add(ea); _trackViewer.AddEvent(ea); } }
private void GazeInputSourcePreview_GazeExited(GazeInputSourcePreview sender, GazeExitedPreviewEventArgs args) { _leftEyePosition.Clear(); _rightEyePosition.Clear(); _headPosition.Clear(); _headRotatePosition.Clear(); GazeExited?.Invoke(); }
private void OnGazeEntered(GazeInputSourcePreview sender, GazeEnteredPreviewEventArgs args) { _lastPosition = args.CurrentPoint.EyeGazePosition; Log(_isEntered ? "Enter while already entered" : "Gaze entered", args.CurrentPoint); _isEntered = true; _isFirstReportExpected = true; }
/// <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; } }
public MainPage() { InitializeComponent(); ShowIntermediatePoints = false; MaxGazeHistorySize = 100; gazeInputSourcePreview = GazeInputSourcePreview.GetForCurrentView(); gazeInputSourcePreview.GazeMoved += GazeInputSourcePreview_GazeMoved; }
/// <summary> /// Start gaze watcher and declare watcher event handlers. /// </summary> private void StartGazeDeviceWatcher() { if (gazeDeviceWatcher == null) { gazeDeviceWatcher = GazeInputSourcePreview.CreateWatcher(); gazeDeviceWatcher.Added += this.DeviceAdded; gazeDeviceWatcher.Updated += this.DeviceUpdated; gazeDeviceWatcher.Start(); } }
/// <summary> /// GazeEntered handler. /// </summary> /// <param name="sender">Source of the gaze entered event</param> /// <param name="e">Event args for the gaze entered event</param> private void GazeEntered( GazeInputSourcePreview sender, GazeEnteredPreviewEventArgs args) { // Show ellipse representing gaze point. eyeGazePositionEllipse.Visibility = Visibility.Visible; // Mark the event handled. args.Handled = true; }
public MainPage() { gazeInputSource = GazeInputSourcePreview.GetForCurrentView(); gazeInputSource.GazeMoved += GazeMoved; // Used only for the Chaos Controls Application.Current.Resources["ToggleButtonBackgroundChecked"] = Application.Current.Resources["SystemBaseMediumColor"]; this.Loaded += MainPage_Loaded; this.InitializeComponent(); }
/// <summary> /// GazeExited handler. /// Call DisplayRequest.RequestRelease to conclude the /// RequestActive called in GazeEntered. /// </summary> /// <param name="sender">Source of the gaze exited event</param> /// <param name="e">Event args for the gaze exited event</param> private void GazeExited( GazeInputSourcePreview sender, GazeExitedPreviewEventArgs args) { // Hide gaze tracking ellipse. eyeGazePositionEllipse.Visibility = Visibility.Collapsed; // Mark the event handled. args.Handled = true; }
public GazeTracingPage() { this.InitializeComponent(); DataContext = this; ShowIntermediatePoints = false; MaxGazeHistorySize = 100; rootFrame = Window.Current.Content as Frame; gazeInputSourcePreview = GazeInputSourcePreview.GetForCurrentView(); gazeInputSourcePreview.GazeMoved += GazeInputSourcePreview_GazeMoved; }
public MediaPage() { InitializeComponent(); _trackViewer = new TrackViewer(); Loaded += TrackingPage_Loaded; var gazeInputSource = GazeInputSourcePreview.GetForCurrentView(); if (gazeInputSource != null) { gazeInputSource.GazeMoved += OnGazeInput; } }
public MainPage() { InitializeComponent(); MaxGazeHistorySize = 100000; rootFrame = Window.Current.Content as Frame; gazeInputSourcePreview = GazeInputSourcePreview.GetForCurrentView(); gazeInputSourcePreview.GazeMoved += GazeInputSourcePreview_GazeMoved; GazeHistoryItemsControl.ItemsSource = GazeHistory; }
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; } }
public MainPage() { InitializeComponent(); gazeInputSourcePreview = GazeInputSourcePreview.GetForCurrentView(); gazeInputSourcePreview.GazeMoved += GazeInputSourcePreview_GazeMoved; displayInformation = DisplayInformation.GetForCurrentView(); screenSize = new Size((int)displayInformation.ScreenWidthInRawPixels, (int)displayInformation.ScreenHeightInRawPixels); screenSizeInchesWidth = screenSize.Width / displayInformation.RawDpiX; screenSizeInchesHeight = screenSize.Height / displayInformation.RawDpiY; screenSizeMicrometersWidth = screenSizeInchesWidth * 25400; screenSizeMicrometersHeight = screenSizeInchesHeight * 25400; }
/// <summary> /// Initialize gaze tracking. /// </summary> /// <param name="gazeDevice"></param> private async void TryEnableGazeTrackingAsync(GazeDevicePreview gazeDevice) { // If eye-tracking device is ready, declare event handlers and start tracking. if (IsSupportedDevice(gazeDevice)) { timerGaze.Interval = new TimeSpan(0, 0, 0, 0, 20); timerGaze.Tick += TimerGaze_Tick; SetGazeTargetLocation(); // This must be called from the UI thread. gazeInputSource = GazeInputSourcePreview.GetForCurrentView(); gazeInputSource.GazeEntered += GazeEntered; gazeInputSource.GazeMoved += GazeMoved; gazeInputSource.GazeExited += GazeExited; } // Notify if device calibration required. else if (gazeDevice.ConfigurationState == GazeDeviceConfigurationStatePreview.UserCalibrationNeeded || gazeDevice.ConfigurationState == GazeDeviceConfigurationStatePreview.ScreenSetupNeeded) { // Device isn't calibrated, so invoke the calibration handler. System.Diagnostics.Debug.WriteLine( "Your device needs to calibrate. Please wait for it to finish."); await gazeDevice.RequestCalibrationAsync(); } // Notify if device calibration underway. else if (gazeDevice.ConfigurationState == GazeDeviceConfigurationStatePreview.Configuring) { // Device is currently undergoing calibration. // A device update is sent when calibration complete. System.Diagnostics.Debug.WriteLine( "Your device is being configured. Please wait for it to finish"); } // Device is not viable. else if (gazeDevice.ConfigurationState == GazeDeviceConfigurationStatePreview.Unknown) { // Notify if device is in unknown state. // Reconfigure/recalbirate the device. System.Diagnostics.Debug.WriteLine( "Your device is not ready. Please set up your device or reconfigure it."); } }
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); } } } }
private void InitializeGazeInputSource() { if (!_initialized) { if (_roots.Count != 0 && _devices.Count != 0) { if (_gazeInputSource == null) { _gazeInputSource = GazeInputSourcePreview.GetForCurrentView(); } if (_gazeInputSource != null) { _gazeInputSource.GazeEntered += OnGazeEntered; _gazeInputSource.GazeMoved += OnGazeMoved; _gazeInputSource.GazeExited += OnGazeExited; _initialized = true; } } } }
private GazePointer() { NonInvokeGazeTargetItem = new NonInvokeGazeTargetItem(); // Default to not filtering sample data Filter = new NullFilter(); _gazeCursor = new GazeCursor(); // timer that gets called back if there gaze samples haven't been received in a while _eyesOffTimer = new DispatcherTimer(); _eyesOffTimer.Tick += OnEyesOff; // provide a default of GAZE_IDLE_TIME microseconds to fire eyes off EyesOffDelay = GAZE_IDLE_TIME; InitializeHistogram(); _devices = new List <GazeDevicePreview>(); _watcher = GazeInputSourcePreview.CreateWatcher(); _watcher.Added += OnDeviceAdded; _watcher.Removed += OnDeviceRemoved; _watcher.Start(); }
// -------------------- 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(); }