Ejemplo n.º 1
0
        /**
         * Checks if the skeleton data matches within certain
         * angles to the users
         */
        private bool SkeletonMatchesCloselyEnough(JointAngles ja)
        {
            if (first == null)
            {
                return(false);
            }
            int leftElbow     = AngleBetweenJoints(first.Joints[JointType.HandLeft], first.Joints[JointType.ElbowLeft], first.Joints[JointType.ShoulderLeft]);
            int rightElbow    = AngleBetweenJoints(first.Joints[JointType.HandRight], first.Joints[JointType.ElbowRight], first.Joints[JointType.ShoulderRight]);
            int rightShoulder = AngleBetweenJoints(first.Joints[JointType.ElbowRight], first.Joints[JointType.ShoulderRight], first.Joints[JointType.ShoulderCenter]);
            int leftHip       = AngleBetweenJoints(first.Joints[JointType.ShoulderLeft], first.Joints[JointType.HipLeft], first.Joints[JointType.KneeLeft]);
            int rightHip      = AngleBetweenJoints(first.Joints[JointType.ShoulderRight], first.Joints[JointType.HipRight], first.Joints[JointType.KneeRight]);
            int leftKnee      = AngleBetweenJoints(first.Joints[JointType.HipLeft], first.Joints[JointType.KneeLeft], first.Joints[JointType.FootLeft]);
            int rightKnee     = AngleBetweenJoints(first.Joints[JointType.HipRight], first.Joints[JointType.KneeRight], first.Joints[JointType.FootRight]);


            //Check if patient's joint angle is +- 20 degrees of the exercise
            if (leftElbow < (ja.leftElbow - 30) || leftElbow > (ja.leftElbow + 30))
            {
                suggestionBlock.Text = "Fix your left elbow!";
                return(false);
            }
            else if (rightElbow < (ja.rightElbow - 30) || rightElbow > (ja.rightElbow + 30))
            {
                suggestionBlock.Text = "Fix your right elbow!";
                return(false);
            }
            else if (leftHip < (ja.leftHip - 30) || leftHip > (ja.leftHip + 30))
            {
                suggestionBlock.Text = "Fix your left hip!";
                return(false);
            }
            else if (rightHip < (ja.rightHip - 30) || rightHip > (ja.rightHip + 30))
            {
                suggestionBlock.Text = "Fix your right hip!";
                return(false);
            }
            else if (rightKnee < (ja.rightKnee - 30) || rightKnee > (ja.rightKnee + 30))
            {
                suggestionBlock.Text = "Fix your right knee!";
                return(false);
            }
            else if (leftKnee < (ja.leftKnee - 30) || leftKnee > (ja.leftKnee + 30))
            {
                suggestionBlock.Text = "Fix your left knee!";
                return(false);
            }
            else if (rightShoulder < (ja.rightShoulder - 30) || rightShoulder > (ja.rightShoulder + 30))
            {
                suggestionBlock.Text = "Fix your right shoulder!";
                return(false);
            }
            else
            {
                return(true);
            }
        }
Ejemplo n.º 2
0
        private void loadExercise()
        {
            string      line;
            JointAngles ja = new JointAngles();

            loadedSkeleton = new List <JointAngles>();
            // Read the file and display it line by line.
            String path = System.AppDomain.CurrentDomain.BaseDirectory;

            path = System.IO.Directory.GetParent(path).FullName;
            path = System.IO.Directory.GetParent(path).FullName;
            path = System.IO.Directory.GetParent(path).FullName;
            path = System.IO.Directory.GetParent(path).FullName;

            System.IO.StreamReader file =
                new System.IO.StreamReader(path + "\\Recordings\\chosenExercise.txt");
            while ((line = file.ReadLine()) != null)
            {
                /*Add in time to check*/

                /* if (line.Contains("Time:"))
                 * {
                 *   foreach (var line in File.ReadAllLines("file").Where(line => line.StartsWith("Time:")))
                 * {
                 * int value = 0;
                 * if(int.TryParse(line.Replace("Time:", "").Trim(), out value))
                 * {
                 * foreach (var
                 * }
                 * }
                 * }*/


                if (line.Contains("Left Shoulder"))
                {
                    ja.leftShoulder = Convert.ToInt32(file.ReadLine());
                }
                else if (line.Contains("Right Shoulder"))
                {
                    ja.rightShoulder = Convert.ToInt32(file.ReadLine());
                }
                else if (line.Contains("Left Elbow"))
                {
                    ja.leftElbow = Convert.ToInt32(file.ReadLine());
                }
                else if (line.Contains("Left Hip"))
                {
                    ja.leftHip = Convert.ToInt32(file.ReadLine());
                }
                else if (line.Contains("Left Knee"))
                {
                    ja.leftKnee = Convert.ToInt32(file.ReadLine());
                }
                else if (line.Contains("Right Elbow"))
                {
                    ja.rightElbow = Convert.ToInt32(file.ReadLine());
                }
                else if (line.Contains("Right Hip"))
                {
                    ja.rightHip = Convert.ToInt32(file.ReadLine());
                }
                else if (line.Contains("Right Knee"))
                {
                    ja.rightKnee = Convert.ToInt32(file.ReadLine());
                }
                else if (line.Contains("End"))
                {
                    loadedSkeleton.Add(ja);
                    ja = new JointAngles();
                }
            }

            file.Close();

            // Suspend the screen.
            Console.ReadLine();
        }