@kitware/vtk.js 25.11.1 → 25.13.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.
@@ -1,3 +1,5 @@
1
+ import { Nullable } from './../../types';
2
+
1
3
  /**
2
4
  *
3
5
  */
@@ -5,6 +7,12 @@ export interface IEdgeLocatorInitialValues {
5
7
  oriented?: boolean;
6
8
  }
7
9
 
10
+ export interface IEdge<T = unknown> {
11
+ key: number;
12
+ edgeId: number;
13
+ value?: T;
14
+ }
15
+
8
16
  export interface vtkEdgeLocator {
9
17
  /**
10
18
  * Remove all the edges previously added.
@@ -15,9 +23,9 @@ export interface vtkEdgeLocator {
15
23
  * Returns the inserted edge or null if no edge was inserted.
16
24
  * @param {Number} pointId0 Edge first point id
17
25
  * @param {Number} pointId1 Edge last point id
18
- * @return {key, edgeId, value} or null
26
+ * @return {IEdge|null} an edge object ({ key, edgeId, value }) or null
19
27
  */
20
- isInsertedEdge(pointId0: number, pointId1: number): { key: any; edgeId: number; value?: any } | null;
28
+ isInsertedEdge<T = unknown>(pointId0: number, pointId1: number): Nullable<IEdge<T>>;
21
29
 
22
30
  /**
23
31
  * Insert edge if it does not already exist.
@@ -25,16 +33,12 @@ export interface vtkEdgeLocator {
25
33
  *
26
34
  * @param {Number} pointId0 Edge first point id
27
35
  * @param {Number} pointId1 Edge last point id
28
- * @param {any} value Optional value option
29
- * @return {key, edgeId, value}
36
+ * @param {unknown} value Optional value option
37
+ * @return {IEdge|null} an edge object ({ key, edgeId, value }) or null
30
38
  * @see insertEdge()
31
39
  * @see isInsertedEdge()
32
40
  */
33
- insertUniqueEdge(
34
- pointId0: number,
35
- pointId1: number,
36
- value?: any
37
- ): { key: any; edgeId: number; value?: any };
41
+ insertUniqueEdge<T>(pointId0: number, pointId1: number, value?: T): IEdge<T>;
38
42
 
39
43
  /**
40
44
  * Insert edge. If the edge already exists, it is overwritten by this
@@ -43,15 +47,12 @@ export interface vtkEdgeLocator {
43
47
  * Returns the newly inserted edge.
44
48
  * @param {Number} pointId0 Edge first point id
45
49
  * @param {Number} pointId1 Edge last point id
46
- * @param {any} value Optional value option
47
- * @return {key, edgeId, value} or null
50
+ * @param {unknown} value Optional value option
51
+ * @return {Edge|null} an edge object ({ key, edgeId, value }) or null
48
52
  * @see isInsertedEdge
49
53
  * @see insertUniqueEdge
50
54
  */
51
- insertEdge(pointId0: number,
52
- pointId1: number,
53
- value?: any
54
- ): { key: any; edgeId: number; value?: any };
55
+ insertEdge<T>(pointId0: number, pointId1: number, value?: T): IEdge<T>;
55
56
  }
56
57
 
57
58
  // ----------------------------------------------------------------------------
@@ -45,8 +45,7 @@ var EdgeLocator = /*#__PURE__*/function () {
45
45
  key: "insertEdge",
46
46
  value: function insertEdge(pointId0, pointId1, newEdgeValue) {
47
47
  // Generate a unique key
48
- var key = this.computeEdgeKey(pointId0, pointId1); // Didn't find key, so add a new edge entry
49
-
48
+ var key = this.computeEdgeKey(pointId0, pointId1);
50
49
  var node = {
51
50
  key: key,
52
51
  edgeId: this.edgeMap.size,
@@ -327,7 +327,18 @@ export interface vtkOpenGLRenderWindow extends vtkOpenGLRenderWindowBase {
327
327
  setViewStream(stream: vtkViewStream): boolean;
328
328
 
329
329
  /**
330
- *
330
+ * Sets the pixel width and height of the rendered image.
331
+ *
332
+ * WebGL and WebGPU render windows apply these values to
333
+ * the width and height attribute of the canvas element.
334
+ *
335
+ * To match the device resolution in browser environments,
336
+ * multiply the container size by `window.devicePixelRatio`
337
+ * `apiSpecificRenderWindow.setSize(Math.floor(containerWidth * devicePixelRatio), Math.floor(containerHeight * devicePixelRatio));
338
+ * See the VTK.js FullscreenRenderWindow class for an example.
339
+ *
340
+ * @see getComputedDevicePixelRatio()
341
+ *
331
342
  * @param {Vector2} size
332
343
  */
333
344
  setSize(size: Vector2): void;
@@ -361,6 +372,19 @@ export interface vtkOpenGLRenderWindow extends vtkOpenGLRenderWindowBase {
361
372
  *
362
373
  */
363
374
  getVrResolution(): Vector2;
375
+
376
+ /**
377
+ * Scales the size of a browser CSS pixel to a rendered canvas pixel.
378
+ * `const renderedPixelWidth = cssPixelWidth * apiRenderWindow.getComputedDevicePixelRatio()`
379
+ * Use to scale rendered objects to a consistent perceived size or DOM pixel position.
380
+ *
381
+ * Rather than using window.devicePixelRatio directly, the device pixel ratio is inferred
382
+ * from the container CSS pixel size and rendered image pixel size. The user directly sets the rendered pixel size.
383
+ *
384
+ * @see setSize()
385
+ * @see getContainerSize()
386
+ */
387
+ getComputedDevicePixelRatio(): number;
364
388
  }
365
389
 
366
390
  /**
@@ -119,14 +119,20 @@ function vtkRenderWindowViewNode(publicAPI, model) {
119
119
  return publicAPI.displayToNormalizedDisplay(x2, y2, z);
120
120
  };
121
121
 
122
+ publicAPI.getComputedDevicePixelRatio = function () {
123
+ return model.size[0] / publicAPI.getContainerSize()[0];
124
+ };
125
+
126
+ publicAPI.getContainerSize = function () {
127
+ macro.vtkErrorMacro('not implemented');
128
+ };
129
+
122
130
  publicAPI.getPixelData = function (x1, y1, x2, y2) {
123
131
  macro.vtkErrorMacro('not implemented');
124
- return undefined;
125
132
  };
126
133
 
127
134
  publicAPI.createSelector = function () {
128
135
  macro.vtkErrorMacro('not implemented');
129
- return undefined;
130
136
  };
131
137
  } // ----------------------------------------------------------------------------
132
138
  // Object factory
@@ -119,7 +119,7 @@ function extend(publicAPI, model) {
119
119
  vtkProp.extend(publicAPI, model, initialValues);
120
120
  vtkInteractorObserver.extend(publicAPI, model, initialValues);
121
121
  macro.setGet(publicAPI, model, ['contextVisibility', 'handleVisibility', '_widgetManager']);
122
- macro.get(publicAPI, model, ['representations', 'widgetState']);
122
+ macro.get(publicAPI, model, ['representations', 'widgetState', 'activeState']);
123
123
  macro.moveToProtected(publicAPI, model, ['widgetManager']);
124
124
  macro.event(publicAPI, model, 'ActivateHandle');
125
125
  vtkAbstractWidget(publicAPI, model);
@@ -126,7 +126,8 @@ function vtkWidgetManager(publicAPI, model) {
126
126
  cwidth = _model$_apiSpecificRe2[0],
127
127
  cheight = _model$_apiSpecificRe2[1];
128
128
 
129
- var ratio = window.devicePixelRatio || 1;
129
+ var ratio = model._apiSpecificRenderWindow.getComputedDevicePixelRatio();
130
+
130
131
  var bwidth = String(cwidth / ratio);
131
132
  var bheight = String(cheight / ratio);
132
133
  var viewBox = "0 0 ".concat(cwidth, " ").concat(cheight);
@@ -243,7 +244,9 @@ function vtkWidgetManager(publicAPI, model) {
243
244
  vxmax = _renderer$getViewport2[2],
244
245
  vymax = _renderer$getViewport2[3];
245
246
 
246
- var rendererPixelDims = [rwW * (vxmax - vxmin), rwH * (vymax - vymin)];
247
+ var pixelRatio = _apiSpecificRenderWindow.getComputedDevicePixelRatio();
248
+
249
+ var rendererPixelDims = [rwW * (vxmax - vxmin) / pixelRatio, rwH * (vymax - vymin) / pixelRatio];
247
250
 
248
251
  var cameraPosition = _camera.getPosition();
249
252
 
@@ -277,7 +280,7 @@ function vtkWidgetManager(publicAPI, model) {
277
280
 
278
281
  function _updateSelection() {
279
282
  _updateSelection = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(callData, fromTouchEvent, callID) {
280
- var position, _yield$publicAPI$getS, requestCount, selectedState, representation, widget, activateHandle, i, w;
283
+ var position, _yield$publicAPI$getS, requestCount, selectedState, representation, widget, activateHandle, wantRender, i, w;
281
284
 
282
285
  return _regeneratorRuntime.wrap(function _callee3$(_context3) {
283
286
  while (1) {
@@ -322,12 +325,11 @@ function vtkWidgetManager(publicAPI, model) {
322
325
  // Default cursor behavior
323
326
  model._apiSpecificRenderWindow.setCursor(widget ? 'pointer' : 'default');
324
327
 
325
- if (model.widgetInFocus === widget && widget.hasFocus()) {
326
- activateHandle(widget); // Ken FIXME
327
-
328
- model._interactor.render();
328
+ wantRender = false;
329
329
 
330
- model._interactor.render();
330
+ if (model.widgetInFocus === widget && widget.hasFocus()) {
331
+ activateHandle(widget);
332
+ wantRender = true;
331
333
  } else {
332
334
  for (i = 0; i < model.widgets.length; i++) {
333
335
  w = model.widgets[i];
@@ -335,18 +337,19 @@ function vtkWidgetManager(publicAPI, model) {
335
337
  if (w === widget && w.getNestedPickable()) {
336
338
  activateHandle(w);
337
339
  model.activeWidget = w;
340
+ wantRender = true;
338
341
  } else {
342
+ wantRender || (wantRender = !!w.getActiveState());
339
343
  w.deactivateAllHandles();
340
344
  }
341
- } // Ken FIXME
342
-
343
-
344
- model._interactor.render();
345
+ }
346
+ }
345
347
 
348
+ if (wantRender) {
346
349
  model._interactor.render();
347
350
  }
348
351
 
349
- case 13:
352
+ case 15:
350
353
  case "end":
351
354
  return _context3.stop();
352
355
  }
@@ -600,7 +603,7 @@ function vtkWidgetManager(publicAPI, model) {
600
603
  model.selections = null;
601
604
 
602
605
  if (!model.pickingEnabled) {
603
- _context2.next = 24;
606
+ _context2.next = 26;
604
607
  break;
605
608
  }
606
609
 
@@ -636,7 +639,7 @@ function vtkWidgetManager(publicAPI, model) {
636
639
 
637
640
  case 16:
638
641
  if (!(!model._capturedBuffers || model.captureOn === CaptureOn.MOUSE_MOVE)) {
639
- _context2.next = 19;
642
+ _context2.next = 21;
640
643
  break;
641
644
  }
642
645
 
@@ -644,24 +647,28 @@ function vtkWidgetManager(publicAPI, model) {
644
647
  return captureBuffers(x, y, x, y);
645
648
 
646
649
  case 19:
650
+ _context2.next = 25;
651
+ break;
652
+
653
+ case 21:
647
654
  // or do we need a pixel that is outside the last capture?
648
655
  capturedRegion = model._capturedBuffers.area;
649
656
 
650
657
  if (!(x < capturedRegion[0] || x > capturedRegion[2] || y < capturedRegion[1] || y > capturedRegion[3])) {
651
- _context2.next = 23;
658
+ _context2.next = 25;
652
659
  break;
653
660
  }
654
661
 
655
- _context2.next = 23;
662
+ _context2.next = 25;
656
663
  return captureBuffers(x, y, x, y);
657
664
 
658
- case 23:
665
+ case 25:
659
666
  model.selections = model._capturedBuffers.generateSelection(x, y, x, y);
660
667
 
661
- case 24:
668
+ case 26:
662
669
  return _context2.abrupt("return", publicAPI.getSelectedData());
663
670
 
664
- case 25:
671
+ case 27:
665
672
  case "end":
666
673
  return _context2.stop();
667
674
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kitware/vtk.js",
3
- "version": "25.11.1",
3
+ "version": "25.13.0",
4
4
  "description": "Visualization Toolkit for the Web",
5
5
  "keywords": [
6
6
  "3d",