Esempio n. 1
0
 public virtual GazeFilterArgs Update(GazeFilterArgs args)
 {
     if (_lastTimestamp == TimeSpan.Zero)
     {
         _lastTimestamp = args.Timestamp;
         _pointFilter   = new LowpassFilter(args.Location);
         _deltaFilter   = new LowpassFilter(default);
        private void ProcessGazePoint(TimeSpan timestamp, Point position)
        {
            var ea = new GazeFilterArgs(position, timestamp);

            var fa = Filter.Update(ea);

            _gazeCursor.Position = fa.Location;

            if (_gazeEventCount != 0)
            {
                _gazeEventArgs.Set(fa.Location, timestamp);
                _gazeEvent?.Invoke(this, _gazeEventArgs);
                if (_gazeEventArgs.Handled)
                {
                    return;
                }
            }

            var targetItem = ResolveHitTarget(fa.Location, fa.Timestamp);

            Debug.Assert(targetItem != null, "targetItem is null when processing gaze point");

            // Debug.WriteLine("ProcessGazePoint. [{0}, {1}], {2}", (int)fa.Location.X, (int)fa.Location.Y, fa.Timestamp);

            // check to see if any element in _hitTargetTimes needs an exit event fired.
            // this ensures that all exit events are fired before enter event
            CheckIfExiting(fa.Timestamp);

            PointerState nextState = (PointerState)((int)targetItem.ElementState + 1);

            // Debug.WriteLine(targetItem.TargetElement.ToString());
            // Debug.WriteLine("\tState={0}, Elapsed={1}, NextStateTime={2}", targetItem.ElementState, targetItem.ElapsedTime, targetItem.NextStateTime);
            if (targetItem.ElapsedTime > targetItem.NextStateTime)
            {
                var prevStateTime = targetItem.NextStateTime;
                ////Debug.WriteLine(prevStateTime);

                // prevent targetItem from ever actually transitioning into the DwellRepeat state so as
                // to continuously emit the DwellRepeat event
                if (nextState != PointerState.DwellRepeat)
                {
                    targetItem.ElementState = nextState;
                    nextState = (PointerState)((int)nextState + 1);     // nextState++
                    targetItem.NextStateTime += GetElementStateDelay(targetItem.TargetElement, nextState);

                    if (targetItem.ElementState == PointerState.Dwell)
                    {
                        targetItem.NextStateTime += GetElementStateDelay(targetItem.TargetElement, GazeInput.RepeatDelayDurationProperty, _defaultDwellRepeatDelay);
                    }
                }
                else
                {
                    // move the NextStateTime by one dwell period, while continuing to stay in Dwell state
                    targetItem.NextStateTime += GetElementStateDelay(targetItem.TargetElement, PointerState.DwellRepeat);
                }

                if (targetItem.ElementState == PointerState.Dwell)
                {
                    targetItem.RepeatCount++;
                    if (targetItem.MaxDwellRepeatCount < targetItem.RepeatCount)
                    {
                        targetItem.NextStateTime = new TimeSpan(long.MaxValue);
                    }
                }

                if (targetItem.ElementState == PointerState.Fixation)
                {
                    // Cache the fixated item
                    _currentlyFixatedElement = targetItem;

                    // We are about to transition into the Dwell state
                    // If switch input is enabled, make sure dwell never completes
                    // via eye gaze
                    if (IsSwitchEnabled)
                    {
                        // Don't allow the next state (Dwell) to progress
                        targetItem.NextStateTime = new TimeSpan(long.MaxValue);
                    }
                }

                RaiseGazePointerEvent(targetItem, targetItem.ElementState, targetItem.ElapsedTime);
            }

            targetItem.GiveFeedback();

            _eyesOffTimer.Start();
            _lastTimestamp = fa.Timestamp;
        }
 public virtual GazeFilterArgs Update(GazeFilterArgs args)
 {
     return(args);
 }