예제 #1
0
파일: WriteBVH.cs 프로젝트: 6eye/BVHC
        /// <summary>
        ///
        /// </summary>
        /// <param name="skel"></param>
        public void Motion(Skeleton skel)
        {
            sw.Start(); //Начать замер времени

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

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

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

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

                        //Position
                        JointType KinectJoint = KinectSkeletonBVH.getJointTypeFromBVHBone(bvhSkeletonWritten.Bones[k]);
                        double    x           = skel.Joints[KinectJoint].Position.X;
                        double    y           = skel.Joints[KinectJoint].Position.Y;
                        double    z           = skel.Joints[KinectJoint].Position.Z;
                        textField.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());
                        double[] boneVec  = KinectSkeletonBVH.getBoneVectorOutofJointPosition(tempBone, skel);
                        double   length   = Math.Sqrt(Math.Pow(boneVec[0], 2) + Math.Pow(boneVec[1], 2) + Math.Pow(boneVec[2], 2));
                        length = Math.Round(length, 2);
                        textField.setTextBoxLength = length.ToString();
                    }
                }
            }
            //Root Bewegung
            tempMotionVector[0] = -Math.Round(skel.Position.X * 100, 2);
            tempMotionVector[1] = Math.Round(skel.Position.Y * 100, 2) + 120;
            tempMotionVector[2] = 300 - Math.Round(skel.Position.Z * 100, 2);

            writeMotion(tempMotionVector);
            file.Flush();

            elapsedTimeSec = Math.Round(Convert.ToDouble(sw.ElapsedMilliseconds) / 1000, 2);
            textField.setTextBoxElapsedTime    = elapsedTimeSec.ToString();
            textField.setTextBoxCapturedFrames = frameCounter.ToString();
            avgFrameRate = Math.Round(frameCounter / elapsedTimeSec, 2);
            textField.setTextBoxFrameRate = avgFrameRate.ToString();
        }
예제 #2
0
파일: WriteBVH.cs 프로젝트: 6eye/BVHC
        /// <summary>
        /// Конструктор класса для записи движения в файл
        /// </summary>
        /// <param name="fileName">Имя файла</param>
        public WriteBVH(string fileName)
        {
            fileName      = fileName + ".bvh";
            this.fileName = fileName;
            KinectSkeletonBVH.AddKinectSkeleton(bvhSkeleton);
            initializing     = true;
            tempOffsetMatrix = new double[3, bvhSkeleton.Bones.Count];
            tempMotionVector = new double[bvhSkeleton.Channels];

            if (File.Exists(fileName))
            {
                File.Delete(fileName);
            }
            file = File.CreateText(fileName);
            file.WriteLine("HIERARCHY");
            recording = true;
        }
예제 #3
0
        public static double[] getBoneVectorOutofJointPosition(BVHBone bvhBone, Skeleton skel)
        {
            double[] boneVector = new double[3] {
                0, 0, 0
            };
            double[] boneVectorParent = new double[3] {
                0, 0, 0
            };
            string boneName = bvhBone.Name;

            JointType Joint;

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

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

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

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

            return(boneVector);
        }
예제 #4
0
파일: WriteBVH.cs 프로젝트: 6eye/BVHC
 /// <summary>
 /// ФОРМИРОВАНИЕ OFFSET для каждого элемента скелета
 /// Функция формирует OFFSET блок для каждой кости BVH в том числие и концевых
 /// </summary>
 /// <param name="skel">Скелета фрейма</param>
 public void Entry(Skeleton skel)
 {
     this.intializingCounter++;
     for (int k = 0; k < bvhSkeleton.Bones.Count; k++)
     {
         double[] boneVector = KinectSkeletonBVH.getBoneVectorOutofJointPosition(bvhSkeleton.Bones[k], skel);
         if (this.intializingCounter == 1)
         {
             this.tempOffsetMatrix[0, k] = Math.Round(boneVector[0] * 100, 2);
             this.tempOffsetMatrix[1, k] = Math.Round(boneVector[1] * 100, 2);
             this.tempOffsetMatrix[2, k] = Math.Round(boneVector[2] * 100, 2);
         }
         else
         {
             this.tempOffsetMatrix[0, k] = (this.intializingCounter * this.tempOffsetMatrix[0, k] + Math.Round(boneVector[0] * 100, 2)) / (this.intializingCounter + 1);
             this.tempOffsetMatrix[1, k] = (this.intializingCounter * this.tempOffsetMatrix[1, k] + Math.Round(boneVector[1] * 100, 2)) / (this.intializingCounter + 1);
             this.tempOffsetMatrix[2, k] = (this.intializingCounter * this.tempOffsetMatrix[1, k] + Math.Round(boneVector[2] * 100, 2)) / (this.intializingCounter + 1);
         }
     }
 }