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

Ensure that resolutions array is dense #3406

Merged
merged 3 commits into from
Nov 5, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.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.md).
- Extended the version restore view and added a view to restore older versions of a volume tracing. Access it through the dropdown next to the Save button. [#3349](https://github.com/scalableminds/webknossos/pull/3349)
- Added support to watch additional dataset directories, automatically creating symbolic links to the main directory [#3330](https://github.com/scalableminds/webknossos/pull/3330)
- A User can now have multiple layouts for tracing views. [#3299](https://github.com/scalableminds/webknossos/pull/3299)
- Added support for datasets with sparse resolutions (e.g., [[1, 1, 1], [16, 16, 16]]). [#3406](https://github.com/scalableminds/webknossos/pull/3406)

### Changed

Expand Down
30 changes: 30 additions & 0 deletions app/assets/javascripts/oxalis/model_initialization.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import * as Utils from "libs/utils";
import DataLayer from "oxalis/model/data_layer";
import ConnectionInfo from "oxalis/model/data_connection_info";
import { ControlModeEnum } from "oxalis/constants";
import type { Vector3 } from "oxalis/constants";
import Toast from "libs/toast";
import ErrorHandling from "libs/error_handling";
import UrlManager from "oxalis/controller/url_manager";
Expand Down Expand Up @@ -252,9 +253,38 @@ function initializeDataset(
dataset.dataSource.dataLayers = newDataLayers;
});

ensureDenseLayerResolutions(dataset);
Store.dispatch(setDatasetAction(dataset));
}

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

function convertToDenseResolution(resolutions: 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]).
// Therefore, the largest dim for each resolution has to be unique across all resolutions.

// This function returns an array of resolutions, for which each index will
// hold a resolution with highest_dim === 2**index.

if (resolutions.length !== _.uniqBy(resolutions.map(_.max)).length) {
throw new Error("Max dimension in resolutions is not unique.");
}
const paddedResolutionCount = 1 + Math.log2(_.max(resolutions.map(v => _.max(v))));
const resolutionsLookUp = _.keyBy(resolutions, _.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];
});
}

function initializeSettings(initialUserSettings: Object, initialDatasetSettings: Object): void {
Store.dispatch(initializeSettingsAction(initialUserSettings, initialDatasetSettings));
}
Expand Down
1 change: 1 addition & 0 deletions flow-typed/npm/lodash_v4.x.x.js
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,7 @@ declare module "lodash" {
divide(dividend: number, divisor: number): number;
floor(number: number, precision?: number): number;
max<T>(array: ?Array<T>): T;
max<T>(array: [T, T, T]): T;
maxBy<T>(array: ?Array<T>, iteratee?: Iteratee<T>): T;
mean(array: Array<*>): number;
meanBy<T>(array: Array<T>, iteratee?: Iteratee<T>): number;
Expand Down