--- a/middleware/src/Tracking/KinectMain.cs Mon Mar 26 16:23:14 2012 +0200
+++ b/middleware/src/Tracking/KinectMain.cs Thu Mar 29 14:39:21 2012 +0200
@@ -20,6 +20,7 @@
* noeuds de son squelette. Lance des événements lorsque la main gauche/droite entre dans/quitte le champ.
* Envoie des données au sous-module de debug de manière a afficher un retour visuel sur la position de l'utilisateur,
* son squelette, la détection de ses mains.
+ * Découpe l'interaction avec le middleware en différents modes.
*/
using System;
@@ -67,8 +68,6 @@
public delegate void JumpHandler(object o, JumpEventArgs e);
//Il s'agit de la fonction permettant d'appeler les fonctions des événements de proximité.
public delegate void UserPositionHandler(object o, UserPositionEventArgs e);
- //Il s'agit de la fonctoin permettant de notifier le serveur en cas de changement de mode.
- public delegate void ModChangeHandler(object o, ModChangeEventArgs e);
public class KinectMain
{
@@ -97,6 +96,9 @@
private float maxDist;
private float zeroPoint;
private int imagesToShow;
+ private int takenPoints;
+ private int directionChangeTresholdXY;
+ private float directionChangeTresholdZ;
//Temps de rafraichissement pour le timer (Détection de gesture dans le serveur TUIO).
private int timerElapsing;
@@ -104,6 +106,9 @@
//Serveur TUIO pour la connexion du Middleware vers le Front Atelier.
private Server server;
+ //Gestionnaire de modes.
+ private ModeManagement modeManagement;
+
//Les événements des mains pour la recherche.
public static event LeftHandTrackedHandler LeftHandTrackedEvent;
public static event RightHandTrackedHandler RightHandTrackedEvent;
@@ -117,8 +122,6 @@
public static event JumpHandler JumpEvent;
//L'événement l'utilisateur se déplace dans la zone de détection.
public static event UserPositionHandler UserPositionEvent;
- //L'événement on change de mode.
- public static event ModChangeHandler ModChangeEvent;
private string connexionHost;
private int connexionPort;
@@ -148,6 +151,9 @@
connexionPort = 80;
timerElapsing = 1000;
imagesToShow = 25;
+ takenPoints = 10;
+ directionChangeTresholdXY = 10;
+ directionChangeTresholdZ = 0.01f;
}
//On crée la fenêtre de debug.
@@ -245,12 +251,11 @@
UserPositionListener userPositionListener = new UserPositionListener();
UserPositionEvent += new UserPositionHandler(userPositionListener.ShowOnScreen);
- //Fonction appelée lorsqu'on change de mode.
- ModChangeListener modChangeListener = new ModChangeListener();
- ModChangeEvent += new ModChangeHandler(modChangeListener.ShowOnScreen);
-
//On connecte le serveur à l'adresse locale sur le port 80.
server = new Server(connexionHost, connexionPort, timerElapsing, debug);
+
+ //On crée le gestionnaire de modes.
+ modeManagement = new ModeManagement(this, server, debug);
}
/*
@@ -400,7 +405,7 @@
//Si la main gauche quitte le champ, on lance l'événement approprié.
else
{
- LeftHandQuitEventArgs leftHandQuitEvent = new LeftHandQuitEventArgs(handLeft, handLeft.Position.Z, debug, server);
+ LeftHandQuitEventArgs leftHandQuitEvent = new LeftHandQuitEventArgs(debug, server);
OnLeftHandQuitEvent(leftHandQuitEvent);
}
//Si la main droite est dans le champ, on lance l'événement approprié.
@@ -412,7 +417,7 @@
//Si la main droite quitte le champ, on lance l'événement approprié.
else
{
- RightHandQuitEventArgs rightHandQuitEvent = new RightHandQuitEventArgs(handRight, handRight.Position.Z, debug, server);
+ RightHandQuitEventArgs rightHandQuitEvent = new RightHandQuitEventArgs(debug, server);
OnRightHandQuitEvent(rightHandQuitEvent);
}
@@ -459,6 +464,8 @@
float proximity = userPositionDetector.CalcProximity(first.Position.Z);
int numberOfImages = userPositionDetector.ImagesToShow(proximity, imagesToShow);
+ modeManagement.DetectProximityBasedModes(proximity, numberOfImages);
+
if (proximity > 0f)
{
UserPositionEventArgs userPositionEvent = new UserPositionEventArgs(debug, server, proximity, numberOfImages);
@@ -467,6 +474,10 @@
else
{
debug.hideSkeleton();
+ LeftHandQuitEventArgs leftHandQuitEvent = new LeftHandQuitEventArgs(debug, server);
+ OnLeftHandQuitEvent(leftHandQuitEvent);
+ RightHandQuitEventArgs rightHandQuitEvent = new RightHandQuitEventArgs(debug, server);
+ OnRightHandQuitEvent(rightHandQuitEvent);
}
}
@@ -475,7 +486,13 @@
debug.showSkeleton(hipCenter, spine, shoulderCenter, head, shoulderLeft, elbowLeft, wristLeft, handLeft, shoulderRight, elbowRight, wristRight, handRight, hipLeft, kneeLeft, ankleLeft, footLeft, hipRight, kneeRight, ankleRight, footRight);
}
else
+ {
debug.hideSkeleton();
+ LeftHandQuitEventArgs leftHandQuitEvent = new LeftHandQuitEventArgs(debug, server);
+ OnLeftHandQuitEvent(leftHandQuitEvent);
+ RightHandQuitEventArgs rightHandQuitEvent = new RightHandQuitEventArgs(debug, server);
+ OnRightHandQuitEvent(rightHandQuitEvent);
+ }
}
/*
@@ -560,15 +577,6 @@
}
/*
- * Initialise l'événement et fait appel aux fonctions du listener quand on change de mode.
- */
- public static void OnModChangeEvent(ModChangeEventArgs e)
- {
- if (ModChangeEvent != null)
- ModChangeEvent(new object(), e);
- }
-
- /*
* Méthode de chargement des paramètres (position du champ de recherche...).
*/
public bool loadParameters()
@@ -584,6 +592,9 @@
connexionPort = int.Parse(ConfigurationManager.AppSettings["connexionPort"]);
timerElapsing = int.Parse(ConfigurationManager.AppSettings["timerElapsing"]);
imagesToShow = int.Parse(ConfigurationManager.AppSettings["imagesToShow"]);
+ takenPoints = int.Parse(ConfigurationManager.AppSettings["takenPoints"]);
+ directionChangeTresholdXY = int.Parse(ConfigurationManager.AppSettings["directionChangeTresholdXY"]);
+ directionChangeTresholdZ = (float)double.Parse(ConfigurationManager.AppSettings["directionChangeTresholdZ"]);
}
catch (Exception)
{
@@ -592,7 +603,8 @@
if (maxDistHands <= 0f || minDistHands <= 0f || maxDistHands > maxDist || minDistHands > maxDist ||
minDistHands >= maxDistHands || zeroPoint < maxDistHands || minDistHands < minDist ||
- zeroPoint >= maxDist || connexionPort < 0 || timerElapsing < 0 || imagesToShow < 1)
+ zeroPoint >= maxDist || connexionPort < 0 || timerElapsing < 0 || imagesToShow < 1 ||
+ takenPoints <= 0 || directionChangeTresholdXY < 0 || directionChangeTresholdZ < 0)
{
debug.ExceptionLbl.Content = rm.GetString("loadParametersIncorrect");
return false;
@@ -606,6 +618,7 @@
public void updateParameters()
{
userPositionDetector.setParams(minDist, maxDist, minDistHands, maxDistHands, zeroPoint);
+ //segmenter.setParams(takenPoints, directionChangeTresholdXY, directionChangeTresholdZ);
//On récupère la config.
Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
@@ -628,6 +641,12 @@
config.AppSettings.Settings.Add("timerElapsing", timerElapsing.ToString());
config.AppSettings.Settings.Remove("imagesToShow");
config.AppSettings.Settings.Add("imagesToShow", imagesToShow.ToString());
+ config.AppSettings.Settings.Remove("takenPoints");
+ config.AppSettings.Settings.Add("takenPoints", takenPoints.ToString());
+ config.AppSettings.Settings.Remove("directionChangeTresholdXY");
+ config.AppSettings.Settings.Add("directionChangeTresholdXY", directionChangeTresholdXY.ToString());
+ config.AppSettings.Settings.Remove("directionChangeTresholdZ");
+ config.AppSettings.Settings.Add("directionChangeTresholdZ", directionChangeTresholdZ.ToString());
//Sauvegarde la configuration.
config.Save(ConfigurationSaveMode.Modified);
@@ -673,6 +692,18 @@
{
imagesToShow = _imagesToShow;
}
+ public void setTakenPoints(int _takenPoints)
+ {
+ takenPoints = _takenPoints;
+ }
+ public void setDirectionChangeTresholdXY(int _directionChangeTresholdXY)
+ {
+ directionChangeTresholdXY = _directionChangeTresholdXY;
+ }
+ public void setDirectionChangeTresholdZ(float _directionChangeTresholdZ)
+ {
+ directionChangeTresholdZ = _directionChangeTresholdZ;
+ }
public float getMinDistHands()
{
@@ -710,5 +741,17 @@
{
return imagesToShow;
}
+ public int getTakenPoints()
+ {
+ return takenPoints;
+ }
+ public int getDirectionChangeTresholdXY()
+ {
+ return directionChangeTresholdXY;
+ }
+ public float getDirectionChangeTresholdZ()
+ {
+ return directionChangeTresholdZ;
+ }
}
}