-
Notifications
You must be signed in to change notification settings - Fork 57
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
Label stack support #1816
Merged
Merged
Label stack support #1816
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
e3e85e7
Factor StackLayer from TileLayer
aschampion 635b6d3
Layer control: use space more effectively
aschampion 1febf39
Object label color map filter: fix control display
aschampion 67e1084
Stack viewer: emit events for stack layer changes
aschampion 4e2613c
Stack layer: add method to get pixel value in FOV
aschampion 649520e
Pixi layer: test unique blend modes more correctly
aschampion dfde1da
Stack viewer: allow duplicate primary stack layers to be removed
aschampion a4f9a4c
Stack viewer: allow multiple stack layers for non-primary stacks
aschampion c00d98a
Stacks: add endpoint to get groups
aschampion c8be170
Stack groups: remove unused variable
aschampion 4ee11b6
Add label annotation manager for label stacks
aschampion 3dd51fa
Label annotations: manage orthoview groups together
aschampion bda29b9
Stack layer: allow independent control of interpolation
aschampion 8f66729
Stack viewer: add method to render to data URL
aschampion 584083d
Label stacks: setup annotations if metadata exists
aschampion bbaa9e3
PR review changes from #1816
aschampion File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
171 changes: 171 additions & 0 deletions
171
django/applications/catmaid/static/js/label-annotations.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,171 @@ | ||
(function (CATMAID) { | ||
|
||
"use strict"; | ||
|
||
class LabelAnnotations { | ||
constructor() { | ||
this.groupManagingStack = new Map(); | ||
this.managers = new Map(); | ||
this.active = undefined; | ||
} | ||
|
||
activate(stackID) { | ||
this.active = stackID; | ||
} | ||
|
||
clear() { | ||
for (const [_stack, manager] of this.managers.entries()) manager.unregister(); | ||
this.managers.clear(); | ||
this.groupManagingStack.clear(); | ||
this.active = undefined; | ||
} | ||
|
||
get(stack) { | ||
let manager = this.managers.get(stack.id); | ||
|
||
if (!manager) { | ||
// Find all stack groups to which this stack belongs. | ||
return CATMAID.fetch(project.id + '/stack/' + stack.id + '/groups') | ||
.then(response => | ||
// Get the info of all of these groups. | ||
Promise.all(response.stack_group_ids.map( | ||
sg_id => CATMAID.fetch(project.id + '/stackgroup/' + sg_id + '/info'))) | ||
tomka marked this conversation as resolved.
Show resolved
Hide resolved
|
||
) | ||
.then(sg_infos => { | ||
// Find stack groups where this stack is an (ortho)view. | ||
let ortho_sgs = sg_infos | ||
.filter(sg_info => sg_info.stacks | ||
.find(s => s.id === stack.id) | ||
.relation === 'view'); | ||
|
||
// Find if an existing manager for any of these stack groups exists. | ||
let managing_stack_id = ortho_sgs.find(sg => this.groupManagingStack.get(sg.id)); | ||
|
||
if (managing_stack_id !== undefined) { | ||
manager = this.managers.get(managing_stack_id); | ||
} else { | ||
// If no manager exists, create a new one. | ||
managing_stack_id = stack.id; | ||
manager = new LabelStackAnnotations(stack); | ||
ortho_sgs.forEach(sg => this.groupManagingStack.set(sg.id, managing_stack_id)); | ||
// Add all other stack (ortho)views in all (ortho)view groups | ||
// to this manager. | ||
ortho_sgs.forEach(sg => sg.stacks | ||
.filter(s => s.relation === 'view') | ||
.forEach(s => manager.addStackID(s.id))); | ||
this.managers.set(stack.id, manager); | ||
} | ||
|
||
return manager; | ||
}); | ||
} | ||
|
||
return Promise.resolve(manager); | ||
} | ||
} | ||
|
||
CATMAID.LabelAnnotations = new LabelAnnotations(); | ||
|
||
CATMAID.Init.on(CATMAID.Init.EVENT_PROJECT_CHANGED, CATMAID.LabelAnnotations.clear, CATMAID.LabelAnnotations); | ||
|
||
|
||
const LABEL_FILTER_KEY = 'Object Label Color Map'; | ||
|
||
const SPECIAL_LABELS = { | ||
background: 0, | ||
}; | ||
|
||
class LabelStackAnnotations { | ||
constructor( | ||
primaryStack | ||
) { | ||
this.primaryStack = primaryStack; | ||
this.stackIDs = new Set([this.primaryStack.id]); | ||
this.activeLabelID = undefined; | ||
|
||
this.specialLabels = Object.assign({}, SPECIAL_LABELS, this.primaryStack.labelMetadata()); | ||
this.stackLayerFilters = new Map(); | ||
|
||
project.on(CATMAID.Project.EVENT_STACKVIEW_ADDED, | ||
this.registerStackViewerLayers, this); | ||
CATMAID.StackViewer.on(CATMAID.StackViewer.EVENT_STACK_LAYER_ADDED, | ||
this.registerStackLayer, this); | ||
CATMAID.StackViewer.on(CATMAID.StackViewer.EVENT_STACK_LAYER_REMOVED, | ||
this.unregisterStackLayer, this); | ||
|
||
this.registerAllStackLayers(); | ||
} | ||
|
||
addStackID(stackID) { | ||
this.stackIDs.add(stackID); | ||
} | ||
|
||
unregister() { | ||
project.off(CATMAID.Project.EVENT_STACKVIEW_ADDED, | ||
this.registerStackViewerLayers, this); | ||
CATMAID.StackViewer.off(CATMAID.StackViewer.EVENT_STACK_LAYER_ADDED, | ||
this.registerStackLayer, this); | ||
CATMAID.StackViewer.off(CATMAID.StackViewer.EVENT_STACK_LAYER_REMOVED, | ||
this.unregisterStackLayer, this); | ||
this.stackLayerFilters.clear(); | ||
} | ||
|
||
activateLabel(labelID) { | ||
this.activeLabelID = labelID; | ||
|
||
for (const [stackLayer, filter] of this.stackLayerFilters.entries()) { | ||
this.updateFilter(filter); | ||
stackLayer.redraw(); | ||
stackLayer.stackViewer.layercontrol.refresh(); | ||
} | ||
} | ||
|
||
registerAllStackLayers() { | ||
for (const stackViewer of project.getStackViewers()) { | ||
this.registerStackViewerLayers(stackViewer); | ||
} | ||
} | ||
|
||
registerStackViewerLayers(stackViewer) { | ||
for (const stackLayer of stackViewer.getLayersOfType(CATMAID.StackLayer)) { | ||
this.registerStackLayer(stackLayer, stackViewer); | ||
} | ||
} | ||
|
||
registerStackLayer(stackLayer, stackViewer) { | ||
if (!this.stackIDs.has(stackLayer.stack.id)) return; | ||
|
||
let layerFilters = stackLayer.getAvailableFilters ? stackLayer.getAvailableFilters() : []; | ||
if (LABEL_FILTER_KEY in layerFilters && !this.stackLayerFilters.has(stackLayer)) { | ||
stackLayer.setBlendMode('add'); | ||
stackLayer.setInterpolationMode(CATMAID.StackLayer.INTERPOLATION_MODES.NEAREST); | ||
stackLayer.isHideable = true; | ||
let filter = new (layerFilters[LABEL_FILTER_KEY])(); | ||
this.updateFilter(filter); | ||
stackLayer.addFilter(filter); | ||
this.stackLayerFilters.set(stackLayer, filter); | ||
|
||
// TODO: coupling state refresh with stack viewer. | ||
stackLayer.redraw(); | ||
stackViewer.layercontrol.refresh(); | ||
} | ||
} | ||
|
||
unregisterStackLayer(stackLayer, stackViewer) { | ||
if (!this.stackIDs.has(stackLayer.stack.id)) return; | ||
|
||
this.stackLayerFilters.delete(stackLayer); | ||
} | ||
|
||
updateFilter(filter) { | ||
filter.pixiFilter.backgroundLabel = CATMAID.PixiLayer.Filters.int2arr( | ||
this.specialLabels.background); | ||
filter.pixiFilter.unknownLabel = typeof this.activeLabelID === 'undefined' ? | ||
[-1, -1, -1, -1] : | ||
CATMAID.PixiLayer.Filters.int2arr(this.activeLabelID); | ||
} | ||
} | ||
|
||
CATMAID.LabelStackAnnotations = LabelStackAnnotations; | ||
|
||
})(CATMAID); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, using the
metadata
field of a stack is reasonable for now. Once the whole infrastructure is there and becomes clearer how everything works together, we can think about the label space implementation again.