@kitware/vtk.js 34.18.0 → 35.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,8 @@
1
+ ## From 34.x to 35
2
+
3
+ - **vtkMapper**: mappers should overwrite `computeBounds()` instead of `getBounds` that now calls `computeBounds()` before returning a copy of the mapper bounds.
4
+
5
+
1
6
  ## From 33.x to 34
2
7
 
3
8
  - **vtkMapper**: many properties have moved to `vtkVolumeProperty`. The full list of changed methods is: `getAnisotropy`, `getComputeNormalFromOpacity`, `getFilterMode`, `getFilterModeAsString`, `getGlobalIlluminationReach`, `getIpScalarRange`, `getIpScalarRangeByReference`, `getLAOKernelRadius`, `getLAOKernelSize`, `getLocalAmbientOcclusion`, `getPreferSizeOverAccuracy`, `getVolumetricScatteringBlending`, `setAnisotropy`, `setAverageIPScalarRange`, `setComputeNormalFromOpacity`, `setFilterMode`, `setFilterModeToNormalized`, `setFilterModeToOff`, `setFilterModeToRaw`, `setGlobalIlluminationReach`, `setIpScalarRange`, `setIpScalarRangeFrom`, `setLAOKernelRadius`, `setLAOKernelSize`, `setLocalAmbientOcclusion`, `setPreferSizeOverAccuracy`, `setVolumetricScatteringBlending`.
@@ -1,5 +1,5 @@
1
1
  import { mat4 } from 'gl-matrix';
2
- import { Bounds, Vector2, Vector3 } from './../../types';
2
+ import { Bounds, TypedArray, Vector2, Vector3 } from './../../types';
3
3
  import vtkPoints from './../Core/Points';
4
4
  import { Nullable } from './../../types';
5
5
 
@@ -394,11 +394,16 @@ declare class BoundingBox {
394
394
  /**
395
395
  * Adds points to a bounding box.
396
396
  * @param {Bounds} bounds
397
- * @param {number} x
397
+ * @param {number|Number[]|TypedArray} xOrPoint
398
398
  * @param {number} y
399
399
  * @param {number} z
400
400
  */
401
- addPoint(bounds: Bounds, x: number, y: number, z: number): Bounds;
401
+ addPoint(
402
+ bounds: Bounds,
403
+ xOrPoint: number | number[] | TypedArray,
404
+ y?: number,
405
+ z?: number
406
+ ): Bounds;
402
407
 
403
408
  /**
404
409
  * Adds points to a bounding box.
@@ -31,14 +31,23 @@ function setBounds(bounds, otherBounds) {
31
31
  function reset(bounds) {
32
32
  return setBounds(bounds, INIT_BOUNDS);
33
33
  }
34
- function addPoint(bounds, x, y, z) {
34
+ function addPoint(bounds, xOrPoint, y, z) {
35
35
  const [xMin, xMax, yMin, yMax, zMin, zMax] = bounds;
36
- bounds[0] = xMin < x ? xMin : x;
37
- bounds[1] = xMax > x ? xMax : x;
38
- bounds[2] = yMin < y ? yMin : y;
39
- bounds[3] = yMax > y ? yMax : y;
40
- bounds[4] = zMin < z ? zMin : z;
41
- bounds[5] = zMax > z ? zMax : z;
36
+ if (typeof xOrPoint === 'number') {
37
+ bounds[0] = xMin < xOrPoint ? xMin : xOrPoint;
38
+ bounds[1] = xMax > xOrPoint ? xMax : xOrPoint;
39
+ bounds[2] = yMin < y ? yMin : y;
40
+ bounds[3] = yMax > y ? yMax : y;
41
+ bounds[4] = zMin < z ? zMin : z;
42
+ bounds[5] = zMax > z ? zMax : z;
43
+ } else {
44
+ bounds[0] = xMin < xOrPoint[0] ? xMin : xOrPoint[0];
45
+ bounds[1] = xMax > xOrPoint[0] ? xMax : xOrPoint[0];
46
+ bounds[2] = yMin < xOrPoint[1] ? yMin : xOrPoint[1];
47
+ bounds[3] = yMax > xOrPoint[1] ? yMax : xOrPoint[1];
48
+ bounds[4] = zMin < xOrPoint[2] ? zMin : xOrPoint[2];
49
+ bounds[5] = zMax > xOrPoint[2] ? zMax : xOrPoint[2];
50
+ }
42
51
  return bounds;
43
52
  }
44
53
  function addPoints(bounds, points) {
@@ -117,7 +117,7 @@ function vtkBox(publicAPI, model) {
117
117
  }
118
118
  vtkBoundingBox.setBounds(model.bbox, boundsArray);
119
119
  };
120
- publicAPI.getBounds = () => model.bbox;
120
+ publicAPI.getBounds = () => [...model.bbox];
121
121
  publicAPI.evaluateFunction = (x, y, z) => {
122
122
  const point = Array.isArray(x) ? x : [x, y, z];
123
123
  let diff;
@@ -22,9 +22,9 @@ function vtkPointSet(publicAPI, model) {
22
22
  model.points = vtk(model.points);
23
23
  }
24
24
  publicAPI.getNumberOfPoints = () => model.points.getNumberOfPoints();
25
- publicAPI.getBounds = () => model.points.getBounds();
25
+ publicAPI.getBounds = () => model.points?.getBounds();
26
26
  publicAPI.computeBounds = () => {
27
- publicAPI.getBounds();
27
+ model.points?.computeBounds();
28
28
  };
29
29
  const superShallowCopy = publicAPI.shallowCopy;
30
30
  publicAPI.shallowCopy = (other, debug = false) => {
@@ -321,7 +321,11 @@ function vtkViewProxy(publicAPI, model) {
321
321
 
322
322
  // --------------------------------------------------------------------------
323
323
 
324
- publicAPI.setBackground = chain(model.renderer.setBackground, updateAnnotationColor);
324
+ publicAPI.setBackground = (...args) => {
325
+ const res = model.renderer.setBackground(...args);
326
+ updateAnnotationColor();
327
+ return res;
328
+ };
325
329
 
326
330
  // --------------------------------------------------------------------------
327
331
 
@@ -15,11 +15,30 @@ export interface IAbstractMapper3DInitialValues
15
15
  export interface vtkAbstractMapper3D extends vtkAbstractMapper {
16
16
  /**
17
17
  * Get the bounds for this mapper as [xmin, xmax, ymin, ymax,zmin, zmax].
18
- * @default 0
19
- * @return {Bounds} The bounds for the mapper.
18
+ * Bounds are (re)computed if needed.
19
+ * @return {Bounds} A copy of the bounds for the mapper.
20
+ * @see getBoundsByReference
21
+ * @see computeBounds
20
22
  */
21
23
  getBounds(): Bounds;
22
24
 
25
+ /**
26
+ * Get the bounds for this mapper as [xmin, xmax, ymin, ymax,zmin, zmax].
27
+ * Bounds are (re)computed if needed.
28
+ * @return {Bounds} The bounds array of the mapper.
29
+ * @see getBounds
30
+ * @see computeBounds
31
+ */
32
+ getBoundsByReference(): Bounds;
33
+
34
+ /**
35
+ * Compute the bounds for this mapper.
36
+ * Must be implemented by sub-classes. Called by getBounds methods.
37
+ * @see getBoundsByReference
38
+ * @see getBounds
39
+ */
40
+ computeBounds(): void;
41
+
23
42
  /**
24
43
  * Get the center of this mapper’s data.
25
44
  * @return {Vector3} The center of the mapper's data.
@@ -1,24 +1,32 @@
1
1
  import { m as macro } from '../../macros2.js';
2
2
  import vtkAbstractMapper from './AbstractMapper.js';
3
3
  import vtkBoundingBox from '../../Common/DataModel/BoundingBox.js';
4
- import { I as createUninitializedBounds } from '../../Common/Core/Math/index.js';
5
4
 
6
5
  // ----------------------------------------------------------------------------
7
6
  // vtkAbstractMapper methods
8
7
  // ----------------------------------------------------------------------------
9
8
 
10
9
  function vtkAbstractMapper3D(publicAPI, model) {
10
+ publicAPI.computeBounds = () => {
11
+ macro.vtkErrorMacro(`vtkAbstractMapper3D.computeBounds - NOT IMPLEMENTED`);
12
+ };
13
+ const superGetBounds = publicAPI.getBounds;
11
14
  publicAPI.getBounds = () => {
12
- macro.vtkErrorMacro(`vtkAbstractMapper3D.getBounds - NOT IMPLEMENTED`);
13
- return createUninitializedBounds();
15
+ publicAPI.computeBounds();
16
+ return superGetBounds();
17
+ };
18
+ const superGetBoundsByReference = publicAPI.getBoundsByReference;
19
+ publicAPI.getBoundsByReference = () => {
20
+ publicAPI.computeBounds();
21
+ return superGetBoundsByReference();
14
22
  };
15
23
  publicAPI.getCenter = () => {
16
- const bounds = publicAPI.getBounds();
24
+ const bounds = publicAPI.getBoundsByReference();
17
25
  model.center = vtkBoundingBox.isValid(bounds) ? vtkBoundingBox.getCenter(bounds) : null;
18
26
  return model.center?.slice();
19
27
  };
20
28
  publicAPI.getLength = () => {
21
- const bounds = publicAPI.getBounds();
29
+ const bounds = publicAPI.getBoundsByReference();
22
30
  return vtkBoundingBox.getDiagonalLength(bounds);
23
31
  };
24
32
  }
@@ -41,6 +49,7 @@ function extend(publicAPI, model, initialValues = {}) {
41
49
  // Inheritance
42
50
  vtkAbstractMapper.extend(publicAPI, model, initialValues);
43
51
  macro.setGet(publicAPI, model, ['viewSpecificProperties']);
52
+ macro.getArray(publicAPI, model, ['bounds'], 6);
44
53
  vtkAbstractMapper3D(publicAPI, model);
45
54
  }
46
55
 
@@ -665,16 +665,19 @@ function vtkCubeAxesActor(publicAPI, model) {
665
665
  // as it relies on the pixel size of the window. Every time the camera
666
666
  // changes the bounds change. This method simplifies by just expanding
667
667
  // the grid bounds by a user specified factor.
668
- publicAPI.getBounds = () => {
668
+ publicAPI.computeBounds = () => {
669
669
  publicAPI.update();
670
670
  vtkBoundingBox.setBounds(model.bounds, model.gridActor.getBounds());
671
671
  vtkBoundingBox.scaleAboutCenter(model.bounds, model.boundsScaleFactor, model.boundsScaleFactor, model.boundsScaleFactor);
672
- return model.bounds;
673
672
  };
674
673
 
675
674
  // Make sure the grid share the actor property
676
- const _setProp = macro.chain(publicAPI.setProperty, model.gridActor.setProperty);
677
- publicAPI.setProperty = p => _setProp(p)[0];
675
+ const superSetProp = publicAPI.setProperty;
676
+ publicAPI.setProperty = p => {
677
+ const res = superSetProp(p);
678
+ model.gridActor.setProperty(p);
679
+ return res;
680
+ };
678
681
  }
679
682
 
680
683
  // ----------------------------------------------------------------------------
@@ -2,7 +2,7 @@ import { mat4, vec3, mat3 } from 'gl-matrix';
2
2
  import Constants from './Glyph3DMapper/Constants.js';
3
3
  import { m as macro } from '../../macros2.js';
4
4
  import vtkMapper from './Mapper.js';
5
- import { I as createUninitializedBounds, n as norm } from '../../Common/Core/Math/index.js';
5
+ import { n as norm } from '../../Common/Core/Math/index.js';
6
6
  import vtkBoundingBox from '../../Common/DataModel/BoundingBox.js';
7
7
 
8
8
  const {
@@ -60,21 +60,15 @@ function vtkGlyph3DMapper(publicAPI, model) {
60
60
  }
61
61
  return idata.getPointData().getArray(model.scaleArray);
62
62
  };
63
- publicAPI.getBounds = () => {
64
- const idata = publicAPI.getInputData(0);
65
- const gdata = publicAPI.getInputData(1);
66
- if (!idata || !gdata) {
67
- return createUninitializedBounds();
68
- }
69
-
70
- // first we build the arrays used for the glyphing
71
- publicAPI.buildArrays();
72
- return model.bounds;
73
- };
63
+ publicAPI.computeBounds = () => publicAPI.buildArrays();
74
64
  publicAPI.buildArrays = () => {
75
65
  // if the mtgime requires it, rebuild
76
66
  const idata = publicAPI.getInputData(0);
77
67
  const gdata = publicAPI.getInputData(1);
68
+ if (!idata || !gdata) {
69
+ vtkBoundingBox.reset(model.bounds);
70
+ return;
71
+ }
78
72
  if (model.buildTime.getMTime() < gdata.getMTime() || model.buildTime.getMTime() < idata.getMTime() || model.buildTime.getMTime() < publicAPI.getMTime()) {
79
73
  const pts = idata.getPoints().getData();
80
74
  let sArray = publicAPI.getScaleArrayData();
@@ -95,12 +89,7 @@ function vtkGlyph3DMapper(publicAPI, model) {
95
89
  // overall bounds while building the arrays
96
90
  const corners = [];
97
91
  vtkBoundingBox.getCorners(gbounds, corners);
98
- model.bounds[0] = vtkBoundingBox.INIT_BOUNDS[0];
99
- model.bounds[1] = vtkBoundingBox.INIT_BOUNDS[1];
100
- model.bounds[2] = vtkBoundingBox.INIT_BOUNDS[2];
101
- model.bounds[3] = vtkBoundingBox.INIT_BOUNDS[3];
102
- model.bounds[4] = vtkBoundingBox.INIT_BOUNDS[4];
103
- model.bounds[5] = vtkBoundingBox.INIT_BOUNDS[5];
92
+ vtkBoundingBox.reset(model.bounds);
104
93
  const tcorner = new Float64Array(3);
105
94
  const oArray = publicAPI.getOrientationArrayData();
106
95
  const identity = mat4.identity(new Float64Array(16));
@@ -193,24 +182,7 @@ function vtkGlyph3DMapper(publicAPI, model) {
193
182
  // update bounds
194
183
  for (let p = 0; p < 8; ++p) {
195
184
  vec3.transformMat4(tcorner, corners[p], z);
196
- if (tcorner[0] < model.bounds[0]) {
197
- model.bounds[0] = tcorner[0];
198
- }
199
- if (tcorner[1] < model.bounds[2]) {
200
- model.bounds[2] = tcorner[1];
201
- }
202
- if (tcorner[2] < model.bounds[4]) {
203
- model.bounds[4] = tcorner[2];
204
- }
205
- if (tcorner[0] > model.bounds[1]) {
206
- model.bounds[1] = tcorner[0];
207
- }
208
- if (tcorner[1] > model.bounds[3]) {
209
- model.bounds[3] = tcorner[1];
210
- }
211
- if (tcorner[2] > model.bounds[5]) {
212
- model.bounds[5] = tcorner[2];
213
- }
185
+ vtkBoundingBox.addPoint(model.bounds, tcorner);
214
186
  }
215
187
  const n = new Float32Array(nbuff, i * 36, 9);
216
188
  mat3.fromMat4(n, z);
@@ -276,10 +248,6 @@ function extend(publicAPI, model, initialValues = {}) {
276
248
  macro.obj(model.buildTime, {
277
249
  mtime: 0
278
250
  });
279
- model.boundsTime = {};
280
- macro.obj(model.boundsTime, {
281
- mtime: 0
282
- });
283
251
  macro.setGet(publicAPI, model, ['orient', 'orientationMode', 'orientationArray', 'scaleArray', 'scaleFactor', 'scaleMode', 'scaling']);
284
252
  macro.get(publicAPI, model, ['colorArray', 'matrixArray', 'normalArray', 'buildTime']);
285
253
 
@@ -1,5 +1,6 @@
1
1
  import { m as macro } from '../../macros2.js';
2
2
  import vtkAbstractImageMapper from './AbstractImageMapper.js';
3
+ import vtkBoundingBox from '../../Common/DataModel/BoundingBox.js';
3
4
  import vtkImageMapper from './ImageMapper.js';
4
5
  import { I as createUninitializedBounds } from '../../Common/Core/Math/index.js';
5
6
  import { intersectWithLineForPointPicking, intersectWithLineForCellPicking } from './AbstractImageMapper/helper.js';
@@ -80,13 +81,17 @@ function vtkImageArrayMapper(publicAPI, model) {
80
81
  }
81
82
  return null;
82
83
  };
83
- publicAPI.getBounds = () => {
84
+
85
+ // reimplemented from AbstractMapper3D
86
+ publicAPI.computeBounds = () => {
84
87
  const image = publicAPI.getCurrentImage();
85
88
  if (!image) {
86
- return createUninitializedBounds();
89
+ vtkBoundingBox.reset(model.bounds);
90
+ return;
87
91
  }
88
92
  if (!model.useCustomExtents) {
89
- return image.getBounds();
93
+ vtkBoundingBox.setBounds(model.bounds, image.getBounds());
94
+ return;
90
95
  }
91
96
  const ex = model.customDisplayExtent.slice();
92
97
  // use sub-slice of the current image,
@@ -94,7 +99,7 @@ function vtkImageArrayMapper(publicAPI, model) {
94
99
  const nSlice = publicAPI.getSubSlice();
95
100
  ex[4] = nSlice;
96
101
  ex[5] = nSlice;
97
- return image.extentToBounds(ex);
102
+ vtkBoundingBox.setBounds(model.bounds, image.extentToBounds(ex));
98
103
  };
99
104
  publicAPI.getBoundsForSlice = (slice = publicAPI.getSlice(), halfThickness = 0) => {
100
105
  const image = publicAPI.getImage(slice);
@@ -1,4 +1,5 @@
1
1
  import { quat, vec3, mat4 } from 'gl-matrix';
2
+ import vtkBoundingBox from '../../Common/DataModel/BoundingBox.js';
2
3
  import CoincidentTopologyHelper from './Mapper/CoincidentTopologyHelper.js';
3
4
  import vtkAbstractImageMapper from './AbstractImageMapper.js';
4
5
  import { m as macro } from '../../macros2.js';
@@ -26,12 +27,12 @@ function vtkImageCPRMapper(publicAPI, model) {
26
27
  };
27
28
 
28
29
  /**
29
- * Public methods
30
+ * Reimplemented from AbstractMapper3D
30
31
  */
31
- publicAPI.getBounds = () => {
32
+ publicAPI.computeBounds = () => {
32
33
  const imageWidth = publicAPI.getWidth();
33
34
  const imageHeight = publicAPI.getHeight();
34
- return [0, imageWidth, 0, imageHeight, 0, 0];
35
+ vtkBoundingBox.setBounds(model.bounds, [0, imageWidth, 0, imageHeight, 0, 0]);
35
36
  };
36
37
  publicAPI.getOrientationDataArray = () => {
37
38
  const pointData = publicAPI.getInputData(1)?.getPointData();
@@ -1,6 +1,7 @@
1
1
  import Constants from './ImageMapper/Constants.js';
2
2
  import { m as macro } from '../../macros2.js';
3
3
  import vtkAbstractImageMapper from './AbstractImageMapper.js';
4
+ import vtkBoundingBox from '../../Common/DataModel/BoundingBox.js';
4
5
  import { intersectWithLineForPointPicking, intersectWithLineForCellPicking } from './AbstractImageMapper/helper.js';
5
6
  import { F as clampValue, U as multiply3x3_vect3, I as createUninitializedBounds, V as getSparseOrthogonalMatrix } from '../../Common/Core/Math/index.js';
6
7
  import CoincidentTopologyHelper from './Mapper/CoincidentTopologyHelper.js';
@@ -186,13 +187,15 @@ function vtkImageMapper(publicAPI, model) {
186
187
  }
187
188
  return model.closestIJKAxis;
188
189
  };
189
- publicAPI.getBounds = () => {
190
+ publicAPI.computeBounds = () => {
190
191
  const image = publicAPI.getCurrentImage();
191
192
  if (!image) {
192
- return createUninitializedBounds();
193
+ vtkBoundingBox.reset(model.bounds);
194
+ return;
193
195
  }
194
196
  if (!model.useCustomExtents) {
195
- return image.getBounds();
197
+ vtkBoundingBox.setBounds(model.bounds, image.getBounds());
198
+ return;
196
199
  }
197
200
  const ex = model.customDisplayExtent.slice();
198
201
  const {
@@ -217,7 +220,7 @@ function vtkImageMapper(publicAPI, model) {
217
220
  ex[5] = nSlice;
218
221
  break;
219
222
  }
220
- return image.extentToBounds(ex);
223
+ vtkBoundingBox.setBounds(model.bounds, image.extentToBounds(ex));
221
224
  };
222
225
  publicAPI.getBoundsForSlice = (slice = model.slice, halfThickness = 0) => {
223
226
  const image = publicAPI.getCurrentImage();
@@ -19,18 +19,18 @@ const {
19
19
  function vtkImageResliceMapper(publicAPI, model) {
20
20
  // Set our className
21
21
  model.classHierarchy.push('vtkImageResliceMapper');
22
- publicAPI.getBounds = () => {
23
- let bds = [...vtkBoundingBox.INIT_BOUNDS];
22
+ publicAPI.computeBounds = () => {
24
23
  const image = publicAPI.getInputData();
25
24
  if (publicAPI.getSlicePolyData()) {
26
- bds = publicAPI.getSlicePolyData().getBounds();
25
+ vtkBoundingBox.setBounds(model.bounds, publicAPI.getSlicePolyData().getBounds());
27
26
  } else if (image) {
28
- bds = image.getBounds();
27
+ vtkBoundingBox.setBounds(model.bounds, image.getBounds());
29
28
  if (publicAPI.getSlicePlane()) {
30
- vtkBoundingBox.cutWithPlane(bds, publicAPI.getSlicePlane().getOrigin(), publicAPI.getSlicePlane().getNormal());
29
+ vtkBoundingBox.cutWithPlane(model.bounds, publicAPI.getSlicePlane().getOrigin(), publicAPI.getSlicePlane().getNormal());
31
30
  }
31
+ } else {
32
+ vtkBoundingBox.reset(model.bounds);
32
33
  }
33
- return bds;
34
34
  };
35
35
  }
36
36
 
@@ -55,22 +55,22 @@ function vtkImageSlice(publicAPI, model) {
55
55
 
56
56
  //----------------------------------------------------------------------------
57
57
  // Get the minimum X bound
58
- publicAPI.getMinXBound = () => publicAPI.getBounds()[0];
58
+ publicAPI.getMinXBound = () => publicAPI.getBoundsByReference()[0];
59
59
 
60
60
  // Get the maximum X bound
61
- publicAPI.getMaxXBound = () => publicAPI.getBounds()[1];
61
+ publicAPI.getMaxXBound = () => publicAPI.getBoundsByReference()[1];
62
62
 
63
63
  // Get the minimum Y bound
64
- publicAPI.getMinYBound = () => publicAPI.getBounds()[2];
64
+ publicAPI.getMinYBound = () => publicAPI.getBoundsByReference()[2];
65
65
 
66
66
  // Get the maximum Y bound
67
- publicAPI.getMaxYBound = () => publicAPI.getBounds()[3];
67
+ publicAPI.getMaxYBound = () => publicAPI.getBoundsByReference()[3];
68
68
 
69
69
  // Get the minimum Z bound
70
- publicAPI.getMinZBound = () => publicAPI.getBounds()[4];
70
+ publicAPI.getMinZBound = () => publicAPI.getBoundsByReference()[4];
71
71
 
72
72
  // Get the maximum Z bound
73
- publicAPI.getMaxZBound = () => publicAPI.getBounds()[5];
73
+ publicAPI.getMaxZBound = () => publicAPI.getBoundsByReference()[5];
74
74
  publicAPI.getRedrawMTime = () => {
75
75
  let mt = model.mtime;
76
76
  if (model.mapper !== null) {
@@ -1,9 +1,10 @@
1
1
  import { m as macro } from '../../macros2.js';
2
2
  import vtkAbstractMapper3D from './AbstractMapper3D.js';
3
+ import vtkBoundingBox from '../../Common/DataModel/BoundingBox.js';
3
4
  import vtkDataArray from '../../Common/Core/DataArray.js';
4
5
  import vtkImageData from '../../Common/DataModel/ImageData.js';
5
6
  import vtkLookupTable from '../../Common/Core/LookupTable.js';
6
- import { I as createUninitializedBounds, i as isNan } from '../../Common/Core/Math/index.js';
7
+ import { i as isNan } from '../../Common/Core/Math/index.js';
7
8
  import vtkScalarsToColors from '../../Common/Core/ScalarsToColors/Constants.js';
8
9
  import CoincidentTopologyHelper from './Mapper/CoincidentTopologyHelper.js';
9
10
  import Constants from './Mapper/Constants.js';
@@ -268,17 +269,16 @@ function getOrCreateColorTextureCoordinates(input, component, range, useLogScale
268
269
  function vtkMapper(publicAPI, model) {
269
270
  // Set our className
270
271
  model.classHierarchy.push('vtkMapper');
271
- publicAPI.getBounds = () => {
272
+ publicAPI.computeBounds = () => {
272
273
  const input = publicAPI.getInputData();
273
274
  if (!input) {
274
- model.bounds = createUninitializedBounds();
275
+ vtkBoundingBox.reset(model.bounds);
275
276
  } else {
276
277
  if (!model.static) {
277
278
  publicAPI.update();
278
279
  }
279
- model.bounds = input.getBounds();
280
+ vtkBoundingBox.setBounds(model.bounds, input.getBounds());
280
281
  }
281
- return model.bounds;
282
282
  };
283
283
  publicAPI.setForceCompileOnly = v => {
284
284
  model.forceCompileOnly = v;
@@ -128,24 +128,20 @@ function vtkProp3D(publicAPI, model) {
128
128
  model.matrixMTime.modified();
129
129
  }
130
130
  };
131
- publicAPI.getBoundsByReference = () => {
131
+ publicAPI.computeBounds = () => {
132
132
  if (model.mapper === null) {
133
- return model.bounds;
133
+ vtkBoundingBox.reset(model.bounds);
134
+ return;
134
135
  }
135
136
 
136
- // Check for the special case when the mapper's bounds are unknown
137
+ // Check for the special case when the mapper's bounds are invalid
137
138
  const bds = model.mapper.getBounds();
138
- if (!bds || bds.length !== 6) {
139
- return bds;
140
- }
141
-
142
- // Check for the special case when the actor is empty.
143
- if (bds[0] > bds[1]) {
139
+ if (!bds || bds.length !== 6 || !vtkBoundingBox.isValid(bds)) {
144
140
  // No need to copy bds, a new array is created when calling getBounds()
145
141
  model.mapperBounds = bds;
146
- model.bounds = [...vtkBoundingBox.INIT_BOUNDS];
142
+ vtkBoundingBox.reset(model.bounds);
147
143
  model.boundsMTime.modified();
148
- return bds;
144
+ return;
149
145
  }
150
146
 
151
147
  // Check if we have cached values for these bounds - we cache the
@@ -165,22 +161,22 @@ function vtkProp3D(publicAPI, model) {
165
161
  vtkBoundingBox.transformBounds(bds, transposedMatrix, model.bounds);
166
162
  model.boundsMTime.modified();
167
163
  }
168
- return model.bounds;
169
164
  };
165
+ const superGetBounds = publicAPI.getBounds;
170
166
  publicAPI.getBounds = () => {
171
- const bounds = publicAPI.getBoundsByReference();
172
- // Handle case when bounds are not iterable (for example null or undefined)
173
- try {
174
- return [...bounds];
175
- } catch {
176
- return bounds;
177
- }
167
+ publicAPI.computeBounds();
168
+ return superGetBounds();
169
+ };
170
+ const superGetBoundsByReference = publicAPI.getBoundsByReference;
171
+ publicAPI.getBoundsByReference = () => {
172
+ publicAPI.computeBounds();
173
+ return superGetBoundsByReference();
178
174
  };
179
- publicAPI.getCenter = () => vtkBoundingBox.getCenter(model.bounds);
180
- publicAPI.getLength = () => vtkBoundingBox.getLength(model.bounds);
181
- publicAPI.getXRange = () => vtkBoundingBox.getXRange(model.bounds);
182
- publicAPI.getYRange = () => vtkBoundingBox.getYRange(model.bounds);
183
- publicAPI.getZRange = () => vtkBoundingBox.getZRange(model.bounds);
175
+ publicAPI.getCenter = () => vtkBoundingBox.getCenter(publicAPI.getBoundsByReference());
176
+ publicAPI.getLength = () => vtkBoundingBox.getLength(publicAPI.getBoundsByReference());
177
+ publicAPI.getXRange = () => vtkBoundingBox.getXRange(publicAPI.getBoundsByReference());
178
+ publicAPI.getYRange = () => vtkBoundingBox.getYRange(publicAPI.getBoundsByReference());
179
+ publicAPI.getZRange = () => vtkBoundingBox.getZRange(publicAPI.getBoundsByReference());
184
180
  publicAPI.getUserMatrix = () => model.userMatrix;
185
181
  function updateIdentityFlag() {
186
182
  publicAPI.computeMatrix();
@@ -227,12 +223,12 @@ function vtkProp3D(publicAPI, model) {
227
223
  // ----------------------------------------------------------------------------
228
224
 
229
225
  const DEFAULT_VALUES = {
226
+ bounds: [...vtkBoundingBox.INIT_BOUNDS],
230
227
  origin: [0, 0, 0],
231
228
  position: [0, 0, 0],
232
229
  orientation: [0, 0, 0],
233
230
  rotation: null,
234
231
  scale: [1, 1, 1],
235
- bounds: [...vtkBoundingBox.INIT_BOUNDS],
236
232
  properties: [],
237
233
  userMatrix: null,
238
234
  userMatrixMTime: null,
@@ -256,6 +252,7 @@ function extend(publicAPI, model, initialValues = {}) {
256
252
  macro.getArray(publicAPI, model, ['orientation']);
257
253
  macro.setGetArray(publicAPI, model, ['origin', 'position', 'scale'], 3);
258
254
  macro.setGet(publicAPI, model, ['properties']);
255
+ macro.getArray(publicAPI, model, ['bounds'], 6);
259
256
 
260
257
  // Object internal instance
261
258
  model.matrix = mat4.identity(new Float64Array(16));
@@ -40,12 +40,16 @@ function vtkVolumeMapper(publicAPI, model) {
40
40
  const superClass = {
41
41
  ...publicAPI
42
42
  };
43
- publicAPI.getBounds = () => {
43
+ publicAPI.computeBounds = () => {
44
+ const input = publicAPI.getInputData();
45
+ if (!input) {
46
+ vtkBoundingBox.reset(model.bounds);
47
+ return;
48
+ }
44
49
  if (!model.static) {
45
50
  publicAPI.update();
46
51
  }
47
- model.bounds = [...publicAPI.getInputData().getBounds()];
48
- return model.bounds;
52
+ vtkBoundingBox.setBounds(model.bounds, input.getBounds());
49
53
  };
50
54
  publicAPI.setBlendModeToComposite = () => {
51
55
  publicAPI.setBlendMode(BlendMode.COMPOSITE_BLEND);
@@ -137,7 +137,13 @@ function vtkArrowHandleRepresentation(publicAPI, model) {
137
137
 
138
138
  // --------------------------------------------------------------------------
139
139
 
140
- publicAPI.setGlyphResolution = macro.chain(publicAPI.setGlyphResolution, r => model._pipeline.glyph.setPhiResolution(r), r => model._pipeline.glyph.setThetaResolution(r));
140
+ const superSetGlyphResolution = publicAPI.setGlyphResolution;
141
+ publicAPI.setGlyphResolution = r => {
142
+ const res = superSetGlyphResolution(r);
143
+ model._pipeline.glyph.setPhiResolution(r);
144
+ model._pipeline.glyph.setThetaResolution(r);
145
+ return res;
146
+ };
141
147
 
142
148
  // --------------------------------------------------------------------------
143
149
 
@@ -12,6 +12,9 @@ import { Resolve } from '../../Rendering/Core/Mapper/Static.js';
12
12
  function vtkCircleContextRepresentation(publicAPI, model) {
13
13
  // Set our className
14
14
  model.classHierarchy.push('vtkCircleContextRepresentation');
15
+ const superClass = {
16
+ ...publicAPI
17
+ };
15
18
 
16
19
  // --------------------------------------------------------------------------
17
20
  // Generic rendering pipeline
@@ -23,15 +26,27 @@ function vtkCircleContextRepresentation(publicAPI, model) {
23
26
 
24
27
  // --------------------------------------------------------------------------
25
28
 
26
- publicAPI.setGlyphResolution = macro.chain(publicAPI.setGlyphResolution, model._pipeline.glyph.setResolution);
29
+ publicAPI.setGlyphResolution = r => {
30
+ const res = superClass.setGlyphResolution(r);
31
+ model._pipeline.glyph.setResolution(r);
32
+ return res;
33
+ };
27
34
 
28
35
  // --------------------------------------------------------------------------
29
36
 
30
- publicAPI.setDrawBorder = macro.chain(publicAPI.setDrawBorder, draw => model._pipeline.glyph.setLines(draw));
37
+ publicAPI.setDrawBorder = draw => {
38
+ const res = superClass.setDrawBorder(draw);
39
+ model._pipeline.glyph.setLines(draw);
40
+ return res;
41
+ };
31
42
 
32
43
  // --------------------------------------------------------------------------
33
44
 
34
- publicAPI.setDrawFace = macro.chain(publicAPI.setDrawFace, draw => model._pipeline.glyph.setFace(draw));
45
+ publicAPI.setDrawFace = draw => {
46
+ const res = superClass.setDrawFace(draw);
47
+ model._pipeline.glyph.setFace(draw);
48
+ return res;
49
+ };
35
50
 
36
51
  // --------------------------------------------------------------------------
37
52
 
@@ -112,11 +112,18 @@ function vtkSplineContextRepresentation(publicAPI, model) {
112
112
  model._pipelines.border.actor.getProperty().setColor(...(inPoints.length <= 3 || model._pipelines.area.filter.getErrorCount() === 0 ? model.borderColor : model.errorBorderColor));
113
113
  };
114
114
  publicAPI.getSelectedState = (prop, compositeID) => model.state;
115
- function updateAreaVisibility() {
116
- model._pipelines.area.actor.setVisibility(model.fill);
117
- }
118
- publicAPI.setFill = macro.chain(publicAPI.setFill, updateAreaVisibility);
119
- publicAPI.setOutputBorder = macro.chain(publicAPI.setOutputBorder, v => model._pipelines.border.actor.setVisibility(v));
115
+ const superSetFill = publicAPI.setFill;
116
+ publicAPI.setFill = fill => {
117
+ const res = superSetFill(fill);
118
+ model._pipelines.area.actor.setVisibility(fill);
119
+ return res;
120
+ };
121
+ const superSetOutputBorder = publicAPI.setOutputBorder;
122
+ publicAPI.setOutputBorder = v => {
123
+ const res = superSetOutputBorder(v);
124
+ model._pipelines.border.actor.setVisibility(v);
125
+ return res;
126
+ };
120
127
  }
121
128
 
122
129
  // ----------------------------------------------------------------------------
@@ -401,10 +401,13 @@ function vtkResliceCursorWidget(publicAPI, model) {
401
401
  res[viewType] = findRepresentationsForViewType(viewType)[0]?.getDisplayScaleParams?.();
402
402
  return res;
403
403
  }, {});
404
- publicAPI.setScaleInPixels = macro.chain(publicAPI.setScaleInPixels, scale => {
404
+ const superSetScaleInPixels = publicAPI.setScaleInPixels;
405
+ publicAPI.setScaleInPixels = scale => {
406
+ const res = superSetScaleInPixels(scale);
405
407
  publicAPI.getViewWidgets().forEach(w => w.setScaleInPixels(scale));
406
408
  updateState(model.widgetState, model.scaleInPixels, model.rotationHandlePosition);
407
- });
409
+ return res;
410
+ };
408
411
  publicAPI.getPlaneExtremities = viewType => {
409
412
  const dirProj = publicAPI.getWidgetState().getPlanes()[viewType].normal;
410
413
  const length = vtkBoundingBox.getDiagonalLength(publicAPI.getWidgetState().getImage().getBounds());
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kitware/vtk.js",
3
- "version": "34.18.0",
3
+ "version": "35.0.0",
4
4
  "description": "Visualization Toolkit for the Web",
5
5
  "keywords": [
6
6
  "3d",