@kitware/vtk.js 25.11.1 → 25.12.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
@@ -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
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kitware/vtk.js",
3
- "version": "25.11.1",
3
+ "version": "25.12.0",
4
4
  "description": "Visualization Toolkit for the Web",
5
5
  "keywords": [
6
6
  "3d",