Skip to content

Commit

Permalink
Rename resolution to mag in local variables (#8168)
Browse files Browse the repository at this point in the history
* rename local vars in ai_model_list_view, create_explorative_modal, model_initialization, api_latest and plane_material_factory

* rename to mag up to volume interpolation saga

* continue renaming local vars

* rename more occurences of resolution to mag

* change ServerNode resolution to mag

* remove shader code edit

* fix test: rename resolution to mag in volumetracing saga spec

* rename resolution in create node action

* rename resolution to mag in DataLayer type

* revert shader code edit

* add changelog

* rename resolution to mag in MutableNode and add type checking file for skeletontracingreducer test

* change dummy trees to test compatibility of backend and frontend CreadeNodeAction

* fix createnode method

* rename resolution to magnification in shader relevant code

* address review: revert one change and rename resInfo

* lint

* refresh annotations e2e snapshot

---------

Co-authored-by: Michael Büßemeyer <[email protected]>
  • Loading branch information
knollengewaechs and Michael Büßemeyer authored Dec 2, 2024
1 parent 3b00409 commit c0fab5a
Show file tree
Hide file tree
Showing 73 changed files with 721 additions and 782 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ For upgrade instructions, please check the [migration guide](MIGRATIONS.released
- Added the total volume of a dataset to a tooltip in the dataset info tab. [#8229](https://github.com/scalableminds/webknossos/pull/8229)

### Changed
- Renamed "resolution" to "magnification" in more places within the codebase, including local variables. [#8168](https://github.com/scalableminds/webknossos/pull/8168)
- Reading image files on datastore filesystem is now done asynchronously. [#8126](https://github.com/scalableminds/webknossos/pull/8126)
- Datasets can now be renamed and can have duplicate names. [#8075](https://github.com/scalableminds/webknossos/pull/8075)
- Improved error messages for starting jobs on datasets from other organizations. [#8181](https://github.com/scalableminds/webknossos/pull/8181)
Expand Down
16 changes: 8 additions & 8 deletions frontend/javascripts/admin/tasktype/task_type_create_view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ type Props = {
};

type FormValues = {
isResolutionRestricted: boolean;
isMagRestricted: boolean;
summary: string;
teamId: string;
description: string;
Expand Down Expand Up @@ -103,7 +103,7 @@ function TaskTypeCreateView({ taskTypeId, history }: Props) {
const taskType = taskTypeId ? await getTaskType(taskTypeId) : null;

const defaultValues = {
isResolutionRestricted: false,
isMagRestricted: false,
settings: {
somaClickingAllowed: true,
branchPointsAllowed: true,
Expand Down Expand Up @@ -131,15 +131,15 @@ function TaskTypeCreateView({ taskTypeId, history }: Props) {
}

if (taskType?.settings.magRestrictions.min || taskType?.settings.magRestrictions.max)
form.setFieldValue(["isResolutionRestricted"], true);
form.setFieldValue(["isMagRestricted"], true);
}

async function onFinish(formValues: FormValues) {
const {
settings,
teamId,
recommendedConfiguration,
isResolutionRestricted: _isResolutionRestricted,
isMagRestricted: _isMagRestricted,
...rest
} = formValues;
const teamName = teams.find((team) => team.id === teamId)!["name"];
Expand Down Expand Up @@ -411,7 +411,7 @@ function TaskTypeCreateView({ taskTypeId, history }: Props) {
</FormItem>

<FormItem
name={["isResolutionRestricted"]}
name={["isMagRestricted"]}
valuePropName="checked"
style={{
marginBottom: 6,
Expand All @@ -431,12 +431,12 @@ function TaskTypeCreateView({ taskTypeId, history }: Props) {
<FormItem
noStyle
shouldUpdate={(prevValues, curValues) =>
!prevValues.isResolutionRestricted ||
prevValues.isResolutionRestricted !== curValues.isResolutionRestricted
!prevValues.isMagRestricted ||
prevValues.isMagRestricted !== curValues.isMagRestricted
}
>
{({ getFieldValue }) =>
getFieldValue(["isResolutionRestricted"]) ? (
getFieldValue(["isMagRestricted"]) ? (
<div
style={{
marginLeft: 24,
Expand Down
4 changes: 2 additions & 2 deletions frontend/javascripts/admin/voxelytics/ai_model_list_view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ function TrainNewAiJobModal({ onClose }: { onClose: () => void }) {
const volumeTracingIndex = volumeTracings.findIndex(
(tracing) => tracing.tracingId === annotationLayer.tracingId,
);
const resolutions = volumeTracingMags[volumeTracingIndex] || ([[1, 1, 1]] as Vector3[]);
return getMagInfo(resolutions).getFinestMag();
const mags = volumeTracingMags[volumeTracingIndex] || ([[1, 1, 1]] as Vector3[]);
return getMagInfo(mags).getFinestMag();
} else {
const segmentationLayer = getSegmentationLayerByName(dataset, layerName);
return getMagInfo(segmentationLayer.resolutions).getFinestMag();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,24 +90,24 @@ export function RestrictMagnificationSlider({
magIndices,
setMagIndices,
}: RestrictMagnificationSliderProps) {
let highestResolutionIndex = magInfo.getCoarsestMagIndex();
let lowestResolutionIndex = magInfo.getFinestMagIndex();
let highestMagIndex = magInfo.getCoarsestMagIndex();
let lowestMagIndex = magInfo.getFinestMagIndex();

if (selectedSegmentationLayer != null) {
const datasetFallbackLayerResolutionInfo = getMagInfo(selectedSegmentationLayer.resolutions);
highestResolutionIndex = datasetFallbackLayerResolutionInfo.getCoarsestMagIndex();
lowestResolutionIndex = datasetFallbackLayerResolutionInfo.getFinestMagIndex();
const datasetFallbackLayerMagInfo = getMagInfo(selectedSegmentationLayer.resolutions);
highestMagIndex = datasetFallbackLayerMagInfo.getCoarsestMagIndex();
lowestMagIndex = datasetFallbackLayerMagInfo.getFinestMagIndex();
}

const highResolutionIndex = Math.min(highestResolutionIndex, magIndices[1]);
const lowResolutionIndex = Math.max(lowestResolutionIndex, magIndices[0]);
const highMagIndex = Math.min(highestMagIndex, magIndices[1]);
const lowMagIndex = Math.max(lowestMagIndex, magIndices[0]);

// biome-ignore lint/correctness/useExhaustiveDependencies: setResolutionIndices should also be added to the dependencies. Consider fixing this.
// biome-ignore lint/correctness/useExhaustiveDependencies: setMagIndices should also be added to the dependencies. Consider fixing this.
useEffect(() => {
setMagIndices([lowestResolutionIndex, highestResolutionIndex]);
}, [lowestResolutionIndex, highestResolutionIndex]);
setMagIndices([lowestMagIndex, highestMagIndex]);
}, [lowestMagIndex, highestMagIndex]);

return lowestResolutionIndex < highestResolutionIndex ? (
return lowestMagIndex < highestMagIndex ? (
<React.Fragment>
<h5
style={{
Expand Down Expand Up @@ -136,16 +136,16 @@ export function RestrictMagnificationSlider({
marginRight: 20,
}}
>
{magInfo.getMagByIndexOrThrow(lowResolutionIndex).join("-")}
{magInfo.getMagByIndexOrThrow(lowMagIndex).join("-")}
</div>
<Slider
tooltip={{ open: false }}
onChange={(value) => setMagIndices(value)}
range
step={1}
min={lowestResolutionIndex}
max={highestResolutionIndex}
value={[lowResolutionIndex, highResolutionIndex]}
min={lowestMagIndex}
max={highestMagIndex}
value={[lowMagIndex, highMagIndex]}
style={{
flexGrow: 1,
}}
Expand All @@ -157,7 +157,7 @@ export function RestrictMagnificationSlider({
textAlign: "right",
}}
>
{magInfo.getMagByIndexOrThrow(highResolutionIndex).join("-")}
{magInfo.getMagByIndexOrThrow(highMagIndex).join("-")}
</div>
</div>
</React.Fragment>
Expand All @@ -167,7 +167,7 @@ export function RestrictMagnificationSlider({
function CreateExplorativeModal({ datasetId, onClose }: Props) {
const dataset = useFetch(() => getDataset(datasetId), null, [datasetId]);
const [annotationType, setAnnotationType] = useState("hybrid");
const [userDefinedResolutionIndices, setUserDefinedResolutionIndices] = useState([0, 10000]);
const [userDefinedMagIndices, setUserDefinedMagIndices] = useState([0, 10000]);
const [selectedSegmentationLayerName, setSelectedSegmentationLayerName] = useState<
string | undefined
>(undefined);
Expand All @@ -194,22 +194,22 @@ function CreateExplorativeModal({ datasetId, onClose }: Props) {
selectedSegmentationLayer != null
? `&fallbackLayerName=${selectedSegmentationLayer.name}`
: "";
const resolutionInfo =
const magInfo =
selectedSegmentationLayer == null
? getSomeMagInfoForDataset(dataset)
: getMagInfo(selectedSegmentationLayer.resolutions);
const highestResolutionIndex = resolutionInfo.getCoarsestMagIndex();
const lowestResolutionIndex = resolutionInfo.getFinestMagIndex();
const highestMagIndex = magInfo.getCoarsestMagIndex();
const lowestMagIndex = magInfo.getFinestMagIndex();

const highResolutionIndex = Math.min(highestResolutionIndex, userDefinedResolutionIndices[1]);
const lowResolutionIndex = Math.max(lowestResolutionIndex, userDefinedResolutionIndices[0]);
const resolutionSlider =
const highMagIndex = Math.min(highestMagIndex, userDefinedMagIndices[1]);
const lowMagIndex = Math.max(lowestMagIndex, userDefinedMagIndices[0]);
const magSlider =
annotationType !== "skeleton" ? (
<RestrictMagnificationSlider
magInfo={resolutionInfo}
magInfo={magInfo}
selectedSegmentationLayer={selectedSegmentationLayer}
magIndices={userDefinedResolutionIndices}
setMagIndices={setUserDefinedResolutionIndices}
magIndices={userDefinedMagIndices}
setMagIndices={setUserDefinedMagIndices}
/>
) : null;
modalContent = (
Expand All @@ -235,17 +235,17 @@ function CreateExplorativeModal({ datasetId, onClose }: Props) {
/>
) : null}

{resolutionSlider}
{magSlider}
<div
style={{
textAlign: "right",
}}
>
<Link
to={`/datasets/${dataset.id}/createExplorative/${annotationType}/?minMag=${Math.max(
...resolutionInfo.getMagByIndexOrThrow(lowResolutionIndex),
...magInfo.getMagByIndexOrThrow(lowMagIndex),
)}&maxMag=${Math.max(
...resolutionInfo.getMagByIndexOrThrow(highResolutionIndex),
...magInfo.getMagByIndexOrThrow(highMagIndex),
)}${fallbackLayerGetParameter}`}
title="Create new annotation with selected properties"
>
Expand Down
50 changes: 24 additions & 26 deletions frontend/javascripts/oxalis/api/api_latest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -670,15 +670,13 @@ class TracingApi {
);
}

const resolutionInfo = getMagInfo(
getLayerByName(state.dataset, segmentationLayerName).resolutions,
);
const magInfo = getMagInfo(getLayerByName(state.dataset, segmentationLayerName).resolutions);
const theoreticalMagIndex = getActiveMagIndexForLayer(state, segmentationLayerName);
const existingMagIndex = resolutionInfo.getIndexOrClosestHigherIndex(theoreticalMagIndex);
const existingMagIndex = magInfo.getIndexOrClosestHigherIndex(theoreticalMagIndex);
if (existingMagIndex == null) {
throw new Error("The index of the current mag could not be found.");
}
const currentMag = resolutionInfo.getMagByIndex(existingMagIndex);
const currentMag = magInfo.getMagByIndex(existingMagIndex);
if (currentMag == null) {
throw new Error("No mag could be found.");
}
Expand Down Expand Up @@ -1843,8 +1841,8 @@ class DataApi {
zoomStep = _zoomStep;
} else {
const layer = getLayerByName(Store.getState().dataset, layerName);
const resolutionInfo = getMagInfo(layer.resolutions);
zoomStep = resolutionInfo.getFinestMagIndex();
const magInfo = getMagInfo(layer.resolutions);
zoomStep = magInfo.getFinestMagIndex();
}

const cube = this.model.getCubeByLayerName(layerName);
Expand Down Expand Up @@ -1900,19 +1898,19 @@ class DataApi {
additionalCoordinates: AdditionalCoordinate[] | null = null,
) {
const layer = getLayerByName(Store.getState().dataset, layerName);
const resolutionInfo = getMagInfo(layer.resolutions);
const magInfo = getMagInfo(layer.resolutions);
let zoomStep;

if (_zoomStep != null) {
zoomStep = _zoomStep;
} else {
zoomStep = resolutionInfo.getFinestMagIndex();
zoomStep = magInfo.getFinestMagIndex();
}

const resolutions = resolutionInfo.getDenseMags();
const mags = magInfo.getDenseMags();
const bucketAddresses = this.getBucketAddressesInCuboid(
mag1Bbox,
resolutions,
mags,
zoomStep,
additionalCoordinates,
);
Expand All @@ -1927,13 +1925,13 @@ class DataApi {
bucketAddresses.map((addr) => this.getLoadedBucket(layerName, addr)),
);
const { elementClass } = getLayerByName(Store.getState().dataset, layerName);
return this.cutOutCuboid(buckets, mag1Bbox, elementClass, resolutions, zoomStep);
return this.cutOutCuboid(buckets, mag1Bbox, elementClass, mags, zoomStep);
}

async getViewportData(
viewport: OrthoView,
layerName: string,
maybeResolutionIndex: number | null | undefined,
maybeMagIndex: number | null | undefined,
additionalCoordinates: AdditionalCoordinate[] | null,
) {
const state = Store.getState();
Expand All @@ -1946,11 +1944,11 @@ class DataApi {
viewport,
);
const layer = getLayerByName(state.dataset, layerName);
const resolutionInfo = getMagInfo(layer.resolutions);
if (maybeResolutionIndex == null) {
maybeResolutionIndex = getActiveMagIndexForLayer(state, layerName);
const magInfo = getMagInfo(layer.resolutions);
if (maybeMagIndex == null) {
maybeMagIndex = getActiveMagIndexForLayer(state, layerName);
}
const zoomStep = resolutionInfo.getClosestExistingIndex(maybeResolutionIndex);
const zoomStep = magInfo.getClosestExistingIndex(maybeMagIndex);

const min = dimensions.transDim(
V3.sub([curU, curV, curW], [halfViewportExtentU, halfViewportExtentV, 0]),
Expand All @@ -1961,10 +1959,10 @@ class DataApi {
viewport,
);

const resolution = resolutionInfo.getMagByIndexOrThrow(zoomStep);
const resolutionUVX = dimensions.transDim(resolution, viewport);
const widthInVoxel = Math.ceil(halfViewportExtentU / resolutionUVX[0]);
const heightInVoxel = Math.ceil(halfViewportExtentV / resolutionUVX[1]);
const mag = magInfo.getMagByIndexOrThrow(zoomStep);
const magUVX = dimensions.transDim(mag, viewport);
const widthInVoxel = Math.ceil(halfViewportExtentU / magUVX[0]);
const heightInVoxel = Math.ceil(halfViewportExtentV / magUVX[1]);
if (widthInVoxel * heightInVoxel > 1024 ** 2) {
throw new Error(
"Requested data for viewport cannot be loaded, since the amount of data is too large for the available magnification. Please zoom in further or ensure that coarser magnifications are available.",
Expand Down Expand Up @@ -2036,12 +2034,12 @@ class DataApi {
magnifications: Array<Vector3>,
zoomStep: number,
): TypedArray {
const resolution = magnifications[zoomStep];
const mag = magnifications[zoomStep];
// All calculations in this method are in zoomStep-space, so in global coordinates which are divided
// by the mag
const topLeft = scaleGlobalPositionWithMagnification(bbox.min, resolution);
const topLeft = scaleGlobalPositionWithMagnification(bbox.min, mag);
// Ceil the bounding box bottom right instead of flooring, because it is exclusive
const bottomRight = scaleGlobalPositionWithMagnification(bbox.max, resolution, true);
const bottomRight = scaleGlobalPositionWithMagnification(bbox.max, mag, true);
const extent: Vector3 = V3.sub(bottomRight, topLeft);
const [TypedArrayClass, channelCount] = getConstructorForElementClass(elementClass);
const result = new TypedArrayClass(channelCount * extent[0] * extent[1] * extent[2]);
Expand Down Expand Up @@ -2107,8 +2105,8 @@ class DataApi {
magnification?: Vector3,
): string {
const { dataset } = Store.getState();
const resolutionInfo = getMagInfo(getLayerByName(dataset, layerName, true).resolutions);
magnification = magnification || resolutionInfo.getFinestMag();
const magInfo = getMagInfo(getLayerByName(dataset, layerName, true).resolutions);
magnification = magnification || magInfo.getFinestMag();

const magString = magnification.join("-");
return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ export const moveW = (deltaW: number, oneSlide: boolean): void => {
// The following logic might not always make sense when having layers
// that are transformed each. Todo: Rethink / adapt the logic once
// problems occur. Tracked in #6926.
const { representativeResolution } = getActiveMagInfo(Store.getState());
const { representativeMag } = getActiveMagInfo(Store.getState());
const wDim = Dimensions.getIndices(activeViewport)[2];
const wStep = (representativeResolution || [1, 1, 1])[wDim];
const wStep = (representativeMag || [1, 1, 1])[wDim];
Store.dispatch(
moveFlycamOrthoAction(
Dimensions.transDim([0, 0, Math.sign(deltaW) * Math.max(1, wStep)], activeViewport),
Expand Down
Loading

0 comments on commit c0fab5a

Please sign in to comment.