GazeDataProcessor.cs 2.48 KB
Newer Older
1 2 3 4 5 6 7
using System;
using System.Windows;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Tobii.Research;
8
using TrackerBridge.DSP;
9

10
namespace TrackerBridge
11
{
12
    public class GazeDataProcessor
13
    {
14 15 16 17 18 19 20 21 22
        public event GazeDataHandler GazeDataProcessed {
            add {
                gazeFilters[gazeFilters.Length - 1].OutputAvailable += value;
            }
            remove {
                gazeFilters[gazeFilters.Length - 1].OutputAvailable -= value;
            }
        }

23 24 25 26 27 28 29 30 31 32 33 34 35
        private readonly IGazeFilter[] gazeFilters;
        private readonly Single screenHeight;
        private readonly Single screenWidth;
        private Single outputFrequency;

        public Single OutputFrequency {
            get { return outputFrequency; }
            set {
                outputFrequency = value;
                Initialize();
            }
        }

36
        public GazeDataProcessor()
37
        {
38
            outputFrequency = 60; //Default
39 40
            screenHeight = Convert.ToSingle(SystemParameters.PrimaryScreenHeight);
            screenWidth = Convert.ToSingle(SystemParameters.PrimaryScreenWidth);
41
            gazeFilters = new IGazeFilter[1];
42
            gazeFilters[0] = new GazeDecimator(this); //TODO: Refactor frequency passthrough
43 44

            //Chain filters
45
            for(Int32 index= 0; index < gazeFilters.Length-1; index++)
46
            {
47
                gazeFilters[index].OutputAvailable += gazeFilters[index + 1].Input;
48 49 50
            }
        }

51 52 53 54
        public void Initialize()
        {
            foreach (IGazeFilter filter in gazeFilters)
            {
55
                filter.Update(this);
56 57
                filter.Reset();
            }
58
        }
59 60
        
        public void Process(Object sender, GazeDataEventArgs e)
61
        {
62 63 64 65
            GazeData data = new GazeData(e.LeftEye.GazePoint.PositionOnDisplayArea.X * screenWidth,
                                         e.LeftEye.GazePoint.PositionOnDisplayArea.Y * screenHeight,
                                         e.RightEye.GazePoint.PositionOnDisplayArea.X * screenWidth,
                                         e.RightEye.GazePoint.PositionOnDisplayArea.Y * screenHeight,
66 67
                                         e.DeviceTimeStamp,
                                         e.SystemTimeStamp);
68 69

            gazeFilters[0].Input(data);
70 71 72 73
        }
        public void Process(Object sender, GazeData input)
        {
            gazeFilters[0].Input(input);
74
        }
75 76
    }
}