@kitware/vtk.js 26.7.0 → 26.8.1

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.
@@ -0,0 +1,27 @@
1
+ export declare enum SelectionContent {
2
+ GLOBALIDS = 0,
3
+ PEDIGREEIDS = 1,
4
+ VALUES = 2,
5
+ INDICES = 3,
6
+ FRUSTUM = 4,
7
+ LOCATIONS = 5,
8
+ THRESHOLDS = 6,
9
+ BLOCKS = 7,
10
+ QUERY = 8,
11
+ }
12
+
13
+ export declare enum SelectionField {
14
+ CELL = 0,
15
+ POINT = 1,
16
+ FIELD = 2,
17
+ VERTEX = 3,
18
+ EDGE = 4,
19
+ ROW = 5,
20
+ }
21
+
22
+ declare const _default: {
23
+ SelectionContent: typeof SelectionContent;
24
+ SelectionField: typeof SelectionField;
25
+ }
26
+
27
+ export default _default;
@@ -1,35 +1,70 @@
1
1
  import { vtkObject } from './../../interfaces' ;
2
2
  import { Bounds } from './../../types';
3
+ import { SelectionContent, SelectionField } from './SelectionNode/Constants';
4
+ import vtkProp from './../../Rendering/Core/Prop';
3
5
 
4
- export enum SelectionContent {
5
- GLOBALIDS,
6
- PEDIGREEIDS,
7
- VALUES,
8
- INDICES,
9
- FRUSTUM,
10
- LOCATIONS,
11
- THRESHOLDS,
12
- BLOCKS,
13
- QUERY,
6
+ export interface ISelectionNodeInitialValues {
7
+ contentType?: SelectionContent;
8
+ fieldType?: SelectionField;
9
+ properties?: ISelectionNodeProperties;
10
+ selectionList?: number[];
14
11
  }
15
12
 
16
- export enum SelectionField {
17
- CELL,
18
- POINT,
19
- FIELD,
20
- VERTEX,
21
- EDGE,
22
- ROW,
13
+ export interface ISelectionNodeProperties {
14
+ propID?: number;
15
+ prop?: vtkProp;
16
+ compositeID?: number;
17
+ attributeID?: number;
18
+ pixelCount?: number;
19
+ displayPosition?: [number, number, number];
20
+ worldPosition?: [number, number, number];
23
21
  }
24
22
 
25
- export interface ISelectionNodeInitialValues {}
26
-
27
23
  export interface vtkSelectionNode extends vtkObject {
28
-
29
24
  /**
30
- *
25
+ * Get the bounds of the selection points.
31
26
  */
32
27
  getBounds(): Bounds;
28
+
29
+ /**
30
+ * Returns -1 if not initialized.
31
+ */
32
+ getContentType(): SelectionContent | -1;
33
+
34
+ /**
35
+ * This functions is called internally by VTK.js and is not intended for public use.
36
+ */
37
+ setContentType(contentType: SelectionContent): void;
38
+
39
+ /**
40
+ * Returns -1 if not initialized.
41
+ */
42
+ getFieldType(): SelectionField | -1;
43
+
44
+ /**
45
+ * This functions is called internally by VTK.js and is not intended for public use.
46
+ */
47
+ setFieldType(fieldType: SelectionField): void;
48
+
49
+ /**
50
+ * Get the selection properties.
51
+ */
52
+ getProperties(): ISelectionNodeProperties;
53
+
54
+ /**
55
+ * This functions is called internally by VTK.js and is not intended for public use.
56
+ */
57
+ setProperties(properties: ISelectionNodeProperties);
58
+
59
+ /**
60
+ * Get the list of the underlying selected attribute IDs.
61
+ */
62
+ getSelectionList(): number[];
63
+
64
+ /**
65
+ * This functions is called internally by VTK.js and is not intended for public use.
66
+ */
67
+ setSelectionList(selectionAttributeIDs: ISelectionNodeProperties);
33
68
  }
34
69
 
35
70
  /**
@@ -57,5 +92,7 @@ export function newInstance(initialValues?: ISelectionNodeInitialValues): vtkSel
57
92
  export declare const vtkSelectionNode: {
58
93
  newInstance: typeof newInstance,
59
94
  extend: typeof extend;
95
+ SelectionContent: typeof SelectionContent;
96
+ SelectionField: typeof SelectionField;
60
97
  };
61
98
  export default vtkSelectionNode;
@@ -1,10 +1,9 @@
1
1
  import vtkDataArray from './../../Common/Core/DataArray';
2
- import { vtkObject } from './../../interfaces';
2
+ import vtkScalarsToColors from './../../Common/Core/ScalarsToColors'
3
3
  import { ColorSpace, Scale } from './ColorTransferFunction/Constants';
4
4
 
5
5
 
6
- /* TODO: use VtkScalarsToColors instead of VtkObject */
7
- export interface vtkColorTransferFunction extends vtkObject {
6
+ export interface vtkColorTransferFunction extends vtkScalarsToColors {
8
7
  /**
9
8
  * Add a point defined in RGB
10
9
  * @param {Number} x The index of the point.
@@ -270,13 +269,6 @@ export interface vtkColorTransferFunction extends vtkObject {
270
269
  */
271
270
  fillFromDataPointer(nb: number, ptr: any): void;
272
271
 
273
- /**
274
- * Set the range of scalars being mapped.
275
- * @param {Number} min
276
- * @param {Number} max
277
- */
278
- setMappingRange(min: number, max: number): void;
279
-
280
272
  /**
281
273
  * Remove all points out of the new range, and make sure there is a point at
282
274
  * each end of that range.
@@ -485,6 +485,10 @@ export interface vtkMapper extends vtkAbstractMapper3D {
485
485
  *
486
486
  */
487
487
  setInterpolateScalarsBeforeMapping(interpolateScalarsBeforeMapping: boolean): boolean;
488
+
489
+ setResolveCoincidentTopologyToPolygonOffset(): boolean;
490
+
491
+ setResolveCoincidentTopologyToOff(): boolean;
488
492
  }
489
493
 
490
494
  /**
@@ -47,7 +47,9 @@ function vtkRenderWindowInteractor(publicAPI, model) {
47
47
 
48
48
  var animationRequesters = new Set(); // map from pointerId to { pointerId: number, position: [x, y] }
49
49
 
50
- var pointerCache = new Map(); // Public API methods
50
+ var pointerCache = new Map(); // Factor to apply on wheel spin.
51
+
52
+ var wheelCoefficient = 1; // Public API methods
51
53
  //----------------------------------------------------------------------
52
54
 
53
55
  publicAPI.start = function () {
@@ -622,7 +624,27 @@ function vtkRenderWindowInteractor(publicAPI, model) {
622
624
  var callData = _objectSpread(_objectSpread(_objectSpread({}, normalizeWheel(event)), getModifierKeysFor(event)), {}, {
623
625
  position: getScreenEventPositionFor(event),
624
626
  deviceType: getDeviceTypeFor(event)
625
- });
627
+ }); // Wheel events are thought to scroll pages (i.e. multiple lines at once).
628
+ // See normalizeWheel() documentation for more context.
629
+ // While trackpad wheel events are many small (<1) wheel spins,
630
+ // mouse wheel events have absolute spin values higher than 1.
631
+ // Here the first spin value is "recorded", and used to normalize
632
+ // all the following mouse wheel events.
633
+
634
+
635
+ if (model.wheelTimeoutID === 0) {
636
+ // 0.4 is roughly half-way between a large trackpad first event and small
637
+ // mouse wheel first event.
638
+ if (Math.abs(callData.spinY) > 0.4) {
639
+ // Event is coming from mouse wheel
640
+ wheelCoefficient = Math.abs(callData.spinY);
641
+ } else {
642
+ // Event is coming from trackpad
643
+ wheelCoefficient = 1;
644
+ }
645
+ }
646
+
647
+ callData.spinY /= wheelCoefficient;
626
648
 
627
649
  if (model.wheelTimeoutID === 0) {
628
650
  publicAPI.startMouseWheelEvent(callData);
@@ -628,6 +628,32 @@ export interface vtkRenderer extends vtkViewport {
628
628
  * Not Implemented yet
629
629
  */
630
630
  visibleVolumeCount(): any;
631
+
632
+ /**
633
+ * Set the viewport background.
634
+ *
635
+ * @param {Number} r Defines the red component (between 0 and 1).
636
+ * @param {Number} g Defines the green component (between 0 and 1).
637
+ * @param {Number} b Defines the blue component (between 0 and 1).
638
+ * @param {Number} b Defines the alpha component (between 0 and 1).
639
+ */
640
+ setBackground(r: number, g: number, b: number, a: number): boolean;
641
+
642
+ /**
643
+ * Set the viewport background.
644
+ *
645
+ * @param {Number} r Defines the red component (between 0 and 1).
646
+ * @param {Number} g Defines the green component (between 0 and 1).
647
+ * @param {Number} b Defines the blue component (between 0 and 1).
648
+ */
649
+ setBackground(r: number, g: number, b: number): boolean;
650
+
651
+ /**
652
+ * Set the viewport background.
653
+ *
654
+ * @param {Number[]} background The RGB color array.
655
+ */
656
+ setBackground(background: number[]): boolean;
631
657
  }
632
658
 
633
659
  /**
@@ -151,7 +151,7 @@ function vtkOpenGLOrderIndependentTranslucentPass(publicAPI, model) {
151
151
  // have the forward pass use a texture backed zbuffer
152
152
 
153
153
  if (forwardPass.getOpaqueActorCount() > 0) {
154
- forwardPass.setCurrentOperation('opaquePass');
154
+ forwardPass.setCurrentOperation('opaqueZBufferPass');
155
155
  renNode.traverse(forwardPass);
156
156
  }
157
157
 
@@ -0,0 +1,10 @@
1
+ export declare enum XrSessionTypes {
2
+ HmdVR = 0,
3
+ MobileAR = 1,
4
+ LookingGlassVR = 2
5
+ }
6
+
7
+ declare const _default: {
8
+ XrSessionTypes: typeof XrSessionTypes;
9
+ };
10
+ export default _default;
@@ -0,0 +1,13 @@
1
+ var XrSessionTypes = {
2
+ HmdVR: 0,
3
+ // Head-mounted display (HMD), two-camera virtual reality session
4
+ MobileAR: 1,
5
+ // Mobile device, single-camera augmented reality session
6
+ LookingGlassVR: 2 // Looking Glass hologram display, N-camera virtual reality session
7
+
8
+ };
9
+ var Constants = {
10
+ XrSessionTypes: XrSessionTypes
11
+ };
12
+
13
+ export { XrSessionTypes, Constants as default };
@@ -34,9 +34,9 @@ export interface IOpenGLRenderWindowInitialValues {
34
34
  }
35
35
 
36
36
  export interface ICaptureOptions {
37
- resetCamera: boolean;
38
- size: Size;
39
- scale: number
37
+ resetCamera?: boolean;
38
+ size?: Size;
39
+ scale?: number
40
40
  }
41
41
 
42
42
  export interface I3DContextOptions {
@@ -232,19 +232,34 @@ export interface vtkOpenGLRenderWindow extends vtkOpenGLRenderWindowBase {
232
232
  get3DContext(options: I3DContextOptions): Nullable<WebGLRenderingContext>;
233
233
 
234
234
  /**
235
- *
235
+ * Request an XR session on the user device with WebXR,
236
+ * typically in response to a user request such as a button press.
236
237
  */
237
- startVR(): void;
238
+ startXR(): void;
239
+
240
+ /**
241
+ * When an XR session is available, set up the XRWebGLLayer
242
+ * and request the first animation frame for the device
243
+ */
244
+ enterXR(): void,
245
+
246
+ /**
247
+ * Adjust world-to-physical parameters for different viewing modalities
248
+ *
249
+ * @param {Number} inputRescaleFactor
250
+ * @param {Number} inputTranslateZ
251
+ */
252
+ resetXRScene(inputRescaleFactor: number, inputTranslateZ: number): void,
238
253
 
239
254
  /**
240
- *
255
+ * Request to stop the current XR session
241
256
  */
242
- stopVR(): void;
257
+ stopXR(): void;
243
258
 
244
259
  /**
245
260
  *
246
261
  */
247
- vrRender(): void;
262
+ xrRender(): void;
248
263
 
249
264
  /**
250
265
  *
@@ -305,7 +320,7 @@ export interface vtkOpenGLRenderWindow extends vtkOpenGLRenderWindowBase {
305
320
  * @param {String} format
306
321
  * @param {ICaptureOptions} options
307
322
  */
308
- captureNextImage(format: string, options: ICaptureOptions): Nullable<Promise<string>>;
323
+ captureNextImage(format: string, options?: ICaptureOptions): Nullable<Promise<string>>;
309
324
 
310
325
  /**
311
326
  *
@@ -12,10 +12,12 @@ import vtkTextureUnitManager from './TextureUnitManager.js';
12
12
  import vtkViewNodeFactory from './ViewNodeFactory.js';
13
13
  import vtkRenderPass from '../SceneGraph/RenderPass.js';
14
14
  import vtkRenderWindowViewNode from '../SceneGraph/RenderWindowViewNode.js';
15
+ import Constants from './RenderWindow/Constants.js';
15
16
  import { createContextProxyHandler, GET_UNDERLYING_CONTEXT } from './RenderWindow/ContextProxy.js';
16
17
 
17
18
  var vtkDebugMacro = macro.vtkDebugMacro,
18
19
  vtkErrorMacro = macro.vtkErrorMacro;
20
+ var XrSessionTypes = Constants.XrSessionTypes;
19
21
  var SCREENSHOT_PLACEHOLDER = {
20
22
  position: 'absolute',
21
23
  top: 0,
@@ -266,12 +268,13 @@ function vtkOpenGLRenderWindow(publicAPI, model) {
266
268
  // typically in response to a user request such as a button press
267
269
 
268
270
 
269
- publicAPI.startXR = function (isAR) {
271
+ publicAPI.startXR = function (xrSessionType) {
270
272
  if (navigator.xr === undefined) {
271
273
  throw new Error('WebXR is not available');
272
274
  }
273
275
 
274
- model.xrSessionIsAR = isAR;
276
+ model.xrSessionType = xrSessionType !== undefined ? xrSessionType : XrSessionTypes.HmdVR;
277
+ var isAR = xrSessionType === XrSessionTypes.MobileAR;
275
278
  var sessionType = isAR ? 'immersive-ar' : 'immersive-vr';
276
279
 
277
280
  if (!navigator.xr.isSessionSupported(sessionType)) {
@@ -348,16 +351,17 @@ function vtkOpenGLRenderWindow(publicAPI, model) {
348
351
  var inputRescaleFactor = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : DEFAULT_RESET_FACTORS.vr.rescaleFactor;
349
352
  var inputTranslateZ = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : DEFAULT_RESET_FACTORS.vr.translateZ;
350
353
  // Adjust world-to-physical parameters for different modalities
351
- // Default parameter values are for VR (model.xrSessionIsAR == false)
354
+ // Default parameter values are for HMD VR
352
355
  var rescaleFactor = inputRescaleFactor;
353
356
  var translateZ = inputTranslateZ;
357
+ var isXrSessionAR = model.xrSessionType === XrSessionTypes.MobileAR;
354
358
 
355
- if (model.xrSessionIsAR && rescaleFactor === DEFAULT_RESET_FACTORS.vr.rescaleFactor) {
359
+ if (isXrSessionAR && rescaleFactor === DEFAULT_RESET_FACTORS.vr.rescaleFactor) {
356
360
  // Scale down by default in AR
357
361
  rescaleFactor = DEFAULT_RESET_FACTORS.ar.rescaleFactor;
358
362
  }
359
363
 
360
- if (model.xrSessionIsAR && translateZ === DEFAULT_RESET_FACTORS.vr.translateZ) {
364
+ if (isXrSessionAR && translateZ === DEFAULT_RESET_FACTORS.vr.translateZ) {
361
365
  // Default closer to the camera in AR
362
366
  translateZ = DEFAULT_RESET_FACTORS.ar.translateZ;
363
367
  }
@@ -444,7 +448,7 @@ function vtkOpenGLRenderWindow(publicAPI, model) {
444
448
  if (xrPose) {
445
449
  gl = publicAPI.get3DContext();
446
450
 
447
- if (model.xrSessionIsAR && model.oldCanvasSize !== undefined) {
451
+ if (model.xrSessionType === XrSessionTypes.MobileAR && model.oldCanvasSize !== undefined) {
448
452
  gl.canvas.width = model.oldCanvasSize[0];
449
453
  gl.canvas.height = model.oldCanvasSize[1];
450
454
  }
@@ -452,16 +456,16 @@ function vtkOpenGLRenderWindow(publicAPI, model) {
452
456
  glLayer = xrSession.renderState.baseLayer;
453
457
  gl.bindFramebuffer(gl.FRAMEBUFFER, glLayer.framebuffer);
454
458
  gl.clear(gl.COLOR_BUFFER_BIT);
455
- gl.clear(gl.DEPTH_BUFFER_BIT); // get the first renderer
459
+ gl.clear(gl.DEPTH_BUFFER_BIT);
460
+ publicAPI.setSize(glLayer.framebufferWidth, glLayer.framebufferHeight); // get the first renderer
456
461
 
457
462
  ren = model.renderable.getRenderers()[0]; // Do a render pass for each eye
458
463
 
459
- xrPose.views.forEach(function (view) {
460
- var viewport = glLayer.getViewport(view);
461
- gl.viewport(viewport.x, viewport.y, viewport.width, viewport.height); // TODO: Appropriate handling for AR passthrough on HMDs
464
+ xrPose.views.forEach(function (view, index) {
465
+ var viewport = glLayer.getViewport(view); // TODO: Appropriate handling for AR passthrough on HMDs
462
466
  // with two eyes will require further investigation.
463
467
 
464
- if (!model.xrSessionIsAR) {
468
+ if (model.xrSessionType === XrSessionTypes.HmdVR) {
465
469
  if (view.eye === 'left') {
466
470
  ren.setViewport(0, 0, 0.5, 1.0);
467
471
  } else if (view.eye === 'right') {
@@ -470,12 +474,24 @@ function vtkOpenGLRenderWindow(publicAPI, model) {
470
474
  // No handling for non-eye viewport
471
475
  return;
472
476
  }
477
+ } else if (model.xrSessionType === XrSessionTypes.LookingGlassVR) {
478
+ var startX = viewport.x / glLayer.framebufferWidth;
479
+ var startY = viewport.y / glLayer.framebufferHeight;
480
+ var endX = (viewport.x + viewport.width) / glLayer.framebufferWidth;
481
+ var endY = (viewport.y + viewport.height) / glLayer.framebufferHeight;
482
+ ren.setViewport(startX, startY, endX, endY);
483
+ } else {
484
+ ren.setViewport(0, 0, 1, 1);
473
485
  }
474
486
 
475
487
  ren.getActiveCamera().computeViewParametersFromPhysicalMatrix(view.transform.inverse.matrix);
476
488
  ren.getActiveCamera().setProjectionMatrix(view.projectionMatrix);
477
489
  publicAPI.traverseAllPasses();
478
- });
490
+ }); // Reset scissorbox before any subsequent rendering to external displays
491
+ // on frame end, such as rendering to a Looking Glass display.
492
+
493
+ gl.scissor(0, 0, glLayer.framebufferWidth, glLayer.framebufferHeight);
494
+ gl.disable(gl.SCISSOR_TEST);
479
495
  }
480
496
 
481
497
  case 5:
@@ -919,7 +935,6 @@ var DEFAULT_VALUES = {
919
935
  // attempt webgl2 on by default
920
936
  activeFramebuffer: null,
921
937
  xrSession: null,
922
- xrSessionIsAR: false,
923
938
  xrReferenceSpace: null,
924
939
  xrSupported: true,
925
940
  imageFormat: 'image/png',
@@ -376,16 +376,19 @@ function vtkOpenGLSurfaceLICInterface(publicAPI, model) {
376
376
  fb.bind();
377
377
  model.geometryImage.activate();
378
378
  model.vectorImage.activate();
379
- model.maskVectorImage.activate();
379
+ model.maskVectorImage.activate(); // Don't use location 1 as it can be used by order independant translucent pass
380
+ // Translucent pass uses location 1 because of this line:
381
+ // gl_FragData[1].r = weight;
382
+
380
383
  fb.removeColorBuffer(0);
381
- fb.removeColorBuffer(1);
382
384
  fb.removeColorBuffer(2);
385
+ fb.removeColorBuffer(3);
383
386
  fb.setColorBuffer(model.geometryImage, 0);
384
- fb.setColorBuffer(model.vectorImage, 1);
385
- fb.setColorBuffer(model.maskVectorImage, 2);
387
+ fb.setColorBuffer(model.vectorImage, 2);
388
+ fb.setColorBuffer(model.maskVectorImage, 3);
386
389
  fb.setDepthBuffer(model.depthTexture);
387
390
  var gl = model.context;
388
- gl.drawBuffers([gl.COLOR_ATTACHMENT0, gl.COLOR_ATTACHMENT1, gl.COLOR_ATTACHMENT2]);
391
+ gl.drawBuffers([gl.COLOR_ATTACHMENT0, gl.NONE, gl.COLOR_ATTACHMENT2, gl.COLOR_ATTACHMENT3]);
389
392
  gl.viewport.apply(gl, [0, 0].concat(_toConsumableArray(model.size)));
390
393
  gl.scissor.apply(gl, [0, 0].concat(_toConsumableArray(model.size)));
391
394
  gl.disable(gl.BLEND);
@@ -30,7 +30,7 @@ function vtkOpenGLSurfaceLICMapper(publicAPI, model) {
30
30
  var array = model.renderable.getInputArrayToProcess(0);
31
31
 
32
32
  if (array && model.canDrawLIC) {
33
- FSSource = vtkShaderProgram.substitute(FSSource, '//VTK::Output::Dec', ['//VTK::Output::Dec', 'layout(location = 1) out vec4 vectorTexture;', 'layout(location = 2) out vec4 maskVectorTexture;']).result;
33
+ FSSource = vtkShaderProgram.substitute(FSSource, '//VTK::Output::Dec', ['//VTK::Output::Dec', 'layout(location = 2) out vec4 vectorTexture;', 'layout(location = 3) out vec4 maskVectorTexture;']).result;
34
34
  var arrayName = array.getName();
35
35
  var attributeName = "".concat(arrayName, "MC"); // We need normals even with no lighting
36
36
 
package/index.d.ts CHANGED
@@ -43,6 +43,7 @@
43
43
  /// <reference path="./Common/DataModel/PolyLine.d.ts" />
44
44
  /// <reference path="./Common/DataModel/Polygon.d.ts" />
45
45
  /// <reference path="./Common/DataModel/Quad.d.ts" />
46
+ /// <reference path="./Common/DataModel/SelectionNode/Constants.d.ts" />
46
47
  /// <reference path="./Common/DataModel/SelectionNode.d.ts" />
47
48
  /// <reference path="./Common/DataModel/Sphere.d.ts" />
48
49
  /// <reference path="./Common/DataModel/Spline1D.d.ts" />
@@ -191,6 +192,7 @@
191
192
  /// <reference path="./Rendering/Misc/SynchronizableRenderWindow/ObjectManager.d.ts" />
192
193
  /// <reference path="./Rendering/Misc/SynchronizableRenderWindow.d.ts" />
193
194
  /// <reference path="./Rendering/Misc/TextureLODsDownloader.d.ts" />
195
+ /// <reference path="./Rendering/OpenGL/RenderWindow/Constants.d.ts" />
194
196
  /// <reference path="./Rendering/OpenGL/RenderWindow.d.ts" />
195
197
  /// <reference path="./Rendering/SceneGraph/RenderPass.d.ts" />
196
198
  /// <reference path="./Rendering/SceneGraph/ViewNode.d.ts" />
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kitware/vtk.js",
3
- "version": "26.7.0",
3
+ "version": "26.8.1",
4
4
  "description": "Visualization Toolkit for the Web",
5
5
  "keywords": [
6
6
  "3d",