//Maps all circles to a joint positions
 public void SetJointPositions(ref Runtime nui, SkeletonDisplay incSD, SkeletonData incSkeleton)
 {
     try
     {
         SetJointPosition(ref nui, incSD.Head.GetEllipse(), incSkeleton.Joints[JointID.Head]);
         SetJointPosition(ref nui, incSD.RightHand.GetEllipse(), incSkeleton.Joints[JointID.HandRight]);
         SetJointPosition(ref nui, incSD.LeftHand.GetEllipse(), incSkeleton.Joints[JointID.HandLeft]);
         SetJointPosition(ref nui, incSD.ElbowLeft.GetEllipse(), incSkeleton.Joints[JointID.ElbowLeft]);
         SetJointPosition(ref nui, incSD.ElbowRight.GetEllipse(), incSkeleton.Joints[JointID.ElbowRight]);
         SetJointPosition(ref nui, incSD.ShoulderLeft.GetEllipse(), incSkeleton.Joints[JointID.ShoulderLeft]);
         SetJointPosition(ref nui, incSD.ShoulderRight.GetEllipse(), incSkeleton.Joints[JointID.ShoulderRight]);
         SetJointPosition(ref nui, incSD.Spine.GetEllipse(), incSkeleton.Joints[JointID.Spine]);
         SetJointPosition(ref nui, incSD.ShoulderCenter.GetEllipse(), incSkeleton.Joints[JointID.ShoulderCenter]);
     }
     catch (NullReferenceException)
     {
     }
 }
        KinectDevice()
        {
            mKinectNUI = Runtime.Kinects[0];

            //Initialize the device with color and depth
            mKinectNUI.Initialize(RuntimeOptions.UseDepthAndPlayerIndex | RuntimeOptions.UseColor | RuntimeOptions.UseSkeletalTracking);

            mKinectNUI.SkeletonEngine.TransformSmooth = true;

            // reduces jitter
            var parameters = new TransformSmoothParameters
            {
                Smoothing          = 0.5f,
                Correction         = 0.0f,
                Prediction         = 0.0f,
                JitterRadius       = 0.1f,
                MaxDeviationRadius = 0.08f
            };

            mKinectNUI.SkeletonEngine.SmoothParameters = parameters;

            //EventHandlers
            mKinectNUI.VideoFrameReady    += new EventHandler <ImageFrameReadyEventArgs>(mKinectNUI_VideoFrameReady);
            mKinectNUI.DepthFrameReady    += new EventHandler <ImageFrameReadyEventArgs>(mKinectNUI_DepthFrameReady);
            mKinectNUI.SkeletonFrameReady += new EventHandler <SkeletonFrameReadyEventArgs>(mKinectNUI_SkeletonFrameReady);


            //Open streams for use
            mKinectNUI.VideoStream.Open(ImageStreamType.Video, 2, ImageResolution.Resolution640x480, ImageType.Color);
            mKinectNUI.DepthStream.Open(ImageStreamType.Depth, 2, ImageResolution.Resolution320x240, ImageType.DepthAndPlayerIndex);
            mWindow          = (MainWindow)Application.Current.MainWindow;
            mSkeletonDisplay = new SkeletonDisplay(mWindow.KinectCameraPanelInMainWindow.SkeletonWindow);

            //Used to prioritize a user (-1 = null)
            mCurrentSkeletonID = -1;

            //defualt video size
            mVideoX = 320;
            mVideoY = 240;
        }
        // Skeleton EventHandler
        void mKinectNUI_SkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e)
        {
            SkeletonFrame allSkeletons = e.SkeletonFrame;

            if (allSkeletons == null)
            {
                return;
            }

            //get the first tracked skeleton
            //mSkeleton = (from s in allSkeletons.Skeletons
            //             where s.TrackingState == SkeletonTrackingState.Tracked
            //             select s).FirstOrDefault();

            //Chooses prime user and handles switching between users
            for (int i = 0; i < allSkeletons.Skeletons.Count(); i++)
            {
                if (allSkeletons.Skeletons.ElementAt(i).TrackingState == SkeletonTrackingState.Tracked &&
                    (EnableNewSkeletonGesture(allSkeletons.Skeletons.ElementAt(i)) || mCurrentSkeletonID == -1 || allSkeletons.Skeletons.ElementAt(i).TrackingID == mCurrentSkeletonID))
                {
                    mSkeleton          = allSkeletons.Skeletons.ElementAt(i);
                    mCurrentSkeletonID = mSkeleton.TrackingID;
                }
            }

            if (mSkeletonDisplay == null)
            {
                mSkeletonDisplay = new SkeletonDisplay(mWindow.KinectCameraPanelInMainWindow.SkeletonWindow);
            }
            if (mSkeleton != null)
            {
                SetJointPositions(ref mKinectNUI, mSkeletonDisplay, mSkeleton);
                mWindow.mMainModel.Update_Skeleton();
            }
            else
            {
                mCurrentSkeletonID = -1;
            }
        }