def make_mask_corners(shape, width, seed, components, concave, convex): """ Make a mask out of all corners """ mask = numpy.zeros(shape, dtype=bool) for corners, masker in ((concave, mask_concave_corner), (convex, mask_convex_corner)): for v in corners: xwidth = int(numpy.round(width / narrowing_factor)) if vec.inside( v * numpy.array([-1, 0], int), components) else int( numpy.round(width)) zwidth = int(numpy.round(width / narrowing_factor)) if vec.inside( v * numpy.array([0, -1], int), components) else int( numpy.round(width)) if seed is not None and masker is mask_concave_corner: xwidth = river_shore( shape, seed, xwidth, v * numpy.array([1, 0]))[shape[1] - 1 if v[0] > 0 else 0] zwidth = river_shore( shape, seed, zwidth, v * numpy.array([0, 1]))[shape[0] - 1 if v[1] > 0 else 0] mask = numpy.logical_or(mask, masker(shape, v, (xwidth, zwidth))) return mask
def make_mask_corners(shape, width, seed, components, concave, convex): """ Make a mask out of all corners """ mask = numpy.zeros(shape, dtype=bool) for corners, masker in ((concave, mask_concave_corner), (convex, mask_convex_corner)): for v in corners: xwidth = int(numpy.round(width/narrowing_factor)) if vec.inside(v*numpy.array([-1, 0], int), components) else int(numpy.round(width)) zwidth = int(numpy.round(width/narrowing_factor)) if vec.inside(v*numpy.array([ 0, -1], int), components) else int(numpy.round(width)) if seed is not None and masker is mask_concave_corner: xwidth = river_shore(shape, seed, xwidth, v*numpy.array([1, 0]))[shape[1] - 1 if v[0] > 0 else 0] zwidth = river_shore(shape, seed, zwidth, v*numpy.array([0, 1]))[shape[0] - 1 if v[1] > 0 else 0] mask = numpy.logical_or(mask, masker(shape, v, (xwidth, zwidth))) return mask
def get_features(edge): """ Returns only the edge components specifying neighbouring erosion features """ straights = get_straights(edge) all_corners = itertools.chain(edge, (x for x in get_induced_corners(edge) if not vec.inside(x, edge))) concave, convex = get_corners(all_corners, straights) return straights, concave, convex
def make_mask_straights(shape, width, seed, components, straights): """ Make a mask out of all straight edge types """ mask = numpy.zeros(shape, dtype=bool) for v in straights: base_width = int(numpy.round(width/narrowing_factor)) if vec.inside(-v, components) else int(numpy.round(width)) shore = itertools.repeat(base_width) if seed is None else river_shore(shape, seed, base_width, v) mask = numpy.logical_or(mask, mask_edge(shape, v, shore)) return mask
def get_induced_corners(edge): """ These corners are induced by straight edges """ corners = [] for x in (-1, 1): for z in (-1, 1): corner = numpy.array([x, z]) if all(vec.inside(v, edge) for v in vec.decompose(corner)): corners.append(corner) return corners
def get_features(edge): """ Returns only the edge components specifying neighbouring erosion features """ straights = get_straights(edge) all_corners = itertools.chain( edge, (x for x in get_induced_corners(edge) if not vec.inside(x, edge))) concave, convex = get_corners(all_corners, straights) return straights, concave, convex
def make_mask_straights(shape, width, seed, components, straights): """ Make a mask out of all straight edge types """ mask = numpy.zeros(shape, dtype=bool) for v in straights: base_width = int(numpy.round(width / narrowing_factor)) if vec.inside( -v, components) else int(numpy.round(width)) shore = itertools.repeat(base_width) if seed is None else river_shore( shape, seed, base_width, v) mask = numpy.logical_or(mask, mask_edge(shape, v, shore)) return mask
def get_corners(edge, straights): """ Get vectors representing corners """ concave_corners = [] convex_corners = [] for corner in (v for v in edge if v[0] != 0 and v[1] != 0): # Are the corner component vectors in straight edges? in_straight = [vec.inside(v, straights) for v in vec.decompose(corner)] # If all or none of the component vectors are in straight edges then it's a real corner if all(in_straight): convex_corners.append(corner) elif not any(in_straight): concave_corners.append(corner) return concave_corners, convex_corners