Skip to content

Commit

Permalink
changes for demo
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisj committed Nov 5, 2024
1 parent efb5a25 commit 54643cc
Show file tree
Hide file tree
Showing 8 changed files with 95 additions and 84 deletions.
14 changes: 7 additions & 7 deletions src/datasource/graphene/backend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ export class ChunkedGraphLayer extends withSegmentationLayerBackendState(
readonly sessionId = self.crypto.randomUUID();

constructor(rpc: RPC, options: any) {
console.log("ChunkedGraphLayer constructor");
// console.log("ChunkedGraphLayer constructor");
super(rpc, options);
this.source = this.registerDisposer(
rpc.getRef<GrapheneChunkedGraphChunkSource>(options.source),
Expand All @@ -384,15 +384,15 @@ export class ChunkedGraphLayer extends withSegmentationLayerBackendState(
this.debouncedUpdateDisplayState();
}),
);
this.registerDisposer(() => {
console.log("ChunkedGraphLayer disposed really", this.sessionId);
});
// this.registerDisposer(() => {
// console.log("ChunkedGraphLayer disposed really", this.sessionId);
// });
}

disposed() {
console.log("ChunkedGraphLayer disposed called");
// console.log("ChunkedGraphLayer disposed called");
if (this.refCount === 0) {
console.log("ChunkedGraphLayer invoking disposers", this.sessionId);
// console.log("ChunkedGraphLayer invoking disposers", this.sessionId);
const { disposers } = this;
if (disposers !== undefined) {
invokeDisposers(disposers);
Expand Down Expand Up @@ -522,7 +522,7 @@ export class ChunkedGraphLayer extends withSegmentationLayerBackendState(
}

private debouncedUpdateDisplayState = debounce(() => {
console.log("ChunkedGraphLayer debounced update invoked", this.sessionId);
// console.log("ChunkedGraphLayer debounced update invoked", this.sessionId);
if (this.wasDisposed) return;
this.updateDisplayState();
}, 100);
Expand Down
98 changes: 50 additions & 48 deletions src/datasource/graphene/frontend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -712,52 +712,54 @@ export class GrapheneDataSource extends PrecomputedDataSource {
const { url: providerUrl, parameters } = parseProviderUrl(
options.providerUrl,
);
// return options.chunkManager.memoize.getUncounted(
// { type: "graphene:get", providerUrl, parameters },
// async (): Promise<DataSource> => {
const { url, credentialsProvider } = parseSpecialUrl(
providerUrl,
options.credentialsManager,
);
let metadata: any;
try {
metadata = await getJsonMetadata(
options.chunkManager,
credentialsProvider,
url,
);
} catch (e) {
if (isNotFoundError(e)) {
if (parameters["type"] === "mesh") {
console.log("does this happen?");
const state = options.state;
state;
return options.chunkManager.memoize.getUncounted(
{ type: "graphene:get", providerUrl, parameters, state },
async (): Promise<DataSource> => {
const { url, credentialsProvider } = parseSpecialUrl(
providerUrl,
options.credentialsManager,
);
let metadata: any;
try {
metadata = await getJsonMetadata(
options.chunkManager,
credentialsProvider,
url,
);
} catch (e) {
if (isNotFoundError(e)) {
if (parameters["type"] === "mesh") {
console.log("does this happen?");
}
}
throw e;
}
}
throw e;
}
verifyObject(metadata);
const redirect = verifyOptionalObjectProperty(
metadata,
"redirect",
verifyString,
);
if (redirect !== undefined) {
throw new RedirectError(redirect);
}
const t = verifyOptionalObjectProperty(metadata, "@type", verifyString);
switch (t) {
case "neuroglancer_multiscale_volume":
case undefined:
return await getVolumeDataSource(
options,
credentialsProvider,
url,
verifyObject(metadata);
const redirect = verifyOptionalObjectProperty(
metadata,
"redirect",
verifyString,
);
default:
throw new Error(`Invalid type: ${JSON.stringify(t)}`);
}
// },
// );
if (redirect !== undefined) {
throw new RedirectError(redirect);
}
const t = verifyOptionalObjectProperty(metadata, "@type", verifyString);
switch (t) {
case "neuroglancer_multiscale_volume":
case undefined:
return await getVolumeDataSource(
options,
credentialsProvider,
url,
metadata,
);
default:
throw new Error(`Invalid type: ${JSON.stringify(t)}`);
}
},
);
}
}

Expand Down Expand Up @@ -908,7 +910,7 @@ class GrapheneState extends RefCounted implements Trackable {
}

toJSON() {
console.log("GS toJSON");
// console.log("GS toJSON");
return {
[MULTICUT_JSON_KEY]: this.multicutState.toJSON(),
[MERGE_JSON_KEY]: this.mergeState.toJSON(),
Expand Down Expand Up @@ -1315,7 +1317,7 @@ class GraphConnection extends SegmentationGraphSourceConnection {
private chunkSource: GrapheneMultiscaleVolumeChunkSource,
public state: GrapheneState,
) {
console.log("GraphConnection constructor");
// console.log("GraphConnection constructor");
super(graph, layer.displayState.segmentationGroupState.value);
const segmentsState = layer.displayState.segmentationGroupState.value;
this.previousVisibleSegmentCount = segmentsState.visibleSegments.size;
Expand Down Expand Up @@ -2475,9 +2477,9 @@ class SliceViewPanelChunkedGraphLayer extends SliceViewPanelRenderLayer {
});
this.registerDisposer(sharedObject.visibility.add(this.visibility));

this.registerDisposer(() => {
console.log("SliceViewPanelChunkedGraphLayer disposed");
});
// this.registerDisposer(() => {
// console.log("SliceViewPanelChunkedGraphLayer disposed");
// });

this.registerDisposer(
this.leafRequestsActive.changed.add(() => {
Expand Down
2 changes: 1 addition & 1 deletion src/layer/segmentation/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,7 @@ export class SegmentationUserLayer extends Base {
);

constructor(managedLayer: Borrowed<ManagedUserLayer>) {
console.log("SegmentationUserLayer constructor");
// console.log("SegmentationUserLayer constructor");
super(managedLayer);
this.registerDisposer(
registerNestedSync((context, group) => {
Expand Down
15 changes: 8 additions & 7 deletions src/shared_disjoint_sets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,13 @@ export class SharedDisjointUint64Sets
highBitRepresentative: WatchableValueInterface<VisibleSegmentEquivalencePolicy>,
name = "foo",
) {
name;
const obj = new SharedDisjointUint64Sets();
console.log(
"making SharedDisjointUint64Sets counterpart",
name,
obj.sessionId,
);
// console.log(
// "making SharedDisjointUint64Sets counterpart",
// name,
// obj.sessionId,
// );
obj.disjointSets.visibleSegmentEquivalencePolicy = highBitRepresentative;
obj.registerDisposer(
highBitRepresentative.changed.add(() => {
Expand All @@ -79,12 +80,12 @@ export class SharedDisjointUint64Sets
if (highBitRepresentative.value) {
updateHighBitRepresentative(obj);
}
console.log("returning", obj);
// console.log("returning", obj);
return obj;
}

disposed() {
console.log("SharedDisjointUint64Sets disposed!", this.sessionId);
// console.log("SharedDisjointUint64Sets disposed!", this.sessionId);
this.debugDisposed = true;
this.disjointSets = <any>undefined;
this.changed = <any>undefined;
Expand Down
14 changes: 10 additions & 4 deletions src/ui/default_viewer_setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,23 +205,29 @@ export function setupDefaultViewer() {

let inReplay = false;

(window as any).ngReplay = (sessionId: string) => {
(window as any).ngReplay = (sessionId: string, skipForward = true) => {
if (inReplay) return;
hashBinding.recording = false;
inReplay = true;
const startTime = Date.now();
let startTime = Date.now();
let historyIndex = 0;
let nextState = localStorage.getItem(`${sessionId}_${historyIndex}`);
if (!nextState) {
console.log(`no history for session ${sessionId}`);
return;
}
let nextTime = parseInt(
localStorage.getItem(`${sessionId}_${historyIndex}_time`)!,
);

const loop = () => {
const elapsedTime = Date.now() - startTime;
console.log("replay", elapsedTime, historyIndex, nextTime - elapsedTime);
let elapsedTime = Date.now() - startTime;
if (skipForward && nextTime - elapsedTime > 5000) {
startTime -= nextTime - elapsedTime - 5000;
elapsedTime = Date.now() - startTime;
// console.log("jumping forward");
}
// console.log("replay", elapsedTime, historyIndex, nextTime - elapsedTime);
if (nextTime > 0 && elapsedTime >= nextTime) {
// set new state
viewer.state.restoreState(JSON.parse(nextState!));
Expand Down
15 changes: 8 additions & 7 deletions src/ui/url_hash_binding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,17 +90,17 @@ export class UrlHashBinding extends RefCounted {
const throttledSetUrlHash = debounce(
() => this.setUrlHash(),
updateDelayMilliseconds,
{ maxWait: updateDelayMilliseconds * 2 },
{ maxWait: updateDelayMilliseconds },
);
this.registerDisposer(root.changed.add(throttledSetUrlHash));
this.registerDisposer(() => throttledSetUrlHash.cancel());
this.defaultFragment = defaultFragment;

this.registerDisposer(
root.changed.add(() => {
this.setUrlHash(true);
}),
);
// this.registerDisposer(
// root.changed.add(() => {
// this.setUrlHash(true);
// }),
// );
}

/**
Expand All @@ -115,7 +115,7 @@ export class UrlHashBinding extends RefCounted {
const stateString = encodeFragment(jsonString);
if (stateString !== this.prevStateString) {
this.prevStateString = stateString;
if (saveOnly) {
if (!saveOnly) {
if (decodeURIComponent(stateString) === "{}") {
history.replaceState(null, "", "#");
} else {
Expand Down Expand Up @@ -189,6 +189,7 @@ export class UrlHashBinding extends RefCounted {
this.root.reset();
const state = urlSafeParse(s);
verifyObject(state);
upgradeState;
this.root.restoreState(upgradeState(state));
} else {
throw new Error(
Expand Down
1 change: 1 addition & 0 deletions src/viewer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@ class TrackableViewerState extends CompoundTrackable {
}

restoreState(obj: any) {
console.log("restore state!");
const { viewer } = this;
super.restoreState(obj);
// Handle legacy properties
Expand Down
20 changes: 10 additions & 10 deletions src/worker_rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -340,10 +340,10 @@ registerRPC("SharedObject.dispose", function (x) {
if (DEBUG) {
console.log(`[${IS_WORKER}] #rpc objects: ${this.numObjects}`);
}
if (obj.RPC_TYPE_ID === "ChunkedGraphLayer") {
console.log("RPC DISPOSING CHUNKED_GRAPH_LAYER");
}
console.log("RPC DISPOSE", obj);
// if (obj.RPC_TYPE_ID === "ChunkedGraphLayer") {
// console.log("RPC DISPOSING CHUNKED_GRAPH_LAYER");
// }
// console.log("RPC DISPOSE", obj);
obj.disposed();
this.delete(obj.rpcId!);
obj.rpcId = null;
Expand Down Expand Up @@ -399,12 +399,12 @@ registerRPC("SharedObject.new", function (x) {

// console.log("test", obj);

if ((obj as any).constructor.name === "SharedDisjointUint64Sets") {
console.log(
"SharedObject.new SharedDisjointUint64Sets",
(obj as any).sessionId,
);
}
// if ((obj as any).constructor.name === "SharedDisjointUint64Sets") {
// console.log(
// "SharedObject.new SharedDisjointUint64Sets",
// (obj as any).sessionId,
// );
// }
// Counterpart objects start with a reference count of zero.
--obj.refCount;
});

0 comments on commit 54643cc

Please sign in to comment.