Tanoda
Frame.cs
Go to the documentation of this file.
1/******************************************************************************
2 * Copyright (C) Ultraleap, Inc. 2011-2020. *
3 * *
4 * Use subject to the terms of the Apache License 2.0 available at *
5 * http://www.apache.org/licenses/LICENSE-2.0, or another agreement *
6 * between Ultraleap and you, your company or other organization. *
7 ******************************************************************************/
8
9namespace Leap {
10 using System;
11 using System.Collections.Generic;
12
23 [Serializable]
24 public class Frame : IEquatable<Frame> {
25 [ThreadStatic]
26 private static Queue<Hand> _handPool;
27
40 public Frame() {
41 Hands = new List<Hand>();
42 }
43
48 public Frame(long id, long timestamp, float fps, List<Hand> hands) {
49 Id = id;
50 Timestamp = timestamp;
52 Hands = hands;
53 }
54
55 [Obsolete]
56 public int SerializeLength {
57 get {
58 throw new NotImplementedException();
59 }
60 }
61
62 [Obsolete]
63 public byte[] Serialize {
64 get {
65 throw new NotImplementedException();
66 }
67 }
68
69 [Obsolete]
70 public void Deserialize(byte[] arg) {
71 throw new NotImplementedException();
72 }
73
88 public Hand Hand(int id) {
89 for (int i = Hands.Count; i-- != 0;) {
90 if (Hands[i].Id == id) {
91 return Hands[i];
92 }
93 }
94 return null;
95 }
96
104 public bool Equals(Frame other) {
105 return Id == other.Id && Timestamp == other.Timestamp;
106 }
107
112 public override string ToString() {
113 return "Frame id: " + this.Id + " timestamp: " + this.Timestamp;
114 }
115
126 public long Id;
127
136 public long Timestamp;
137
149
156 public List<Hand> Hands;
157
164 internal void ResizeHandList(int count) {
165 if (_handPool == null) {
166 _handPool = new Queue<Hand>();
167 }
168
169 while (Hands.Count < count) {
170 Hand newHand;
171 if (_handPool.Count > 0) {
172 newHand = _handPool.Dequeue();
173 } else {
174 newHand = new Hand();
175 }
176 Hands.Add(newHand);
177 }
178
179 while (Hands.Count > count) {
180 Hand lastHand = Hands[Hands.Count - 1];
181 Hands.RemoveAt(Hands.Count - 1);
182 _handPool.Enqueue(lastHand);
183 }
184 }
185 }
186}
The Frame class represents a set of hand and finger tracking data detected in a single frame.
Definition: Frame.cs:24
override string ToString()
A string containing a brief, human readable description of the Frame object.
Definition: Frame.cs:112
long Id
A unique ID for this Frame.
Definition: Frame.cs:126
Frame()
Constructs a Frame object.
Definition: Frame.cs:40
bool Equals(Frame other)
Compare Frame object equality.
Definition: Frame.cs:104
long Timestamp
The frame capture time in microseconds elapsed since an arbitrary point in time in the past.
Definition: Frame.cs:136
byte[] Serialize
Definition: Frame.cs:63
Hand Hand(int id)
The Hand object with the specified ID in this frame, or null if none exists.
Definition: Frame.cs:88
Frame(long id, long timestamp, float fps, List< Hand > hands)
Constructs a new Frame.
Definition: Frame.cs:48
int SerializeLength
Definition: Frame.cs:56
float CurrentFramesPerSecond
The instantaneous framerate.
Definition: Frame.cs:148
void Deserialize(byte[] arg)
Definition: Frame.cs:70
List< Hand > Hands
The list of Hand objects detected in this frame, given in arbitrary order. The list can be empty if n...
Definition: Frame.cs:156
The Hand class reports the physical characteristics of a detected hand.
Definition: Hand.cs:26