Esempio n. 1
0
        private void SetRandomImage(CalibrationPoint point)
        {
            if (errorLoadingImages)
            {
                return;
            }

            try
            {
                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);
            }
            catch (Exception ex)
            {
                errorLoadingImages = true;
                MessageBox.Show("Could not locate the \"InfantGraphics\" folder, please ensure that it exists in the application directory.");
            }
        }
Esempio n. 2
0
        private void EyeTrackerPointStop(CalibrationPoint calPoint)
        {
            currentPoint = calPoint;
            var args1 = new RoutedEventArgs();

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

            var args1 = new RoutedEventArgs();

            args1 = new RoutedEventArgs(PointStartEvent, calPoint);
            RaiseEvent(args1);
        }
Esempio n. 4
0
 public void Reset()
 {
     calibrationCompleted = false;
     CanvasCalibration.Children.Clear();
     currentPoint       = null;
     nextPoint          = null;
     indexInstancePoint = -1;
     calibrationPoints  = new List <CalibrationPoint>();
     _avgSumStdDev      = 0;
 }
Esempio n. 5
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();
        }
Esempio n. 6
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);
        }
Esempio n. 7
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);
            }
        }
Esempio n. 8
0
        private void StartWithFirstFakePoint(Point start, Point end)
        {
            fakePoint = new CalibrationPoint(
                -1,
                TrackingScreen.TrackingScreenCenter,
                pointDiameter,
                ColorPoints,
                2000);

            // 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;
        }
Esempio 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);
        }
Esempio 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..
            }
        }
Esempio 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());
        }
 private void EyeTrackerPointStop(CalibrationPoint calPoint)
 {
     currentPoint = calPoint;
     var args1 = new RoutedEventArgs();
     args1 = new RoutedEventArgs(PointStopEvent, calPoint);
     RaiseEvent(args1);
 }
 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;
 }
        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();
        }
        private void EyeTrackerPointStart(CalibrationPoint calPoint)
        {
            currentPoint = calPoint;
            //GTCommands.Instance.CalibrationPointStart(InstancePoint.Number, InstancePoint.Point);

            var args1 = new RoutedEventArgs();
            args1 = new RoutedEventArgs(PointStartEvent, calPoint);
            RaiseEvent(args1);
        }
        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;
        }
        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..
            }
        }
 public void Reset()
 {
     calibrationCompleted = false;
     CanvasCalibration.Children.Clear();
     currentPoint = null;
     nextPoint = null;
     indexInstancePoint = -1;
     calibrationPoints = new List<CalibrationPoint>();
     _avgSumStdDev = 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);
        }
        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)

			switch (numberOfPoints)
			{
                case 5:
                    columnCount = 2;
                    rowCount = 2;
                    break;
				case 9:
					columnCount = 3;
					rowCount = 3;
					break;
				case 12:
					columnCount = 4;
					rowCount = 3;
					break;
				default:
					columnCount = 2;
					rowCount = 2;
					break;
			}

            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++;
                }
            }
        }
Esempio n. 21
0
        public BitmapSource VisualizeCalibrationResults(List <CalibrationTarget> calibTargets)
        {
            CanvasCalibration.Children.Clear();

            // Draw also to Drawing Visual
            DrawingVisual  drawingVisual  = new DrawingVisual();
            DrawingContext drawingContext = drawingVisual.RenderOpen();

            // Fill with background color
            drawingContext.DrawRectangle(
                this.CanvasCalibration.Background,
                null,
                new Rect(0, 0, this.ActualWidth, this.ActualHeight));

            // 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);

                            // Draw also to Drawing Visual
                            drawingContext.DrawEllipse(Brushes.Red, null, p, 3, 3);
                        }

                        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);

                            // Draw also to Drawing Visual
                            drawingContext.DrawEllipse(Brushes.Blue, null, p, 3, 3);
                        }

                        #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);

                        // Draw also to Drawing Visual
                        drawingContext.DrawEllipse(
                            feedback.EllipseBackground.Fill,
                            null,
                            adjustedAvgMeanGazePoint,
                            stdDevGazeCoordinates,
                            stdDevGazeCoordinates);


                        #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);

                            // Draw also to Drawing Visual
                            Pen linePen = new Pen();
                            linePen.Brush     = myLine.Stroke;
                            linePen.DashStyle = DashStyles.Dash;
                            linePen.DashCap   = PenLineCap.Round;

                            drawingContext.DrawLine(
                                linePen,
                                new Point(myLine.X1, myLine.Y1),
                                new Point(myLine.X2, myLine.Y2));
                        }

                        #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);

                // Draw also to Drawing Visual
                SolidColorBrush whiteBrush = new SolidColorBrush();
                whiteBrush.Color = Color.FromArgb(122, 255, 255, 255);
                drawingContext.DrawEllipse(
                    whiteBrush,
                    null,
                    calPoint.Point,
                    calPoint.Diameter / 2,
                    calPoint.Diameter / 2);
                drawingContext.DrawEllipse(
                    null,
                    new Pen(Brushes.Black, 1f),
                    calPoint.Point,
                    8,
                    8);

                // 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
            drawingContext.Close();
            var bmp = new RenderTargetBitmap((int)ActualWidth, (int)ActualHeight, 96, 96, PixelFormats.Pbgra32);
            bmp.Render(drawingVisual);

            return(bmp);
        }
        private void SetRandomImage(CalibrationPoint point)
        {
            if (errorLoadingImages)
                return;

            try
            {
                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);
            }
            catch (Exception ex)
            {
                errorLoadingImages = true;
                MessageBox.Show("Could not locate the \"InfantGraphics\" folder, please ensure that it exists in the application directory.");
            }
        }
        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());
        }
Esempio n. 24
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)

            switch (numberOfPoints)
            {
            case 5:
                columnCount = 2;
                rowCount    = 2;
                break;

            case 9:
                columnCount = 3;
                rowCount    = 3;
                break;

            case 12:
                columnCount = 4;
                rowCount    = 3;
                break;

            default:
                columnCount = 2;
                rowCount    = 2;
                break;
            }

            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++;
                }
            }

            // Send the calibration point list to the client
            foreach (CalibrationPoint t in calibrationPoints)
            {
                CalibrationPoint calPoint = CopyPoint(t);
                Tracker.Instance.CalibrationPointList(calPoint.Number, calPoint.Point);
            }
        }