-
Notifications
You must be signed in to change notification settings - Fork 1
/
GestureResultView.cs
245 lines (212 loc) · 8.54 KB
/
GestureResultView.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
//------------------------------------------------------------------------------
// <copyright file="GestureResultView.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
namespace Kinect.KinectBand
{
using Instruments;
using System;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.Windows.Media;
using System.Windows.Media.Imaging;
/// <summary>
/// Stores discrete gesture results for the GestureDetector.
/// Properties are stored/updated for display in the UI.
/// </summary>
public sealed class GestureResultView : INotifyPropertyChanged
{
/// <summary> Image to show when the 'detected' property is true for a tracked body </summary>
private readonly ImageSource seatedImage = new BitmapImage(new Uri(@"Images\Seated.png", UriKind.Relative));
/// <summary> Image to show when the 'detected' property is false for a tracked body </summary>
private readonly ImageSource notSeatedImage = new BitmapImage(new Uri(@"Images\NotSeated.png", UriKind.Relative));
/// <summary> Image to show when the body associated with the GestureResultView object is not being tracked </summary>
private readonly ImageSource notTrackedImage = new BitmapImage(new Uri(@"Images\NotTracked.png", UriKind.Relative));
/// <summary> Array of brush colors to use for a tracked body; array position corresponds to the body colors used in the KinectBodyView class </summary>
private readonly Brush[] trackedColors = new Brush[] { Brushes.Red, Brushes.Orange, Brushes.Green, Brushes.Blue, Brushes.Indigo, Brushes.Violet };
/// <summary> Brush color to use as background in the UI </summary>
private Brush bodyColor = Brushes.Gray;
/// <summary> The body index (0-5) associated with the current gesture detector </summary>
private int bodyIndex = 0;
/// <summary> Current confidence value reported by the discrete gesture </summary>
private float confidence = 0.0f;
/// <summary> True, if the discrete gesture is currently being detected </summary>
private bool detected = false;
/// <summary> Image to display in UI which corresponds to tracking/detection state </summary>
private ImageSource imageSource = null;
/// <summary> True, if the body is currently being tracked </summary>
private bool isTracked = false;
private Instruments.IInstrument drums;
/// <summary>
/// Initializes a new instance of the GestureResultView class and sets initial property values
/// </summary>
/// <param name="bodyIndex">Body Index associated with the current gesture detector</param>
/// <param name="isTracked">True, if the body is currently tracked</param>
/// <param name="detected">True, if the gesture is currently detected for the associated body</param>
/// <param name="confidence">Confidence value for detection of the 'Seated' gesture</param>
public GestureResultView(int bodyIndex, bool isTracked, bool detected, float confidence)
{
this.BodyIndex = bodyIndex;
this.IsTracked = isTracked;
this.Detected = detected;
this.Confidence = confidence;
this.ImageSource = this.notTrackedImage;
this.drums = new Drum();
}
/// <summary>
/// INotifyPropertyChangedPropertyChanged event to allow window controls to bind to changeable data
/// </summary>
public event PropertyChangedEventHandler PropertyChanged;
/// <summary>
/// Gets the body index associated with the current gesture detector result
/// </summary>
public int BodyIndex
{
get
{
return this.bodyIndex;
}
private set
{
if (this.bodyIndex != value)
{
this.bodyIndex = value;
this.NotifyPropertyChanged();
}
}
}
/// <summary>
/// Gets the body color corresponding to the body index for the result
/// </summary>
public Brush BodyColor
{
get
{
return this.bodyColor;
}
private set
{
if (this.bodyColor != value)
{
this.bodyColor = value;
this.NotifyPropertyChanged();
}
}
}
/// <summary>
/// Gets a value indicating whether or not the body associated with the gesture detector is currently being tracked
/// </summary>
public bool IsTracked
{
get
{
return this.isTracked;
}
private set
{
if (this.IsTracked != value)
{
this.isTracked = value;
this.NotifyPropertyChanged();
}
}
}
/// <summary>
/// Gets a value indicating whether or not the discrete gesture has been detected
/// </summary>
public bool Detected
{
get
{
return this.detected;
}
private set
{
if (this.detected != value)
{
this.detected = value;
this.NotifyPropertyChanged();
}
}
}
/// <summary>
/// Gets a float value which indicates the detector's confidence that the gesture is occurring for the associated body
/// </summary>
public float Confidence
{
get
{
return this.confidence;
}
private set
{
if (this.confidence != value)
{
this.confidence = value;
this.NotifyPropertyChanged();
}
}
}
/// <summary>
/// Gets an image for display in the UI which represents the current gesture result for the associated body
/// </summary>
public ImageSource ImageSource
{
get
{
return this.imageSource;
}
private set
{
if (this.ImageSource != value)
{
this.imageSource = value;
this.NotifyPropertyChanged();
}
}
}
/// <summary>
/// Updates the values associated with the discrete gesture detection result
/// </summary>
/// <param name="isBodyTrackingIdValid">True, if the body associated with the GestureResultView object is still being tracked</param>
/// <param name="isGestureDetected">True, if the discrete gesture is currently detected for the associated body</param>
/// <param name="detectionConfidence">Confidence value for detection of the discrete gesture</param>
public void UpdateGestureResult(bool isBodyTrackingIdValid, bool isGestureDetected, float detectionConfidence)
{
this.IsTracked = isBodyTrackingIdValid;
this.Confidence = 0.0f;
if (!this.IsTracked)
{
this.ImageSource = this.notTrackedImage;
this.Detected = false;
this.BodyColor = Brushes.Gray;
}
else
{
this.Detected = isGestureDetected;
this.BodyColor = this.trackedColors[this.BodyIndex];
if (this.Detected)
{
this.Confidence = detectionConfidence;
this.ImageSource = this.seatedImage;
}
else
{
this.ImageSource = this.notSeatedImage;
}
}
}
/// <summary>
/// Notifies UI that a property has changed
/// </summary>
/// <param name="propertyName">Name of property that has changed</param>
private void NotifyPropertyChanged([CallerMemberName] string propertyName = "")
{
if (this.PropertyChanged != null)
{
this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
}
}