Example #1
0
        /// <summary>
        /// Draws a body
        /// </summary>
        /// <param name="joints">joints to draw</param>
        /// <param name="jointPoints">translated positions of joints to draw</param>
        /// <param name="drawingContext">drawing context to draw to</param>
        /// <param name="drawingPen">specifies color to draw a specific body</param>
        private void DrawBody(JointCollection joints, DrawingContext drawingContext, Pen drawingPen)
        {
            // Draw the bones
            foreach (var bone in this.bones)
            {
                this.DrawBone(joints, bone.Item1, bone.Item2, drawingContext, drawingPen);
            }

            // Draw the joints
            foreach (Joint joint in joints)
            {
                Brush drawBrush = null;

                JointTrackingState trackingState = joint.TrackingState;

                if (trackingState == JointTrackingState.Tracked)
                {
                    drawBrush = this.trackedJointBrush;
                }
                else if (trackingState == JointTrackingState.Inferred)
                {
                    drawBrush = this.inferredJointBrush;
                }

                if (drawBrush != null)
                {
                    drawingContext.DrawEllipse(drawBrush, null, this.SkeletonPointToScreen(joint.Position), JointThickness, JointThickness);
                }
            }
        }
        public SkeletonBone(SkeletonBoneType type, JointTrackingState trackingState, double x, double y, double z)
        {
            this.type = type;
            this.trackingState = trackingState;

            vector = new Vector3D(x, y, z);
            vector.Normalize();
        }
Example #3
0
        public SkeletonBone(SkeletonBoneType type, JointTrackingState trackingState, double x, double y, double z)
        {
            this.type          = type;
            this.trackingState = trackingState;

            vector = new Vector3D(x, y, z);
            vector.Normalize();
        }
Example #4
0
 public JointData(TimeSpan elapsed, JointType _type, JointTrackingState _state, double _x, double _y, double _z)
 {
     this.DataTime      = elapsed;
     this.JointType     = _type;
     this.TrackingState = _state;
     this.X             = _x;
     this.Y             = _y;
     this.Z             = _z;
 }
Example #5
0
        private NTrackingState ResolveTrackingState(JointTrackingState state)
        {
            switch (state)
            {
            case JointTrackingState.Tracked: return(NTrackingState.Tracked);

            case JointTrackingState.Inferred: return(NTrackingState.Inferred);

            case JointTrackingState.NotTracked: return(NTrackingState.NotTracked);
            }
            return(NTrackingState.NotTracked);
        }
        void controller_SkeletonPreProcessed(object sender, SkeletonPreProcessedEventArgs e)
        {
            // Process core
            Skeleton           skel      = e.Skeleton;
            SkeletonPoint      leftFoot  = skel.Joints[JointType.FootLeft].Position;
            SkeletonPoint      rightFoot = skel.Joints[JointType.FootRight].Position;
            float              minFootY;
            JointTrackingState leftFootTracking  = skel.Joints[JointType.FootLeft].TrackingState;
            JointTrackingState rightFootTracking = skel.Joints[JointType.FootRight].TrackingState;
            bool footTracked = true;

            if (leftFootTracking == JointTrackingState.Tracked && rightFootTracking == JointTrackingState.Tracked)
            {
                minFootY = Math.Min(leftFoot.Y, rightFoot.Y);
            }
            else if (leftFootTracking == JointTrackingState.Tracked)
            {
                minFootY = leftFoot.Y;
            }
            else if (rightFootTracking == JointTrackingState.Tracked)
            {
                minFootY = rightFoot.Y;
            }
            else
            {
                footTracked = false;
                minFootY    = leftFoot.Y; // Not sure what's best in this case
            }

            if (skel.Joints[JointType.ShoulderCenter].TrackingState == JointTrackingState.Tracked && footTracked)
            {
                SkeletonPoint shoulderPos = skel.Joints[JointType.ShoulderCenter].Position;

                // ## Compute scale factor for larger/smaller people based off spine to foot height ##
                double shoulderHeight = shoulderPos.Y - minFootY;                        // Get the spinal height and use it a rough guide
                double fullHeight     = SHOULDER_TO_EXTENDED_ARM_RATIO * shoulderHeight; // Get the full height as a scale
                float  scale          = (float)(ActiveRectangle.Height / fullHeight);

                if (skel.TrackingId != curSkeletonId)
                {
                    scaleHistory.Clear();
                    curSkeletonId = skel.TrackingId;
                }
                if (scaleHistory.Count > 5)
                {
                    scaleHistory.RemoveAt(0);
                }
                scaleHistory.Add(scale);
                scaleFactor = scaleHistory.Average();
            }
            bottomCenterPoint   = skel.Joints[JointType.HipCenter].Position;
            bottomCenterPoint.Y = minFootY;
        }
        private string translateTrackingState(JointTrackingState state)
        {
            switch (state)
            {
            case JointTrackingState.Tracked: return("Sledzony");

            case JointTrackingState.NotTracked: return("Szkielet niewykryty");

            case JointTrackingState.Inferred: return("Szkielet zaklocony");

            default: return(state.ToString());
            }
        }
        private VertexPositionColor constructVert(JointType type)
        {
            JointTrackingState state = skeleton[0].Joints[type].TrackingState;
            Color c;

            switch (state)
            {
            case JointTrackingState.Inferred: c = Color.Orange; break;

            case JointTrackingState.Tracked: c = Color.White; break;

            default: c = Color.Teal; break;
            }

            return(new VertexPositionColor(ToWorldSpace(skeleton[0].Joints[type].Position), c));
        }
        /// <summary>
        /// Helper method to swap two joints in the skeleton when mirroring the avatar.
        /// </summary>
        /// <param name="skeleton">The skeleton to mirror.</param>
        /// <param name="left">The left joint type.</param>
        /// <param name="right">The right joint type.</param>
        private static void SwapJoints(Skeleton skeleton, JointType left, JointType right)
        {
            Joint jL = skeleton.Joints[left];
            Joint jR = skeleton.Joints[right];

            Microsoft.Kinect.SkeletonPoint tempPos = jL.Position;
            jL.Position = jR.Position;
            jR.Position = tempPos;

            JointTrackingState tempTs = jL.TrackingState;

            jL.TrackingState = jR.TrackingState;
            jR.TrackingState = tempTs;

            skeleton.Joints[left]  = jL;
            skeleton.Joints[right] = jR;
        }
Example #10
0
        void DrawBoneLine(SkeletonPoint skeletonFrom, SkeletonPoint skeletonTo, JointTrackingState trackingState)
        {
            var colorImagePointFrom = mapper.MapSkeletonPointToColorPoint(skeletonFrom, ColorImageFormat.RgbResolution640x480Fps30);
            var colorImagePointTo   = mapper.MapSkeletonPointToColorPoint(skeletonTo, ColorImageFormat.RgbResolution640x480Fps30);

            var color = Color.Red;

            switch (trackingState)
            {
            case JointTrackingState.Tracked:
                color = Color.Red;
                break;

            case JointTrackingState.Inferred:
                color = Color.Blue;
                break;
            }

            graphics.DrawLine(new Pen(color)
            {
                Width = 4
            }, colorImagePointFrom.X, colorImagePointFrom.Y, colorImagePointTo.X, colorImagePointTo.Y);
        }
Example #11
0
        public static MySkeleton jsonStrToMySkeleton(String jsonStr)
        {
            MySkeleton skel = new MySkeleton();

            JSONArray array = new JSONArray(jsonStr);

            for (int i = 0; i < array.Length(); i++)
            {
                JSONObject jointObj      = array.GetJSONObject(i);
                JSONArray  positionArray = jointObj.GetJSONArray("Position");

                JointType          jointType     = jointTypeNameReverseMap[jointObj.GetString("JointType")];
                JointTrackingState trackingState = jointTrackingStateNameReverseMap[jointObj.GetString("TrackingState")];
                SkeletonPoint      position      = new SkeletonPoint();
                position.X = float.Parse(positionArray.GetString(0));
                position.Y = float.Parse(positionArray.GetString(1));
                position.Z = float.Parse(positionArray.GetString(2));

                skel.Joints[jointType] = new MyJoint(jointType, position, trackingState);
            }

            return(skel);
        }
        /// <summary>
        /// LerpAndApply performs a Lerp and applies the Lerped vector to the skeleton joint.
        /// </summary>
        /// <param name="skeleton">The skeleton.</param>
        /// <param name="jt">The joint type.</param>
        /// <param name="newJointVector">The new Vector3 value to lerp to.</param>
        /// <param name="lerpValue">The lerp amount between current and new Vector3.</param>
        /// <param name="finalTrackingState">The tracking state of the joint to set after lerp.</param>
        public static void LerpAndApply(Skeleton skeleton, JointType jt, Vector3 newJointVector, float lerpValue, JointTrackingState finalTrackingState)
        {
            if (null == skeleton)
            {
                return;
            }

            Joint joint = skeleton.Joints[jt];
            SkeletonPoint pt = KinectHelper.LerpVector(joint.Position, newJointVector, lerpValue);
            joint.Position = pt;
            joint.TrackingState = finalTrackingState;
            skeleton.Joints[jt] = joint;
        }
Example #13
0
 private KinectBase.TrackingState convertTrackingState(JointTrackingState trackingState)
 {
     //These both have the tracking states numbered the same, so we can do a straight cast
     return((KinectBase.TrackingState)trackingState);
 }
Example #14
0
 internal Joint(JointType jointType, SkeletonPoint skeletonPoint, JointTrackingState jointTrackingState)
 {
     JointType = jointType;
     Position = skeletonPoint;
     TrackingState = jointTrackingState;
 }
Example #15
0
        /// <summary>
        /// LerpAndApply performs a Lerp and applies the Lerped vector to the skeleton joint.
        /// </summary>
        /// <param name="skeleton">The skeleton.</param>
        /// <param name="jt">The joint type.</param>
        /// <param name="newJointVector">The new Vector3 value to lerp to.</param>
        /// <param name="lerpValue">The lerp amount between current and new Vector3.</param>
        /// <param name="finalTrackingState">The tracking state of the joint to set after lerp.</param>
        public static void LerpAndApply(Skeleton skeleton, JointType jt, Vector3 newJointVector, float lerpValue, JointTrackingState finalTrackingState)
        {
            if (null == skeleton)
            {
                return;
            }

            Joint         joint = skeleton.Joints[jt];
            SkeletonPoint pt    = KinectHelper.LerpVector(joint.Position, newJointVector, lerpValue);

            joint.Position      = pt;
            joint.TrackingState = finalTrackingState;
            skeleton.Joints[jt] = joint;
        }
 public ValueJoint(Vector3 position, JointTrackingState jts)
 {
     this.position = position;
     this.jts      = jts;
 }
Example #17
0
 private KinectBase.TrackingState convertTrackingState(JointTrackingState trackingState)
 {
     //These both have the tracking states numbered the same, so we can do a straight cast
     return (KinectBase.TrackingState)trackingState;
 }
Example #18
0
        /// <summary>
        /// SkeletonFrameReady gets fired every skeleton frame update, and refreshes the LocatedSensor's
        ///  global and relative skeleton maps
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void refreshSkeletonPositions(object sender, SkeletonFrameReadyEventArgs e)
        {
            using (SkeletonFrame skeletonFrame = e.OpenSkeletonFrame()) {
                if (skeletonFrame != null)
                {
                    // First, get the relative skeletons - easy peasy
                    Skeleton[] skeletonsR = new Skeleton[skeletonFrame.SkeletonArrayLength];
                    skeletonFrame.CopySkeletonDataTo(skeletonsR);
                    this.relativeSkeletons = skeletonsR.ToList <Skeleton>();

                    // Now global skeletons...
                    // First, clear our global skeletons list.
                    //  We'll be building this back up from scratch here
                    this.globalSkeletons.Clear();
                    // Next, iterate through all the skeletons, applying a rotation and translation
                    //  to get us into global coordinates
                    foreach (Skeleton skel in this.relativeSkeletons)
                    {
                        // Add a temporary skeleton object to store transformed
                        //  data into
                        Skeleton tempSkel = new Skeleton();
                        tempSkel.TrackingState = skel.TrackingState;
                        tempSkel.TrackingId    = skel.TrackingId;
                        tempSkel.Position      = skel.Position;

                        foreach (Joint j in skel.Joints)
                        {
                            // Make a new joint, then put it into our temporary joint
                            //  collection
                            JointType type      = j.JointType;
                            Joint     tempJoint = tempSkel.Joints[type];
                            // Copy the current joint state
                            JointTrackingState tracking = j.TrackingState;
                            tempJoint.TrackingState = tracking;

                            // However, we transform the position of the joint at least
                            SkeletonPoint shiftedPoint = new SkeletonPoint();
                            // Rotate the points
                            DenseMatrix point = new DenseMatrix(1, 3);
                            point[0, 0] = j.Position.X;
                            point[0, 1] = j.Position.Y;
                            point[0, 2] = j.Position.Z;
                            var rotatedPoint = point.Multiply(this.rotationMatrix);

                            // Then shift them by the global coordinates.
                            shiftedPoint.X     = (float)rotatedPoint[0, 0] + this.xOffset;
                            shiftedPoint.Y     = (float)rotatedPoint[0, 1] + this.yOffset;
                            shiftedPoint.Z     = (float)rotatedPoint[0, 2] + this.zOffset;
                            tempJoint.Position = shiftedPoint;

                            tempSkel.Joints[type] = tempJoint;
                        }
                        // Next, alter the higher-level parameters of our skeleton
                        SkeletonPoint shiftedPosition = new SkeletonPoint();
                        // Rotate
                        DenseMatrix p = new DenseMatrix(1, 3);
                        p[0, 0] = tempSkel.Position.X;
                        p[0, 1] = tempSkel.Position.Y;
                        p[0, 2] = tempSkel.Position.Z;
                        var rPoint = p.Multiply(this.rotationMatrixPitch);

                        // Then shift them by the global coordinates.
                        shiftedPosition.X = (float)rPoint[0, 0] + this.xOffset;
                        shiftedPosition.Y = (float)rPoint[0, 1] + this.yOffset;
                        shiftedPosition.Z = (float)rPoint[0, 2] + this.zOffset;

                        tempSkel.Position = shiftedPosition;

                        // Now add that skeleton to our global skeleton list
                        this.globalSkeletons.Add(tempSkel);
                    }
                }
            }
        }
Example #19
0
 public MyJoint(JointType jointType, SkeletonPoint position, JointTrackingState trackingState)
 {
     this.JointType     = jointType;
     this.Position      = position;
     this.TrackingState = trackingState;
 }
Example #20
0
 private NTrackingState ResolveTrackingState(JointTrackingState state) {
   switch (state) {
     case JointTrackingState.Tracked: return NTrackingState.Tracked;
     case JointTrackingState.Inferred: return NTrackingState.Inferred;
     case JointTrackingState.NotTracked: return NTrackingState.NotTracked;
   }
   return NTrackingState.NotTracked;
 }