Skip to content
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

Extend JS API with some functionality for managing segments #7694

Merged
merged 3 commits into from
Mar 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ For upgrade instructions, please check the [migration guide](MIGRATIONS.released
- Prepared support to download full stl meshes via the HTTP api. [#7587](https://github.com/scalableminds/webknossos/pull/7587)
- Added an action to delete erronous, unimported datasets directly from the dashboard. [#7448](https://github.com/scalableminds/webknossos/pull/7448)
- Added support for `window`, `active`, `inverted` keys from the `omero` info in the NGFF metadata. [7685](https://github.com/scalableminds/webknossos/pull/7685)
- Added getSegment function to JavaScript API. Also, createSegmentGroup returns the id of the new group now. [#7694](https://github.com/scalableminds/webknossos/pull/7694)

### Changed
- Datasets stored in WKW format are no longer loaded with memory mapping, reducing memory demands. [#7528](https://github.com/scalableminds/webknossos/pull/7528)
Expand Down
24 changes: 22 additions & 2 deletions frontend/javascripts/oxalis/api/api_latest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ import {
getRequestedOrVisibleSegmentationLayer,
getRequestedOrVisibleSegmentationLayerEnforced,
getSegmentColorAsRGBA,
getSegmentsForLayer,
getVolumeDescriptors,
getVolumeTracingById,
getVolumeTracingByLayerName,
Expand Down Expand Up @@ -584,6 +585,23 @@ class TracingApi {
);
}

/**
* Gets a segment object within the referenced volume layer. Note that this object
* does not support any modifications made to it.
*
* @example
* const segment = api.tracing.getSegment(
* 3,
* "volume-layer-id"
* );
* console.log(segment.groupId)
*/
getSegment(segmentId: number, layerName: string): Segment {
const segment = getSegmentsForLayer(Store.getState(), layerName).get(segmentId);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if the layer name does not exist?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

an error will be thrown which I find acceptable.

// Return a copy to avoid mutations by third-party code.
return { ...segment };
}

/**
* Updates a segment. The segment parameter can contain all properties of a Segment
* (except for the id) or less.
Expand Down Expand Up @@ -635,7 +653,7 @@ class TracingApi {
}

/**
* Renames the segment group referenced by the provided id.
* Creates a new segment group and returns its id.
*
* @example
* api.tracing.createSegmentGroup(
Expand All @@ -648,7 +666,7 @@ class TracingApi {
name: string | null = null,
parentGroupId: number = MISSING_GROUP_ID,
volumeLayerName?: string,
) {
): number {
if (parentGroupId == null) {
// Guard against explicitly passed null or undefined.
parentGroupId = MISSING_GROUP_ID;
Expand Down Expand Up @@ -678,6 +696,8 @@ class TracingApi {
}

Store.dispatch(setSegmentGroupsAction(newSegmentGroups, volumeTracing.tracingId));

return newGroupId;
}

/**
Expand Down