@kitware/vtk.js 22.1.7 → 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.
Files changed (31) hide show
  1. package/IO/Core/ImageStream/DefaultProtocol.d.ts +8 -8
  2. package/IO/Core/ImageStream.d.ts +17 -15
  3. package/Rendering/Core/RenderWindowInteractor.js +3 -13
  4. package/Rendering/Core/ScalarBarActor.d.ts +39 -3
  5. package/Rendering/Core/ScalarBarActor.js +28 -8
  6. package/Rendering/Misc/SynchronizableRenderWindow.d.ts +73 -0
  7. package/Rendering/OpenGL/RenderWindow.d.ts +107 -106
  8. package/Rendering/OpenGL/RenderWindow.js +6 -0
  9. package/Rendering/OpenGL/VolumeMapper.js +64 -68
  10. package/Rendering/SceneGraph/RenderWindowViewNode.js +5 -0
  11. package/Rendering/WebGPU/FullScreenQuad.js +1 -1
  12. package/Rendering/WebGPU/Glyph3DMapper.js +2 -2
  13. package/Rendering/WebGPU/HardwareSelector.js +1 -0
  14. package/Rendering/WebGPU/ImageMapper.js +2 -2
  15. package/Rendering/WebGPU/MapperHelper.js +4 -4
  16. package/Rendering/WebGPU/OrderIndependentTranslucentPass.js +3 -3
  17. package/Rendering/WebGPU/PolyDataMapper.js +4 -4
  18. package/Rendering/WebGPU/RenderWindow.js +10 -1
  19. package/Rendering/WebGPU/Renderer.js +1 -1
  20. package/Rendering/WebGPU/Sampler.js +1 -1
  21. package/Rendering/WebGPU/ShaderDescription.js +4 -4
  22. package/Rendering/WebGPU/SphereMapper.js +3 -3
  23. package/Rendering/WebGPU/StickMapper.js +4 -4
  24. package/Rendering/WebGPU/StorageBuffer.js +1 -1
  25. package/Rendering/WebGPU/TextureView.js +2 -2
  26. package/Rendering/WebGPU/UniformBuffer.js +1 -1
  27. package/Rendering/WebGPU/VertexInput.js +1 -1
  28. package/Rendering/WebGPU/VolumePass.js +3 -3
  29. package/Rendering/WebGPU/VolumePassFSQ.js +3 -3
  30. package/Widgets/Core/WidgetManager.js +211 -71
  31. package/package.json +1 -1
@@ -3,23 +3,23 @@ import { Size, Vector3 } from '@kitware/vtk.js/types';
3
3
  declare function createMethods(session: any): {
4
4
  subscribeToImageStream: (callback: any) => any;
5
5
  unsubscribeToImageStream: (subscription: any) => any;
6
- registerView: (viewId: number) => any;
7
- unregisterView: (viewId: number) => any;
8
- enableView: (viewId: number, enabled: boolean) => any;
6
+ registerView: (viewId: string) => any;
7
+ unregisterView: (viewId: string) => any;
8
+ enableView: (viewId: string, enabled: boolean) => any;
9
9
  render: (options?: {
10
10
  size: Size;
11
11
  view: number;
12
12
  }) => any;
13
13
  resetCamera: (view?: number) => any;
14
- invalidateCache: (viewId: number) => any;
15
- setQuality: (viewId: number, quality: number, ratio?: number) => any;
16
- setSize: (viewId: number, width?: number, height?: number) => any;
14
+ invalidateCache: (viewId: string) => any;
15
+ setQuality: (viewId: string, quality: number, ratio?: number) => any;
16
+ setSize: (viewId: string, width?: number, height?: number) => any;
17
17
  setServerAnimationFPS: (fps?: number) => any;
18
18
  getServerAnimationFPS: () => number;
19
19
  startAnimation: (viewId?: number) => any;
20
20
  stopAnimation: (viewId?: number) => any;
21
- updateCamera: (viewId: number, focalPoint: Vector3, viewUp: Vector3, position: Vector3, forceUpdate?: boolean) => any;
21
+ updateCamera: (viewId: string, focalPoint: Vector3, viewUp: Vector3, position: Vector3, forceUpdate?: boolean) => any;
22
22
  updateCameraParameters: (viewId?: number, parameters?: {}, forceUpdate?: boolean) => any;
23
23
  }
24
24
 
25
- export default createMethods;
25
+ export default createMethods;
@@ -1,6 +1,6 @@
1
1
  import { vtkObject } from '@kitware/vtk.js/interfaces';
2
2
  import { Size } from '@kitware/vtk.js/types';
3
-
3
+ import vtkViewStream from '@kitware/vtk.js/IO/Core/ImageStream/ViewStream';
4
4
 
5
5
  /**
6
6
  *
@@ -10,54 +10,56 @@ export interface IImageStreamInitialValues {
10
10
  serverAnimationFPS?: number,
11
11
  }
12
12
 
13
+ // Return type of wslink/src/WebsocketConnection, getSession() method.
14
+ type WebsocketSession = any;
13
15
 
14
16
  export interface vtkImageStream extends vtkObject {
15
17
 
16
18
  /**
17
- *
19
+ *
18
20
  */
19
- connect(): void;
21
+ connect(session: WebsocketSession): void;
20
22
 
21
23
  /**
22
- *
23
- * @param {Number} [viewId] The ID of the view.
24
- * @param {Size} [size] The size of the view.
24
+ *
25
+ * @param {String} [viewId] The ID of the view.
26
+ * @param {Size} [size] The size of the view.
25
27
  */
26
- createViewStream(viewId?: number, size?: Size): any;
28
+ createViewStream(viewId?: string, size?: Size): vtkViewStream;
27
29
 
28
30
  /**
29
- *
31
+ *
30
32
  */
31
33
  delete(): void;
32
34
 
33
35
  /**
34
- *
36
+ *
35
37
  */
36
38
  disconnect(): void;
37
39
 
38
40
  /**
39
- *
41
+ *
40
42
  */
41
43
  getProtocol(): any;
42
44
 
43
45
  /**
44
- *
46
+ *
45
47
  */
46
48
  getServerAnimationFPS(): number;
47
49
 
48
50
  /**
49
- *
51
+ *
50
52
  */
51
53
  registerViewStream(): void;
52
54
 
53
55
  /**
54
- *
55
- * @param serverAnimationFPS
56
+ *
57
+ * @param serverAnimationFPS
56
58
  */
57
59
  setServerAnimationFPS(serverAnimationFPS: number): boolean;
58
60
 
59
61
  /**
60
- *
62
+ *
61
63
  */
62
64
  unregisterViewStream(): void;
63
65
  }
@@ -328,8 +328,6 @@ function vtkRenderWindowInteractor(publicAPI, model) {
328
328
  if (animationRequesters.size === 1 && !model.xrAnimation) {
329
329
  model._animationStartTime = Date.now();
330
330
  model._animationFrameCount = 0;
331
- model.lastFrameTime = 0.1;
332
- model.lastFrameStart = Date.now();
333
331
  model.animationRequest = requestAnimationFrame(publicAPI.handleAnimation);
334
332
  publicAPI.startAnimationEvent();
335
333
  }
@@ -375,7 +373,7 @@ function vtkRenderWindowInteractor(publicAPI, model) {
375
373
  model.xrAnimation = false;
376
374
 
377
375
  if (animationRequesters.size !== 0) {
378
- model.FrameTime = -1;
376
+ model.recentAnimationFrameRate = 10.0;
379
377
  model.animationRequest = requestAnimationFrame(publicAPI.handleAnimation);
380
378
  }
381
379
  };
@@ -456,19 +454,12 @@ function vtkRenderWindowInteractor(publicAPI, model) {
456
454
 
457
455
  if (currTime - model._animationStartTime > 1000.0 && model._animationFrameCount > 1) {
458
456
  model.recentAnimationFrameRate = 1000.0 * (model._animationFrameCount - 1) / (currTime - model._animationStartTime);
457
+ model.lastFrameTime = 1.0 / model.recentAnimationFrameRate;
459
458
  publicAPI.animationFrameRateUpdateEvent();
460
459
  model._animationStartTime = currTime;
461
460
  model._animationFrameCount = 1;
462
461
  }
463
462
 
464
- if (model.FrameTime === -1.0) {
465
- model.lastFrameTime = 0.1;
466
- } else {
467
- model.lastFrameTime = (currTime - model.lastFrameStart) / 1000.0;
468
- }
469
-
470
- model.lastFrameTime = Math.max(0.01, model.lastFrameTime);
471
- model.lastFrameStart = currTime;
472
463
  publicAPI.animationEvent();
473
464
  forceRender();
474
465
  model.animationRequest = requestAnimationFrame(publicAPI.handleAnimation);
@@ -933,7 +924,6 @@ function vtkRenderWindowInteractor(publicAPI, model) {
933
924
  };
934
925
 
935
926
  publicAPI.handleVisibilityChange = function () {
936
- model.lastFrameStart = Date.now();
937
927
  model._animationStartTime = Date.now();
938
928
  model._animationFrameCount = 0;
939
929
  };
@@ -957,7 +947,7 @@ function vtkRenderWindowInteractor(publicAPI, model) {
957
947
 
958
948
  superDelete();
959
949
  }; // Use the Page Visibility API to detect when we switch away from or back to
960
- // this tab, and reset the lastFrameStart. When tabs are not active, browsers
950
+ // this tab, and reset the animationFrameStart. When tabs are not active, browsers
961
951
  // will stop calling requestAnimationFrame callbacks.
962
952
 
963
953
 
@@ -38,7 +38,10 @@ export interface IScalarBarActorInitialValues extends IActorInitialValues {
38
38
  axisTitlePixelOffset?: number,
39
39
  axisTextStyle?: IStyle,
40
40
  tickLabelPixelOffset?: number,
41
- tickTextStyle?: IStyle
41
+ tickTextStyle?: IStyle,
42
+ drawNanAnnotation?: boolean,
43
+ drawBelowRangeSwatch?: boolean,
44
+ drawAboveRangeSwatch?: boolean,
42
45
  }
43
46
 
44
47
  export interface vtkScalarBarActor extends vtkActor {
@@ -135,6 +138,21 @@ export interface vtkScalarBarActor extends vtkActor {
135
138
  */
136
139
  getScalarsToColors(): vtkScalarsToColors;
137
140
 
141
+ /**
142
+ *
143
+ */
144
+ getDrawNanAnnotation(): boolean
145
+
146
+ /**
147
+ *
148
+ */
149
+ getDrawBelowRangeSwatch(): boolean
150
+
151
+ /**
152
+ *
153
+ */
154
+ getDrawAboveRangeSwatch(): boolean
155
+
138
156
  /**
139
157
  *
140
158
  */
@@ -212,8 +230,26 @@ export interface vtkScalarBarActor extends vtkActor {
212
230
  setScalarsToColors(scalarsToColors: vtkScalarsToColors): boolean;
213
231
 
214
232
  /**
215
- *
216
- * @param tickLabelPixelOffset
233
+ * Set whether the NaN annotation should be rendered or not.
234
+ * @param {Boolean} drawNanAnnotation
235
+ */
236
+ setDrawNanAnnotation(drawNanAnnotation: boolean): boolean;
237
+
238
+ /**
239
+ * Set whether the Below range swatch should be rendered or not
240
+ * @param {Boolean} drawBelowRangeSwatch
241
+ */
242
+ setDrawBelowRangeSwatch(drawBelowRangeSwatch: boolean): boolean;
243
+
244
+ /**
245
+ * Set whether the Above range swatch should be rendered or not
246
+ * @param {Boolean} drawAboveRangeSwatch
247
+ */
248
+ setDrawAboveRangeSwatch(drawAboveRangeSwatch: boolean): boolean;
249
+
250
+ /**
251
+ *
252
+ * @param tickLabelPixelOffset
217
253
  */
218
254
  setTickLabelPixelOffset(tickLabelPixelOffset: number): boolean;
219
255
 
@@ -319,6 +319,8 @@ function vtkScalarBarActor(publicAPI, model) {
319
319
 
320
320
 
321
321
  publicAPI.recomputeBarSegments = function (textSizes) {
322
+ var _model$scalarsToColor, _model$scalarsToColor2, _model$scalarsToColor3, _model$scalarsToColor4;
323
+
322
324
  // first compute the barSize/Position
323
325
  var segSize = publicAPI.computeBarSize(textSizes);
324
326
  model.barSegments = [];
@@ -337,22 +339,22 @@ function vtkScalarBarActor(publicAPI, model) {
337
339
  startPos[barAxis] += segSize[barAxis] + segSpace;
338
340
  }
339
341
 
340
- if (typeof model.scalarsToColors.getNanColor === 'function') {
342
+ if (model.drawNanAnnotation && model.scalarsToColors.getNanColor) {
341
343
  pushSeg('NaN', [NaN, NaN, NaN, NaN]);
342
344
  }
343
345
 
344
- if (typeof model.scalarsToColors.getUseBelowRangeColor === 'function' && model.scalarsToColors.getUseBelowRangeColor()) {
346
+ if (model.drawBelowRangeSwatch && (_model$scalarsToColor = (_model$scalarsToColor2 = model.scalarsToColors).getUseBelowRangeColor) !== null && _model$scalarsToColor !== void 0 && _model$scalarsToColor.call(_model$scalarsToColor2)) {
345
347
  pushSeg('Below', [-0.1, -0.1, -0.1, -0.1]);
346
348
  }
347
349
 
348
- var haveAbove = typeof model.scalarsToColors.getUseAboveRangeColor === 'function' && model.scalarsToColors.getUseAboveRangeColor(); // extra space around the ticks section
350
+ var haveAbove = (_model$scalarsToColor3 = (_model$scalarsToColor4 = model.scalarsToColors).getUseAboveRangeColor) === null || _model$scalarsToColor3 === void 0 ? void 0 : _model$scalarsToColor3.call(_model$scalarsToColor4); // extra space around the ticks section
349
351
 
350
352
  startPos[barAxis] += segSpace;
351
353
  var oldSegSize = segSize[barAxis];
352
354
  segSize[barAxis] = haveAbove ? 1.0 - 2.0 * segSpace - segSize[barAxis] - startPos[barAxis] : 1.0 - segSpace - startPos[barAxis];
353
355
  pushSeg('ticks', model.vertical ? [0, 0, 0.995, 0.995] : [0, 0.995, 0.995, 0]);
354
356
 
355
- if (haveAbove) {
357
+ if (model.drawAboveRangeSwatch && haveAbove) {
356
358
  segSize[barAxis] = oldSegSize;
357
359
  startPos[barAxis] += segSpace;
358
360
  pushSeg('Above', [1.1, 1.1, 1.1, 1.1]);
@@ -551,11 +553,26 @@ function vtkScalarBarActor(publicAPI, model) {
551
553
  };
552
554
 
553
555
  publicAPI.updatePolyDataForBarSegments = function () {
556
+ var _model$scalarsToColor5, _model$scalarsToColor6, _model$scalarsToColor7, _model$scalarsToColor8;
557
+
554
558
  var cmat = model.camera.getCompositeProjectionMatrix(model.lastAspectRatio, -1, 1);
555
559
  mat4.transpose(cmat, cmat);
556
560
  mat4.invert(invmat, cmat);
557
- var haveExtraColors = typeof model.scalarsToColors.getNanColor === 'function' && typeof model.scalarsToColors.getAboveRangeColor === 'function' && typeof model.scalarsToColors.getBelowRangeColor === 'function';
558
- var numPts = 4 + (haveExtraColors ? 12 : 0);
561
+ var numberOfExtraColors = 0;
562
+
563
+ if (model.drawNanAnnotation && model.scalarsToColors.getNanColor) {
564
+ numberOfExtraColors += 1;
565
+ }
566
+
567
+ if (model.drawBelowRangeSwatch && (_model$scalarsToColor5 = (_model$scalarsToColor6 = model.scalarsToColors).getUseBelowRangeColor) !== null && _model$scalarsToColor5 !== void 0 && _model$scalarsToColor5.call(_model$scalarsToColor6)) {
568
+ numberOfExtraColors += 1;
569
+ }
570
+
571
+ if (model.drawAboveRangeSwatch && (_model$scalarsToColor7 = (_model$scalarsToColor8 = model.scalarsToColors).getUseAboveRangeColor) !== null && _model$scalarsToColor7 !== void 0 && _model$scalarsToColor7.call(_model$scalarsToColor8)) {
572
+ numberOfExtraColors += 1;
573
+ }
574
+
575
+ var numPts = 4 * (1 + numberOfExtraColors);
559
576
  var numQuads = numPts; // handle vector component mode
560
577
 
561
578
  var numComps = 1;
@@ -667,7 +684,10 @@ function defaultValues(initialValues) {
667
684
  fontStyle: 'normal',
668
685
  fontSize: 14,
669
686
  fontFamily: 'serif'
670
- }
687
+ },
688
+ drawNanAnnotation: true,
689
+ drawBelowRangeSwatch: true,
690
+ drawAboveRangeSwatch: true
671
691
  }, initialValues);
672
692
  } // ----------------------------------------------------------------------------
673
693
 
@@ -738,7 +758,7 @@ function extend(publicAPI, model) {
738
758
 
739
759
  publicAPI.update();
740
760
  });
741
- macro.setGet(publicAPI, model, ['automated', 'autoLayout', 'axisTitlePixelOffset', 'axisLabel', 'scalarsToColors', 'tickLabelPixelOffset']);
761
+ macro.setGet(publicAPI, model, ['automated', 'autoLayout', 'axisTitlePixelOffset', 'axisLabel', 'scalarsToColors', 'tickLabelPixelOffset', 'drawNanAnnotation', 'drawBelowRangeSwatch', 'drawAboveRangeSwatch']);
742
762
  macro.get(publicAPI, model, ['axisTextStyle', 'tickTextStyle']);
743
763
  macro.getArray(publicAPI, model, ['boxPosition', 'boxSize']);
744
764
  macro.setArray(publicAPI, model, ['boxPosition', 'boxSize'], 2); // Object methods
@@ -0,0 +1,73 @@
1
+ import { vtkRenderWindow, IRenderWindowInitialValues } from '@kitware/vtk.js/Rendering/Rendering/Core/RenderWindow';
2
+
3
+ // Keeps state for client / server scene synchronization.
4
+ export interface SynchContext {
5
+ // Set a function that fetches the data array for the given object.
6
+ setFetchArrayFunction(fetcher: (hash: string, dataType: any) => Promise<ArrayBuffer>): void;
7
+ // Invokes the fetcher registered by setFetchArrayFunction.
8
+ getArray(sha: string, dataType: any, context: SynchContext): Promise<ArrayBuffer>;
9
+ emptyCachedArrays(): void;
10
+ freeOldArrays(threshold: number, context: SynchContext): void;
11
+
12
+ // instanceMap
13
+ getInstance(id: any): any;
14
+ getInstanceId(instance: any): any | null;
15
+ registerInstance(id: any, instance: any): void;
16
+ unregister(id: any): void;
17
+ emptyCachedInstances(): void;
18
+
19
+ // sceneMtimeHandler
20
+ getMtime(): number;
21
+ incrementMtime(viewId: string): number;
22
+ setActiveViewId(viewId: string): void;
23
+ getActiveViewId(): string;
24
+
25
+ // TODO: fill progresshandler
26
+ }
27
+
28
+ export interface IInitialValues extends IRenderWindowInitialValues {
29
+ synchronizerContextName?: string; // default: 'default':
30
+ synchronizerContext?: SynchContext | null;
31
+ synchronizedViewId?: string | null;
32
+ }
33
+
34
+ // Server-side view state.
35
+ export interface ViewState {
36
+ id: ViewId;
37
+ // vtk object type.
38
+ type: string;
39
+ // vtk object mtime.
40
+ mtime: number;
41
+ // ID of the parent. Null for the root.
42
+ parent?: string | null;
43
+ properties?: {[key: string]: any};
44
+ // Child objects.
45
+ dependencies?: ViewState[];
46
+ extra?: any;
47
+ // List of [methodName, args] to be invoked on the object.
48
+ calls?: [string, string[]][];
49
+ // ViewState may contain other arbitrary key / value pairs.
50
+ [key: string]: any;
51
+ }
52
+
53
+ export interface vtkSynchronizableRenderWindowInstance extends vtkRenderWindow {
54
+ getSynchronizerContext(): SynchContext;
55
+
56
+ // methods added by createSyncFunction
57
+ synchronize(state: ViewState): Promise<boolean>;
58
+ setSynchronizedViewId(viewId: string): void;
59
+ getSynchronizedViewId(): string;
60
+ updateGarbageCollectorThreshold(v: number): void;
61
+ getManagedInstanceIds(): Array<string>;
62
+ clearOneTimeUpdaters(): void;
63
+ }
64
+
65
+ export function newInstance(props: IInitialValues): vtkSynchronizableRenderWindowInstance;
66
+ export function getSynchronizerContext(name?: string): SynchContext;
67
+
68
+ export const vtkSynchronizableRenderWindow: {
69
+ newInstance: typeof newInstance;
70
+ getSynchronizerContext: typeof getSynchronizerContext;
71
+ };
72
+
73
+ export default vtkSynchronizableRenderWindow;