@kitware/vtk.js 22.2.1 → 22.2.2

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.
@@ -816,6 +816,12 @@ function vtkOpenGLRenderWindow(publicAPI, model) {
816
816
  return true;
817
817
  };
818
818
 
819
+ publicAPI.createSelector = function () {
820
+ var ret = vtkHardwareSelector.newInstance();
821
+ ret.setOpenGLRenderWindow(publicAPI);
822
+ return ret;
823
+ };
824
+
819
825
  publicAPI.delete = macro.chain(publicAPI.delete, publicAPI.setViewStream, deleteGLContext);
820
826
  } // ----------------------------------------------------------------------------
821
827
  // Object factory
@@ -123,6 +123,11 @@ function vtkRenderWindowViewNode(publicAPI, model) {
123
123
  macro.vtkErrorMacro('not implemented');
124
124
  return undefined;
125
125
  };
126
+
127
+ publicAPI.createSelector = function () {
128
+ macro.vtkErrorMacro('not implemented');
129
+ return undefined;
130
+ };
126
131
  } // ----------------------------------------------------------------------------
127
132
  // Object factory
128
133
  // ----------------------------------------------------------------------------
@@ -598,6 +598,13 @@ function vtkWebGPURenderWindow(publicAPI, model) {
598
598
  }
599
599
  }, _callee2);
600
600
  }));
601
+
602
+ publicAPI.createSelector = function () {
603
+ var ret = vtkWebGPUHardwareSelector.newInstance();
604
+ ret.setWebGPURenderWindow(publicAPI);
605
+ return ret;
606
+ };
607
+
601
608
  publicAPI.delete = macro.chain(publicAPI.delete, publicAPI.setViewStream);
602
609
  } // ----------------------------------------------------------------------------
603
610
  // Object factory
@@ -1,4 +1,6 @@
1
+ import _asyncToGenerator from '@babel/runtime/helpers/asyncToGenerator';
1
2
  import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
3
+ import _regeneratorRuntime from '@babel/runtime/regenerator';
2
4
  import { r as radiansFromDegrees } from '../../Common/Core/Math/index.js';
3
5
  import { FieldAssociations } from '../../Common/DataModel/DataSet/Constants.js';
4
6
  import macro from '../../macros.js';
@@ -10,7 +12,8 @@ import { diff } from './WidgetManager/vdom.js';
10
12
  var ViewTypes = WidgetManagerConst.ViewTypes,
11
13
  RenderingTypes = WidgetManagerConst.RenderingTypes,
12
14
  CaptureOn = WidgetManagerConst.CaptureOn;
13
- var vtkErrorMacro = macro.vtkErrorMacro;
15
+ var vtkErrorMacro = macro.vtkErrorMacro,
16
+ vtkWarningMacro = macro.vtkWarningMacro;
14
17
  var createSvgElement = vtkSVGRepresentation.createSvgElement,
15
18
  createSvgDomElement = vtkSVGRepresentation.createSvgDomElement;
16
19
  var viewIdCount = 1; // ----------------------------------------------------------------------------
@@ -267,17 +270,48 @@ function vtkWidgetManager(publicAPI, model) {
267
270
  model.widgets.forEach(updateWidgetForRender);
268
271
  }
269
272
 
270
- function captureBuffers(x1, y1, x2, y2) {
271
- renderPickingBuffer();
272
- model.selector.setArea(x1, y1, x2, y2);
273
- model.selector.releasePixBuffers();
274
- model.previousSelectedData = null;
275
- return model.selector.captureBuffers();
273
+ function captureBuffers(_x, _x2, _x3, _x4) {
274
+ return _captureBuffers.apply(this, arguments);
275
+ }
276
+
277
+ function _captureBuffers() {
278
+ _captureBuffers = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(x1, y1, x2, y2) {
279
+ return _regeneratorRuntime.wrap(function _callee3$(_context3) {
280
+ while (1) {
281
+ switch (_context3.prev = _context3.next) {
282
+ case 0:
283
+ if (!model._captureInProgress) {
284
+ _context3.next = 2;
285
+ break;
286
+ }
287
+
288
+ return _context3.abrupt("return");
289
+
290
+ case 2:
291
+ model._captureInProgress = true;
292
+ renderPickingBuffer();
293
+ model._capturedBuffers = null;
294
+ _context3.next = 7;
295
+ return model.selector.getSourceDataAsync(model.renderer, x1, y1, x2, y2);
296
+
297
+ case 7:
298
+ model._capturedBuffers = _context3.sent;
299
+ model.previousSelectedData = null;
300
+ renderFrontBuffer();
301
+ model._captureInProgress = false;
302
+
303
+ case 11:
304
+ case "end":
305
+ return _context3.stop();
306
+ }
307
+ }
308
+ }, _callee3);
309
+ }));
310
+ return _captureBuffers.apply(this, arguments);
276
311
  }
277
312
 
278
313
  publicAPI.enablePicking = function () {
279
314
  model.pickingEnabled = true;
280
- model.pickingAvailable = true;
281
315
  publicAPI.renderWidgets();
282
316
  };
283
317
 
@@ -288,7 +322,7 @@ function vtkWidgetManager(publicAPI, model) {
288
322
  w = _model$apiSpecificRen4[0],
289
323
  h = _model$apiSpecificRen4[1];
290
324
 
291
- model.pickingAvailable = captureBuffers(0, 0, w, h);
325
+ captureBuffers(0, 0, w, h);
292
326
  }
293
327
 
294
328
  renderFrontBuffer();
@@ -297,7 +331,6 @@ function vtkWidgetManager(publicAPI, model) {
297
331
 
298
332
  publicAPI.disablePicking = function () {
299
333
  model.pickingEnabled = false;
300
- model.pickingAvailable = false;
301
334
  };
302
335
 
303
336
  publicAPI.setRenderer = function (renderer) {
@@ -307,9 +340,8 @@ function vtkWidgetManager(publicAPI, model) {
307
340
  subscriptions.pop().unsubscribe();
308
341
  }
309
342
 
310
- model.selector = model.apiSpecificRenderWindow.getSelector();
343
+ model.selector = model.apiSpecificRenderWindow.createSelector();
311
344
  model.selector.setFieldAssociation(FieldAssociations.FIELD_ASSOCIATION_POINTS);
312
- model.selector.attach(model.apiSpecificRenderWindow, model.renderer);
313
345
  subscriptions.push(model.interactor.onRenderEvent(updateSvg));
314
346
  subscriptions.push(model.apiSpecificRenderWindow.onModified(setSvgSize));
315
347
  setSvgSize();
@@ -323,61 +355,90 @@ function vtkWidgetManager(publicAPI, model) {
323
355
  model.isAnimating = false;
324
356
  publicAPI.renderWidgets();
325
357
  }));
326
- subscriptions.push(model.interactor.onMouseMove(function (_ref) {
327
- var position = _ref.position;
328
-
329
- if (model.isAnimating || !model.pickingAvailable) {
330
- return;
331
- }
332
-
333
- publicAPI.updateSelectionFromXY(position.x, position.y);
334
-
335
- var _publicAPI$getSelecte = publicAPI.getSelectedData(),
336
- requestCount = _publicAPI$getSelecte.requestCount,
337
- selectedState = _publicAPI$getSelecte.selectedState,
338
- representation = _publicAPI$getSelecte.representation,
339
- widget = _publicAPI$getSelecte.widget;
340
-
341
- if (requestCount) {
342
- // Call activate only once
343
- return;
344
- } // Default cursor behavior
345
-
346
-
347
- model.apiSpecificRenderWindow.setCursor(widget ? 'pointer' : 'default');
348
-
349
- if (model.widgetInFocus === widget && widget.hasFocus()) {
350
- widget.activateHandle({
351
- selectedState: selectedState,
352
- representation: representation
353
- }); // Ken FIXME
354
-
355
- model.interactor.render();
356
- model.interactor.render();
357
- } else {
358
- for (var i = 0; i < model.widgets.length; i++) {
359
- var w = model.widgets[i];
360
-
361
- if (w === widget && w.getNestedPickable()) {
362
- w.activateHandle({
363
- selectedState: selectedState,
364
- representation: representation
365
- });
366
- model.activeWidget = w;
367
- } else {
368
- w.deactivateAllHandles();
358
+ subscriptions.push(model.interactor.onMouseMove( /*#__PURE__*/function () {
359
+ var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(_ref) {
360
+ var position, _yield$publicAPI$getS, requestCount, selectedState, representation, widget, i, w;
361
+
362
+ return _regeneratorRuntime.wrap(function _callee$(_context) {
363
+ while (1) {
364
+ switch (_context.prev = _context.next) {
365
+ case 0:
366
+ position = _ref.position;
367
+
368
+ if (!(model.isAnimating || !model.pickingEnabled || model._selectionInProgress)) {
369
+ _context.next = 3;
370
+ break;
371
+ }
372
+
373
+ return _context.abrupt("return");
374
+
375
+ case 3:
376
+ model._selectionInProgress = true;
377
+ _context.next = 6;
378
+ return publicAPI.getSelectedDataForXY(position.x, position.y);
379
+
380
+ case 6:
381
+ _yield$publicAPI$getS = _context.sent;
382
+ requestCount = _yield$publicAPI$getS.requestCount;
383
+ selectedState = _yield$publicAPI$getS.selectedState;
384
+ representation = _yield$publicAPI$getS.representation;
385
+ widget = _yield$publicAPI$getS.widget;
386
+ model._selectionInProgress = false;
387
+
388
+ if (!requestCount) {
389
+ _context.next = 14;
390
+ break;
391
+ }
392
+
393
+ return _context.abrupt("return");
394
+
395
+ case 14:
396
+ // Default cursor behavior
397
+ model.apiSpecificRenderWindow.setCursor(widget ? 'pointer' : 'default');
398
+
399
+ if (model.widgetInFocus === widget && widget.hasFocus()) {
400
+ widget.activateHandle({
401
+ selectedState: selectedState,
402
+ representation: representation
403
+ }); // Ken FIXME
404
+
405
+ model.interactor.render();
406
+ model.interactor.render();
407
+ } else {
408
+ for (i = 0; i < model.widgets.length; i++) {
409
+ w = model.widgets[i];
410
+
411
+ if (w === widget && w.getNestedPickable()) {
412
+ w.activateHandle({
413
+ selectedState: selectedState,
414
+ representation: representation
415
+ });
416
+ model.activeWidget = w;
417
+ } else {
418
+ w.deactivateAllHandles();
419
+ }
420
+ } // Ken FIXME
421
+
422
+
423
+ model.interactor.render();
424
+ model.interactor.render();
425
+ }
426
+
427
+ case 16:
428
+ case "end":
429
+ return _context.stop();
430
+ }
369
431
  }
370
- } // Ken FIXME
432
+ }, _callee);
433
+ }));
371
434
 
372
-
373
- model.interactor.render();
374
- model.interactor.render();
375
- }
376
- }));
435
+ return function (_x5) {
436
+ return _ref2.apply(this, arguments);
437
+ };
438
+ }()));
377
439
  publicAPI.modified();
378
440
 
379
441
  if (model.pickingEnabled) {
380
- // also sets pickingAvailable
381
442
  publicAPI.enablePicking();
382
443
  }
383
444
 
@@ -453,7 +514,93 @@ function vtkWidgetManager(publicAPI, model) {
453
514
  }
454
515
  };
455
516
 
517
+ publicAPI.getSelectedDataForXY = /*#__PURE__*/function () {
518
+ var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(x, y) {
519
+ var i, widget, hoveredSVGReps, selection, capturedRegion;
520
+ return _regeneratorRuntime.wrap(function _callee2$(_context2) {
521
+ while (1) {
522
+ switch (_context2.prev = _context2.next) {
523
+ case 0:
524
+ model.selections = null;
525
+
526
+ if (!model.pickingEnabled) {
527
+ _context2.next = 24;
528
+ break;
529
+ }
530
+
531
+ i = 0;
532
+
533
+ case 3:
534
+ if (!(i < model.widgets.length)) {
535
+ _context2.next = 16;
536
+ break;
537
+ }
538
+
539
+ widget = model.widgets[i];
540
+ hoveredSVGReps = widget.getRepresentations().filter(function (r) {
541
+ return r.isA('vtkSVGRepresentation') && r.getHover() != null;
542
+ });
543
+
544
+ if (!hoveredSVGReps.length) {
545
+ _context2.next = 13;
546
+ break;
547
+ }
548
+
549
+ selection = vtkSelectionNode.newInstance();
550
+ selection.getProperties().compositeID = hoveredSVGReps[0].getHover();
551
+ selection.getProperties().widget = widget;
552
+ selection.getProperties().representation = hoveredSVGReps[0];
553
+ model.selections = [selection];
554
+ return _context2.abrupt("return", publicAPI.getSelectedData());
555
+
556
+ case 13:
557
+ ++i;
558
+ _context2.next = 3;
559
+ break;
560
+
561
+ case 16:
562
+ if (!(!model._capturedBuffers || model.captureOn === CaptureOn.MOUSE_MOVE)) {
563
+ _context2.next = 19;
564
+ break;
565
+ }
566
+
567
+ _context2.next = 19;
568
+ return captureBuffers(x, y, x, y);
569
+
570
+ case 19:
571
+ // or do we need a pixel that is outside the last capture?
572
+ capturedRegion = model._capturedBuffers.area;
573
+
574
+ if (!(x < capturedRegion[0] || x > capturedRegion[2] || y < capturedRegion[1] || y > capturedRegion[3])) {
575
+ _context2.next = 23;
576
+ break;
577
+ }
578
+
579
+ _context2.next = 23;
580
+ return captureBuffers(x, y, x, y);
581
+
582
+ case 23:
583
+ model.selections = model._capturedBuffers.generateSelection(x, y, x, y);
584
+
585
+ case 24:
586
+ return _context2.abrupt("return", publicAPI.getSelectedData());
587
+
588
+ case 25:
589
+ case "end":
590
+ return _context2.stop();
591
+ }
592
+ }
593
+ }, _callee2);
594
+ }));
595
+
596
+ return function (_x6, _x7) {
597
+ return _ref3.apply(this, arguments);
598
+ };
599
+ }();
600
+
456
601
  publicAPI.updateSelectionFromXY = function (x, y) {
602
+ vtkWarningMacro('updateSelectionFromXY is deprecated, please use getSelectedDataForXY');
603
+
457
604
  if (model.pickingEnabled) {
458
605
  // First pick SVG representation
459
606
  for (var i = 0; i < model.widgets.length; ++i) {
@@ -473,20 +620,14 @@ function vtkWidgetManager(publicAPI, model) {
473
620
  } // Then pick regular representations.
474
621
 
475
622
 
476
- var pickingAvailable = model.pickingAvailable;
477
-
478
623
  if (model.captureOn === CaptureOn.MOUSE_MOVE) {
479
- pickingAvailable = captureBuffers(x, y, x, y);
480
- renderFrontBuffer();
481
- }
482
-
483
- if (pickingAvailable) {
484
- model.selections = model.selector.generateSelection(x, y, x, y);
624
+ captureBuffers(x, y, x, y);
485
625
  }
486
626
  }
487
627
  };
488
628
 
489
629
  publicAPI.updateSelectionFromMouseEvent = function (event) {
630
+ vtkWarningMacro('updateSelectionFromMouseEvent is deprecated, please use getSelectedDataForXY');
490
631
  var pageX = event.pageX,
491
632
  pageY = event.pageY;
492
633
 
@@ -603,7 +744,6 @@ var DEFAULT_VALUES = {
603
744
  widgets: [],
604
745
  renderer: null,
605
746
  viewType: ViewTypes.DEFAULT,
606
- pickingAvailable: false,
607
747
  isAnimating: false,
608
748
  pickingEnabled: true,
609
749
  selections: null,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kitware/vtk.js",
3
- "version": "22.2.1",
3
+ "version": "22.2.2",
4
4
  "description": "Visualization Toolkit for the Web",
5
5
  "keywords": [
6
6
  "3d",