#pragma warning restore

        public void Refresh(bool isPrimary, Body body, Rect bodyPresenceArea)
        {
            this.IsPrimary          = isPrimary;
            this.IsHuman            = body.IsHuman();
            this.IsInFrame          = PersonDetector.IsInFrame(body, bodyPresenceArea);
            this.DistanceFromSensor = body.DistanceFromSensor().ToString("0.00");
            this.TrackedJointCount  = body.TrackedJoints(includeInferred: false).Count();
        }
            public void Render(Body body, bool isPrimary)
            {
                if (body.IsTracked && PersonDetector.IsPersonPresent(body, CameraView))
                {
                    DrawJointLine(this.headLine, body.Joints[JointType.Head], body.Joints[JointType.SpineShoulder], isPrimary);
                    DrawJointLine(this.rightShoulderLine, body.Joints[JointType.ShoulderRight], body.Joints[JointType.SpineShoulder], isPrimary);
                    DrawJointLine(this.leftShoulderLine, body.Joints[JointType.ShoulderLeft], body.Joints[JointType.SpineShoulder], isPrimary);
                    DrawJointLine(this.rightElbowLine, body.Joints[JointType.ElbowRight], body.Joints[JointType.ShoulderRight], isPrimary);
                    DrawJointLine(this.leftElbowLine, body.Joints[JointType.ElbowLeft], body.Joints[JointType.ShoulderLeft], isPrimary);
                    DrawJointLine(this.topSpineLine, body.Joints[JointType.SpineShoulder], body.Joints[JointType.SpineMid], isPrimary);
                    DrawJointLine(this.bottomSpineLine, body.Joints[JointType.SpineMid], body.Joints[JointType.SpineBase], isPrimary);

                    DrawJointPoint(this.headPoint, body.Joints[JointType.Head], isPrimary);
                    DrawJointPoint(this.spineShoulderPoint, body.Joints[JointType.SpineShoulder], isPrimary);
                    DrawJointPoint(this.spineMidPoint, body.Joints[JointType.SpineMid], isPrimary);
                    DrawJointPoint(this.spineBasePoint, body.Joints[JointType.SpineBase], isPrimary);
                    DrawJointPoint(this.shoulderLeftPoint, body.Joints[JointType.ShoulderLeft], isPrimary);
                    DrawJointPoint(this.shoulderRightPoint, body.Joints[JointType.ShoulderRight], isPrimary);
                    DrawJointPoint(this.elbowLeftPoint, body.Joints[JointType.ElbowLeft], isPrimary);
                    DrawJointPoint(this.elbowRightPoint, body.Joints[JointType.ElbowRight], isPrimary);

                    DrawHandPointer(body, isPrimary);
                }
                else
                {
                    this.headLine.Opacity          = HiddenOpacity;
                    this.rightShoulderLine.Opacity = HiddenOpacity;
                    this.leftShoulderLine.Opacity  = HiddenOpacity;
                    this.rightElbowLine.Opacity    = HiddenOpacity;
                    this.leftElbowLine.Opacity     = HiddenOpacity;
                    this.topSpineLine.Opacity      = HiddenOpacity;
                    this.bottomSpineLine.Opacity   = HiddenOpacity;
                    this.rightHandPointer.Opacity  = HiddenOpacity;

                    this.headPoint.Opacity          = HiddenOpacity;
                    this.spineShoulderPoint.Opacity = HiddenOpacity;
                    this.spineMidPoint.Opacity      = HiddenOpacity;
                    this.spineBasePoint.Opacity     = HiddenOpacity;
                    this.shoulderLeftPoint.Opacity  = HiddenOpacity;
                    this.shoulderRightPoint.Opacity = HiddenOpacity;
                    this.elbowLeftPoint.Opacity     = HiddenOpacity;
                    this.elbowRightPoint.Opacity    = HiddenOpacity;
                }
            }
        private void BodyReader_FrameArrived(object sender, BodyFrameArrivedEventArgs e)
        {
            using (BodyFrame frame = e.FrameReference.AcquireFrame())
            {
                if (frame != null)
                {
                    frame.GetAndRefreshBodyData(this.bodies);
                    if (Settings.IsDebugViewEnabled)
                    {
                        RefreshPersonDetectionStates();
                    }

                    DrawSkeletons();

                    if (this.primaryPerson == null)
                    {
                        // If we are not tracking anyone, make the first tracked person in the
                        // frame the primary body.
                        for (int i = 0; i < this.bodies.Count; i++)
                        {
                            var body = this.bodies[i];
                            if (body != null && body.IsTracked && PersonDetector.IsPersonPresent(body, this.bodyPresenceArea))
                            {
                                this.primaryPerson = new Person(i, body.TrackingId);
                                this.StateMachine.Fire(Trigger.PersonEnters);
                                break;
                            }
                        }
                    }
                    else
                    {
                        // If we are tracking someone, check if they are still present and still in
                        // the frame.
                        var primaryBody = this.bodies[this.primaryPerson.BodyIndex];
                        if (primaryBody != null && primaryBody.TrackingId == this.primaryPerson.TrackingId && primaryBody.IsTracked)
                        {
                            var isPrimaryPersonPresent = PersonDetector.IsPersonPresent(primaryBody, this.bodyPresenceArea, this.primaryPerson.ExpectedMaxDistance);
                            if (isPrimaryPersonPresent)
                            {
                                // Primary person is in the frame and is a valid distance from the camera.
                                if (this.StateMachine.IsInState(State.ConfirmingPresence))
                                {
                                    // Calibrate the primary person's distance
                                    this.personCalibrator.AddDistanceFromCamera(primaryBody.DistanceFromSensor());
                                }
                                else if (this.StateMachine.IsInState(State.Painting))
                                {
                                    var primaryBodyAsSensorBody = new SensorBody(primaryBody, this.sensor);
                                    var frameAsSensorFrame      = new SensorBodyFrame(frame, this.sensor);
                                    this.paintingSession.Paint(primaryBodyAsSensorBody, this.currentBrush, this.canvas, frameAsSensorFrame);
                                }
                            }
                            else
                            {
                                this.StateMachine.Fire(Trigger.PersonLeaves);
                            }
                        }
                        else
                        {
                            this.StateMachine.Fire(Trigger.PersonLeaves);
                        }
                    }
                }
            }
        }