% Version 1.01 
%
% Code provided by Graham Taylor, Geoff Hinton and Sam Roweis 
%
% For more information, see:
%     http://www.cs.toronto.edu/~gwtaylor/publications/nips2006mhmublv
%
% Permission is granted for anyone to copy, use, modify, or distribute this
% program and accompanying programs and documents for any purpose, provided
% this copyright notice is retained and prominently displayed, along with
% a note saying that the original programs are available from our
% web page.
% The programs and documents are distributed without any warranty, express or
% implied.  As the programs were written for research purposes only, they have
% not been tested to the degree that would be advisable in any important
% application.  All use of these programs is entirely at the user's own risk.
%
% This program postprocesses data. 
% It is the first stage of preprocessing (essentially reverses
% preprocess2.m)
% 
% We support two types of skeletons:
%  1) Those built from the CMU database (acclaim)
%     http://mocap.cs.cmu.edu/
%  2) Those built from data from Eugene Hsu (mit)
%     http://people.csail.mit.edu/ehsu/work/sig05stf/
%

clear newdata

%scale back to original
newdata = repmat(data_std, size(visible,1),1) .* ...
  visible + repmat(data_mean, size(visible,1),1);
 
if strcmp(skel.type,'acclaim')
 %CMU-style data
 %No offsets, but several dimensions are constant 
 
 newdata = ...
     [ newdata(:,1) newdata(:,2) newdata(:,3) ...%x,z,y rot
     newdata(:,4) newdata(:,5) newdata(:,6)... %x,y,z pos
     zeros(size(newdata,1),3) newdata(:,7:10) ...
     zeros(size(newdata,1),2) newdata(:,11:14) ...
     zeros(size(newdata,1),5) newdata(:,15:18) ...
     zeros(size(newdata,1),2) newdata(:,19:22) ... %end right foot
     zeros(size(newdata,1),2) newdata(:,23:40) ... %end head
     zeros(size(newdata,1),3) newdata(:,41:44) ... %end lradius
     zeros(size(newdata,1),3) newdata(:,45) ... %end lwrist
     zeros(size(newdata,1),1) newdata(:,46:48) ...
     zeros(size(newdata,1),3) newdata(:,49:51) ... %end lthumb
     zeros(size(newdata,1),3) newdata(:,52:55) ... %end rwrist
     zeros(size(newdata,1),3) newdata(:,56) ... %end rwrist
     zeros(size(newdata,1),1) newdata(:,57:59) ...
     zeros(size(newdata,1),3) newdata(:,60:62)];

elseif strcmp(skel.type,'mit')
  %MIT-style data
  
newdata = ...
[ newdata(:,1) newdata(:,2) newdata(:,3) ...%x,z,y rot
  newdata(:,4) newdata(:,5) newdata(:,6)... %x,y,z pos
  newdata(:,7:9) repmat(offsets(1,:),size(newdata,1),1) ...
  zeros(size(newdata,1),1) newdata(:,10) ...
  zeros(size(newdata,1),1) repmat(offsets(2,:),size(newdata,1),1) ...
  newdata(:,11:13) repmat(offsets(3,:),size(newdata,1),1) ...
  zeros(size(newdata,1),1) ...
  newdata(:,14) zeros(size(newdata,1),1) ...
  repmat(offsets(4,:),size(newdata,1),1) ...
  newdata(:,15:17) repmat(offsets(5,:),size(newdata,1),1) ...
  zeros(size(newdata,1),1) ...
  newdata(:,18) zeros(size(newdata,1),1) ...
  repmat(offsets(6,:),size(newdata,1),1) ...
  newdata(:,19:21) repmat(offsets(7,:),size(newdata,1),1) ...
  zeros(size(newdata,1),1) ...
  newdata(:,22) zeros(size(newdata,1),1) ...
  repmat(offsets(8,:),size(newdata,1),1) ...
  newdata(:,23:25) repmat(offsets(9,:),size(newdata,1),1) ...
  newdata(:,26:28) repmat(offsets(10,:),size(newdata,1),1) ...
  newdata(:,29:31) repmat(offsets(11,:),size(newdata,1),1) ...
  newdata(:,32:34) repmat(offsets(12,:),size(newdata,1),1) ...
  newdata(:,35:37) repmat(offsets(13,:),size(newdata,1),1) ...
  newdata(:,38:40) repmat(offsets(14,:),size(newdata,1),1) ...
  newdata(:,41:43) repmat(offsets(15,:),size(newdata,1),1) ...
  newdata(:,44:46) repmat(offsets(16,:),size(newdata,1),1) ...
  newdata(:,47:49) repmat(offsets(17,:),size(newdata,1),1)]; 
elseif strcmp(skel.type,'bvh') || strcmp(skel.type,'cmubvh')
  %BVH data (from motion builder)
  totaldata = zeros(size(newdata,1),BVH_NUM_DIMS); %all dimensions
  totaldata(:,indx) = newdata; %leave constant dimensions zero
  newdata = totaldata; %use original naming convention

else
  error('Unknown skeleton type');
end