@@ -28,15 +28,9 @@ function vtkImageData(publicAPI, model) {
28
28
return false ;
29
29
}
30
30
31
- let changeDetected = false ;
32
- model . extent . forEach ( ( item , index ) => {
33
- if ( item !== extentArray [ index ] ) {
34
- if ( changeDetected ) {
35
- return ;
36
- }
37
- changeDetected = true ;
38
- }
39
- } ) ;
31
+ const changeDetected = model . extent . some (
32
+ ( item , index ) => item !== extentArray [ index ]
33
+ ) ;
40
34
41
35
if ( changeDetected ) {
42
36
model . extent = extentArray . slice ( ) ;
@@ -195,51 +189,27 @@ function vtkImageData(publicAPI, model) {
195
189
publicAPI . extentToBounds = ( ex ) => {
196
190
// prettier-ignore
197
191
const corners = [
198
- ex [ 0 ] , ex [ 2 ] , ex [ 4 ] ,
199
- ex [ 1 ] , ex [ 2 ] , ex [ 4 ] ,
200
- ex [ 0 ] , ex [ 3 ] , ex [ 4 ] ,
201
- ex [ 1 ] , ex [ 3 ] , ex [ 4 ] ,
202
- ex [ 0 ] , ex [ 2 ] , ex [ 5 ] ,
203
- ex [ 1 ] , ex [ 2 ] , ex [ 5 ] ,
204
- ex [ 0 ] , ex [ 3 ] , ex [ 5 ] ,
205
- ex [ 1 ] , ex [ 3 ] , ex [ 5 ] ] ;
206
-
207
- const idx = new Float64Array ( [ corners [ 0 ] , corners [ 1 ] , corners [ 2 ] ] ) ;
208
- const vout = new Float64Array ( 3 ) ;
209
- publicAPI . indexToWorld ( idx , vout ) ;
210
- const bounds = [ vout [ 0 ] , vout [ 0 ] , vout [ 1 ] , vout [ 1 ] , vout [ 2 ] , vout [ 2 ] ] ;
211
- for ( let i = 3 ; i < 24 ; i += 3 ) {
212
- vec3 . set ( idx , corners [ i ] , corners [ i + 1 ] , corners [ i + 2 ] ) ;
213
- publicAPI . indexToWorld ( idx , vout ) ;
214
- if ( vout [ 0 ] < bounds [ 0 ] ) {
215
- bounds [ 0 ] = vout [ 0 ] ;
216
- }
217
- if ( vout [ 1 ] < bounds [ 2 ] ) {
218
- bounds [ 2 ] = vout [ 1 ] ;
219
- }
220
- if ( vout [ 2 ] < bounds [ 4 ] ) {
221
- bounds [ 4 ] = vout [ 2 ] ;
222
- }
223
- if ( vout [ 0 ] > bounds [ 1 ] ) {
224
- bounds [ 1 ] = vout [ 0 ] ;
225
- }
226
- if ( vout [ 1 ] > bounds [ 3 ] ) {
227
- bounds [ 3 ] = vout [ 1 ] ;
228
- }
229
- if ( vout [ 2 ] > bounds [ 5 ] ) {
230
- bounds [ 5 ] = vout [ 2 ] ;
231
- }
192
+ [ ex [ 0 ] , ex [ 2 ] , ex [ 4 ] ] ,
193
+ [ ex [ 1 ] , ex [ 2 ] , ex [ 4 ] ] ,
194
+ [ ex [ 0 ] , ex [ 3 ] , ex [ 4 ] ] ,
195
+ [ ex [ 1 ] , ex [ 3 ] , ex [ 4 ] ] ,
196
+ [ ex [ 0 ] , ex [ 2 ] , ex [ 5 ] ] ,
197
+ [ ex [ 1 ] , ex [ 2 ] , ex [ 5 ] ] ,
198
+ [ ex [ 0 ] , ex [ 3 ] , ex [ 5 ] ] ,
199
+ [ ex [ 1 ] , ex [ 3 ] , ex [ 5 ] ]
200
+ ] ;
201
+
202
+ const bounds = [ ...vtkBoundingBox . INIT_BOUNDS ] ;
203
+ const vout = [ ] ;
204
+ for ( let i = 0 ; i < 8 ; ++ i ) {
205
+ publicAPI . indexToWorld ( corners [ i ] , vout ) ;
206
+ vtkBoundingBox . addPoint ( bounds , ...vout ) ;
232
207
}
233
-
234
208
return bounds ;
235
209
} ;
236
210
237
- publicAPI . getSpatialExtent = ( ) => {
238
- const boundingBox = vtkBoundingBox . newInstance ( ) ;
239
- boundingBox . setBounds ( model . extent ) ;
240
- boundingBox . inflate ( 0.5 ) ;
241
- return boundingBox . getBounds ( ) ;
242
- } ;
211
+ publicAPI . getSpatialExtent = ( ) =>
212
+ vtkBoundingBox . inflate ( [ ...model . extent ] , 0.5 ) ;
243
213
244
214
// Internal, shouldn't need to call this manually.
245
215
publicAPI . computeTransforms = ( ) => {
@@ -350,16 +320,7 @@ function vtkImageData(publicAPI, model) {
350
320
publicAPI . onModified ( publicAPI . computeTransforms ) ;
351
321
publicAPI . computeTransforms ( ) ;
352
322
353
- publicAPI . getCenter = ( ) => {
354
- const bounds = publicAPI . getBounds ( ) ;
355
- const center = [ ] ;
356
-
357
- for ( let i = 0 ; i < 3 ; i ++ ) {
358
- center [ i ] = ( bounds [ 2 * i + 1 ] + bounds [ 2 * i ] ) / 2 ;
359
- }
360
-
361
- return center ;
362
- } ;
323
+ publicAPI . getCenter = ( ) => vtkBoundingBox . getCenter ( publicAPI . getBounds ( ) ) ;
363
324
364
325
publicAPI . computeHistogram = ( worldBounds , voxelFunc = null ) => {
365
326
const bounds = [ 0 , 0 , 0 , 0 , 0 , 0 ] ;
0 commit comments