/// <summary>
        ///     Initializes a new instance of the <see cref="GazeSelectionService" /> class.
        /// </summary>
        /// <param name="eventAggregator">Provides pub/sub events (obtained through DI).</param>
        public GazeSelectionService(IEventAggregator eventAggregator)
        {
            this.timedPoints     = new TimedPoints(Configuration.PointKeepAliveTimeSpan);
            this.averagingFilter = new AveragingLastNpointsWithinTimeSpanFilter(3, TimeSpan.FromMilliseconds(75));
            this.dataPerControl  = new ConcurrentDictionary <SelectableControl, ISelectableControlViewModel>();
            this.KnownWindows.Add(Application.Current.MainWindow);

            eventAggregator.GetEvent <Events.NewCoordinateEvent>().Subscribe(this.ProcessPoint);
            Application.Current.MainWindow.Closing +=
                (sender, args) => eventAggregator.GetEvent <Events.NewCoordinateEvent>().Unsubscribe(this.ProcessPoint);
        }
        /// <summary>
        ///     Filters the specified timed points.
        /// </summary>
        /// <param name="timedPoints">The timed points.</param>
        /// <returns>
        ///     An average of the last N points (as long as they fall within a given timespan from <see cref="DateTime.Now" />).
        /// </returns>
        public override Point?Filter(TimedPoints timedPoints)
        {
            if (timedPoints == null)
            {
                return(null);
            }

            var withinTimeSpan = timedPoints.Where(pair => DateTime.Now - pair.Key <= this.timeSpan).ToList();

            if (withinTimeSpan.Count < this.numberOfPoints)
            {
                return(null);
            }

            var pointsToAverage = withinTimeSpan.OrderByDescending(pair => pair.Key).Take(this.numberOfPoints).ToList();
            var averageX        = pointsToAverage.Select(pair => pair.Value.X).Average();
            var averageY        = pointsToAverage.Select(pair => pair.Value.Y).Average();

            return(new Point(averageX, averageY));
        }
Ejemplo n.º 3
0
 /// <summary>
 ///     Filters the specified timed points.
 /// </summary>
 /// <param name="timedPoints">The timed points.</param>
 /// <returns>
 ///     An average of the points. The actual average depends on implementation (e.g. it could be an average of the
 ///     last 5 points, or of the 10 points nearest to the last in a given timespan)
 /// </returns>
 public abstract Point?Filter(TimedPoints timedPoints);