API initializer. Will be called as soon as the webKnossos API is ready.
(number)
window.webknossos.apiReady(3).then((api) => {
// Your cool user script / wK plugin
const nodes = api.tracing.getAllNodes();
...
});
All tracing related API methods. This is the newest version of the API (version 3).
(OxalisModel)
window.webknossos.apiReady(3).then(api => {
api.tracing.getActiveNodeId();
api.tracing.getActiveTreeId();
...
}
Returns all trees belonging to a tracing.
TreeMap
Deletes the node with nodeId in the tree with treeId
Centers the active node.
Creates a new and empty tree. Returns the id of that tree.
Creates a new node in the current tree. If the active tree is not empty, the node will be connected with an edge to the currently active node.
Completely resets the skeleton tracing.
Sets the comment for a node.
void
const activeNodeId = api.tracing.getActiveNodeId();
api.tracing.setCommentForNode("This is a branch point", activeNodeId);
Returns the comment for a given node and tree (optional).
(number)
(number?)
Supplying the tree id will provide a performance boost for looking up a comment.
(string | null | undefined)
const comment = api.tracing.getCommentForNode(23);
// Provide a tree for lookup speed boost
const comment = api.tracing.getCommentForNode(23, api.getActiveTreeid());
Sets the visibility of the edges for a tree. If no tree id is given, the active tree is used.
api.tracing.setTreeEdgeVisibility(false, 1);
Changes the color of the referenced tree. Internally, a pre-defined array of colors is used which is why this function uses a colorIndex (between 0 and 500) instead of a proper color.
api.tracing.setTreeColorIndex(3, 10);
Sets the parent group of the referenced tree.
api.tracing.setTreeGroup(
3,
api.tracing.getTreeGroups.find(({ name }) => name === "My Tree Group").id,
);
Renames the group referenced by the provided id.
api.tracing.renameSkeletonGroup(
3,
"New group name",
);
Moves one skeleton group to another one (or to the root node when providing null as the second parameter).
api.tracing.moveSkeletonGroup(
3,
null, // moves group with id 0 to the root node
);
Adds a segment to the segment list.
api.tracing.registerSegment(
3,
[1, 2, 3],
null, // optional
"volume-layer-id" // optional
);
Registers all segments that exist at least partially in the given bounding box.
api.tracing.registerSegmentsForBoundingBox(
[0, 0, 0],
[10, 10, 10],
"My Bounding Box"
);
Gets a segment object within the referenced volume layer. Note that this object does not support any modifications made to it.
Segment
const segment = api.tracing.getSegment(
3,
"volume-layer-id"
);
console.log(segment.groupId)
Updates a segment. The segment parameter can contain all properties of a Segment (except for the id) or less.
api.tracing.updateSegment(
3,
{
name: "A name",
somePosition: [1, 2, 3],
someAdditionalCoordinates: [],
color: [1, 2, 3],
groupId: 1,
},
"volume-layer-id"
);
Removes a segment from the segment list. This does not mutate the actual voxel data.
api.tracing.removeSegment(
3,
"volume-layer-id"
);
Moves one segment group to another one (or to the root node when providing null as the second parameter).
api.tracing.moveSegmentGroup(
3,
null, // moves group with id 0 to the root node
"volume-layer-id"
);
Creates a new segment group and returns its id.
number
api.tracing.createSegmentGroup(
"Group name", // optional
parentGroupId, // optional. use -1 for the root group
volumeLayerName, // see getSegmentationLayerNames
);
Renames the segment group referenced by the provided id.
api.tracing.renameSegmentGroup(
3,
"New group name",
volumeLayerName, // see getSegmentationLayerNames
);
Deletes the segment group referenced by the provided id. If deleteChildren is true, the deletion is recursive.
api.tracing.deleteSegmentGroup(
3,
true,
volumeLayerName, // see getSegmentationLayerNames
);
Deprecated! Use renameSkeletonGroup instead.
Saves the tracing and returns a promise (which you can call then
on or use await with).
api.tracing.save().then(() => ... );
await api.tracing.save();
Finishes the task and gets the next one. It returns a promise (which you can call then
on or use await with).
Don't assume that code after the finishAndGetNextTask call will be executed.
It can happen that there is no further task, in which case the user will be redirected to the dashboard.
Or the the page can be reloaded (e.g., if the dataset changed), which also means that no further JS code will
be executed in this site context.
api.tracing.finishAndGetNextTask().then(() => ... );
await api.tracing.finishAndGetNextTask();
Restart webKnossos without refreshing the page. Please prefer finishAndGetNextTask for user scripts since it does extra validation of the requested change and makes sure everything is saved etc.
((APICompoundType | null))
(string)
(ControlMode)
(Versions?)
(boolean
= false
)
api.tracing.restart("Explorational", "5909b5aa3e0000d4009d4d15", "TRACE")
Reload tracing by reloading the entire page.
api.tracing.hardReload()
Increases the node radius of the given node by multiplying it with 1.05^delta. If no nodeId and/or treeId are provided, it defaults to the current tree and current node.
void
api.tracing.setNodeRadius(1)
Centers the given node. If no node is provided, the active node is centered.
(number?)
void
api.tracing.centerNode()
Centers the 3D view.
void
api.tracing.centerTDView()
Returns the shortest path between two nodes in nanometer and voxels as well as an array of the node IDs in the shortest path.
{lengthInUnit: number, lengthInVx: number, shortestPath: Array<number>}
Starts an animation to center the given position. See setCameraPosition for a non-animated version of this function.
(Vector3)
Vector3
(boolean
= true
)
Boolean which decides whether the third dimension shall also be animated (defaults to true)
When true, this lets the user still manipulate the "third dimension"
during the animation (important because otherwise the user cannot continue to trace until
the animation is over).
(Vector3?)
Vector3 (optional) - Will only be noticeable in flight or oblique mode.
void
api.tracing.centerPositionAnimated([0, 0, 0])
Returns the current camera position.
Vector3
const currentPosition = api.tracing.getCameraPosition()
Sets the current camera position. See centerPositionAnimated for an animated version of this function.
(Vector3)
api.tracing.setCameraPosition([100, 100, 100])
Returns the active tool which is either "MOVE", "SKELETON", "TRACE", "BRUSH", "FILL_CELL" or "PICK_CELL"
AnnotationTool
Sets the active tool which should be either "MOVE", "SKELETON", "TRACE", "BRUSH", "FILL_CELL" or "PICK_CELL" Volume tracing only!
(AnnotationTool)
Deprecated! Use getAnnotationTool instead.
AnnotationTool
Deprecated! Use setAnnotationTool instead.
(AnnotationTool)
Use this method to create a complete magnification pyramid by downsampling the lowest present mag (e.g., mag 1). This method will save the current changes and then reload the page after the downsampling has finished. This function can only be used for non-tasks. Note that this invoking this method will not block the UI. Thus, user actions can be performed during the downsampling. The caller should prohibit this (e.g., by showing a not-closable modal during the process).
(string)
Disables the saving for the current annotation. WARNING: Cannot be undone. Only do this if you know what you are doing.
All binary data / layer related API methods.
(OxalisModel)
window.webknossos.apiReady(3).then(api => {
api.data.getLayerNames();
api.data.reloadBuckets(...);
...
}
Invalidates all downloaded buckets of the given layer so that they are reloaded. If an additional predicate is passed, each bucket is checked to see whether it should be reloaded. Note that buckets that are in a REQUESTED state (i.e., currently being queued or downloaded) will always be reloaded by cancelling and rescheduling the request.
Promise<void>
Sets a mapping for a given layer.
(string)
const position = [123, 123, 123];
const segmentationLayerName = "segmentation";
const segmentId = await api.data.getDataValue(segmentationLayerName, position);
const treeId = api.tracing.getActiveTreeId();
const mapping = {[segmentId]: treeId}
api.data.setMapping(segmentationLayerName, mapping);
Enables/Disables the active mapping. If layerName is not passed, the currently visible segmentation layer will be used.
Sets the active mapping for a given layer. If layerName is not passed, the currently visible segmentation layer will be used.
void
Returns raw binary data for a given layer, position and zoom level. If the zoom level is not provided, the first magnification will be used. If this mag does not exist, the next existing mag will be used. If the zoom level is provided and points to a not existent mag, 0 will be returned.
(string)
(Vector3)
((Array<AdditionalCoordinate> | null)
= null
)
Promise<number>
// Return the greyscale value for a bucket
const position = [123, 123, 123];
api.data.getDataValue("binary", position).then((greyscaleColor) => ...);
// Using the await keyword instead of the promise syntax
const greyscaleColor = await api.data.getDataValue("binary", position);
// Get the segmentation id for the first volume tracing layer
const segmentId = await api.data.getDataValue(api.data.getVolumeTracingLayerIds()[0], position);
Returns the magnification that is currently rendered at the given position.
number
Downloads a cuboid of raw data from a dataset (not tracing) layer. A new window is opened for the download - if that is not the case, please check your pop-up blocker.
Promise<void>
// Download a cuboid (from (0, 0, 0) to (100, 200, 100)) of raw data from the "segmentation" layer.
api.data.downloadRawDataCuboid("segmentation", [0,0,0], [100,200,100]);
Label voxels with the supplied value. Note that this method does not mutate the data immediately, but instead returns a promise (since the data might have to be downloaded first).
Volume tracing only!
(Array<Vector3>)
(number)
((Array<AdditionalCoordinate> | null)
= null
)
Promise<void>
// Set the segmentation id for some voxels to 1337
await api.data.labelVoxels([[1,1,1], [1,2,1], [2,1,1], [2,2,1]], 1337);
Returns the dataset's setting for the tracing view.
((any | OutdatedDatasetConfigurationKeys))
One of the following keys:
const segmentationOpacity = api.data.getConfiguration("segmentationOpacity");
Set the dataset's setting for the tracing view.
((any | OutdatedDatasetConfigurationKeys))
Same keys as for getConfiguration()
(any)
api.data.setConfiguration("segmentationOpacity", 20);
Set currently active mesh file (can be set to null). If layerName is not passed, the currently visible segmentation layer will be used.
const availableMeshFileNames = api.data.getAvailableMeshFiles();
if (availableMeshFileNames.length > 0) {
api.data.setActiveMeshFile(availableMeshFileNames[0]);
}
If a mesh file is active, loadPrecomputedMesh can be used to load a mesh for a given segment at a given seed position for a specified segmentation layer. If layerName is not passed, the currently visible segmentation layer will be used. If there is no mesh file for the dataset's segmentation layer available, you can use api.data.computeMeshOnDemand instead.
const currentPosition = api.tracing.getCameraPosition();
const segmentId = await api.data.getDataValue("segmentation", currentPosition);
const availableMeshFiles = await api.data.getAvailableMeshFiles();
api.data.setActiveMeshFile(availableMeshFiles[0]);
api.data.loadPrecomputedMesh(segmentId, currentPosition);
Load a mesh for a given segment id and a seed position by computing it ad-hoc.
const currentPosition = api.tracing.getCameraPosition();
const segmentId = await api.data.getDataValue("segmentation", currentPosition);
api.data.computeMeshOnDemand(segmentId, currentPosition);
Set the visibility for a loaded mesh by providing the corresponding segment id. If layerName is not passed, the currently visible segmentation layer will be used.
api.data.setMeshVisibility(segmentId, false);
Remove the mesh for a given segment and segmentation layer. If layerName is not passed, the currently visible segmentation layer will be used.
void
api.data.removeMesh(segmentId, layerName);
Get the RGB color of a segment (and its mesh) for a given segmentation layer. If layerName is not passed, the currently visible segmentation layer will be used.
Vector3
api.data.getSegmentColor(3);
Set the RGB color of a segment (and its mesh) for a given segmentation layer. If layerName is not passed, the currently visible segmentation layer will be used.
api.data.setSegmentColor(3, [0, 1, 1]);
All user configuration related API methods.
(OxalisModel)
window.webknossos.apiReady(3).then(api => {
api.user.getConfiguration(...);
api.user.setConfiguration(...);
...
}
Returns the user's setting for the tracing view.
(any)
One of the following keys:
const keyboardDelay = api.user.getConfiguration("keyboardDelay");
Set the user's setting for the tracing view.
(any)
Same keys as for getConfiguration()
(any)
api.user.setConfiguration("keyboardDelay", 20);
Utility API methods to control wK.
(OxalisModel)
window.webknossos.apiReady(3).then(api => {
api.utils.sleep(...);
api.utils.showToast(...);
...
}
Show a toast to the user. Returns a function which can be used to remove the toast again.
(string)
Can be one of the following: "info", "warning", "success" or "error"
(string)
The message string you want to show
(number)
Time period in milliseconds after which the toast will be hidden. Time is measured as soon as the user moves the mouse. A value of 0 means that the toast will only hide by clicking on it's X button.
(function (...args: Array<any>): any | null | undefined)
// Show a toast for 5 seconds
const removeToast = api.utils.showToast("info", "You just got toasted", false, 5000);
// ... optionally:
// removeToast();
Overwrite existing wK actions. wK uses Redux actions to trigger any changes to the application state.
(string)
The name of the action you wish to override:
(function (store, next, originalAction))
Your new implementation for the method in question. Receives the central wK store, a callback to fire the next/original action and the original action.
function ()
:
A function used to unregister the overwriteFunction
api.utils.registerOverwrite("MERGE_TREES", (store, next, originalAction) => {
// ... do stuff before the original function...
next(originalAction);
// ... do something after the original function ...
});