1
1
import macro from 'vtk.js/Sources/macros' ;
2
2
import vtkDataArray from 'vtk.js/Sources/Common/Core/DataArray' ;
3
3
import { VtkDataTypes } from 'vtk.js/Sources/Common/Core/DataArray/Constants' ;
4
+ import * as vtkMath from 'vtk.js/Sources/Common/Core/Math' ;
4
5
5
6
const { vtkErrorMacro } = macro ;
6
-
7
- const INVALID_BOUNDS = [ 1 , - 1 , 1 , - 1 , 1 , - 1 ] ;
8
-
9
7
// ----------------------------------------------------------------------------
10
8
// vtkPoints methods
11
9
// ----------------------------------------------------------------------------
12
10
13
11
function vtkPoints ( publicAPI , model ) {
12
+ // Keep track of modified time for bounds computation
13
+ let boundMTime = 0 ;
14
+
14
15
// Set our className
15
16
model . classHierarchy . push ( 'vtkPoints' ) ;
16
17
@@ -37,7 +38,24 @@ function vtkPoints(publicAPI, model) {
37
38
38
39
publicAPI . insertPoint = ( ptId , point ) => publicAPI . insertTuple ( ptId , point ) ;
39
40
41
+ const superGetBounds = publicAPI . getBounds ;
40
42
publicAPI . getBounds = ( ) => {
43
+ if ( boundMTime < model . mtime ) {
44
+ publicAPI . computeBounds ( ) ;
45
+ }
46
+ return superGetBounds ( ) ;
47
+ } ;
48
+
49
+ const superGetBoundsByReference = publicAPI . getBoundsByReference ;
50
+ publicAPI . getBoundsByReference = ( ) => {
51
+ if ( boundMTime < model . mtime ) {
52
+ publicAPI . computeBounds ( ) ;
53
+ }
54
+ return superGetBoundsByReference ( ) ;
55
+ } ;
56
+
57
+ // Trigger the computation of bounds
58
+ publicAPI . computeBounds = ( ) => {
41
59
if ( publicAPI . getNumberOfComponents ( ) === 3 ) {
42
60
const xRange = publicAPI . getRange ( 0 ) ;
43
61
model . bounds [ 0 ] = xRange [ 0 ] ;
@@ -48,31 +66,24 @@ function vtkPoints(publicAPI, model) {
48
66
const zRange = publicAPI . getRange ( 2 ) ;
49
67
model . bounds [ 4 ] = zRange [ 0 ] ;
50
68
model . bounds [ 5 ] = zRange [ 1 ] ;
51
- return model . bounds ;
52
- }
53
-
54
- if ( publicAPI . getNumberOfComponents ( ) !== 2 ) {
69
+ } else if ( publicAPI . getNumberOfComponents ( ) === 2 ) {
70
+ const xRange = publicAPI . getRange ( 0 ) ;
71
+ model . bounds [ 0 ] = xRange [ 0 ] ;
72
+ model . bounds [ 1 ] = xRange [ 1 ] ;
73
+ const yRange = publicAPI . getRange ( 1 ) ;
74
+ model . bounds [ 2 ] = yRange [ 0 ] ;
75
+ model . bounds [ 3 ] = yRange [ 1 ] ;
76
+ model . bounds [ 4 ] = 0 ;
77
+ model . bounds [ 5 ] = 0 ;
78
+ } else {
55
79
vtkErrorMacro (
56
80
`getBounds called on an array with components of ${ publicAPI . getNumberOfComponents ( ) } `
57
81
) ;
58
- return INVALID_BOUNDS ;
82
+ vtkMath . uninitializeBounds ( model . bounds ) ;
59
83
}
60
-
61
- const xRange = publicAPI . getRange ( 0 ) ;
62
- model . bounds [ 0 ] = xRange [ 0 ] ;
63
- model . bounds [ 1 ] = xRange [ 1 ] ;
64
- const yRange = publicAPI . getRange ( 1 ) ;
65
- model . bounds [ 2 ] = yRange [ 0 ] ;
66
- model . bounds [ 3 ] = yRange [ 1 ] ;
67
- model . bounds [ 4 ] = 0 ;
68
- model . bounds [ 5 ] = 0 ;
69
-
70
- return model . bounds ;
84
+ boundMTime = macro . getCurrentGlobalMTime ( ) ;
71
85
} ;
72
86
73
- // Trigger the computation of bounds
74
- publicAPI . computeBounds = publicAPI . getBounds ;
75
-
76
87
// Initialize
77
88
publicAPI . setNumberOfComponents (
78
89
model . numberOfComponents < 2 ? 3 : model . numberOfComponents
@@ -96,6 +107,8 @@ export function extend(publicAPI, model, initialValues = {}) {
96
107
Object . assign ( model , DEFAULT_VALUES , initialValues ) ;
97
108
98
109
vtkDataArray . extend ( publicAPI , model , initialValues ) ;
110
+
111
+ macro . getArray ( publicAPI , model , [ 'bounds' ] , 6 ) ;
99
112
vtkPoints ( publicAPI , model ) ;
100
113
}
101
114
0 commit comments