Last active
April 1, 2021 08:43
-
-
Save heikowissler/498f38429ca307f28042d97b4aed8634 to your computer and use it in GitHub Desktop.
edgeMode2
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
window.webknossos.apiReady(3).then(async(api) => { | |
const welcomeMessage = | |
`edgeMode (version 17.02.2021) | |
[6] Adds "Yes" to current tree name | |
[5] Adds "Maybe" to current tree name | |
[4] Adds "No" to current tree name`; | |
/* | |
Edge Annotation Tool | |
Easily label edge tracings with a single key stroke. | |
Note: User must create a new node for this script to work. | |
Written by | |
Alessandro Motta <alessandro.motta@brain.mpg.de> | |
Modified by | |
Sahil Loomba <sahil.loomba@brain.mpg.de> | |
Thanks to | |
Anselm Weber for valuable input | |
*/ | |
function updateTree(treeId, nameSuffix, color, treeVisibility, groupId) { | |
let oldName = api.tracing.getTreeName(treeId); | |
let newName = oldName + " " + nameSuffix; | |
api.tracing.setTreeName(newName, treeId); | |
if (treeVisibility === undefined) { treeVisibility = false; } | |
api.tracing.setTreeVisibility(treeId, treeVisibility); | |
if (groupId !== undefined) { | |
api.tracing.setTreeGroup(treeId, groupId); | |
} | |
} | |
function goToNextTree() { | |
// Find next unlabled tree | |
let treeId = allTreeIds.find(curTreeId => { | |
let curTreeName = api.tracing.getTreeName(curTreeId); | |
return (curTreeName.match(/.*\(\w+\)$/) === null); | |
}); | |
if (treeId === undefined) { | |
alert("Congratulation! You're done! You can finish and get next task"); | |
} | |
api.tracing.setActiveTree(treeId); | |
allTreeIds.forEach(id => api.tracing.setTreeVisibility(id, id == treeId)); | |
} | |
function doTree(label, color, treeVisibility, groupId) { | |
let suffix = "(" + label + ")"; | |
let treeId = api.tracing.getActiveTreeId(); | |
updateTree(treeId, suffix, color, treeVisibility, groupId); | |
goToNextTree(); | |
} | |
function shuffleArray(array) { | |
for (let i = array.length - 1; i > 0; i--) { | |
const j = Math.floor(Math.random() * (i + 1)); | |
[array[i], array[j]] = [array[j], array[i]]; | |
} | |
return array; | |
} | |
/* NOTE(amotta): Shuffle to get rid of attentional biases */ | |
const allTreeIds = shuffleArray(Object.keys(api.tracing.getAllTrees()).map(Number)); | |
/* assign desired functions to keys */ | |
api.utils.registerKeyHandler("6", () => { | |
doTree("Yes", 10); // green | |
}); | |
api.utils.registerKeyHandler("5", () => { | |
doTree("Maybe", 0); // black | |
}); | |
api.utils.registerKeyHandler("4", () => { | |
doTree("No", 1); // red | |
}); | |
alert(welcomeMessage); | |
goToNextTree(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment