Skip to content

Commit

Permalink
convert bounding box to mag1
Browse files Browse the repository at this point in the history
  • Loading branch information
dieknolle3333 committed Sep 25, 2023
1 parent ac92cfd commit 5f2174f
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 22 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ For upgrade instructions, please check the [migration guide](MIGRATIONS.released
### Changed

### Fixed
- Fixed that segment statistics were requested in the wrong resolution within the statistics modal. [#7355](https://github.com/scalableminds/webknossos/pull/7355)
- Fixed that segment statistics were requested in the wrong resolution. [#7355](https://github.com/scalableminds/webknossos/pull/7355)

### Removed

Expand Down
15 changes: 14 additions & 1 deletion frontend/javascripts/oxalis/model/sagas/volume/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import DataCube from "oxalis/model/bucket_data_handling/data_cube";
import { Model } from "oxalis/singletons";
import VolumeLayer, { VoxelBuffer2D } from "oxalis/model/volumetracing/volumelayer";
import { enforceActiveVolumeTracing } from "oxalis/model/accessors/volumetracing_accessor";
import { VolumeTracing } from "oxalis/store";
import { BoundingBoxObject, VolumeTracing } from "oxalis/store";
import { getFlooredPosition } from "oxalis/model/accessors/flycam_accessor";
import { zoomedPositionToZoomedAddress } from "oxalis/model/helpers/position_converter";
import { ResolutionInfo } from "oxalis/model/helpers/resolution_info";
Expand Down Expand Up @@ -58,6 +58,19 @@ export function* getBoundingBoxForViewport(
return new BoundingBox(currentViewportBounding).intersectedWith(datasetBoundingBox);
}

export function getBoundingBoxInMag1(boudingBox: BoundingBoxObject, magOfBB: Vector3) {
return {
topLeft: [
boudingBox.topLeft[0] * magOfBB[0],
boudingBox.topLeft[1] * magOfBB[1],
boudingBox.topLeft[2] * magOfBB[2],
] as Vector3,
width: boudingBox.width * magOfBB[0],
height: boudingBox.height * magOfBB[1],
depth: boudingBox.depth * magOfBB[2],
};
}

export function applyLabeledVoxelMapToAllMissingResolutions(
inputLabeledVoxelMap: LabeledVoxelsMap,
labeledZoomStep: number,
Expand Down
7 changes: 7 additions & 0 deletions frontend/javascripts/oxalis/model/scaleinfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@ export function getBaseVoxel(dataSetScale: Vector3): number {
// base voxel should be a cube with highest resolution
return Math.min(...dataSetScale);
}

export function voxelToNm3(dataSetScale: Vector3, mag: Vector3, volumeInVx: number): number {
return (
mag[0] * mag[1] * mag[2] * dataSetScale[0] * dataSetScale[1] * dataSetScale[2] * volumeInVx
);
}

export function getBaseVoxelFactors(dataSetScale: Vector3): Vector3 {
// base voxel should be a cube with highest resolution
const baseVoxel = getBaseVoxel(dataSetScale);
Expand Down
21 changes: 15 additions & 6 deletions frontend/javascripts/oxalis/view/context_menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ import { getSegmentBoundingBoxes, getSegmentVolumes } from "admin/admin_rest_api
import { useFetch } from "libs/react_helpers";
import { AsyncIconButton } from "components/async_clickables";
import { type AdditionalCoordinate } from "types/api_flow_types";
import { voxelToNm3 } from "oxalis/model/scaleinfo";
import { getBoundingBoxInMag1 } from "oxalis/model/sagas/volume/helpers";

type ContextMenuContextValue = React.MutableRefObject<HTMLElement | null> | null;
export const ContextMenuContext = createContext<ContextMenuContextValue>(null);
Expand Down Expand Up @@ -1119,22 +1121,29 @@ function ContextMenuInner(propsWithInputRef: Props) {
const tracingId = volumeTracing.tracingId;
const tracingStoreUrl = Store.getState().tracing.tracingStore.url;
const magInfo = getResolutionInfo(visibleSegmentationLayer.resolutions);
const layersFinestResolution = magInfo.getFinestResolution();
const dataSetScale = Store.getState().dataset.dataSource.scale;
const [segmentSize] = await getSegmentVolumes(
tracingStoreUrl,
tracingId,
magInfo.getFinestResolution(),
layersFinestResolution,
[segmentIdAtPosition],
);
const [boundingBox] = await getSegmentBoundingBoxes(
const [boundingBoxInRequestedMag] = await getSegmentBoundingBoxes(
tracingStoreUrl,
tracingId,
magInfo.getFinestResolution(),
layersFinestResolution,
[segmentIdAtPosition],
);
const boundingBoxTopLeftString = `(${boundingBox.topLeft[0]}, ${boundingBox.topLeft[1]}, ${boundingBox.topLeft[2]})`;
const boundingBoxSizeString = `(${boundingBox.width}, ${boundingBox.height}, ${boundingBox.depth})`;
const boundingBoxInMag1 = getBoundingBoxInMag1(
boundingBoxInRequestedMag,
layersFinestResolution,
);
const boundingBoxTopLeftString = `(${boundingBoxInMag1.topLeft[0]}, ${boundingBoxInMag1.topLeft[1]}, ${boundingBoxInMag1.topLeft[2]})`;
const boundingBoxSizeString = `(${boundingBoxInMag1.width}, ${boundingBoxInMag1.height}, ${boundingBoxInMag1.depth})`;
const volumeInNm3 = voxelToNm3(dataSetScale, layersFinestResolution, segmentSize);
return [
formatNumberToVolume(segmentSize),
formatNumberToVolume(volumeInNm3),
`${boundingBoxTopLeftString}, ${boundingBoxSizeString}`,
];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import React from "react";
import { SegmentHierarchyNode, SegmentHierarchyGroup } from "./segments_view_helper";
import { Store, api } from "oxalis/singletons";
import { APISegmentationLayer } from "types/api_flow_types";
import { getBaseVoxel } from "oxalis/model/scaleinfo";
import { voxelToNm3 } from "oxalis/model/scaleinfo";
import { getBoundingBoxInMag1 } from "oxalis/model/sagas/volume/helpers";

const SEGMENT_STATISTICS_CSV_HEADER =
"segmendId,segmentName,groupId,groupName,volumeInVoxel,volumeInNm3,boundingBoxTopLeftPositionX,boundingBoxTopLeftPositionY,boundingBoxTopLeftPositionZ,boundingBoxSizeX,boundingBoxSizeY,boundingBoxSizeZ";
Expand Down Expand Up @@ -84,22 +85,23 @@ export function SegmentStatisticsModal({
parentGroup,
groupTree,
}: Props) {
const mag = getResolutionInfo(visibleSegmentationLayer.resolutions);
const scaleFactor = getBaseVoxel(Store.getState().dataset.dataSource.scale);
const magInfo = getResolutionInfo(visibleSegmentationLayer.resolutions);
const layersFinestResolution = magInfo.getFinestResolution();
const dataSetScale = Store.getState().dataset.dataSource.scale;
const dataSource = useFetch(
async () => {
await api.tracing.save();
const segmentStatisticsObjects = await Promise.all([
getSegmentVolumes(
tracingStoreUrl,
tracingId,
mag.getFinestResolution(),
layersFinestResolution,
segments.map((segment) => segment.id),
),
getSegmentBoundingBoxes(
tracingStoreUrl,
tracingId,
mag.getFinestResolution(),
layersFinestResolution,
segments.map((segment) => segment.id),
),
]).then((response) => {
Expand All @@ -110,10 +112,18 @@ export function SegmentStatisticsModal({
// segments in request and their statistics in the response are in the same order
const currentSegment = segments[i];
const currentBoundingBox = boundingBoxes[i];
const boundingBoxInMag1 = getBoundingBoxInMag1(
currentBoundingBox,
layersFinestResolution,
);
const currentSegmentSizeInVx = segmentSizes[i];
const volumeInNm3 = currentSegmentSizeInVx * scaleFactor;
const volumeInNm3 = voxelToNm3(
dataSetScale,
layersFinestResolution,
currentSegmentSizeInVx,
);
const currentGroupId = getGroupIdForSegment(currentSegment);
const segmentStatObject = {
const segmentStateObject = {
key: currentSegment.id,
segmentId: currentSegment.id,
segmentName:
Expand All @@ -123,16 +133,16 @@ export function SegmentStatisticsModal({
volumeInVoxel: currentSegmentSizeInVx,
volumeInNm3,
formattedSize: formatNumberToVolume(volumeInNm3),
boundingBoxTopLeft: currentBoundingBox.topLeft,
boundingBoxTopLeftAsString: `(${currentBoundingBox.topLeft.join(", ")})`,
boundingBoxTopLeft: boundingBoxInMag1.topLeft,
boundingBoxTopLeftAsString: `(${boundingBoxInMag1.topLeft.join(", ")})`,
boundingBoxPosition: [
currentBoundingBox.width,
currentBoundingBox.height,
currentBoundingBox.depth,
boundingBoxInMag1.width,
boundingBoxInMag1.height,
boundingBoxInMag1.depth,
] as Vector3,
boundingBoxPositionAsString: `(${currentBoundingBox.width}, ${currentBoundingBox.height}, ${currentBoundingBox.depth})`,
boundingBoxPositionAsString: `(${boundingBoxInMag1.width}, ${boundingBoxInMag1.height}, ${boundingBoxInMag1.depth})`,
};
statisticsObjects.push(segmentStatObject);
statisticsObjects.push(segmentStateObject);
}
return statisticsObjects;
});
Expand Down

0 comments on commit 5f2174f

Please sign in to comment.