Пример #1
0
 public static TSkeleton SkeletonToTSkeleton(Body skeleton, long TimePeriod, Vector4 FloorClipPlane)
 {
     TSkeleton tSkeleton = new TSkeleton();
     tSkeleton.ClippedEdges = skeleton.ClippedEdges;
     tSkeleton.HandLeftConfidence = skeleton.HandLeftConfidence;
     tSkeleton.HandLeftState = skeleton.HandLeftState;
     tSkeleton.HandRightConfidence = skeleton.HandRightConfidence;
     tSkeleton.HandRightState = skeleton.HandRightState;
     tSkeleton.IsRestricted = skeleton.IsRestricted;
     tSkeleton.IsTracked = skeleton.IsTracked;
     tSkeleton.Lean = skeleton.Lean;
     tSkeleton.LeanTrackingState = skeleton.LeanTrackingState;
     tSkeleton.FloorClipPlane = FloorClipPlane;
     tSkeleton.Orientation = new Vector4[25];
     tSkeleton.Position = new CameraSpacePoint[25];
     tSkeleton.TrackingState = new TrackingState[25];
     for (int a = 0; a < tSkeleton.Orientation.Length; a++)
     {
         tSkeleton.Orientation[a] = skeleton.JointOrientations[(JointType)a].Orientation;
         tSkeleton.Position[a] = skeleton.Joints[(JointType)a].Position;
         tSkeleton.TrackingState[a] = skeleton.Joints[(JointType)a].TrackingState;
     }
     tSkeleton.TimePeriod = TimePeriod;
     //tSkeleton.AbsoluteTime = AbsoluteTime;
     return tSkeleton;
 }
Пример #2
0
 public static ArrayList CloneRecording(ArrayList recording)
 {
     if (recording == null)
         return null;
     ArrayList clone = new ArrayList();
     for (int a = 0; a < recording.Count; a++)
     {
         TSkeleton[] ts = (TSkeleton[])recording[a];
         TSkeleton[] tsClone = new TSkeleton[ts.Length];
         for (int b = 0; b < ts.Length; b++)
         {
             tsClone[b] = ts[b].Clone();
         }
         clone.Add(tsClone);
     }
     return clone;
 }
Пример #3
0
 public static void SaveTSkeletonToFile(TSkeleton tSkeleton, StreamWriter sw, long currentFrameNumber)
 {
     sw.Write(currentFrameNumber + " ");
     sw.Write(tSkeleton.TimePeriod + " ");
     sw.Write((int)tSkeleton.ClippedEdges + " ");
     sw.Write((int)tSkeleton.HandLeftConfidence + " ");
     sw.Write((int)tSkeleton.HandLeftState + " ");
     sw.Write((int)tSkeleton.HandRightConfidence + " ");
     sw.Write((int)tSkeleton.HandRightState + " ");
     sw.Write(tSkeleton.IsRestricted + " ");
     sw.Write(tSkeleton.IsTracked + " ");
     WriteToFile(sw, tSkeleton.Lean);
     sw.Write((int)tSkeleton.LeanTrackingState + " ");
     WriteToFile(sw, tSkeleton.Orientation);
     WriteToFile(sw, tSkeleton.Position);
     WriteToFile(sw, tSkeleton.TrackingState);
     sw.WriteLine();
 }
Пример #4
0
        /*
         * //bone rotation
         * //Quaternion - x y z w
         * public float[][] AbsoluteRotation;
         * public float[][] HierarchicalRotation;
         * //None = 0,
         * //Right = 1,
         * //Left = 2,
         * //Top = 4,
         * //Bottom = 8,
         * public int ClippedEdges = 0;
         * //x y z
         * public float[] Position;
         * //joint - x y z
         * public float[][] JointsPositions;
         * //NotTracked = 0,
         * //Inferred = 1,
         * //Tracked = 2,
         * public int[] JointsTrackingState;
         *
         * //
         * public ulong TrackingId;
         *
         * //NotTracked = 0,
         * //PositionOnly = 1,
         * //Tracked = 2,
         * public int TrackingState;
         * public long TimePeriod;
         * public long AbsoluteTime;
         *
         * public System.Tuple<float, float, float, float> FloorClipPlane = new Tuple<float, float, float, float>(0, 0, 0, 0);
         * public int ElevationAngle = 0;
         * public int SeatedMode = 0;
         *
         * public long SyncTime = 0;*/

        public TSkeleton Clone()
        {
            TSkeleton ts = new TSkeleton();

            ts.ClippedEdges        = this.ClippedEdges;
            ts.HandLeftConfidence  = this.HandLeftConfidence;
            ts.HandLeftState       = this.HandLeftState;
            ts.HandRightConfidence = this.HandRightConfidence;
            ts.HandRightState      = this.HandRightState;
            ts.IsRestricted        = this.IsRestricted;
            ts.IsTracked           = this.IsTracked;
            ts.Orientation         = new Vector4[this.Orientation.Length];
            for (int a = 0; a < ts.Orientation.Length; a++)
            {
                ts.Orientation[a].W = this.Orientation[a].W;
                ts.Orientation[a].X = this.Orientation[a].X;
                ts.Orientation[a].Y = this.Orientation[a].Y;
                ts.Orientation[a].Z = this.Orientation[a].Z;
            }

            ts.Position = new CameraSpacePoint[this.Position.Length];
            for (int a = 0; a < ts.Orientation.Length; a++)
            {
                ts.Position[a].X = this.Position[a].X;
                ts.Position[a].Y = this.Position[a].Y;
                ts.Position[a].Z = this.Position[a].Z;
            }

            ts.TrackingState = new TrackingState[this.TrackingState.Length];
            for (int a = 0; a < ts.Orientation.Length; a++)
            {
                ts.TrackingState[a] = this.TrackingState[a];
            }
            ts.Lean = this.Lean;
            ts.LeanTrackingState = this.LeanTrackingState;
            ts.TrackingId        = this.TrackingId;
            ts.TimePeriod        = this.TimePeriod;
            ts.AbsoluteTime      = this.AbsoluteTime;
            ts.FloorClipPlane    = this.FloorClipPlane;
            ts.ElevationAngle    = this.ElevationAngle;
            return(ts);
        }
Пример #5
0
        public static ArrayList ReadRecordingFromFile(String fileToPlay)
        {
            ArrayList recording = new ArrayList();
            StreamReader sr = new StreamReader(fileToPlay);
            String line;
            ArrayList arHelp = new ArrayList();
            long prevFrameNumber = -1;
            long currentFrameNumber = -1;

            long absoluteTime = 0;
            try
            {
                do
                {
                    TSkeleton tSkeleton = new TSkeleton();
                    prevFrameNumber = currentFrameNumber;
                    //do
                    {
                        
                        line = sr.ReadLine();
                        line = line.Replace(',', '.');
                        char[] delimiterChars = { ' ' };
                        int index = 0;
                        String[] array = line.Split(delimiterChars);
                        
                        currentFrameNumber = long.Parse(array[index], CultureInfo.InvariantCulture);
                        index++;
                        tSkeleton.TimePeriod = long.Parse(array[index], CultureInfo.InvariantCulture);
                        index++;
                        tSkeleton.ClippedEdges = (FrameEdges)int.Parse(array[index], CultureInfo.InvariantCulture);
                        index++;
                        tSkeleton.HandLeftConfidence = (TrackingConfidence)int.Parse(array[index], CultureInfo.InvariantCulture);
                        index++;
                        tSkeleton.HandLeftState = (HandState)int.Parse(array[index], CultureInfo.InvariantCulture);
                        index++;
                        tSkeleton.HandRightConfidence = (TrackingConfidence)int.Parse(array[index], CultureInfo.InvariantCulture);
                        index++;
                        tSkeleton.HandRightState = (HandState)int.Parse(array[index], CultureInfo.InvariantCulture);
                        index++;
                        tSkeleton.IsRestricted = bool.Parse(array[index]);
                        index++;
                        tSkeleton.IsTracked = bool.Parse(array[index]);
                        index++;
                        ReadFromFile(ref tSkeleton.Lean, array, ref index);
                        tSkeleton.LeanTrackingState = (TrackingState)int.Parse(array[index], CultureInfo.InvariantCulture);
                        index++;
                        tSkeleton.Orientation = new Vector4[25];
                        ReadFromFile(ref tSkeleton.Orientation, array, ref index);
                        tSkeleton.Position = new CameraSpacePoint[25];
                        ReadFromFile(ref tSkeleton.Position, array, ref index);
                        tSkeleton.TrackingState = new TrackingState[25];
                        ReadFromFile(ref tSkeleton.TrackingState, array, ref index);
                    }

                    if (currentFrameNumber != prevFrameNumber && prevFrameNumber >= 0)
                    {
                        TSkeleton[] skeletons = new TSkeleton[arHelp.Count];
                        for (int b = 0; b < skeletons.Length; b++)
                        {
                            skeletons[b] = (TSkeleton)arHelp[b];
                        }
                        arHelp.Clear();
                        //STARY BUG ;-) GDY ŁAPAŁO WIĘCEJ NIŻ JEDNĄ KLATKĘ W 30 HZ
                        if (skeletons[0].TimePeriod > 10)
                        {
                            recording.Add(skeletons);
                        }
                        arHelp.Add(tSkeleton);
                        absoluteTime += skeletons[0].TimePeriod;
                    }
                    else
                    {
                        arHelp.Add(tSkeleton);
                        absoluteTime += tSkeleton.TimePeriod;
                    }

                }
                while (line != null && sr != null);
            }
            catch { };
            if (sr != null)
            {
                sr.Close();
                sr = null;
            }
            if (arHelp.Count > 0)
            {
                TSkeleton[] skeletons = new TSkeleton[arHelp.Count];
                for (int b = 0; b < skeletons.Length; b++)
                    skeletons[b] = (TSkeleton)arHelp[b];
                arHelp.Clear();
                //STARY BUG ;-) GDY ŁAPAŁO WIĘCEJ NIŻ JEDNĄ KLATKĘ W 30 HZ
                if (skeletons[0].TimePeriod > 10)
                {
                    recording.Add(skeletons);
                }
            }

            return recording;
        }