function [R2] = regs2layers(R, grid)
r2 = zeros(size(R));
R2(:,:,1) = R;
opts = [];
for i=2:length(grid.REGS)
    wg = grid.REGS{i};
    pts = [grid.shape(wg.edge,1), grid.shape(wg.edge,2)];
    pts = [pts; grid.control_pts(wg.vertex,1), grid.control_pts(wg.vertex,2)];
    rpts = order_xy_pts(pts);
    r2 = roipoly(zeros(size(R)), rpts(:,1), rpts(:,2));
    R2(:,:,end+1) = r2;
end
return;