Skip to content

Commit 8743b75

Browse files
committed
Automatically zoom to resolution of derived images
1 parent 2554e18 commit 8743b75

File tree

1 file changed

+69
-4
lines changed

1 file changed

+69
-4
lines changed

src/viewer.js

Lines changed: 69 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3177,6 +3177,18 @@ class VolumeImageViewer {
31773177
bins: Math.pow(2, 8)
31783178
})
31793179

3180+
const minZoomLevel = fittedPyramid.metadata.findIndex(item => {
3181+
return item !== undefined
3182+
})
3183+
let maxZoomLevel = fittedPyramid.metadata.findIndex((item, index) => {
3184+
return index > minZoomLevel && item === undefined
3185+
})
3186+
if (maxZoomLevel < 0) {
3187+
maxZoomLevel = fittedPyramid.metadata.length - 1
3188+
} else if (maxZoomLevel > 0) {
3189+
maxZoomLevel = maxZoomLevel - 1
3190+
}
3191+
31803192
const segment = {
31813193
segment: new Segment({
31823194
uid: segmentUID,
@@ -3206,6 +3218,8 @@ class VolumeImageViewer {
32063218
}),
32073219
minStoredValue,
32083220
maxStoredValue,
3221+
minZoomLevel,
3222+
maxZoomLevel,
32093223
loaderParams: {
32103224
pyramid: fittedPyramid,
32113225
client: this[_options].client,
@@ -3308,6 +3322,15 @@ class VolumeImageViewer {
33083322
source.setLoader(loader)
33093323
}
33103324

3325+
const view = this[_map].getView()
3326+
const currentZoomLevel = view.getZoom()
3327+
if (
3328+
currentZoomLevel < segment.minZoomLevel ||
3329+
currentZoomLevel > segment.maxZoomLevel
3330+
) {
3331+
view.animate({ zoom: segment.minZoomLevel })
3332+
}
3333+
33113334
segment.layer.setVisible(true)
33123335
this.setSegmentStyle(segmentUID, styleOptions)
33133336
}
@@ -3616,6 +3639,18 @@ class VolumeImageViewer {
36163639
}
36173640
}
36183641

3642+
const minZoomLevel = fittedPyramid.metadata.findIndex(item => {
3643+
return item !== undefined
3644+
})
3645+
let maxZoomLevel = fittedPyramid.metadata.findIndex((item, index) => {
3646+
return index > minZoomLevel && item === undefined
3647+
})
3648+
if (maxZoomLevel < 0) {
3649+
maxZoomLevel = fittedPyramid.metadata.length - 1
3650+
} else if (maxZoomLevel > 0) {
3651+
maxZoomLevel = maxZoomLevel - 1
3652+
}
3653+
36193654
const mapping = {
36203655
mapping: new ParameterMapping({
36213656
uid: mappingUID,
@@ -3645,6 +3680,8 @@ class VolumeImageViewer {
36453680
},
36463681
minStoredValue,
36473682
maxStoredValue,
3683+
minZoomLevel,
3684+
maxZoomLevel,
36483685
loaderParams: {
36493686
pyramid: fittedPyramid,
36503687
client: this[_options].client,
@@ -3744,6 +3781,15 @@ class VolumeImageViewer {
37443781
source.setLoader(loader)
37453782
}
37463783

3784+
const view = this[_map].getView()
3785+
const currentZoomLevel = view.getZoom()
3786+
if (
3787+
currentZoomLevel < mapping.minZoomLevel ||
3788+
currentZoomLevel > mapping.maxZoomLevel
3789+
) {
3790+
view.animate({ zoom: mapping.minZoomLevel })
3791+
}
3792+
37473793
mapping.layer.setVisible(true)
37483794
this.setParameterMappingStyle(mappingUID, styleOptions)
37493795
}
@@ -4055,13 +4101,13 @@ class _NonVolumeImageViewer {
40554101
* @param {Object} options - Rendering options.
40564102
* @param {(string|HTMLElement)} options.container - HTML Element in which the viewer should be injected.
40574103
*/
4058-
render (options) {
4059-
if (options.container == null) {
4104+
render ({ container }) {
4105+
if (container == null) {
40604106
console.error('container must be provided for rendering images')
40614107
return
40624108
}
40634109

4064-
this[_map].setTarget(options.container)
4110+
this[_map].setTarget(container)
40654111
const view = this[_map].getView()
40664112
const projection = view.getProjection()
40674113
view.fit(projection.getExtent(), { size: this[_map].getSize() })
@@ -4072,7 +4118,26 @@ class _NonVolumeImageViewer {
40724118
}
40734119

40744120
/**
4075-
* DICOM metadata for the displayed VL Whole Slide Microscopy Image instance.
4121+
* Move the view to a spatial position or resolution level.
4122+
*
4123+
* @param {Object} options - Options.
4124+
* @param {number} level - Zoom level.
4125+
*/
4126+
move ({ level }) {
4127+
const numLevels = this[_pyramid].resolutions.length
4128+
if (level > numLevels) {
4129+
throw new Error('Argument "level" exceeds number of resolution levels.')
4130+
}
4131+
// TODO: center position in slide/image coordinates
4132+
const view = this[_map].getView()
4133+
const currentZoomLevel = view.getZoom()
4134+
if (level !== currentZoomLevel) {
4135+
view.animate({ zoom: this[_pyramid] })
4136+
}
4137+
}
4138+
4139+
/**
4140+
* DICOM metadata for the displayed VL Whole Slide Microscopy Image instances.
40764141
*
40774142
* @return {VLWholeSlideMicroscopyImage}
40784143
*/

0 commit comments

Comments
 (0)