Skip to content

Commit 0419b44

Browse files
committed
Improve fitting derived pyramid to source pyramid
1 parent 8af5b3a commit 0419b44

File tree

2 files changed

+38
-39
lines changed

2 files changed

+38
-39
lines changed

src/pyramid.js

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -585,10 +585,10 @@ function _fitImagePyramid (pyramid, refPyramid) {
585585
// Fit the pyramid levels to the reference image pyramid
586586
const fittedPyramid = {
587587
extent: [...refPyramid.extent],
588-
origins: [...refPyramid.origins],
589-
resolutions: [...refPyramid.resolutions],
590-
gridSizes: [...refPyramid.gridSizes],
591-
tileSizes: [...refPyramid.tileSizes],
588+
origins: [],
589+
resolutions: [],
590+
gridSizes: [],
591+
tileSizes: [],
592592
pixelSpacings: [],
593593
metadata: [],
594594
frameMappings: []
@@ -597,19 +597,36 @@ function _fitImagePyramid (pyramid, refPyramid) {
597597
const index = matchingLevelIndices.find(element => element[0] === i)
598598
if (index) {
599599
const j = index[1]
600-
fittedPyramid.gridSizes[i] = [...pyramid.gridSizes[j]]
601-
fittedPyramid.tileSizes[i] = [...pyramid.tileSizes[j]]
600+
fittedPyramid.origins.push([...pyramid.origins[j]])
601+
fittedPyramid.gridSizes.push([...pyramid.gridSizes[j]])
602+
fittedPyramid.tileSizes.push([...pyramid.tileSizes[j]])
603+
fittedPyramid.resolutions.push(Number(refPyramid.resolutions[i]))
602604
fittedPyramid.pixelSpacings.push([...pyramid.pixelSpacings[j]])
603605
fittedPyramid.metadata.push(pyramid.metadata[j])
604606
fittedPyramid.frameMappings.push(pyramid.frameMappings[j])
605-
} else {
606-
fittedPyramid.pixelSpacings.push(undefined)
607-
fittedPyramid.metadata.push(undefined)
608-
fittedPyramid.frameMappings.push(undefined)
609607
}
610608
}
611609

612-
return fittedPyramid
610+
let minZoom = 0
611+
for (let i = 0; i < refPyramid.resolutions.length; i++) {
612+
for (let j = 0; j < fittedPyramid.resolutions.length; j++) {
613+
if (refPyramid.resolutions[i] === fittedPyramid.resolutions[j]) {
614+
minZoom = i
615+
break
616+
}
617+
}
618+
}
619+
let maxZoom = refPyramid.resolutions.length - 1
620+
for (let i = (refPyramid.resolutions.length - 1); i >= minZoom; i--) {
621+
for (let j = (fittedPyramid.resolutions.length - 1); j >= 0; j--) {
622+
if (refPyramid.resolutions[i] === fittedPyramid.resolutions[j]) {
623+
maxZoom = i
624+
break
625+
}
626+
}
627+
}
628+
629+
return [fittedPyramid, minZoom, maxZoom]
613630
}
614631

615632
export {

src/viewer.js

Lines changed: 10 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1279,10 +1279,10 @@ class VolumeImageViewer {
12791279
const map = this[_overviewMap].getOverviewMap()
12801280

12811281
const overviewElement = this[_overviewMap].element
1282-
const overviewChildren = overviewElement.children
1283-
const overviewmapElement = Object.values(overviewChildren).find(
1282+
const overviewmapElement = Object.values(overviewElement.children).find(
12841283
c => c.className === 'ol-overviewmap-map'
12851284
)
1285+
// TODO: color "ol-overviewmap-map-box" using primary color
12861286
overviewmapElement.style.width = `${width}px`
12871287
overviewmapElement.style.height = `${height}px`
12881288
map.updateSize()
@@ -3662,7 +3662,10 @@ class VolumeImageViewer {
36623662
)
36633663

36643664
const pyramid = _computeImagePyramid({ metadata })
3665-
const fittedPyramid = _fitImagePyramid(pyramid, this[_pyramid])
3665+
const [fittedPyramid, minZoomLevel, maxZoomLevel] = _fitImagePyramid(
3666+
pyramid,
3667+
this[_pyramid]
3668+
)
36663669

36673670
const tileGrid = new TileGrid({
36683671
extent: fittedPyramid.extent,
@@ -3694,18 +3697,6 @@ class VolumeImageViewer {
36943697
bins: Math.pow(2, 8)
36953698
})
36963699

3697-
const minZoomLevel = fittedPyramid.metadata.findIndex(item => {
3698-
return item !== undefined
3699-
})
3700-
let maxZoomLevel = fittedPyramid.metadata.findIndex((item, index) => {
3701-
return index > minZoomLevel && item === undefined
3702-
})
3703-
if (maxZoomLevel < 0) {
3704-
maxZoomLevel = fittedPyramid.metadata.length - 1
3705-
} else if (maxZoomLevel > 0) {
3706-
maxZoomLevel = maxZoomLevel - 1
3707-
}
3708-
37093700
const defaultSegmentStyle = {
37103701
opacity: 0.75,
37113702
paletteColorLookupTable: buildPaletteColorLookupTable({
@@ -4082,7 +4073,10 @@ class VolumeImageViewer {
40824073
)
40834074

40844075
const pyramid = _computeImagePyramid({ metadata })
4085-
const fittedPyramid = _fitImagePyramid(pyramid, this[_pyramid])
4076+
const [fittedPyramid, minZoomLevel, maxZoomLevel] = _fitImagePyramid(
4077+
pyramid,
4078+
this[_pyramid]
4079+
)
40864080

40874081
const tileGrid = new TileGrid({
40884082
extent: fittedPyramid.extent,
@@ -4182,18 +4176,6 @@ class VolumeImageViewer {
41824176
}
41834177
}
41844178

4185-
const minZoomLevel = fittedPyramid.metadata.findIndex(item => {
4186-
return item !== undefined
4187-
})
4188-
let maxZoomLevel = fittedPyramid.metadata.findIndex((item, index) => {
4189-
return index > minZoomLevel && item === undefined
4190-
})
4191-
if (maxZoomLevel < 0) {
4192-
maxZoomLevel = fittedPyramid.metadata.length - 1
4193-
} else if (maxZoomLevel > 0) {
4194-
maxZoomLevel = maxZoomLevel - 1
4195-
}
4196-
41974179
const defaultMappingStyle = {
41984180
opacity: 1.0,
41994181
limitValues: [

0 commit comments

Comments
 (0)