Skip to content

Commit

Permalink
add stop_layer
Browse files Browse the repository at this point in the history
  • Loading branch information
fcollman committed May 3, 2023
1 parent 3d9939a commit 9eb296f
Showing 1 changed file with 64 additions and 65 deletions.
129 changes: 64 additions & 65 deletions src/neuroglancer/sliceview/chunked_graph/frontend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@
* limitations under the License.
*/

import {authFetch, responseIdentity} from 'neuroglancer/authentication/frontend.ts';
import {ChunkManager} from 'neuroglancer/chunk_manager/frontend';
import {VisibleSegmentsState} from 'neuroglancer/segmentation_display_state/base';
import {CHUNKED_GRAPH_LAYER_RPC_ID, CHUNKED_GRAPH_SOURCE_UPDATE_ROOT_SEGMENTS_RPC_ID, ChunkedGraphChunkSource as ChunkedGraphChunkSourceInterface, ChunkedGraphChunkSpecification, RENDER_RATIO_LIMIT} from 'neuroglancer/sliceview/chunked_graph/base';
import {SliceViewChunkSource} from 'neuroglancer/sliceview/frontend';
import {RenderLayer as GenericSliceViewRenderLayer, RenderLayerOptions} from 'neuroglancer/sliceview/renderlayer';
import {StatusMessage} from 'neuroglancer/status';
import {TrackableBoolean} from 'neuroglancer/trackable_boolean';
import {Uint64Set} from 'neuroglancer/uint64_set';
import {vec3} from 'neuroglancer/util/geom';
import {verify3dVec, verifyObjectProperty} from 'neuroglancer/util/json';
import {Uint64} from 'neuroglancer/util/uint64';
import {RPC} from 'neuroglancer/worker_rpc';
import { authFetch, responseIdentity } from 'neuroglancer/authentication/frontend.ts';
import { ChunkManager } from 'neuroglancer/chunk_manager/frontend';
import { VisibleSegmentsState } from 'neuroglancer/segmentation_display_state/base';
import { CHUNKED_GRAPH_LAYER_RPC_ID, CHUNKED_GRAPH_SOURCE_UPDATE_ROOT_SEGMENTS_RPC_ID, ChunkedGraphChunkSource as ChunkedGraphChunkSourceInterface, ChunkedGraphChunkSpecification, RENDER_RATIO_LIMIT } from 'neuroglancer/sliceview/chunked_graph/base';
import { SliceViewChunkSource } from 'neuroglancer/sliceview/frontend';
import { RenderLayer as GenericSliceViewRenderLayer, RenderLayerOptions } from 'neuroglancer/sliceview/renderlayer';
import { StatusMessage } from 'neuroglancer/status';
import { TrackableBoolean } from 'neuroglancer/trackable_boolean';
import { Uint64Set } from 'neuroglancer/uint64_set';
import { vec3 } from 'neuroglancer/util/geom';
import { verify3dVec, verifyObjectProperty } from 'neuroglancer/util/json';
import { Uint64 } from 'neuroglancer/util/uint64';
import { RPC } from 'neuroglancer/worker_rpc';

export const GRAPH_SERVER_NOT_SPECIFIED = Symbol('Graph Server Not Specified.');

Expand All @@ -49,7 +49,7 @@ export function restoreSegmentSelection(x: any): SegmentSelection {
}

export class ChunkedGraphChunkSource extends SliceViewChunkSource implements
ChunkedGraphChunkSourceInterface {
ChunkedGraphChunkSourceInterface {
rootSegments: Uint64Set;
spec: ChunkedGraphChunkSpecification;

Expand All @@ -69,19 +69,19 @@ export class ChunkedGraphChunkSource extends SliceViewChunkSource implements
updateRootSegments(rpc: RPC, rootSegments: Uint64Set) {
this.rootSegments = rootSegments;
rpc.invoke(
CHUNKED_GRAPH_SOURCE_UPDATE_ROOT_SEGMENTS_RPC_ID,
{'id': this.rpcId, 'rootSegments': this.rootSegments.rpcId});
CHUNKED_GRAPH_SOURCE_UPDATE_ROOT_SEGMENTS_RPC_ID,
{ 'id': this.rpcId, 'rootSegments': this.rootSegments.rpcId });
}
}

export class ChunkedGraphLayer extends GenericSliceViewRenderLayer {
private graphurl: string;
private leafRequestsStatusMessage: StatusMessage|undefined;
private leafRequestsStatusMessage: StatusMessage | undefined;
leafRequestsActive = new TrackableBoolean(true, true);

constructor(
chunkManager: ChunkManager, url: string, public sources: ChunkedGraphChunkSource[][],
displayState: VisibleSegmentsState&RenderLayerOptions) {
chunkManager: ChunkManager, url: string, public sources: ChunkedGraphChunkSource[][],
displayState: VisibleSegmentsState & RenderLayerOptions) {
super(chunkManager, sources, {
rpcTransfer: {
'chunkManager': chunkManager.rpcId,
Expand All @@ -108,15 +108,14 @@ export class ChunkedGraphLayer extends GenericSliceViewRenderLayer {
}

async getRoot(selection: SegmentSelection, timestamp?: string): Promise<Uint64> {
const {url} = this;
const { url } = this;
if (url === '') {
return Promise.resolve(selection.segmentId);
}

const promise = authFetch(
`${url}/node/${String(selection.segmentId)}/root?int64_as_str=1${
timestamp ? `&timestamp=${timestamp}` : ``}`,
{}, responseIdentity, undefined, false);
`${url}/node/${String(selection.segmentId)}/root?stop_layer=6&int64_as_str=1${timestamp ? `&timestamp=${timestamp}` : ``}`,
{}, responseIdentity, undefined, false);

const response = await this.withErrorMessage(promise, {
initialMessage: `Retrieving root for segment ${selection.segmentId}`,
Expand All @@ -127,20 +126,20 @@ export class ChunkedGraphLayer extends GenericSliceViewRenderLayer {
}

async mergeSegments(first: SegmentSelection, second: SegmentSelection): Promise<Uint64> {
const {url} = this;
const { url } = this;
if (url === '') {
return Promise.reject(GRAPH_SERVER_NOT_SPECIFIED);
}

const promise = authFetch(
`${url}/merge?int64_as_str=1`, {
method: 'POST',
body: JSON.stringify([
[String(first.segmentId), ...first.position.values()],
[String(second.segmentId), ...second.position.values()]
])
},
responseIdentity, undefined, false);
`${url}/merge?int64_as_str=1`, {
method: 'POST',
body: JSON.stringify([
[String(first.segmentId), ...first.position.values()],
[String(second.segmentId), ...second.position.values()]
])
},
responseIdentity, undefined, false);

const response = await this.withErrorMessage(promise, {
initialMessage: `Merging ${first.segmentId} and ${second.segmentId}`,
Expand All @@ -151,20 +150,20 @@ export class ChunkedGraphLayer extends GenericSliceViewRenderLayer {
}

async splitSegments(first: SegmentSelection[], second: SegmentSelection[]): Promise<Uint64[]> {
const {url} = this;
const { url } = this;
if (url === '') {
return Promise.reject(GRAPH_SERVER_NOT_SPECIFIED);
}

const promise = authFetch(
`${url}/split?int64_as_str=1`, {
method: 'POST',
body: JSON.stringify({
'sources': first.map(x => [String(x.segmentId), ...x.position.values()]),
'sinks': second.map(x => [String(x.segmentId), ...x.position.values()])
})
},
responseIdentity, undefined, false);
`${url}/split?int64_as_str=1`, {
method: 'POST',
body: JSON.stringify({
'sources': first.map(x => [String(x.segmentId), ...x.position.values()]),
'sinks': second.map(x => [String(x.segmentId), ...x.position.values()])
})
},
responseIdentity, undefined, false);

const response = await this.withErrorMessage(promise, {
initialMessage: `Splitting ${first.length} sources from ${second.length} sinks`,
Expand All @@ -179,25 +178,25 @@ export class ChunkedGraphLayer extends GenericSliceViewRenderLayer {
}

async splitPreview(first: SegmentSelection[], second: SegmentSelection[]):
Promise<{supervoxelConnectedComponents: Uint64Set[], isSplitIllegal: boolean}> {
const {url} = this;
Promise<{ supervoxelConnectedComponents: Uint64Set[], isSplitIllegal: boolean }> {
const { url } = this;
if (url === '') {
return Promise.reject(GRAPH_SERVER_NOT_SPECIFIED);
}

const promise = authFetch(
`${url}/graph/split_preview?int64_as_str=1`, {
method: 'POST',
body: JSON.stringify({
'sources': first.map(x => [String(x.segmentId), ...x.position.values()]),
'sinks': second.map(x => [String(x.segmentId), ...x.position.values()])
})
},
responseIdentity, undefined, false);
`${url}/graph/split_preview?int64_as_str=1`, {
method: 'POST',
body: JSON.stringify({
'sources': first.map(x => [String(x.segmentId), ...x.position.values()]),
'sinks': second.map(x => [String(x.segmentId), ...x.position.values()])
})
},
responseIdentity, undefined, false);

const response = await this.withErrorMessage(promise, {
initialMessage:
`Calculating split preview: ${first.length} sources, and ${second.length} sinks`,
`Calculating split preview: ${first.length} sources, and ${second.length} sinks`,
errorPrefix: 'Split preview failed: '
});
const jsonResp = await response.json();
Expand All @@ -213,24 +212,24 @@ export class ChunkedGraphLayer extends GenericSliceViewRenderLayer {
supervoxelConnectedComponents[i] = connectedComponentSet;
}
const jsonIllegalSplitKey = 'illegal_split';
return {supervoxelConnectedComponents, isSplitIllegal: jsonResp[jsonIllegalSplitKey]};
return { supervoxelConnectedComponents, isSplitIllegal: jsonResp[jsonIllegalSplitKey] };
}

async findPath(first: SegmentSelection, second: SegmentSelection, precisionMode: boolean):
Promise<number[][]> {
const {url} = this;
Promise<number[][]> {
const { url } = this;
if (url === '') {
return Promise.reject(GRAPH_SERVER_NOT_SPECIFIED);
}

const promise =
authFetch(`${url}/graph/find_path?int64_as_str=1&precision_mode=${Number(precisionMode)}`, {
method: 'POST',
body: JSON.stringify([
[String(first.rootId), ...first.position.values()],
[String(second.rootId), ...second.position.values()]
])
});
authFetch(`${url}/graph/find_path?int64_as_str=1&precision_mode=${Number(precisionMode)}`, {
method: 'POST',
body: JSON.stringify([
[String(first.rootId), ...first.position.values()],
[String(second.rootId), ...second.position.values()]
])
});

const response = await this.withErrorMessage(promise, {
initialMessage: `Finding path between ${first.segmentId} and ${second.segmentId}`,
Expand All @@ -243,12 +242,12 @@ export class ChunkedGraphLayer extends GenericSliceViewRenderLayer {
const missingL2Ids = jsonResponse[missingL2IdsKey];
if (missingL2Ids && missingL2Ids.length > 0) {
StatusMessage.showTemporaryMessage(
'Some level 2 meshes are missing, so the path shown may have a poor level of detail.');
'Some level 2 meshes are missing, so the path shown may have a poor level of detail.');
}
return centroids;
}

draw() {}
draw() { }

async withErrorMessage(promise: Promise<Response>, options: {
initialMessage: string,
Expand All @@ -271,7 +270,7 @@ export class ChunkedGraphLayer extends GenericSliceViewRenderLayer {
} catch {
msg = await response.text();
}
const {errorPrefix = ''} = options;
const { errorPrefix = '' } = options;
status.setErrorMessage(errorPrefix + msg);
status.setVisible(true);
throw new Error(`[${response.status}] ${errorPrefix}${msg}`);
Expand Down

0 comments on commit 9eb296f

Please sign in to comment.