11import macro from 'vtk.js/Sources/macros' ;
22import vtkDataArray from 'vtk.js/Sources/Common/Core/DataArray' ;
33import { VtkDataTypes } from 'vtk.js/Sources/Common/Core/DataArray/Constants' ;
4+ import * as vtkMath from 'vtk.js/Sources/Common/Core/Math' ;
45
56const { vtkErrorMacro } = macro ;
6-
7- const INVALID_BOUNDS = [ 1 , - 1 , 1 , - 1 , 1 , - 1 ] ;
8-
97// ----------------------------------------------------------------------------
108// vtkPoints methods
119// ----------------------------------------------------------------------------
1210
1311function vtkPoints ( publicAPI , model ) {
12+ // Keep track of modified time for bounds computation
13+ let boundMTime = 0 ;
14+
1415 // Set our className
1516 model . classHierarchy . push ( 'vtkPoints' ) ;
1617
@@ -37,7 +38,24 @@ function vtkPoints(publicAPI, model) {
3738
3839 publicAPI . insertPoint = ( ptId , point ) => publicAPI . insertTuple ( ptId , point ) ;
3940
41+ const superGetBounds = publicAPI . getBounds ;
4042 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 = ( ) => {
4159 if ( publicAPI . getNumberOfComponents ( ) === 3 ) {
4260 const xRange = publicAPI . getRange ( 0 ) ;
4361 model . bounds [ 0 ] = xRange [ 0 ] ;
@@ -48,31 +66,24 @@ function vtkPoints(publicAPI, model) {
4866 const zRange = publicAPI . getRange ( 2 ) ;
4967 model . bounds [ 4 ] = zRange [ 0 ] ;
5068 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 {
5579 vtkErrorMacro (
5680 `getBounds called on an array with components of ${ publicAPI . getNumberOfComponents ( ) } `
5781 ) ;
58- return INVALID_BOUNDS ;
82+ vtkMath . uninitializeBounds ( model . bounds ) ;
5983 }
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 ( ) ;
7185 } ;
7286
73- // Trigger the computation of bounds
74- publicAPI . computeBounds = publicAPI . getBounds ;
75-
7687 // Initialize
7788 publicAPI . setNumberOfComponents (
7889 model . numberOfComponents < 2 ? 3 : model . numberOfComponents
@@ -96,6 +107,8 @@ export function extend(publicAPI, model, initialValues = {}) {
96107 Object . assign ( model , DEFAULT_VALUES , initialValues ) ;
97108
98109 vtkDataArray . extend ( publicAPI , model , initialValues ) ;
110+
111+ macro . getArray ( publicAPI , model , [ 'bounds' ] , 6 ) ;
99112 vtkPoints ( publicAPI , model ) ;
100113}
101114
0 commit comments