diff --git a/config/custom-keybinds.json b/config/custom-keybinds.json index 9b4aa85..39c074a 100644 --- a/config/custom-keybinds.json +++ b/config/custom-keybinds.json @@ -10,7 +10,7 @@ "provider": "graphene" }, "keyt": { - "layer": "segmentation", + "layer": "annotation", "tool": "annotateCustomCube" } } diff --git a/src/widgets/add_cube_annotation.ts b/src/widgets/add_cube_annotation.ts index 3a0ffd8..538c535 100644 --- a/src/widgets/add_cube_annotation.ts +++ b/src/widgets/add_cube_annotation.ts @@ -1,9 +1,9 @@ import {LayerTool, makeToolActivationStatusMessageWithHeader, registerTool, ToolActivation} from "neuroglancer/ui/tool"; -import {SegmentationUserLayer} from "neuroglancer/segmentation_user_layer"; +// import {SegmentationUserLayer} from "neuroglancer/segmentation_user_layer"; import {makeIcon} from "neuroglancer/widget/icon"; import {EventActionMap} from "neuroglancer/util/mouse_bindings"; import {TextInputWidget} from "neuroglancer/widget/text_input"; -import {TrackableValue, WatchableValue} from "neuroglancer/trackable_value"; +import {TrackableValue} from "neuroglancer/trackable_value"; import { Annotation, LocalAnnotationSource, @@ -17,12 +17,16 @@ import {removeChildren} from "neuroglancer/util/dom"; import {RenderLayerRole} from "neuroglancer/renderlayer"; import {LoadedDataSubsource} from "neuroglancer/layer_data_source"; import {vec3} from "neuroglancer/util/geom"; -import {TrackableBoolean} from "neuroglancer/trackable_boolean"; +// import {TrackableBoolean} from "neuroglancer/trackable_boolean"; import {RefCounted} from "neuroglancer/util/disposable"; import {Trackable} from "neuroglancer/util/trackable"; import {verifyOptionalObjectProperty} from "neuroglancer/util/json"; import {NullarySignal} from "neuroglancer/util/signal"; import {StatusMessage} from "neuroglancer/status"; +import {AnnotationUserLayer} from "neuroglancer/annotation/user_layer"; +// import {SegmentationUserLayer} from "neuroglancer/segmentation_user_layer"; +// import {SegmentationUserLayer} from "neuroglancer/segmentation_user_layer"; +// import {makeAnnotationListElement} from 'neuroglancer/ui/annotations'; const ADD_CUBE_TOOL_ID = "annotateCustomCube"; const ADD_CUBE_EVENT_MAP = EventActionMap.fromObject({ @@ -64,19 +68,19 @@ const calculateBoundingBox = (mousePoint: Float32Array, cubeSize: Float32Array) } function makeColoredAnnotationState( - layer: SegmentationUserLayer, loadedSubsource: LoadedDataSubsource, + layer: AnnotationUserLayer, loadedSubsource: LoadedDataSubsource, subsubsourceId: string, color: vec3, readonly = false) { const {subsourceEntry} = loadedSubsource; - const source = new LocalAnnotationSource(loadedSubsource.loadedDataSource.transform, [], ['associated segments']); + const source = new LocalAnnotationSource(loadedSubsource.loadedDataSource.transform, [], []); + // const source = new AnnotationSource(); source.readonly = readonly; - const displayState = new AnnotationDisplayState(); displayState.color.value.set(color); - - displayState.relationshipStates.set('associated segments', { - segmentationState: new WatchableValue(layer.displayState), - showMatches: new TrackableBoolean(false), - }); + console.log(loadedSubsource, source, displayState) + // displayState.relationshipStates.set('associated segments', { + // segmentationState: new WatchableValue(layer.displayState), + // showMatches: new TrackableBoolean(false), + // }); const state = new AnnotationLayerState({ localPosition: layer.localPosition, @@ -89,17 +93,21 @@ function makeColoredAnnotationState( subsubsourceId, role: RenderLayerRole.ANNOTATION, }); + console.log(layer) layer.addAnnotationLayerState(state, loadedSubsource); + console.log(state) return state; } -function getGraphLoadedSubsource(layer: SegmentationUserLayer) { +function getDefaultLoadedSubsource(layer: AnnotationUserLayer) { + for (const dataSource of layer.dataSources) { + console.log(dataSource) const {loadState} = dataSource; if (loadState === undefined || loadState.error !== undefined) continue; for (const subsource of loadState.subsources) { if (subsource.enabled) { - if (subsource.subsourceEntry.id === 'graph') { + if (subsource.subsourceEntry.id === 'default') { return subsource; } } @@ -150,7 +158,8 @@ class AddCubeAnnotationState extends RefCounted implements Trackable { } } -class AddCubeAnnotationTool extends LayerTool { +// class AddCubeAnnotationTool extends LayerTool { +class AddCubeAnnotationTool extends LayerTool { cubeAnnotationState: AnnotationLayerState; annotation: Annotation; addCubeAnnotationState = new AddCubeAnnotationState(); @@ -212,7 +221,12 @@ class AddCubeAnnotationTool extends LayerTool { const updateAnnotationElements = () => { removeChildren(annotationElements); - const loadedSubsource = getGraphLoadedSubsource(layer)!; + // const maxColumnWidths = [0, 0, 0]; + // const globalDimensionIndices = [0, 1, 2]; + // const localDimensionIndices: number[] = [0, 1, 2]; + // const template = '[symbol] 2ch [dim] var(--neuroglancer-column-0-width) [dim] var(--neuroglancer-column-1-width) [dim] var(--neuroglancer-column-2-width) [delete] min-content'; + + const loadedSubsource = getDefaultLoadedSubsource(layer)!; const YELLOW_COLOR = vec3.fromValues(1, 1, 0); const annotationGroup = makeColoredAnnotationState(layer, loadedSubsource, "addcustomcube", YELLOW_COLOR, false); this.cubeAnnotationState = annotationGroup; @@ -229,6 +243,22 @@ class AddCubeAnnotationTool extends LayerTool { properties: [] }; this.cubeAnnotationState.source.add(annotation); + // this.cubeAnnotationState.disposed(); + // layer.updateAttachedAnnotationLayerStates(); + // layer.addAnnotationLayerState(this.cubeAnnotationState, loadedSubsource) + // layer.annotations.add() + // console.log(this.cubeAnnotationState) + + // const [element, elementColumnWidths] = makeAnnotationListElement(this.layer, annotation, this.cubeAnnotationState, template, globalDimensionIndices, localDimensionIndices); + // for (const [column, width] of elementColumnWidths.entries()) { + // maxColumnWidths[column] = width; + // } + // console.log(element, elementColumnWidths) + // annotationElements.appendChild(element); + // + // for (const [column, width] of maxColumnWidths.entries()) { + // annotationElements.style.setProperty(`--neuroglancer-column-${column}-width`, `${width + 2}ch`); + // } }; activation.bindInputEventMap(ADD_CUBE_EVENT_MAP); @@ -258,7 +288,10 @@ class AddCubeAnnotationTool extends LayerTool { } export function registerAnnotateCubeTool() { - registerTool(SegmentationUserLayer, ADD_CUBE_TOOL_ID, layer => { + // registerTool(SegmentationUserLayer, ADD_CUBE_TOOL_ID, layer => { + // return new AddCubeAnnotationTool(layer, true) + // }) + registerTool(AnnotationUserLayer, ADD_CUBE_TOOL_ID, layer => { return new AddCubeAnnotationTool(layer, true) }) }