@kitware/vtk.js 24.16.5 → 24.17.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.
@@ -132,11 +132,7 @@ function vtkOBBTree(publicAPI, model) {
132
132
 
133
133
  for (var _i2 = 0; _i2 < 3; _i2++) {
134
134
  for (var _j2 = 0; _j2 < 3; _j2++) {
135
- a[_i2][_j2] = a[_i2][_j2] / totMass - mean[_i2] * mean[_j2]; // send to zero if close to zero
136
-
137
- if (Math.abs(a[_i2][_j2]) < 1e-12) {
138
- a[_i2][_j2] = 0;
139
- }
135
+ a[_i2][_j2] = a[_i2][_j2] / totMass - mean[_i2] * mean[_j2];
140
136
  }
141
137
  } //
142
138
  // Extract axes (i.e., eigenvectors) from covariance matrix.
@@ -199,7 +199,10 @@ function vtkMouseRangeManipulator(publicAPI, model) {
199
199
  // and the last `onMouseMove` event, we must make sure the pointer
200
200
  // is still locked before we run this logic otherwise we may
201
201
  // get a `onMouseMove` call after the pointer has been unlocked.
202
- if (!interactor.isPointerLocked()) return;
202
+ if (!interactor.isPointerLocked()) return; // previousPosition could be undefined if for some reason the
203
+ // `startPointerLockEvent` method is called before the `onButtonDown` one.
204
+
205
+ if (model.previousPosition == null) return;
203
206
  model.previousPosition.x += event.movementX;
204
207
  model.previousPosition.y += event.movementY;
205
208
  publicAPI.onMouseMove(interactor, renderer, model.previousPosition);
@@ -57,6 +57,8 @@ export interface IRenderWindowInteractorInitialValues {
57
57
  lastFrameTime?: number;
58
58
  wheelTimeoutID?: number;
59
59
  moveTimeoutID?: number;
60
+ preventDefaultOnPointerDown?: boolean;
61
+ preventDefaultOnPointerUp?: boolean;
60
62
  }
61
63
 
62
64
  interface IPosition {
@@ -151,6 +153,16 @@ export interface vtkRenderWindowInteractor extends vtkObject {
151
153
  */
152
154
  getStillUpdateRate(): number;
153
155
 
156
+ /**
157
+ * @default false
158
+ */
159
+ getPreventDefaultOnPointerDown(): boolean;
160
+
161
+ /**
162
+ * @default false
163
+ */
164
+ getPreventDefaultOnPointerUp(): boolean;
165
+
154
166
  /**
155
167
  *
156
168
  * @param {IRenderWindowInteractorEvent} callData
@@ -821,6 +833,22 @@ export interface vtkRenderWindowInteractor extends vtkObject {
821
833
  setPicker(picker: any): boolean;
822
834
 
823
835
  /**
836
+ * Set whether preventDefault is called on pointer down.
837
+ * @param {Boolean} preventDefault
838
+ */
839
+ setPreventDefaultOnPointerDown(preventDefault: boolean): boolean;
840
+
841
+ /**
842
+ * Set whether preventDefault is called on pointer up.
843
+ *
844
+ * If pointerup occurs without a preceeding pointerdown, then
845
+ * this does nothing.
846
+ *
847
+ * @param {Boolean} preventDefault
848
+ */
849
+ setPreventDefaultOnPointerUp(preventDefault: boolean): boolean;
850
+
851
+ /**
824
852
  *
825
853
  * @param recognizeGestures
826
854
  */
@@ -24,11 +24,8 @@ var handledEvents = ['StartAnimation', 'Animation', 'EndAnimation', 'PointerEnte
24
24
 
25
25
  function preventDefault(event) {
26
26
  if (event.cancelable) {
27
- event.stopPropagation();
28
27
  event.preventDefault();
29
28
  }
30
-
31
- return false;
32
29
  }
33
30
 
34
31
  function pointerCacheToPositions(cache) {
@@ -173,8 +170,7 @@ function vtkRenderWindowInteractor(publicAPI, model) {
173
170
 
174
171
  publicAPI.bindEvents = function (container) {
175
172
  model.container = container;
176
- container.addEventListener('contextmenu', preventDefault); // container.addEventListener('click', preventDefault); // Avoid stopping event propagation
177
-
173
+ container.addEventListener('contextmenu', preventDefault);
178
174
  container.addEventListener('wheel', publicAPI.handleWheel);
179
175
  container.addEventListener('DOMMouseScroll', publicAPI.handleWheel);
180
176
  container.addEventListener('pointerenter', publicAPI.handlePointerEnter);
@@ -201,8 +197,7 @@ function vtkRenderWindowInteractor(publicAPI, model) {
201
197
 
202
198
  publicAPI.unbindEvents = function () {
203
199
  var container = model.container;
204
- container.removeEventListener('contextmenu', preventDefault); // model.container.removeEventListener('click', preventDefault); // Avoid stopping event propagation
205
-
200
+ container.removeEventListener('contextmenu', preventDefault);
206
201
  container.removeEventListener('wheel', publicAPI.handleWheel);
207
202
  container.removeEventListener('DOMMouseScroll', publicAPI.handleWheel);
208
203
  container.removeEventListener('pointerenter', publicAPI.handlePointerEnter);
@@ -270,7 +265,9 @@ function vtkRenderWindowInteractor(publicAPI, model) {
270
265
  return;
271
266
  }
272
267
 
273
- preventDefault(event);
268
+ if (model.preventDefaultOnPointerDown) {
269
+ preventDefault(event);
270
+ }
274
271
 
275
272
  if (event.target.hasPointerCapture(event.pointerId)) {
276
273
  event.target.releasePointerCapture(event.pointerId);
@@ -302,7 +299,10 @@ function vtkRenderWindowInteractor(publicAPI, model) {
302
299
 
303
300
  publicAPI.handlePointerUp = function (event) {
304
301
  if (pointerCache.has(event.pointerId)) {
305
- preventDefault(event);
302
+ if (model.preventDefaultOnPointerUp) {
303
+ preventDefault(event);
304
+ }
305
+
306
306
  pointerCache.delete(event.pointerId);
307
307
  model.container.releasePointerCapture(event.pointerId);
308
308
 
@@ -384,8 +384,9 @@ function vtkRenderWindowInteractor(publicAPI, model) {
384
384
 
385
385
 
386
386
  publicAPI.requestPointerLock = function () {
387
- var canvas = publicAPI.getView().getCanvas();
388
- canvas.requestPointerLock();
387
+ if (model.container) {
388
+ model.container.requestPointerLock();
389
+ }
389
390
  }; //----------------------------------------------------------------------
390
391
 
391
392
 
@@ -395,7 +396,7 @@ function vtkRenderWindowInteractor(publicAPI, model) {
395
396
 
396
397
 
397
398
  publicAPI.isPointerLocked = function () {
398
- return !!document.pointerLockElement;
399
+ return !!model.container && document.pointerLockElement === model.container;
399
400
  }; //----------------------------------------------------------------------
400
401
 
401
402
 
@@ -1075,7 +1076,9 @@ var DEFAULT_VALUES = {
1075
1076
  recentAnimationFrameRate: 10.0,
1076
1077
  wheelTimeoutID: 0,
1077
1078
  moveTimeoutID: 0,
1078
- lastGamepadValues: {}
1079
+ lastGamepadValues: {},
1080
+ preventDefaultOnPointerDown: false,
1081
+ preventDefaultOnPointerUp: false
1079
1082
  }; // ----------------------------------------------------------------------------
1080
1083
 
1081
1084
  function extend(publicAPI, model) {
@@ -1092,7 +1095,7 @@ function extend(publicAPI, model) {
1092
1095
 
1093
1096
  macro.get(publicAPI, model, ['initialized', 'container', 'interactorStyle', 'lastFrameTime', 'recentAnimationFrameRate', '_view']); // Create get-set macros
1094
1097
 
1095
- macro.setGet(publicAPI, model, ['lightFollowCamera', 'enabled', 'enableRender', 'recognizeGestures', 'desiredUpdateRate', 'stillUpdateRate', 'picker']);
1098
+ macro.setGet(publicAPI, model, ['lightFollowCamera', 'enabled', 'enableRender', 'recognizeGestures', 'desiredUpdateRate', 'stillUpdateRate', 'picker', 'preventDefaultOnPointerDown', 'preventDefaultOnPointerUp']);
1096
1099
  macro.moveToProtected(publicAPI, model, ['view']); // For more macro methods, see "Sources/macros.js"
1097
1100
  // Object specific methods
1098
1101
 
@@ -567,13 +567,8 @@ function vtkOpenGLTexture(publicAPI, model) {
567
567
  if (dataType !== VtkDataTypes.FLOAT && model.openGLDataType === model.context.FLOAT) {
568
568
  for (var idx = 0; idx < data.length; idx++) {
569
569
  if (data[idx]) {
570
- var newArray = new Float32Array(pixCount);
571
-
572
- for (var i = 0; i < pixCount; i++) {
573
- newArray[i] = data[idx][i];
574
- }
575
-
576
- pixData.push(newArray);
570
+ var dataArrayToCopy = data[idx].length > pixCount ? data[idx].subarray(0, pixCount) : data[idx];
571
+ pixData.push(new Float32Array(dataArrayToCopy));
577
572
  } else {
578
573
  pixData.push(null);
579
574
  }
@@ -585,13 +580,9 @@ function vtkOpenGLTexture(publicAPI, model) {
585
580
  if (dataType !== VtkDataTypes.UNSIGNED_CHAR && model.openGLDataType === model.context.UNSIGNED_BYTE) {
586
581
  for (var _idx = 0; _idx < data.length; _idx++) {
587
582
  if (data[_idx]) {
588
- var _newArray = new Uint8Array(pixCount);
583
+ var _dataArrayToCopy = data[_idx].length > pixCount ? data[_idx].subarray(0, pixCount) : data[_idx];
589
584
 
590
- for (var _i = 0; _i < pixCount; _i++) {
591
- _newArray[_i] = data[_idx][_i];
592
- }
593
-
594
- pixData.push(_newArray);
585
+ pixData.push(new Uint8Array(_dataArrayToCopy));
595
586
  } else {
596
587
  pixData.push(null);
597
588
  }
@@ -606,13 +597,13 @@ function vtkOpenGLTexture(publicAPI, model) {
606
597
  if (halfFloat) {
607
598
  for (var _idx2 = 0; _idx2 < data.length; _idx2++) {
608
599
  if (data[_idx2]) {
609
- var _newArray2 = new Uint16Array(pixCount);
600
+ var newArray = new Uint16Array(pixCount);
610
601
 
611
- for (var _i2 = 0; _i2 < pixCount; _i2++) {
612
- _newArray2[_i2] = HalfFloat.toHalf(data[_idx2][_i2]);
602
+ for (var i = 0; i < pixCount; i++) {
603
+ newArray[i] = HalfFloat.toHalf(data[_idx2][i]);
613
604
  }
614
605
 
615
- pixData.push(_newArray2);
606
+ pixData.push(newArray);
616
607
  } else {
617
608
  pixData.push(null);
618
609
  }
@@ -621,8 +612,8 @@ function vtkOpenGLTexture(publicAPI, model) {
621
612
 
622
613
 
623
614
  if (pixData.length === 0) {
624
- for (var _i3 = 0; _i3 < data.length; _i3++) {
625
- pixData.push(data[_i3]);
615
+ for (var _i = 0; _i < data.length; _i++) {
616
+ pixData.push(data[_i]);
626
617
  }
627
618
  }
628
619
 
@@ -714,8 +705,8 @@ function vtkOpenGLTexture(publicAPI, model) {
714
705
 
715
706
 
716
707
  if (pixData.length === 0) {
717
- for (var _i4 = 0; _i4 < data.length; _i4++) {
718
- pixData.push(data[_i4]);
708
+ for (var _i2 = 0; _i2 < data.length; _i2++) {
709
+ pixData.push(data[_i2]);
719
710
  }
720
711
  }
721
712
 
@@ -819,7 +810,7 @@ function vtkOpenGLTexture(publicAPI, model) {
819
810
 
820
811
  model.context.pixelStorei(model.context.UNPACK_ALIGNMENT, 1); // We get the 6 images
821
812
 
822
- for (var _i5 = 0; _i5 < 6; _i5++) {
813
+ for (var _i3 = 0; _i3 < 6; _i3++) {
823
814
  // For each mipmap level
824
815
  var j = 0;
825
816
  var w = model.width;
@@ -832,10 +823,10 @@ function vtkOpenGLTexture(publicAPI, model) {
832
823
  var tempData = null;
833
824
 
834
825
  if (j <= model.maxLevel) {
835
- tempData = invertedData[6 * j + _i5];
826
+ tempData = invertedData[6 * j + _i3];
836
827
  }
837
828
 
838
- model.context.texImage2D(model.context.TEXTURE_CUBE_MAP_POSITIVE_X + _i5, j, model.internalFormat, w, h, 0, model.format, model.openGLDataType, tempData);
829
+ model.context.texImage2D(model.context.TEXTURE_CUBE_MAP_POSITIVE_X + _i3, j, model.internalFormat, w, h, 0, model.format, model.openGLDataType, tempData);
839
830
  j++;
840
831
  w /= 2;
841
832
  h /= 2;
@@ -1111,7 +1102,7 @@ function vtkOpenGLTexture(publicAPI, model) {
1111
1102
  } // otherwise convert to float
1112
1103
 
1113
1104
 
1114
- var _newArray3 = new Float32Array(numPixelsIn * numComps); // compute min and max values
1105
+ var _newArray = new Float32Array(numPixelsIn * numComps); // compute min and max values
1115
1106
 
1116
1107
 
1117
1108
  model.volumeInfo.offset = computedOffset;
@@ -1123,12 +1114,12 @@ function vtkOpenGLTexture(publicAPI, model) {
1123
1114
 
1124
1115
  for (var i = 0; i < numPixelsIn; i++) {
1125
1116
  for (var nc = 0; nc < numComps; nc++) {
1126
- _newArray3[count] = (data[count] - computedOffset[nc]) * scaleInverse[nc];
1117
+ _newArray[count] = (data[count] - computedOffset[nc]) * scaleInverse[nc];
1127
1118
  count++;
1128
1119
  }
1129
1120
  }
1130
1121
 
1131
- return publicAPI.create3DFromRaw(width, height, depth, numComps, VtkDataTypes.FLOAT, _newArray3);
1122
+ return publicAPI.create3DFromRaw(width, height, depth, numComps, VtkDataTypes.FLOAT, _newArray);
1132
1123
  } // not webgl2, deal with webgl1, no 3d textures
1133
1124
  // and maybe no float textures
1134
1125
  // compute min and max values
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kitware/vtk.js",
3
- "version": "24.16.5",
3
+ "version": "24.17.0",
4
4
  "description": "Visualization Toolkit for the Web",
5
5
  "keywords": [
6
6
  "3d",