function [lims1, lims2] = gtGetVolsIntersectLimits(size1, size2, shift)
% GTGETVOLSINTERSECTLIMITS Returns the limits in the two volumes, that overlap,
% according to the shift.
%   [lims1, lims2] = gtGetVolsIntersectLimits(size1, size2, shift)

    % volume1 limits
    lims1_min = max(1, shift +1);
    lims1_max = min(size1, shift + size2);

    % volume2 limits
    lims2_min = max(1, -shift +1);
    lims2_max = min(size2, size1 - shift);

    lims1 = [reshape(lims1_min, [1 3]); reshape(lims1_max, [1 3])];
    lims2 = [reshape(lims2_min, [1 3]); reshape(lims2_max, [1 3])];
end
