Пример #1
0
    /// <summary>
    /// The <see cref="ITracker.GazeDataChanged"/> event handler.
    ///   Calculates the new sampling data from the trackers format.
    ///   Updates the live viewers cursors and send a
    ///   <see cref="NewRawDataAvailable"/> message to write the
    ///   data into the database.
    /// </summary>
    /// <param name="sender">
    /// Source of the event.
    /// </param>
    /// <param name="e">
    /// A <see cref="GazeDataChangedEventArgs"/> with the event data.
    /// </param>
    public void TrackerGazeDataChanged(object sender, GazeDataChangedEventArgs e)
    {
      // Save current timestamp
      lock (this.timeLock)
      {
        this.lastTimeStamp = e.Gazedata.Time;
      }

      if (this.currentTrial == null)
      {
        return;
      }

      // Create a new RawData object
      var newRawData = new RawData
                         {
                           SubjectName = this.currentTracker.Subject.SubjectName,
                           GazePosX = e.Gazedata.GazePosX,
                           GazePosY = e.Gazedata.GazePosY
                         };

      newRawData = ModifyGazeDataWhenBetweenZeroAndOne(newRawData);

      newRawData.PupilDiaX = e.Gazedata.PupilDiaX;
      newRawData.PupilDiaY = e.Gazedata.PupilDiaY;

      long gazeTime = e.Gazedata.Time - this.recordingStarttime;
      newRawData.Time = gazeTime;
      newRawData.TrialSequence = this.trialSequenceCounter;

      // Retrieve mouse position, this is already in SCREEN COORDINATES
      PointF? newMousePos = this.GetMousePosition();
      if (this.currentSlide.MouseCursorVisible && newMousePos != null)
      {
        newRawData.MousePosX = newMousePos.Value.X + this.xScrollOffset;
        newRawData.MousePosY = newMousePos.Value.Y + this.yScrollOffset;
      }

      // Update gaze cursor with reduced update rate
      // if (_counter % REDUCING_COUNT == 0)
      if (newRawData.GazePosX != null && newRawData.GazePosY != null)
      {
        var newCursorPos = new PointF(newRawData.GazePosX.Value, newRawData.GazePosY.Value);

        if (this.smoothing)
        {
          if (this.PointsArNear(newCursorPos, this.currentGazeCursorCenter))
          {
            this.numberOfSamplesInRegion++;
            this.sumOfSamplesInRegion.X += newCursorPos.X;
            this.sumOfSamplesInRegion.Y += newCursorPos.Y;
            this.currentGazeCursorCenter.X = this.sumOfSamplesInRegion.X / this.numberOfSamplesInRegion;
            this.currentGazeCursorCenter.Y = this.sumOfSamplesInRegion.Y / this.numberOfSamplesInRegion;
          }
          else
          {
            this.numberOfSamplesInRegion = 0;
            this.sumOfSamplesInRegion = PointF.Empty;
            this.currentGazeCursorCenter = newCursorPos;
          }
        }
        else
        {
          this.currentGazeCursorCenter = newCursorPos;
        }
      }

      // Update mouse cursor with reduced update rate
      // if (_counter % REDUCING_COUNT == 0)
      {
        if (this.systemHasSecondaryScreen || this.forcePanelViewerUpdate)
        {
          if (newRawData.MousePosX.HasValue && newRawData.MousePosY.HasValue)
          {
            this.currentMouseCursorCenter = new PointF(newRawData.MousePosX.Value, newRawData.MousePosY.Value);
          }
        }
      }

      if (!this.currentSlide.IsDisabled)
      {
        this.OnNewRawDataAvailable(new NewRawDataAvailableEventArgs(newRawData));
      }
    }
Пример #2
0
    /// <summary>
    /// The
    ///   <see cref="GTNetworkClient.GazeData.OnGazeData"/> event handler
    ///   which is called whenever there is a new frame arrived.
    ///   Sends the GazeDataChanged event to the recording module.
    /// </summary>
    /// <param name="sender">
    /// The sender.
    /// </param>
    /// <param name="e">
    /// The <see cref="GazeDataChangedEventArgs"/> instance containing the event data.
    /// </param>
    private void GazeDataReceived(object sender, GazeDataChangedEventArgs e)
    {
      this.clientStatus = this.clientStatus | HaythamStatus.IsStreaming;

      if (e.Gazedata.GazePosX != null && e.Gazedata.GazePosY != null)
      {
        this.lastGazedataString = string.Format(
          "Receiving gaze data: {0}Time: {1} {2} X: {3}, Y: {4} {5} Pupil: {6}",
          Environment.NewLine,
          e.Gazedata.Time.ToString("N0"),
          Environment.NewLine,
          e.Gazedata.GazePosX.Value.ToString("N0"),
          e.Gazedata.GazePosY.Value.ToString("N0"),
          Environment.NewLine,
          e.Gazedata.PupilDiaX);
      }

      if (this.shouldSendGazeSamples)
      {
        this.lastTime = e.Gazedata.Time;
        this.OnGazeDataChanged(e);
      }
    }
Пример #3
0
 /// <summary>
 /// The OnGazeDataReceived method raises the event by invoking
 ///   the delegates. The sender is always this, the current instance
 ///   of the class.
 /// </summary>
 /// <param name="e">
 /// An empty <see cref="EventArgs"/>
 /// </param>
 private void OnGazeDataReceived(GazeDataChangedEventArgs e)
 {
   // Invokes the delegates. 
   if (this.GazeDataReceived != null)
   {
     this.GazeDataReceived(this, e);
   }
 }
Пример #4
0
    ///////////////////////////////////////////////////////////////////////////////
    // Inherited methods                                                         //
    ///////////////////////////////////////////////////////////////////////////////
    #region OVERRIDES
    #endregion //OVERRIDES

    ///////////////////////////////////////////////////////////////////////////////
    // Eventhandler                                                              //
    ///////////////////////////////////////////////////////////////////////////////
    #region EVENTS

    ///////////////////////////////////////////////////////////////////////////////
    // Eventhandler for UI, Menu, Buttons, Toolbars etc.                         //
    ///////////////////////////////////////////////////////////////////////////////
    #region WINDOWSEVENTHANDLER
    #endregion //WINDOWSEVENTHANDLER

    ///////////////////////////////////////////////////////////////////////////////
    // Eventhandler for Custom Defined Events                                    //
    ///////////////////////////////////////////////////////////////////////////////
    #region CUSTOMEVENTHANDLER

    /// <summary>
    /// Raised when new gaze data is available.
    /// </summary>
    /// <param name="e"><see cref="GazeDataChangedEventArgs"/> event arguments</param>.
    private void OnGazeDataChanged(GazeDataChangedEventArgs e)
    {
      if (this.GazeDataChanged != null)
      {
        this.GazeDataChanged(this, e);
      }
    }
Пример #5
0
 /// <summary>
 /// Fires the <see cref="Tracker.OnGazeDataChanged"/>
 /// event to the recorder, if client has new gaze data.
 /// </summary>
 /// <param name="sender">Source of the event.</param>
 /// <param name="e">A <see cref="GazeDataChangedEventArgs"/> with the event data.</param>
 private void SMIClientGazeDataChanged(object sender, GazeDataChangedEventArgs e)
 {
   this.OnGazeDataChanged(new GazeDataChangedEventArgs(e.Gazedata));
 }
Пример #6
0
 /// <summary>
 /// Calls listeners methods (which is always the <see cref="RecordModule"/>)
 ///   when new gaze data is available.
 /// </summary>
 /// <param name="e">
 /// <see cref="GazeDataChangedEventArgs"/> event arguments
 /// </param>
 protected void OnGazeDataChanged(GazeDataChangedEventArgs e)
 {
   if (this.GazeDataChanged != null)
   {
     this.GazeDataChanged(this, e);
   }
 }
Пример #7
0
    /// <summary>
    /// Ons the sample data.
    /// </summary>
    /// <param name="data">The data.</param>
    public void onSampleData(EyeTrackingController.SampleStruct data)
    {
      lock (LOCK)
      {
        if (!IsTracking)
        {
          return;
        }
        if (this.GazeDataChanged == null)
        {
          return;
        }
        GazeData gazeData = ExtractTrackerData(data);

        GazeDataChangedEventArgs eventArgs = new GazeDataChangedEventArgs(gazeData);

        this.OnGazeDataChanged(eventArgs);
      }
    }