
function [order] = makeorder(S, E)
num_regions = size(S,1);
N = E(:, 1:num_regions);
order = cell(num_regions,1);
for i=1:num_regions
    indx=find(N(:,i));
    P = E(indx,end-1:end);
    [P, ind] = sort_region_pts(P);
    order{i} = indx(ind);
end
return;