@kitware/vtk.js 25.5.0 → 25.6.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,7 +1,7 @@
1
1
  import vtkProp, { IPropInitialValues } from './Prop';
2
2
  import vtkCoordinate from './Coordinate';
3
3
  import vtkMapper from './Mapper';
4
- import vtkProperty from './Property';
4
+ import vtkProperty2D, { IProperty2DInitialValues } from './Property2D';
5
5
  import { Bounds } from './../../types';
6
6
 
7
7
  /**
@@ -9,7 +9,7 @@ import { Bounds } from './../../types';
9
9
  */
10
10
  export interface IActor2DInitialValues extends IPropInitialValues {
11
11
  mapper?: vtkMapper;
12
- property?: vtkProperty;
12
+ property?: vtkProperty2D;
13
13
  layerNumber?: number;
14
14
  positionCoordinate?: vtkCoordinate;
15
15
  positionCoordinate2?: vtkCoordinate;
@@ -31,12 +31,18 @@ export interface vtkActor2D extends vtkProp {
31
31
 
32
32
  /**
33
33
  * Return the property object that controls this actors surface
34
- * properties. This should be an instance of a vtkProperty object. Every
34
+ * properties. This should be an instance of a vtkProperty2D object. Every
35
35
  * actor must have a property associated with it. If one isn’t specified,
36
36
  * then one will be generated automatically. Multiple actors can share one
37
37
  * property object.
38
38
  */
39
- getProperty(): vtkProperty;
39
+ getProperty(): vtkProperty2D;
40
+
41
+ /**
42
+ * Create a new property suitable for use with this type of Actor.
43
+ * @param {IProperty2DInitialValues} [initialValues] (default: {})
44
+ */
45
+ makeProperty(initialValues?: IProperty2DInitialValues): vtkProperty2D;
40
46
 
41
47
  /**
42
48
  *
@@ -112,8 +118,8 @@ export function newInstance(initialValues?: IActor2DInitialValues): vtkActor2D;
112
118
  * vtkProp. The actor also has scaling and maintains a reference to the
113
119
  * defining geometry (i.e., the mapper), rendering properties, and possibly a
114
120
  * texture map.
115
- * @see [vtkMapper](./Rendering_Core_Mapper.html)2D
116
- * @see [vtkProperty](./Rendering_Core_Property.html)2D
121
+ * @see [vtkMapper2D](./Rendering_Core_Mapper2D.html)
122
+ * @see [vtkProperty2D](./Rendering_Core_Property2D.html)
117
123
  */
118
124
  export declare const vtkActor2D: {
119
125
  newInstance: typeof newInstance,
@@ -0,0 +1,24 @@
1
+ /**
2
+ * vtkColorMaps represents a global registry of preset color maps.
3
+ */
4
+
5
+ import { Vector3 } from '../../../types';
6
+
7
+ export interface IColorMapPreset {
8
+ Name: string;
9
+ Creator?: string;
10
+ ColorSpace?: string;
11
+ NanColor?: Vector3;
12
+ RGBPoints: number[];
13
+ IndexedColors?: number[];
14
+ Annotations?: (number | string)[];
15
+ }
16
+
17
+ export declare const vtkColorMaps: {
18
+ addPreset(preset: IColorMapPreset): void;
19
+ removePresetByName(name: string): void;
20
+ getPresetByName(name: string): IColorMapPreset;
21
+ rgbPresetNames: string[];
22
+ };
23
+
24
+ export default vtkColorMaps;
@@ -2,7 +2,7 @@ import { vtkObject } from './../../interfaces';
2
2
  import { RGBColor } from './../../types';
3
3
  import { DisplayLocation } from './Property2D/Constants';
4
4
 
5
- interface IProperty2DInitialValues{
5
+ export interface IProperty2DInitialValues{
6
6
  color?: RGBColor;
7
7
  opacity?: number;
8
8
  pointSize?: number;
@@ -5,7 +5,7 @@ import { InterpolationType, OpacityMode } from './VolumeProperty/Constants';
5
5
 
6
6
  export interface IVolumePropertyInitialValues {
7
7
  independentComponents?: boolean;
8
- shade?: number;
8
+ shade?: boolean;
9
9
  ambient?: number;
10
10
  diffuse?: number;
11
11
  specular?: number;
@@ -111,7 +111,7 @@ export interface vtkVolumeProperty extends vtkObject {
111
111
  /**
112
112
  * Get the shading of a volume.
113
113
  */
114
- getShade(): number;
114
+ getShade(): boolean;
115
115
 
116
116
  /**
117
117
  *
@@ -236,9 +236,9 @@ export interface vtkVolumeProperty extends vtkObject {
236
236
  * turning shading off is generally the same as setting ambient=1,
237
237
  * diffuse=0, specular=0. Shading can be independently turned on/off per
238
238
  * component.
239
- * @param {Number} shade
239
+ * @param {Boolean} shade
240
240
  */
241
- setShade(shade: number): boolean;
241
+ setShade(shade: boolean): boolean;
242
242
 
243
243
  /**
244
244
  *
@@ -237,7 +237,7 @@ function vtkVolumeProperty(publicAPI, model) {
237
237
  var DEFAULT_VALUES = {
238
238
  independentComponents: true,
239
239
  interpolationType: InterpolationType.FAST_LINEAR,
240
- shade: 0,
240
+ shade: false,
241
241
  ambient: 0.1,
242
242
  diffuse: 0.7,
243
243
  specular: 0.2,
@@ -1,8 +1,14 @@
1
1
  import macro from '../../macros.js';
2
+ import vtkWebGPUFullScreenQuad from './FullScreenQuad.js';
2
3
  import vtkWebGPUOpaquePass from './OpaquePass.js';
3
4
  import vtkWebGPUOrderIndepenentTranslucentPass from './OrderIndependentTranslucentPass.js';
5
+ import vtkWebGPURenderEncoder from './RenderEncoder.js';
4
6
  import vtkWebGPUVolumePass from './VolumePass.js';
5
7
  import vtkRenderPass from '../SceneGraph/RenderPass.js';
8
+ import vtkWebGPUSampler from './Sampler.js';
9
+ import vtkWebGPUTextureView from './TextureView.js';
10
+
11
+ var finalBlitFragTemplate = "\n//VTK::Mapper::Dec\n\n//VTK::TCoord::Dec\n\n//VTK::RenderEncoder::Dec\n\n//VTK::IOStructs::Dec\n\n@fragment\nfn main(\n//VTK::IOStructs::Input\n)\n//VTK::IOStructs::Output\n{\n var output: fragmentOutput;\n\n var computedColor: vec4<f32> = clamp(textureSampleLevel(opaquePassColorTexture, finalPassSampler, input.tcoordVS, 0),vec4<f32>(0.0),vec4<f32>(1.0));\n\n //VTK::RenderEncoder::Impl\n return output;\n}\n"; // ----------------------------------------------------------------------------
6
12
 
7
13
  function vtkForwardPass(publicAPI, model) {
8
14
  // Set our className
@@ -69,24 +75,96 @@ function vtkForwardPass(publicAPI, model) {
69
75
  model.volumePass.setDepthTextureView(model.opaquePass.getDepthTextureView());
70
76
  model.volumePass.setVolumes(model.volumes);
71
77
  model.volumePass.traverse(renNode, viewNode);
72
- }
78
+ } // blit the result into the swap chain
79
+
80
+
81
+ publicAPI.finalPass(viewNode, renNode);
73
82
  }
74
83
  }
75
- } // blit the result into the swap chain
76
-
77
-
78
- var sctex = viewNode.getCurrentTexture();
79
- var optex = model.opaquePass.getColorTexture();
80
- var cmdEnc = viewNode.getCommandEncoder();
81
- cmdEnc.copyTextureToTexture({
82
- texture: optex.getHandle()
83
- }, {
84
- texture: sctex
85
- }, {
86
- width: optex.getWidth(),
87
- height: optex.getHeight(),
88
- depthOrArrayLayers: 1
84
+ }
85
+ };
86
+
87
+ publicAPI.finalPass = function (viewNode, renNode) {
88
+ if (!model._finalBlitEncoder) {
89
+ publicAPI.createFinalBlitEncoder(viewNode);
90
+ }
91
+
92
+ model._finalBlitOutputTextureView.createFromTextureHandle(viewNode.getCurrentTexture(), {
93
+ depth: 1,
94
+ format: viewNode.getPresentationFormat()
95
+ });
96
+
97
+ model._finalBlitEncoder.attachTextureViews();
98
+
99
+ model._finalBlitEncoder.begin(viewNode.getCommandEncoder());
100
+
101
+ renNode.scissorAndViewport(model._finalBlitEncoder);
102
+
103
+ model._fullScreenQuad.prepareAndDraw(model._finalBlitEncoder);
104
+
105
+ model._finalBlitEncoder.end();
106
+ };
107
+
108
+ publicAPI.createFinalBlitEncoder = function (viewNode) {
109
+ model._finalBlitEncoder = vtkWebGPURenderEncoder.newInstance({
110
+ label: 'forwardPassBlit'
111
+ });
112
+
113
+ model._finalBlitEncoder.setDescription({
114
+ colorAttachments: [{
115
+ view: null,
116
+ loadOp: 'load',
117
+ storeOp: 'store'
118
+ }]
119
+ });
120
+
121
+ model._finalBlitEncoder.setPipelineHash('fpf');
122
+
123
+ model._finalBlitEncoder.setPipelineSettings({
124
+ primitive: {
125
+ cullMode: 'none'
126
+ },
127
+ fragment: {
128
+ targets: [{
129
+ format: viewNode.getPresentationFormat(),
130
+ blend: {
131
+ color: {
132
+ srcFactor: 'src-alpha',
133
+ dstFactor: 'one-minus-src-alpha'
134
+ },
135
+ alpha: {
136
+ srcfactor: 'one',
137
+ dstFactor: 'one-minus-src-alpha'
138
+ }
139
+ }
140
+ }]
141
+ }
142
+ });
143
+
144
+ model._fsqSampler = vtkWebGPUSampler.newInstance({
145
+ label: 'finalPassSampler'
146
+ });
147
+
148
+ model._fsqSampler.create(viewNode.getDevice(), {
149
+ minFilter: 'linear',
150
+ magFilter: 'linear'
89
151
  });
152
+
153
+ model._fullScreenQuad = vtkWebGPUFullScreenQuad.newInstance();
154
+
155
+ model._fullScreenQuad.setDevice(viewNode.getDevice());
156
+
157
+ model._fullScreenQuad.setPipelineHash('fpfsq');
158
+
159
+ model._fullScreenQuad.setTextureViews([model.opaquePass.getColorTextureView()]);
160
+
161
+ model._fullScreenQuad.setAdditionalBindables([model._fsqSampler]);
162
+
163
+ model._fullScreenQuad.setFragmentShaderTemplate(finalBlitFragTemplate);
164
+
165
+ model._finalBlitOutputTextureView = vtkWebGPUTextureView.newInstance();
166
+
167
+ model._finalBlitEncoder.setColorTextureView(0, model._finalBlitOutputTextureView);
90
168
  };
91
169
 
92
170
  publicAPI.incrementOpaqueActorCount = function () {
@@ -27,7 +27,7 @@ function vtkWebGPUOpaquePass(publicAPI, model) {
27
27
  model.colorTexture.create(device, {
28
28
  width: viewNode.getCanvas().width,
29
29
  height: viewNode.getCanvas().height,
30
- format: 'bgra8unorm',
30
+ format: 'rgba16float',
31
31
 
32
32
  /* eslint-disable no-undef */
33
33
 
@@ -184,7 +184,7 @@ function vtkWebGPUOrderIndependentTranslucentPass(publicAPI, model) {
184
184
  },
185
185
  fragment: {
186
186
  targets: [{
187
- format: 'bgra8unorm',
187
+ format: 'rgba16float',
188
188
  blend: {
189
189
  color: {
190
190
  srcFactor: 'src-alpha',
@@ -51,9 +51,11 @@ function vtkWebGPURenderEncoder(publicAPI, model) {
51
51
  console.trace();
52
52
  } else {
53
53
  for (var i = 0; i < model.colorTextureViews.length; i++) {
54
- var fmt = model.colorTextureViews[i].getTexture().getFormat();
54
+ var _model$colorTextureVi;
55
55
 
56
- if (fmt !== pd.fragment.targets[i].format) {
56
+ var fmt = (_model$colorTextureVi = model.colorTextureViews[i].getTexture()) === null || _model$colorTextureVi === void 0 ? void 0 : _model$colorTextureVi.getFormat();
57
+
58
+ if (fmt && fmt !== pd.fragment.targets[i].format) {
57
59
  console.log("mismatched attachments for attachment ".concat(i, " on pipeline ").concat(pd.fragment.targets[i].format, " while encoder has ").concat(fmt));
58
60
  console.trace();
59
61
  }
@@ -65,9 +67,11 @@ function vtkWebGPURenderEncoder(publicAPI, model) {
65
67
  console.log('mismatched depth attachments');
66
68
  console.trace();
67
69
  } else if (model.depthTextureView) {
68
- var dfmt = model.depthTextureView.getTexture().getFormat();
70
+ var _model$depthTextureVi;
71
+
72
+ var dfmt = (_model$depthTextureVi = model.depthTextureView.getTexture()) === null || _model$depthTextureVi === void 0 ? void 0 : _model$depthTextureVi.getFormat();
69
73
 
70
- if (dfmt !== pd.depthStencil.format) {
74
+ if (dfmt && dfmt !== pd.depthStencil.format) {
71
75
  console.log("mismatched depth attachments on pipeline ".concat(pd.depthStencil.format, " while encoder has ").concat(dfmt));
72
76
  console.trace();
73
77
  }
@@ -202,7 +206,7 @@ function extend(publicAPI, model) {
202
206
  },
203
207
  fragment: {
204
208
  targets: [{
205
- format: 'bgra8unorm',
209
+ format: 'rgba16float',
206
210
  blend: {
207
211
  color: {
208
212
  srcFactor: 'src-alpha',
@@ -9,6 +9,7 @@ import vtkWebGPUHardwareSelector from './HardwareSelector.js';
9
9
  import vtkWebGPUViewNodeFactory from './ViewNodeFactory.js';
10
10
  import vtkRenderPass from '../SceneGraph/RenderPass.js';
11
11
  import vtkRenderWindowViewNode from '../SceneGraph/RenderWindowViewNode.js';
12
+ import HalfFloat from '../../Common/Core/HalfFloat.js';
12
13
 
13
14
  var vtkErrorMacro = macro.vtkErrorMacro; // const IS_CHROME = navigator.userAgent.indexOf('Chrome') !== -1;
14
15
 
@@ -67,14 +68,14 @@ function vtkWebGPURenderWindow(publicAPI, model) {
67
68
  publicAPI.recreateSwapChain = function () {
68
69
  if (model.context) {
69
70
  model.context.unconfigure();
70
- var presentationFormat = navigator.gpu.getPreferredCanvasFormat(model.adapter);
71
+ model.presentationFormat = navigator.gpu.getPreferredCanvasFormat(model.adapter);
71
72
  /* eslint-disable no-undef */
72
73
 
73
74
  /* eslint-disable no-bitwise */
74
75
 
75
76
  model.context.configure({
76
77
  device: model.device.getHandle(),
77
- format: presentationFormat,
78
+ format: model.presentationFormat,
78
79
  alphaMode: 'premultiplied',
79
80
  usage: GPUTextureUsage.RENDER_ATTACHMENT | GPUTextureUsage.COPY_DST,
80
81
  width: model.size[0],
@@ -545,10 +546,10 @@ function vtkWebGPURenderWindow(publicAPI, model) {
545
546
  result = {
546
547
  width: texture.getWidth(),
547
548
  height: texture.getHeight()
548
- }; // must be a multiple of 256 bytes, so 64 texels with rgba8
549
+ }; // must be a multiple of 256 bytes, so 32 texels with rgba16
549
550
 
550
- result.colorBufferWidth = 64 * Math.floor((result.width + 63) / 64);
551
- result.colorBufferSizeInBytes = result.colorBufferWidth * result.height * 4;
551
+ result.colorBufferWidth = 32 * Math.floor((result.width + 31) / 32);
552
+ result.colorBufferSizeInBytes = result.colorBufferWidth * result.height * 8;
552
553
  colorBuffer = vtkWebGPUBuffer.newInstance();
553
554
  colorBuffer.setDevice(device);
554
555
  /* eslint-disable no-bitwise */
@@ -565,7 +566,7 @@ function vtkWebGPURenderWindow(publicAPI, model) {
565
566
  texture: texture.getHandle()
566
567
  }, {
567
568
  buffer: colorBuffer.getHandle(),
568
- bytesPerRow: 4 * result.colorBufferWidth,
569
+ bytesPerRow: 8 * result.colorBufferWidth,
569
570
  rowsPerImage: result.height
570
571
  }, {
571
572
  width: result.width,
@@ -581,7 +582,7 @@ function vtkWebGPURenderWindow(publicAPI, model) {
581
582
 
582
583
  case 14:
583
584
  /* eslint-enable no-undef */
584
- result.colorValues = new Uint8ClampedArray(colorBuffer.getMappedRange().slice());
585
+ result.colorValues = new Uint16Array(colorBuffer.getMappedRange().slice());
585
586
  colorBuffer.unmap(); // repack the array
586
587
 
587
588
  tmparray = new Uint8ClampedArray(result.height * result.width * 4);
@@ -590,10 +591,10 @@ function vtkWebGPURenderWindow(publicAPI, model) {
590
591
  for (x = 0; x < result.width; x++) {
591
592
  doffset = (y * result.width + x) * 4;
592
593
  soffset = (y * result.colorBufferWidth + x) * 4;
593
- tmparray[doffset] = result.colorValues[soffset + 2];
594
- tmparray[doffset + 1] = result.colorValues[soffset + 1];
595
- tmparray[doffset + 2] = result.colorValues[soffset];
596
- tmparray[doffset + 3] = result.colorValues[soffset + 3];
594
+ tmparray[doffset] = 255.0 * HalfFloat.fromHalf(result.colorValues[soffset]);
595
+ tmparray[doffset + 1] = 255.0 * HalfFloat.fromHalf(result.colorValues[soffset + 1]);
596
+ tmparray[doffset + 2] = 255.0 * HalfFloat.fromHalf(result.colorValues[soffset + 2]);
597
+ tmparray[doffset + 3] = 255.0 * HalfFloat.fromHalf(result.colorValues[soffset + 3]);
597
598
  }
598
599
  }
599
600
 
@@ -635,7 +636,8 @@ var DEFAULT_VALUES = {
635
636
  useOffScreen: false,
636
637
  useBackgroundImage: false,
637
638
  nextPropID: 1,
638
- xrSupported: false
639
+ xrSupported: false,
640
+ presentationFormat: null
639
641
  }; // ----------------------------------------------------------------------------
640
642
 
641
643
  function extend(publicAPI, model) {
@@ -671,7 +673,7 @@ function extend(publicAPI, model) {
671
673
  macro.event(publicAPI, model, 'imageReady');
672
674
  macro.event(publicAPI, model, 'initialized'); // Build VTK API
673
675
 
674
- macro.get(publicAPI, model, ['commandEncoder', 'device', 'useBackgroundImage', 'xrSupported']);
676
+ macro.get(publicAPI, model, ['commandEncoder', 'device', 'presentationFormat', 'useBackgroundImage', 'xrSupported']);
675
677
  macro.setGet(publicAPI, model, ['initialized', 'context', 'canvas', 'device', 'renderPasses', 'notifyStartCaptureImage', 'cursor', 'useOffScreen']);
676
678
  macro.setGetArray(publicAPI, model, ['size'], 2); // Object methods
677
679
 
@@ -23,6 +23,19 @@ function vtkWebGPUTextureView(publicAPI, model) {
23
23
  model.bindGroupLayoutEntry.texture.sampleType = tDetails.sampleType;
24
24
  };
25
25
 
26
+ publicAPI.createFromTextureHandle = function (textureHandle, options) {
27
+ model.texture = null;
28
+ model.options = options;
29
+ model.options.dimension = model.options.dimension || '2d';
30
+ model.options.label = model.label;
31
+ model.textureHandle = textureHandle;
32
+ model.handle = model.textureHandle.createView(model.options);
33
+ model.bindGroupLayoutEntry.texture.viewDimension = model.options.dimension;
34
+ var tDetails = vtkWebGPUTypes.getDetailsFromTextureFormat(options.format);
35
+ model.bindGroupLayoutEntry.texture.sampleType = tDetails.sampleType;
36
+ model.bindGroupTime.modified();
37
+ };
38
+
26
39
  publicAPI.getBindGroupEntry = function () {
27
40
  var foo = {
28
41
  resource: publicAPI.getHandle()
@@ -58,7 +71,7 @@ function vtkWebGPUTextureView(publicAPI, model) {
58
71
 
59
72
  publicAPI.getBindGroupTime = function () {
60
73
  // check if the handle changed
61
- if (model.texture.getHandle() !== model.textureHandle) {
74
+ if (model.texture && model.texture.getHandle() !== model.textureHandle) {
62
75
  model.textureHandle = model.texture.getHandle();
63
76
  model.handle = model.textureHandle.createView(model.options);
64
77
  model.bindGroupTime.modified();
@@ -69,7 +82,7 @@ function vtkWebGPUTextureView(publicAPI, model) {
69
82
 
70
83
 
71
84
  publicAPI.getHandle = function () {
72
- if (model.texture.getHandle() !== model.textureHandle) {
85
+ if (model.texture && model.texture.getHandle() !== model.textureHandle) {
73
86
  model.textureHandle = model.texture.getHandle();
74
87
  model.handle = model.textureHandle.createView(model.options);
75
88
  model.bindGroupTime.modified();
@@ -560,7 +560,7 @@ function vtkWebGPUVolumePass(publicAPI, model) {
560
560
  },
561
561
  fragment: {
562
562
  targets: [{
563
- format: 'bgra8unorm',
563
+ format: 'rgba16float',
564
564
  blend: {
565
565
  color: {
566
566
  srcFactor: 'one',
package/index.d.ts CHANGED
@@ -103,6 +103,7 @@
103
103
  /// <reference path="./Rendering/Core/AxesActor.d.ts" />
104
104
  /// <reference path="./Rendering/Core/Camera.d.ts" />
105
105
  /// <reference path="./Rendering/Core/CellPicker.d.ts" />
106
+ /// <reference path="./Rendering/Core/ColorTransferFunction/ColorMaps.d.ts" />
106
107
  /// <reference path="./Rendering/Core/ColorTransferFunction/Constants.d.ts" />
107
108
  /// <reference path="./Rendering/Core/ColorTransferFunction.d.ts" />
108
109
  /// <reference path="./Rendering/Core/Coordinate/Constants.d.ts" />
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kitware/vtk.js",
3
- "version": "25.5.0",
3
+ "version": "25.6.0",
4
4
  "description": "Visualization Toolkit for the Web",
5
5
  "keywords": [
6
6
  "3d",