Esempio n. 1
0
        /// <summary>
        /// Write bvh data into a file
        /// </summary>
        /// <param name="path"></param>
        public void OutputBVHToFile()
        {
            // if skeleton struture not clibrated or there is no motion frame, just return
            if (_structuredSkeleton.NeedBoneClibrated() || _frameCount == 0)
            {
                return;
            }

            StringBuilder wholeBVH = new StringBuilder();

            // HIRARCHY
            wholeBVH.Append(STR_HIERARCHY + CHAR_LF);

            // all the joints
            buildBVHOutputSkeleton(_structuredSkeleton.HipCenter);
            wholeBVH.Append(_bvhSkeletonBuffer);

            // MOTION
            wholeBVH.Append(STR_MOTION + CHAR_LF);

            // frame info
            wholeBVH.Append(STR_FRAMES + CHAR_SPACE + _frameCount + CHAR_LF);
            wholeBVH.Append(STR_FRAME_TIME + CHAR_SPACE + DOUBLE_FRAMERATE + CHAR_LF);

            // frames
            wholeBVH.Append(_bvhMotionFrameBuffer);

            // write out
            using (StreamWriter bvhStreamWriter = new StreamWriter(FilePath))
            {
                bvhStreamWriter.Write(wholeBVH.ToString());
            }
        }
        private void SensorSkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e)
        {
            Skeleton[] skeletons      = new Skeleton[0];
            long       frameTimeStamp = 0;

            using (SkeletonFrame skeletonFrame = e.OpenSkeletonFrame())
            {
                if (skeletonFrame != null)
                {
                    skeletons = new Skeleton[skeletonFrame.SkeletonArrayLength];
                    skeletonFrame.CopySkeletonDataTo(skeletons);
                    frameTimeStamp = skeletonFrame.Timestamp;
                }
            }

            if (skeletons.Length != 0)
            {
                canvas.Children.Clear();
                foreach (Skeleton skel in skeletons)
                {
                    // render clipped edges
                    renderClippedEdges(skel);

                    if (SkeletonTrackingState.Tracked == skel.TrackingState)
                    {
                        // clibrate the bones if not done yet
                        _kinectSkeleton.CliberateSkeleton(skel);

                        // render the skeleton on the canvas
                        addBones(skel);

                        if (!_kinectSkeleton.NeedBoneClibrated())
                        {
                            canvas.Background = BRUSH_BACKGROUNDCLIBRATED;
                            _kinectSkeleton.UpdateJoints(skel);

                            // record motion data to bvh file
                            if (underRecording)
                            {
                                bvhWriter.AppendOneMotionFrame();
                            }

                            addBVHBones_Debug();
                        }
                    }
                }
            }
        }