% generate causal painted sequence with current frame = reference frame

load parameters_pairwisem_5_3 % generates p

% generate reverse sequence of time-varying reference frame

more off

% find extrema of boundinboxextrama
ML=[];  NL=[];  MH=[];  NH=[];
for k=170:4:290
  P=pintegrate(p,k);
  [Ml,Nl,Mh,Nh] = boundingboxextrema(P(k-1:291,:)); %consider only region P used
  ML = [ML;Ml];
  MH = [MH;Mh];
  NL = [NL;Nl];
  NH = [NH;Nh];
end%for
% compute extrema
Ml = min(ML);
Mh = max(MH);
Nl = min(NL);
Nh = max(NH);

% generate reverse-causal-painted sequence
for k=290:-4:170;  % this creates about 480 pixels high canvas
  %% do the rest... for k=178-4:-4:170;
  %% do the rest... for k=174:-4:170;
  P=pintegrate(p,k);
  eval(sprintf('cementcolor(P,290,k,-4,''causal%03d'',Ml,Nl,Mh,Nh,k);',k))
  eval(sprintf('!temp_dattopnm_hp causal%03d > causal%03d.ppm',k,k))
  eval(sprintf('!rm causal%03d/data',k))        % less risk than rm -r
  eval(sprintf('!rm causal%03d/descriptor',k))
  eval(sprintf('!rmdir causal%03d',k))
end%for

