public SkeletonFrameValidationData ValidateCurrentSkeletonFrame(Dictionary <JointType, List <MovementVector> > serverWorkoutVectors, BodyStructure body, Dictionary <JointType, float> distanceScale)
        {
            var result = new SkeletonFrameValidationData();

            foreach (var joint in body.currentFrameBody)
            {
                if (jointsOfInterest.Contains(joint.Key))
                {
                    lastPositions[0][joint.Key] = joint.Value;

                    switch (joint.Key)
                    {
                    case JointType.HandLeft:
                        CoordinatesListHandLeft.Add(joint.Value);
                        smoothingBuffer[joint.Key] = CoordinatesListHandLeft;
                        break;

                    case JointType.HandRight:
                        CoordinatesListHandRight.Add(joint.Value);
                        smoothingBuffer[joint.Key] = CoordinatesListHandRight;
                        break;

                    case JointType.KneeLeft:
                        CoordinatesListKneeLeft.Add(joint.Value);
                        smoothingBuffer[joint.Key] = CoordinatesListKneeLeft;
                        break;

                    case JointType.KneeRight:
                        CoordinatesListKneeRight.Add(joint.Value);
                        smoothingBuffer[joint.Key] = CoordinatesListKneeRight;
                        break;

                    case JointType.Head:
                        CoordinatesListHead.Add(joint.Value);
                        smoothingBuffer[joint.Key] = CoordinatesListHead;
                        break;

                    case JointType.SpineMid:
                        CoordinatesListSpineMid.Add(joint.Value);
                        smoothingBuffer[joint.Key] = CoordinatesListSpineMid;
                        break;
                    }
                }
            }
            var jointDirChange = IsDirChanged();

            UpdateMovementVectors(jointDirChange, distanceScale);

            result.BoneStates = new Dictionary <JointType, SkeletonBoneState>();

            CalculateVectors(serverWorkoutVectors, body, result);

            return(result);
        }
        public SkeletonFrameValidationData ValidateCurrentSkeletonFrame(Dictionary<JointType, List<MovementVector>> serverWorkoutVectors, BodyStructure body, Dictionary<JointType, float> distanceScale)
        {
            var result = new SkeletonFrameValidationData();

            foreach (var joint in body.currentFrameBody)
            {
                if (jointsOfInterest.Contains(joint.Key))
                {
                    lastPositions[0][joint.Key] = joint.Value;

                    switch (joint.Key)
                    {
                        case JointType.HandLeft:
                            CoordinatesListHandLeft.Add(joint.Value);
                            smoothingBuffer[joint.Key] = CoordinatesListHandLeft;
                            break;

                        case JointType.HandRight:
                            CoordinatesListHandRight.Add(joint.Value);
                            smoothingBuffer[joint.Key] = CoordinatesListHandRight;
                            break;

                        case JointType.KneeLeft:
                            CoordinatesListKneeLeft.Add(joint.Value);
                            smoothingBuffer[joint.Key] = CoordinatesListKneeLeft;
                            break;

                        case JointType.KneeRight:
                            CoordinatesListKneeRight.Add(joint.Value);
                            smoothingBuffer[joint.Key] = CoordinatesListKneeRight;
                            break;

                        case JointType.Head:
                            CoordinatesListHead.Add(joint.Value);
                            smoothingBuffer[joint.Key] = CoordinatesListHead;
                            break;

                        case JointType.SpineMid:
                            CoordinatesListSpineMid.Add(joint.Value);
                            smoothingBuffer[joint.Key] = CoordinatesListSpineMid;
                            break;
                    }

                }
            }
            var jointDirChange = IsDirChanged();

            UpdateMovementVectors(jointDirChange, distanceScale);

            result.BoneStates = new Dictionary<JointType, SkeletonBoneState>();

            CalculateVectors(serverWorkoutVectors, body, result);

            return result;
        }
        public void CalculateVectors(Dictionary<JointType, List<MovementVector>> serverPoints, BodyStructure body, SkeletonFrameValidationData result)
        {
            //We take the last calculated vector for each joint and compare it with the serverRecorded ones

            foreach (var joint in jointsOfInterest)
            {
                bool isFoundInServerVectors = false;

                var movementVectorLast = jointMovementVectors[joint];

                foreach (var serverVector in serverPoints[joint])
                {
                    switch (_workingMode)
                    {
                        case 1:
                            /*since the difference in pixels is almost linear to the distance to the sensor - we can use the following approximation for distance*/
                            if (USE_DISTANCE_APPROXIMATION)
                            {
                                _distanceThreshold = 3 * ((movementVectorLast._startPoint.Z + movementVectorLast._endPoint.Z) / 2 - (serverVector._startPoint.Z + serverVector._endPoint.Z) / 2);
                            }

                            if (Math.Abs(serverVector._angle - movementVectorLast._angle) < _angleThreshold)
                            {
                                if (Math.Abs(serverVector._distance - movementVectorLast._distance) < _distanceThreshold)
                                {
                                    /*if we have a match for both angle and distance*/
                                    isFoundInServerVectors = true;
                                    break;
                                }
                            }
                            break;
                        case 2:
                            if (Math.Abs(serverVector._angle - movementVectorLast._angle) < _angleThreshold)
                            {
                                /*if we have a match for both angle*/
                                isFoundInServerVectors = true;
                            }
                            break;
                    }
                    if (isFoundInServerVectors == true) break;
                }

                if (isFoundInServerVectors)
                {
                    result.BoneStates.Add(joint, SkeletonBoneState.Matched);
                }
                else
                {
                    result.BoneStates.Add(joint, SkeletonBoneState.Unmatched);
                }
            }

            _calculatedFramesSinceStart++;
        }
        public void CalculateVectors(Dictionary <JointType, List <MovementVector> > serverPoints, BodyStructure body, SkeletonFrameValidationData result)
        {
            //We take the last calculated vector for each joint and compare it with the serverRecorded ones

            foreach (var joint in jointsOfInterest)
            {
                bool isFoundInServerVectors = false;

                var movementVectorLast = jointMovementVectors[joint];

                foreach (var serverVector in serverPoints[joint])
                {
                    switch (_workingMode)
                    {
                    case 1:
                        /*since the difference in pixels is almost linear to the distance to the sensor - we can use the following approximation for distance*/
                        if (USE_DISTANCE_APPROXIMATION)
                        {
                            _distanceThreshold = 3 * ((movementVectorLast._startPoint.Z + movementVectorLast._endPoint.Z) / 2 - (serverVector._startPoint.Z + serverVector._endPoint.Z) / 2);
                        }

                        if (Math.Abs(serverVector._angle - movementVectorLast._angle) < _angleThreshold)
                        {
                            if (Math.Abs(serverVector._distance - movementVectorLast._distance) < _distanceThreshold)
                            {
                                /*if we have a match for both angle and distance*/
                                isFoundInServerVectors = true;
                                break;
                            }
                        }
                        break;

                    case 2:
                        if (Math.Abs(serverVector._angle - movementVectorLast._angle) < _angleThreshold)
                        {
                            /*if we have a match for both angle*/
                            isFoundInServerVectors = true;
                        }
                        break;
                    }
                    if (isFoundInServerVectors == true)
                    {
                        break;
                    }
                }

                if (isFoundInServerVectors)
                {
                    result.BoneStates.Add(joint, SkeletonBoneState.Matched);
                }
                else
                {
                    result.BoneStates.Add(joint, SkeletonBoneState.Unmatched);
                }
            }

            _calculatedFramesSinceStart++;
        }