function [ MotionData ] = Prep_RemoveEmpty( MotionData, extradim )
%PREP_REMOVEEMPTY This function removes the empty 
% Function by Omid Alemi
% Code by Taylor
% Version 0.100 (Unsupported, unreleased) 
%
% Code provided by Graham Taylor and Geoff Hinton 
%
% 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, expressed 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.
%

% We extract the dimensions of interest 
%
Motion=MotionData.data;
skel = MotionData.skel;

clear seqlengths;

if strcmp(skel.type,'acclaim')
 %CMU-style data
 %No offsets, but several dimensions are constant 
 indx = [ 1:6 ...        %root (special representation)
   10:12 13 16:18 19 ... %lfemur ltibia lfoot ltoes
   25:27 28 31:33 34 ... %rfemur rtibia rfoot rtoes
   37:39 40:42 43:45 46:48 49:51 52:54 ... %lowerback upperback thorax lowerneck upperneck %head
   58:60 61 65 67:69 73:75 ... %(lclavicle ignored) lhumerus lradius lwrist lhand (fingers are constant) lthumb
   79:81 82 86 88:90 94:96 ];  %(rclavicle ignored) rhumerus rradius rwrist rhand (fingers are constant) rthumb    

elseif strcmp(skel.type,'mit')
  %MIT-style data
  indx = [   1:6 7:9 14 19:21 26 31:33 38 43:45 50 55:57 61:63 67:69 ...
    73:75 79:81 85:87 91:93 97:99 103:105 ];
  %Save the offsets, they will be inserted later
  offsets = [  Motion{1}(1,10:12); Motion{1}(1,16:18); ...
    Motion{1}(1,22:24); Motion{1}(1,28:30); Motion{1}(1,34:36); ...
    Motion{1}(1,40:42); Motion{1}(1,46:48); Motion{1}(1,52:54); ...
    Motion{1}(1,58:60); Motion{1}(1,64:66); Motion{1}(1,70:72); ...
    Motion{1}(1,76:78); Motion{1}(1,82:84); Motion{1}(1,88:90); ...
    Motion{1}(1,94:96); Motion{1}(1,100:102); Motion{1}(1,106:108)];
elseif strcmp(skel.type,'bvh')
  %some dimensions are constant (don't model)
 % BVH_NUM_DIMS = 75; %Original - Commented by Omid
%   BVH_NUM_DIMS = 114;
%   BVH_CONST_DIMS = [8,9,13,15,19,21,26,27,31,33,37,39,43,45,49,51,62,63,67,69,73,75,86,87,91,93,97,99,103,105,109,111, ... % zero
%       7,14,20,25,32,38,44,55,56,57,61,68,74,79,80,81,85,92,98,104,110]; %non-zero
  
BVH_NUM_DIMS = 84;
    BVH_CONST_DIMS = [32,33,37:42,50,51,55:60,64,65,70,71,76,77,82,83, ... % zero
        ]; %non-zero
    
    
      % this is conversion from non-rotated data
     BVH_CONST_DIMS = [31,32,37:42,59,50,55:60,65,66,71,72,77,78,83,84];
     
     BVH_CONST_DIMS = [31:33,37:39,40:42,49:51,55:57,58:60,64:66,70:72,76:78,82:84];
     
    
  BVH_CONST_DIMS = BVH_CONST_DIMS + extradim; %we have to add extradim to the indices since we might add an extra column in the invar prep
  indx = setdiff(1:BVH_NUM_DIMS+ extradim,BVH_CONST_DIMS);  

elseif strcmp(skel.type,'ms1')
    
      BVH_NUM_DIMS = 114;
      BVH_CONST_DIMS = [8,9,13,15,19,21,26,27,31,33,37,39,43,45,49,51,62,63,67,69,73,75,86,87,91,93,97,99,103,105,109,111, ... % zero
      7,14,20,25,32,38,44,55,56,57,61,68,74,79,80,81,85,92,98,104,110]; %non-zero
    
    BVH_CONST_DIMS = BVH_CONST_DIMS + extradim; %we have to add extradim to the indices since might add extra column in the invar prep
    xx = (BVH_NUM_DIMS+extradim);
    indx = setdiff(1:xx,BVH_CONST_DIMS);
    
elseif strcmp(skel.type,'ms2')
    %Moving Stories: Dec 2013 - May 2014
    BVH_NUM_DIMS = 84;
   
    % this is conversion from non-rotated data
     BVH_CONST_DIMS = [31,32,37:42,59,50,55:60,65,66,71,72,77,78,83,84]; %non-zero
    
    %BVH_CONST_DIMS = [31:33,37:39,40:42,49:51,55:57,58:60,64:66,70:72,76:78,82:84];
    
    BVH_CONST_DIMS = BVH_CONST_DIMS + extradim; %we have to add extradim to the indices since might add extra column in the invar prep
    xx = (BVH_NUM_DIMS+extradim);
    indx = setdiff(1:xx,BVH_CONST_DIMS);
elseif strcmp(skel.type,'ms2.5')
    %Moving Stories: Dec 2013 - May 2014
    BVH_NUM_DIMS = 84;
    BVH_CONST_DIMS = [32,33,37:42,50,51,55:60,64,65,70,71,76,77,82,83, ... % zero
        ]; %non-zero
    
   % BVH_CONST_DIMS = [31:33,37:39,40:42,49:51,55:57,58:60,64:66,70:72,76:78,82:84];
    
    BVH_CONST_DIMS = BVH_CONST_DIMS + extradim; %we have to add extradim to the indices since might add extra column in the invar prep
    indx = setdiff(1:BVH_NUM_DIMS+ extradim,BVH_CONST_DIMS);   
    
elseif strcmp(skel.type,'ms3')
    %Moving Stories: Dec 2013 - May 2014 | Rick Cleaned
    BVH_NUM_DIMS = 138;
   
    % this is conversion from non-rotated data
     BVH_CONST_DIMS = [7,8,9,13,14,15,19,20,21,25,26,27,31,32,33,37,38,39,... %empty position channels
                        43,44,45,49,50,51,55,56,57,61,62,63,67,68,69,73,74,...
                        75,79,80,81,85,86,87,91,92,93,97,98,99,103,104,105,...
                        109,110,111,115,116,117,121,122,123,127,128,129,133,...
                        134,135,...   
                        43:57,79:93,101,102,113,114,125,126,137,138
                        ];
    
    BVH_CONST_DIMS = BVH_CONST_DIMS + extradim; %we have to add extradim to the indices since might add extra column in the invar prep
    xx = (BVH_NUM_DIMS+extradim);
    indx = setdiff(1:xx,BVH_CONST_DIMS);
elseif strcmp(skel.type,'ms3.x')
    %Moving Stories: Dec 2013 - May 2014 | Rick Cleaned
    BVH_NUM_DIMS = 66;
   
    % this is conversion from non-rotated data
     BVH_CONST_DIMS = [25:27 40:42 47:48 53:54 59:60 65:66];
    
    BVH_CONST_DIMS = BVH_CONST_DIMS + extradim; %we have to add extradim to the indices since might add extra column in the invar prep
    xx = (BVH_NUM_DIMS+extradim);
    indx = setdiff(1:xx,BVH_CONST_DIMS);
elseif strcmp(skel.type,'cmubvh')
  %some dimensions are constant (don't model)
  BVH_NUM_DIMS = 96;
  %We don't need to get rid of toes, but we do to make our space smaller
  %This means dimensions 20:21, 35:36 (19,34 are constant anyway)
  %BVH_CONST_DIMS = [7:9 13 19:21 22:24 28 34:36 55:57 62 64 66 70:75 76:78 83 85 87 91:96];
  
  BVH_CONST_DIMS = [7:9 13 19:21 22:24 28 34:36 55:57 62 64 66 67:69 70:75 76:78 83 85 87 88:90 91:96];
  
  BVH_CONST_DIMS = BVH_CONST_DIMS + extradim; %we have to add extradim to the indices since might add extra column in the invar prep
  indx = setdiff(1:BVH_NUM_DIMS+ extradim,BVH_CONST_DIMS); 
else
  error('Unknown skeleton type');
end

for jj=1:length(Motion)
    Motion{jj} = Motion{jj}(:,indx); %Remove the dimensions
end


MotionData.data  = Motion;
MotionData.BVH_CONST_DIMS = BVH_CONST_DIMS;
MotionData.emptyindx = indx;
MotionData.BVH_NUM_DIMS = BVH_NUM_DIMS;
end

