-
Notifications
You must be signed in to change notification settings - Fork 1
/
FlyThroughCapture.m
119 lines (94 loc) · 3.29 KB
/
FlyThroughCapture.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
114
115
116
117
118
function FlyThroughCapture( hFig, hAxes )
%Roll down from XZ to XY and fly through volume
XDim = get(hAxes, 'XLim');
YDim = get(hAxes, 'YLim');
ZDim = get(hAxes, 'ZLim');
FrameNumber = 0;
tilt = 0;
angle = 0;
step = 1;
%Figure out where the camera should be when circling the target
view(0,0);
drawnow
XYva = camva;
view(0,90);
drawnow
XZva = camva;
angle = 0;
tilt = 90;
step = -1;
tilts = 90:step:0;
camAngles = [];
if(XZva ~= XYva)
camAngles = XZva:-(XZva-XYva)/(length(tilts)-1):XYva;
else
camAngles = repmat(XZva, 1, length(tilts));
end
%startVA =
for(i = 1:length(tilts))
f = getframe(hFig); %Capture screen shot
[im,map] = frame2im(f); %Return associated image data
if isempty(map) %Truecolor system
rgb = im;
else %Indexed system
rgb = ind2rgb(im,map); %Convert image data
end
imwrite(rgb, ['Frame_' num2str(FrameNumber) '.png']);
FrameNumber = FrameNumber +1;
tilt = tilts(i);
camva(camAngles(i));
view(0,tilt);
camorbit(hAxes, 0, step);
% drawnow
end
step = 1;
angle = 0;
while(angle <= 90)
f = getframe(hFig); %Capture screen shot
[im,map] = frame2im(f); %Return associated image data
if isempty(map) %Truecolor system
rgb = im;
else %Indexed system
rgb = ind2rgb(im,map); %Convert image data
end
imwrite(rgb, ['Frame_' num2str(FrameNumber) '.png']);
FrameNumber = FrameNumber +1;
angle = angle + step;
view(angle,tilt);
camorbit(hAxes, step, 0);
% drawnow
end
%camva(XYva);
view(90,0);
%OK, figure out the camera position
CamPosition = get(hAxes, 'CameraPosition');
CamTarget = get(hAxes, 'CameraTarget');
%Put the camera target on the back of the Y axis
CamTarget(1) = XDim(1);
set(hAxes, 'CameraTarget', CamTarget);
%Walkt the camera forward for a while
StepSize = (XDim(2)-XDim(1)) / 400;
NumSteps = (XDim(2)-XDim(1)) / 250; %Step 100 pixels each frame
disp(['Num Steps: ' num2str(NumSteps)]);
Distance = CamTarget(1) - CamPosition(1);
Steps = CamPosition(1):Distance/NumSteps:CamTarget(1);
while(CamPosition(1) > XDim(1))
f = getframe(hFig); %Capture screen shot
[im,map] = frame2im(f); %Return associated image data
if isempty(map) %Truecolor system
rgb = im;
else %Indexed system
rgb = ind2rgb(im,map); %Convert image data
end
imwrite(rgb, ['Frame_' num2str(FrameNumber) '.png']);
FrameNumber = FrameNumber +1;
if(CamPosition(1) > XDim(2))
TempStep = StepSize + ((CamPosition(1) - XDim(2)) / 25);
CamPosition(1) = CamPosition(1) - TempStep;
else
CamPosition(1) = CamPosition(1) - StepSize;
end
set(hAxes, 'CameraPosition', CamPosition);
end
% camva(XYva); %Fix the camera at a set distance
end