public void UpdateCache(int interpolationFactor = 0)
        {
            for (int i = 0; i < this.GhostSkeletons.Count - 1; i += (interpolationFactor + 1))
            {
                GhostSkeleton current = this.GhostSkeletons[i];
                GhostSkeleton next = this.GhostSkeletons[i + 1];

                List<GhostSkeleton> newSkeletons = new List<GhostSkeleton>();
                for (int j = 0; j < interpolationFactor; j++)
                {
                    GhostSkeleton newSkeleton = new GhostSkeleton();
                    this.GhostSkeletons.Insert(i + j + 1, newSkeleton);
                    newSkeletons.Add(newSkeleton);
                }

                foreach (GhostJoint joint in current.GhostJoints)
                {
                    GhostJoint nextJoint = next.GetJoint((JointType)joint.JointType);
                    if (nextJoint == null)
                    {
                        continue;
                    }

                    GhostJoint deltaJoint = (nextJoint - joint) / (interpolationFactor + 1);
                    for (int j = 0; j < interpolationFactor; j++)
                    {
                        GhostJoint newJoint = joint + (deltaJoint * (j + 1));
                        newSkeletons[j].GhostJoints.Add(newJoint);
                    }
                }
            }

            this.SavedSkeletons = this.GhostSkeletons.ToList();
            this.SavedSkeletons.ForEach(skel => skel.UpdateCache());
        }
예제 #2
0
        private void DrawBonesAndJoints(GhostSkeleton skeleton, DrawingContext drawingContext)
        {
            byte alpha = 100;

            // Render Torso
            this.DrawBone(skeleton.GetJoint(JointType.Head), skeleton.GetJoint(JointType.ShoulderCenter), drawingContext, alpha);
            this.DrawBone(skeleton.GetJoint(JointType.ShoulderCenter), skeleton.GetJoint(JointType.ShoulderLeft), drawingContext, alpha);
            this.DrawBone(skeleton.GetJoint(JointType.ShoulderCenter), skeleton.GetJoint(JointType.ShoulderRight), drawingContext, alpha);
            this.DrawBone(skeleton.GetJoint(JointType.ShoulderCenter), skeleton.GetJoint(JointType.Spine), drawingContext, alpha);
            this.DrawBone(skeleton.GetJoint(JointType.Spine), skeleton.GetJoint(JointType.HipCenter), drawingContext, alpha);
            this.DrawBone(skeleton.GetJoint(JointType.HipCenter), skeleton.GetJoint(JointType.HipLeft), drawingContext, alpha);
            this.DrawBone(skeleton.GetJoint(JointType.HipCenter), skeleton.GetJoint(JointType.HipRight), drawingContext, alpha);

            // Left Arm
            this.DrawBone(skeleton.GetJoint(JointType.ShoulderLeft), skeleton.GetJoint(JointType.ElbowLeft), drawingContext, alpha);
            this.DrawBone(skeleton.GetJoint(JointType.ElbowLeft), skeleton.GetJoint(JointType.WristLeft), drawingContext, alpha);
            this.DrawBone(skeleton.GetJoint(JointType.WristLeft), skeleton.GetJoint(JointType.HandLeft), drawingContext, alpha);

            // Right Arm
            this.DrawBone(skeleton.GetJoint(JointType.ShoulderRight), skeleton.GetJoint(JointType.ElbowRight), drawingContext, alpha);
            this.DrawBone(skeleton.GetJoint(JointType.ElbowRight), skeleton.GetJoint(JointType.WristRight), drawingContext, alpha);
            this.DrawBone(skeleton.GetJoint(JointType.WristRight), skeleton.GetJoint(JointType.HandRight), drawingContext, alpha);

            // Left Leg
            this.DrawBone(skeleton.GetJoint(JointType.HipLeft), skeleton.GetJoint(JointType.KneeLeft), drawingContext, alpha);
            this.DrawBone(skeleton.GetJoint(JointType.KneeLeft), skeleton.GetJoint(JointType.AnkleLeft), drawingContext, alpha);
            this.DrawBone(skeleton.GetJoint(JointType.AnkleLeft), skeleton.GetJoint(JointType.FootLeft), drawingContext, alpha);

            // Right Leg
            this.DrawBone(skeleton.GetJoint(JointType.HipRight), skeleton.GetJoint(JointType.KneeRight), drawingContext, alpha);
            this.DrawBone(skeleton.GetJoint(JointType.KneeRight), skeleton.GetJoint(JointType.AnkleRight), drawingContext, alpha);
            this.DrawBone(skeleton.GetJoint(JointType.AnkleRight), skeleton.GetJoint(JointType.FootRight), drawingContext, alpha);
        }
예제 #3
0
        public void UpdateCache(int interpolationFactor = 0)
        {
            for (int i = 0; i < this.GhostSkeletons.Count - 1; i += (interpolationFactor + 1))
            {
                GhostSkeleton current = this.GhostSkeletons[i];
                GhostSkeleton next    = this.GhostSkeletons[i + 1];

                List <GhostSkeleton> newSkeletons = new List <GhostSkeleton>();
                for (int j = 0; j < interpolationFactor; j++)
                {
                    GhostSkeleton newSkeleton = new GhostSkeleton();
                    this.GhostSkeletons.Insert(i + j + 1, newSkeleton);
                    newSkeletons.Add(newSkeleton);
                }

                foreach (GhostJoint joint in current.GhostJoints)
                {
                    GhostJoint nextJoint = next.GetJoint((JointType)joint.JointType);
                    if (nextJoint == null)
                    {
                        continue;
                    }

                    GhostJoint deltaJoint = (nextJoint - joint) / (interpolationFactor + 1);
                    for (int j = 0; j < interpolationFactor; j++)
                    {
                        GhostJoint newJoint = joint + (deltaJoint * (j + 1));
                        newSkeletons[j].GhostJoints.Add(newJoint);
                    }
                }
            }

            this.SavedSkeletons = this.GhostSkeletons.ToList();
            this.SavedSkeletons.ForEach(skel => skel.UpdateCache());
        }
예제 #4
0
        private void sensor_ColorFrameReady(object sender, ColorImageFrameReadyEventArgs e)
        {
            using (ColorImageFrame colorFrame = e.OpenColorImageFrame())
            {
                if (colorFrame != null)
                {
                    frameCount++;

                    using (DrawingContext dc = this.drawingGroup.Open())
                    {
                        // Copy the pixel data from the image to a temporary array
                        colorFrame.CopyPixelDataTo(this.colorPixels);

                        for (int i = 0; i < this.colorPixels.Length; i += 4)
                        {
                            // Convert image to grayscale
                            int  avg     = (this.colorPixels[i] + this.colorPixels[i + 1] + this.colorPixels[i + 2]) / 3;
                            byte avgByte = Convert.ToByte(avg);

                            this.colorPixels[i]     = avgByte;
                            this.colorPixels[i + 1] = avgByte;
                            this.colorPixels[i + 2] = avgByte;
                            this.colorPixels[i + 3] = 255; // alpha channel
                            //this.colorPixels[i + 3] = Convert.ToByte(255 - avg);
                        }

                        // Write the pixel data into our bitmap
                        this.colorBitmap.WritePixels(
                            new Int32Rect(0, 0, this.colorBitmap.PixelWidth, this.colorBitmap.PixelHeight),
                            this.colorPixels,
                            this.colorBitmap.PixelWidth * sizeof(int),
                            0);
                        dc.DrawImage(this.colorBitmap, new Rect(0, 0, this.colorBitmap.PixelWidth, this.colorBitmap.PixelHeight));

                        lock (lockObj)
                        {
                            List <GhostSkeletonSequence> toRemove = new List <GhostSkeletonSequence>();
                            foreach (GhostSkeletonSequence sequence in activeSequences)
                            {
                                if (sequence.CurrentFrame >= sequence.SavedSkeletons.Count - 1)
                                {
                                    sequence.CurrentFrame = 0;
                                    toRemove.Add(sequence);
                                    continue;
                                }

                                GhostSkeleton skeleton = sequence.SavedSkeletons[sequence.CurrentFrame];
                                this.DrawBonesAndJoints(skeleton, dc);

                                sequence.CurrentFrame++;
                            }

                            toRemove.ForEach(sequence => activeSequences.Remove(sequence));
                        }
                    }
                }
            }
        }
        public void AddSkeleton(Skeleton skeleton)
        {
            if (this.GhostSkeletons.Count == 0)
            {
                this.StartDate = DateTime.Now;
                this.EndDate = DateTime.MaxValue;
            }

            GhostSkeleton ghostSkeleton = new GhostSkeleton(skeleton);
            this.GhostSkeletons.Add(ghostSkeleton);
        }
예제 #6
0
        public void AddSkeleton(Skeleton skeleton)
        {
            if (this.GhostSkeletons.Count == 0)
            {
                this.StartDate = DateTime.Now;
                this.EndDate   = DateTime.MaxValue;
            }

            GhostSkeleton ghostSkeleton = new GhostSkeleton(skeleton);

            this.GhostSkeletons.Add(ghostSkeleton);
        }
 partial void DeleteGhostSkeleton(GhostSkeleton instance);
 partial void UpdateGhostSkeleton(GhostSkeleton instance);
 partial void InsertGhostSkeleton(GhostSkeleton instance);
		private void detach_GhostSkeletons(GhostSkeleton entity)
		{
			this.SendPropertyChanging();
			entity.GhostSkeletonSequence = null;
		}
예제 #11
0
        private void DrawBonesAndJoints(GhostSkeleton skeleton, DrawingContext drawingContext)
        {
            byte alpha = 100;

            // Render Torso
            this.DrawBone(skeleton.GetJoint(JointType.Head), skeleton.GetJoint(JointType.ShoulderCenter), drawingContext, alpha);
            this.DrawBone(skeleton.GetJoint(JointType.ShoulderCenter), skeleton.GetJoint(JointType.ShoulderLeft), drawingContext, alpha);
            this.DrawBone(skeleton.GetJoint(JointType.ShoulderCenter), skeleton.GetJoint(JointType.ShoulderRight), drawingContext, alpha);
            this.DrawBone(skeleton.GetJoint(JointType.ShoulderCenter), skeleton.GetJoint(JointType.Spine), drawingContext, alpha);
            this.DrawBone(skeleton.GetJoint(JointType.Spine), skeleton.GetJoint(JointType.HipCenter), drawingContext, alpha);
            this.DrawBone(skeleton.GetJoint(JointType.HipCenter), skeleton.GetJoint(JointType.HipLeft), drawingContext, alpha);
            this.DrawBone(skeleton.GetJoint(JointType.HipCenter), skeleton.GetJoint(JointType.HipRight), drawingContext, alpha);

            // Left Arm
            this.DrawBone(skeleton.GetJoint(JointType.ShoulderLeft), skeleton.GetJoint(JointType.ElbowLeft), drawingContext, alpha);
            this.DrawBone(skeleton.GetJoint(JointType.ElbowLeft), skeleton.GetJoint(JointType.WristLeft), drawingContext, alpha);
            this.DrawBone(skeleton.GetJoint(JointType.WristLeft), skeleton.GetJoint(JointType.HandLeft), drawingContext, alpha);

            // Right Arm
            this.DrawBone(skeleton.GetJoint(JointType.ShoulderRight), skeleton.GetJoint(JointType.ElbowRight), drawingContext, alpha);
            this.DrawBone(skeleton.GetJoint(JointType.ElbowRight), skeleton.GetJoint(JointType.WristRight), drawingContext, alpha);
            this.DrawBone(skeleton.GetJoint(JointType.WristRight), skeleton.GetJoint(JointType.HandRight), drawingContext, alpha);

            // Left Leg
            this.DrawBone(skeleton.GetJoint(JointType.HipLeft), skeleton.GetJoint(JointType.KneeLeft), drawingContext, alpha);
            this.DrawBone(skeleton.GetJoint(JointType.KneeLeft), skeleton.GetJoint(JointType.AnkleLeft), drawingContext, alpha);
            this.DrawBone(skeleton.GetJoint(JointType.AnkleLeft), skeleton.GetJoint(JointType.FootLeft), drawingContext, alpha);

            // Right Leg
            this.DrawBone(skeleton.GetJoint(JointType.HipRight), skeleton.GetJoint(JointType.KneeRight), drawingContext, alpha);
            this.DrawBone(skeleton.GetJoint(JointType.KneeRight), skeleton.GetJoint(JointType.AnkleRight), drawingContext, alpha);
            this.DrawBone(skeleton.GetJoint(JointType.AnkleRight), skeleton.GetJoint(JointType.FootRight), drawingContext, alpha);
        }
예제 #12
0
 partial void DeleteGhostSkeleton(GhostSkeleton instance);
예제 #13
0
 partial void UpdateGhostSkeleton(GhostSkeleton instance);
예제 #14
0
 partial void InsertGhostSkeleton(GhostSkeleton instance);
예제 #15
0
 private void detach_GhostSkeletons(GhostSkeleton entity)
 {
     this.SendPropertyChanging();
     entity.GhostSkeletonSequence = null;
 }