Skip to content

Commit

Permalink
Tile layer: allow digital zoom for non-negative zoom levels
Browse files Browse the repository at this point in the history
In some datasets only downsampled versions of the data are available or
practical to use. To indicate to CATMAID that a dataset has only scale
levels available starting at a certain point, stacks nach now include
the minZoomLevel field in the stack's JSON metadata field. It is zero by
default. If set to e.g. one, tile layers will digitally zoom scale level
one 200% to show scale level zero.
  • Loading branch information
tomka committed May 8, 2024
1 parent 7d9f836 commit 1d7b2b1
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 5 deletions.
13 changes: 8 additions & 5 deletions django/applications/catmaid/static/js/layers/tile-layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -504,19 +504,22 @@
if (typeof efficiencyThreshold === 'undefined') efficiencyThreshold = 0.0;
var zoom = s;
var mag = 1.0;
// The minimum zoom level indicates down to what scale level data is
// available. Usually this is zoom level zero.
var minZoom = this.stack.minZoomLevel;

/* If the zoom is negative we zoom in digitally. For this
* we take the zero zoom level and adjust the tile properties.
* This way we let the browser do the zooming work.
/* If the zoom is below our minimum zoom level (usually this means negative)
* we zoom in digitally. For this we take the zero zoom level and adjust the
* tile properties. This way we let the browser do the zooming work.
*/
if (zoom < 0 || zoom % 1 !== 0) {
if (zoom < minZoom || zoom % 1 !== 0) {
/* For nonintegral zoom levels the ceiling is used to select
* source image zoom level. While using the floor would allow
* better image quality, it would requiring dynamically
* increasing the number of tiles to fill the viewport since
* in that case effectiveTileWidth < tileWidth.
*/
zoom = Math.min(this.stack.MAX_S, Math.max(0, Math.ceil(zoom)));
zoom = Math.min(this.stack.MAX_S, Math.max(minZoom, Math.ceil(zoom)));
/* Magnification is positive for digital zoom beyond image
* resolution and negative for non-integral zooms within
* image resolution.
Expand Down
4 changes: 4 additions & 0 deletions django/applications/catmaid/static/js/stack.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@
}
self.MIN_S = max_zoom_level;
self.downsample_factors = downsample_factors;
// A min zoom level can be defined as part of the stack's meta data. It
// allow to start artificial zoom at larger zoom levels than zero. This is
// useful if e.g. if only downscaled parts of a dataset are available.
self.minZoomLevel = metadata ? CATMAID.tools.getDefined(metadata.minZoomLevel, 0) : 0;

self.comment = comment;
self.description = description;
Expand Down
1 change: 1 addition & 0 deletions django/applications/catmaid/static/js/tools/navigator.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
this.updateControls = function()
{
if (self.stackViewer) {
self.slider_s.setSplitValue( self.stackViewer.primaryStack.minZoomLevel, true );
self.slider_s.setByValue( self.stackViewer.s, true );
self.slider_z.setByValue( self.stackViewer.z, true );

Expand Down
9 changes: 9 additions & 0 deletions django/applications/catmaid/static/js/widgets/slider.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,15 @@
return this._inputView;
};

Slider.prototype.setSplitValue = function (value, exclusive = false) {
const indices = this._binValue(value, this._values);
let index = indices[indices.length > 1 ? 1 : 0];
if (exclusive && this._values.length > index + 1) {
index += 1;
}
this._splitIndex = index;
};

/**
* set a value by its index in the value array
*/
Expand Down

0 comments on commit 1d7b2b1

Please sign in to comment.