fix: compute exact pyramid resolutions to keep THUMBNAIL levels aligned (slim#318)#245
Open
igoroctaviano wants to merge 2 commits into
Open
fix: compute exact pyramid resolutions to keep THUMBNAIL levels aligned (slim#318)#245igoroctaviano wants to merge 2 commits into
igoroctaviano wants to merge 2 commits into
Conversation
The per-level zoom factor in _computeImagePyramid was rounded to the nearest integer (Math.round). VOLUME levels are clean power-of-two downsamples so rounding was harmless, but THUMBNAIL images are not exact fractions of the base level. For example a thumbnail whose base/level column ratio is ~57.70 was rounded to 58, a ~0.5% scale error that stretches the level and makes its upsampled image content drift relative to vector annotations while zooming, so annotations appear misplaced. Use the exact column ratio for every level instead of rounding, keeping each level aligned to the base coordinate system. Resolutions are still guaranteed to be unique and strictly descending as required by OpenLayers. Fixes ImagingDataCommons/slim#318 Refs openlayers/openlayers#12768
4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes the annotation misplacement reported in ImagingDataCommons/slim#318, where the presence of a
THUMBNAILimage causes the slide to "jump" and annotations to render in the wrong place while zooming.Root cause
_computeImagePyramidcomputed each level's resolution (zoom factor) asbaseTotalPixelMatrixColumns / totalPixelMatrixColumnsand then rounded it to the nearest integer (Math.round).VOLUMElevels are clean (power-of-two style) downsamples of the base level, so their ratio is already (essentially) an integer and rounding is harmless.THUMBNAILimages are not exact fractions of the base level. Confirmed against the repo's ownTCGA-LUADfixture:Rounding
57.70 → 58is a ~0.5% scale error (~238 px across the slide). It stretches the thumbnail level so its upsampled image content drifts toward the bottom-right relative to the (correctly placed) vector annotation layer. This is why disabling thumbnails (skipThumbnails) "fixed" it — the remaining volume-only pyramid has integer ratios.This is distinct from, but compounds, the transient nearest-neighbor upsampling shift discussed in openlayers/openlayers#12768.
Fix
Use the exact column ratio for every level instead of rounding. Levels are processed base → top, so each zoom factor is naturally strictly greater than the previous; a small floating-point guard preserves OpenLayers' requirement that resolutions be unique and strictly descending.
Test plan
src/pyramid.test.jsregression tests: thumbnail level is kept, every resolution equals the exact ratio, the thumbnail factor is not rounded to an integer, and resolutions remain unique/strictly descending.162 passed.biome checkclean.webpack-bundle).Follow-up
After release, ImagingDataCommons/slim can drop the
skipThumbnails: trueworkaround and re-enable thumbnails for faster initial load (see slim#318 discussion).