示例#1
1
        /// <summary>
        /// Draws a bone line between two joints
        /// </summary>
        /// <param name="skeleton">skeleton to draw bones from</param>
        /// <param name="drawingContext">drawing context to draw to</param>
        /// <param name="jointType0">joint to start drawing from</param>
        /// <param name="jointType1">joint to end drawing at</param>
        public static void DrawBone(TSkeleton skeleton, DrawingContext drawingContext, TJointType jointType0, TJointType jointType1)
        {
            TJoint joint0 = skeleton.Joints[(int)jointType0];
            TJoint joint1 = skeleton.Joints[(int)jointType1];

            // If we can't find either of these joints, exit
            if (joint0.TrackingState == TJointTrackingState.NotTracked ||
                joint1.TrackingState == TJointTrackingState.NotTracked)
            {
                return;
            }

            // Don't draw if both points are inferred
            if (joint0.TrackingState == TJointTrackingState.Inferred &&
                joint1.TrackingState == TJointTrackingState.Inferred)
            {
                return;
            }

            // We assume all drawn bones are inferred unless BOTH joints are tracked
            Pen drawPen = inferredBonePen;
            if (joint0.TrackingState == TJointTrackingState.Tracked && joint1.TrackingState == TJointTrackingState.Tracked)
            {
                drawPen = trackedBonePen;
            }

            drawingContext.DrawLine(drawPen, SkeletonPointToScreen(joint0.Position), SkeletonPointToScreen(joint1.Position));
        }
示例#2
0
        public override void Read(BinaryReader reader)
        {
            Timestamp   = reader.ReadInt64();
            FrameNumber = reader.ReadInt32();

            FloorClipPlane = new Tuple <float, float, float, float>(
                reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle());

            SkeletonArrayLength = reader.ReadInt32();

            Skeletons = new TSkeleton[SkeletonArrayLength];
            for (int i = 0; i < Skeletons.Length; i++)
            {
                Skeletons[i] = new TSkeleton();
                Skeletons[i].Read(reader);
            }
        }
示例#3
0
        public TSkeletonFrame(SkeletonFrame sensorFrame)
        {
            var skeletonData = new Skeleton[sensorFrame.SkeletonArrayLength];

            sensorFrame.CopySkeletonDataTo(skeletonData);

            var skeletons = new TSkeleton[sensorFrame.SkeletonArrayLength];

            for (int i = 0; i < sensorFrame.SkeletonArrayLength; i++)
            {
                skeletons[i] = new TSkeleton(skeletonData[i]);
            }

            Skeletons = skeletons;

            FloorClipPlane      = sensorFrame.FloorClipPlane;
            SkeletonArrayLength = sensorFrame.SkeletonArrayLength;
            FrameNumber         = sensorFrame.FrameNumber;
            Timestamp           = sensorFrame.Timestamp;
        }
示例#4
0
        /// <summary>
        /// Draws indicators to show which edges are clipping skeleton data
        /// </summary>
        /// <param name="skeleton">skeleton to draw clipping information for</param>
        /// <param name="drawingContext">drawing context to draw to</param>
        public static void RenderClippedEdges(TSkeleton skeleton, DrawingContext drawingContext)
        {
            if (skeleton.ClippedEdges.HasFlag(TFrameEdges.Bottom))
            {
                drawingContext.DrawRectangle(
                    Brushes.Red,
                    null,
                    new Rect(0, RenderHeight - ClipBoundsThickness, RenderWidth, ClipBoundsThickness));
            }

            if (skeleton.ClippedEdges.HasFlag(TFrameEdges.Top))
            {
                drawingContext.DrawRectangle(
                    Brushes.Red,
                    null,
                    new Rect(0, 0, RenderWidth, ClipBoundsThickness));
            }

            if (skeleton.ClippedEdges.HasFlag(TFrameEdges.Left))
            {
                drawingContext.DrawRectangle(
                    Brushes.Red,
                    null,
                    new Rect(0, 0, ClipBoundsThickness, RenderHeight));
            }

            if (skeleton.ClippedEdges.HasFlag(TFrameEdges.Right))
            {
                drawingContext.DrawRectangle(
                    Brushes.Red,
                    null,
                    new Rect(RenderWidth - ClipBoundsThickness, 0, ClipBoundsThickness, RenderHeight));
            }
        }
示例#5
0
        /// <summary>
        /// Draws a skeleton's bones and joints
        /// </summary>
        /// <param name="skeleton">skeleton to draw</param>
        /// <param name="drawingContext">drawing context to draw to</param>
        public static void DrawBonesAndJoints(TSkeleton skeleton, DrawingContext drawingContext)
        {
            // Render Torso
            DrawBone(skeleton, drawingContext, TJointType.Head, TJointType.ShoulderCenter);
            DrawBone(skeleton, drawingContext, TJointType.ShoulderCenter, TJointType.ShoulderLeft);
            DrawBone(skeleton, drawingContext, TJointType.ShoulderCenter, TJointType.ShoulderRight);
            DrawBone(skeleton, drawingContext, TJointType.ShoulderCenter, TJointType.Spine);
            DrawBone(skeleton, drawingContext, TJointType.Spine, TJointType.HipCenter);
            DrawBone(skeleton, drawingContext, TJointType.HipCenter, TJointType.HipLeft);
            DrawBone(skeleton, drawingContext, TJointType.HipCenter, TJointType.HipRight);

            // Left Arm
            DrawBone(skeleton, drawingContext, TJointType.ShoulderLeft, TJointType.ElbowLeft);
            DrawBone(skeleton, drawingContext, TJointType.ElbowLeft, TJointType.WristLeft);
            DrawBone(skeleton, drawingContext, TJointType.WristLeft, TJointType.HandLeft);

            // Right Arm
            DrawBone(skeleton, drawingContext, TJointType.ShoulderRight, TJointType.ElbowRight);
            DrawBone(skeleton, drawingContext, TJointType.ElbowRight, TJointType.WristRight);
            DrawBone(skeleton, drawingContext, TJointType.WristRight, TJointType.HandRight);

            // Left Leg
            DrawBone(skeleton, drawingContext, TJointType.HipLeft, TJointType.KneeLeft);
            DrawBone(skeleton, drawingContext, TJointType.KneeLeft, TJointType.AnkleLeft);
            DrawBone(skeleton, drawingContext, TJointType.AnkleLeft, TJointType.FootLeft);

            // Right Leg
            DrawBone(skeleton, drawingContext, TJointType.HipRight, TJointType.KneeRight);
            DrawBone(skeleton, drawingContext, TJointType.KneeRight, TJointType.AnkleRight);
            DrawBone(skeleton, drawingContext, TJointType.AnkleRight, TJointType.FootRight);

            // Render Joints
            foreach (TJoint joint in skeleton.Joints)
            {
                Brush drawBrush = null;

                if (joint.TrackingState == TJointTrackingState.Tracked)
                {
                    drawBrush = trackedJointBrush;
                }
                else if (joint.TrackingState == TJointTrackingState.Inferred)
                {
                    drawBrush = inferredJointBrush;
                }

                if (drawBrush != null)
                {
                    drawingContext.DrawEllipse(drawBrush, null, SkeletonPointToScreen(joint.Position), JointThickness, JointThickness);
                }
            }
        }
示例#6
0
        public void Draw(TSkeleton[] skeletons, bool seated)
        {
            if (rootCanvas == null)
            {
                return;
            }
            rootCanvas.Children.Clear();
            foreach (TSkeleton skeleton in skeletons)
            {
                if (skeleton.TrackingState != TSkeletonTrackingState.Tracked)
                    continue;

                Plot(TJointType.HandLeft, skeleton.Joints);
                Trace(TJointType.HandLeft, TJointType.WristLeft, skeleton.Joints);
                Plot(TJointType.WristLeft, skeleton.Joints);
                Trace(TJointType.WristLeft, TJointType.ElbowLeft, skeleton.Joints);
                Plot(TJointType.ElbowLeft, skeleton.Joints);
                Trace(TJointType.ElbowLeft, TJointType.ShoulderLeft, skeleton.Joints);
                Plot(TJointType.ShoulderLeft, skeleton.Joints);
                Trace(TJointType.ShoulderLeft, TJointType.ShoulderCenter, skeleton.Joints);
                Plot(TJointType.ShoulderCenter, skeleton.Joints);

                Trace(TJointType.ShoulderCenter, TJointType.Head, skeleton.Joints);

                Plot(TJointType.Head, TJointType.ShoulderCenter, skeleton.Joints);

                Trace(TJointType.ShoulderCenter, TJointType.ShoulderRight, skeleton.Joints);
                Plot(TJointType.ShoulderRight, skeleton.Joints);
                Trace(TJointType.ShoulderRight, TJointType.ElbowRight, skeleton.Joints);
                Plot(TJointType.ElbowRight, skeleton.Joints);
                Trace(TJointType.ElbowRight, TJointType.WristRight, skeleton.Joints);
                Plot(TJointType.WristRight, skeleton.Joints);
                Trace(TJointType.WristRight, TJointType.HandRight, skeleton.Joints);
                Plot(TJointType.HandRight, skeleton.Joints);

                if (!seated)
                {
                    Trace(TJointType.ShoulderCenter, TJointType.Spine, skeleton.Joints);
                    Plot(TJointType.Spine, skeleton.Joints);
                    Trace(TJointType.Spine, TJointType.HipCenter, skeleton.Joints);
                    Plot(TJointType.HipCenter, skeleton.Joints);

                    Trace(TJointType.HipCenter, TJointType.HipLeft, skeleton.Joints);
                    Plot(TJointType.HipLeft, skeleton.Joints);
                    Trace(TJointType.HipLeft, TJointType.KneeLeft, skeleton.Joints);
                    Plot(TJointType.KneeLeft, skeleton.Joints);
                    Trace(TJointType.KneeLeft, TJointType.AnkleLeft, skeleton.Joints);
                    Plot(TJointType.AnkleLeft, skeleton.Joints);
                    Trace(TJointType.AnkleLeft, TJointType.FootLeft, skeleton.Joints);
                    Plot(TJointType.FootLeft, skeleton.Joints);

                    Trace(TJointType.HipCenter, TJointType.HipRight, skeleton.Joints);
                    Plot(TJointType.HipRight, skeleton.Joints);
                    Trace(TJointType.HipRight, TJointType.KneeRight, skeleton.Joints);
                    Plot(TJointType.KneeRight, skeleton.Joints);
                    Trace(TJointType.KneeRight, TJointType.AnkleRight, skeleton.Joints);
                    Plot(TJointType.AnkleRight, skeleton.Joints);
                    Trace(TJointType.AnkleRight, TJointType.FootRight, skeleton.Joints);
                    Plot(TJointType.FootRight, skeleton.Joints);
                }
            }
        }