% makes 3 flatland movies

% M = 30; N = 40;
M=45; N=60;

%if ~exist('G')
% G=loadraw('/mas/disks/vision9/steve/flakes/perspectivepics/red/data',203,320);
%end%if
% load /mas/disks/vision9/steve/flakes/perspectivepics/red.txt
load bu1_dechirped_part.txt;
g=bu1_dechirped_part;
%g=g(21:140);     % crop it (how far into g we would like to go)
scalemax=1;       % zoom range <= 1 (whole image or fraction of it)
scalemin=.333;     % 
g=dechirp(g,500);  % length doesnt matter much; not too big or slow computer
%as = linspace(.5,1,M);  % zooms (scales) must go from 0<a1<=1 to 0<a2<=1
as = linspace(scalemin,scalemax,M);  % zooms (scales)
A = NaN*ones(M,N);
for m=1:M; % time coord
  fprintf('flatlandmovies: making A(:,%g)\r',m)
  scale = as(m);
%  A(m,:)=interp1(linspace(1,N*(1/scale),N),g,1:N).'; % make all have length N
  x = 1:length(g);
  center = length(g)/2;  % zoom about center of image
  xi = linspace(1 + center-scale*length(g)/2,center+scale*length(g)/2,N); 
  A(m,:)=interp1(x,g,xi).'; % make all have length N
end%for
fprintf('flatlandmovies: finished making A                            \n')

g=bu1_dechirped_part;
gclip=g;  % may want to clip part of it
g=dechirp(gclip,4*N); % desire result same shape regardless of M
%bs = linspace(1,3*N,M);
bs = linspace(1,3*N,M);
B = NaN*ones(M,N);
for m=1:M; % time coord
  fprintf('flatlandmovies: making B(:,%g)\r',m)
  x=1:length(g);
  xi=1+bs(m):N+bs(m);
  B(m,:)=interp1(x,g,xi).';
end%for  
fprintf('flatlandmovies: finished making B                            \n')
%

g=bu1_dechirped_part;
gclip=g;  % may want to clip part of it
g=dechirp(gclip,500); %
% ts = linspace(45*o,0,M);
ts = linspace(60*o,0,M);
C = NaN*ones(M,N);
for m=1:M; % time coord
  fprintf('flatlandmovies: making C(:,%g)\r',m)
  x=1:length(g);
%  x1=linspace(1,405,N);
  x1=linspace(1,256,N);
  z1=20/36*max(x1); % focal length, like a 20mm lens on 36mm long film
  x2=project(x1,ts(m),z1) - min(project(x1,max(ts),z1)) + 1;  % offset...
  C(m,:)=interp1(x,g,x2).';
end%for
fprintf('flatlandmovies: finished making C                            \n')
%
figure;
subplot(221); tvs(A)
subplot(222); tvs(B)
subplot(223); tvs(C)

