-
Notifications
You must be signed in to change notification settings - Fork 0
/
AnalysisCreationWizard.cs
executable file
·283 lines (225 loc) · 9.09 KB
/
AnalysisCreationWizard.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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using bCoach_Assistant.Storage.CaptureFile;
namespace bCoach_Assistant
{
public partial class AnalysisCreationWizard : Form
{
int currentStep = 1;
int totalPanels = 3;
// Data
private Court court;
private List<Camera> cameraList = new List<Camera>();
public AnalysisCreationWizard()
{
InitializeComponent();
}
private void AnalysisCreationWizard_Load(object sender, EventArgs e)
{
groupBox1.Enabled = false;
listView1.SelectedIndexChanged += listView1_SelectedIndexChanged;
DisplayPanel(1);
}
#region Panel manager
private void nextBtn_Click(object sender, EventArgs e)
{
// Store court properties
if (currentStep == 2)
{
court = new Court(court_width.Value, court_height.Value);
}
if (currentStep == totalPanels)
{
Finish();
}
else
{
DisplayPanel(++currentStep);
}
}
private void previousBtn_Click(object sender, EventArgs e)
{
DisplayPanel(--currentStep);
}
private void DisplayPanel(int n)
{
for (int i = 1; i <= totalPanels; i++)
{
this.Controls["panel" + i].Visible = false;
}
this.Controls["panel" + n].Visible = true;
if (n == totalPanels)
{
nextBtn.Text = "Finish";
}
else
{
nextBtn.Text = "Next";
}
if (n == 1)
previousBtn.Enabled = false;
else
previousBtn.Enabled = true;
}
private void cancelBtn_Click(object sender, EventArgs e)
{
ExitWizard();
}
private void Finish()
{
MessageBox.Show("Finished");
}
private void ExitWizard()
{
this.Close();
}
#endregion
#region Panel 3 - Camera calibration and positioning
private void listView1_SelectedIndexChanged(object sender, EventArgs e)
{
if (listView1.SelectedIndices.Count > 0)
UpdateGroupBox(listView1.SelectedIndices[0]);
else
groupBox1.Enabled = false;
}
private void camera_add_Click(object sender, EventArgs e)
{
Camera c = new Camera();
c.Id = listView1.Items.Count == 0 ? 0 : cameraList.OrderByDescending(a => a.Id).FirstOrDefault().Id + 1;
c.Name = "Camera #" + c.Id;
cameraList.Add(c);
string[] subItems = {"No", "No", "No"}; // That's a no-no, no!
listView1.Items.Add(c.Name).SubItems.AddRange(subItems);
GrantSoleSelection(listView1.Items.Count - 1);
}
/// <summary>
/// Grants selection solely to the specified index of the list view.
/// </summary>
/// <param name="n">The index to be selected.</param>
private void GrantSoleSelection(int n)
{
foreach (ListViewItem i in listView1.Items)
i.Selected = false;
listView1.Items[listView1.Items.Count - 1].Selected = true;
}
private void UpdateGroupBox(int n)
{
// TODO: Add color coding to text-boxes so that it is easy to see what isn't setup yet
groupBox1.Enabled = true;
Camera c = cameraList.Where(p => p.Id == n).FirstOrDefault();
camera_name.Text = c.Name;
camera_notes.Text = c.Notes;
if (c.FocalLength != -1)
camera_calibrateText.Text = "Focal length: " + c.FocalLength.ToString();
else
camera_calibrateText.Text = "Not calibrated yet.";
if (c.X != -999 && c.Y != -999 && c.Angle != -1)
camera_positionText.Text = "X: " + c.X.ToString() + "; Y: " + c.Y.ToString() + "; Angle: " + c.Angle.ToString();
else
camera_positionText.Text = "Not positioned yet.";
bool video = false;
bool detector = false;
if (c.FilePath != "" && c.StartFrame != -1 && c.EndFrame != -1)
video = true;
else
video = false;
if (c.Iterations != -1) // We can still work with unset thresholds! (e.g.: all at 0!) I think...
detector = true;
else
detector = false;
if (!video && !detector)
camera_configText.Text = "Not setup yet.";
else if (video && !detector)
camera_configText.Text = "Must setup detector.";
else if (!video && detector) // Should be impossible
camera_configText.Text = "Must setup video.";
else
camera_configText.Text = "Correctly setup.";
UpdateListView();
}
private int GetCurrentFocusIndex()
{
return listView1.SelectedIndices[0]; // Throws ArgumentOutOfRangeException if no camera from the
// ListView is selected
}
private Camera GetCameraFromId(int n)
{
return cameraList.Where(p => p.Id == n).FirstOrDefault();
}
private Camera GetCurrentCamera()
{
int currIndex = listView1.SelectedIndices[0]; // Throws ArgumentOutOfRangeException if no camera from the
// ListView is selected
return cameraList[currIndex];
}
private void camera_calibrate_Click(object sender, EventArgs e)
{
using (CameraCalibration cal = new CameraCalibration())
{
cal.ShowDialog();
if (cal.FocalLength != -1)
{
GetCurrentCamera().FocalLength = cal.FocalLength;
}
UpdateGroupBox(GetCurrentFocusIndex());
}
}
private void camera_position_Click(object sender, EventArgs e)
{
using (CameraPosition pos = new CameraPosition())
{
pos.ShowDialog();
//if (pos.X != -999 && pos.Y != -999 && pos.Angle != -1)
//{
GetCurrentCamera().X = pos.X;
GetCurrentCamera().Y = pos.Y;
GetCurrentCamera().Angle = pos.Angle;
//}
UpdateGroupBox(GetCurrentFocusIndex());
}
}
private void camera_notes_TextChanged(object sender, EventArgs e)
{
GetCurrentCamera().Notes = camera_notes.Text;
}
private void camera_name_TextChanged(object sender, EventArgs e)
{
GetCurrentCamera().Name = camera_name.Text;
UpdateListView();
}
private void UpdateListView()
{
for (int i = 0; i < listView1.Items.Count; i++)
{
listView1.Items[i].SubItems[0].Text = cameraList[i].Name;
listView1.Items[i].SubItems[1].Text = cameraList[i].FocalLength != -1 ? "Yes" : "No";
listView1.Items[i].SubItems[2].Text = (cameraList[i].X != -999 & cameraList[i].Y != -999 & cameraList[i].Angle != -1) ? "Yes" : "No";
listView1.Items[i].SubItems[3].Text = (cameraList[i].FilePath != "" && cameraList[i].StartFrame != -1 && cameraList[i].EndFrame != -1 && cameraList[i].Iterations != -1) ? "Yes" : "No";
}
}
private void camera_config_Click(object sender, EventArgs e)
{
Camera c = GetCurrentCamera();
using (CameraConfiguration camConfig = new CameraConfiguration(c.FilePath, c.StartFrame, c.EndFrame, c.MinimumThresholds,
c.MaximumThresholds, c.Iterations))
{
camConfig.ShowDialog();
GetCurrentCamera().MinimumThresholds = camConfig.Minimum;
GetCurrentCamera().MaximumThresholds = camConfig.Maximum;
GetCurrentCamera().Iterations = camConfig.Iterations;
GetCurrentCamera().FilePath = camConfig.FileName;
GetCurrentCamera().StartFrame = camConfig.StartFrame;
GetCurrentCamera().EndFrame = camConfig.EndFrame;
UpdateGroupBox(GetCurrentFocusIndex());
}
}
#endregion
}
}