Пример #1
0
        /// <summary>
        ///   Clean up objects.
        /// </summary>
        public override void CleanUp()
        {
            try
            {
                this.Stop();
                this.clientStatus = 0;
                if (this.haythamClient != null)
                {
                    this.haythamClient.Disconnect();
                    this.haythamClient.CalibrationFinished    -= this.CalibrationFinished;
                    this.haythamClient.GazeDataReceived       -= this.GazeDataReceived;
                    this.haythamClient.TrackStatusDataChanged -= this.HaythamClientTrackStatusDataChanged;

                    // Hide track status control
                    this.trackControlsSplitContainer.Panel1Collapsed = false;
                    this.trackControlsSplitContainer.Panel2Collapsed = true;
                }
            }
            catch (Exception ex)
            {
                this.DisplayMessage("Haytham Cleanup failed with the following message: " + Environment.NewLine + ex.Message);
            }

            base.CleanUp();
        }
Пример #2
0
        /// <summary>
        /// Event handler for the calibration OnEnd event of the haytham tracker client
        ///   which updates the status with the calibration quality rating.
        /// </summary>
        /// <param name="sender">
        /// The sender.
        /// </param>
        /// <param name="e">
        /// The <see cref="EventArgs"/> instance containing the event data.
        /// </param>
        private void CalibrationFinished(object sender, EventArgs e)
        {
            ThreadSafe.EnableDisableButton(this.RecordButton, true);
            this.DisplayMessage("Calibration Finished");
            this.clientStatus = this.clientStatus | HaythamStatus.IsCalibrated;

            // Show track status control
            ThreadSafe.ShowHideSplitContainerPanel(this.trackControlsSplitContainer, true, false);
            ThreadSafe.ShowHideSplitContainerPanel(this.trackControlsSplitContainer, false, true);
        }
Пример #3
0
        /// <summary>
        ///   Reads settings from file. Then checks for existing haytham servers on
        ///   the network to set the IP in the settings.
        /// </summary>
        protected override sealed void Initialize()
        {
            // Load haytham tracker settings.
            if (File.Exists(this.SettingsFile))
            {
                this.settings = this.DeserializeSettings(this.SettingsFile);
            }
            else
            {
                this.settings = new HaythamSetting();
                this.SerializeSettings(this.settings, this.SettingsFile);
            }

            Task.Factory.StartNew(
                () =>
            {
                // find haytham hosts on network
                Uri hostUri = Client.getActiveHosts().FirstOrDefault();
                while (hostUri == null)
                {
                    // wait 5 seconds before next try
                    Thread.Sleep(5000);

                    // it has 2seconds timeout
                    hostUri = Client.getActiveHosts().FirstOrDefault();
                }

                // show IPv4 address if exists
                IPAddress server =
                    Dns.GetHostAddresses(hostUri.DnsSafeHost)
                    .FirstOrDefault(adr => adr.AddressFamily == AddressFamily.InterNetwork);
                if (server != null)
                {
                    this.settings.HaythamServerIPAddress = server.ToString();
                }
            });

            this.lastTime            = 0;
            this.launchButton.Click += this.LaunchButtonClick;
            this.statusUpdateTimer   = new Timer {
                Interval = 100
            };
            this.statusUpdateTimer.Tick += this.StatusUpdateTimerTick;
            this.statusUpdateTimer.Start();
            this.clientStatus = 0;
            this.trackControlsSplitContainer.Panel1Collapsed = false;
            this.trackControlsSplitContainer.Panel2Collapsed = true;

            ThreadSafe.EnableDisableButton(this.ConnectButton, false);
        }
Пример #4
0
        /// <summary>
        ///   Connects to the Haytham camera system via UDP connection.
        /// </summary>
        /// <returns>
        ///   <strong>True</strong> if connection succeded, otherwise
        ///   <strong>false</strong>.
        /// </returns>
        public override bool Connect()
        {
            try
            {
                this.haythamClient = new HaythamClient
                {
                    ServerIPAddress = IPAddress.Parse(this.Settings.HaythamServerIPAddress)
                };

                this.haythamClient.CalibrationFinished    += this.CalibrationFinished;
                this.haythamClient.GazeDataReceived       += this.GazeDataReceived;
                this.haythamClient.TrackStatusDataChanged += this.HaythamClientTrackStatusDataChanged;

                if (!this.clientStatus.HasFlag(HaythamStatus.IsConnected))
                {
                    if (!this.haythamClient.Connect())
                    {
                        throw new Exception("Connection to haytham server failed.");
                    }
                    //else
                    //{
                    //  // Show track status control
                    //  this.trackControlsSplitContainer.Panel1Collapsed = true;
                    //  this.trackControlsSplitContainer.Panel2Collapsed = false;

                    //}
                }
            }
            catch (Exception ex)
            {
                var dlg = new ConnectionFailedDialog {
                    ErrorMessage = ex.Message
                };
                dlg.ShowDialog();
                this.CleanUp();
                return(false);
            }

            this.clientStatus = this.clientStatus | HaythamStatus.IsConnected;
            return(true);
        }
Пример #5
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);
            }
        }
Пример #6
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);
      }
    }
Пример #7
0
    /// <summary>
    /// Event handler for the calibration OnEnd event of the haytham tracker client
    ///   which updates the status with the calibration quality rating.
    /// </summary>
    /// <param name="sender">
    /// The sender.
    /// </param>
    /// <param name="e">
    /// The <see cref="EventArgs"/> instance containing the event data.
    /// </param>
    private void CalibrationFinished(object sender, EventArgs e)
    {
      ThreadSafe.EnableDisableButton(this.RecordButton, true);
      this.DisplayMessage("Calibration Finished");
      this.clientStatus = this.clientStatus | HaythamStatus.IsCalibrated;

      // Show track status control
      ThreadSafe.ShowHideSplitContainerPanel(this.trackControlsSplitContainer, true, false);
      ThreadSafe.ShowHideSplitContainerPanel(this.trackControlsSplitContainer, false, true);
    }
Пример #8
0
    /// <summary>
    ///   Reads settings from file. Then checks for existing haytham servers on
    ///   the network to set the IP in the settings.
    /// </summary>
    protected override sealed void Initialize()
    {
      // Load haytham tracker settings.
      if (File.Exists(this.SettingsFile))
      {
        this.settings = this.DeserializeSettings(this.SettingsFile);
      }
      else
      {
        this.settings = new HaythamSetting();
        this.SerializeSettings(this.settings, this.SettingsFile);
      }

      Task.Factory.StartNew(
        () =>
        {
          // find haytham hosts on network
          Uri hostUri = Client.getActiveHosts().FirstOrDefault();
          while (hostUri == null)
          {
            // wait 5 seconds before next try
            Thread.Sleep(5000);

            // it has 2seconds timeout
            hostUri = Client.getActiveHosts().FirstOrDefault();
          }

          // show IPv4 address if exists
          IPAddress server =
          Dns.GetHostAddresses(hostUri.DnsSafeHost)
            .FirstOrDefault(adr => adr.AddressFamily == AddressFamily.InterNetwork);
          if (server != null)
          {
            this.settings.HaythamServerIPAddress = server.ToString();
          }
        });

      this.lastTime = 0;
      this.launchButton.Click += this.LaunchButtonClick;
      this.statusUpdateTimer = new Timer { Interval = 100 };
      this.statusUpdateTimer.Tick += this.StatusUpdateTimerTick;
      this.statusUpdateTimer.Start();
      this.clientStatus = 0;
      this.trackControlsSplitContainer.Panel1Collapsed = false;
      this.trackControlsSplitContainer.Panel2Collapsed = true;

      ThreadSafe.EnableDisableButton(this.ConnectButton, false);
    }
Пример #9
0
 /// <summary>
 ///   Stops tracking.
 /// </summary>
 public override void Stop()
 {
   this.shouldSendGazeSamples = false;
   this.clientStatus = HaythamStatus.IsCalibrated | HaythamStatus.IsConnected;
 }
Пример #10
0
    /// <summary>
    ///   Connects to the Haytham camera system via UDP connection.
    /// </summary>
    /// <returns>
    ///   <strong>True</strong> if connection succeded, otherwise
    ///   <strong>false</strong>.
    /// </returns>
    public override bool Connect()
    {
      try
      {
        this.haythamClient = new HaythamClient
                     {
                       ServerIPAddress = IPAddress.Parse(this.Settings.HaythamServerIPAddress)
                     };

        this.haythamClient.CalibrationFinished += this.CalibrationFinished;
        this.haythamClient.GazeDataReceived += this.GazeDataReceived;
        this.haythamClient.TrackStatusDataChanged += this.HaythamClientTrackStatusDataChanged;

        if (!this.clientStatus.HasFlag(HaythamStatus.IsConnected))
        {
          if (!this.haythamClient.Connect())
          {
            throw new Exception("Connection to haytham server failed.");
          }
          //else
          //{
          //  // Show track status control
          //  this.trackControlsSplitContainer.Panel1Collapsed = true;
          //  this.trackControlsSplitContainer.Panel2Collapsed = false;

          //}
        }
      }
      catch (Exception ex)
      {
        var dlg = new ConnectionFailedDialog { ErrorMessage = ex.Message };
        dlg.ShowDialog();
        this.CleanUp();
        return false;
      }

      this.clientStatus = this.clientStatus | HaythamStatus.IsConnected;
      return true;
    }
Пример #11
0
    /// <summary>
    ///   Clean up objects.
    /// </summary>
    public override void CleanUp()
    {
      try
      {
        this.Stop();
        this.clientStatus = 0;
        if (this.haythamClient != null)
        {
          this.haythamClient.Disconnect();
          this.haythamClient.CalibrationFinished -= this.CalibrationFinished;
          this.haythamClient.GazeDataReceived -= this.GazeDataReceived;
          this.haythamClient.TrackStatusDataChanged -= this.HaythamClientTrackStatusDataChanged;

          // Hide track status control
          this.trackControlsSplitContainer.Panel1Collapsed = false;
          this.trackControlsSplitContainer.Panel2Collapsed = true;
        }
      }
      catch (Exception ex)
      {
        this.DisplayMessage("Haytham Cleanup failed with the following message: " + Environment.NewLine + ex.Message);
      }

      base.CleanUp();
    }
Пример #12
0
 /// <summary>
 ///   Stops tracking.
 /// </summary>
 public override void Stop()
 {
     this.shouldSendGazeSamples = false;
     this.clientStatus          = HaythamStatus.IsCalibrated | HaythamStatus.IsConnected;
 }