Skip to content

Commit

Permalink
Merge branch 'ng-extend-flywire' of https://github.com/seung-lab/neur…
Browse files Browse the repository at this point in the history
…oglancer into ng-extend-flywire
  • Loading branch information
ogewan committed Sep 27, 2022
2 parents 021580f + 8167375 commit d937f81
Show file tree
Hide file tree
Showing 9 changed files with 112 additions and 52 deletions.
29 changes: 29 additions & 0 deletions src/neuroglancer/graph/path_finder_state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,35 @@ class PathBetweenSupervoxels extends RefCounted {
this.changed.dispatch();
}

getLatestSegments(layer: SegmentationUserLayerWithGraph) {
if (!this._source || !this._target){
return
}
const {segmentSelectionState} = layer.displayState;
const newSource: Point = {
id: '',
segments: [
segmentSelectionState.rawSelectedSegment.clone(),
segmentSelectionState.selectedSegment.clone()
],
point: this._source.point,
type: AnnotationType.POINT,
};

const newTarget: Point = {
id: '',
segments: [
segmentSelectionState.rawSelectedSegment.clone(),
segmentSelectionState.selectedSegment.clone()
],
point: this._target.point,
type: AnnotationType.POINT,
};
this.clear();
this.addSourceOrTarget(newSource);
this.addSourceOrTarget(newTarget);
}

toJSON() {
const x: any = {
[ANNOTATION_PATH_JSON_KEY]: this.annotationSource.toJSON(),
Expand Down
18 changes: 18 additions & 0 deletions src/neuroglancer/segmentation_user_layer_with_graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -330,12 +330,30 @@ function helper<TBase extends BaseConstructor>(Base: TBase) {
}
break;
}
case 'decrease-segmentation-opacity': {
this.changeOnOpacity('decrease');
break;
}
case 'increase-segmentation-opacity': {
this.changeOnOpacity('increase');
break;
}
default:
super.handleAction(action);
break;
}
}

changeOnOpacity(direction: string) {
// function that changes opacity by 10%
if (direction === "decrease") {
this.displayState.objectAlpha.value = Math.round(Math.max(0, this.displayState.objectAlpha.value - 0.1)*10)/10;
}

else if (direction === "increase") {
this.displayState.objectAlpha.value = Math.round(Math.min(1, this.displayState.objectAlpha.value + 0.1)*10)/10;
}
}
getRootOfSelectedSupervoxel() {
let {segmentSelectionState, timestamp} = this.displayState;
let tsValue = (timestamp.value !== '') ? timestamp.value : void (0);
Expand Down
4 changes: 2 additions & 2 deletions src/neuroglancer/sliceview/chunked_graph/frontend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,8 @@ export class ChunkedGraphLayer extends GenericSliceViewRenderLayer {
this.leafRequestsStatusMessage = undefined;
StatusMessage.showTemporaryMessage('Loading chunked graph segmentation...', 3000);
} else if ((!this.leafRequestsStatusMessage) && (!leafRequestsActive)) {
this.leafRequestsStatusMessage = StatusMessage.showMessage(
'At this zoom level, chunked graph segmentation will not be loaded. Please zoom in if you wish to load it.');
this.leafRequestsStatusMessage = StatusMessage.showTemporaryMessage(
'At this zoom level, chunked graph segmentation will not be loaded. Please zoom in if you wish to load it.', 3000);
}
}
}
8 changes: 8 additions & 0 deletions src/neuroglancer/status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,4 +151,12 @@ export class StatusMessage {
}): StatusMessage {
return this.showTemporaryMessage(message, closeAfter, config);
}

static disposeAll() {
if (statusContainer !== null) {
while (statusContainer.firstChild) {
statusContainer.removeChild(statusContainer.firstChild);
}
}
}
}
5 changes: 4 additions & 1 deletion src/neuroglancer/ui/default_input_event_bindings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ 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');
map.set('keyg', 'switch-multicut-group');
map.set('keyi', 'decrease-segmentation-opacity');
map.set('keyu', 'increase-segmentation-opacity');
map.set('keyx', 'dismiss-all-status-messages');
defaultGlobalBindings = map;
}
return defaultGlobalBindings;
Expand Down
8 changes: 4 additions & 4 deletions src/neuroglancer/viewer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -766,7 +766,8 @@ export class Viewer extends RefCounted implements ViewerState {
private registerActionListeners() {
for (const action
of ['recolor', 'clear-segments', 'merge-selected', 'cut-selected',
'shatter-segment-equivalences', 'switch-multicut-group']) {
'shatter-segment-equivalences', 'switch-multicut-group',
'decrease-segmentation-opacity', 'increase-segmentation-opacity']) {
this.bindAction(action, () => {
this.layerManager.invokeAction(action);
});
Expand All @@ -788,7 +789,8 @@ export class Viewer extends RefCounted implements ViewerState {
});

this.bindAction('help', () => this.showHelpDialog());

this.bindAction('dismiss-all-status-messages', () => StatusMessage.disposeAll() )

for (let i = 1; i <= 9; ++i) {
this.bindAction(`toggle-layer-${i}`, () => {
const layerIndex = i - 1;
Expand Down Expand Up @@ -1113,8 +1115,6 @@ export class Viewer extends RefCounted implements ViewerState {
}
hashBinding.parseError;
}));
StatusMessage.showTemporaryMessage(
`RAW URLs will soon be Deprecated. Please use JSON URLs whenever available.`, 10000);
hashBinding.updateFromUrlHash();

return hashBinding;
Expand Down
79 changes: 40 additions & 39 deletions src/neuroglancer/widget/find_path_widget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,50 +69,51 @@ export class FindPathWidget extends RefCounted {
selectSourceAndTargetButton.addEventListener('click', () => {
this.layer.tool.value = new PathFindingMarkerTool(this.layer);
});
let pathFound = false;
const {findPathButton, precisionModeCheckbox} = this;
precisionModeCheckbox.addEventListener('click', () => {
pathFound = false;
});
let pathFound = false;
precisionModeCheckbox.checked = true;
findPathButton.textContent = '✔️';
findPathButton.title = 'Find path';
findPathButton.addEventListener('click', () => {
if (!pathFound) {
if (!this.pathBetweenSupervoxels.ready()) {
StatusMessage.showTemporaryMessage('You must select a source and target to find a path');
} else {
const getSegmentSelectionFromPoint = (point: Point) => {
return {
segmentId: point.segments![0],
rootId: point.segments![1],
position: point.point
};
};
this.layer.chunkedGraphLayer!
.findPath(
getSegmentSelectionFromPoint(this.pathBetweenSupervoxels.source!),
getSegmentSelectionFromPoint(this.pathBetweenSupervoxels.target!),
precisionModeCheckbox.checked)
.then((centroids) => {
pathFound = true;
findPathButton.title = 'Path found!';
StatusMessage.showTemporaryMessage('Path found!', 5000);
const path: Line[] = [];
for (let i = 0; i < centroids.length - 1; i++) {
const line: Line = {
pointA: vec3.fromValues(centroids[i][0], centroids[i][1], centroids[i][2]),
pointB: vec3.fromValues(
centroids[i + 1][0], centroids[i + 1][1], centroids[i + 1][2]),
id: '',
type: AnnotationType.LINE
};
path.push(line);
}
this.pathBetweenSupervoxels.setPath(path);
});
}
if (!this.pathBetweenSupervoxels.ready()) {
StatusMessage.showTemporaryMessage('You must select a source and target to find a path');
} else {
StatusMessage.showTemporaryMessage('Requested path already found.');
// Update Points to have the latest segment ID if path has already been found.
if (pathFound) {
console.log("Retrieving latest segments")
this.pathBetweenSupervoxels.getLatestSegments(this.layer);
}
const getSegmentSelectionFromPoint = (point: Point) => {
return {
segmentId: point.segments![0],
rootId: point.segments![1],
position: point.point
};
};
this.layer.chunkedGraphLayer!
.findPath(
getSegmentSelectionFromPoint(this.pathBetweenSupervoxels.source!),
getSegmentSelectionFromPoint(this.pathBetweenSupervoxels.target!),
precisionModeCheckbox.checked)
.then((centroids) => {
pathFound = true;
findPathButton.title = 'Path found!';
StatusMessage.showTemporaryMessage('Path found!', 5000);
const path: Line[] = [];
for (let i = 0; i < centroids.length - 1; i++) {
const line: Line = {
pointA: vec3.fromValues(centroids[i][0], centroids[i][1], centroids[i][2]),
pointB: vec3.fromValues(
centroids[i + 1][0], centroids[i + 1][1], centroids[i + 1][2]),
id: '',
type: AnnotationType.LINE
};
path.push(line);
}
this.pathBetweenSupervoxels.setPath(path);
}, error => {
StatusMessage.showTemporaryMessage(`Path finding failed: ${error}`);
});
}
});
const clearButton = document.createElement('button');
Expand Down
8 changes: 4 additions & 4 deletions src/neuroglancer/widget/segment_set_widget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,20 +259,20 @@ export class SegmentSetWidget extends RefCounted {
itemButton.title = `Remove segment ID ${segmentIDString}`;
itemButton.dataset.segId = segmentIDString;
itemButton.addEventListener('click', function(this: HTMLButtonElement) {
temp.tryParseString(this.textContent!);
temp.tryParseString(this.dataset.segId!);
widget.rootSegments.delete(temp);
widget.hiddenRootSegments!.delete(temp);
widget.segmentColors.delete(segmentIDString);
});
itemButton.addEventListener('mouseenter', function(this: HTMLButtonElement) {
temp.tryParseString(this.textContent!);
temp.tryParseString(this.dataset.segId!);
widget.segmentSelectionState.set(temp);
widget.segmentSelectionState.setRaw(temp);
this.classList.add('selectedSeg');
this.style.setProperty('--pulseSpeed', '2.5s');
});
itemButton.addEventListener('mouseleave', function(this: HTMLButtonElement) {
temp.tryParseString(this.textContent!);
temp.tryParseString(this.dataset.segId!);
widget.segmentSelectionState.set(null);
widget.segmentSelectionState.setRaw(null);
this.classList.remove('selectedSeg');
Expand Down Expand Up @@ -381,7 +381,7 @@ export class SegmentSetWidget extends RefCounted {

private setItemButtonColor(itemElement: ItemElement) {
const itemButton = <HTMLElement>(itemElement.getElementsByClassName('segment-button')[0]);
const segmentIDString = itemButton.textContent!;
const segmentIDString = itemButton.dataset.segId!;
itemButton.style.backgroundColor = this.getSegmentColor(segmentIDString);
}

Expand Down
5 changes: 3 additions & 2 deletions src/neuroglancer/widget/time_segment_widget.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import 'flatpickr/dist/flatpickr.min.css';

import flatpickr from 'flatpickr';
import minMaxTimePlugin from 'flatpickr/dist/plugins/minMaxTimePlugin';
import {SegmentationUserLayerWithGraphDisplayState} from 'neuroglancer/segmentation_user_layer_with_graph';
import {TrackableValue} from 'neuroglancer/trackable_value';
import {RefCounted} from 'neuroglancer/util/disposable';
import {removeFromParent} from 'neuroglancer/util/dom';

import 'flatpickr/dist/flatpickr.min.css';

export class TimeSegmentWidget extends RefCounted {
element = document.createElement('div');
input = <HTMLInputElement>document.createElement('input');
Expand Down Expand Up @@ -82,6 +82,7 @@ export class TimeSegmentWidget extends RefCounted {
defaultDate,
enableTime: true,
enableSeconds: true,
dateFormat: 'Z',
'disable': [(date) => {
const target = date.valueOf();
const future = Date.now();
Expand Down

0 comments on commit d937f81

Please sign in to comment.