@kitware/vtk.js 34.11.1 → 34.11.3

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.
@@ -234,14 +234,14 @@ function oppositeSign(a, b) {
234
234
  return a <= 0 && b >= 0 || a >= 0 && b <= 0;
235
235
  }
236
236
  function getCorners(bounds, corners) {
237
- let count = 0;
238
- for (let ix = 0; ix < 2; ix++) {
239
- for (let iy = 2; iy < 4; iy++) {
240
- for (let iz = 4; iz < 6; iz++) {
241
- corners[count++] = [bounds[ix], bounds[iy], bounds[iz]];
242
- }
243
- }
244
- }
237
+ corners[0] = [bounds[0], bounds[2], bounds[4]];
238
+ corners[1] = [bounds[0], bounds[2], bounds[5]];
239
+ corners[2] = [bounds[0], bounds[3], bounds[4]];
240
+ corners[3] = [bounds[0], bounds[3], bounds[5]];
241
+ corners[4] = [bounds[1], bounds[2], bounds[4]];
242
+ corners[5] = [bounds[1], bounds[2], bounds[5]];
243
+ corners[6] = [bounds[1], bounds[3], bounds[4]];
244
+ corners[7] = [bounds[1], bounds[3], bounds[5]];
245
245
  return corners;
246
246
  }
247
247
 
@@ -9,6 +9,7 @@ export interface IImageDataInitialValues extends IDataSetInitialValues {
9
9
  spacing?: number[];
10
10
  origin?: number[];
11
11
  extent?: number[];
12
+ direction?: number[];
12
13
  }
13
14
 
14
15
  interface IComputeHistogram {
@@ -193,7 +193,9 @@ function vtkImageData(publicAPI, model) {
193
193
  };
194
194
 
195
195
  // Make sure the transform is correct
196
- publicAPI.onModified(publicAPI.computeTransforms);
196
+ model._onOriginChanged = publicAPI.computeTransforms;
197
+ model._onDirectionChanged = publicAPI.computeTransforms;
198
+ model._onSpacingChanged = publicAPI.computeTransforms;
197
199
  publicAPI.computeTransforms();
198
200
  publicAPI.getCenter = () => vtkBoundingBox.getCenter(publicAPI.getBounds());
199
201
  publicAPI.computeHistogram = function (worldBounds) {
@@ -1,20 +1,18 @@
1
1
  import { m as macro } from '../../macros2.js';
2
- import { l as normalize, e as distance2BetweenPoints } from '../../Common/Core/Math/index.js';
2
+ import { l as normalize, E as areEquals, e as distance2BetweenPoints } from '../../Common/Core/Math/index.js';
3
3
  import vtkMatrixBuilder from '../../Common/Core/MatrixBuilder.js';
4
+ import vtkBoundingBox from '../../Common/DataModel/BoundingBox.js';
4
5
  import vtkInteractorStyleManipulator from './InteractorStyleManipulator.js';
5
6
  import vtkMouseCameraTrackballRotateManipulator from '../Manipulators/MouseCameraTrackballRotateManipulator.js';
6
7
  import vtkMouseCameraTrackballPanManipulator from '../Manipulators/MouseCameraTrackballPanManipulator.js';
7
8
  import vtkMouseCameraTrackballZoomManipulator from '../Manipulators/MouseCameraTrackballZoomManipulator.js';
8
9
  import vtkMouseRangeManipulator from '../Manipulators/MouseRangeManipulator.js';
10
+ import { mat4 } from 'gl-matrix';
9
11
 
10
12
  // ----------------------------------------------------------------------------
11
13
  // Global methods
12
14
  // ----------------------------------------------------------------------------
13
15
 
14
- function boundsToCorners(bounds) {
15
- return [[bounds[0], bounds[2], bounds[4]], [bounds[0], bounds[2], bounds[5]], [bounds[0], bounds[3], bounds[4]], [bounds[0], bounds[3], bounds[5]], [bounds[1], bounds[2], bounds[4]], [bounds[1], bounds[2], bounds[5]], [bounds[1], bounds[3], bounds[4]], [bounds[1], bounds[3], bounds[5]]];
16
- }
17
-
18
16
  // ----------------------------------------------------------------------------
19
17
 
20
18
  function clamp(value, min, max) {
@@ -120,9 +118,8 @@ function vtkInteractorStyleMPRSlice(publicAPI, model) {
120
118
  const camera = renderer.getActiveCamera();
121
119
  if (model.volumeMapper) {
122
120
  const range = publicAPI.getSliceRange();
123
- const bounds = model.volumeMapper.getBounds();
124
121
  const clampedSlice = clamp(slice, ...range);
125
- const center = [(bounds[0] + bounds[1]) / 2.0, (bounds[2] + bounds[3]) / 2.0, (bounds[4] + bounds[5]) / 2.0];
122
+ const center = model.volumeMapper.getCenter();
126
123
  const distance = camera.getDistance();
127
124
  const dop = camera.getDirectionOfProjection();
128
125
  normalize(dop);
@@ -137,28 +134,23 @@ function vtkInteractorStyleMPRSlice(publicAPI, model) {
137
134
  publicAPI.getSliceRange = () => {
138
135
  if (model.volumeMapper) {
139
136
  const sliceNormal = publicAPI.getSliceNormal();
140
- if (sliceNormal[0] === cache.sliceNormal[0] && sliceNormal[1] === cache.sliceNormal[1] && sliceNormal[2] === cache.sliceNormal[2]) {
137
+ if (areEquals(sliceNormal, cache.sliceNormal)) {
141
138
  return cache.sliceRange;
142
139
  }
143
- const bounds = model.volumeMapper.getBounds();
144
- const points = boundsToCorners(bounds);
145
140
 
146
141
  // Get rotation matrix from normal to +X (since bounds is aligned to XYZ)
147
- const transform = vtkMatrixBuilder.buildFromDegree().identity().rotateFromDirections(sliceNormal, [1, 0, 0]);
148
- points.forEach(pt => transform.apply(pt));
142
+ const sliceOrientation = vtkMatrixBuilder.buildFromDegree().identity().rotateFromDirections(sliceNormal, [1, 0, 0]);
143
+ const imageAlongSliceNormal = mat4.create();
144
+ mat4.multiply(imageAlongSliceNormal, sliceOrientation.getMatrix(), model.volumeMapper.getInputData().getIndexToWorld());
145
+
146
+ // Transform the 8 corners of the input data's bounding box
147
+ // to rotate into the slice plane space without the intermediate
148
+ // axis-aligned box (provided by getBounds) which would grow the bounds.
149
+ const transformedBounds = vtkBoundingBox.transformBounds(model.volumeMapper.getInputData().getSpatialExtent(), imageAlongSliceNormal);
149
150
 
150
151
  // range is now maximum X distance
151
- let minX = Infinity;
152
- let maxX = -Infinity;
153
- for (let i = 0; i < 8; i++) {
154
- const x = points[i][0];
155
- if (x > maxX) {
156
- maxX = x;
157
- }
158
- if (x < minX) {
159
- minX = x;
160
- }
161
- }
152
+ const minX = transformedBounds[0];
153
+ const maxX = transformedBounds[1];
162
154
  cache.sliceNormal = sliceNormal;
163
155
  cache.sliceRange = [minX, maxX];
164
156
  return cache.sliceRange;
@@ -186,6 +186,12 @@ function vtkProp3D(publicAPI, model) {
186
186
  }
187
187
  return model.properties[mapperInputPort];
188
188
  };
189
+ publicAPI.getProperties = () => {
190
+ if (model.properties.length === 0) {
191
+ model.properties[0] = publicAPI.makeProperty?.();
192
+ }
193
+ return model.properties;
194
+ };
189
195
  publicAPI.setProperty = (firstArg, secondArg) => {
190
196
  // Two options for argument layout:
191
197
  // - (mapperInputPort, property)
@@ -63,14 +63,19 @@ export interface vtkViewport extends vtkObject {
63
63
  getSize(): Size;
64
64
 
65
65
  /**
66
- *
66
+ * Viewport for the Viewport to draw in the rendering window.
67
+ * Coordinates are expressed as (xmin,ymin,xmax,ymax), where each
68
+ * coordinate is 0 <= coordinate <= 1.0.
69
+ * @returns {Number[]}
70
+ * @see getViewportByReference()
71
+ * @see setViewport()
67
72
  */
68
- getViewport(): vtkViewport;
73
+ getViewport(): [number, number, number, number];
69
74
 
70
75
  /**
71
76
  *
72
77
  */
73
- getViewportByReference(): vtkViewport;
78
+ getViewportByReference(): [number, number, number, number];
74
79
 
75
80
  /**
76
81
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kitware/vtk.js",
3
- "version": "34.11.1",
3
+ "version": "34.11.3",
4
4
  "description": "Visualization Toolkit for the Web",
5
5
  "keywords": [
6
6
  "3d",
@@ -123,7 +123,7 @@
123
123
  "typescript": "^5.8.3",
124
124
  "webpack": "5.97.1",
125
125
  "webpack-bundle-analyzer": "4.5.0",
126
- "webpack-cli": "4.9.2",
126
+ "webpack-cli": "5.1.4",
127
127
  "webpack-dashboard": "3.3.7",
128
128
  "webpack-dev-server": "^5.2.2",
129
129
  "webpack-merge": "5.8.0",