Skip to content

Commit

Permalink
Ensure that resolutions array is dense (#3406)
Browse files Browse the repository at this point in the history
* ensure that resolutions array is dense

* update changelog
  • Loading branch information
philippotto authored Nov 5, 2018
1 parent 572022e commit 3f84d22
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ For upgrade instructions, please check the [migration guide](MIGRATIONS.md).
- Added a button to the users list view that revokes admin rights from all selected users. [#3378](https://github.com/scalableminds/webknossos/pull/3378)
- Hybrid tracings are now enabled by default. They allow to combine the functionality of skeleton and volume annotations in one tracing. [#3399](https://github.com/scalableminds/webknossos/pull/3399)
- 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)
- The info tab in tracing views now displays the extent of the current dataset. [#3371](https://github.com/scalableminds/webknossos/pull/3371).

### 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

0 comments on commit 3f84d22

Please sign in to comment.