Ejemplo n.º 1
0
        private void EyeTrackerPointStop(CalibrationPoint calPoint)
        {
            currentPoint = calPoint;
            var args1 = new RoutedEventArgs();

            args1 = new RoutedEventArgs(PointStopEvent, calPoint);
            RaiseEvent(args1);
        }
Ejemplo n.º 2
0
        private void EyeTrackerPointStart(CalibrationPoint calPoint)
        {
            currentPoint = calPoint;
            //GTCommands.Instance.CalibrationPointStart(currentPoint.Number, currentPoint.Point);

            var args1 = new RoutedEventArgs();

            args1 = new RoutedEventArgs(PointStartEvent, calPoint);
            RaiseEvent(args1);
        }
Ejemplo n.º 3
0
 public void Reset()
 {
     calibrationCompleted = false;
     CanvasCalibration.Children.Clear();
     currentPoint      = null;
     nextPoint         = null;
     indexCurrentPoint = -1;
     calibrationPoints = new List <CalibrationPoint>();
     _avgSumStdDev     = 0;
 }
Ejemplo n.º 4
0
        private void AnimateBetweenPoints_Completed(object sender, EventArgs e)
        {
            // Hide last point, make a switch to the next point
            currentPoint.Visibility = Visibility.Collapsed;

            currentPoint            = nextPoint;
            currentPoint.Visibility = Visibility.Visible;

            // Get next point and continue..
            DisplayPoints();
        }
Ejemplo n.º 5
0
        private static CalibrationPoint CopyPoint(CalibrationPoint point)
        {
            var newPoint = new CalibrationPoint
            {
                Number        = point.Number,
                Point         = point.Point,
                PointColor    = point.PointColor,
                Diameter      = point.Diameter,
                PointDuration = point.PointDuration
            };

            return(newPoint);
        }
Ejemplo n.º 6
0
        public void ShowAllPoints()
        {
            // Loop through Calpoints in the UserControl (eg. this)
            foreach (CalibrationPoint t in calibrationPoints)
            {
                CalibrationPoint calPoint = CopyPoint(t);
                calPoint.Visibility = Visibility.Visible;

                CanvasCalibration.Children.Add(calPoint);
                Canvas.SetTop(calPoint, calPoint.Point.Y - calPoint.Diameter / 2);
                Canvas.SetLeft(calPoint, calPoint.Point.X - calPoint.Diameter / 2);
                Panel.SetZIndex(calPoint, 1);
            }
        }
Ejemplo n.º 7
0
        private static void SetRandomImage(CalibrationPoint point)
        {
            var imageList = new ArrayList();
            var di        = new DirectoryInfo(Directory.GetCurrentDirectory() + "\\InfantGraphics\\");

            foreach (FileInfo file in di.GetFiles())
            {
                imageList.Add(file.FullName);
            }

            var random = new Random();
            int num    = random.Next(imageList.Count - 1);

            var img = new BitmapImage(new Uri(imageList[num].ToString()));

            point.PointImage(img);
        }
Ejemplo n.º 8
0
        private void StartWithFirstFakePoint(Point start, Point end)
        {
            fakePoint = new CalibrationPoint(
                -1,
                TrackingScreen.TrackingScreenCenter,
                pointDiameter,
                ColorPoints,
                1000);

            // Add point to display canvas
            CanvasCalibration.Children.Add(fakePoint);
            Canvas.SetTop(fakePoint, fakePoint.Point.Y - pointDiameter / 2);
            Canvas.SetLeft(fakePoint, fakePoint.Point.X - pointDiameter / 2);

            fakePoint.RunScalePointAnimation();
            fakePoint.OnPointDisplayed += fakePoint_PointDisplayedAction;
        }
Ejemplo n.º 9
0
        public void Start()
        {
            Reset();

            GeneratePositions(this.Width, this.Height);

            if (RandomOrder)
            {
                RandomizeCalibrationPoints();
            }

            if (currentPoint == null)
            {
                currentPoint = GetNextPoint();
            }

            Cursor = Cursors.None; // Redisplay after calibration

            StartWithFirstFakePoint(new Point(0, 0), currentPoint.Point);
        }
Ejemplo n.º 10
0
        private void AnimateBetweenPoints(object sender, RoutedEventArgs e)
        {
            // Get next point (to animate between)
            nextPoint = GetNextPoint();

            if (nextPoint == null)
            {
                // All points displayed, raise event
                calibrationCompleted = true;
                var args1 = new RoutedEventArgs();
                args1 = new RoutedEventArgs(CalibrationEndEvent, this);
                RaiseEvent(args1);
            }
            else
            {
                // Animate from previous to new point
                var calPointX = new DoubleAnimation();
                calPointX.From              = currentPoint.Point.X - pointDiameter / 2;
                calPointX.To                = nextPoint.Point.X - pointDiameter / 2;
                calPointX.Duration          = TimeSpan.FromMilliseconds(PointTransitionDuration);
                calPointX.AccelerationRatio = _acceleration;
                calPointX.DecelerationRatio = _deacceleration;

                var calPointY = new DoubleAnimation();
                calPointY.From              = currentPoint.Point.Y - pointDiameter / 2;
                calPointY.To                = nextPoint.Point.Y - pointDiameter / 2;
                calPointY.Duration          = TimeSpan.FromMilliseconds(PointTransitionDuration);
                calPointY.AccelerationRatio = _acceleration;
                calPointY.DecelerationRatio = _deacceleration;

                calPointX.Completed += AnimateBetweenPoints_Completed;

                // Start animations
                currentPoint.BeginAnimation(Canvas.LeftProperty, calPointX);
                currentPoint.BeginAnimation(Canvas.TopProperty, calPointY);
                currentPoint.RunScalePointAnimationReverse(); // At the same time, zoom out again..
            }
        }
Ejemplo n.º 11
0
        private void CanvasCalibration_OnUIElementMoved(object sender, RoutedEventArgs e)
        {
            var replacePoint = e.OriginalSource as CalibrationPoint;
            var oldPoint     = new CalibrationPoint(99, new Point(), 0, new SolidColorBrush(), 1);

            int index      = 0;
            int foundIndex = 0;

            foreach (CalibrationPoint c in calibrationPoints)
            {
                if (replacePoint != null)
                {
                    if (c.Number == replacePoint.Number)
                    {
                        foundIndex = index;
                    }
                }

                index++;
            }

            calibrationPoints[foundIndex] = replacePoint;
            RecalibratePoint(calibrationPoints[foundIndex], new RoutedEventArgs());
        }
Ejemplo n.º 12
0
        public void GeneratePositions(double areaWidth, double areaHeight)
        {
            int pointNumber = 1;
            int columnCount = 4; // default 12 points (indx starting at 1-4, eg. 4x3)
            int rowCount    = 3; // default 12 points (indx starting at 1-3, eg. 4x3)

            if (numberOfPoints.Equals(4))
            {
                columnCount = 2;
                rowCount    = 2;
            }

            else if (numberOfPoints.Equals(9))
            {
                columnCount = 3;
                rowCount    = 3;
            }
            else if (numberOfPoints.Equals(12))
            {
                columnCount = 4;
                rowCount    = 3;
            }
            else if (numberOfPoints.Equals(16))
            {
                columnCount = 4;
                rowCount    = 4;
            }

            double rowSpacer    = (areaHeight - pointDiameter) / (rowCount - 1);
            double columnSpacer = (areaWidth - pointDiameter) / (columnCount - 1);

            //if (UseInfantGraphics)
            //    calibrationPointDiameter = calibrationPointDiameter * 2;

            //rowSpacer = rowSpacer - pointDiameter / 2;
            //columnSpacer = columnSpacer - pointDiameter / 2;

            // Adjust for 0-based array loop
            rowCount    -= 1;
            columnCount -= 1;

            for (int row = 0; row <= rowCount; row++)
            {
                for (int column = 0; column <= columnCount; column++)
                {
                    var pos = new Point(column * columnSpacer, row * rowSpacer);

                    pos.Y = pos.Y + pointDiameter / 2;
                    // Compensate for top/left positioning, eg. 0,0 is top/left when it should be 25,25 (center of point)
                    pos.X = pos.X + pointDiameter / 2;

                    var calPoint = new CalibrationPoint(
                        pointNumber,
                        pos,
                        pointDiameter,
                        _colorPoints,
                        PointDuration);

                    if (UseInfantGraphics)
                    {
                        SetRandomImage(calPoint);
                    }

                    calibrationPoints.Add(calPoint);
                    pointNumber++;
                }
            }
        }
Ejemplo n.º 13
0
        public BitmapSource VisualizeCalibrationResults(List <CalibrationTarget> calibTargets)
        {
            CanvasCalibration.Children.Clear();

            // Redisplay cursor
            Cursor = Cursors.Arrow;

            double sumStdDeviation     = 0;
            double sumDistFromTargetsX = 0;
            double sumDistFromTargetsY = 0;

            // Loop through Calpoints in the UserControl
            foreach (CalibrationPoint t in calibrationPoints)
            {
                CalibrationPoint calPoint = CopyPoint(t);

                #region Draw tracker data for calPoint

                foreach (CalibrationTarget trackerPoint in calibTargets)
                {
                    // If target number is the same, create visuals for calibration point
                    if (trackerPoint.targetNumber.Equals(calPoint.Number))
                    {
                        #region Draw raw estimated gaze positions

                        foreach (GTPoint gpLeft in trackerPoint.estimatedGazeCoordinatesLeft)
                        {
                            // compensate for relative to full screen coordinates
                            Point   p = AdjustPointToPartial(new Point(gpLeft.X, gpLeft.Y));
                            Ellipse g = new Ellipse {
                                Width = 3, Height = 3, Fill = new SolidColorBrush(Colors.Red)
                            };
                            CanvasCalibration.Children.Add(g);
                            Canvas.SetTop(g, p.Y);
                            Canvas.SetLeft(g, p.X);
                        }

                        foreach (GTPoint gpRight in trackerPoint.estimatedGazeCoordinatesRight)
                        {
                            Point   p = AdjustPointToPartial(new Point(gpRight.X, gpRight.Y));
                            Ellipse g = new Ellipse {
                                Width = 3, Height = 3, Fill = new SolidColorBrush(Colors.Blue)
                            };
                            CanvasCalibration.Children.Add(g);
                            Canvas.SetTop(g, p.Y);
                            Canvas.SetLeft(g, p.X);
                        }

                        #endregion

                        #region Draw Standard deviation indicator

                        CalibrationFeedbackPoint feedback = new CalibrationFeedbackPoint();
                        double stdDevGazeCoordinates      = trackerPoint.stdDeviationGazeCoordinatesLeft;

                        // binocular
                        if (trackerPoint.stdDeviationGazeCoordinatesRight != 0)
                        {
                            stdDevGazeCoordinates += trackerPoint.stdDeviationGazeCoordinatesRight;
                            stdDevGazeCoordinates  = stdDevGazeCoordinates / 2;
                        }

                        feedback.Width  = stdDevGazeCoordinates;
                        feedback.Height = stdDevGazeCoordinates;

                        if (feedback.Width > 80)
                        {
                            feedback.EllipseBackground.Fill = new SolidColorBrush(Colors.Red);
                        }
                        else
                        {
                            feedback.EllipseBackground.Fill = new SolidColorBrush(Colors.Green);
                        }

                        CanvasCalibration.Children.Add(feedback);

                        #endregion


                        #region Average mean gaze

                        Point avgMeanGazeCoordinates = new Point(trackerPoint.meanGazeCoordinatesLeft.X, trackerPoint.meanGazeCoordinatesLeft.Y);

                        //// binocular
                        //if (trackerPoint.meanGazeCoordinatesRight.X != 0)
                        //{
                        //    avgMeanGazeCoordinates.Y += trackerPoint.meanGazeCoordinatesRight.Y;
                        //    avgMeanGazeCoordinates.X += trackerPoint.meanGazeCoordinatesRight.X;

                        //    avgMeanGazeCoordinates.X = avgMeanGazeCoordinates.X/2;
                        //    avgMeanGazeCoordinates.Y = avgMeanGazeCoordinates.Y/2;
                        //}

                        // Position avgMean feedback, compensate for relative to full screen coordinates
                        Point adjustedAvgMeanGazePoint = AdjustPointToPartial(avgMeanGazeCoordinates);
                        Canvas.SetTop(feedback, adjustedAvgMeanGazePoint.Y);
                        Canvas.SetLeft(feedback, adjustedAvgMeanGazePoint.X);
                        Panel.SetZIndex(feedback, 2);


                        #region Connect with line if more than 80 px away

                        // When point is more than 80px. away connect it with a dotted line to center
                        if (trackerPoint.meanGazeCoordinatesLeft.Y >= calPoint.Point.Y + 80 ||
                            trackerPoint.meanGazeCoordinatesLeft.Y <= calPoint.Point.Y + 80)
                        {
                            // Start line
                            var myLine = new Line {
                                X1 = calPoint.Point.X, Y1 = calPoint.Point.Y
                            };

                            // End line
                            if (!double.IsNaN(feedback.Width))
                            {
                                myLine.X2 = adjustedAvgMeanGazePoint.X + feedback.Width / 2;
                            }

                            if (!double.IsNaN(feedback.Height))
                            {
                                myLine.Y2 = adjustedAvgMeanGazePoint.Y + feedback.Height / 2;
                            }

                            myLine.Stroke = Brushes.LightSteelBlue;

                            var dashes = new DoubleCollection {
                                2, 2
                            };
                            myLine.StrokeDashArray = dashes;
                            myLine.StrokeDashCap   = PenLineCap.Round;

                            CanvasCalibration.Children.Add(myLine);
                        }

                        #endregion

                        #endregion


                        #region Calculate sum std dev

                        sumDistFromTargetsY += avgMeanGazeCoordinates.Y - (calPoint.Point.Y - calPoint.Diameter / 2);
                        sumDistFromTargetsX += avgMeanGazeCoordinates.X - (calPoint.Point.X - calPoint.Diameter / 2);

                        double sumStdDevAvg = trackerPoint.stdDeviationGazeCoordinatesLeft + trackerPoint.stdDeviationGazeCoordinatesRight;
                        sumStdDevAvg     = sumStdDevAvg / 2;
                        sumStdDeviation += sumStdDevAvg;

                        #endregion
                    }
                }

                #endregion

                #region Draw calibration points (last to stay on top)

                calPoint.Visibility = Visibility.Visible;
                calPoint.Opacity    = 0.5;
                CanvasCalibration.Children.Add(calPoint);
                Canvas.SetTop(calPoint, calPoint.Point.Y - calPoint.Diameter / 2);
                Canvas.SetLeft(calPoint, calPoint.Point.X - calPoint.Diameter / 2);
                Panel.SetZIndex(calPoint, 99);

                // Enable recalibration
                calPoint.OnClick += RecalibratePoint;

                #endregion
            }

            // Generate values for the 1-5 star ratings-control from quality feeback
            AvgSumStdDev       = sumStdDeviation / calibTargets.Count;
            AvgDistFromTargets = ((sumDistFromTargetsY + sumDistFromTargetsX) / 2) / calibTargets.Count;

            // Now perform the rendering of the Visual to a bitmap
            //context.Close();
            var bmp = new RenderTargetBitmap((int)ActualWidth, (int)ActualHeight, 96, 96, PixelFormats.Pbgra32);
            bmp.Render(CanvasCalibration);

            return(bmp);
        }