@kitware/vtk.js 29.4.2 → 29.4.4

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.
@@ -440,8 +440,8 @@ function vtkCCSMakePolysFromLines(polyData, firstLine, endLine, oriented, newPol
440
440
  let ptsEnd = npts - 1;
441
441
  if (endIdx === 1) {
442
442
  pit = npts - 1 - (completePoly ? 1 : 0);
443
- ptsIt = pts + 1;
444
- ptsEnd = pts + npts - (completePoly ? 1 : 0);
443
+ ptsIt = 1;
444
+ ptsEnd = npts - (completePoly ? 1 : 0);
445
445
  }
446
446
  while (ptsIt !== ptsEnd) {
447
447
  poly[--pit] = poly[ptsIt++];
@@ -33,6 +33,35 @@ function vtkPicker(publicAPI, model) {
33
33
  model.globalTMin = Number.MAX_VALUE;
34
34
  }
35
35
 
36
+ /**
37
+ * Compute the tolerance in world coordinates.
38
+ * Do this by determining the world coordinates of the diagonal points of the
39
+ * window, computing the width of the window in world coordinates, and
40
+ * multiplying by the tolerance.
41
+ * @param {Number} selectionZ
42
+ * @param {Number} aspect
43
+ * @param {vtkRenderer} renderer
44
+ * @returns {Number} the computed tolerance
45
+ */
46
+ function computeTolerance(selectionZ, aspect, renderer) {
47
+ let tolerance = 0.0;
48
+ const view = renderer.getRenderWindow().getViews()[0];
49
+ const viewport = renderer.getViewport();
50
+ const winSize = view.getSize();
51
+ let x = winSize[0] * viewport[0];
52
+ let y = winSize[1] * viewport[1];
53
+ const normalizedLeftDisplay = view.displayToNormalizedDisplay(x, y, selectionZ);
54
+ const windowLowerLeft = renderer.normalizedDisplayToWorld(normalizedLeftDisplay[0], normalizedLeftDisplay[1], normalizedLeftDisplay[2], aspect);
55
+ x = winSize[0] * viewport[2];
56
+ y = winSize[1] * viewport[3];
57
+ const normalizedRightDisplay = view.displayToNormalizedDisplay(x, y, selectionZ);
58
+ const windowUpperRight = renderer.normalizedDisplayToWorld(normalizedRightDisplay[0], normalizedRightDisplay[1], normalizedRightDisplay[2], aspect);
59
+ for (let i = 0; i < 3; i++) {
60
+ tolerance += (windowUpperRight[i] - windowLowerLeft[i]) * (windowUpperRight[i] - windowLowerLeft[i]);
61
+ }
62
+ return Math.sqrt(tolerance);
63
+ }
64
+
36
65
  // Intersect data with specified ray.
37
66
  // Project the center point of the mapper onto the ray and determine its parametric value
38
67
  publicAPI.intersectWithLine = (p1, p2, tol, mapper) => {
@@ -73,13 +102,6 @@ function vtkPicker(publicAPI, model) {
73
102
  let tB;
74
103
  const p1World = [];
75
104
  const p2World = [];
76
- let viewport = [];
77
- let winSize = [];
78
- let x;
79
- let y;
80
- let windowLowerLeft = [];
81
- let windowUpperRight = [];
82
- let tol = 0.0;
83
105
  let props = [];
84
106
  let pickable = false;
85
107
  const p1Mapper = new Float64Array(4);
@@ -108,6 +130,7 @@ function vtkPicker(publicAPI, model) {
108
130
  displayCoords = renderer.worldToNormalizedDisplay(cameraFP[0], cameraFP[1], cameraFP[2], aspect);
109
131
  displayCoords = view.normalizedDisplayToDisplay(displayCoords[0], displayCoords[1], displayCoords[2]);
110
132
  selectionZ = displayCoords[2];
133
+ const tolerance = computeTolerance(selectionZ, aspect, renderer) * model.tolerance;
111
134
 
112
135
  // Convert the selection point into world coordinates.
113
136
  const normalizedDisplay = view.displayToNormalizedDisplay(selectionX, selectionY, selectionZ);
@@ -150,27 +173,6 @@ function vtkPicker(publicAPI, model) {
150
173
  }
151
174
  p1World[3] = 1.0;
152
175
  p2World[3] = 1.0;
153
-
154
- // Compute the tolerance in world coordinates. Do this by
155
- // determining the world coordinates of the diagonal points of the
156
- // window, computing the width of the window in world coordinates, and
157
- // multiplying by the tolerance.
158
- viewport = renderer.getViewport();
159
- if (renderer.getRenderWindow()) {
160
- winSize = renderer.getRenderWindow().getViews()[0].getSize();
161
- }
162
- x = winSize[0] * viewport[0];
163
- y = winSize[1] * viewport[1];
164
- const normalizedLeftDisplay = view.displayToNormalizedDisplay(x, y, selectionZ);
165
- windowLowerLeft = renderer.normalizedDisplayToWorld(normalizedLeftDisplay[0], normalizedLeftDisplay[1], normalizedLeftDisplay[2], aspect);
166
- x = winSize[0] * viewport[2];
167
- y = winSize[1] * viewport[3];
168
- const normalizedRightDisplay = view.displayToNormalizedDisplay(x, y, selectionZ);
169
- windowUpperRight = renderer.normalizedDisplayToWorld(normalizedRightDisplay[0], normalizedRightDisplay[1], normalizedRightDisplay[2], aspect);
170
- for (let i = 0; i < 3; i++) {
171
- tol += (windowUpperRight[i] - windowLowerLeft[i]) * (windowUpperRight[i] - windowLowerLeft[i]);
172
- }
173
- tol = Math.sqrt(tol) * model.tolerance;
174
176
  if (model.pickFromList) {
175
177
  props = model.pickList;
176
178
  } else {
@@ -209,12 +211,12 @@ function vtkPicker(publicAPI, model) {
209
211
  }
210
212
  if (mapper) {
211
213
  bbox.setBounds(mapper.getBounds());
212
- bbox.inflate(tol);
214
+ bbox.inflate(tolerance);
213
215
  } else {
214
216
  bbox.reset();
215
217
  }
216
218
  if (bbox.intersectBox(p1Mapper, ray, hitPosition, t)) {
217
- t[0] = publicAPI.intersectWithLine(p1Mapper, p2Mapper, tol * 0.333 * (scale[0] + scale[1] + scale[2]), prop, mapper);
219
+ t[0] = publicAPI.intersectWithLine(p1Mapper, p2Mapper, tolerance * 0.333 * (scale[0] + scale[1] + scale[2]), prop, mapper);
218
220
  if (t[0] < Number.MAX_VALUE) {
219
221
  const p = [];
220
222
  p[0] = (1.0 - t[0]) * p1World[0] + t[0] * p2World[0];
@@ -24,29 +24,30 @@ function widgetBehavior(publicAPI, model) {
24
24
  };
25
25
  publicAPI.handleEvent = callData => {
26
26
  const manipulator = model.activeState?.getManipulator?.() ?? model.manipulator;
27
- if (manipulator && model.activeState && model.activeState.getActive()) {
28
- const normal = model._camera.getDirectionOfProjection();
29
- const up = model._camera.getViewUp();
30
- const right = [];
31
- vec3.cross(right, up, normal);
32
- model.activeState.setUp(...up);
33
- model.activeState.setRight(...right);
34
- model.activeState.setDirection(...normal);
35
- const {
36
- worldCoords
37
- } = manipulator.handleEvent(callData, model._apiSpecificRenderWindow);
38
- if (worldCoords.length) {
39
- model.widgetState.setTrueOrigin(...worldCoords);
40
- model.activeState.setOrigin(...worldCoords);
41
- if (model.painting) {
42
- const trailCircle = model.widgetState.addTrail();
43
- trailCircle.set(model.activeState.get('origin', 'up', 'right', 'direction', 'scale1'));
44
- }
45
- }
46
- publicAPI.invokeInteractionEvent();
47
- return macro.EVENT_ABORT;
27
+ if (!(manipulator && model.activeState && model.activeState.getActive())) {
28
+ return macro.VOID;
29
+ }
30
+ const normal = model._camera.getDirectionOfProjection();
31
+ const up = model._camera.getViewUp();
32
+ const right = [];
33
+ vec3.cross(right, up, normal);
34
+ model.activeState.setUp(...up);
35
+ model.activeState.setRight(...right);
36
+ model.activeState.setDirection(...normal);
37
+ const {
38
+ worldCoords
39
+ } = manipulator.handleEvent(callData, model._apiSpecificRenderWindow);
40
+ if (!worldCoords.length) {
41
+ return macro.VOID;
48
42
  }
49
- return macro.VOID;
43
+ model.widgetState.setTrueOrigin(...worldCoords);
44
+ model.activeState.setOrigin(...worldCoords);
45
+ if (model.painting) {
46
+ const trailCircle = model.widgetState.addTrail();
47
+ trailCircle.set(model.activeState.get('origin', 'up', 'right', 'direction', 'scale1'));
48
+ }
49
+ publicAPI.invokeInteractionEvent();
50
+ return macro.EVENT_ABORT;
50
51
  };
51
52
  publicAPI.grabFocus = () => {
52
53
  if (!model.hasFocus) {
@@ -75,7 +75,7 @@ export interface vtkResliceCursorWidget extends vtkAbstractWidgetFactory {
75
75
  * Return an array of the first and the last possible points of the plane
76
76
  * along its normal.
77
77
  * @param {ViewTypes} viewType
78
- * @returns {[Vector3, Vector3]} first and last points
78
+ * @returns {Array<Vector3>} two Vector3 arrays (first and last points)
79
79
  */
80
80
  getPlaneExtremities(viewType: ViewTypes): Array<Vector3>;
81
81
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kitware/vtk.js",
3
- "version": "29.4.2",
3
+ "version": "29.4.4",
4
4
  "description": "Visualization Toolkit for the Web",
5
5
  "keywords": [
6
6
  "3d",
@@ -118,7 +118,6 @@
118
118
  "string-replace-loader": "3.1.0",
119
119
  "style-loader": "3.3.1",
120
120
  "tape": "5.5.3",
121
- "tape-catch": "1.0.6",
122
121
  "webpack": "5.76.0",
123
122
  "webpack-bundle-analyzer": "4.5.0",
124
123
  "webpack-cli": "4.9.2",