Tanoda
RawLeapRecording.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
9using System;
10using System.Collections.Generic;
11
12namespace Leap.Unity.Recording {
13
15
16 public List<Frame> frameList = new List<Frame>();
17
18 public long EarliestTimestamp {
19 get {
20 if (frameList.Count != 0) {
21 return frameList[0].Timestamp;
22 } else {
23 return 0;
24 }
25 }
26 }
27
28 public long LatestTimestamp {
29 get {
30 if (frameList.Count != 0) {
31 return frameList[frameList.Count - 1].Timestamp;
32 } else {
33 return 0;
34 }
35 }
36 }
37
38 public override void LoadFrames(List<Frame> frames) {
39 frameList.Clear();
40
41 foreach (var frame in frames) {
42 var copy = new Frame();
43 copy.CopyFrom(frame);
44 frameList.Add(copy);
45 }
46 }
47
48 public override float length {
49 get {
50 if (frameList.Count != 0) {
51 return (float)((frameList[frameList.Count - 1].Timestamp - frameList[0].Timestamp) * NS_TO_S);
52 } else {
53 return 0;
54 }
55 }
56 }
57
58 public override bool Sample(float time, Frame toFill, bool clampTimeToValid = true) {
59 if (frameList.Count == 0) {
60 return false;
61 }
62
63 if (!clampTimeToValid && time < 0 || time > length) {
64 return false;
65 }
66
67 long timestamp = (long)(time * S_TO_NS) + EarliestTimestamp;
68
69 int index = 0;
70 while (index < frameList.Count && frameList[index].Timestamp < timestamp) {
71 index++;
72 }
73
74 toFill.CopyFrom(frameList[index]);
75 return true;
76 }
77 }
78}
The Frame class represents a set of hand and finger tracking data detected in a single frame.
Definition: Frame.cs:24
const double NS_TO_S
Converts nanoseconds to seconds. Leap frames store timestamps in nanoseconds.
const double S_TO_NS
Converts seconds to nanoseconds. Leap frames store timestamps in nanoseconds.
override void LoadFrames(List< Frame > frames)
Loads this recording with data from the provided TEMPORARY list of frames. These frames reflect raw r...
override bool Sample(float time, Frame toFill, bool clampTimeToValid=true)
Samples the recording at the given time. Caller must provide a frame object that will be filled with ...