Skip to content

Commit

Permalink
rename in tool accessor
Browse files Browse the repository at this point in the history
  • Loading branch information
knollengewaechs committed Oct 11, 2024
1 parent 5e2ff76 commit e6c887d
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 87 deletions.
9 changes: 3 additions & 6 deletions frontend/javascripts/oxalis/model/accessors/tool_accessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { isSkeletonLayerTransformed } from "./skeletontracing_accessor";
import { reuseInstanceOnEquality } from "./accessor_helpers";

const zoomInToUseToolMessage =
"Please zoom in further to use this tool. If you want to edit volume data on this zoom level, create an annotation with restricted resolutions from the extended annotation menu in the dashboard.";
"Please zoom in further to use this tool. If you want to edit volume data on this zoom level, create an annotation with restricted magnifications from the extended annotation menu in the dashboard.";

const getExplanationForDisabledVolume = (
isSegmentationTracingVisible: boolean,
Expand Down Expand Up @@ -274,11 +274,8 @@ function getDisabledVolumeInfo(state: OxalisState) {
const hasVolume = state.tracing.volumes.length > 0;
const hasSkeleton = state.tracing.skeleton != null;
const segmentationTracingLayer = getActiveSegmentationTracing(state);
const labeledResolution = getRenderableMagForSegmentationTracing(
state,
segmentationTracingLayer,
)?.resolution;
const isSegmentationTracingVisibleForMag = labeledResolution != null;
const labeledMag = getRenderableMagForSegmentationTracing(state, segmentationTracingLayer)?.mag;
const isSegmentationTracingVisibleForMag = labeledMag != null;
const visibleSegmentationLayer = getVisibleSegmentationLayer(state);
const isSegmentationTracingTransformed =
segmentationTracingLayer != null &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ function _getMagnificationInfoOfActiveSegmentationTracingLayer(
return getMagnificationInfo(segmentationLayer.resolutions);
}

const getResolutionInfoOfActiveSegmentationTracingLayer = memoizeOne(
const getMagnificationInfoOfActiveSegmentationTracingLayer = memoizeOne(
_getMagnificationInfoOfActiveSegmentationTracingLayer,
);
export function getServerVolumeTracings(
Expand All @@ -213,9 +213,9 @@ export function getContourTracingMode(volumeTracing: VolumeTracing): ContourMode
}

const MAG_THRESHOLDS_FOR_ZOOM: Partial<Record<AnnotationTool, number>> = {
// Note that these are relative to the lowest existing resolution index.
// Note that these are relative to the lowest existing mag index.
// A threshold of 1 indicates that the respective tool can be used in the
// lowest existing resolution as well as the next highest one.
// lowest existing mag as well as the next highest one.
[AnnotationToolEnum.TRACE]: 1,
[AnnotationToolEnum.ERASE_TRACE]: 1,
[AnnotationToolEnum.BRUSH]: 3,
Expand Down Expand Up @@ -244,28 +244,28 @@ export function isVolumeAnnotationDisallowedForZoom(tool: AnnotationTool, state:
return true;
}

const volumeResolutions = getResolutionInfoOfActiveSegmentationTracingLayer(state);
const lowestExistingResolutionIndex = volumeResolutions.getFinestMagIndex();
// The current resolution is too high for the tool
const volumeMags = getMagnificationInfoOfActiveSegmentationTracingLayer(state);
const lowestExistingMagIndex = volumeMags.getFinestMagIndex();
// The current mag is too high for the tool
// because too many voxels could be annotated at the same time.
const isZoomStepTooHigh =
getActiveMagIndexForLayer(state, activeSegmentation.tracingId) >
threshold + lowestExistingResolutionIndex;
threshold + lowestExistingMagIndex;
return isZoomStepTooHigh;
}

const MAX_BRUSH_SIZE_FOR_MAG1 = 300;
export function getMaximumBrushSize(state: OxalisState) {
const volumeResolutions = getResolutionInfoOfActiveSegmentationTracingLayer(state);
const volumeMags = getMagnificationInfoOfActiveSegmentationTracingLayer(state);

if (volumeResolutions.magnifications.length === 0) {
if (volumeMags.magnifications.length === 0) {
return MAX_BRUSH_SIZE_FOR_MAG1;
}

const lowestExistingResolutionIndex = volumeResolutions.getFinestMagIndex();
const lowestExistingMagIndex = volumeMags.getFinestMagIndex();
// For each leading magnification which does not exist,
// we double the maximum brush size.
return MAX_BRUSH_SIZE_FOR_MAG1 * 2 ** lowestExistingResolutionIndex;
return MAX_BRUSH_SIZE_FOR_MAG1 * 2 ** lowestExistingMagIndex;
}

export function getRequestedOrVisibleSegmentationLayer(
Expand Down Expand Up @@ -476,16 +476,16 @@ export function getActiveSegmentPosition(state: OxalisState): Vector3 | null | u
}

/*
This function returns the resolution and zoom step in which the given segmentation
This function returns the mag and zoom step in which the given segmentation
tracing layer is currently rendered (if it is rendered). These properties should be used
when labeling volume data.
*/
function _getRenderableResolutionForSegmentationTracing(
function _getRenderableMagForSegmentationTracing(
state: OxalisState,
segmentationTracing: VolumeTracing | null | undefined,
):
| {
resolution: Vector3;
mag: Vector3;
zoomStep: number;
}
| null
Expand All @@ -498,7 +498,7 @@ function _getRenderableResolutionForSegmentationTracing(

const requestedZoomStep = getActiveMagIndexForLayer(state, segmentationLayer.name);
const { renderMissingDataBlack } = state.datasetConfiguration;
const resolutionInfo = getMagnificationInfo(segmentationLayer.resolutions);
const magInfo = getMagnificationInfo(segmentationLayer.resolutions);
// Check whether the segmentation layer is enabled
const segmentationSettings = state.datasetConfiguration.layers[segmentationLayer.name];

Expand All @@ -507,31 +507,31 @@ function _getRenderableResolutionForSegmentationTracing(
}

// Check whether the requested zoom step exists
if (resolutionInfo.hasIndex(requestedZoomStep)) {
if (magInfo.hasIndex(requestedZoomStep)) {
return {
zoomStep: requestedZoomStep,
resolution: resolutionInfo.getMagByIndexOrThrow(requestedZoomStep),
mag: magInfo.getMagByIndexOrThrow(requestedZoomStep),
};
}

// Since `renderMissingDataBlack` is enabled, the fallback resolutions
// Since `renderMissingDataBlack` is enabled, the fallback mags
// should not be considered.
if (renderMissingDataBlack) {
return null;
}

// The current resolution is missing and fallback rendering
// The current mag is missing and fallback rendering
// is activated. Thus, check whether one of the fallback
// zoomSteps can be rendered.
for (
let fallbackZoomStep = requestedZoomStep + 1;
fallbackZoomStep <= requestedZoomStep + MAX_ZOOM_STEP_DIFF;
fallbackZoomStep++
) {
if (resolutionInfo.hasIndex(fallbackZoomStep)) {
if (magInfo.hasIndex(fallbackZoomStep)) {
return {
zoomStep: fallbackZoomStep,
resolution: resolutionInfo.getMagByIndexOrThrow(fallbackZoomStep),
mag: magInfo.getMagByIndexOrThrow(fallbackZoomStep),
};
}
}
Expand All @@ -540,12 +540,12 @@ function _getRenderableResolutionForSegmentationTracing(
}

export const getRenderableMagForSegmentationTracing = reuseInstanceOnEquality(
_getRenderableResolutionForSegmentationTracing,
_getRenderableMagForSegmentationTracing,
);

function _getRenderableMagForActiveSegmentationTracing(state: OxalisState):
| {
resolution: Vector3;
mag: Vector3;
zoomStep: number;
}
| null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ class BoundingBox {
return [u, v];
}

getBoxForZoomStep = _.memoize((resolution: Vector3): BoundingBoxType => {
getBoxForZoomStep = _.memoize((mag: Vector3): BoundingBoxType => {
// No `map` for performance reasons
const min = [0, 0, 0] as Vector3;
const max = [0, 0, 0] as Vector3;

for (let i = 0; i < 3; i++) {
const divisor = constants.BUCKET_WIDTH * resolution[i];
const divisor = constants.BUCKET_WIDTH * mag[i];
min[i] = Math.floor(this.min[i] / divisor);
max[i] = Math.ceil(this.max[i] / divisor);
}
Expand All @@ -51,16 +51,16 @@ class BoundingBox {
};
});

containsBucket([x, y, z, zoomStep]: Vector4, resolutionInfo: MagnificationInfo): boolean {
containsBucket([x, y, z, zoomStep]: Vector4, magInfo: MagnificationInfo): boolean {
/* Checks whether a bucket is contained in the active bounding box.
* If the passed resolutionInfo does not contain the passed zoomStep, this method
* If the passed magInfo does not contain the passed zoomStep, this method
* returns false.
*/
const resolutionIndex = resolutionInfo.getMagByIndex(zoomStep);
if (resolutionIndex == null) {
const magIndex = magInfo.getMagByIndex(zoomStep);
if (magIndex == null) {
return false;
}
const { min, max } = this.getBoxForZoomStep(resolutionIndex);
const { min, max } = this.getBoxForZoomStep(magIndex);
return min[0] <= x && x < max[0] && min[1] <= y && y < max[1] && min[2] <= z && z < max[2];
}

Expand Down
16 changes: 8 additions & 8 deletions frontend/javascripts/oxalis/model/bucket_data_handling/bucket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,12 +187,12 @@ export class DataBucket {
}

getBoundingBox(): BoundingBoxType {
const min = bucketPositionToGlobalAddress(this.zoomedAddress, this.cube.resolutionInfo);
const bucketResolution = this.cube.resolutionInfo.getMagByIndexOrThrow(this.zoomedAddress[3]);
const min = bucketPositionToGlobalAddress(this.zoomedAddress, this.cube.magInfo);
const bucketMag = this.cube.magInfo.getMagByIndexOrThrow(this.zoomedAddress[3]);
const max: Vector3 = [
min[0] + Constants.BUCKET_WIDTH * bucketResolution[0],
min[1] + Constants.BUCKET_WIDTH * bucketResolution[1],
min[2] + Constants.BUCKET_WIDTH * bucketResolution[2],
min[0] + Constants.BUCKET_WIDTH * bucketMag[0],
min[1] + Constants.BUCKET_WIDTH * bucketMag[1],
min[2] + Constants.BUCKET_WIDTH * bucketMag[2],
];
return {
min,
Expand All @@ -201,7 +201,7 @@ export class DataBucket {
}

getGlobalPosition(): Vector3 {
return bucketPositionToGlobalAddress(this.zoomedAddress, this.cube.resolutionInfo);
return bucketPositionToGlobalAddress(this.zoomedAddress, this.cube.magInfo);
}

getTopLeftInMag(): Vector3 {
Expand Down Expand Up @@ -707,9 +707,9 @@ export class DataBucket {
if (this.zoomedAddress[3] === zoomStep) {
// @ts-ignore
this.visualizedMesh = window.addBucketMesh(
bucketPositionToGlobalAddress(this.zoomedAddress, this.cube.resolutionInfo),
bucketPositionToGlobalAddress(this.zoomedAddress, this.cube.magInfo),
this.zoomedAddress[3],
this.cube.resolutionInfo.getMagByIndex(this.zoomedAddress[3]),
this.cube.magInfo.getMagByIndex(this.zoomedAddress[3]),
colors[this.zoomedAddress[3]] || this.visualizationColor,
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@ import { mod } from "libs/utils"; // Attention: Note that the implemented paper
export default function traverse(
startPosition: Vector3,
endPosition: Vector3,
resolutions: Array<Vector3>,
mags: Array<Vector3>,
zoomStep: number,
): Vector3[] {
// The equation of the ray is →u + t→ v for t ≥ 0. The new traversal algorithm breaks down the ray into intervals of t,
// each of which spans one voxel. We start at the ray origin and visit each of these voxels in interval order.
const u = startPosition;
const v = V3.sub(endPosition, startPosition);
// The initialization phase begins by identifying the voxel in which the ray origin, → u, is found.
const uBucket = globalPositionToBucketPosition(startPosition, resolutions, zoomStep, null);
const lastBucket = globalPositionToBucketPosition(endPosition, resolutions, zoomStep, null);
const uBucket = globalPositionToBucketPosition(startPosition, mags, zoomStep, null);
const lastBucket = globalPositionToBucketPosition(endPosition, mags, zoomStep, null);
// The integer variables X and Y are initialized to the starting voxel coordinates.
let [X, Y, Z] = uBucket;
const voxelSize = getBucketExtent(resolutions[zoomStep]);
const voxelSize = getBucketExtent(mags[zoomStep]);
// In addition, the variables stepX and stepY are initialized to either 1 or -1 indicating whether X and Y are
// incremented or decremented as the ray crosses voxel boundaries (this is determined by the sign of the x and y components of → v).
const [stepX, stepY, stepZ] = v.map((el) => Math.sign(el));
Expand Down
Loading

0 comments on commit e6c887d

Please sign in to comment.