Esempio n. 1
0
        /// <summary>
        /// The on paint.
        /// </summary>
        /// <param name="e">
        /// The e.
        /// </param>
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);

            // Draw calibration circle
            var monitorSize  = PresentationScreen.GetPresentationResolution();
            var circleBounds = new Rectangle
            {
                X      = (int)(monitorSize.Width * this.CalibrationPoint.X - PixelRadius),
                Y      = (int)(monitorSize.Height * this.CalibrationPoint.Y - PixelRadius),
                Width  = 2 * PixelRadius,
                Height = 2 * PixelRadius
            };

            var smallCircleBounds = new Rectangle
            {
                X      = (int)(monitorSize.Width * this.CalibrationPoint.X - 1),
                Y      = (int)(monitorSize.Height * this.CalibrationPoint.Y - 1),
                Width  = 2,
                Height = 2
            };

            using (var brush = new SolidBrush(this.PointColor))
            {
                e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
                Console.WriteLine("Drawing circle " + circleBounds + " color " + this.PointColor);
                e.Graphics.FillEllipse(brush, circleBounds);

                brush.Color = this.PointColor == Color.Transparent ? Color.Transparent : Color.Black;
                e.Graphics.FillEllipse(brush, smallCircleBounds);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Start collecting gaze samples for current calibration point.
        /// </summary>
        /// <param name="collectionId">Current ID.</param>
        /// <param name="screenPoint">The actual screen target.</param>
        private void CollectSamples(int collectionId, Point2D screenPoint)
        {
            this.goToNextPointTimer.Stop();
            this.state = CalibrationState.CollectingSamples;

            var x = screenPoint.X * PresentationScreen.GetPresentationResolution().Width;
            var y = screenPoint.Y * PresentationScreen.GetPresentationResolution().Height;

            try
            {
                this.client.RpcClient.StartCollectSamplesObject(collectionId, this.screenName, x, y, 0, this.calibTime * 2);
            }
            catch (Exception ex)
            {
                if (this.settings.SilentMode)
                {
                    ExceptionMethods.HandleExceptionSilent(ex);
                }
                else
                {
                    ExceptionMethods.HandleException(ex);
                    this.HasShownMessage = true;
                }

                this.AbortCalibration();
                return;
            }

            this.collectSamplesStopwatch = new Stopwatch();
            this.collectSamplesStopwatch.Start();

            this.collectSamplesTimer.Start();
        }
        /// <summary>
        /// The on paint.
        /// </summary>
        /// <param name="e">
        /// The e.
        /// </param>
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);

            if (this.Message != null)
            {
                var x = PresentationScreen.GetPresentationResolution().Width / 2;
                var y = PresentationScreen.GetPresentationResolution().Height / 2;

                Font stringFont = new Font("Helvetica", 24);

                // Measure string.
                SizeF stringSize = new SizeF();
                stringSize = e.Graphics.MeasureString(this.Message, stringFont);

                // Draw string to screen.
                e.Graphics.DrawString(this.Message, stringFont, new SolidBrush(this.MessageColor), new PointF(x - stringSize.Width / 2, y - stringSize.Height / 2));
            }

            // Draw calibration circle
            if (this.CalibrationPoint == null)
            {
                return;
            }

            var monitorSize  = PresentationScreen.GetPresentationResolution();
            var circleBounds = new Rectangle
            {
                X      = (int)(monitorSize.Width * this.CalibrationPoint.X - this.PointSize),
                Y      = (int)(monitorSize.Height * this.CalibrationPoint.Y - this.PointSize),
                Width  = 2 * this.PointSize,
                Height = 2 * this.PointSize
            };

            var smallCircleBounds = new Rectangle
            {
                X      = (int)(monitorSize.Width * this.CalibrationPoint.X - 1),
                Y      = (int)(monitorSize.Height * this.CalibrationPoint.Y - 1),
                Width  = 2,
                Height = 2
            };

            using (var brush = new SolidBrush(this.PointColor))
            {
                e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
                Console.WriteLine("Drawing circle " + circleBounds + " color " + this.PointColor);
                e.Graphics.FillEllipse(brush, circleBounds);

                brush.Color = this.PointColor == Color.Transparent ? Color.Transparent : Color.Black;
                e.Graphics.FillEllipse(brush, smallCircleBounds);
            }
        }
Esempio n. 4
0
        /// <summary>
        /// The <see cref="Control.Click"/> event handler for the
        /// <see cref="Button"/> <see cref="btnPreviewSlideshow"/>.
        /// Starts a <see cref="PresenterModule"/> with the given slides.
        /// </summary>
        /// <param name="sender">Source of the event.</param>
        /// <param name="e">An empty <see cref="EventArgs"/></param>
        private void BtnPreviewSlideshowClick(object sender, EventArgs e)
        {
            if (!RecordModule.CheckForCorrectPresentationScreenResolution(PresentationScreen.GetPresentationResolution()))
            {
                return;
            }

            PresenterModule objPresenter = new PresenterModule();

            // Create a newly randomized trial list.
            TrialCollection trials = this.slideshow.GetRandomizedTrials();

            // Create a hardcopy of the trials.
            TrialCollection copyOfTrials = (TrialCollection)trials.Clone();

            // Set slide list of presenter
            objPresenter.TrialList = copyOfTrials;

            // Show presenter form, that starts presentation.
            objPresenter.ShowDialog();

            // Update slideshow pictures of newly created trials
            Document.ActiveDocument.ExperimentSettings.SlideShow.UpdateExperimentPathOfResources(Document.ActiveDocument.ExperimentSettings.SlideResourcesPath);
        }
Esempio n. 5
0
        /// <summary>
        /// This method performs a unrandomized nine point calibration.
        /// </summary>
        public void Calibrate()
        {
            if (!this.IsConnected)
            {
                this.Connect();
            }

            // Get presentation size
            Size presentationSize = PresentationScreen.GetPresentationResolution();

            // Set calibration area size
            this.SendString("ET_CSZ " + presentationSize.Width.ToString() + " " + presentationSize.Height.ToString());


            // Set calibration points
            int          fivePercentX      = (int)(0.05f * presentationSize.Width);
            int          fivePercentY      = (int)(0.05f * presentationSize.Height);
            int          xHalf             = presentationSize.Width / 2;
            int          yHalf             = presentationSize.Height / 2;//was Width
            Point        topLeft           = new Point(fivePercentX, fivePercentY);
            Point        topMiddle         = new Point(xHalf, fivePercentY);
            Point        topRight          = new Point(presentationSize.Width - fivePercentX, fivePercentY);
            Point        middleLeft        = new Point(fivePercentX, yHalf);
            Point        center            = new Point(xHalf, yHalf);
            Point        middleRight       = new Point(presentationSize.Width - fivePercentX, yHalf);
            Point        bottomLeft        = new Point(fivePercentX, presentationSize.Height - fivePercentY);
            Point        bottomMiddle      = new Point(xHalf, presentationSize.Height - fivePercentY);
            Point        bottomRight       = new Point(presentationSize.Width - fivePercentX, presentationSize.Height - fivePercentY);
            List <Point> calibrationPoints = new List <Point>();

            calibrationPoints.Add(center);
            calibrationPoints.Add(topLeft);
            calibrationPoints.Add(topRight);
            calibrationPoints.Add(bottomLeft);
            calibrationPoints.Add(bottomRight);
            calibrationPoints.Add(middleLeft);
            calibrationPoints.Add(topMiddle);
            calibrationPoints.Add(middleRight);
            calibrationPoints.Add(bottomMiddle);

            ////this.SendString("ET_PNT 1 " + center.X.ToString() + " " + center.Y.ToString());
            ////this.SendString("ET_PNT 2 " + topLeft.X.ToString() + " " + topLeft.Y.ToString());
            ////this.SendString("ET_PNT 3 " + topRight.X.ToString() + " " + topRight.Y.ToString());
            ////this.SendString("ET_PNT 4 " + bottomLeft.X.ToString() + " " + bottomLeft.Y.ToString());
            ////this.SendString("ET_PNT 5 " + bottomRight.X.ToString() + " " + bottomRight.Y.ToString());

            this.newCalibrationForm = new SMIiViewXCalibrationForm();
            this.newCalibrationForm.CalibPointColor   = this.smiSettings.CalibPointColor;
            this.newCalibrationForm.CalibPointSize    = this.smiSettings.CalibPointSize;
            this.newCalibrationForm.BackColor         = this.smiSettings.CalibBackgroundColor;
            this.newCalibrationForm.Width             = presentationSize.Width;
            this.newCalibrationForm.Height            = presentationSize.Height;
            this.newCalibrationForm.CalibrationPoints = calibrationPoints;


            PresentationScreen.PutFormOnPresentationScreen(this.newCalibrationForm, true);

            this.newCalibrationForm.Show();

            // Starts calibration.
            this.SendString("ET_CAL 9");

            // Wait 2 seconds at the center point.
            int counter = 0;

            do
            {
                Application.DoEvents();
                Thread.Sleep(100);
                counter++;
            }while (counter < 50);

            // Accepts calibration point.
            this.SendString("ET_ACC");
        }
Esempio n. 6
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
        #endregion //CUSTOMEVENTHANDLER

        #endregion //EVENTS

        ///////////////////////////////////////////////////////////////////////////////
        // Methods and Eventhandling for Background tasks                            //
        ///////////////////////////////////////////////////////////////////////////////
        #region BACKGROUNDWORKER
        #endregion //BACKGROUNDWORKER

        ///////////////////////////////////////////////////////////////////////////////
        // Methods for doing main class job                                          //
        ///////////////////////////////////////////////////////////////////////////////
        #region PRIVATEMETHODS

        /// <summary>
        ///  Create a new filter graph and add filters (devices, compressors,
        ///  misc), but leave the filters unconnected. Call renderGraph()
        ///  to connect the filters.
        /// </summary>
        /// <returns>True if successful created the graph.</returns>
        protected bool createGraph()
        {
            int hr;

            try
            {
                // Garbage collect, ensure that previous filters are released
                GC.Collect();

                // Get the graphbuilder object
                this.graphBuilder = new FilterGraph() as IFilterGraph2;

                // Get a ICaptureGraphBuilder2 to help build the graph
                this.captureGraphBuilder = new CaptureGraphBuilder2() as ICaptureGraphBuilder2;

                // Link the CaptureGraphBuilder to the filter graph
                hr = this.captureGraphBuilder.SetFiltergraph(this.graphBuilder);
                DsError.ThrowExceptionForHR(hr);

#if DEBUG
                this.rotCookie = new DsROTEntry(this.graphBuilder);
#endif

                // this.screenCaptureFilter = (IBaseFilter)new OgamaScreenCaptureFilter();

                // Get the ogama screen capture device and add it to the filter graph
                this.screenCaptureFilter = DirectShowUtils.CreateFilter(FilterCategory.VideoInputDevice, "OgamaCapture");

                hr = this.graphBuilder.AddFilter(this.screenCaptureFilter, "OgamaCapture");
                DsError.ThrowExceptionForHR(hr);

                // Query the interface for the screen capture Filter
                var ogamaFilter = this.screenCaptureFilter as IOgamaScreenCapture;

                hr = ogamaFilter.set_Monitor(this.monitorIndex);
                DsError.ThrowExceptionForHR(hr);

                hr = ogamaFilter.set_Framerate(this.frameRate);
                DsError.ThrowExceptionForHR(hr);

                //// Get the IAMStreamConfig from the filter so we can configure it
                //var videoStreamConfig = this.screenCaptureFilter as IAMStreamConfig;

                var resolution = PresentationScreen.GetPresentationResolution();
                //hr = videoStreamConfig.SetFormat(this.CreateVideoMediaType(24, resolution.Width, resolution.Height));
                //DsError.ThrowExceptionForHR(hr);

                this.smartTeeFilter = new SmartTee() as IBaseFilter;
                hr = this.graphBuilder.AddFilter(this.smartTeeFilter, "Smart Tee");
                DsError.ThrowExceptionForHR(hr);

                if (SecondaryScreen.SystemHasSecondaryScreen())
                {
                    // Add a DMO Wrapper Filter
                    this.dmoFilter        = (IBaseFilter) new DMOWrapperFilter();
                    this.dmoWrapperFilter = (IDMOWrapperFilter)this.dmoFilter;

                    // But it is more useful to show how to scan for the DMO
                    var g = this.FindGuid("DmoOverlay", DMOCategory.VideoEffect);

                    hr = this.dmoWrapperFilter.Init(g, DMOCategory.VideoEffect);
                    DMOError.ThrowExceptionForHR(hr);

                    this.SetDMOParams(this.dmoFilter);

                    // Add it to the Graph
                    hr = this.graphBuilder.AddFilter(this.dmoFilter, "DMO Filter");
                    DsError.ThrowExceptionForHR(hr);

                    var dmo = (IMediaObject)this.dmoFilter;
                    hr = dmo.SetInputType(0, this.CreateVideoMediaType(24, resolution.Width, resolution.Height), DMOSetType.None);
                    DsError.ThrowExceptionForHR(hr);
                    hr = dmo.SetOutputType(0, this.CreateVideoMediaType(24, resolution.Width, resolution.Height), DMOSetType.None);
                    DsError.ThrowExceptionForHR(hr);
                }

                // Get the video compressor and add it to the filter graph
                // Create the filter for the selected video compressor
                this.videoCompressorFilter = DirectShowUtils.CreateFilter(
                    FilterCategory.VideoCompressorCategory,
                    this.videoCompressorName);
                hr = this.graphBuilder.AddFilter(this.videoCompressorFilter, "Video Compressor");
                DsError.ThrowExceptionForHR(hr);

                // Render the file writer portion of graph (mux -> file)
                hr = this.captureGraphBuilder.SetOutputFileName(
                    MediaSubType.Avi,
                    this.tempFilename,
                    out this.muxFilter,
                    out this.fileWriterFilter);
                DsError.ThrowExceptionForHR(hr);

                //// Disable overwrite
                //// hr = this.fileWriterFilter.SetMode(AMFileSinkFlags.None);
                //// DsError.ThrowExceptionForHR(hr);
                hr = this.captureGraphBuilder.AllocCapFile(this.tempFilename, 10000000);
                DsError.ThrowExceptionForHR(hr);

                if (SecondaryScreen.SystemHasSecondaryScreen())
                {
                    hr = this.captureGraphBuilder.RenderStream(null, null, this.screenCaptureFilter, null, this.smartTeeFilter);
                    DsError.ThrowExceptionForHR(hr);

                    hr = this.captureGraphBuilder.RenderStream(
                        null,
                        null,
                        this.smartTeeFilter,
                        this.videoCompressorFilter,
                        this.muxFilter);
                    DsError.ThrowExceptionForHR(hr);

                    hr = this.captureGraphBuilder.RenderStream(null, null, this.smartTeeFilter, null, this.dmoFilter);
                    DsError.ThrowExceptionForHR(hr);

                    hr = this.captureGraphBuilder.RenderStream(null, null, this.dmoFilter, null, null);
                    DsError.ThrowExceptionForHR(hr);
                }
                else
                {
                    hr = this.captureGraphBuilder.RenderStream(
                        null,
                        null,
                        this.screenCaptureFilter,
                        this.videoCompressorFilter,
                        this.muxFilter);
                    DsError.ThrowExceptionForHR(hr);
                }

                // IMediaFilter filter = this.graphBuilder as IMediaFilter;
                // IReferenceClock clock;
                // filter.GetSyncSource(out clock);
                hr = this.graphBuilder.SetDefaultSyncSource();
                DsError.ThrowExceptionForHR(hr);

                // Retreive the media control interface (for starting/stopping graph)
                this.mediaControl = (IMediaControl)this.graphBuilder;
            }
            catch (Exception ex)
            {
                ExceptionMethods.HandleException(ex);
                return(false);
            }

            return(true);
        }
Esempio n. 7
0
        /// <summary>
        /// Prepare for calibration by resetting profile and fields
        /// </summary>
        /// <returns>A <see cref="bool"/> with the tracking state.</returns>
        private bool PrepareForCalibration()
        {
            this.HasShownMessage = false;

            try
            {
                string wm;
                this.client.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("name=\"");
                    if (i >= 0)
                    {
                        var wmSub = wmScreenSub.Substring(i + 6);
                        var j     = wmSub.IndexOf("\"");
                        this.screenName = wmSub.Substring(0, j);
                    }

                    i = wmScreenSub.IndexOf("resolution=");
                    if (i >= 0)
                    {
                        var wmSub2            = wmScreenSub.Substring(i + 11);
                        var j2                = wmSub2.IndexOf(",");
                        var screenWidthString = wmSub2.Substring(0, j2);
                        var screenWidth       = Convert.ToInt32(screenWidthString);

                        var j3 = wmSub2.IndexOf("\n");
                        var screenHeightString = wmSub2.Substring(j2 + 1, j3 - j2 - 1);
                        var screenHeight       = Convert.ToInt32(screenHeightString);

                        if (screenWidth != PresentationScreen.GetPresentationResolution().Width ||
                            screenHeight != PresentationScreen.GetPresentationResolution().Height)
                        {
                            string message = "The resolution of the presentation screen: " + PresentationScreen.GetPresentationResolution().Width + "x"
                                             + PresentationScreen.GetPresentationResolution().Height + " is different from the size "
                                             + "specified in the Smart Eye World Model: " + screenWidthString + "x" + screenHeightString + "."
                                             + Environment.NewLine
                                             + "Please change the display settings or the Smart Eye World Model to fit the resolution specified in the experiment settings.";

                            ExceptionMethods.ProcessMessage("Resolution mismatch", message);
                            this.HasShownMessage = true;
                            return(false);
                        }
                    }
                }
                else
                {
                    string message = "There is no screen specified in the Smart Eye World Model, please edit it!";
                    ExceptionMethods.ProcessMessage("Screen not defined in World Model", message);
                    this.HasShownMessage = true;
                    return(false);
                }
            }
            catch (Exception ex)
            {
                if (this.settings.SilentMode)
                {
                    ExceptionMethods.HandleExceptionSilent(ex);
                }
                else
                {
                    ExceptionMethods.HandleException(ex);
                    this.HasShownMessage = true;
                }

                this.AbortCalibration();
                return(false);
            }

            this.ResetValues();
            this.smartEyeCalibrationForm.BackColor = this.settings.CalibBackgroundColor;
            return(true);
        }
Esempio n. 8
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);
        }