Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: shortcut for multicut to improve usability #560

Merged
merged 3 commits into from
Jun 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/neuroglancer/graph/graph_operation_layer_state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ export class GraphOperationLayerState extends RefCounted {
this.annotationToSupervoxelA.isActive.value = true;
this.annotationToSupervoxelB.isActive.value = false;
}
this.changed.dispatch();
}

getReference(id: AnnotationId): AnnotationReference {
Expand Down
11 changes: 10 additions & 1 deletion src/neuroglancer/segmentation_user_layer_with_graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import {StatusMessage} from 'neuroglancer/status';
import {trackableAlphaValue} from 'neuroglancer/trackable_alpha';
import {TrackableBoolean} from 'neuroglancer/trackable_boolean';
import {TrackableValue, WatchableRefCounted, WatchableValue} from 'neuroglancer/trackable_value';
import {GraphOperationTab, SelectedGraphOperationState} from 'neuroglancer/ui/graph_multicut';
import {enableSplitPointTool, GraphOperationTab, PlaceGraphOperationMarkerTool, SelectedGraphOperationState} from 'neuroglancer/ui/graph_multicut';
import {Uint64Set} from 'neuroglancer/uint64_set';
import {TrackableRGB} from 'neuroglancer/util/color';
import {Borrowed, RefCounted} from 'neuroglancer/util/disposable';
Expand Down Expand Up @@ -321,6 +321,15 @@ function helper<TBase extends BaseConstructor>(Base: TBase) {
this.reloadManifest();
break;
}
case 'switch-multicut-group': {
if (this.tool.value === undefined ||
(!(this.tool.value instanceof PlaceGraphOperationMarkerTool))) {
enableSplitPointTool(this, this.graphOperationLayerState.value!);
} else {
this.graphOperationLayerState.value!.toggleSource();
}
break;
}
default:
super.handleAction(action);
break;
Expand Down
1 change: 1 addition & 0 deletions src/neuroglancer/ui/default_input_event_bindings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export function getDefaultGlobalBindings() {
map.set('space', 'toggle-layout');
map.set('shift+space', 'toggle-layout-alternative');
map.set('backslash', 'toggle-show-statistics');
map.set('control+shift+backslash', 'switch-multicut-group');
defaultGlobalBindings = map;
}
return defaultGlobalBindings;
Expand Down
34 changes: 29 additions & 5 deletions src/neuroglancer/ui/graph_multicut.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,26 @@ function getCenterPosition(annotation: Annotation, transform: mat4) {
return vec3.transformMat4(center, center, transform);
}

export function enableSplitPointTool(
layer: SegmentationUserLayerWithGraph, graphOperationLayerState: GraphOperationLayerState) {
layer.tool.value = new PlaceGraphOperationMarkerTool(
layer, {},
() => {
if (graphOperationLayerState.activeSource === graphOperationLayerState.sourceA) {
return 'set graph red split point';
} else {
return 'set graph blue split point';
}
},
() => {
if (graphOperationLayerState.activeSource === graphOperationLayerState.sourceA) {
return 'rgb(255,0,0)';
} else {
return 'rgb(120,120,255)';
}
});
}

export class GraphOperationLayerView extends Tab {
private annotationListContainer = document.createElement('ul');
private annotationListElements = new Map<string, HTMLElement>();
Expand Down Expand Up @@ -319,9 +339,7 @@ export class GraphOperationLayerView extends Tab {
const pointButton = document.createElement('button');
pointButton.textContent = getAnnotationTypeHandler(AnnotationType.POINT).icon;
pointButton.title = 'Set split point';
pointButton.addEventListener('click', () => {
this.wrapper.tool.value = new PlaceGraphOperationMarkerTool(this.wrapper, {});
});
pointButton.addEventListener('click', enableSplitPointTool.bind(undefined, this.wrapper, this.annotationLayer));
toolbox.appendChild(pointButton);
}

Expand Down Expand Up @@ -979,8 +997,14 @@ abstract class PlaceGraphOperationTool extends Tool {
}

export class PlaceGraphOperationMarkerTool extends PlaceGraphOperationTool {
constructor(layer: SegmentationUserLayerWithGraph, options: any) {
private _getDescription: () => string;

constructor(
layer: SegmentationUserLayerWithGraph, options: any, getDescription: () => string,
getDescriptionColor: () => string) {
super(layer, options);
this._getDescription = getDescription;
this.getDescriptionColor = getDescriptionColor;
}

trigger(mouseState: MouseSelectionState) {
Expand Down Expand Up @@ -1039,7 +1063,7 @@ export class PlaceGraphOperationMarkerTool extends PlaceGraphOperationTool {
}

get description() {
return `set graph merge/split point`;
return this._getDescription();
}

toJSON() {
Expand Down
1 change: 1 addition & 0 deletions src/neuroglancer/ui/tool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export abstract class Tool extends RefCounted {
abstract toJSON(): any;
deactivate(): void {}
description: string;
getDescriptionColor?(): string;
}

export function restoreTool(layer: UserLayer, obj: any) {
Expand Down
2 changes: 1 addition & 1 deletion src/neuroglancer/viewer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -762,7 +762,7 @@ export class Viewer extends RefCounted implements ViewerState {
private registerActionListeners() {
for (const action
of ['recolor', 'clear-segments', 'merge-selected', 'cut-selected',
'shatter-segment-equivalences']) {
'shatter-segment-equivalences', 'switch-multicut-group']) {
this.bindAction(action, () => {
this.layerManager.invokeAction(action);
});
Expand Down
18 changes: 18 additions & 0 deletions src/neuroglancer/widget/annotation_tool_status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,25 @@ export class AnnotationToolStatusWidget extends RefCounted {
return tool.description;
}

private getDescriptionColor(): string {
const defaultColor = '#33cc33';
const layer = this.selectedLayer.layer;
if (layer === undefined) {
return defaultColor;
}
const userLayer = layer.layer;
if (userLayer === null) {
return defaultColor;
}
const tool = userLayer.tool.value;
if (tool === undefined || tool.getDescriptionColor === undefined) {
return defaultColor;
}
return tool.getDescriptionColor();
}

private updateView() {
this.element.textContent = this.getDescriptionText() || '';
this.element.style.color = this.getDescriptionColor();
}
}