Exemplo n.º 1
0
        public BVH_IO(string fileName, string path)
        {
            fileNameWithPath   = path + "\\" + fileName + ".bvh";
            this.fileNameShort = fileName;
            KinectSkeletonBVH.AddKinectSkeleton(bvhSkeleton);
            initializing     = true;
            tempOffsetMatrix = new float[3, bvhSkeleton.Bones.Count];
            tempMotionVektor = new float[bvhSkeleton.Channels];

            if (File.Exists(fileNameWithPath))
            {
                File.Delete(fileNameWithPath);
            }
            file = File.CreateText(fileNameWithPath);
            file.WriteLine("HIERARCHY");
            recording = true;
        }
Exemplo n.º 2
0
        public static float[] getBoneVectorOutofJointPosition(BVHBone bvhBone, KinectSkeleton skel)
        {
            float[] boneVector = new float[3] {
                0, 0, 0
            };
            float[] boneVectorParent = new float[3] {
                0, 0, 0
            };
            string boneName = bvhBone.Name;

            JointType Joint;

            if (bvhBone.Root == true)
            {
                boneVector = new float[3] {
                    0, 0, 0
                };
            }
            else
            {
                if (bvhBone.IsKinectJoint == true)
                {
                    Joint = KinectSkeletonBVH.String2JointType(boneName);

                    boneVector[0] = skel.Joints[Joint].X;
                    boneVector[1] = skel.Joints[Joint].Y;
                    boneVector[2] = skel.Joints[Joint].Z;

                    try
                    {
                        Joint = KinectSkeletonBVH.String2JointType(bvhBone.Parent.Name);
                    }
                    catch
                    {
                        Joint = KinectSkeletonBVH.String2JointType(bvhBone.Parent.Parent.Name);
                    }

                    boneVector[0] -= skel.Joints[Joint].X;
                    boneVector[1] -= skel.Joints[Joint].Y;
                    boneVector[2] -= skel.Joints[Joint].Z;
                }
            }

            return(boneVector);
        }
Exemplo n.º 3
0
 //eigentliche Schreibarbeit:
 public void Entry(KinectSkeleton skel)
 {
     this.intializingCounter++;
     for (int k = 0; k < bvhSkeleton.Bones.Count; k++)
     {
         float[] bonevector = KinectSkeletonBVH.getBoneVectorOutofJointPosition(bvhSkeleton.Bones[k], skel);
         {
             if (this.intializingCounter == 1)
             {
                 tempOffsetMatrix[0, k] = (float)Math.Round(bonevector[0] * 100, 2);
                 tempOffsetMatrix[1, k] = (float)Math.Round(bonevector[1] * 100, 2);
                 tempOffsetMatrix[2, k] = (float)Math.Round(bonevector[2] * 100, 2);
             }
             else
             {
                 tempOffsetMatrix[0, k] = (float)(this.intializingCounter * tempOffsetMatrix[0, k] + Math.Round(bonevector[0] * 100, 2)) / (this.intializingCounter + 1);
                 tempOffsetMatrix[1, k] = (float)(this.intializingCounter * tempOffsetMatrix[1, k] + Math.Round(bonevector[1] * 100, 2)) / (this.intializingCounter + 1);
                 tempOffsetMatrix[2, k] = (float)(this.intializingCounter * tempOffsetMatrix[1, k] + Math.Round(bonevector[2] * 100, 2)) / (this.intializingCounter + 1);
             }
         }
     }
 }
Exemplo n.º 4
0
        public void WriteMotions(KinectSkeleton skel, Body body)
        {
            sw.Start(); //Aufnahme der Bewegungen beginnt

            for (int k = 0; k < bvhSkeletonWritten.Bones.Count; k++)
            {
                if (bvhSkeletonWritten.Bones[k].End == false)
                {
                    float[] degVec = new float[3];
                    degVec = KinectSkeletonBVH.getEulerFromBone(bvhSkeletonWritten.Bones[k], skel, body);

                    int indexOffset = 0;
                    if (bvhSkeletonWritten.Bones[k].Root == true)
                    {
                        indexOffset = 3;
                    }

                    tempMotionVektor[bvhSkeletonWritten.Bones[k].MotionSpace + indexOffset]     = degVec[0];
                    tempMotionVektor[bvhSkeletonWritten.Bones[k].MotionSpace + 1 + indexOffset] = degVec[1];
                    tempMotionVektor[bvhSkeletonWritten.Bones[k].MotionSpace + 2 + indexOffset] = degVec[2];

                    //// Textbox setzen
                    //string boneName = bvhSkeletonWritten.Bones[k].Name;
                    //if (boneName == textFeld.getDropDownJoint)
                    //{
                    //    //Rotation
                    //    string textBox = Math.Round(degVec[0], 1).ToString() + " " + Math.Round(degVec[1], 1).ToString() + " " + Math.Round(degVec[2], 1).ToString();
                    //    textFeld.setTextBoxAngles = textBox;

                    //    //Position
                    //    JointType KinectJoint = KinectSkeletonBVH.getJointTypeFromBVHBone(bvhSkeletonWritten.Bones[k]);
                    //    float x = skel.Joints[KinectJoint].Position.X;
                    //    float y = skel.Joints[KinectJoint].Position.Y;
                    //    float z = skel.Joints[KinectJoint].Position.Z;
                    //    textFeld.setTextPosition = Math.Round(x, 2).ToString() + " " + Math.Round(y, 2).ToString() + " " + Math.Round(z, 2).ToString();

                    //    //Length
                    //    BVHBone tempBone = bvhSkeletonWritten.Bones.Find(i => i.Name == KinectJoint.ToString());
                    //    float[] boneVec = KinectSkeletonBVH.getBoneVectorOutofJointPosition(tempBone, skel);
                    //    float length = Math.Sqrt(Math.Pow(boneVec[0], 2) + Math.Pow(boneVec[1], 2) + Math.Pow(boneVec[2], 2));
                    //    length = Math.Round(length, 2);
                    //    textFeld.setTextBoxLength = length.ToString();
                    //}
                }
            }
            //Root Bewegung
            tempMotionVektor[0] = (float)-Math.Round(skel.Joints[JointType.SpineMid].X * 100, 2);
            tempMotionVektor[1] = (float)Math.Round(skel.Joints[JointType.SpineMid].Y * 100, 2) + 120;
            tempMotionVektor[2] = 300 - (float)Math.Round(skel.Joints[JointType.SpineMid].Z * 100, 2);

            for (int i = 0; i < 3; i++)
            {
                if (tempMotionVektor[i] == float.NaN)
                {
                    tempMotionVektor[i] = 0;
                }
            }
            writeMotion(tempMotionVektor);
            file.Flush();

            elapsedTimeSec = (float)Math.Round(Convert.ToDouble(sw.ElapsedMilliseconds) / 1000, 2);
            //textFeld.setTextBoxElapsedTime = elapsedTimeSec.ToString();
            //textFeld.setTextBoxCapturedFrames = frameCounter.ToString();
            avgFrameRate = (float)Math.Round(frameCounter / elapsedTimeSec, 2);
            //  textFeld.setTextBoxFrameRate = avgFrameRate.ToString();
        }