Spelunx Cavern SDK
 
Loading...
Searching...
No Matches
FrameData.cs
Go to the documentation of this file.
1using UnityEngine;
2
3namespace Spelunx.Orbbec {
4 using System;
5 using System.Runtime.Serialization;
6
7 // Class which contains all data sent from background thread to main thread. Copied from BackgroundData from Azure Body Tracking Samples.
8 [Serializable]
9 public class FrameData : ISerializable {
10 /// Timestamp of current data.
11 public float TimestampInMs { get; set; }
12
13 public byte[] DepthImage { get; set; }
14 public int DepthImageWidth { get; set; }
15 public int DepthImageHeight { get; set; }
16 public int DepthImageSize { get; set; }
17
18 public ulong NumDetectedBodies { get; set; }
19
20 /// Array of bodies. Use NumDetectedBodies to determine how many bodies contain useful data.
21 public BodyData[] Bodies { get; set; }
22
23 public FrameData(int maxDepthImageSize = 1024 * 1024 * 3, int maxBodiesCount = 20, int maxJointsSize = 100) {
25 DepthImage = new byte[maxDepthImageSize];
26 Bodies = new BodyData[maxBodiesCount];
27 for (int i = 0; i < maxBodiesCount; i++) {
28 Bodies[i] = new BodyData(maxJointsSize);
29 }
30 }
31
32 public FrameData(SerializationInfo info, StreamingContext context) {
33 TimestampInMs = (float)info.GetValue("TimestampInMs", typeof(float));
34 DepthImageWidth = (int)info.GetValue("DepthImageWidth", typeof(int));
35 DepthImageHeight = (int)info.GetValue("DepthImageHeight", typeof(int));
36 DepthImageSize = (int)info.GetValue("DepthImageSize", typeof(int));
37 NumDetectedBodies = (ulong)info.GetValue("NumDetectedBodies", typeof(ulong));
38 Bodies = (BodyData[])info.GetValue("Bodies", typeof(BodyData[]));
39 DepthImage = (byte[])info.GetValue("DepthImage", typeof(byte[]));
40 }
41
42 public void GetObjectData(SerializationInfo info, StreamingContext context) {
43 // Writing only relevant data to serialized stream, without the placeholder data
44 // (the real depthimage size is not maxdepthimagesize, but smaller).
45 info.AddValue("TimestampInMs", TimestampInMs, typeof(float));
46 info.AddValue("DepthImageWidth", DepthImageWidth, typeof(int));
47 info.AddValue("DepthImageHeight", DepthImageHeight, typeof(int));
48 info.AddValue("DepthImageSize", DepthImageSize, typeof(int));
49 info.AddValue("NumDetectedBodies", NumDetectedBodies, typeof(ulong));
50 BodyData[] ValidBodies = new BodyData[NumDetectedBodies];
51 for (int i = 0; i < (int)NumDetectedBodies; i++) {
52 ValidBodies[i] = Bodies[i];
53 }
54 info.AddValue("Bodies", ValidBodies, typeof(BodyData[]));
55 byte[] ValidDepthImage = new byte[DepthImageSize];
56 for (int i = 0; i < DepthImageSize; i++) {
57 ValidDepthImage[i] = DepthImage[i];
58 }
59 info.AddValue("DepthImage", ValidDepthImage, typeof(byte[]));
60 }
61 }
62}
void GetObjectData(SerializationInfo info, StreamingContext context)
Definition: FrameData.cs:42
float TimestampInMs
Timestamp of current data.
Definition: FrameData.cs:11
FrameData(SerializationInfo info, StreamingContext context)
Definition: FrameData.cs:32
BodyData[] Bodies
Array of bodies. Use NumDetectedBodies to determine how many bodies contain useful data.
Definition: FrameData.cs:21
FrameData(int maxDepthImageSize=1024 *1024 *3, int maxBodiesCount=20, int maxJointsSize=100)
Definition: FrameData.cs:23