-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCalibrationController.cs
163 lines (132 loc) · 5.56 KB
/
CalibrationController.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
160
161
162
163
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using Tobii.Gaze.Core;
using System.Diagnostics;
namespace GazeMonitor
{
struct CalibrationPoints
{
public List<Point> Left;
public List<Point> Right;
}
class CalibrationController
{
private CalibrationGUI gui;
CalibrationPoints calibrationPoints;
List<Point>.Enumerator currentPointLeft;
List<Point>.Enumerator currentPointRight;
private TrackerController trackerController;
private MainWindow mainWindow;
public CalibrationController(MainWindow mainWindow, TrackerController trackerController)
{
this.trackerController = trackerController;
this.mainWindow = mainWindow;
calibrationPoints.Left = new List<Point>();
calibrationPoints.Left.Add(new Point(0.1, 0.1));
calibrationPoints.Left.Add(new Point(0.1, 0.5));
calibrationPoints.Left.Add(new Point(0.1, 0.9));
calibrationPoints.Left.Add(new Point(0.5, 0.1));
calibrationPoints.Left.Add(new Point(0.5, 0.9));
calibrationPoints.Left.Add(new Point(0.9, 0.1));
calibrationPoints.Left.Add(new Point(0.9, 0.5));
calibrationPoints.Left.Add(new Point(0.9, 0.9));
calibrationPoints.Left.Add(new Point(0.5, 0.5));
calibrationPoints.Right = new List<Point>();
calibrationPoints.Right.Add(new Point(0.1, 0.1));
calibrationPoints.Right.Add(new Point(0.1, 0.5));
calibrationPoints.Right.Add(new Point(0.1, 0.9));
calibrationPoints.Right.Add(new Point(0.5, 0.1));
calibrationPoints.Right.Add(new Point(0.5, 0.5));
calibrationPoints.Right.Add(new Point(0.5, 0.9));
calibrationPoints.Right.Add(new Point(0.9, 0.1));
calibrationPoints.Right.Add(new Point(0.9, 0.5));
calibrationPoints.Right.Add(new Point(0.9, 0.9));
currentPointLeft = calibrationPoints.Left.GetEnumerator();
currentPointRight = calibrationPoints.Right.GetEnumerator();
gui = new CalibrationGUI();
gui.CalibrationCanceled += this.CalibrationCanceledEventHandler;
gui.Show();
trackerController.tracker.StartCalibrationAsync(CalibrationStarted);
}
private void LeftTargetReadyEventHandler(object sender, EventArgs e)
{
trackerController.tracker.AddCalibrationPointAsync(new Point2D(currentPointLeft.Current.X, currentPointLeft.Current.Y), PointAddedLeft);
}
private void RightTargetReadyEventHandler(object sender, EventArgs e)
{
trackerController.tracker.AddCalibrationPointAsync(new Point2D(currentPointRight.Current.X, currentPointRight.Current.Y), PointAddedRight);
}
private void CalibrationStarted(ErrorCode errorCode)
{
Debug.WriteLine("Calibration Started: " + errorCode.ToString());
InvokeInGUI(new Action(delegate() { StartLeft(); }));
}
private void StartLeft()
{
gui.ShowMessage("Cover your right eye and follow the white circle!");
gui.TargetSet += this.LeftTargetReadyEventHandler;
if (currentPointLeft.MoveNext())
gui.SetTarget(currentPointLeft.Current);
}
private void NextLeft()
{
if (currentPointLeft.MoveNext())
gui.SetTarget(currentPointLeft.Current);
else
StartRight();
}
private void StartRight()
{
gui.TargetSet -= this.LeftTargetReadyEventHandler;
gui.ShowMessage("Cover your left eye and follow the white circle!");
gui.TargetSet += this.RightTargetReadyEventHandler;
if (currentPointRight.MoveNext())
gui.SetTarget(currentPointRight.Current);
}
private void NextRight()
{
if (currentPointRight.MoveNext())
gui.SetTarget(currentPointRight.Current);
else
Compute();
}
private void Compute()
{
trackerController.tracker.ComputeAndSetCalibrationAsync(CalibrationComputed);
}
private void CalibrationComputed(ErrorCode errorCode)
{
Debug.WriteLine("Calibration Compute: " + errorCode.ToString());
trackerController.tracker.StopCalibrationAsync(CalibrationStopped);
}
private void PointAddedLeft(ErrorCode errorCode)
{
Debug.WriteLine("Point Add (Left): " + errorCode.ToString());
InvokeInGUI(new Action(delegate() { NextLeft(); }));
}
private void PointAddedRight(ErrorCode errorCode)
{
Debug.WriteLine("Point Add (Right): " + errorCode.ToString());
InvokeInGUI(new Action(delegate() { NextRight(); }));
}
private void InvokeInGUI(Action action)
{
gui.Dispatcher.Invoke(
System.Windows.Threading.DispatcherPriority.Normal, action);
}
public void CalibrationCanceledEventHandler(object sender, EventArgs e)
{
trackerController.tracker.StopCalibrationAsync(CalibrationStopped);
}
private void CalibrationStopped(ErrorCode errorCode)
{
Debug.WriteLine("Calibration Stop: " + errorCode.ToString());
InvokeInGUI(new Action(delegate() { gui.Close(); }));
}
}
}