Пример #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
Пример #2
0
async def redo(request: Request, graph_id: str, int64_as_str: Optional[bool] = False):
    from .edits_helpers import redo_helper

    try:
        result = await redo_helper(copy(get_cg(graph_id)), request)
    except (exceptions.PreconditionError, exceptions.ChunkedGraphError) as e:
        raise exceptions.BadRequest(e)
    except Exception as e:
        raise exceptions.InternalServerError(e)
    return format_edit_result(result, int64_as_str)
Пример #3
0
async def split_preview(
    request: Request, graph_id: str, int64_as_str: Optional[bool] = False
):
    from .edits_helpers import split_preview_helper

    try:
        return await split_preview_helper(
            copy(get_cg(graph_id)), request, int64_as_str=int64_as_str
        )
    except (exceptions.PreconditionError, exceptions.ChunkedGraphError) as e:
        raise exceptions.BadRequest(e)
    except Exception as e:
        raise exceptions.InternalServerError(e)
Пример #4
0
async def redo_helper(cg: ChunkedGraph, request: Request):
    operation_id = uint64(loads(await request.body())["operation_id"])
    try:
        resp = cg.redo(
            user_id=request.headers.get("X-Forwarded-User",
                                        str(request.client)),
            operation_id=operation_id,
        )
    except exceptions.LockingError as e:
        raise exceptions.InternalServerError(e)
    except (exceptions.PreconditionError, exceptions.PostconditionError) as e:
        raise exceptions.BadRequest(e)
    if len(resp.new_lvl2_ids):
        await _remesh(cg, resp.operation_id, resp.new_lvl2_ids.tolist())
    return resp
Пример #5
0
async def split_helper(cg: ChunkedGraph, request: Request):
    from collections import defaultdict

    data_dict = _process_split_request_nodes(cg, loads(await request.body()))
    try:
        resp = cg.remove_edges(
            user_id=request.headers.get("X-Forwarded-User",
                                        str(request.client)),
            source_ids=data_dict["sources"]["id"],
            sink_ids=data_dict["sinks"]["id"],
            source_coords=data_dict["sources"]["coord"],
            sink_coords=data_dict["sinks"]["coord"],
            mincut=True,
        )
    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 split selected segment groups."
    if len(resp.new_lvl2_ids):
        await _remesh(cg, resp.operation_id, resp.new_lvl2_ids.tolist())
    return resp