-
Notifications
You must be signed in to change notification settings - Fork 6
/
mni2fs_contslider.m
executable file
·69 lines (56 loc) · 2.04 KB
/
mni2fs_contslider.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
classdef mni2fs_contslider < handle
properties
currframe = 0;
OL
framerate = 10;
end
properties(Hidden)
ft = uint64(0);
end
methods
function obj = mni2fs_contslider(objarray)
for oi = objarray
if ~isobject(oi)
error('Inputs should be a cell array of overlay "objects"')
elseif ~strcmp(oi.Type, 'overlay_object')
error('Inputs should be a cell array of overlay "objects"')
end
end
obj.OL = objarray;
obj.framerate = obj.OL(1).S.framerate; % just grab framerate from the first overlay object
h = uicontrol('style','slider','Position', [0 0 400 20], 'Min',1,'Max',size(oi.Vsurf,2),'Value',1);
addlistener(h,'Value','PreSet',@obj.contcallback);
end
function animate(obj, nframes)
if nargin < 2
nframes = size(obj.OL(1).Vsurf,2);
end
for ii = 1:nframes
obj.nextframe();
end
end
%
function nextframe(obj, nframes)
if nargin == 1
nframes = 1;
end
obj.currframe = obj.currframe + nframes;
si = mod(obj.currframe, size(obj.OL(1).Vsurf,2))+1;
for oi = obj.OL
oi.frame(si);
end
end
function contcallback(obj, ~, evt)
% Callback for continuous slider
if 1/obj.framerate-toc(obj.ft) < 0
si = mod(obj.currframe, size(obj.OL(1).Vsurf,2))+1;
obj.currframe = round(get(evt.AffectedObject, 'Value'));
for oi = obj.OL
oi.frame(si);
end
obj.ft = tic;
disp(sprintf('Animval = %2.2f: ind = %d', obj.OL(1).S.animvals(si), si)); %#ok<DSPS>
end
end
end
end