forked from pdollar/toolbox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
playAnim.m
98 lines (84 loc) · 2.71 KB
/
playAnim.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
% Display a point cloud animation
%
% USAGE
% playAnimation( A, [fps], [loop], [N] )
%
% INPUTS
% I - Nx3xT or Nx2xT array (N=num points, T=num frames)
% fps - [100] maximum number of frames to display per second
% use fps==0 to introduce no pause and have the movie play as
% fast as possible
% loop - [0] number of time to loop video (may be inf),
% if neg plays video forward then backward then forward etc.
% N - [] cell array containing the connectivity neighbors
%
% OUTPUTS
%
% EXAMPLE
%
% See also
% Piotr's Image&Video Toolbox Version 1.03
% Written and maintained by Piotr Dollar pdollar-at-cs.ucsd.edu
% Please email me if you find bugs, or have suggestions or questions!
function playAnim( anim, prm )
dfs = {'nCamera',-1,'fps',100, 'loop',1, 'N',[]};
prm = getParamDefaults( prm, dfs );
nCamera=prm.nCamera; fps=prm.fps; loop=prm.loop; N=prm.N;
A=anim.A3; cam=anim.cam;
siz=size(A); nframes=siz(3); nDim=siz(1);
% Determine the boundaries of the data
if nCamera<0; bound=minmax(reshape(A,nDim,[]));
else bound=minmax([reshape(A,nDim,[]), cam]);end
maxB=max(bound(:,2)-bound(:,1))/2;
bound=mean(bound,2); bound=[bound-maxB bound+maxB]; % make axes equal
bound=reshape(bound',1,[]);
% Define some initial variables
h=gcf; figure(h); % bring to focus
set( gcf, 'KeyPressFcn', { @interface } );
doReturn=0; doPause=0;
clf;
[hPoint, hCam]=initializeCloud( struct('cam',anim.cam,'nCamera',nCamera,...
'c',[0.4,0.4,1],'N',N,'A',anim.A3,'bound',bound) );
% play the animation several times
for nplayed = 1 : abs(loop)
if( loop<0 && mod(nplayed,2)==1 )
order = nframes:-1:1;
else
order = 1:nframes;
end
% Play the animation once
for i=order
tic; try geth=get(h); catch return; end
if doReturn; return; end
hCam=updateCloud( struct('hPoint',hPoint,'hCam',hCam,'nCamera',...
nCamera, 'i',i,'A',anim.A3,'cam',cam));
while doPause
pause(0.1);
end
% Display the image
title(sprintf('frame %d of %d',i,nframes));
axis(bound); drawnow;
if(fps>0); pause(1/fps - toc); else pause(eps); end
end
end
%%%%%%%%%%
function interface( src, event )
% Deal with a pressed key to change the view or quit the animation
if ~isempty(event)
switch event.Key
case 'leftarrow',
set( gca, 'View', get( gca, 'View' ) + [ 10 0 ] );
case 'rightarrow',
set( gca, 'View', get( gca, 'View' ) - [ 10 0 ] );
case 'uparrow',
set( gca, 'View', get( gca, 'View' ) - [ 0 10 ] );
case 'downarrow',
set( gca, 'View', get( gca, 'View' ) + [ 0 10 ] );
case 'space',
doPause=~doPause;
case 'q',
doReturn=1;
end
end
end
end