-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAccuracyTest.xaml.cs
159 lines (135 loc) · 5.31 KB
/
AccuracyTest.xaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Tobii.Gaze.Core;
namespace GazeMonitor
{
public partial class AccuracyTest : Window
{
public AccuracyTest()
{
InitializeComponent();
}
private void Window_KeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Escape)
{
this.Close();
}
}
internal void Start()
{
Show();
DrawTargets();
}
private void DrawTargets()
{
double w = canvas.ActualWidth; double h = canvas.ActualHeight;
double r = w / 30; double m = 2 * r;
Brush b = Brushes.White;
DrawCircle(new Point(m, m), r, false, b);
DrawCircle(new Point(m, h / 2), r, false, b);
DrawCircle(new Point(m, h - m), r, false, b);
DrawCircle(new Point(w / 2, m), r, false, b);
DrawCircle(new Point(w / 2, h / 2), r, false, b);
DrawCircle(new Point(w / 2, h - m), r, false, b);
DrawCircle(new Point(w - m, m), r, false, b);
DrawCircle(new Point(w - m, h / 2), r, false, b);
DrawCircle(new Point(w - m, h - m), r, false, b);
r /= 10;
DrawCircle(new Point(m, m), r, true, b);
DrawCircle(new Point(m, h / 2), r, true, b);
DrawCircle(new Point(m, h - m), r, true, b);
DrawCircle(new Point(w / 2, m), r, true, b);
DrawCircle(new Point(w / 2, h / 2), r, true, b);
DrawCircle(new Point(w / 2, h - m), r, true, b);
DrawCircle(new Point(w - m, m), r, true, b);
DrawCircle(new Point(w - m, h / 2), r, true, b);
DrawCircle(new Point(w - m, h - m), r, true, b);
}
internal void EyeTrackerGazeData(object sender, GazeDataEventArgs e)
{
Dispatcher.Invoke(
System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate() { DisplayGaze(e.GazeData); }));
}
internal void EyeTrackerError(object sender, EyeTrackerErrorEventArgs e)
{
Close();
}
private void DisplayGaze(GazeData data)
{
if (this.IsLoaded)
{
switch (data.TrackingStatus)
{
case TrackingStatus.BothEyesTracked:
DisplayGazeLeft(data.Left);
DisplayGazeRight(data.Right);
break;
case TrackingStatus.OnlyLeftEyeTracked:
case TrackingStatus.OneEyeTrackedProbablyLeft:
DisplayGazeLeft(data.Left);
break;
case TrackingStatus.OnlyRightEyeTracked:
case TrackingStatus.OneEyeTrackedProbablyRight:
DisplayGazeRight(data.Right);
break;
}
}
}
private void DisplayGazeRight(GazeDataEye gazeDataEye)
{
Point p = new Point(gazeDataEye.GazePointOnDisplayNormalized.X, gazeDataEye.GazePointOnDisplayNormalized.Y);
var circle = DrawCircle(Denormalize(p), 5, true, Brushes.Red);
circle.Loaded += new RoutedEventHandler(CircleLoaded);
}
private void DisplayGazeLeft(GazeDataEye gazeDataEye)
{
Point p = new Point(gazeDataEye.GazePointOnDisplayNormalized.X, gazeDataEye.GazePointOnDisplayNormalized.Y);
var circle = DrawCircle(Denormalize(p), 5, true, Brushes.Green);
circle.Loaded += new RoutedEventHandler(CircleLoaded);
}
private void CircleLoaded(object sender, RoutedEventArgs e)
{
DoubleAnimation fadeAnimation = new DoubleAnimation();
fadeAnimation.From = 1.0;
fadeAnimation.To = 0.0;
fadeAnimation.Duration = TimeSpan.FromSeconds(.5);
Storyboard fadeStoryboard = new Storyboard();
fadeStoryboard.Children.Add(fadeAnimation);
Storyboard.SetTarget(fadeAnimation, (Ellipse) sender);
Storyboard.SetTargetProperty(fadeAnimation, new PropertyPath(Ellipse.OpacityProperty));
fadeStoryboard.Begin();
}
private Ellipse DrawCircle(Point center, double radius, bool filled, Brush brush)
{
Ellipse circle = new Ellipse() { Height = radius*2, Width = radius*2 };
circle.Stroke = brush;
if (filled)
circle.Fill = brush;
Canvas.SetLeft(circle, center.X - radius);
Canvas.SetTop(circle, center.Y - radius);
canvas.Children.Add(circle);
return circle;
}
private Point Normalize(Point p)
{
return new Point(p.X / canvas.ActualWidth, p.Y / canvas.ActualHeight);
}
private Point Denormalize(Point p)
{
return new Point(p.X * canvas.ActualWidth, p.Y * canvas.ActualHeight);
}
}
}