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

Fix conversion to dense resolution in case of anisotropic, partial resolutions #4344

Merged
merged 7 commits into from
Dec 2, 2019
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ For upgrade instructions, please check the [migration guide](MIGRATIONS.md).
-

### Fixed
-
- Fixed an issue where webKnossos would complained in certain scenarios when resolutions of datasets were not complete. [#4344](https://github.com/scalableminds/webknossos/pull/4344)
philippotto marked this conversation as resolved.
Show resolved Hide resolved

### Removed
-
Expand Down
18 changes: 12 additions & 6 deletions frontend/javascripts/oxalis/model_initialization.js
Original file line number Diff line number Diff line change
Expand Up @@ -308,13 +308,14 @@ function initializeDataset(
Store.dispatch(setDatasetAction(dataset));
}

function ensureDenseLayerResolutions(dataset: APIDataset) {
export function ensureDenseLayerResolutions(dataset: APIDataset) {
const mostExtensiveResolutions = convertToDenseResolution(getMostExtensiveResolutions(dataset));
for (const layer of dataset.dataSource.dataLayers) {
layer.resolutions = convertToDenseResolution(layer.resolutions);
layer.resolutions = convertToDenseResolution(layer.resolutions, mostExtensiveResolutions);
}
}

function ensureMatchingLayerResolutions(dataset: APIDataset): void {
export function ensureMatchingLayerResolutions(dataset: APIDataset): void {
const mostExtensiveResolutions = getMostExtensiveResolutions(dataset);
for (const layer of dataset.dataSource.dataLayers) {
for (const resolution of layer.resolutions) {
Expand All @@ -325,7 +326,10 @@ function ensureMatchingLayerResolutions(dataset: APIDataset): void {
}
}

function convertToDenseResolution(resolutions: Array<Vector3>) {
export function convertToDenseResolution(
resolutions: Array<Vector3>,
fallbackDenseResolutions?: Array<Vector3>,
): Array<Vector3> {
// Each resolution entry can be characterized by it's greatest resolution dimension.
// E.g., the resolution array [[1, 1, 1], [2, 2, 1], [4, 4, 2]] defines that
// a log zoomstep of 2 corresponds to the resolution [2, 2, 1] (and not [4, 4, 2]).
Expand All @@ -339,11 +343,13 @@ function convertToDenseResolution(resolutions: Array<Vector3>) {
}
const paddedResolutionCount = 1 + Math.log2(_.max(resolutions.map(v => _.max(v))));
const resolutionsLookUp = _.keyBy(resolutions, _.max);
const fallbackResolutionsLookUp = _.keyBy(fallbackDenseResolutions || [], _.max);

return _.range(0, paddedResolutionCount).map(exp => {
const resPower = 2 ** exp;
// If the resolution does not exist, use a fallback resolution
return resolutionsLookUp[resPower] || [resPower, resPower, resPower];
// If the resolution does not exist, use either the given fallback resolution or an isotropic fallback
const fallback = fallbackResolutionsLookUp[resPower] || [resPower, resPower, resPower];
return resolutionsLookUp[resPower] || fallback;
});
}

Expand Down
40 changes: 40 additions & 0 deletions frontend/javascripts/test/model/model_resolutions.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import test from "ava";

import {
ensureDenseLayerResolutions,
ensureMatchingLayerResolutions,
convertToDenseResolution,
} from "oxalis/model_initialization";

test("Simple convertToDenseResolution", t => {
const denseResolutions = convertToDenseResolution([[2, 2, 1], [4, 4, 2]]);
t.deepEqual(denseResolutions, [[1, 1, 1], [2, 2, 1], [4, 4, 2]]);
});

test("Complex convertToDenseResolution", t => {
const dataset = {
dataSource: {
dataLayers: [
{
resolutions: [[2, 2, 1], [4, 4, 1], [8, 8, 1], [16, 16, 2], [32, 32, 4]],
},
{
resolutions: [[32, 32, 4]],
},
],
},
};
ensureDenseLayerResolutions(dataset);
ensureMatchingLayerResolutions(dataset);
const expectedResolutions = [
[1, 1, 1],
[2, 2, 1],
[4, 4, 1],
[8, 8, 1],
[16, 16, 2],
[32, 32, 4],
];

t.deepEqual(dataset.dataSource.dataLayers[0].resolutions, expectedResolutions);
t.deepEqual(dataset.dataSource.dataLayers[1].resolutions, expectedResolutions);
});