function ci = shape_all_features(ci)
  if ~isfield(ci,'nI')
    ci.nI = ci.patchSize;
  end
  if ~isfield(ci,'nJ')
    ci.nJ = ci.patchSize;
  end
  nI = ci.nI-1;
  nJ = ci.nJ-1;
  if ~isfield(ci,'shape_feature')
    for iStage = ci.startCascade:ci.numCascade    
      % cache shape_features if necessary
      for iFeat = ci.cascade(iStage).start:ci.cascade(iStage).end
	[ci.shape_feature(iFeat).i ci.shape_feature(iFeat).j ci.shape_feature(iFeat).c]=shapefeature(ci.F(:,ci.RFIndex(iFeat)),nI+1,nJ+1);
      end
    end
  end

function [i, j, c] = shapefeature(f,nI,nJ)  % nI, nJ include zero padding
% reshape feature vector into arrays of indices i,j and coefficients, c
  f = reshape(f,nI,nJ);
  [i j] = find(f);
  c = f(find(f));

