Skip to content

Commit

Permalink
fix: move add cube tool to annotationlayer, todo: share
Browse files Browse the repository at this point in the history
  • Loading branch information
jinhan committed Feb 13, 2024
1 parent a367893 commit db7b43d
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 17 deletions.
2 changes: 1 addition & 1 deletion config/custom-keybinds.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"provider": "graphene"
},
"keyt": {
"layer": "segmentation",
"layer": "annotation",
"tool": "annotateCustomCube"
}
}
65 changes: 49 additions & 16 deletions src/widgets/add_cube_annotation.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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({
Expand Down Expand Up @@ -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,
Expand All @@ -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;
}
}
Expand Down Expand Up @@ -150,7 +158,8 @@ class AddCubeAnnotationState extends RefCounted implements Trackable {
}
}

class AddCubeAnnotationTool extends LayerTool<SegmentationUserLayer> {
// class AddCubeAnnotationTool extends LayerTool<SegmentationUserLayer> {
class AddCubeAnnotationTool extends LayerTool<AnnotationUserLayer> {
cubeAnnotationState: AnnotationLayerState;
annotation: Annotation;
addCubeAnnotationState = new AddCubeAnnotationState();
Expand Down Expand Up @@ -212,7 +221,12 @@ class AddCubeAnnotationTool extends LayerTool<SegmentationUserLayer> {

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;
Expand All @@ -229,6 +243,22 @@ class AddCubeAnnotationTool extends LayerTool<SegmentationUserLayer> {
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);
Expand Down Expand Up @@ -258,7 +288,10 @@ class AddCubeAnnotationTool extends LayerTool<SegmentationUserLayer> {
}

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)
})
}
Expand Down

0 comments on commit db7b43d

Please sign in to comment.