@@ -65,6 +65,7 @@ import { ParameterMapping, _groupFramesPerMapping } from './mapping.js'
6565import { ROI } from './roi.js'
6666import { Segment } from './segment.js'
6767import {
68+ applyTransform ,
6869 buildInverseTransform ,
6970 buildTransform ,
7071 computeRotation ,
@@ -1961,6 +1962,88 @@ class VolumeImageViewer {
19611962 }
19621963 }
19631964
1965+ /**
1966+ * Get the number of zoom levels.
1967+ *
1968+ * @type number
1969+ */
1970+ get numLevels ( ) {
1971+ return this [ _pyramid ] . pixelSpacings . length
1972+ }
1973+
1974+ /**
1975+ * Get the pixel spacing at a given zoom level.
1976+ *
1977+ * @param {Object } options - Options.
1978+ * @param {number } options.level - Zoom level.
1979+ * @returns {number[] } Spacing between the centers of two neighboring pixels
1980+ */
1981+ getPixelSpacing ( level ) {
1982+ return this [ _pyramid ] . pixelSpacings [ level ] . slice ( 0 )
1983+ }
1984+
1985+ /**
1986+ * Get the physical offset of images on the slide.
1987+ * Offset along the X and Y axes of the slide coordinate system in
1988+ * millimeter unit.
1989+ *
1990+ * @type number[]
1991+ */
1992+ get physicalOffset ( ) {
1993+ const point = applyTransform ( {
1994+ coordinate : [ 0 , 0 ] ,
1995+ affine : this [ _affine ]
1996+ } )
1997+ return [ point [ 0 ] , point [ 1 ] , 0 ]
1998+ }
1999+
2000+ /**
2001+ * Get the physical size of images on the slide.
2002+ * Length along the X and Y axes of the slide coordinate system in
2003+ * millimeter unit.
2004+ *
2005+ * @type number[]
2006+ */
2007+ get physicalSize ( ) {
2008+ const offset = this . physicalOffset
2009+ const metadata = this [ _pyramid ] . metadata [ this [ _pyramid ] . metadata . length - 1 ]
2010+ const point = applyTransform ( {
2011+ coordinate : [
2012+ metadata . TotalPixelMatrixColumns ,
2013+ metadata . TotalPixelMatrixRows
2014+ ] ,
2015+ affine : this [ _affine ]
2016+ } )
2017+ return [
2018+ Math . abs ( point [ 0 ] - offset [ 0 ] ) ,
2019+ Math . abs ( point [ 1 ] - offset [ 1 ] )
2020+ ]
2021+ }
2022+
2023+ /**
2024+ * Get the offset and size of the bounding box that contains the images
2025+ * in the slide coordinate system in millimeter unit.
2026+ *
2027+ * @type number[]
2028+ */
2029+ get boundingBox ( ) {
2030+ const startPoint = this . physicalOffset
2031+ const metadata = this [ _pyramid ] . metadata [ this [ _pyramid ] . metadata . length - 1 ]
2032+ const endPoint = applyTransform ( {
2033+ coordinate : [
2034+ metadata . TotalPixelMatrixColumns ,
2035+ metadata . TotalPixelMatrixRows
2036+ ] ,
2037+ affine : this [ _affine ]
2038+ } )
2039+ const offset = [
2040+ Math . min ( startPoint [ 0 ] , endPoint [ 0 ] ) ,
2041+ Math . min ( startPoint [ 1 ] , endPoint [ 1 ] )
2042+ ]
2043+ const size = this . physicalSize
2044+ return [ offset , size ]
2045+ }
2046+
19642047 /**
19652048 * Navigate the view to a spatial position or resolution level.
19662049 *
@@ -1969,8 +2052,7 @@ class VolumeImageViewer {
19692052 * @param {number[] } options.position - X, Y coordinates in slide coordinate system.
19702053 */
19712054 navigate ( { level, position } ) {
1972- const numLevels = this [ _pyramid ] . resolutions . length
1973- if ( level > numLevels ) {
2055+ if ( level > this . numLevels ) {
19742056 throw new Error ( 'Argument "level" exceeds number of resolution levels.' )
19752057 }
19762058 let coordinates
@@ -2923,7 +3005,6 @@ class VolumeImageViewer {
29233005 i ,
29243006 numberOfAnnotations
29253007 )
2926- console . log ( 'DEBUG: ' , this [ _affineInverse ] )
29273008 const coordinates = _scoord3dCoordinates2geometryCoordinates (
29283009 point ,
29293010 pyramid ,
@@ -4371,7 +4452,7 @@ class _NonVolumeImageViewer {
43714452 /**
43724453 * Get the size of the viewport.
43734454 *
4374- * @return { number[] }
4455+ * @type number[]
43754456 */
43764457 get size ( ) {
43774458 return this [ _map ] . getSize ( )
0 commit comments