1 /* |
|
2 * This file is part of the TraKERS\Middleware package. |
|
3 * |
|
4 * (c) IRI <http://www.iri.centrepompidou.fr/> |
|
5 * |
|
6 * For the full copyright and license information, please view the LICENSE_MIDDLEWARE |
|
7 * file that was distributed with this source code. |
|
8 */ |
|
9 |
|
10 /* |
|
11 * Projet : TraKERS |
|
12 * Module : MIDDLEWARE |
|
13 * Sous-Module : Debug |
|
14 * Classe : DebugWindow |
|
15 * |
|
16 * Auteur : alexandre.bastien@iri.centrepompidou.fr |
|
17 * |
|
18 * Fonctionnalités : Reçoit des notifications des sous-modules Tracking, Communication et Exception. |
|
19 * Intéragit avec la fenêtre XAML de debug de façon à afficher un rendu visuel. |
|
20 */ |
|
21 |
|
22 using System; |
|
23 using System.Collections.Generic; |
|
24 using System.Linq; |
|
25 using System.Text; |
|
26 using System.Windows; |
|
27 using System.Windows.Controls; |
|
28 using System.Windows.Data; |
|
29 using System.Windows.Documents; |
|
30 using System.Windows.Input; |
|
31 using System.Windows.Media; |
|
32 using System.Windows.Media.Imaging; |
|
33 using System.Windows.Navigation; |
|
34 using System.Windows.Shapes; |
|
35 using System.Drawing; |
|
36 using System.Windows.Media.Media3D; |
|
37 using Microsoft.Kinect; |
|
38 |
|
39 using Coding4Fun.Kinect.Wpf; |
|
40 |
|
41 using Trakers.Tracking; |
|
42 using System.Threading; |
|
43 using Trakers.Tracking.Events; |
|
44 using Trakers.Tracking.Gestures; |
|
45 using System.Resources; |
|
46 using System.Reflection; |
|
47 using System.Timers; |
|
48 using Trakers.Communication; |
|
49 |
|
50 namespace Trakers.Debug |
|
51 { |
|
52 public partial class DebugWindow : Window |
|
53 { |
|
54 //Gestionnaire de ressources. |
|
55 private ResourceManager rm; |
|
56 //Timer. |
|
57 private System.Timers.Timer _timer; |
|
58 //Membre permettant d'atteindre la classe KinectMain du sous-module Tracking. |
|
59 private KinectMain kinectMain; |
|
60 //Tableau contenant une image en couleurs. |
|
61 private byte[] colorPixelData; |
|
62 //Indique si la kinect est allumée/éteinte. |
|
63 private bool on; |
|
64 //Indique si la fenêtre de debug est actuellement en cours de fermeture. |
|
65 private bool closing; |
|
66 //Indique si l'image doit être raffraichie. |
|
67 private Boolean refreshImage; |
|
68 |
|
69 /* |
|
70 * Constructeur : Affiche la fenêtre de debug en lui passant en paramètre une instanciation de la |
|
71 * classe KinectMain. |
|
72 * Au départ, la kinect est éteinte. |
|
73 */ |
|
74 public DebugWindow(KinectMain main) |
|
75 { |
|
76 rm = new ResourceManager("Trakers.Properties.resources", Assembly.GetExecutingAssembly()); |
|
77 InitializeComponent(); |
|
78 kinectMain = main; |
|
79 on = true; |
|
80 closing = false; |
|
81 refreshImage = true; |
|
82 |
|
83 try |
|
84 { |
|
85 //On instancie le timer à N ms. |
|
86 _timer = new System.Timers.Timer(kinectMain.getTimerElapsing()); |
|
87 //Dès que le timer est expiré, on appelle _timer_Elapsed. |
|
88 _timer.Elapsed += new ElapsedEventHandler(_timer_Elapsed); |
|
89 } |
|
90 catch (Exception){} |
|
91 } |
|
92 |
|
93 /* |
|
94 * Méthode appelée à l'expiration du timer pour les gestures et modes. |
|
95 */ |
|
96 public void _timer_Elapsed(object sender, ElapsedEventArgs e) |
|
97 { |
|
98 //On débloque le raffraichissement de l'image. |
|
99 refreshImage = true; |
|
100 //On arrête le timer. |
|
101 _timer.Stop(); |
|
102 } |
|
103 |
|
104 /* |
|
105 * Getter pour le membre indiquant la fermeture de la fenêtre de debug. |
|
106 */ |
|
107 public bool isClosing() |
|
108 { |
|
109 return closing; |
|
110 } |
|
111 |
|
112 /* |
|
113 * Est appelée à la fermeture de la fenêtre. |
|
114 */ |
|
115 private void Window_Closed(object sender, EventArgs e) |
|
116 { |
|
117 closing = true; |
|
118 //On éteint la Kinect (pour éviter qu'elle reste allumée même lorsque le programme est éteint). |
|
119 kinectMain.KinectClose(); |
|
120 } |
|
121 |
|
122 /* |
|
123 * Bouton ON/OFF. |
|
124 */ |
|
125 private void Switch_Click(object sender, RoutedEventArgs e) |
|
126 { |
|
127 //S'il valait faux, il vaut vrai maintenant et inversement. |
|
128 on = !on; |
|
129 //Si la kinect est allumée. |
|
130 if (on) |
|
131 { |
|
132 //Il affiche OFF (pour éteindre la kinect). |
|
133 Switch.Content = "OFF"; |
|
134 //On vide le label des exceptions. |
|
135 ExceptionLbl.Content = ""; |
|
136 //On initialise la Kinect. |
|
137 kinectMain.KinectInitialization(); |
|
138 } |
|
139 else |
|
140 { |
|
141 //Il affiche ON (pour allumer la kinect). |
|
142 Switch.Content = "ON"; |
|
143 //On remet à zéro tous les éléments du retour visuel. |
|
144 R1.Fill = System.Windows.Media.Brushes.DarkGray; |
|
145 R2.Fill = System.Windows.Media.Brushes.DarkGray; |
|
146 R3.Fill = System.Windows.Media.Brushes.DarkGray; |
|
147 R4.Fill = System.Windows.Media.Brushes.DarkGray; |
|
148 DistanceLbl.Content = "Distance :"; |
|
149 LeftHand.Background = System.Windows.Media.Brushes.DarkGray; |
|
150 LeftHand.Content = ""; |
|
151 RightHand.Background = System.Windows.Media.Brushes.DarkGray; |
|
152 RightHand.Content = ""; |
|
153 DebugCanvas.Children.RemoveRange(1, DebugCanvas.Children.Count - 1); |
|
154 //On éteint la Kinect. |
|
155 kinectMain.KinectClose(); |
|
156 } |
|
157 } |
|
158 |
|
159 /* |
|
160 * Récupère le flux video et met à jour le rendu visuel de debug. |
|
161 */ |
|
162 public void RefreshVideo(AllFramesReadyEventArgs e) |
|
163 { |
|
164 if (refreshImage) |
|
165 { |
|
166 bool receivedData = false; |
|
167 ColorImageFrame colorImageFrameData; |
|
168 using (colorImageFrameData = e.OpenColorImageFrame()) |
|
169 { |
|
170 //Si on ne reçoit pas de trames de la kinect. |
|
171 if (colorImageFrameData == null) |
|
172 { |
|
173 //L'image est supprimée. |
|
174 DebugImage.Source = null; |
|
175 } |
|
176 //Si le tableau stockant l'image en cours est nul. |
|
177 if (colorPixelData == null) |
|
178 //On alloue un nouveau tableau. |
|
179 colorPixelData = new byte[colorImageFrameData.PixelDataLength]; |
|
180 else |
|
181 { |
|
182 try |
|
183 { |
|
184 //Sinon on met à jour le tableau en copiant le contenu de la trame dans le tableau. |
|
185 colorImageFrameData.CopyPixelDataTo(colorPixelData); |
|
186 receivedData = true; |
|
187 } |
|
188 catch (Exception) { } |
|
189 } |
|
190 } |
|
191 //Si on a des données dans le tableau et que la kinect est allumée. |
|
192 if (receivedData && on) |
|
193 { |
|
194 //On met à jour l'image de la caméra. |
|
195 DebugImage.Source = BitmapSource.Create(colorImageFrameData.Width, colorImageFrameData.Height, 96, 96, PixelFormats.Bgr32, null, colorPixelData, colorImageFrameData.Width * colorImageFrameData.BytesPerPixel); |
|
196 DebugImage.HorizontalAlignment = System.Windows.HorizontalAlignment.Center; |
|
197 DebugImage.VerticalAlignment = System.Windows.VerticalAlignment.Center; |
|
198 DebugImage.Stretch = Stretch.Fill; |
|
199 //On annule l'image associée aux gestures. |
|
200 Gestures.Source = null; |
|
201 } |
|
202 } |
|
203 } |
|
204 |
|
205 /* |
|
206 * Affiche la distance de l'utilisateur dans le rendu visuel. |
|
207 * Sous forme de nombre en m et de rectangles changeant de couleur en fonction de la distance. |
|
208 */ |
|
209 public void showDistance(float proximity) |
|
210 { |
|
211 DistanceLbl.Content = "Proximity : " + proximity + "%"; |
|
212 |
|
213 if (proximity == 0) |
|
214 { |
|
215 R0.Fill = System.Windows.Media.Brushes.DarkGray; |
|
216 R1.Fill = System.Windows.Media.Brushes.DarkGray; |
|
217 R2.Fill = System.Windows.Media.Brushes.DarkGray; |
|
218 R3.Fill = System.Windows.Media.Brushes.DarkGray; |
|
219 R4.Fill = System.Windows.Media.Brushes.DarkGray; |
|
220 R5.Fill = System.Windows.Media.Brushes.DarkGray; |
|
221 R6.Fill = System.Windows.Media.Brushes.DarkGray; |
|
222 R7.Fill = System.Windows.Media.Brushes.DarkGray; |
|
223 R8.Fill = System.Windows.Media.Brushes.DarkGray; |
|
224 R9.Fill = System.Windows.Media.Brushes.DarkGray; |
|
225 R10.Fill = System.Windows.Media.Brushes.DarkGray; |
|
226 } |
|
227 else if (proximity > 0 && proximity < 10) |
|
228 { |
|
229 R0.Fill = System.Windows.Media.Brushes.DarkGray; |
|
230 R1.Fill = System.Windows.Media.Brushes.DarkGray; |
|
231 R2.Fill = System.Windows.Media.Brushes.DarkGray; |
|
232 R3.Fill = System.Windows.Media.Brushes.DarkGray; |
|
233 R4.Fill = System.Windows.Media.Brushes.DarkGray; |
|
234 R5.Fill = System.Windows.Media.Brushes.DarkGray; |
|
235 R6.Fill = System.Windows.Media.Brushes.DarkGray; |
|
236 R7.Fill = System.Windows.Media.Brushes.DarkGray; |
|
237 R8.Fill = System.Windows.Media.Brushes.DarkGray; |
|
238 R9.Fill = System.Windows.Media.Brushes.DarkGray; |
|
239 R10.Fill = System.Windows.Media.Brushes.Red; |
|
240 } |
|
241 else if (proximity > 10 && proximity < 20) |
|
242 { |
|
243 R0.Fill = System.Windows.Media.Brushes.DarkGray; |
|
244 R1.Fill = System.Windows.Media.Brushes.DarkGray; |
|
245 R2.Fill = System.Windows.Media.Brushes.DarkGray; |
|
246 R3.Fill = System.Windows.Media.Brushes.DarkGray; |
|
247 R4.Fill = System.Windows.Media.Brushes.DarkGray; |
|
248 R5.Fill = System.Windows.Media.Brushes.DarkGray; |
|
249 R6.Fill = System.Windows.Media.Brushes.DarkGray; |
|
250 R7.Fill = System.Windows.Media.Brushes.DarkGray; |
|
251 R8.Fill = System.Windows.Media.Brushes.DarkGray; |
|
252 R9.Fill = System.Windows.Media.Brushes.Red; |
|
253 R10.Fill = System.Windows.Media.Brushes.Red; |
|
254 } |
|
255 else if (proximity > 20 && proximity < 30) |
|
256 { |
|
257 R0.Fill = System.Windows.Media.Brushes.DarkGray; |
|
258 R1.Fill = System.Windows.Media.Brushes.DarkGray; |
|
259 R2.Fill = System.Windows.Media.Brushes.DarkGray; |
|
260 R3.Fill = System.Windows.Media.Brushes.DarkGray; |
|
261 R4.Fill = System.Windows.Media.Brushes.DarkGray; |
|
262 R5.Fill = System.Windows.Media.Brushes.DarkGray; |
|
263 R6.Fill = System.Windows.Media.Brushes.DarkGray; |
|
264 R7.Fill = System.Windows.Media.Brushes.DarkGray; |
|
265 R8.Fill = System.Windows.Media.Brushes.Red; |
|
266 R9.Fill = System.Windows.Media.Brushes.Red; |
|
267 R10.Fill = System.Windows.Media.Brushes.Red; |
|
268 } |
|
269 else if (proximity > 30 && proximity < 40) |
|
270 { |
|
271 R0.Fill = System.Windows.Media.Brushes.DarkGray; |
|
272 R1.Fill = System.Windows.Media.Brushes.DarkGray; |
|
273 R2.Fill = System.Windows.Media.Brushes.DarkGray; |
|
274 R3.Fill = System.Windows.Media.Brushes.DarkGray; |
|
275 R4.Fill = System.Windows.Media.Brushes.DarkGray; |
|
276 R5.Fill = System.Windows.Media.Brushes.DarkGray; |
|
277 R6.Fill = System.Windows.Media.Brushes.DarkGray; |
|
278 R7.Fill = System.Windows.Media.Brushes.Orange; |
|
279 R8.Fill = System.Windows.Media.Brushes.Red; |
|
280 R9.Fill = System.Windows.Media.Brushes.Red; |
|
281 R10.Fill = System.Windows.Media.Brushes.Red; |
|
282 } |
|
283 else if (proximity > 40 && proximity < 50) |
|
284 { |
|
285 R0.Fill = System.Windows.Media.Brushes.DarkGray; |
|
286 R1.Fill = System.Windows.Media.Brushes.DarkGray; |
|
287 R2.Fill = System.Windows.Media.Brushes.DarkGray; |
|
288 R3.Fill = System.Windows.Media.Brushes.DarkGray; |
|
289 R4.Fill = System.Windows.Media.Brushes.DarkGray; |
|
290 R5.Fill = System.Windows.Media.Brushes.DarkGray; |
|
291 R6.Fill = System.Windows.Media.Brushes.Orange; |
|
292 R7.Fill = System.Windows.Media.Brushes.Orange; |
|
293 R8.Fill = System.Windows.Media.Brushes.Red; |
|
294 R9.Fill = System.Windows.Media.Brushes.Red; |
|
295 R10.Fill = System.Windows.Media.Brushes.Red; |
|
296 } |
|
297 else if (proximity > 50 && proximity < 60) |
|
298 { |
|
299 R0.Fill = System.Windows.Media.Brushes.DarkGray; |
|
300 R1.Fill = System.Windows.Media.Brushes.DarkGray; |
|
301 R2.Fill = System.Windows.Media.Brushes.DarkGray; |
|
302 R3.Fill = System.Windows.Media.Brushes.DarkGray; |
|
303 R4.Fill = System.Windows.Media.Brushes.DarkGray; |
|
304 R5.Fill = System.Windows.Media.Brushes.Orange; |
|
305 R6.Fill = System.Windows.Media.Brushes.Orange; |
|
306 R7.Fill = System.Windows.Media.Brushes.Orange; |
|
307 R8.Fill = System.Windows.Media.Brushes.Red; |
|
308 R9.Fill = System.Windows.Media.Brushes.Red; |
|
309 R10.Fill = System.Windows.Media.Brushes.Red; |
|
310 } |
|
311 else if (proximity > 60 && proximity < 70) |
|
312 { |
|
313 R0.Fill = System.Windows.Media.Brushes.DarkGray; |
|
314 R1.Fill = System.Windows.Media.Brushes.DarkGray; |
|
315 R2.Fill = System.Windows.Media.Brushes.DarkGray; |
|
316 R3.Fill = System.Windows.Media.Brushes.DarkGray; |
|
317 R4.Fill = System.Windows.Media.Brushes.Yellow; |
|
318 R5.Fill = System.Windows.Media.Brushes.Orange; |
|
319 R6.Fill = System.Windows.Media.Brushes.Orange; |
|
320 R7.Fill = System.Windows.Media.Brushes.Orange; |
|
321 R8.Fill = System.Windows.Media.Brushes.Red; |
|
322 R9.Fill = System.Windows.Media.Brushes.Red; |
|
323 R10.Fill = System.Windows.Media.Brushes.Red; |
|
324 } |
|
325 else if (proximity > 70 && proximity < 80) |
|
326 { |
|
327 R0.Fill = System.Windows.Media.Brushes.DarkGray; |
|
328 R1.Fill = System.Windows.Media.Brushes.DarkGray; |
|
329 R2.Fill = System.Windows.Media.Brushes.DarkGray; |
|
330 R3.Fill = System.Windows.Media.Brushes.Yellow; |
|
331 R4.Fill = System.Windows.Media.Brushes.Yellow; |
|
332 R5.Fill = System.Windows.Media.Brushes.Orange; |
|
333 R6.Fill = System.Windows.Media.Brushes.Orange; |
|
334 R7.Fill = System.Windows.Media.Brushes.Orange; |
|
335 R8.Fill = System.Windows.Media.Brushes.Red; |
|
336 R9.Fill = System.Windows.Media.Brushes.Red; |
|
337 R10.Fill = System.Windows.Media.Brushes.Red; |
|
338 } |
|
339 else if (proximity > 80 && proximity < 90) |
|
340 { |
|
341 R0.Fill = System.Windows.Media.Brushes.DarkGray; |
|
342 R1.Fill = System.Windows.Media.Brushes.DarkGray; |
|
343 R2.Fill = System.Windows.Media.Brushes.Yellow; |
|
344 R3.Fill = System.Windows.Media.Brushes.Yellow; |
|
345 R4.Fill = System.Windows.Media.Brushes.Yellow; |
|
346 R5.Fill = System.Windows.Media.Brushes.Orange; |
|
347 R6.Fill = System.Windows.Media.Brushes.Orange; |
|
348 R7.Fill = System.Windows.Media.Brushes.Orange; |
|
349 R8.Fill = System.Windows.Media.Brushes.Red; |
|
350 R9.Fill = System.Windows.Media.Brushes.Red; |
|
351 R10.Fill = System.Windows.Media.Brushes.Red; |
|
352 } |
|
353 else if (proximity > 90 && proximity < 100) |
|
354 { |
|
355 R0.Fill = System.Windows.Media.Brushes.DarkGray; |
|
356 R1.Fill = System.Windows.Media.Brushes.Yellow; |
|
357 R2.Fill = System.Windows.Media.Brushes.Yellow; |
|
358 R3.Fill = System.Windows.Media.Brushes.Yellow; |
|
359 R4.Fill = System.Windows.Media.Brushes.Yellow; |
|
360 R5.Fill = System.Windows.Media.Brushes.Orange; |
|
361 R6.Fill = System.Windows.Media.Brushes.Orange; |
|
362 R7.Fill = System.Windows.Media.Brushes.Orange; |
|
363 R8.Fill = System.Windows.Media.Brushes.Red; |
|
364 R9.Fill = System.Windows.Media.Brushes.Red; |
|
365 R10.Fill = System.Windows.Media.Brushes.Red; |
|
366 } |
|
367 else if (proximity == 100) |
|
368 { |
|
369 R0.Fill = System.Windows.Media.Brushes.Green; |
|
370 R1.Fill = System.Windows.Media.Brushes.Yellow; |
|
371 R2.Fill = System.Windows.Media.Brushes.Yellow; |
|
372 R3.Fill = System.Windows.Media.Brushes.Yellow; |
|
373 R4.Fill = System.Windows.Media.Brushes.Yellow; |
|
374 R5.Fill = System.Windows.Media.Brushes.Orange; |
|
375 R6.Fill = System.Windows.Media.Brushes.Orange; |
|
376 R7.Fill = System.Windows.Media.Brushes.Orange; |
|
377 R8.Fill = System.Windows.Media.Brushes.Red; |
|
378 R9.Fill = System.Windows.Media.Brushes.Red; |
|
379 R10.Fill = System.Windows.Media.Brushes.Red; |
|
380 } |
|
381 } |
|
382 |
|
383 /* |
|
384 * Affiche la détection de la main droite via un label. |
|
385 */ |
|
386 public void showRightHandRect(bool show) |
|
387 { |
|
388 if (show) |
|
389 RightHand.Background = System.Windows.Media.Brushes.Blue; |
|
390 else |
|
391 RightHand.Background = System.Windows.Media.Brushes.DarkGray; |
|
392 } |
|
393 |
|
394 /* |
|
395 * Affiche la détection de la main gauche via un label. |
|
396 */ |
|
397 public void showLeftHandRect(bool show) |
|
398 { |
|
399 if (show) |
|
400 LeftHand.Background = System.Windows.Media.Brushes.Blue; |
|
401 else |
|
402 LeftHand.Background = System.Windows.Media.Brushes.DarkGray; |
|
403 } |
|
404 |
|
405 /* |
|
406 * Dessine les noeuds du squelette dans le rendu visuel. |
|
407 */ |
|
408 public void drawJoints(JointCollection joints, Skeleton first) |
|
409 { |
|
410 if (refreshImage) |
|
411 { |
|
412 //On enlève tout élément du Canvas à part l'image, de manière à mettre à jour la position du squelette. |
|
413 DebugCanvas.Children.RemoveRange(1, DebugCanvas.Children.Count - 1); |
|
414 |
|
415 //Pour chaque noeud. |
|
416 foreach (Joint joint in first.Joints) |
|
417 { |
|
418 //On crée une ellipse de taille 20 et de largeur 20. |
|
419 Ellipse node = new Ellipse(); |
|
420 node.Height = 20; |
|
421 node.Width = 20; |
|
422 |
|
423 //S'il s'agit d'un noeud de tête, on le colorie en rouge, sinon en bleu. |
|
424 if (joint.JointType == JointType.Head) |
|
425 node.Fill = System.Windows.Media.Brushes.Red; |
|
426 else if (joint.JointType == JointType.ShoulderCenter) |
|
427 node.Fill = System.Windows.Media.Brushes.Green; |
|
428 else if (joint.JointType == JointType.HipCenter) |
|
429 node.Fill = System.Windows.Media.Brushes.Green; |
|
430 else if (joint.JointType == JointType.HandRight) |
|
431 node.Fill = System.Windows.Media.Brushes.Red; |
|
432 else |
|
433 node.Fill = System.Windows.Media.Brushes.Blue; |
|
434 |
|
435 //On met à la bonne échelle les coordonnées des positions des noeuds. |
|
436 Joint scaledJoint = Coding4Fun.Kinect.Wpf.SkeletalExtensions.ScaleTo(joint, 600, 400, 0.75f, 0.75f); |
|
437 |
|
438 //On positionne le noeud dans le Canvas, et on l'ajoute. |
|
439 Canvas.SetLeft(node, scaledJoint.Position.X); |
|
440 Canvas.SetTop(node, scaledJoint.Position.Y); |
|
441 DebugCanvas.Children.Add(node); |
|
442 } |
|
443 } |
|
444 } |
|
445 |
|
446 /* |
|
447 * Dessine un os, en ayant en paramètres deux noeuds. |
|
448 */ |
|
449 public void drawBone(Joint j1, Joint j2) |
|
450 { |
|
451 //On crée une nouvelle ligne verte d'épaisseur 8 entre les deux noeuds et on l'ajoute au Canvas. |
|
452 Line line = new Line(); |
|
453 line.Stroke = System.Windows.Media.Brushes.Green; |
|
454 line.X1 = j1.Position.X; |
|
455 line.X2 = j2.Position.X; |
|
456 line.Y1 = j1.Position.Y; |
|
457 line.Y2 = j2.Position.Y; |
|
458 line.StrokeThickness = 8; |
|
459 DebugCanvas.Children.Add(line); |
|
460 } |
|
461 |
|
462 /* |
|
463 * Dessine le squelette (ensemble des os), en ayant en paramètres tous les noeuds. |
|
464 */ |
|
465 public void showSkeleton(Joint hipCenter, Joint spine, Joint shoulderCenter, Joint head, Joint shoulderLeft, Joint elbowLeft, Joint wristLeft, Joint handLeft, Joint shoulderRight, Joint elbowRight, Joint wristRight, Joint handRight, Joint hipLeft, Joint kneeLeft, Joint ankleLeft, Joint footLeft, Joint hipRight, Joint kneeRight, Joint ankleRight, Joint footRight) |
|
466 { |
|
467 if (refreshImage) |
|
468 { |
|
469 //On met les noeuds deux par deux en fonction de leur position dans le squelette. |
|
470 drawBone(head, shoulderCenter); |
|
471 drawBone(shoulderCenter, shoulderLeft); |
|
472 drawBone(shoulderLeft, elbowLeft); |
|
473 drawBone(elbowLeft, wristLeft); |
|
474 drawBone(wristLeft, handLeft); |
|
475 drawBone(shoulderCenter, shoulderRight); |
|
476 drawBone(shoulderRight, elbowRight); |
|
477 drawBone(elbowRight, wristRight); |
|
478 drawBone(wristRight, handRight); |
|
479 drawBone(shoulderCenter, spine); |
|
480 drawBone(spine, hipCenter); |
|
481 drawBone(hipCenter, hipLeft); |
|
482 drawBone(hipLeft, kneeLeft); |
|
483 drawBone(kneeLeft, ankleLeft); |
|
484 drawBone(ankleLeft, footLeft); |
|
485 drawBone(hipCenter, hipRight); |
|
486 drawBone(hipRight, kneeRight); |
|
487 drawBone(kneeRight, ankleRight); |
|
488 drawBone(ankleRight, footRight); |
|
489 } |
|
490 } |
|
491 |
|
492 /* |
|
493 * Cache le squelette et le reste de l'interface à part l'image. |
|
494 */ |
|
495 public void hideSkeleton() |
|
496 { |
|
497 //On vide le canvas mais en gardant l'image. |
|
498 if(DebugCanvas.Children.Count > 1) |
|
499 DebugCanvas.Children.RemoveRange(1, DebugCanvas.Children.Count - 1); |
|
500 //On colore en gris tous les indicateurs. |
|
501 R0.Fill = System.Windows.Media.Brushes.DarkGray; |
|
502 R1.Fill = System.Windows.Media.Brushes.DarkGray; |
|
503 R2.Fill = System.Windows.Media.Brushes.DarkGray; |
|
504 R3.Fill = System.Windows.Media.Brushes.DarkGray; |
|
505 R4.Fill = System.Windows.Media.Brushes.DarkGray; |
|
506 R5.Fill = System.Windows.Media.Brushes.DarkGray; |
|
507 R6.Fill = System.Windows.Media.Brushes.DarkGray; |
|
508 R7.Fill = System.Windows.Media.Brushes.DarkGray; |
|
509 R8.Fill = System.Windows.Media.Brushes.DarkGray; |
|
510 R9.Fill = System.Windows.Media.Brushes.DarkGray; |
|
511 R10.Fill = System.Windows.Media.Brushes.DarkGray; |
|
512 } |
|
513 |
|
514 /* |
|
515 * Affiche la position de la main gauche dans le rendu visuel. |
|
516 */ |
|
517 public void showLeftHandCoord(String coord) |
|
518 { |
|
519 LeftHand.Content = coord; |
|
520 } |
|
521 |
|
522 /* |
|
523 * Affiche la position de la main gauche dans le rendu visuel. |
|
524 */ |
|
525 public void showRightHandCoord(String coord) |
|
526 { |
|
527 RightHand.Content = coord; |
|
528 } |
|
529 |
|
530 /* |
|
531 * Méthode associée à l'événement : Ouvrir la fenêtre de paramétrage via le menu. |
|
532 */ |
|
533 private void Parameters_Click(object sender, RoutedEventArgs e) |
|
534 { |
|
535 DebugParameters param = new DebugParameters(kinectMain); |
|
536 |
|
537 try |
|
538 { |
|
539 param.ShowDialog(); |
|
540 } |
|
541 catch (Exception) |
|
542 { |
|
543 ExceptionLbl.Content = rm.GetString("loadParamFail"); |
|
544 } |
|
545 } |
|
546 |
|
547 /* |
|
548 * Méthode associée à l'événement : Quitter via le menu. |
|
549 */ |
|
550 private void Quit_Click(object sender, RoutedEventArgs e) |
|
551 { |
|
552 closing = true; |
|
553 //On éteint la Kinect (pour éviter qu'elle reste allumée même lorsque le programme est éteint). |
|
554 kinectMain.KinectClose(); |
|
555 Application.Current.Shutdown(); |
|
556 } |
|
557 |
|
558 /* |
|
559 * Permet d'initialiser la Kinect dès que la fenêtre est lancée. |
|
560 */ |
|
561 private void Window_Loaded(object sender, RoutedEventArgs e) |
|
562 { |
|
563 kinectMain.KinectInitialization(); |
|
564 } |
|
565 |
|
566 /* |
|
567 * Méthode d'affichage des gestures. |
|
568 */ |
|
569 public void showGesture(String gesture) |
|
570 { |
|
571 if (refreshImage) |
|
572 { |
|
573 refreshImage = false; |
|
574 _timer.Start(); |
|
575 Bitmap bitmap = null; |
|
576 //S'il s'agit de telle ou telle gesture, on prend l'image correspondante dans les ressources, |
|
577 //on la convertit et on l'affiche. |
|
578 switch (gesture) |
|
579 { |
|
580 case "SWIPE-LEFT": bitmap = (Bitmap)rm.GetObject("swipe_left"); |
|
581 break; |
|
582 case "SWIPE-RIGHT": bitmap = (Bitmap)rm.GetObject("swipe_right"); |
|
583 break; |
|
584 case "PUSH-RIGHT": bitmap = (Bitmap)rm.GetObject("push_right"); |
|
585 break; |
|
586 case "PUSH-LEFT": bitmap = (Bitmap)rm.GetObject("push_left"); |
|
587 break; |
|
588 case "PUSH-BOTH": bitmap = (Bitmap)rm.GetObject("push_both"); |
|
589 break; |
|
590 case "PULL-RIGHT": bitmap = (Bitmap)rm.GetObject("pull_right"); |
|
591 break; |
|
592 case "PULL-LEFT": bitmap = (Bitmap)rm.GetObject("pull_left"); |
|
593 break; |
|
594 case "PULL-BOTH": bitmap = (Bitmap)rm.GetObject("pull_both"); |
|
595 break; |
|
596 } |
|
597 Gestures.Source = CreateBitmapSourceFromBitmap(bitmap); |
|
598 } |
|
599 |
|
600 DebugImage.Source = null; |
|
601 hideSkeleton(); |
|
602 } |
|
603 |
|
604 /* |
|
605 * Méthode d'indication de raffraichissement de l'image ("on la raffraichit ou pas ?"). |
|
606 */ |
|
607 public void setRefreshImage(bool refresh) |
|
608 { |
|
609 refreshImage = refresh; |
|
610 } |
|
611 |
|
612 /* |
|
613 * Méthode de conversion de Bitmap (des ressources) en BitmapSource (du debug). |
|
614 */ |
|
615 public static BitmapSource CreateBitmapSourceFromBitmap(Bitmap bitmap) |
|
616 { |
|
617 if (bitmap == null) |
|
618 return null; |
|
619 |
|
620 return System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap( |
|
621 bitmap.GetHbitmap(), |
|
622 IntPtr.Zero, |
|
623 Int32Rect.Empty, |
|
624 BitmapSizeOptions.FromEmptyOptions()); |
|
625 } |
|
626 } |
|
627 } |
|