Skip to content

Instantly share code, notes, and snippets.

@philippotto
Last active July 22, 2019 13:31
Show Gist options
  • Save philippotto/9a0ca5c96c0428226e3ad2db03f5aa80 to your computer and use it in GitHub Desktop.
Save philippotto/9a0ca5c96c0428226e3ad2db03f5aa80 to your computer and use it in GitHub Desktop.
async function applyMapping(api) {
const trees = api.tracing.getAllTrees();
const currentTreeId = api.tracing.getActiveTreeId();
const currentTree = trees[currentTreeId];
const segmentationName = api.data.getVolumeTracingLayerName()
const cellIdSet = new Set()
for (const node of currentTree.nodes.values()) {
const cellId = await api.data.getDataValue(segmentationName, node.position);
cellIdSet.add(cellId);
}
const cellIds = Array.from(cellIdSet.values());
const mapping = {};
for (const cellId of cellIds) {
mapping[cellId] = cellId
}
api.data.setMapping(segmentationName, mapping, { hideUnmappedIds: true})
}
webknossos.apiReady(3).then(api => {
api.utils.registerOverwrite("SET_ACTIVE_TREE", (store, next, originalAction) => {
next(originalAction);
applyMapping(api)
});
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment