Exemplo n.º 1
0
 private static void CreateAndVisualizeSensitiveFilteredFixationsStream()
 {
     _fixationDataStream = _host.Streams.CreateFixationDataStream();
     _fixationDataStream
     .Begin((x, y, _) =>
     {
         Console.WriteLine("\n" +
                           "Fixation started at X: {0}, Y: {1}", x, y);
         _fixationBeginTime = DateTime.Now;
     })
     .Data((x, y, _) =>
     {
         Console.WriteLine("During fixation, currently at: X: {0}, Y: {1}", x, y);
     })
     .End((x, y, _) =>
     {
         Console.WriteLine("Fixation ended at X: {0}, Y: {1}", x, y);
         if (_fixationBeginTime != default(DateTime))
         {
             Console.ForegroundColor = ConsoleColor.Cyan;
             Console.WriteLine("Fixation duration: {0}", DateTime.Now - _fixationBeginTime);
             Console.ForegroundColor = _defaultForegroundColor;
         }
     });
 }
Exemplo n.º 2
0
 public void StartGazeDataStreams(GazePointCallback gazePointCallback, FixationCallback fixationCallback, EyePositionCallback eyePositionCallback)
 {
     if (gazePointCallback != null)
     {
         if (gazePointDataStream == null)
         {
             gazePointDataStream = eyeXHost.CreateGazePointDataStream(Tobii.EyeX.Framework.GazePointDataMode.Unfiltered);
         }
         gazePointDataStream.Next += InvokeGazePointEvent;
         GazePointEvent           += gazePointCallback;
         GazePointEvent           += RecordGazePoint;
     }
     if (fixationCallback != null)
     {
         if (fixationDataStream == null)
         {
             fixationDataStream = eyeXHost.CreateFixationDataStream(FixationDataMode.Sensitive);
         }
         fixationDataStream.Next += InvokeFixationEvent;
         FixationEvent           += fixationCallback;
         FixationEvent           += RecordFixation;
     }
     if (eyePositionCallback != null)
     {
         if (eyePositionDataStream == null)
         {
             eyePositionDataStream = eyeXHost.CreateEyePositionDataStream();
         }
         eyePositionDataStream.Next += InvokeEyePositionEvent;
         EyePositionEvent           += eyePositionCallback;
         EyePositionEvent           += RecordEyePosition;
     }
 }
Exemplo n.º 3
0
 //starts a fixation data stream (class constructor)
 public _Tobii()
 {
     //create connection to Tobii Eyetracker
     _host = new Host();
     _fixationDataStream  = _host.Streams.CreateFixationDataStream();
     _gazePointDataStream = _host.Streams.CreateGazePointDataStream();
 }
Exemplo n.º 4
0
 public TobiiAgentAnalyzer(object host)
 {
     //m_FixationBeginWithoutEnd = false;
     m_SentForRecognition = false;
     this.m_host          = new Host();
     m_Stream             = m_host.Streams.CreateFixationDataStream(FixationDataMode.Sensitive, true);
 }
Exemplo n.º 5
0
Arquivo: Gaze.cs Projeto: feugy/alfred
        /// <summary>
        /// Detect EyeX engine presence, and starts it to get gaze positions
        /// </summary>
        /// <param name="fps">Number of gaze positions expected per second</param>
        /// <exception cref="Exception">If EyeX engine is not installed or running</exception>
        public Gaze(int fps)
        {
            this.interpolated = duration * fps / 1000;
            this.Position     = Cursor.Position;
            positions         = new Queue <Point>(interpolated);

            // simple check of EyeX presence
            switch (EyeXHost.EyeXAvailability)
            {
            case EyeXAvailability.NotAvailable:
                throw new Exception("Please install the EyeX Engine");

            case EyeXAvailability.NotRunning:
                throw new Exception("Please make sure that the EyeX Engine is started");
            }

            Engine = new EyeXHost();
            // track display size
            Engine.ScreenBoundsChanged += (object s, EngineStateValue <Rect> e) => displaySize = e.Value;;
            // track gaze position to set cursor on it
            gazeStream       = Engine.CreateFixationDataStream(FixationDataMode.Sensitive);
            gazeStream.Next += OnGazeChange;
            // start the EyeX engine
            Engine.Start();
            displaySize = Engine.ScreenBounds.Value;

            // start timer
            timer          = new System.Timers.Timer(duration / interpolated);
            timer.Enabled  = true;
            timer.Elapsed += OnTick;
        }
Exemplo n.º 6
0
        /*************************EYE_X_COMPONENT.INIT********************/

        /*
         * Receive method for the EyeX gaze data stream.
         */
        private void ReceiveGazeData(Envelope e)
        {
            using (gazeDataStream = host.CreateGazePointDataStream(GazePointDataMode.LightlyFiltered))
            {
                Console.WriteLine("EyeX data stream initiated.");

                gazePoint.Post(gazeDataStream, e.OriginatingTime);

                using (eyePositionStream = host.CreateEyePositionDataStream())
                {
                    Console.WriteLine("EyeX eye position stream initiated.");

                    eyeData.Post(eyePositionStream, e.OriginatingTime);

                    gazeDataStream.Next += (s, q) =>
                    {
                        frameDataX = q.X;
                        frameDataY = q.Y;
                    };

                    eyePositionStream.Next += (s, q) =>
                    {
                        leftEyeX = q.LeftEye.X;
                        leftEyeY = q.LeftEye.Y;
                        leftEyeZ = q.LeftEye.Z;

                        leftEyeNormalizedX = q.LeftEyeNormalized.X;
                        leftEyeNormalizedY = q.LeftEyeNormalized.Y;
                        leftEyeNormalizedZ = q.LeftEyeNormalized.Z;

                        rightEyeX = q.RightEye.X;
                        rightEyeY = q.RightEye.Y;
                        rightEyeZ = q.RightEye.Z;

                        rightEyeNormalizedX = q.RightEyeNormalized.X;
                        rightEyeNormalizedY = q.RightEyeNormalized.Y;
                        rightEyeNormalizedZ = q.RightEyeNormalized.Z;
                    };

                    Console.WriteLine("Listening for gaze data...");

                    using (FixationDataStream fixationStream = host.CreateFixationDataStream(FixationDataMode.Sensitive))
                    {
                        fixationData.Post(fixationStream, e.OriginatingTime);

                        fixationStream.Next += (s, q) =>
                        {
                            fixationX = q.X;
                            fixationY = q.Y;
                        };

                        Console.WriteLine("Recording fixation points...");
                        Console.In.Read();
                    }
                }
            }
        }
Exemplo n.º 7
0
 private static void CreateAndVisualizeSlowFilteredFixationsStream()
 {
     if (_fixationDataStream != null)
     {
         _fixationDataStream.Next -= OnNextFixation;
     }
     _fixationDataStream       = _host.Streams.CreateFixationDataStream(FixationDataMode.Slow);
     _fixationDataStream.Next += OnNextFixation;
 }
Exemplo n.º 8
0
 public Form1()
 {
     eyeXHost.Start();
     fixation = eyeXHost.CreateFixationDataStream(FixationDataMode.Slow);
     InitializeComponent();
     pictureBox1.ImageLocation = @"..\a.png";
     pictureBox3.ImageLocation = @"..\c.png";
     pictureBox2.ImageLocation = @"..\b.png";
     fixation.Next            += fixationEventHandler;
 }
Exemplo n.º 9
0
        private void CollectData()
        {
            double previousTime = GetUnixTimestampForNow();
            double elapsedTime  = 0;

            double startTime = 0;
            double endTime   = 0;

            int numFixations = 0;

            double lastFixationStartTime      = 0;
            double fixationLengthRunningTotal = 0;

            // Increment the number of fixations each time we receive data from the eye tracker.
            fixationDataStream = eyeXHost.CreateFixationDataStream(FixationDataMode.Sensitive);
            System.EventHandler <FixationEventArgs> inc = delegate(object s, FixationEventArgs e) {
                if (e.EventType == FixationDataEventType.Begin)
                {
                    numFixations++;
                    lastFixationStartTime = e.Timestamp;
                }
                if (e.EventType == FixationDataEventType.End)
                {
                    fixationLengthRunningTotal += e.Timestamp - lastFixationStartTime;
                }
            };

            fixationDataStream.Next += inc;

            // Keep collecting the data until we tell it not to.
            while (!shouldEndCollection)
            {
                if (elapsedTime < instanceLength)
                {
                    elapsedTime += GetUnixTimestampForNow() - previousTime;
                    previousTime = GetUnixTimestampForNow();
                }
                else
                {
                    endTime = GetUnixTimestampForNow();
                    double fixationsPerSecond   = numFixations / (instanceLength / 1000);
                    double meanLengthOfFixation = fixationLengthRunningTotal / numFixations;

                    Instance instance = new Instance(startTime, endTime, numFixations, fixationsPerSecond, meanLengthOfFixation, instanceClass);
                    collectedInstances.Add(instance);

                    startTime    = GetUnixTimestampForNow();
                    numFixations = 0;
                    fixationLengthRunningTotal = 0;

                    elapsedTime  = 0;
                    previousTime = GetUnixTimestampForNow();
                }
            }
        }
Exemplo n.º 10
0
        public GazeHandler()
        {
            _host = new Host();
            _wpfInteractorAgent = _host.InitializeWpfAgent();

            _gazePointDataStream = _host.Streams.CreateGazePointDataStream();
            _fixationDataStream  = _host.Streams.CreateFixationDataStream();

            _fixationDataStream.Subscribe(this);
            _gazePointDataStream.Subscribe(this);
        }
Exemplo n.º 11
0
 private static void SetupStream()
 {
     host   = new Host();
     stream = host.Streams.CreateFixationDataStream(FixationDataMode.Slow);
     stream.Data(
         (x, y, ts) =>
     {
         currentGazePoint.X = (int)Math.Round(x);
         currentGazePoint.Y = (int)Math.Round(y);
     });
 }
Exemplo n.º 12
0
 public EyeTrackingHandler(Gecko.GeckoWebBrowser b, TransparentPanel scroll, Keyboard keys, FavoritesPanel favorites, Button click, Panel close)
 {
     host           = new Host();
     fixationStream = host.Streams.CreateFixationDataStream(FixationDataMode.Slow);
     HandleFixation();
     acceptClick           = true;
     circleCenter          = new Point(1, 1);
     zooming               = false;
     zoomingExecution      = false;
     freePointingExecution = false;
     pointedPosition       = new Point(1, 1);
     browser               = b;
     browserX              = browser.Location.X;
     width              = browserX + browser.Width;
     browserY           = browser.Location.Y;
     height             = browserY + browser.Height;
     clickButton        = click;
     scrollPanel        = scroll;
     keyboardPanel      = keys;
     closePanel         = close;
     favoritesPanel     = favorites;
     firstPointedX      = 0;
     firstPointedY      = 0;
     pointedX           = 0;
     pointedY           = 0;
     fixationCounter    = 0;
     requiredSamplings  = 120;
     radiusLimit        = 150;
     zoomingSamplings   = 30;
     scrollingSamplings = 10;
     settingsPath       = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "EyeBrowserTimingPreferences.txt");
     if (File.Exists(settingsPath))
     {
         using (StreamReader reader = new StreamReader(settingsPath))
         {
             requiredSamplings  = Int32.Parse(reader.ReadLine());
             radiusLimit        = Int32.Parse(reader.ReadLine());
             zoomingSamplings   = Int32.Parse(reader.ReadLine());
             scrollingSamplings = Int32.Parse(reader.ReadLine());
         }
     }
     else
     {
         using (StreamWriter writer = new StreamWriter(settingsPath, false))
         {
             writer.WriteLine(requiredSamplings);
             writer.WriteLine(radiusLimit);
             writer.WriteLine(zoomingSamplings);
             writer.WriteLine(scrollingSamplings);
         }
     }
 }
Exemplo n.º 13
0
 public Form1()
 {
     eyeXHost.Start();
     fixation = eyeXHost.CreateFixationDataStream(FixationDataMode.Slow);
     InitializeComponent();
     comboBox1.SelectedItem = comboBox1.Items[0];
     s.SelectVoice("Microsoft Zira Desktop");
     //bmp = new Bitmap(500, 500);
     //using (Graphics g = Graphics.FromImage(bmp))
     //{
     //    g.Clear(Color.White);
     //}
 }
Exemplo n.º 14
0
 public void StopAllGazeDataStream()
 {
     SetGazeDataRecording(false, false, false);
     GazePointEvent = null;
     gazePointDataStream.Dispose();
     gazePointDataStream = null;
     FixationEvent       = null;
     fixationDataStream.Dispose();
     fixationDataStream = null;
     EyePositionEvent   = null;
     eyePositionDataStream.Dispose();
     eyePositionDataStream = null;
 }
Exemplo n.º 15
0
            protected override void OnOpen()
            {
                PrintSampleIntroText();

                // Everything starts with initializing Host, which manages the connection to the
                // Tobii Engine and provides all the Tobii Core SDK functionality.
                // NOTE: Make sure that Tobii.EyeX.exe is running
                host = new Host();

                // Initialize Fixation data stream.
                fixationDataStream = host.Streams.CreateFixationDataStream();

                // Because timestamp of fixation events is relative to the previous ones
                // only, we will store them in this variable.
                var fixationBeginTime = 0d;

                fixationDataStream.Next += (o, fixation) =>
                {
                    // On the Next event, data comes as FixationData objects, wrapped in a StreamData<T> object.
                    var fixationPointX = fixation.Data.X;
                    var fixationPointY = fixation.Data.Y;

                    switch (fixation.Data.EventType)
                    {
                    case FixationDataEventType.Begin:
                        fixationBeginTime = fixation.Data.Timestamp;
                        string beginString = string.Format("begin|{0}|{1}", fixationPointX, fixationPointY);
                        Send(beginString);
                        break;

                    case FixationDataEventType.Data:
                        string duringString = string.Format("during|{0}|{1}", fixationPointX, fixationPointY);
                        Send(duringString);
                        break;

                    case FixationDataEventType.End:
                        string endString = string.Format("end|{0}|{1}", fixationPointX, fixationPointY);
                        Send(endString);
                        string fixString = string.Format("duration|{0}|null",
                                                         fixationBeginTime > 0
                                    ? TimeSpan.FromMilliseconds(fixation.Data.Timestamp - fixationBeginTime)
                                    : TimeSpan.Zero);
                        Send(fixString);
                        break;

                    default:
                        throw new InvalidOperationException("Unknown fixation event type, which doesn't have explicit handling.");
                    }
                };
            }
        private void StartButton_Click(object sender, EventArgs e)
        {
            StartOverButton_Click(sender, e);
            fsFIX   = new FileStream(@"C: \Users\CTS\Desktop\testFIX.txt", FileMode.Create, FileAccess.Write);
            fsSAC   = new FileStream(@"C: \Users\CTS\Desktop\testSAC.txt", FileMode.Create, FileAccess.Write);
            swFIX   = new StreamWriter(fsFIX);
            swSAC   = new StreamWriter(fsSAC);
            hostFIX = new Host();
            hostSAC = new Host();

            fixationDataStream  = hostFIX.Streams.CreateFixationDataStream(Tobii.Interaction.Framework.FixationDataMode.Slow);
            gazePointDataStream = hostSAC.Streams.CreateGazePointDataStream();

            fixationDataStream.Data((x, y, timestamp) => addToTXTFIX(x, y, timestamp));
            gazePointDataStream.GazePoint((x, y, ts) => addToTXTSAC(x, y, ts));
        }
Exemplo n.º 17
0
        public void Connect()
        {
            if (!_isConnected)
            {
                _TobiiHost.EnableConnection();
                _TobiiWPFAgent = _TobiiHost.InitializeWpfAgent();

                _GazePointDataStream       = _TobiiHost.Streams.CreateGazePointDataStream(Tobii.Interaction.Framework.GazePointDataMode.Unfiltered);
                _GazePointDataStream.Next += OnGazePointData;
                _FixationDataStream        = _TobiiHost.Streams.CreateFixationDataStream();
                _FixationDataStream.Next  += OnFixationData;
                _EyePositionStream         = _TobiiHost.Streams.CreateEyePositionStream(true);
                _EyePositionStream.Next   += OnEyePositionData;
                _isConnected = true;
            }
        }
Exemplo n.º 18
0
        public static void Main(string[] args)
        {
            // create host stream for Tobii
            _host = new Host();

            // _gazePointDataStream = _host.Streams.CreateGazePointDataStream();
            _fixationDataStream = _host.Streams.CreateFixationDataStream();

            // set params to save streams on file
            string gaze_path = "gazeStream.csv";
            string fixs_path = "fixationStream.csv";


            // call for save on file function
            stream_read_write(path_to_py, gaze_path, fixs_path);


            Console.Write("----------------------------------------------------------------------------------------------------");
            Console.ReadKey();
        }
Exemplo n.º 19
0
        public static void Capture()
        {
            try
            {
                // Initializes Eyetracker.
                EyeXHost eyeXHost = new EyeXHost();
                eyeXHost.Start();
                FixationDataStream lightlyFilteredGazeDataStream = eyeXHost.CreateFixationDataStream(FixationDataMode.Slow);
                lightlyFilteredGazeDataStream.Next += lightlyFilteredGazeDataStream_Next;
                _eyeXhost = eyeXHost;

                // Timer which checks URL every 0.1s
                Timer t = new Timer();
                t.Interval = 100;
                t.Elapsed += CheckUrl;

                // Starting URL. CHANGE IT HERE IF NEEDED.
                string url = "http://panache.fr/";
                //string url = "http://www.fmf.uni-lj.si/si/";
                //string url = "http://stackoverflow.com/questions/21555394/how-to-create-bitmap-from-byte-array";

                /* Creates new visible ChromeDriver, maximizes the browser window, navigates to the starting URL
                 * and starts the "check url" timer. CHANGE THE PATH TO THE DRIVER HERE IF NEEDED.
                 */
                driver = new ChromeDriver("D:\\IJS\\EyeTracker");
                driver.Manage().Window.Maximize();
                driver.Navigate().GoToUrl(url);
                t.Start();
                lastUrl = url;

                Console.ReadKey();
            }
            finally
            {
                // Dispose the driver if the above code fails.
                if (driver != null)
                {
                    driver.Dispose();
                }
            }
        }
Exemplo n.º 20
0
 // KeyPress event
 private void TrialForm_KeyPress(object sender, KeyPressEventArgs e)
 {
     if (e.KeyChar == (char)Keys.Escape)
     {
         StopTrials();
     }
     else if (e.KeyChar == (char)Keys.Space && trialState == 0)
     {
         if (true) //if (gazeCentered())
         {
             //Launch trials thread
             trialsThread = new Thread(new ThreadStart(TrialsRunningThread))
             {
                 IsBackground = true
             };
             trialsThread.Start();
             //Init tobbi gaze
             fixationDataStream = MainForm.tobii4C.Streams.CreateFixationDataStream();
             fixationDataStream.Begin((x, y, timestamp) =>
             {
                 if (x != 0)
                 {
                     currentFixation           = new Fixation();
                     currentFixation.x         = x;
                     currentFixation.y         = y;
                     currentFixation.timestamp = timestamp;
                 }
             });
             fixationDataStream.End((x, y, timestamp) =>
             {
                 currentFixation.timespan = timestamp;
                 trialFixations.Add(currentFixation);
             });
         }
         else
         {
             synth.SpeakAsync(fixCenterMsg);
         }
     }
 }
        public DeviceInteractionHost()
        {
            MainWindow _mainWindow = (MainWindow)Application.Current.MainWindow;

            //Device
            _host = new Host();

            //init tobii streams
            _fixationDataStream = _host.Streams.CreateFixationDataStream();
            //_fixationDataStream = _host.Streams.CreateFixationDataStream(Tobii.Interaction.Framework.FixationDataMode.Slow);
            _gazePointDataStream = _host.Streams.CreateGazePointDataStream();

            lsloffset = _mainWindow.stopwatch.ElapsedMilliseconds - liblsl.local_clock() * 1000;

            _lslDevices = new List <LSLDevice>();


            _tasks = new List <Task>();

            _source = new CancellationTokenSource();
            _token  = _source.Token;

            _mre = new ManualResetEvent(false);
        }
Exemplo n.º 22
0
        public void StartServer()
        {
            this.eyeXHost = new EyeXHost();
            this.eyeXHost.Start();
            this.gazeDataStream = eyeXHost.CreateGazePointDataStream(GazePointDataMode.LightlyFiltered);
            this.gazeDataStream.Next += new System.EventHandler<EyeXFramework.GazePointEventArgs>(this.HandleEyeGazeEvent);

            this.fixationDataStream = eyeXHost.CreateFixationDataStream(FixationDataMode.Slow);
            this.fixationDataStream.Next += new System.EventHandler<EyeXFramework.FixationEventArgs>(this.HandleEyeFixationEvent);

            try
            {
                IPAddress ipAddr = IPAddress.Parse(host);
                tcpServer = new TcpClient();
                tcpServer.Connect(ipAddr, port);
                swSender = new StreamWriter(tcpServer.GetStream());
            }
            catch
            {
                this.StopServer();
            }
        }
Exemplo n.º 23
0
 public TobiiAgentAnalyzer()
 {
     this.sentForRecognition = false;
     this.host   = new Host();
     this.stream = host.Streams.CreateFixationDataStream();
 }
Exemplo n.º 24
0
 /// <summary>
 /// Gets a fixation data stream.
 /// </summary>
 /// <param name="mode">Specifies the kind of data processing to be applied by the EyeX Engine.</param>
 /// <returns>The data stream.</returns>
 public FixationDataStream CreateFixationDataStream(FixationDataMode mode)
 {
     var dataStream = new FixationDataStream(mode);
     RegisterDataStreamObserver(dataStream);
     return dataStream;
 }