Exemplo n.º 1
0
async def merge_helper(cg: ChunkedGraph, request: Request):
    from numpy import all
    from numpy import abs

    nodes = loads(await request.body())
    assert len(nodes) == 2, "Only 2 points can be merged at this time."

    atomic_edge, coords = _process_node_info(cg, nodes)
    # limit merge span to 3 chunks
    coord0 = cg.get_chunk_coordinates(atomic_edge[0])
    coord1 = cg.get_chunk_coordinates(atomic_edge[1])
    assert all(
        abs(coord0 - coord1) < 4), "Chebyshev distance exceeded, max 3 chunks."

    try:
        resp = cg.add_edges(
            user_id=request.headers.get("X-Forwarded-User",
                                        str(request.client)),
            atomic_edges=array(atomic_edge, dtype=uint64),
            source_coords=coords[:1],
            sink_coords=coords[1:],
        )
    except exceptions.LockingError as e:
        raise exceptions.InternalServerError(e)
    except exceptions.PreconditionError as e:
        raise exceptions.BadRequest(e)

    assert resp.new_root_ids is not None, "Could not merge selected supervoxels."
    if len(resp.new_lvl2_ids):
        await _remesh(cg, resp.operation_id, resp.new_lvl2_ids.tolist())
    return resp
Exemplo n.º 2
0
def _check_post_options(cg: ChunkedGraph, resp: dict, data: dict,
                        seg_ids: Iterable) -> dict:
    from ..utils import toboolean

    if toboolean(data.get("return_seg_ids", "false")):
        resp["seg_ids"] = seg_ids
    if toboolean(data.get("return_seg_id_layers", "false")):
        resp["seg_id_layers"] = cg.get_chunk_layers(seg_ids)
    if toboolean(data.get("return_seg_chunk_coordinates", "false")):
        resp["seg_chunk_coordinates"] = [
            cg.get_chunk_coordinates(seg_id) for seg_id in seg_ids
        ]
    return resp