@kitware/vtk.js 24.2.0 → 24.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.
@@ -696,7 +696,7 @@ function vtkCubeAxesActor(publicAPI, model) {
696
696
  publicAPI.getBounds = function () {
697
697
  publicAPI.update();
698
698
  vtkBoundingBox.setBounds(model.bounds, model.gridActor.getBounds());
699
- vtkBoundingBox.scaleAboutCenter(model.bounds, model.boundsScaleFactor);
699
+ vtkBoundingBox.scaleAboutCenter(model.bounds, model.boundsScaleFactor, model.boundsScaleFactor, model.boundsScaleFactor);
700
700
  return model.bounds;
701
701
  };
702
702
  } // ----------------------------------------------------------------------------
@@ -184,8 +184,14 @@ function vtkRenderWindowInteractor(publicAPI, model) {
184
184
  rootElm[method]('mouseup', publicAPI.handleMouseUp);
185
185
  rootElm[method]('mousemove', publicAPI.handleMouseMove);
186
186
  rootElm[method]('touchend', publicAPI.handleTouchEnd, false);
187
- rootElm[method]('touchcancel', publicAPI.handleTouchEnd, false);
188
- rootElm[method]('touchmove', publicAPI.handleTouchMove, false);
187
+ rootElm[method]('touchcancel', publicAPI.handleTouchEnd, {
188
+ passive: false,
189
+ capture: false
190
+ });
191
+ rootElm[method]('touchmove', publicAPI.handleTouchMove, {
192
+ passive: false,
193
+ capture: false
194
+ });
189
195
  }
190
196
 
191
197
  if (!force && addListeners) {
@@ -207,7 +213,10 @@ function vtkRenderWindowInteractor(publicAPI, model) {
207
213
  document.addEventListener('keydown', publicAPI.handleKeyDown);
208
214
  document.addEventListener('keyup', publicAPI.handleKeyUp);
209
215
  document.addEventListener('pointerlockchange', publicAPI.handlePointerLockChange);
210
- container.addEventListener('touchstart', publicAPI.handleTouchStart, false);
216
+ container.addEventListener('touchstart', publicAPI.handleTouchStart, {
217
+ passive: false,
218
+ capture: false
219
+ });
211
220
  };
212
221
 
213
222
  publicAPI.unbindEvents = function () {
@@ -225,7 +234,10 @@ function vtkRenderWindowInteractor(publicAPI, model) {
225
234
  document.removeEventListener('keydown', publicAPI.handleKeyDown);
226
235
  document.removeEventListener('keyup', publicAPI.handleKeyUp);
227
236
  document.removeEventListener('pointerlockchange', publicAPI.handlePointerLockChange);
228
- model.container.removeEventListener('touchstart', publicAPI.handleTouchStart);
237
+ model.container.removeEventListener('touchstart', publicAPI.handleTouchStart, {
238
+ passive: false,
239
+ capture: false
240
+ });
229
241
  model.container = null;
230
242
  };
231
243
 
@@ -212,7 +212,7 @@ function vtkOpenGLOrderIndependentTranslucentPass(publicAPI, model) {
212
212
  return translucentShaderReplacement;
213
213
  }
214
214
 
215
- return {};
215
+ return null;
216
216
  };
217
217
 
218
218
  publicAPI.releaseGraphicsResources = function (viewNode) {
@@ -7,6 +7,7 @@ import macro from '../../macros.js';
7
7
  import vtkSelectionNode from '../../Common/DataModel/SelectionNode.js';
8
8
  import WidgetManagerConst from './WidgetManager/Constants.js';
9
9
  import vtkSVGRepresentation from '../SVG/SVGRepresentation.js';
10
+ import { WIDGET_PRIORITY } from './AbstractWidget/Constants.js';
10
11
  import { diff } from './WidgetManager/vdom.js';
11
12
 
12
13
  var ViewTypes = WidgetManagerConst.ViewTypes,
@@ -263,6 +264,110 @@ function vtkWidgetManager(publicAPI, model) {
263
264
  // --------------------------------------------------------------------------
264
265
 
265
266
 
267
+ function updateSelection(_x) {
268
+ return _updateSelection.apply(this, arguments);
269
+ }
270
+
271
+ function _updateSelection() {
272
+ _updateSelection = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(_ref) {
273
+ var position, _yield$publicAPI$getS, requestCount, selectedState, representation, widget, i, w;
274
+
275
+ return _regeneratorRuntime.wrap(function _callee2$(_context2) {
276
+ while (1) {
277
+ switch (_context2.prev = _context2.next) {
278
+ case 0:
279
+ position = _ref.position;
280
+ model._selectionInProgress = true;
281
+ _context2.next = 4;
282
+ return publicAPI.getSelectedDataForXY(position.x, position.y);
283
+
284
+ case 4:
285
+ _yield$publicAPI$getS = _context2.sent;
286
+ requestCount = _yield$publicAPI$getS.requestCount;
287
+ selectedState = _yield$publicAPI$getS.selectedState;
288
+ representation = _yield$publicAPI$getS.representation;
289
+ widget = _yield$publicAPI$getS.widget;
290
+ model._selectionInProgress = false;
291
+
292
+ if (!requestCount) {
293
+ _context2.next = 12;
294
+ break;
295
+ }
296
+
297
+ return _context2.abrupt("return");
298
+
299
+ case 12:
300
+ // Default cursor behavior
301
+ model._apiSpecificRenderWindow.setCursor(widget ? 'pointer' : 'default');
302
+
303
+ if (model.widgetInFocus === widget && widget.hasFocus()) {
304
+ widget.activateHandle({
305
+ selectedState: selectedState,
306
+ representation: representation
307
+ }); // Ken FIXME
308
+
309
+ model._interactor.render();
310
+
311
+ model._interactor.render();
312
+ } else {
313
+ for (i = 0; i < model.widgets.length; i++) {
314
+ w = model.widgets[i];
315
+
316
+ if (w === widget && w.getNestedPickable()) {
317
+ w.activateHandle({
318
+ selectedState: selectedState,
319
+ representation: representation
320
+ });
321
+ model.activeWidget = w;
322
+ } else {
323
+ w.deactivateAllHandles();
324
+ }
325
+ } // Ken FIXME
326
+
327
+
328
+ model._interactor.render();
329
+
330
+ model._interactor.render();
331
+ }
332
+
333
+ case 14:
334
+ case "end":
335
+ return _context2.stop();
336
+ }
337
+ }
338
+ }, _callee2);
339
+ }));
340
+ return _updateSelection.apply(this, arguments);
341
+ }
342
+
343
+ var handleEvent = function handleEvent(eventName) {
344
+ var guard = false;
345
+ return function (callData) {
346
+ if (guard || model.isAnimating || !model.pickingEnabled || model._selectionInProgress) {
347
+ return macro.VOID;
348
+ }
349
+
350
+ var updatePromise = updateSelection(callData);
351
+ macro.measurePromiseExecution(updatePromise, function (elapsed) {
352
+ // 100ms is deemed fast enough. Anything higher can degrade usability.
353
+ if (elapsed > 100) {
354
+ macro.vtkWarningMacro("vtkWidgetManager updateSelection() took ".concat(elapsed, "ms on ").concat(eventName));
355
+ }
356
+ });
357
+ updatePromise.then(function () {
358
+ if (model._interactor) {
359
+ // re-trigger the event, ignoring our own handler
360
+ guard = true;
361
+
362
+ model._interactor["invoke".concat(eventName)](callData);
363
+
364
+ guard = false;
365
+ }
366
+ });
367
+ return macro.EVENT_ABORT;
368
+ };
369
+ };
370
+
266
371
  function updateWidgetForRender(w) {
267
372
  w.updateRepresentationForRender(model.renderingType);
268
373
  }
@@ -277,7 +382,7 @@ function vtkWidgetManager(publicAPI, model) {
277
382
  model.widgets.forEach(updateWidgetForRender);
278
383
  }
279
384
 
280
- function captureBuffers(_x, _x2, _x3, _x4) {
385
+ function captureBuffers(_x2, _x3, _x4, _x5) {
281
386
  return _captureBuffers.apply(this, arguments);
282
387
  }
283
388
 
@@ -366,89 +471,9 @@ function vtkWidgetManager(publicAPI, model) {
366
471
  model.isAnimating = false;
367
472
  publicAPI.renderWidgets();
368
473
  }));
369
- subscriptions.push(model._interactor.onMouseMove( /*#__PURE__*/function () {
370
- var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(_ref) {
371
- var position, _yield$publicAPI$getS, requestCount, selectedState, representation, widget, i, w;
372
-
373
- return _regeneratorRuntime.wrap(function _callee$(_context) {
374
- while (1) {
375
- switch (_context.prev = _context.next) {
376
- case 0:
377
- position = _ref.position;
378
-
379
- if (!(model.isAnimating || !model.pickingEnabled || model._selectionInProgress)) {
380
- _context.next = 3;
381
- break;
382
- }
383
-
384
- return _context.abrupt("return");
385
-
386
- case 3:
387
- model._selectionInProgress = true;
388
- _context.next = 6;
389
- return publicAPI.getSelectedDataForXY(position.x, position.y);
390
-
391
- case 6:
392
- _yield$publicAPI$getS = _context.sent;
393
- requestCount = _yield$publicAPI$getS.requestCount;
394
- selectedState = _yield$publicAPI$getS.selectedState;
395
- representation = _yield$publicAPI$getS.representation;
396
- widget = _yield$publicAPI$getS.widget;
397
- model._selectionInProgress = false;
398
-
399
- if (!requestCount) {
400
- _context.next = 14;
401
- break;
402
- }
403
-
404
- return _context.abrupt("return");
405
-
406
- case 14:
407
- // Default cursor behavior
408
- model._apiSpecificRenderWindow.setCursor(widget ? 'pointer' : 'default');
409
-
410
- if (model.widgetInFocus === widget && widget.hasFocus()) {
411
- widget.activateHandle({
412
- selectedState: selectedState,
413
- representation: representation
414
- }); // Ken FIXME
415
-
416
- model._interactor.render();
417
-
418
- model._interactor.render();
419
- } else {
420
- for (i = 0; i < model.widgets.length; i++) {
421
- w = model.widgets[i];
422
-
423
- if (w === widget && w.getNestedPickable()) {
424
- w.activateHandle({
425
- selectedState: selectedState,
426
- representation: representation
427
- });
428
- model.activeWidget = w;
429
- } else {
430
- w.deactivateAllHandles();
431
- }
432
- } // Ken FIXME
433
-
434
-
435
- model._interactor.render();
436
-
437
- model._interactor.render();
438
- }
439
-
440
- case 16:
441
- case "end":
442
- return _context.stop();
443
- }
444
- }
445
- }, _callee);
446
- }));
447
-
448
- return function (_x5) {
449
- return _ref2.apply(this, arguments);
450
- };
451
- }()));
474
+ subscriptions.push(model._interactor.onMouseMove(handleEvent('MouseMove')));
475
+ subscriptions.push(model._interactor.onLeftButtonPress(handleEvent('LeftButtonPress'), // stay after widgets, but before default of 0
476
+ WIDGET_PRIORITY / 2));
452
477
  publicAPI.modified();
453
478
 
454
479
  if (model.pickingEnabled) {
@@ -530,16 +555,16 @@ function vtkWidgetManager(publicAPI, model) {
530
555
  };
531
556
 
532
557
  publicAPI.getSelectedDataForXY = /*#__PURE__*/function () {
533
- var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(x, y) {
558
+ var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(x, y) {
534
559
  var i, widget, hoveredSVGReps, selection, capturedRegion;
535
- return _regeneratorRuntime.wrap(function _callee2$(_context2) {
560
+ return _regeneratorRuntime.wrap(function _callee$(_context) {
536
561
  while (1) {
537
- switch (_context2.prev = _context2.next) {
562
+ switch (_context.prev = _context.next) {
538
563
  case 0:
539
564
  model.selections = null;
540
565
 
541
566
  if (!model.pickingEnabled) {
542
- _context2.next = 24;
567
+ _context.next = 24;
543
568
  break;
544
569
  }
545
570
 
@@ -547,7 +572,7 @@ function vtkWidgetManager(publicAPI, model) {
547
572
 
548
573
  case 3:
549
574
  if (!(i < model.widgets.length)) {
550
- _context2.next = 16;
575
+ _context.next = 16;
551
576
  break;
552
577
  }
553
578
 
@@ -557,7 +582,7 @@ function vtkWidgetManager(publicAPI, model) {
557
582
  });
558
583
 
559
584
  if (!hoveredSVGReps.length) {
560
- _context2.next = 13;
585
+ _context.next = 13;
561
586
  break;
562
587
  }
563
588
 
@@ -566,20 +591,20 @@ function vtkWidgetManager(publicAPI, model) {
566
591
  selection.getProperties().widget = widget;
567
592
  selection.getProperties().representation = hoveredSVGReps[0];
568
593
  model.selections = [selection];
569
- return _context2.abrupt("return", publicAPI.getSelectedData());
594
+ return _context.abrupt("return", publicAPI.getSelectedData());
570
595
 
571
596
  case 13:
572
597
  ++i;
573
- _context2.next = 3;
598
+ _context.next = 3;
574
599
  break;
575
600
 
576
601
  case 16:
577
602
  if (!(!model._capturedBuffers || model.captureOn === CaptureOn.MOUSE_MOVE)) {
578
- _context2.next = 19;
603
+ _context.next = 19;
579
604
  break;
580
605
  }
581
606
 
582
- _context2.next = 19;
607
+ _context.next = 19;
583
608
  return captureBuffers(x, y, x, y);
584
609
 
585
610
  case 19:
@@ -587,29 +612,29 @@ function vtkWidgetManager(publicAPI, model) {
587
612
  capturedRegion = model._capturedBuffers.area;
588
613
 
589
614
  if (!(x < capturedRegion[0] || x > capturedRegion[2] || y < capturedRegion[1] || y > capturedRegion[3])) {
590
- _context2.next = 23;
615
+ _context.next = 23;
591
616
  break;
592
617
  }
593
618
 
594
- _context2.next = 23;
619
+ _context.next = 23;
595
620
  return captureBuffers(x, y, x, y);
596
621
 
597
622
  case 23:
598
623
  model.selections = model._capturedBuffers.generateSelection(x, y, x, y);
599
624
 
600
625
  case 24:
601
- return _context2.abrupt("return", publicAPI.getSelectedData());
626
+ return _context.abrupt("return", publicAPI.getSelectedData());
602
627
 
603
628
  case 25:
604
629
  case "end":
605
- return _context2.stop();
630
+ return _context.stop();
606
631
  }
607
632
  }
608
- }, _callee2);
633
+ }, _callee);
609
634
  }));
610
635
 
611
636
  return function (_x6, _x7) {
612
- return _ref3.apply(this, arguments);
637
+ return _ref2.apply(this, arguments);
613
638
  };
614
639
  }();
615
640
 
@@ -16,6 +16,20 @@ function widgetBehavior(publicAPI, model) {
16
16
 
17
17
  function ignoreKey(e) {
18
18
  return e.altKey || e.controlKey || e.shiftKey;
19
+ }
20
+
21
+ function updateMoveHandle(callData) {
22
+ model.manipulator.setOrigin(model._camera.getFocalPoint());
23
+ model.manipulator.setNormal(model._camera.getDirectionOfProjection());
24
+ var worldCoords = model.manipulator.handleEvent(callData, model._apiSpecificRenderWindow);
25
+
26
+ if (worldCoords.length && (model.activeState === model.widgetState.getMoveHandle() || isDragging)) {
27
+ model.activeState.setOrigin(worldCoords);
28
+ publicAPI.invokeInteractionEvent();
29
+ return macro.EVENT_ABORT;
30
+ }
31
+
32
+ return macro.VOID;
19
33
  } // --------------------------------------------------------------------------
20
34
  // Right click: Delete handle
21
35
  // --------------------------------------------------------------------------
@@ -51,7 +65,8 @@ function widgetBehavior(publicAPI, model) {
51
65
  }
52
66
 
53
67
  if (model.activeState === model.widgetState.getMoveHandle()) {
54
- // Commit handle to location
68
+ updateMoveHandle(e); // Commit handle to location
69
+
55
70
  var moveHandle = model.widgetState.getMoveHandle();
56
71
  var newHandle = model.widgetState.addHandle();
57
72
  newHandle.setOrigin.apply(newHandle, _toConsumableArray(moveHandle.getOrigin()));
@@ -74,13 +89,7 @@ function widgetBehavior(publicAPI, model) {
74
89
 
75
90
  publicAPI.handleMouseMove = function (callData) {
76
91
  if (model.pickable && model.dragable && model.manipulator && model.activeState && model.activeState.getActive() && !ignoreKey(callData)) {
77
- model.manipulator.setOrigin(model.activeState.getOrigin());
78
- model.manipulator.setNormal(model._camera.getDirectionOfProjection());
79
- var worldCoords = model.manipulator.handleEvent(callData, model._apiSpecificRenderWindow);
80
-
81
- if (worldCoords.length && (model.activeState === model.widgetState.getMoveHandle() || isDragging)) {
82
- model.activeState.setOrigin(worldCoords);
83
- publicAPI.invokeInteractionEvent();
92
+ if (updateMoveHandle(callData) === macro.EVENT_ABORT) {
84
93
  return macro.EVENT_ABORT;
85
94
  }
86
95
  }
package/index.d.ts CHANGED
@@ -2,8 +2,8 @@
2
2
  /// <reference path="./interfaces.d.ts" />
3
3
  /// <reference path="./macros.d.ts" />
4
4
  /// <reference path="./vtk.d.ts" />
5
- /// <reference path="./Common/Core/CellArray.d.ts" />
6
5
  /// <reference path="./Common/Core/Base64.d.ts" />
6
+ /// <reference path="./Common/Core/CellArray.d.ts" />
7
7
  /// <reference path="./Common/Core/DataArray.d.ts" />
8
8
  /// <reference path="./Common/Core/Endian.d.ts" />
9
9
  /// <reference path="./Common/Core/HalfFloat.d.ts" />
package/macros.d.ts CHANGED
@@ -138,6 +138,16 @@ declare function getStateArrayMapFunc(item: any): any;
138
138
  */
139
139
  export function setImmediateVTK(fn: () => void ): void;
140
140
 
141
+ /**
142
+ * Measures the time it takes for a promise to finish from the time this function is invoked.
143
+ *
144
+ * The callback receives the time it took for the promise to resolve or reject.
145
+ *
146
+ * @param promise promise to measure
147
+ * @param callback called with the elapsed time for the promise
148
+ */
149
+ export function measurePromiseExecution(promise: Promise<any>, callback: (elapsed: number) => void): void;
150
+
141
151
  /**
142
152
  * Turns the provided publicAPI into a VtkObject
143
153
  *
@@ -631,6 +641,8 @@ declare const Macro: {
631
641
  getStateArrayMapFunc: typeof getStateArrayMapFunc,
632
642
  isVtkObject: typeof isVtkObject,
633
643
  keystore: typeof keystore,
644
+ measurePromiseExecution: typeof measurePromiseExecution,
645
+ moveToProtected: typeof moveToProtected,
634
646
  newInstance: typeof newInstance,
635
647
  normalizeWheel: typeof normalizeWheel,
636
648
  obj: typeof obj,
package/macros.js CHANGED
@@ -202,6 +202,20 @@ function getStateArrayMapFunc(item) {
202
202
  function setImmediateVTK(fn) {
203
203
  setTimeout(fn, 0);
204
204
  } // ----------------------------------------------------------------------------
205
+ // measurePromiseExecution
206
+ //
207
+ // Measures the time it takes for a promise to finish from
208
+ // the time this function is invoked.
209
+ // The callback receives the time it took for the promise to resolve or reject.
210
+ // ----------------------------------------------------------------------------
211
+
212
+ function measurePromiseExecution(promise, callback) {
213
+ var start = performance.now();
214
+ promise.finally(function () {
215
+ var delta = performance.now() - start;
216
+ callback(delta);
217
+ });
218
+ } // ----------------------------------------------------------------------------
205
219
  // vtkObject: modified(), onModified(callback), delete()
206
220
  // ----------------------------------------------------------------------------
207
221
 
@@ -1824,6 +1838,7 @@ var macro = {
1824
1838
  getStateArrayMapFunc: getStateArrayMapFunc,
1825
1839
  isVtkObject: isVtkObject,
1826
1840
  keystore: keystore,
1841
+ measurePromiseExecution: measurePromiseExecution,
1827
1842
  moveToProtected: moveToProtected,
1828
1843
  newInstance: newInstance,
1829
1844
  newTypedArray: newTypedArray,
@@ -1854,4 +1869,4 @@ var macro = {
1854
1869
  vtkWarningMacro: vtkWarningMacro
1855
1870
  };
1856
1871
 
1857
- export { EVENT_ABORT, TYPED_ARRAYS, VOID, _capitalize, algo, capitalize, chain, debounce, macro as default, event, formatBytesToProperUnit, formatNumbersWithThousandSeparator, get, getArray, isVtkObject, keystore, moveToProtected, newInstance, newTypedArray, newTypedArrayFrom, normalizeWheel, obj, proxy, proxyPropertyMapping, proxyPropertyState, set, setArray, setGet, setGetArray, setImmediateVTK, setLoggerFunction, throttle, traverseInstanceTree, uncapitalize, vtkDebugMacro, vtkErrorMacro, vtkInfoMacro, vtkLogMacro, vtkOnceErrorMacro, vtkWarningMacro };
1872
+ export { EVENT_ABORT, TYPED_ARRAYS, VOID, _capitalize, algo, capitalize, chain, debounce, macro as default, event, formatBytesToProperUnit, formatNumbersWithThousandSeparator, get, getArray, isVtkObject, keystore, measurePromiseExecution, moveToProtected, newInstance, newTypedArray, newTypedArrayFrom, normalizeWheel, obj, proxy, proxyPropertyMapping, proxyPropertyState, set, setArray, setGet, setGetArray, setImmediateVTK, setLoggerFunction, throttle, traverseInstanceTree, uncapitalize, vtkDebugMacro, vtkErrorMacro, vtkInfoMacro, vtkLogMacro, vtkOnceErrorMacro, vtkWarningMacro };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kitware/vtk.js",
3
- "version": "24.2.0",
3
+ "version": "24.3.0",
4
4
  "description": "Visualization Toolkit for the Web",
5
5
  "keywords": [
6
6
  "3d",