-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdiscreteAnnotation.m
113 lines (90 loc) · 3.07 KB
/
discreteAnnotation.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
classdef discreteAnnotation < gestureAnnotation
properties (Constant)
annotType = "discrete"
end
properties
triggerFrame
end
methods (Static)
function obj = default()
obj = discreteAnnotation("Unnamed", 500);
end
function obj = from(annot)
if annot.annotType == "discrete"
obj = annot;
return;
end
% previous annot becomes a dud
obj = discreteAnnotation.default();
obj.name = annot.name;
if (annot.parent ~= "Unassigned")
annot.parent.removeChild(annot);
annot.parent.addChild(obj);
end
end
end
methods
function obj = discreteAnnotation(name, triggerFrame)
obj@gestureAnnotation(name, [1 0 0]);
obj.triggerFrame = triggerFrame;
end
function record = getExportRecord(obj)
record = strcat(",", obj.name, ",", string(obj.triggerFrame));
end
function dist = distanceTo(obj, x, ~)
dist = abs(obj.triggerFrame - x);
end
function [sframe, eframe] = getPlaybackFrames(obj)
sframe = obj.triggerFrame;
eframe = obj.triggerFrame;
end
function res = isValid(obj)
res = 1 <= obj.triggerFrame;
end
function json = getJson(obj)
superStruct = jsondecode(getJson@gestureAnnotation(obj));
jsonStruct.name = superStruct.name;
jsonStruct.triggerFrame = obj.triggerFrame;
jsonStruct.annotType = obj.annotType;
json = jsonencode(jsonStruct, PrettyPrint=true);
end
function boundsResize(obj)
newTrigger = obj.parent.clampToBounds(obj.triggerFrame);
if (newTrigger ~= obj.triggerFrame)
obj.triggerFrame = newTrigger;
obj.updateAnnot();
end
end
function clampOwnBounds(obj, startFrame, endFrame)
obj.triggerFrame = basicReplayGrid.clamp(obj.triggerFrame, startFrame, endFrame);
end
function clamped = clampToBounds(obj, ~)
clamped = obj.triggerFrame;
end
function result = containsFrame(obj, frame)
result = (obj.triggerFrame == frame);
end
function handleDrag(obj, newX)
obj.triggerFrame = newX;
obj.updateAnnot();
end
function updateAlpha(obj)
if (obj.annot ~= "Unassigned")
obj.annot.Alpha = obj.alpha;
end
end
function updateAnnot(obj)
obj.annot.Value = obj.triggerFrame;
end
function drawAnnot(obj, axes, ~)
if (obj.annot == "Unassigned")
obj.annot = xline(axes, obj.triggerFrame, ...
"Color", obj.colour, ...
"LineWidth", 2, ...
"Alpha", obj.alpha);
else
updateAnnot(obj);
end
end
end
end