@@ -103,6 +103,51 @@ function vtkImageSlice(publicAPI, model) {
103103 return model . bounds ;
104104 } ;
105105
106+ publicAPI . getBoundsForSlice = ( slice , thickness = 0 ) => {
107+ // Check for the special case when the mapper's bounds are unknown
108+ const bds = model . mapper . getBoundsForSlice ( slice , thickness ) ;
109+ if ( ! bds || bds . length !== 6 ) {
110+ return bds ;
111+ }
112+
113+ // Check for the special case when the actor is empty.
114+ if ( bds [ 0 ] > bds [ 1 ] ) {
115+ return bds ;
116+ }
117+
118+ const bbox = [
119+ vec3 . fromValues ( bds [ 1 ] , bds [ 3 ] , bds [ 5 ] ) ,
120+ vec3 . fromValues ( bds [ 1 ] , bds [ 2 ] , bds [ 5 ] ) ,
121+ vec3 . fromValues ( bds [ 0 ] , bds [ 2 ] , bds [ 5 ] ) ,
122+ vec3 . fromValues ( bds [ 0 ] , bds [ 3 ] , bds [ 5 ] ) ,
123+ vec3 . fromValues ( bds [ 1 ] , bds [ 3 ] , bds [ 4 ] ) ,
124+ vec3 . fromValues ( bds [ 1 ] , bds [ 2 ] , bds [ 4 ] ) ,
125+ vec3 . fromValues ( bds [ 0 ] , bds [ 2 ] , bds [ 4 ] ) ,
126+ vec3 . fromValues ( bds [ 0 ] , bds [ 3 ] , bds [ 4 ] ) ,
127+ ] ;
128+
129+ publicAPI . computeMatrix ( ) ;
130+ const tmp4 = mat4 . create ( ) ;
131+ mat4 . transpose ( tmp4 , model . matrix ) ;
132+ bbox . forEach ( ( pt ) => vec3 . transformMat4 ( pt , pt , tmp4 ) ) ;
133+
134+ let newBounds = [
135+ Number . MAX_VALUE ,
136+ - Number . MAX_VALUE ,
137+ Number . MAX_VALUE ,
138+ - Number . MAX_VALUE ,
139+ Number . MAX_VALUE ,
140+ - Number . MAX_VALUE ,
141+ ] ;
142+ newBounds = newBounds . map (
143+ ( d , i ) =>
144+ i % 2 === 0
145+ ? bbox . reduce ( ( a , b ) => ( a > b [ i / 2 ] ? b [ i / 2 ] : a ) , d )
146+ : bbox . reduce ( ( a , b ) => ( a < b [ ( i - 1 ) / 2 ] ? b [ ( i - 1 ) / 2 ] : a ) , d )
147+ ) ;
148+ return newBounds ;
149+ } ;
150+
106151 //----------------------------------------------------------------------------
107152 // Get the minimum X bound
108153 publicAPI . getMinXBound = ( ) => {
0 commit comments