Exemplo n.º 1
0
    /// <summary>
    /// An implementation of this method should do the calibration
    /// for the specific hardware, so that the
    /// system is ready for recording.
    /// </summary>
    /// <param name="isRecalibrating"><strong>True</strong> if calibration
    /// is in recalibration mode, indicating to renew only a few points,
    /// otherwise <strong>false</strong>.</param>
    /// <returns><strong>True</strong> if successful calibrated,
    /// otherwise <strong>false</strong>.</returns>
    /// <remarks>Implementations do not have to use the recalibrating 
    /// parameter.</remarks>
    public override bool Calibrate(bool isRecalibrating)
    {
      try
      {
        int? auroraConfigured = (int?)Registry.GetValue(@"HKEY_CURRENT_USER\Software\Smart Eye AB\Aurora Configuration Tool", "isConfigured", null);
        if (auroraConfigured == null || auroraConfigured == 0)
        {
          var message = "Calibration cannot be started as the Aurora Hardware has not yet been linked to a screen." +
            Environment.NewLine + "Please set up the system correctly in the Aurora Configuration Tool software before using it in OGAMA.";
          ExceptionMethods.ProcessMessage(
            "Aurora not configured via Aurora Configuration Tool",
            message);
          return false;
        }
      }
      catch (Exception e)
      {
        if (this.smartEyeSettings.SilentMode)
        {
          ExceptionMethods.HandleExceptionSilent(e);
        }
        else
        {
          ExceptionMethods.HandleException(e);
        }
      }

      if (!this.IsTrackerTracking("Calibration"))
      {
        return false;
      }

      // Should hide TrackStatusDlg
      if (this.dlgTrackStatus != null)
      {
        this.ShowOnSecondaryScreenButton.BackColor = System.Drawing.Color.Transparent;
        this.ShowOnSecondaryScreenButton.Text = "Show on presentation screen";
        this.dlgTrackStatus.Close();
      }

      this.ShowTrackStatus();

      if (this.liveImageThread.IsAlive)
      {
        this.stopliveImageThread = true;
      }

      try
      {
        this.smartEyeCalibration = new SmartEyeCalibrationRunner(this.smartEyeClient, this.smartEyeSettings);
      }
      catch (Exception ex)
      {
        if (this.smartEyeSettings.SilentMode)
        {
          ExceptionMethods.HandleExceptionSilent(ex);
        }
        else
        {
          ExceptionMethods.HandleException(ex);
        }

        this.StartLiveImageThread();

        return false;
      }

      try
      {
        // Start a new calibration procedure
        List<CalibrationResult> calibResult = this.smartEyeCalibration.RunCalibration();

        // Show a calibration plot if everything went OK
        if (calibResult != null)
        {
          double degreeToPixel = 0;
          string wm;

          if (this.smartEyeClient != null && this.smartEyeClient.RpcClient != null)
          {
            try
            {
              this.smartEyeClient.RpcClient.GetWorldModel(out wm);
              var wmClean = Regex.Replace(wm, @"[ \t\r\f]", string.Empty);
              var h = wmClean.IndexOf("Screen:{");

              if (h >= 0)
              {
                var wmScreenSub = wmClean.Substring(h);
                var i = wmScreenSub.IndexOf("size=");
                if (i >= 0)
                {
                  var wmSub = wmScreenSub.Substring(i + 5);
                  var j = wmSub.IndexOf(",");
                  var physWidthString = wmSub.Substring(0, j);
                  var physWidth = Convert.ToDouble(physWidthString, CultureInfo.InvariantCulture);

                  var resWidth = PresentationScreen.GetPresentationResolution().Width;

                  degreeToPixel = Math.Tan(Math.PI / 180) * 0.65 * resWidth / physWidth;
                }
              }
            }
            catch (Exception ex)
            {
              if (this.smartEyeSettings.SilentMode)
              {
                ExceptionMethods.HandleExceptionSilent(ex);
              }
              else
              {
                ExceptionMethods.HandleException(ex);
              }
            }
          }

          if (degreeToPixel != 0)
          {
            this.smartEyeCalibPlot.Initialize(calibResult, degreeToPixel);
          }
          else
          {
            this.smartEyeCalibPlot.Initialize(calibResult);
          }

          this.ShowCalibPlot();
        }
        else
        {
          if (!this.smartEyeCalibration.HasShownMessage)
          {
            ExceptionMethods.ProcessMessage("Calibration failed", "Not enough data to create a calibration (or calibration aborted).");
          }

          this.StartLiveImageThread();

          return false;
        }
      }
      catch (Exception ee)
      {
        if (this.smartEyeSettings.SilentMode)
        {
          ExceptionMethods.HandleExceptionSilent(ee);
        }
        else
        {
          ExceptionMethods.HandleException(ee);
        }

        this.StartLiveImageThread();

        return false;
      }

      return true;
    }
Exemplo n.º 2
0
        /// <summary>
        /// An implementation of this method should do the calibration
        /// for the specific hardware, so that the
        /// system is ready for recording.
        /// </summary>
        /// <param name="isRecalibrating"><strong>True</strong> if calibration
        /// is in recalibration mode, indicating to renew only a few points,
        /// otherwise <strong>false</strong>.</param>
        /// <returns><strong>True</strong> if successful calibrated,
        /// otherwise <strong>false</strong>.</returns>
        /// <remarks>Implementations do not have to use the recalibrating
        /// parameter.</remarks>
        public override bool Calibrate(bool isRecalibrating)
        {
            try
            {
                int?auroraConfigured = (int?)Registry.GetValue(@"HKEY_CURRENT_USER\Software\Smart Eye AB\Aurora Configuration Tool", "isConfigured", null);
                if (auroraConfigured == null || auroraConfigured == 0)
                {
                    var message = "Calibration cannot be started as the Aurora Hardware has not yet been linked to a screen." +
                                  Environment.NewLine + "Please set up the system correctly in the Aurora Configuration Tool software before using it in OGAMA.";
                    ExceptionMethods.ProcessMessage(
                        "Aurora not configured via Aurora Configuration Tool",
                        message);
                    return(false);
                }
            }
            catch (Exception e)
            {
                if (this.smartEyeSettings.SilentMode)
                {
                    ExceptionMethods.HandleExceptionSilent(e);
                }
                else
                {
                    ExceptionMethods.HandleException(e);
                }
            }

            if (!this.IsTrackerTracking("Calibration"))
            {
                return(false);
            }

            // Should hide TrackStatusDlg
            if (this.dlgTrackStatus != null)
            {
                this.ShowOnSecondaryScreenButton.BackColor = System.Drawing.Color.Transparent;
                this.ShowOnSecondaryScreenButton.Text      = "Show on presentation screen";
                this.dlgTrackStatus.Close();
            }

            this.ShowTrackStatus();

            if (this.liveImageThread.IsAlive)
            {
                this.stopliveImageThread = true;
            }

            try
            {
                this.smartEyeCalibration = new SmartEyeCalibrationRunner(this.smartEyeClient, this.smartEyeSettings);
            }
            catch (Exception ex)
            {
                if (this.smartEyeSettings.SilentMode)
                {
                    ExceptionMethods.HandleExceptionSilent(ex);
                }
                else
                {
                    ExceptionMethods.HandleException(ex);
                }

                this.StartLiveImageThread();

                return(false);
            }

            try
            {
                // Start a new calibration procedure
                List <CalibrationResult> calibResult = this.smartEyeCalibration.RunCalibration();

                // Show a calibration plot if everything went OK
                if (calibResult != null)
                {
                    double degreeToPixel = 0;
                    string wm;

                    if (this.smartEyeClient != null && this.smartEyeClient.RpcClient != null)
                    {
                        try
                        {
                            this.smartEyeClient.RpcClient.GetWorldModel(out wm);
                            var wmClean = Regex.Replace(wm, @"[ \t\r\f]", string.Empty);
                            var h       = wmClean.IndexOf("Screen:{");

                            if (h >= 0)
                            {
                                var wmScreenSub = wmClean.Substring(h);
                                var i           = wmScreenSub.IndexOf("size=");
                                if (i >= 0)
                                {
                                    var wmSub           = wmScreenSub.Substring(i + 5);
                                    var j               = wmSub.IndexOf(",");
                                    var physWidthString = wmSub.Substring(0, j);
                                    var physWidth       = Convert.ToDouble(physWidthString, CultureInfo.InvariantCulture);

                                    var resWidth = PresentationScreen.GetPresentationResolution().Width;

                                    degreeToPixel = Math.Tan(Math.PI / 180) * 0.65 * resWidth / physWidth;
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            if (this.smartEyeSettings.SilentMode)
                            {
                                ExceptionMethods.HandleExceptionSilent(ex);
                            }
                            else
                            {
                                ExceptionMethods.HandleException(ex);
                            }
                        }
                    }

                    if (degreeToPixel != 0)
                    {
                        this.smartEyeCalibPlot.Initialize(calibResult, degreeToPixel);
                    }
                    else
                    {
                        this.smartEyeCalibPlot.Initialize(calibResult);
                    }

                    this.ShowCalibPlot();
                }
                else
                {
                    if (!this.smartEyeCalibration.HasShownMessage)
                    {
                        ExceptionMethods.ProcessMessage("Calibration failed", "Not enough data to create a calibration (or calibration aborted).");
                    }

                    this.StartLiveImageThread();

                    return(false);
                }
            }
            catch (Exception ee)
            {
                if (this.smartEyeSettings.SilentMode)
                {
                    ExceptionMethods.HandleExceptionSilent(ee);
                }
                else
                {
                    ExceptionMethods.HandleException(ee);
                }

                this.StartLiveImageThread();

                return(false);
            }

            return(true);
        }