/// <summary> /// Is called when new gaze data is available, updates track status and raises OnGazeDataChanged /// </summary> /// <param name="sender">The Sender.</param> /// <param name="e">Gaze data.</param> private void SmartEyeGazeDataAvailable(object sender, GazeDataReceivedEventArgs e) { // Send the gaze data to the track status control. SmartEyeGazeData gd = e.Gazedata; this.smartEyeTrackStatus.OnGazeData(gd); if (this.dlgTrackStatus != null && this.dlgTrackStatus.Visible) { this.dlgTrackStatus.Update(gd); } GazeData newGD = new GazeData(); newGD.Time = gd.Time; if (gd.HeadQuality >= 1 && gd.GazeQuality > this.smartEyeSettings.QualityThreshold) // cut off bad quality data { newGD.GazePosX = gd.GazePosX; newGD.GazePosY = gd.GazePosY; newGD.PupilDiaX = gd.PupilDiaX; newGD.PupilDiaY = gd.PupilDiaY; } else { newGD.GazePosX = null; newGD.GazePosY = null; newGD.PupilDiaX = null; newGD.PupilDiaY = null; } this.OnGazeDataChanged(new GazeDataChangedEventArgs(newGD)); }
/////////////////////////////////////////////////////////////////////////////// // Eventhandler // /////////////////////////////////////////////////////////////////////////////// #region EVENTS /// <summary> /// The on gaze data. /// </summary> /// <param name="gd"> /// The gaze data. /// </param> public void OnGazeData(SmartEyeGazeData gd) { this.gazeData = gd; if (gd.GazeQuality != null) { this.brush.Color = this.ComputeStatusColor(gd.GazeQuality); this.headBrush.Color = this.ComputeStatusColor(gd.HeadQuality); } this.Invalidate(); }
/////////////////////////////////////////////////////////////////////////////// // Construction and Initializing methods // /////////////////////////////////////////////////////////////////////////////// #region CONSTRUCTION /// <summary> /// Initializes a new instance of the <see cref="SmartEyeTrackStatusControl"/> class. /// </summary> public SmartEyeTrackStatusControl() { this.InitializeComponent(); this.SetStyle(ControlStyles.UserPaint, true); this.SetStyle(ControlStyles.AllPaintingInWmPaint, true); this.SetStyle(ControlStyles.DoubleBuffer, true); this.gazeData = new SmartEyeGazeData(); this.brush = new SolidBrush(Color.Transparent); this.headBrush = new SolidBrush(Color.Transparent); this.liveImagePictureBox.Paint += this.LiveImagePictureBoxOnPaint; }
/////////////////////////////////////////////////////////////////////////////// // Methods for doing main class job // /////////////////////////////////////////////////////////////////////////////// #region PRIVATEMETHODS /// <summary> /// Parse the gaze data packet into a <see cref="SmartEyeGazeData"/> gazeData object. /// </summary> /// <param name="packet">The network packet.</param> /// <param name="gazeData">The gaze data.</param> /// <returns>True if parsing was successful.</returns> private bool ParseGazeData(NetworkDataPacket packet, out SmartEyeGazeData gazeData) { gazeData = new SmartEyeGazeData(); NetworkData data; if (packet.TryGetValue(TrackerDataId.GazeDirectionQ, out data)) { gazeData.GazeQuality = data.GetValue <double>(); } if (packet.TryGetValue(TrackerDataId.HeadPositionQ, out data)) { gazeData.HeadQuality = data.GetValue <double>(); } if (packet.TryGetValue(TrackerDataId.RealTimeClock, out data)) { gazeData.RealTime = (long)data.GetValue <ulong>(); gazeData.Time = (long)(gazeData.RealTime / 10000); } if (packet.TryGetValue(TrackerDataId.ClosestWorldIntersection, out data)) { var intersection = data.GetValue <WorldIntersection>(); gazeData.GazePosX = (float)intersection.ObjectPoint.X / Document.ActiveDocument.PresentationSize.Width; gazeData.GazePosY = (float)intersection.ObjectPoint.Y / Document.ActiveDocument.PresentationSize.Height; } if (packet.TryGetValue(TrackerDataId.LeftPupilDiameter, out data)) { gazeData.PupilDiaX = (float)data.GetValue <double>(); } if (packet.TryGetValue(TrackerDataId.RightPupilDiameter, out data)) { gazeData.PupilDiaY = (float)data.GetValue <double>(); } return(true); }
/////////////////////////////////////////////////////////////////////////////// // Eventhandler // /////////////////////////////////////////////////////////////////////////////// #region EVENTS /// <summary> /// Updates the status control with the incoming gaze data. /// </summary> /// <param name="gd">The GazeDataItem with the current /// gaze data.</param> public void Update(SmartEyeGazeData gd) { this.smartEyeTrackStatusControl.OnGazeData(gd); }
/////////////////////////////////////////////////////////////////////////////// // Construction and Initializing methods // /////////////////////////////////////////////////////////////////////////////// #region CONSTRUCTION /// <summary> /// Initializes a new instance of the GazeDataChangedEventArgs class. /// </summary> /// <param name="newGazedata">The gaze data as a <see cref="SmartEyeGazeData"/> value.</param> public GazeDataReceivedEventArgs(SmartEyeGazeData newGazedata) { this.gazedata = newGazedata; }
/////////////////////////////////////////////////////////////////////////////// // Methods for doing main class job // /////////////////////////////////////////////////////////////////////////////// #region PRIVATEMETHODS /// <summary> /// Parse the gaze data packet into a <see cref="SmartEyeGazeData"/> gazeData object. /// </summary> /// <param name="packet">The network packet.</param> /// <param name="gazeData">The gaze data.</param> /// <returns>True if parsing was successful.</returns> private bool ParseGazeData(NetworkDataPacket packet, out SmartEyeGazeData gazeData) { gazeData = new SmartEyeGazeData(); NetworkData data; if (packet.TryGetValue(TrackerDataId.GazeDirectionQ, out data)) { gazeData.GazeQuality = data.GetValue<double>(); } if (packet.TryGetValue(TrackerDataId.HeadPositionQ, out data)) { gazeData.HeadQuality = data.GetValue<double>(); } if (packet.TryGetValue(TrackerDataId.RealTimeClock, out data)) { gazeData.RealTime = (long)data.GetValue<ulong>(); gazeData.Time = (long)(gazeData.RealTime / 10000); } if (packet.TryGetValue(TrackerDataId.ClosestWorldIntersection, out data)) { var intersection = data.GetValue<WorldIntersection>(); gazeData.GazePosX = (float)intersection.ObjectPoint.X / Document.ActiveDocument.PresentationSize.Width; gazeData.GazePosY = (float)intersection.ObjectPoint.Y / Document.ActiveDocument.PresentationSize.Height; } if (packet.TryGetValue(TrackerDataId.LeftPupilDiameter, out data)) { gazeData.PupilDiaX = (float)data.GetValue<double>(); } if (packet.TryGetValue(TrackerDataId.RightPupilDiameter, out data)) { gazeData.PupilDiaY = (float)data.GetValue<double>(); } return true; }
/// <summary> /// The clear. /// </summary> public void Clear() { this.gazeData = new SmartEyeGazeData(); this.Invalidate(); }