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

Make "Registering of All Segments for a BBox"- feature mag aware #8082

Merged
merged 12 commits into from
Sep 19, 2024
2 changes: 1 addition & 1 deletion CHANGELOG.unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ For upgrade instructions, please check the [migration guide](MIGRATIONS.released

### Added
- It is now possible to focus a bounding box in the bounding box tab by clicking its edges in a viewport or via a newly added context menu entry. [#8054](https://github.com/scalableminds/webknossos/pull/8054)
### Added
- Added an assertion to the backend to ensure unique keys in the metadata info of datasets and folders. [#8068](https://github.com/scalableminds/webknossos/issues/8068)
- The feature to register all segments within a bounding box now takes the current magnification into consideration, e.g. for calculating the volume limit for a bounding box. [#8082](https://github.com/scalableminds/webknossos/pull/8082)

### Changed
- Clicking on a bounding box within the bounding box tab centers it within the viewports and focusses it in the list. [#8049](https://github.com/scalableminds/webknossos/pull/8049)
Expand Down
43 changes: 29 additions & 14 deletions frontend/javascripts/oxalis/api/api_latest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ import {
getPosition,
getActiveMagIndexForLayer,
getRotation,
getCurrentResolution,
} from "oxalis/model/accessors/flycam_accessor";
import {
loadAdHocMeshAction,
Expand Down Expand Up @@ -656,11 +657,28 @@ class TracingApi {
bbName: string,
options?: { maximumSegmentCount?: number; maximumVolume?: number },
) => {
const state = Store.getState();
const maximumVolume = options?.maximumVolume ?? Constants.REGISTER_SEGMENTS_BB_MAX_VOLUME_VX;
const maximumSegmentCount =
options?.maximumSegmentCount ?? Constants.REGISTER_SEGMENTS_BB_MAX_SEGMENT_COUNT;
const shape = Utils.computeShapeFromBoundingBox({ min, max });
const volume = Math.ceil(shape[0] * shape[1] * shape[2]);

const segmentationLayerName = api.data.getVisibleSegmentationLayerName();
if (segmentationLayerName == null) {
Toast.error("The current segmentation layer could not be found.");
dieknolle3333 marked this conversation as resolved.
Show resolved Hide resolved
return;
}

const currentMag = getCurrentResolution(state, segmentationLayerName);
if (currentMag == null) {
Toast.error("No mag could not be found.");
dieknolle3333 marked this conversation as resolved.
Show resolved Hide resolved
return;
}

const volume =
Math.ceil(shape[0] / currentMag[0]) *
Math.ceil(shape[1] / currentMag[1]) *
Math.ceil(shape[2] / currentMag[2]);
if (volume > maximumVolume) {
Toast.error(
`The volume of the bounding box exceeds ${maximumVolume} Vx, please make it smaller.`,
dieknolle3333 marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -672,19 +690,16 @@ class TracingApi {
);
}

const segmentationLayerName = api.data.getSegmentationLayerNames()[0];
const layer = getLayerByName(Store.getState().dataset, segmentationLayerName);

const resolutionInfo = getResolutionInfo(layer.resolutions);
const finestResolution = resolutionInfo.getFinestResolution();
// By default, getDataForBoundingBox uses the finest existing magnification.
// We use that as strides to traverse the data array properly.
const [dx, dy, dz] = finestResolution;

const data = await api.data.getDataForBoundingBox(segmentationLayerName, {
min,
max,
});
const magIndex = getActiveMagIndexForLayer(state, segmentationLayerName);
dieknolle3333 marked this conversation as resolved.
Show resolved Hide resolved
const data = await api.data.getDataForBoundingBox(
segmentationLayerName,
{
min,
max,
},
magIndex,
);
const [dx, dy, dz] = currentMag;

const segmentIdToPosition = new Map();
let idx = 0;
Expand Down