@kitware/vtk.js 27.2.0 → 27.3.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.
@@ -349,7 +349,9 @@ function vtkOBJReader(publicAPI, model) {
349
349
 
350
350
  publicAPI.loadData = function () {
351
351
  var option = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
352
- return fetchData(model.url, option).then(publicAPI.parseAsText);
352
+ return fetchData(model.url, option).then(function (content) {
353
+ return publicAPI.isDeleted() ? false : publicAPI.parseAsText(content);
354
+ });
353
355
  };
354
356
 
355
357
  publicAPI.parseAsText = function (content) {
@@ -1,10 +1,8 @@
1
- import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
2
- import { mat4, vec3 } from 'gl-matrix';
1
+ import { vec3, mat4 } from 'gl-matrix';
3
2
  import macro from '../../macros.js';
4
3
  import vtkCompositeCameraManipulator from './CompositeCameraManipulator.js';
5
4
  import vtkCompositeMouseManipulator from './CompositeMouseManipulator.js';
6
5
  import { r as radiansFromDegrees, j as cross } from '../../Common/Core/Math/index.js';
7
- import vtkMatrixBuilder from '../../Common/Core/MatrixBuilder.js';
8
6
 
9
7
  // vtkMouseCameraAxisRotateManipulator methods
10
8
  // ----------------------------------------------------------------------------
@@ -12,14 +10,15 @@ import vtkMatrixBuilder from '../../Common/Core/MatrixBuilder.js';
12
10
  function vtkMouseCameraAxisRotateManipulator(publicAPI, model) {
13
11
  // Set our className
14
12
  model.classHierarchy.push('vtkMouseCameraAxisRotateManipulator');
13
+ var negCameraDir = new Float64Array(3);
15
14
  var newCamPos = new Float64Array(3);
16
- var newFp = new Float64Array(3); // const newViewUp = new Float64Array(3);
17
-
15
+ var newFp = new Float64Array(3);
16
+ var newViewUp = new Float64Array(3);
18
17
  var trans = new Float64Array(16);
18
+ var rotation = new Float64Array(16);
19
19
  var v2 = new Float64Array(3);
20
20
  var centerNeg = new Float64Array(3);
21
- var direction = new Float64Array(3);
22
- var fpDirection = new Float64Array(3);
21
+ var negRotationAxis = new Float64Array(3);
23
22
 
24
23
  publicAPI.onButtonDown = function (interactor, renderer, position) {
25
24
  model.previousPosition = position;
@@ -35,83 +34,53 @@ function vtkMouseCameraAxisRotateManipulator(publicAPI, model) {
35
34
  var cameraFp = camera.getFocalPoint();
36
35
  var cameraViewUp = camera.getViewUp();
37
36
  var cameraDirection = camera.getDirectionOfProjection();
37
+ vec3.negate(negCameraDir, cameraDirection);
38
38
  mat4.identity(trans);
39
+ mat4.identity(rotation);
39
40
  var center = model.center,
40
41
  rotationFactor = model.rotationFactor,
41
- rotationAxis = model.rotationAxis; // Translate to center
42
-
43
- mat4.translate(trans, trans, center);
42
+ rotationAxis = model.rotationAxis;
43
+ vec3.negate(negRotationAxis, rotationAxis);
44
44
  var dx = model.previousPosition.x - position.x;
45
45
  var dy = model.previousPosition.y - position.y;
46
46
  var size = interactor.getView().getViewportSize(renderer); // Azimuth
47
47
 
48
- mat4.rotate(trans, trans, radiansFromDegrees(360.0 * dx / size[0] * rotationFactor), rotationAxis); // Elevation
48
+ var azimuthDelta = radiansFromDegrees(360.0 * dx / size[0] * rotationFactor);
49
+ mat4.rotate(rotation, rotation, azimuthDelta, rotationAxis); // Elevation
49
50
 
50
51
  cross(cameraDirection, cameraViewUp, v2);
51
- mat4.rotate(trans, trans, radiansFromDegrees(-360.0 * dy / size[1] * rotationFactor), v2); // Translate back
52
-
53
- centerNeg[0] = -center[0];
54
- centerNeg[1] = -center[1];
55
- centerNeg[2] = -center[2];
56
- mat4.translate(trans, trans, centerNeg); // Apply transformation to camera position, focal point, and view up
52
+ var elevationDelta = radiansFromDegrees(-360.0 * dy / size[1] * rotationFactor); // angle of camera to rotation axis on the positive or negative half,
53
+ // relative to the origin.
57
54
 
58
- vec3.transformMat4(newCamPos, cameraPos, trans);
59
- vec3.transformMat4(newFp, cameraFp, trans); // what is the current direction from the fp
60
- // to the camera
55
+ var angleToPosHalf = Math.acos(vec3.dot(negCameraDir, rotationAxis));
56
+ var angleToNegHalf = Math.acos(vec3.dot(negCameraDir, negRotationAxis)); // whether camera is in positive half of the rotation axis or neg half
61
57
 
62
- vec3.subtract(fpDirection, newCamPos, newFp);
63
- vec3.normalize(fpDirection, fpDirection); // make the top sticky to avoid accidental flips
58
+ var inPosHalf = angleToPosHalf <= angleToNegHalf;
59
+ var elevationToAxis = Math.min(angleToPosHalf, angleToNegHalf);
64
60
 
65
- if (Math.abs(vec3.dot(fpDirection, rotationAxis)) > 0.95) {
66
- // this can be smarter where it still allows Azimuth here
67
- // but prevents the elevation part
68
- model.previousPosition = position;
69
- return;
61
+ if (model.useHalfAxis && !inPosHalf) {
62
+ elevationDelta = Math.PI / 2 - angleToPosHalf;
63
+ } else if (inPosHalf && elevationToAxis + elevationDelta < 0) {
64
+ elevationDelta = -elevationToAxis; // } else if (!inPosHalf && elevationToAxis - elevationDelta < 0) {
65
+ } else if (!inPosHalf && angleToPosHalf + elevationDelta > Math.PI) {
66
+ elevationDelta = elevationToAxis;
70
67
  }
71
68
 
72
- if (model.useHalfAxis) {
73
- // what is the current distance from pos to center of rotation
74
- var distance = vec3.distance(newCamPos, center); // what is the current direction from the center of rotation
75
- // to the camera
76
-
77
- vec3.subtract(direction, newCamPos, center);
78
- vec3.normalize(direction, direction); // project the rotation axis onto the direction
79
- // so we know how much below the half plane we are
80
-
81
- var dotP = vec3.dot(rotationAxis, direction);
69
+ mat4.rotate(rotation, rotation, elevationDelta, v2); // Translate from origin
82
70
 
83
- if (dotP < 0) {
84
- // adjust the new camera position to bring it up to the half plane
85
- vec3.scaleAndAdd(newCamPos, newCamPos, rotationAxis, -dotP * distance); // the above step will change the distance which might feel odd
86
- // so the next couple lines restore the distance to the center
87
- // what is the new direction from the center of rotation
88
- // to the camera
71
+ mat4.translate(trans, trans, center); // apply rotation
89
72
 
90
- vec3.subtract(direction, newCamPos, center);
91
- vec3.normalize(direction, direction);
92
- vec3.scaleAndAdd(newCamPos, center, direction, distance); // compute original cam direction to center
73
+ mat4.multiply(trans, trans, rotation); // Translate to origin
93
74
 
94
- vec3.subtract(v2, cameraPos, center);
95
- vec3.normalize(v2, v2); // const rAngle = 0.0;
96
-
97
- var acosR = Math.min(1.0, Math.max(-1.0, vec3.dot(direction, v2)));
98
- var rAngle = Math.acos(acosR); // 0 to pi
99
-
100
- vec3.cross(v2, v2, direction);
101
- vec3.normalize(v2, v2);
102
- vec3.subtract(newFp, cameraFp, center);
103
- var fpDist = vec3.length(newFp); // Note it normalizes the vector to be rotated
104
-
105
- var result = _toConsumableArray(newFp);
106
-
107
- vtkMatrixBuilder.buildFromRadian().rotate(rAngle, v2).apply(result);
108
- vec3.scaleAndAdd(newFp, center, result, fpDist);
109
- }
110
- }
75
+ vec3.negate(centerNeg, center);
76
+ mat4.translate(trans, trans, centerNeg); // Apply transformation to camera position, focal point, and view up
111
77
 
78
+ vec3.transformMat4(newCamPos, cameraPos, trans);
79
+ vec3.transformMat4(newFp, cameraFp, trans);
80
+ vec3.transformMat4(newViewUp, cameraViewUp, rotation);
112
81
  camera.setPosition(newCamPos[0], newCamPos[1], newCamPos[2]);
113
82
  camera.setFocalPoint(newFp[0], newFp[1], newFp[2]);
114
- camera.setViewUp(rotationAxis);
83
+ camera.setViewUp(newViewUp);
115
84
  renderer.resetCameraClippingRange();
116
85
 
117
86
  if (interactor.getLightFollowCamera()) {
@@ -2,6 +2,7 @@ import vtkProp, { IPropInitialValues } from './Prop';
2
2
  import vtkCoordinate from './Coordinate';
3
3
  import vtkMapper from './Mapper';
4
4
  import vtkProperty2D, { IProperty2DInitialValues } from './Property2D';
5
+ import vtkMapper2D from './Mapper2D';
5
6
  import { Bounds } from './../../types';
6
7
 
7
8
  /**
@@ -44,6 +45,16 @@ export interface vtkActor2D extends vtkProp {
44
45
  */
45
46
  makeProperty(initialValues?: IProperty2DInitialValues): vtkProperty2D;
46
47
 
48
+ /**
49
+ * Sets the 2D mapper.
50
+ */
51
+ setMapper(mapper: vtkMapper2D): boolean;
52
+
53
+ /**
54
+ * Gets the 2D mapper.
55
+ */
56
+ getMapper(): vtkMapper2D;
57
+
47
58
  /**
48
59
  *
49
60
  */
@@ -272,7 +272,7 @@ function extend(publicAPI, model) {
272
272
 
273
273
  macro.obj(publicAPI, model);
274
274
  macro.algo(publicAPI, model, 6, 0);
275
- macro.get(publicAPI, model, ['canvas', 'image', 'jsImageData', 'imageLoaded']);
275
+ macro.get(publicAPI, model, ['canvas', 'image', 'jsImageData', 'imageLoaded', 'resizable']);
276
276
  macro.setGet(publicAPI, model, ['repeat', 'edgeClamp', 'interpolate', 'mipLevel']);
277
277
  vtkTexture(publicAPI, model);
278
278
  } // ----------------------------------------------------------------------------
@@ -16,7 +16,8 @@ var Wrap = Constants.Wrap,
16
16
  var VtkDataTypes = vtkDataArray.VtkDataTypes;
17
17
  var vtkDebugMacro = vtkDebugMacro$1,
18
18
  vtkErrorMacro = vtkErrorMacro$1,
19
- vtkWarningMacro = vtkWarningMacro$1; // ----------------------------------------------------------------------------
19
+ vtkWarningMacro = vtkWarningMacro$1;
20
+ var toHalf = HalfFloat.toHalf; // ----------------------------------------------------------------------------
20
21
  // vtkOpenGLTexture methods
21
22
  // ----------------------------------------------------------------------------
22
23
 
@@ -610,9 +611,10 @@ function vtkOpenGLTexture(publicAPI, model) {
610
611
  for (var _idx2 = 0; _idx2 < data.length; _idx2++) {
611
612
  if (data[_idx2]) {
612
613
  var newArray = new Uint16Array(pixCount);
614
+ var src = data[_idx2];
613
615
 
614
616
  for (var i = 0; i < pixCount; i++) {
615
- newArray[i] = HalfFloat.toHalf(data[_idx2][i]);
617
+ newArray[i] = toHalf(src[i]);
616
618
  }
617
619
 
618
620
  pixData.push(newArray);
@@ -728,7 +730,9 @@ function vtkOpenGLTexture(publicAPI, model) {
728
730
 
729
731
  function useTexStorage(dataType) {
730
732
  if (model._openGLRenderWindow) {
731
- if (model.resizable) {
733
+ var _model$renderable;
734
+
735
+ if (model.resizable || (_model$renderable = model.renderable) !== null && _model$renderable !== void 0 && _model$renderable.getResizable()) {
732
736
  // Cannot use texStorage if the texture is supposed to be resizable.
733
737
  return false;
734
738
  }
@@ -879,7 +883,7 @@ function vtkOpenGLTexture(publicAPI, model) {
879
883
  tempData = invertedData[6 * j + _i3];
880
884
  }
881
885
 
882
- if (model._openGLRenderWindow.getWebgl2() && !model.resizable) {
886
+ if (useTexStorage(dataType)) {
883
887
  if (tempData != null) {
884
888
  model.context.texSubImage2D(model.context.TEXTURE_CUBE_MAP_POSITIVE_X + _i3, j, 0, 0, w, h, model.format, model.openGLDataType, tempData);
885
889
  }
@@ -82,6 +82,13 @@ export interface vtkWidgetManager extends vtkObject {
82
82
  */
83
83
  getWidgets(): vtkAbstractWidget[];
84
84
 
85
+ /**
86
+ * Get the active widget.
87
+ *
88
+ * If no widget is active, returns null.
89
+ */
90
+ getActiveWidget(): Nullable<vtkAbstractWidget>;
91
+
85
92
  /**
86
93
  * Get the view id.
87
94
  */
@@ -190,10 +190,12 @@ function vtkWidgetManager(publicAPI, model) {
190
190
  // Default cursor behavior
191
191
  model._apiSpecificRenderWindow.setCursor(widget ? 'pointer' : 'default');
192
192
 
193
+ model.activeWidget = null;
193
194
  wantRender = false;
194
195
 
195
196
  if (model.widgetInFocus === widget && widget.hasFocus()) {
196
197
  activateHandle(widget);
198
+ model.activeWidget = widget;
197
199
  wantRender = true;
198
200
  } else {
199
201
  for (i = 0; i < model.widgets.length; i++) {
@@ -214,7 +216,7 @@ function vtkWidgetManager(publicAPI, model) {
214
216
  model._interactor.render();
215
217
  }
216
218
 
217
- case 15:
219
+ case 16:
218
220
  case "end":
219
221
  return _context3.stop();
220
222
  }
@@ -614,6 +616,7 @@ var DEFAULT_VALUES = {
614
616
  // _currentUpdateSelectionCallID: null,
615
617
  viewId: null,
616
618
  widgets: [],
619
+ activeWidget: null,
617
620
  renderer: null,
618
621
  viewType: ViewTypes.DEFAULT,
619
622
  isAnimating: false,
@@ -633,7 +636,7 @@ function extend(publicAPI, model) {
633
636
  name: 'viewType',
634
637
  enum: ViewTypes
635
638
  }]);
636
- macro.get(publicAPI, model, ['selections', 'widgets', 'viewId', 'pickingEnabled']); // Object specific methods
639
+ macro.get(publicAPI, model, ['selections', 'widgets', 'viewId', 'pickingEnabled', 'activeWidget']); // Object specific methods
637
640
 
638
641
  vtkWidgetManager(publicAPI, model);
639
642
  } // ----------------------------------------------------------------------------
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kitware/vtk.js",
3
- "version": "27.2.0",
3
+ "version": "27.3.0",
4
4
  "description": "Visualization Toolkit for the Web",
5
5
  "keywords": [
6
6
  "3d",