Пример #1
0
        public void GazeDataThreadProc()
        {
            while (!_terminating)
            {
                EyeTrackingController.SampleStruct sampleData = new EyeTrackingController.SampleStruct();
                if (_eyeTracker.iV_GetSample(ref sampleData) != (int)EyeTrackingController.RetCode.Success)
                {
                    Thread.Sleep(_sleepTime);
                    continue;
                }

                EventHandler <GazeEventArgs> handler = GazeEvent;
                if (handler != null)
                {
                    GazeEventArgs gazeEventArgs = new GazeEventArgs(sampleData.leftEye.gazeX,
                                                                    sampleData.leftEye.gazeY,
                                                                    sampleData.timestamp / 1000,
                                                                    Fixation.Unknown,
                                                                    false);
                    handler(this, gazeEventArgs);
                }

                Thread.Sleep(_sleepTime);
            }
        }
Пример #2
0
        private void OnEyeTrackerGazeData(object sender, GazeDataEventArgs e)
        {
            EventHandler <GazeEventArgs> handler = GazeEvent;

            if (handler != null)
            {
                Point2D gazePoint;
                var     gazeData = e.GazeData;

                switch (gazeData.TrackingStatus)
                {
                case TrackingStatus.BothEyesTracked:
                    gazePoint = new Point2D((gazeData.Left.GazePointOnDisplayNormalized.X + gazeData.Right.GazePointOnDisplayNormalized.X) / 2.0,
                                            (gazeData.Left.GazePointOnDisplayNormalized.Y + gazeData.Right.GazePointOnDisplayNormalized.Y) / 2.0);
                    break;

                case TrackingStatus.OnlyLeftEyeTracked:
                case TrackingStatus.OneEyeTrackedProbablyLeft:
                    gazePoint = gazeData.Left.GazePointOnDisplayNormalized;
                    break;

                case TrackingStatus.OnlyRightEyeTracked:
                case TrackingStatus.OneEyeTrackedProbablyRight:
                    gazePoint = gazeData.Right.GazePointOnDisplayNormalized;
                    break;

                default:
                    return;
                }

                GazeEventArgs gazeEventArgs = new GazeEventArgs(gazePoint.X, gazePoint.Y, gazeData.Timestamp / 1000, Fixation.Unknown, true);
                handler(this, gazeEventArgs);
            }
        }
Пример #3
0
        private void GazeDataReaderProc()
        {
            string        line         = null;
            GazeEventArgs ea           = null;
            long          curTimeStamp = 0;

            line = _gazeDataReader.ReadLine();
            if (line != null)
            {
                ea = ParseGazeEventArgs(line);
                if (ea != null)
                {
                    curTimeStamp = ea.Timestamp;
                }
            }

            Thread.Sleep(2000);
            RaiseGazeEvent(ea);

            while ((!_terminating) && ((line = _gazeDataReader.ReadLine()) != null))
            {
                ea = ParseGazeEventArgs(line);
                if (ea == null)
                {
                    continue;
                }

                Thread.Sleep((int)(ea.Timestamp - curTimeStamp));
                curTimeStamp = ea.Timestamp;
                RaiseGazeEvent(ea);
            }
        }
Пример #4
0
        public void dataCallback(
            long timestamp,
            float mouseX,
            float mouseY,
            float mouseRawX,
            float pogRawY,
            int screenWidth,
            int screenHeight,
            [MarshalAs(UnmanagedType.U1)] bool leftEyeDetected,
            [MarshalAs(UnmanagedType.U1)] bool rightEyeDetected,
            int imageWidth,
            int imageHeight,
            float leftEyeX,
            float leftEyeY,
            float leftEyeSize,
            float rightEyeX,
            float rightEyeY,
            float rightEyeSize,
            float distanceFactor)
        {
            var eventData = new GazeEventArgs(
                mouseX,
                mouseY,
                Environment.TickCount, Fixation.Unknown, false);

            _gazeEvent?.Invoke(this, eventData);
        }
Пример #5
0
        private void RaiseGazeEvent(GazeEventArgs ea)
        {
            EventHandler <GazeEventArgs> handler = GazeEvent;

            if (handler != null)
            {
                handler(this, ea);
            }
        }
Пример #6
0
        void RaiseGazeEvent(double x, double y, double timestamp)
        {
            EventHandler <GazeEventArgs> handler = GazeEvent;

            if (handler != null)
            {
                GazeEventArgs gazeEventArgs = new GazeEventArgs(x, y, (long)timestamp, Fixation.Unknown, false);
                handler(this, gazeEventArgs);
            }
        }
Пример #7
0
        private GazeEventArgs ParseGazeEventArgs(string line)
        {
            string[] parts = line.Split(',');
            if (parts.Length != 3)
            {
                return(null);
            }

            double x = double.Parse(parts[0]);
            double y = double.Parse(parts[1]);
            long   t = long.Parse(parts[2]);

            GazeEventArgs ea = new GazeEventArgs(x, y, t, Fixation.Unknown, true);

            return(ea);
        }
Пример #8
0
        void MouseTick(object sender, EventArgs e)
        {
            try
            {
                var window      = Application.Current.MainWindow;
                var windowPoint = Mouse.GetPosition(window);
                var point       = window.PointToScreen(windowPoint);

                var eventData = new GazeEventArgs(point.X, point.Y, Environment.TickCount, Fixation.Unknown, false);

                _gazeEvent?.Invoke(this, eventData);
            }
            catch
            {
                // A Win32Exception is sometimes thrown Mouse.GetPosition; this try-catch block just lessens the impact of that.
            }
        }
Пример #9
0
        void Tick(object sender, EventArgs e)
        {
            try
            {
                QuickLink2API.QLDevice_GetFrame(deviceId, (IntPtr)10000, ref frameData);
                if (frameData.WeightedGazePoint.Valid)
                {
                    var eventData = new GazeEventArgs(
                        frameData.WeightedGazePoint.x * System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width / 100,
                        frameData.WeightedGazePoint.y * System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height / 100,
                        Environment.TickCount,
                        Fixation.Unknown,
                        false
                        );

                    _gazeEvent?.Invoke(this, eventData);
                }
            }
            catch
            {
                // A Win32Exception is sometimes thrown Mouse.GetPosition; this try-catch block just lessens the impact of that.
            }
        }
 public GazeEventArgs(double x, double y, GazeEventArgs ea, bool scaled) :
     this(x, y, ea.Timestamp, ea.Fixation, scaled)
 {
 }