/////////////////////////////////////////////////////////////////////////////// // Construction and Initializing methods // /////////////////////////////////////////////////////////////////////////////// #region CONSTRUCTION /// <summary> /// Initializes a new instance of the Client class. /// </summary> public Client() { // Will attempt to load "GazeTrackerSettings.xml" from execution dir. or set default this.settings = new Settings(); this.socketUdpReceive = new Socket( AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); this.commands = new Commands(); this.stream = new Stream(this); this.streamformat = new StreamFormat { TimeStampMilliseconds = true, GazePosition = true, EyetrackingType = StreamFormat.EyeTrackingType.Left }; this.stream.StreamFormat = this.streamformat; this.tracker = new Tracker(); this.camera = new Camera(this); this.calibration = new Calibration(this); this.uiControl = new UIControl(this); this.log = new Log(this); // Not fully implemented yet.. this.MouseControl = new MouseControl(); // On new gaze data this.gazeData = new GazeData(); this.gazeData.OnSmoothedGazeData += this.MouseControl.Move; }
public UDPServer() { streamFormat = new StreamFormat(); streamFormat.TimeStampMilliseconds = true; streamFormat.GazePosition = true; // Listen for changes in settings, start/stop GTSettings.Settings.Instance.Network.PropertyChanged += Network_PropertyChanged; try { socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); } catch (Exception ex) { ErrorLogger.ProcessException(ex, false); } }
public void extractTrackerData(StreamFormat format, string dataStr) { rowCount++; double XRight = 0; double XLeft = 0; double YRight = 0; double YLeft = 0; char[] seperator = { ' ' }; string[] tmp = dataStr.Split(seperator, 15); string[] formatStr = format.GetFormatString().Split(seperator); int colCount = 1; // Starts at 1 because 0 is ET_SPL (data) foreach (string fstr in formatStr) { if (tmp.Length == colCount) { // safety check to avoid reading empty columns break; } switch (fstr) { case StreamFormat.StrTimeStampMilliseconds: TimeStamp = long.Parse(tmp[colCount]); break; case StreamFormat.StrTimeStampMicroseconds: TimeStamp = long.Parse(tmp[colCount]); break; case StreamFormat.StrGazePositionX: if (format.EyetrackingType == StreamFormat.EyeTrackingType.Left) { XLeft = Convert.ToDouble(tmp[colCount]); } else if (format.EyetrackingType == StreamFormat.EyeTrackingType.Right) { XRight = Convert.ToDouble(tmp[colCount]); } else if (format.EyetrackingType == StreamFormat.EyeTrackingType.Binocular) { XLeft = Convert.ToDouble(tmp[colCount]); colCount = colCount + 1; // Two values for binocular XRight = Convert.ToDouble(tmp[colCount]); } break; case StreamFormat.StrGazePositionY: if (format.EyetrackingType == StreamFormat.EyeTrackingType.Left) { YLeft = Convert.ToDouble(tmp[colCount]); } else if (format.EyetrackingType == StreamFormat.EyeTrackingType.Right) { YRight = Convert.ToDouble(tmp[colCount]); } else if (format.EyetrackingType == StreamFormat.EyeTrackingType.Binocular) { YRight = Convert.ToDouble(tmp[colCount]); colCount = colCount + 1; // Two values for binocular YLeft = Convert.ToDouble(tmp[colCount]); } break; case StreamFormat.StrPupilDiameter: if (format.EyetrackingType == StreamFormat.EyeTrackingType.Left) { PupilDiameterLeft = Convert.ToInt32(tmp[colCount]); } else if (format.EyetrackingType == StreamFormat.EyeTrackingType.Right) { PupilDiameterRight = Convert.ToInt32(tmp[colCount]); } else if (format.EyetrackingType == StreamFormat.EyeTrackingType.Binocular) { PupilDiameterLeft = Convert.ToInt32(tmp[colCount]); colCount = colCount + 1; // Two values for binocular PupilDiameterRight = Convert.ToInt32(tmp[colCount]); } break; //case StreamFormat.StrPupilDiameterR: // if (format.EyetrackingType == StreamFormat.EyeTrackingType.Left) // PupilDiameterRight = Convert.ToInt32(tmp[colCount]); // else if (format.EyetrackingType == StreamFormat.EyeTrackingType.Right) // PupilDiameterRightY = Convert.ToInt32(tmp[colCount]); // else if (format.EyetrackingType == StreamFormat.EyeTrackingType.Binocular) // { // PupilDiameterLeftY = Convert.ToInt32(tmp[colCount]); // colCount = colCount + 1; // Two values for binocular // PupilDiameterRightY = Convert.ToInt32(tmp[colCount]); // } // break; case StreamFormat.StrPupilPositionX: if (format.EyetrackingType == StreamFormat.EyeTrackingType.Left) { PupilPositionLeftX = Convert.ToInt32(tmp[colCount]); } else if (format.EyetrackingType == StreamFormat.EyeTrackingType.Right) { PupilPositionRightX = Convert.ToInt32(tmp[colCount]); } else if (format.EyetrackingType == StreamFormat.EyeTrackingType.Binocular) { PupilPositionLeftX = Convert.ToInt32(tmp[colCount]); colCount = colCount + 1; // Two values for binocular PupilPositionRightX = Convert.ToInt32(tmp[colCount]); } break; case StreamFormat.StrPupilPositionY: if (format.EyetrackingType == StreamFormat.EyeTrackingType.Left) { PupilPositionLeftY = Convert.ToInt32(tmp[colCount]); } else if (format.EyetrackingType == StreamFormat.EyeTrackingType.Right) { PupilPositionLeftY = Convert.ToInt32(tmp[colCount]); } else if (format.EyetrackingType == StreamFormat.EyeTrackingType.Binocular) { PupilPositionLeftY = Convert.ToInt32(tmp[colCount]); colCount = colCount + 1; // Two values for binocular PupilPositionLeftY = Convert.ToInt32(tmp[colCount]); } break; case StreamFormat.StrCornealReflexPositionX: if (format.EyetrackingType == StreamFormat.EyeTrackingType.Left) { try { CornealReflexPositionLeftX = Convert.ToInt32(tmp[colCount]); } catch (Exception ex) { Console.Out.WriteLine("GazeData. Error parsing Corneal Reflex X-Position: " + ex.Message); } } else if (format.EyetrackingType == StreamFormat.EyeTrackingType.Right) { try { CornealReflexPositionRightX = Convert.ToInt32(tmp[colCount]); } catch (Exception ex) { Console.Out.WriteLine("GazeData. Error parsing Corneal Reflex X-Position: " + ex.Message); } } else if (format.EyetrackingType == StreamFormat.EyeTrackingType.Binocular) { try { CornealReflexPositionLeftX = Convert.ToInt32(tmp[colCount]); colCount = colCount + 1; // Two values for binocular CornealReflexPositionRightX = Convert.ToInt32(tmp[colCount]); } catch (Exception ex) { Console.Out.WriteLine("GazeData. Error parsing Corneal Reflex X-Position: " + ex.Message); } } break; case StreamFormat.StrCornealReflexPositionY: if (format.EyetrackingType == StreamFormat.EyeTrackingType.Left) { try { CornealReflexPositionLeftY = Convert.ToInt32(tmp[colCount]); } catch (Exception ex) { Console.Out.WriteLine("GazeData. Error parsing Corneal Reflex Y-Position: " + ex.Message); } } else if (format.EyetrackingType == StreamFormat.EyeTrackingType.Right) { try { CornealReflexPositionRightY = Convert.ToInt32(tmp[colCount]); } catch (Exception ex) { Console.Out.WriteLine("GazeData. Error parsing Corneal Reflex Y-Position: " + ex.Message); } } else if (format.EyetrackingType == StreamFormat.EyeTrackingType.Binocular) { try { CornealReflexPositionLeftY = Convert.ToInt32(tmp[colCount]); colCount = colCount + 1; // Two values for binocular CornealReflexPositionRightY = Convert.ToInt32(tmp[colCount]); } catch (Exception ex) { Console.Out.WriteLine("GazeData. Error parsing Corneal Reflex Y-Position: " + ex.Message); } } break; case StreamFormat.StrEyeTrackingType: // Set by the stream format.. but // l = left // r = right // b = binocular break; } colCount++; } // Check values, if one is left is 0 set it to right and vice versa try { if (XLeft == 0 && XRight == 0) { XRight = GazeX; XLeft = GazeX; } else if (XLeft == 0 && XRight != 0) { XLeft = XRight; } else if (XRight == 0 && XLeft != 0) { XRight = XLeft; } if (YLeft == 0 && YRight == 0) { YRight = GazeY; YLeft = GazeY; } else if (YLeft == 0 && YRight != 0) { YLeft = YRight; } else if (YRight == 0 && YLeft != 0) { YRight = YLeft; } } catch (Exception ex) { Console.Out.WriteLine("ETClient.GazeData.ExtractTrackerData. Could not parse X/Y. Data: " + dataStr + " Message: " + ex.Message); } // Average gaze postition (to be implemented in tracker?) GazeX = (XLeft + XRight) / 2; GazeY = (YLeft + YRight) / 2; if (TimeStamp != timestampLast) { SetGazePositionValues(GazeX, GazeY); SetGazePositionSmoothedValues(GazeX, GazeY); timestampLast = TimeStamp; } //GazeTrackingLibrary.GTPoint gtp = new GazeTrackingLibrary.GTPoint(XLast, YLast); //SetGazePositionSmoothedValues(smoother.Smooth(gtp).X, smoother.Smooth(gtp).Y); }
public void extractTrackerData(StreamFormat format, string dataStr) { rowCount++; double XRight = 0; double XLeft = 0; double YRight = 0; double YLeft = 0; char[] seperator = { ' ' }; string[] tmp = dataStr.Split(seperator, 15); string[] formatStr = format.GetFormatString().Split(seperator); int colCount = 1; // Starts at 1 because 0 is ET_SPL (data) foreach (string fstr in formatStr) { if (tmp.Length == colCount) { // safety check to avoid reading empty columns break; } switch (fstr) { case StreamFormat.StrTimeStampMilliseconds: TimeStamp = long.Parse(tmp[colCount]); break; case StreamFormat.StrTimeStampMicroseconds: TimeStamp = long.Parse(tmp[colCount]); break; case StreamFormat.StrGazePositionX: if (format.EyetrackingType == StreamFormat.EyeTrackingType.Left) XLeft = Convert.ToDouble(tmp[colCount]); else if (format.EyetrackingType == StreamFormat.EyeTrackingType.Right) XRight = Convert.ToDouble(tmp[colCount]); else if (format.EyetrackingType == StreamFormat.EyeTrackingType.Binocular) { XLeft = Convert.ToDouble(tmp[colCount]); colCount = colCount + 1; // Two values for binocular XRight = Convert.ToDouble(tmp[colCount]); } break; case StreamFormat.StrGazePositionY: if (format.EyetrackingType == StreamFormat.EyeTrackingType.Left) YLeft = Convert.ToDouble(tmp[colCount]); else if (format.EyetrackingType == StreamFormat.EyeTrackingType.Right) YRight = Convert.ToDouble(tmp[colCount]); else if (format.EyetrackingType == StreamFormat.EyeTrackingType.Binocular) { YRight = Convert.ToDouble(tmp[colCount]); colCount = colCount + 1; // Two values for binocular YLeft = Convert.ToDouble(tmp[colCount]); } break; case StreamFormat.StrPupilDiameter: if (format.EyetrackingType == StreamFormat.EyeTrackingType.Left) PupilDiameterLeft = Convert.ToInt32(tmp[colCount]); else if (format.EyetrackingType == StreamFormat.EyeTrackingType.Right) PupilDiameterRight = Convert.ToInt32(tmp[colCount]); else if (format.EyetrackingType == StreamFormat.EyeTrackingType.Binocular) { PupilDiameterLeft = Convert.ToInt32(tmp[colCount]); colCount = colCount + 1; // Two values for binocular PupilDiameterRight = Convert.ToInt32(tmp[colCount]); } break; //case StreamFormat.StrPupilDiameterR: // if (format.EyetrackingType == StreamFormat.EyeTrackingType.Left) // PupilDiameterRight = Convert.ToInt32(tmp[colCount]); // else if (format.EyetrackingType == StreamFormat.EyeTrackingType.Right) // PupilDiameterRightY = Convert.ToInt32(tmp[colCount]); // else if (format.EyetrackingType == StreamFormat.EyeTrackingType.Binocular) // { // PupilDiameterLeftY = Convert.ToInt32(tmp[colCount]); // colCount = colCount + 1; // Two values for binocular // PupilDiameterRightY = Convert.ToInt32(tmp[colCount]); // } // break; case StreamFormat.StrPupilPositionX: if (format.EyetrackingType == StreamFormat.EyeTrackingType.Left) PupilPositionLeftX = Convert.ToInt32(tmp[colCount]); else if (format.EyetrackingType == StreamFormat.EyeTrackingType.Right) PupilPositionRightX = Convert.ToInt32(tmp[colCount]); else if (format.EyetrackingType == StreamFormat.EyeTrackingType.Binocular) { PupilPositionLeftX = Convert.ToInt32(tmp[colCount]); colCount = colCount + 1; // Two values for binocular PupilPositionRightX = Convert.ToInt32(tmp[colCount]); } break; case StreamFormat.StrPupilPositionY: if (format.EyetrackingType == StreamFormat.EyeTrackingType.Left) PupilPositionLeftY = Convert.ToInt32(tmp[colCount]); else if (format.EyetrackingType == StreamFormat.EyeTrackingType.Right) PupilPositionLeftY = Convert.ToInt32(tmp[colCount]); else if (format.EyetrackingType == StreamFormat.EyeTrackingType.Binocular) { PupilPositionLeftY = Convert.ToInt32(tmp[colCount]); colCount = colCount + 1; // Two values for binocular PupilPositionLeftY = Convert.ToInt32(tmp[colCount]); } break; case StreamFormat.StrCornealReflexPositionX: if (format.EyetrackingType == StreamFormat.EyeTrackingType.Left) { try { CornealReflexPositionLeftX = Convert.ToInt32(tmp[colCount]); } catch (Exception ex) { Console.Out.WriteLine("GazeData. Error parsing Corneal Reflex X-Position: " + ex.Message); } } else if (format.EyetrackingType == StreamFormat.EyeTrackingType.Right) { try { CornealReflexPositionRightX = Convert.ToInt32(tmp[colCount]); } catch (Exception ex) { Console.Out.WriteLine("GazeData. Error parsing Corneal Reflex X-Position: " + ex.Message); } } else if (format.EyetrackingType == StreamFormat.EyeTrackingType.Binocular) { try { CornealReflexPositionLeftX = Convert.ToInt32(tmp[colCount]); colCount = colCount + 1; // Two values for binocular CornealReflexPositionRightX = Convert.ToInt32(tmp[colCount]); } catch (Exception ex) { Console.Out.WriteLine("GazeData. Error parsing Corneal Reflex X-Position: " + ex.Message); } } break; case StreamFormat.StrCornealReflexPositionY: if (format.EyetrackingType == StreamFormat.EyeTrackingType.Left) { try { CornealReflexPositionLeftY = Convert.ToInt32(tmp[colCount]); } catch (Exception ex) { Console.Out.WriteLine("GazeData. Error parsing Corneal Reflex Y-Position: " + ex.Message); } } else if (format.EyetrackingType == StreamFormat.EyeTrackingType.Right) { try { CornealReflexPositionRightY = Convert.ToInt32(tmp[colCount]); } catch (Exception ex) { Console.Out.WriteLine("GazeData. Error parsing Corneal Reflex Y-Position: " + ex.Message); } } else if (format.EyetrackingType == StreamFormat.EyeTrackingType.Binocular) { try { CornealReflexPositionLeftY = Convert.ToInt32(tmp[colCount]); colCount = colCount + 1; // Two values for binocular CornealReflexPositionRightY = Convert.ToInt32(tmp[colCount]); } catch (Exception ex) { Console.Out.WriteLine("GazeData. Error parsing Corneal Reflex Y-Position: " + ex.Message); } } break; case StreamFormat.StrEyeTrackingType: // Set by the stream format.. but // l = left // r = right // b = binocular break; } colCount++; } // Check values, if one is left is 0 set it to right and vice versa try { if (XLeft == 0 && XRight == 0) { XRight = GazeX; XLeft = GazeX; } else if (XLeft == 0 && XRight != 0) { XLeft = XRight; } else if (XRight == 0 && XLeft != 0) { XRight = XLeft; } if (YLeft == 0 && YRight == 0) { YRight = GazeY; YLeft = GazeY; } else if (YLeft == 0 && YRight != 0) { YLeft = YRight; } else if (YRight == 0 && YLeft != 0) { YRight = YLeft; } } catch (Exception ex) { Console.Out.WriteLine("ETClient.GazeData.ExtractTrackerData. Could not parse X/Y. Data: " + dataStr + " Message: " + ex.Message); } // Average gaze postition (to be implemented in tracker?) GazeX = (XLeft + XRight) / 2; GazeY = (YLeft + YRight) / 2; if (TimeStamp != timestampLast) { SetGazePositionValues(GazeX, GazeY); SetGazePositionSmoothedValues(GazeX, GazeY); timestampLast = TimeStamp; } //GazeTrackingLibrary.GTPoint gtp = new GazeTrackingLibrary.GTPoint(XLast, YLast); //SetGazePositionSmoothedValues(smoother.Smooth(gtp).X, smoother.Smooth(gtp).Y); }