| changeset 6 | 93dfb08dcc97 |
| parent 5 | d40f84d77db4 |
| child 7 | 8a21bec5d45f |
| 5:d40f84d77db4 | 6:93dfb08dcc97 |
|---|---|
54 public delegate void SwipeHandler(object o, SwipeEventArgs e); |
54 public delegate void SwipeHandler(object o, SwipeEventArgs e); |
55 //Il s'agit de la fonction permettant d'appeler les fonctions des événements Push/Pull. |
55 //Il s'agit de la fonction permettant d'appeler les fonctions des événements Push/Pull. |
56 public delegate void PushHandler(object o, PushEventArgs e); |
56 public delegate void PushHandler(object o, PushEventArgs e); |
57 //Il s'agit de la fonction permettant d'appeler les fonctions des événements Jump. |
57 //Il s'agit de la fonction permettant d'appeler les fonctions des événements Jump. |
58 public delegate void JumpHandler(object o, JumpEventArgs e); |
58 public delegate void JumpHandler(object o, JumpEventArgs e); |
59 //Il s'agit de la fonction permettant d'appeler les fonctions des événements de proximité. |
|
60 public delegate void UserPositionHandler(object o, UserPositionEventArgs e); |
|
59 |
61 |
60 public class KinectMain |
62 public class KinectMain |
61 { |
63 { |
62 //Gestionnaire de ressources. |
64 //Gestionnaire de ressources. |
63 private ResourceManager rm; |
65 private ResourceManager rm; |
72 private SwipeDetector swipeDetector; |
74 private SwipeDetector swipeDetector; |
73 //Détecteur de pushes. |
75 //Détecteur de pushes. |
74 private PushDetector pushDetector; |
76 private PushDetector pushDetector; |
75 //Détecteur de jumps. |
77 //Détecteur de jumps. |
76 private JumpDetector jumpDetector; |
78 private JumpDetector jumpDetector; |
79 //Détecteur de proximité. |
|
80 private UserPositionDetector userPositionDetector; |
|
77 |
81 |
78 //Distances min/max délimitant le champ de recherche. |
82 //Distances min/max délimitant le champ de recherche. |
79 private float minDistHands; |
83 private float minDistHands; |
80 private float maxDistHands; |
84 private float maxDistHands; |
85 private float minDist; |
|
86 private float maxDist; |
|
87 private float zeroPoint; |
|
81 |
88 |
82 //Temps de rafraichissement pour le timer (Détection de gesture dans le serveur TUIO). |
89 //Temps de rafraichissement pour le timer (Détection de gesture dans le serveur TUIO). |
83 private int timerElapsing; |
90 private int timerElapsing; |
84 |
91 |
85 //Serveur TUIO pour la connexion du Middleware vers le Front Atelier. |
92 //Serveur TUIO pour la connexion du Middleware vers le Front Atelier. |
94 public static event SwipeHandler SwipeEvent; |
101 public static event SwipeHandler SwipeEvent; |
95 //L'événement push. |
102 //L'événement push. |
96 public static event PushHandler PushEvent; |
103 public static event PushHandler PushEvent; |
97 //L'événement jump. |
104 //L'événement jump. |
98 public static event JumpHandler JumpEvent; |
105 public static event JumpHandler JumpEvent; |
106 //L'événement l'utilisateur se déplace dans la zone de détection. |
|
107 public static event UserPositionHandler UserPositionEvent; |
|
99 |
108 |
100 private string connexionHost; |
109 private string connexionHost; |
101 private int connexionPort; |
110 private int connexionPort; |
102 |
111 |
103 /* |
112 /* |
110 //On fait appel au gestionnaire de ressources. |
119 //On fait appel au gestionnaire de ressources. |
111 rm = new ResourceManager("Trakers.Properties.resources", Assembly.GetExecutingAssembly()); |
120 rm = new ResourceManager("Trakers.Properties.resources", Assembly.GetExecutingAssembly()); |
112 //On crée la fenêtre de debug. |
121 //On crée la fenêtre de debug. |
113 debug = new Debug.DebugWindow(this); |
122 debug = new Debug.DebugWindow(this); |
114 |
123 |
124 //On tente de charger les paramètres du fichier params.ini. |
|
125 //Si on n'y arrive pas, on affiche une erreur et on charge les paramètres par défaut. |
|
126 if (!loadParameters()) |
|
127 { |
|
128 debug.ExceptionLbl.Content = rm.GetString("loadParametersFail"); |
|
129 //Distances de détection des mains par défaut pour la recherche (ici de 1m à 2m de la Kinect). |
|
130 minDistHands = 1.0f; |
|
131 maxDistHands = 1.5f; |
|
132 minDist = 1.0f; |
|
133 maxDist = 4.0f; |
|
134 zeroPoint = 1.7f; |
|
135 connexionHost = "127.0.0.1"; |
|
136 connexionPort = 80; |
|
137 timerElapsing = 1000; |
|
138 } |
|
139 |
|
115 //On crée les détecteurs de gestes. |
140 //On crée les détecteurs de gestes. |
116 swipeDetector = new SwipeDetector(debug); |
141 swipeDetector = new SwipeDetector(debug); |
117 pushDetector = new PushDetector(debug); |
142 pushDetector = new PushDetector(debug); |
118 jumpDetector = new JumpDetector(debug); |
143 jumpDetector = new JumpDetector(debug); |
119 |
144 //On crée le détecteur de proximité. |
120 //On tente de charger les paramètres du fichier params.ini. |
145 userPositionDetector = new UserPositionDetector(debug, minDist, maxDist, zeroPoint, minDistHands, maxDistHands); |
121 //Si on n'y arrive pas, on affiche une erreur et on charge les paramètres par défaut. |
|
122 if (!loadParameters()) |
|
123 { |
|
124 debug.ExceptionLbl.Content = rm.GetString("loadParametersFail"); |
|
125 //Distances de détection des mains par défaut pour la recherche (ici de 1m à 2m de la Kinect). |
|
126 minDistHands = (float)1.0; |
|
127 maxDistHands = (float)1.5; |
|
128 connexionHost = "127.0.0.1"; |
|
129 connexionPort = 80; |
|
130 timerElapsing = 1000; |
|
131 } |
|
132 |
146 |
133 //On affiche la fenêtre de debug. |
147 //On affiche la fenêtre de debug. |
134 try |
148 try |
135 { |
149 { |
136 debug.ShowDialog(); |
150 debug.ShowDialog(); |
208 PushEvent += new PushHandler(pushListener.ShowOnScreen); |
222 PushEvent += new PushHandler(pushListener.ShowOnScreen); |
209 |
223 |
210 //Fonction appelée lorsque l'utilisateur effectue un Jump. |
224 //Fonction appelée lorsque l'utilisateur effectue un Jump. |
211 JumpListener jumpListener = new JumpListener(); |
225 JumpListener jumpListener = new JumpListener(); |
212 JumpEvent += new JumpHandler(jumpListener.ShowOnScreen); |
226 JumpEvent += new JumpHandler(jumpListener.ShowOnScreen); |
227 |
|
228 //Fonction appelée lorsque l'utilisateur se déplace dans la zone de détection. |
|
229 UserPositionListener userPositionListener = new UserPositionListener(); |
|
230 UserPositionEvent += new UserPositionHandler(userPositionListener.ShowOnScreen); |
|
213 |
231 |
214 //On connecte le serveur à l'adresse locale sur le port 80. |
232 //On connecte le serveur à l'adresse locale sur le port 80. |
215 server = new Server(connexionHost, connexionPort, timerElapsing, debug); |
233 server = new Server(connexionHost, connexionPort, timerElapsing, debug); |
216 } |
234 } |
217 |
235 |
350 joints.Insert((int)JointType.HipRight, hipRight); |
368 joints.Insert((int)JointType.HipRight, hipRight); |
351 joints.Insert((int)JointType.KneeRight, kneeRight); |
369 joints.Insert((int)JointType.KneeRight, kneeRight); |
352 joints.Insert((int)JointType.AnkleRight, ankleRight); |
370 joints.Insert((int)JointType.AnkleRight, ankleRight); |
353 joints.Insert((int)JointType.FootRight, footRight); |
371 joints.Insert((int)JointType.FootRight, footRight); |
354 GestureDetector.UpdateSkeletonHistory(joints); |
372 GestureDetector.UpdateSkeletonHistory(joints); |
355 |
|
356 //On obtient sa distance à la Kinect. |
|
357 float distance = first.Position.Z; |
|
358 |
|
359 //On affiche la distance dans le debug. |
|
360 debug.showDistance(distance); |
|
361 |
373 |
362 //Si la main gauche est dans le champ, on lance l'événement approprié. |
374 //Si la main gauche est dans le champ, on lance l'événement approprié. |
363 if (handLeft.Position.Z < maxDistHands && handLeft.Position.Z > minDistHands) |
375 if (handLeft.Position.Z < maxDistHands && handLeft.Position.Z > minDistHands) |
364 { |
376 { |
365 LeftHandTrackedEventArgs leftHandTrackedEvent = new LeftHandTrackedEventArgs(handLeft, handLeft.Position.Z, debug, server); |
377 LeftHandTrackedEventArgs leftHandTrackedEvent = new LeftHandTrackedEventArgs(handLeft, handLeft.Position.Z, debug, server); |
418 { |
430 { |
419 JumpEventArgs jumpEvent = new JumpEventArgs(debug, server); |
431 JumpEventArgs jumpEvent = new JumpEventArgs(debug, server); |
420 OnJumpEvent(jumpEvent); |
432 OnJumpEvent(jumpEvent); |
421 }*/ |
433 }*/ |
422 |
434 |
435 //Si l'utilisateur se déplace dans la zone de détection. |
|
436 //On traite le problème en plusieurs limites, on discrétise la zone. |
|
437 if(first.TrackingState == SkeletonTrackingState.Tracked) |
|
438 { |
|
439 float proximity = userPositionDetector.CalcProximity(first.Position.Z); |
|
440 /*if (proximity > 0f && proximity < 25f) |
|
441 { |
|
442 Console.Out.WriteLine("1/4"); |
|
443 |
|
444 } |
|
445 else if (proximity > 25f && proximity < 50f) |
|
446 { |
|
447 Console.Out.WriteLine("1/2"); |
|
448 |
|
449 } |
|
450 else if (proximity > 50f && proximity < 75f) |
|
451 { |
|
452 Console.Out.WriteLine("3/4"); |
|
453 |
|
454 } |
|
455 else if (proximity == 100f) |
|
456 { |
|
457 Console.Out.WriteLine("TRUE"); |
|
458 |
|
459 }*/ |
|
460 |
|
461 if (proximity > 0f) |
|
462 { |
|
463 UserPositionEventArgs userPositionEvent = new UserPositionEventArgs(debug, server, proximity); |
|
464 OnUserPositionEvent(userPositionEvent); |
|
465 } |
|
466 else |
|
467 Console.Out.WriteLine("FAIL"); |
|
468 } |
|
469 |
|
423 //Dessine le squelette dans le debug. |
470 //Dessine le squelette dans le debug. |
424 debug.drawJoints(first.Joints, first); |
471 debug.drawJoints(first.Joints, first); |
425 debug.showSkeleton(hipCenter, spine, shoulderCenter, head, shoulderLeft, elbowLeft, wristLeft, handLeft, shoulderRight, elbowRight, wristRight, handRight, hipLeft, kneeLeft, ankleLeft, footLeft, hipRight, kneeRight, ankleRight, footRight); |
472 debug.showSkeleton(hipCenter, spine, shoulderCenter, head, shoulderLeft, elbowLeft, wristLeft, handLeft, shoulderRight, elbowRight, wristRight, handRight, hipLeft, kneeLeft, ankleLeft, footLeft, hipRight, kneeRight, ankleRight, footRight); |
426 } |
473 } |
427 } |
474 } |
496 if (JumpEvent != null) |
543 if (JumpEvent != null) |
497 JumpEvent(new object(), e); |
544 JumpEvent(new object(), e); |
498 } |
545 } |
499 |
546 |
500 /* |
547 /* |
548 * Initialise l'événement et fait appel aux fonctions du listener quand l'utilisateur se déplace |
|
549 * dans la zone de détection. |
|
550 */ |
|
551 public static void OnUserPositionEvent(UserPositionEventArgs e) |
|
552 { |
|
553 if (UserPositionEvent != null) |
|
554 UserPositionEvent(new object(), e); |
|
555 } |
|
556 |
|
557 /* |
|
501 * Méthode de chargement des paramètres (position du champ de recherche...). |
558 * Méthode de chargement des paramètres (position du champ de recherche...). |
502 */ |
559 */ |
503 public bool loadParameters() |
560 public bool loadParameters() |
504 { |
561 { |
505 try |
562 try |
506 { |
563 { |
507 minDistHands = (float)double.Parse(ConfigurationManager.AppSettings["searchMinDistance"]); |
564 minDistHands = (float)double.Parse(ConfigurationManager.AppSettings["searchMinDistance"]); |
508 maxDistHands = (float)double.Parse(ConfigurationManager.AppSettings["searchMaxDistance"]); |
565 maxDistHands = (float)double.Parse(ConfigurationManager.AppSettings["searchMaxDistance"]); |
566 minDist = (float)double.Parse(ConfigurationManager.AppSettings["minDistance"]); |
|
567 maxDist = (float)double.Parse(ConfigurationManager.AppSettings["maxDistance"]); |
|
568 zeroPoint = (float)double.Parse(ConfigurationManager.AppSettings["zeroPoint"]); |
|
509 connexionHost = ConfigurationManager.AppSettings["connexionHost"]; |
569 connexionHost = ConfigurationManager.AppSettings["connexionHost"]; |
510 connexionPort = int.Parse(ConfigurationManager.AppSettings["connexionPort"]); |
570 connexionPort = int.Parse(ConfigurationManager.AppSettings["connexionPort"]); |
511 timerElapsing = int.Parse(ConfigurationManager.AppSettings["timerElapsing"]); |
571 timerElapsing = int.Parse(ConfigurationManager.AppSettings["timerElapsing"]); |
512 } |
572 } |
513 catch (Exception) |
573 catch (Exception) |
514 { |
574 { |
515 return false; |
575 return false; |
516 } |
576 } |
517 |
577 |
518 if (maxDistHands <= 0 || minDistHands <= 0 || maxDistHands > 4 || minDistHands > 4 || minDistHands >= maxDistHands) |
578 if (maxDistHands <= 0f || minDistHands <= 0f || maxDistHands > maxDist || minDistHands > maxDist || |
579 minDistHands >= maxDistHands || zeroPoint < maxDistHands || minDistHands < minDist || |
|
580 zeroPoint >= maxDist || connexionPort < 0 || timerElapsing < 0) |
|
519 { |
581 { |
520 debug.ExceptionLbl.Content = rm.GetString("loadParametersIncorrect"); |
582 debug.ExceptionLbl.Content = rm.GetString("loadParametersIncorrect"); |
521 return false; |
583 return false; |
522 } |
584 } |
523 return true; |
585 return true; |
526 /* |
588 /* |
527 * Met à jour les nouveaux paramètres dans la configuration. |
589 * Met à jour les nouveaux paramètres dans la configuration. |
528 */ |
590 */ |
529 public void updateParameters() |
591 public void updateParameters() |
530 { |
592 { |
593 userPositionDetector.setParams(minDist, maxDist, minDistHands, maxDistHands, zeroPoint); |
|
594 |
|
531 //On récupère la config. |
595 //On récupère la config. |
532 Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); |
596 Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); |
533 //On met à jour. |
597 //On met à jour. |
534 config.AppSettings.Settings.Remove("searchMinDistance"); |
598 config.AppSettings.Settings.Remove("searchMinDistance"); |
535 config.AppSettings.Settings.Add("searchMinDistance", minDistHands.ToString()); |
599 config.AppSettings.Settings.Add("searchMinDistance", minDistHands.ToString()); |
536 config.AppSettings.Settings.Remove("searchMaxDistance"); |
600 config.AppSettings.Settings.Remove("searchMaxDistance"); |
537 config.AppSettings.Settings.Add("searchMaxDistance", maxDistHands.ToString()); |
601 config.AppSettings.Settings.Add("searchMaxDistance", maxDistHands.ToString()); |
602 config.AppSettings.Settings.Remove("minDistance"); |
|
603 config.AppSettings.Settings.Add("minDistance", minDist.ToString()); |
|
604 config.AppSettings.Settings.Remove("maxDistance"); |
|
605 config.AppSettings.Settings.Add("maxDistance", maxDist.ToString()); |
|
606 config.AppSettings.Settings.Remove("zeroPoint"); |
|
607 config.AppSettings.Settings.Add("zeroPoint", zeroPoint.ToString()); |
|
538 config.AppSettings.Settings.Remove("connexionHost"); |
608 config.AppSettings.Settings.Remove("connexionHost"); |
539 config.AppSettings.Settings.Add("connexionHost", connexionHost); |
609 config.AppSettings.Settings.Add("connexionHost", connexionHost); |
540 config.AppSettings.Settings.Remove("connexionPort"); |
610 config.AppSettings.Settings.Remove("connexionPort"); |
541 config.AppSettings.Settings.Add("connexionPort", connexionPort.ToString()); |
611 config.AppSettings.Settings.Add("connexionPort", connexionPort.ToString()); |
542 config.AppSettings.Settings.Remove("timerElapsing"); |
612 config.AppSettings.Settings.Remove("timerElapsing"); |