@kitware/vtk.js 34.4.0 → 34.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.
Files changed (66) hide show
  1. package/Common/Core/CellArray.d.ts +3 -0
  2. package/Common/Core/CellArray.js +12 -1
  3. package/Common/Core/DataArray.d.ts +15 -0
  4. package/Common/Core/DataArray.js +8 -4
  5. package/Common/Core/Math/index.js +1 -1
  6. package/Common/Core/Math.js +1 -1
  7. package/Common/DataModel/Triangle.d.ts +68 -19
  8. package/Common/DataModel/Triangle.js +140 -1
  9. package/Common/DataModel/TriangleStrip.d.ts +180 -0
  10. package/Common/DataModel/TriangleStrip.js +396 -0
  11. package/Common/DataModel.js +3 -1
  12. package/Common/Transform/LandmarkTransform.js +1 -1
  13. package/Common/Transform/Transform.d.ts +112 -1
  14. package/Common/Transform/Transform.js +301 -2
  15. package/Filters/Core/Cutter.js +41 -0
  16. package/Filters/General/OBBTree.js +1 -1
  17. package/Filters/General/TransformPolyDataFilter.d.ts +75 -0
  18. package/Filters/General/TransformPolyDataFilter.js +194 -0
  19. package/Filters/General.js +2 -0
  20. package/Filters/Sources/CircleSource.js +1 -1
  21. package/Filters/Sources/PointSource.js +1 -1
  22. package/Filters/Texture/TextureMapToPlane.js +1 -1
  23. package/IO/Geometry/DracoReader.js +1 -1
  24. package/IO/Geometry/GLTFImporter/Animations.js +1 -1
  25. package/IO/Geometry/GLTFImporter/Reader.js +2 -2
  26. package/IO/Image/HDRReader/Utils.js +1 -1
  27. package/IO/Image/HDRReader.js +1 -1
  28. package/Interaction/Manipulators/MouseCameraTrackballRollManipulator.js +1 -1
  29. package/Interaction/Manipulators/MouseCameraTrackballRotateManipulator.js +1 -1
  30. package/Interaction/Manipulators/MouseCameraUnicamManipulator.js +1 -1
  31. package/Interaction/Manipulators/MouseCameraUnicamRotateManipulator.js +1 -1
  32. package/Interaction/Style/InteractorStyleTrackballCamera.js +1 -1
  33. package/Interaction/Widgets/PiecewiseGaussianWidget.js +1 -1
  34. package/Proxy/Core/View2DProxy.js +1 -1
  35. package/Rendering/Core/AbstractImageMapper.js +1 -1
  36. package/Rendering/Core/AbstractMapper3D.js +1 -1
  37. package/Rendering/Core/ColorTransferFunction/CssFilters.js +1 -1
  38. package/Rendering/Core/ColorTransferFunction.js +1 -1
  39. package/Rendering/Core/Coordinate.js +1 -1
  40. package/Rendering/Core/CubeAxesActor.js +1 -1
  41. package/Rendering/Core/Glyph3DMapper.js +1 -1
  42. package/Rendering/Core/ImageArrayMapper.js +1 -1
  43. package/Rendering/Core/ImageMapper.js +1 -1
  44. package/Rendering/Core/ImageProperty.d.ts +10 -4
  45. package/Rendering/Core/Mapper.js +1 -1
  46. package/Rendering/Core/Mapper2D.js +362 -8
  47. package/Rendering/Core/Prop3D.js +1 -1
  48. package/Rendering/Core/RenderWindowInteractor.js +3 -3
  49. package/Rendering/Core/Renderer.js +1 -1
  50. package/Rendering/Core/ScalarBarActor.js +1 -1
  51. package/Rendering/Core/TextActor.js +1 -1
  52. package/Rendering/Core/VectorText/Utils.js +1 -1
  53. package/Rendering/Core/VolumeProperty.js +1 -1
  54. package/Rendering/OpenGL/ImageMapper.js +90 -20
  55. package/Rendering/OpenGL/PolyDataMapper2D.js +89 -30
  56. package/Rendering/OpenGL/Texture.js +1 -1
  57. package/Rendering/OpenGL/VolumeMapper.js +21 -19
  58. package/Widgets/Manipulators/LineManipulator.js +1 -1
  59. package/Widgets/Representations/PolyLineRepresentation.js +1 -1
  60. package/Widgets/Widgets3D/AngleWidget.js +1 -1
  61. package/Widgets/Widgets3D/LineWidget/helpers.js +1 -1
  62. package/Widgets/Widgets3D/ResliceCursorWidget/behavior.js +1 -1
  63. package/Widgets/Widgets3D/ResliceCursorWidget/helpers.js +1 -1
  64. package/Widgets/Widgets3D/ResliceCursorWidget.js +1 -1
  65. package/index.d.ts +2 -0
  66. package/package.json +1 -1
@@ -54,7 +54,7 @@ function vtkOpenGLImageMapper(publicAPI, model) {
54
54
  // The openGLTexture is not shared
55
55
  model.openGLTexture.releaseGraphicsResources(renderWindow);
56
56
  // All these other resources are shared
57
- [model._colorTransferFunc, model._pwFunc, model._labelOutlineThicknessArray].forEach(coreObject => renderWindow.unregisterGraphicsResourceUser(coreObject, publicAPI));
57
+ [model._colorTransferFunc, model._pwFunc, model._labelOutlineThicknessArray, model._labelOutlineOpacity].forEach(coreObject => renderWindow.unregisterGraphicsResourceUser(coreObject, publicAPI));
58
58
  }
59
59
  publicAPI.buildPass = prepass => {
60
60
  if (prepass) {
@@ -131,7 +131,14 @@ function vtkOpenGLImageMapper(publicAPI, model) {
131
131
  // color shift and scale
132
132
  'uniform float cshift0;', 'uniform float cscale0;',
133
133
  // pwf shift and scale
134
- 'uniform float pwfshift0;', 'uniform float pwfscale0;', 'uniform sampler2D texture1;', 'uniform sampler2D colorTexture1;', 'uniform sampler2D pwfTexture1;', 'uniform sampler2D labelOutlineTexture1;', 'uniform float opacity;', 'uniform float outlineOpacity;'];
134
+ 'uniform float pwfshift0;', 'uniform float pwfscale0;', 'uniform sampler2D texture1;', 'uniform sampler2D colorTexture1;', 'uniform sampler2D pwfTexture1;', 'uniform float opacity;'];
135
+ if (actor.getProperty().getUseLabelOutline()) {
136
+ tcoordDec = tcoordDec.concat([
137
+ // outline thickness
138
+ 'uniform sampler2D labelOutlineTexture1;',
139
+ // outline opacity
140
+ 'uniform sampler2D labelOutlineOpacityTexture1;']);
141
+ }
135
142
  if (iComps) {
136
143
  for (let comp = 1; comp < tNumComp; comp++) {
137
144
  tcoordDec = tcoordDec.concat([
@@ -167,7 +174,7 @@ function vtkOpenGLImageMapper(publicAPI, model) {
167
174
  // check for the outline thickness and opacity
168
175
  const vtkImageLabelOutline = actor.getProperty().getUseLabelOutline();
169
176
  if (vtkImageLabelOutline === true) {
170
- FSSource = vtkShaderProgram.substitute(FSSource, '//VTK::LabelOutline::Dec', ['uniform int outlineThickness;', 'uniform float vpWidth;', 'uniform float vpHeight;', 'uniform float vpOffsetX;', 'uniform float vpOffsetY;', 'uniform mat4 PCWCMatrix;', 'uniform mat4 vWCtoIDX;', 'uniform ivec3 imageDimensions;', 'uniform int sliceAxis;']).result;
177
+ FSSource = vtkShaderProgram.substitute(FSSource, '//VTK::LabelOutline::Dec', ['uniform float vpWidth;', 'uniform float vpHeight;', 'uniform float vpOffsetX;', 'uniform float vpOffsetY;', 'uniform mat4 PCWCMatrix;', 'uniform mat4 vWCtoIDX;', 'uniform ivec3 imageDimensions;', 'uniform int sliceAxis;']).result;
171
178
  FSSource = vtkShaderProgram.substitute(FSSource, '//VTK::ImageLabelOutlineOn', '#define vtkImageLabelOutlineOn').result;
172
179
  FSSource = vtkShaderProgram.substitute(FSSource, '//VTK::LabelOutlineHelperFunction', ['#ifdef vtkImageLabelOutlineOn', 'vec3 fragCoordToIndexSpace(vec4 fragCoord) {', ' vec4 pcPos = vec4(', ' (fragCoord.x / vpWidth - vpOffsetX - 0.5) * 2.0,', ' (fragCoord.y / vpHeight - vpOffsetY - 0.5) * 2.0,', ' (fragCoord.z - 0.5) * 2.0,', ' 1.0);', '', ' vec4 worldCoord = PCWCMatrix * pcPos;', ' vec4 vertex = (worldCoord/worldCoord.w);', '', ' vec3 index = (vWCtoIDX * vertex).xyz;', '', ' // half voxel fix for labelmapOutline', ' return (index + vec3(0.5)) / vec3(imageDimensions);', '}', 'vec2 getSliceCoords(vec3 coord, int axis) {', ' if (axis == 0) return coord.yz;', ' if (axis == 1) return coord.xz;', ' if (axis == 2) return coord.xy;', '}', '#endif']).result;
173
180
  }
@@ -209,6 +216,7 @@ function vtkOpenGLImageMapper(publicAPI, model) {
209
216
  int segmentIndex = int(centerValue * 255.0);
210
217
  float textureCoordinate = float(segmentIndex - 1) / 1024.0;
211
218
  float textureValue = texture2D(labelOutlineTexture1, vec2(textureCoordinate, 0.5)).r;
219
+ float outlineOpacity = texture2D(labelOutlineOpacityTexture1, vec2(textureCoordinate, 0.5)).r;
212
220
  int actualThickness = int(textureValue * 255.0);
213
221
 
214
222
  if (segmentIndex == 0){
@@ -301,7 +309,7 @@ function vtkOpenGLImageMapper(publicAPI, model) {
301
309
  if (!model.currentRenderPass && model.lastRenderPassShaderReplacement || model.currentRenderPass && model.currentRenderPass.getShaderReplacement() !== model.lastRenderPassShaderReplacement) {
302
310
  needRebuild = true;
303
311
  }
304
- if (needRebuild || model.lastHaveSeenDepthRequest !== model.haveSeenDepthRequest || cellBO.getProgram()?.getHandle() === 0 || model.lastTextureComponents !== tNumComp || model.lastIndependentComponents !== iComp) {
312
+ if (needRebuild || model.lastHaveSeenDepthRequest !== model.haveSeenDepthRequest || cellBO.getProgram()?.getHandle() === 0 || cellBO.getShaderSourceTime().getMTime() < model.renderable.getMTime() || cellBO.getShaderSourceTime().getMTime() < model.currentInput.getMTime() || cellBO.getShaderSourceTime().getMTime() < actor.getProperty().getMTime() || model.lastTextureComponents !== tNumComp || model.lastIndependentComponents !== iComp) {
305
313
  model.lastHaveSeenDepthRequest = model.haveSeenDepthRequest;
306
314
  model.lastTextureComponents = tNumComp;
307
315
  model.lastIndependentComponents = iComp;
@@ -417,8 +425,12 @@ function vtkOpenGLImageMapper(publicAPI, model) {
417
425
  cellBO.getProgram().setUniformi('colorTexture1', texColorUnit);
418
426
  const texOpacityUnit = model.pwfTexture.getTextureUnit();
419
427
  cellBO.getProgram().setUniformi('pwfTexture1', texOpacityUnit);
420
- const outlineThicknessUnit = model.labelOutlineThicknessTexture.getTextureUnit();
421
- cellBO.getProgram().setUniformi('labelOutlineTexture1', outlineThicknessUnit);
428
+ if (actor.getProperty().getUseLabelOutline()) {
429
+ const outlineThicknessUnit = model.labelOutlineThicknessTexture.getTextureUnit();
430
+ cellBO.getProgram().setUniformi('labelOutlineTexture1', outlineThicknessUnit);
431
+ const texOutlineOpacityUnit = model.labelOutlineOpacityTexture.getTextureUnit();
432
+ cellBO.getProgram().setUniformi('labelOutlineOpacityTexture1', texOutlineOpacityUnit);
433
+ }
422
434
  if (model.renderable.getNumberOfClippingPlanes()) {
423
435
  // add all the clipping planes
424
436
  let numClipPlanes = model.renderable.getNumberOfClippingPlanes();
@@ -449,13 +461,6 @@ function vtkOpenGLImageMapper(publicAPI, model) {
449
461
  cellBO.getProgram().setUniformi('numClipPlanes', numClipPlanes);
450
462
  cellBO.getProgram().setUniform4fv('clipPlanes', planeEquations);
451
463
  }
452
-
453
- // outline thickness and opacity
454
- const vtkImageLabelOutline = actor.getProperty().getUseLabelOutline();
455
- if (vtkImageLabelOutline === true) {
456
- const outlineOpacity = actor.getProperty().getLabelOutlineOpacity();
457
- cellBO.getProgram().setUniformf('outlineOpacity', outlineOpacity);
458
- }
459
464
  };
460
465
  publicAPI.setCameraShaderParameters = (cellBO, ren, actor) => {
461
466
  const program = cellBO.getProgram();
@@ -516,7 +521,10 @@ function vtkOpenGLImageMapper(publicAPI, model) {
516
521
  // activate the texture
517
522
  model.openGLTexture.activate();
518
523
  model.colorTexture.activate();
519
- model.labelOutlineThicknessTexture.activate();
524
+ if (actor.getProperty().getUseLabelOutline()) {
525
+ model.labelOutlineThicknessTexture.activate();
526
+ model.labelOutlineOpacityTexture.activate();
527
+ }
520
528
  model.pwfTexture.activate();
521
529
 
522
530
  // draw polygons
@@ -528,7 +536,10 @@ function vtkOpenGLImageMapper(publicAPI, model) {
528
536
  }
529
537
  model.openGLTexture.deactivate();
530
538
  model.colorTexture.deactivate();
531
- model.labelOutlineThicknessTexture.deactivate();
539
+ if (actor.getProperty().getUseLabelOutline()) {
540
+ model.labelOutlineThicknessTexture.deactivate();
541
+ model.labelOutlineOpacityTexture.deactivate();
542
+ }
532
543
  model.pwfTexture.deactivate();
533
544
  };
534
545
  publicAPI.renderPieceFinish = (ren, actor) => {};
@@ -560,7 +571,7 @@ function vtkOpenGLImageMapper(publicAPI, model) {
560
571
  publicAPI.buildBufferObjects(ren, actor);
561
572
  }
562
573
  };
563
- publicAPI.getNeedToRebuildBufferObjects = (ren, actor) => model.VBOBuildTime.getMTime() < publicAPI.getMTime() || model.VBOBuildTime.getMTime() < actor.getMTime() || model.VBOBuildTime.getMTime() < model.renderable.getMTime() || model.VBOBuildTime.getMTime() < actor.getProperty().getMTime() || model.VBOBuildTime.getMTime() < model.currentInput.getMTime() || !model.openGLTexture?.getHandle() || !model.colorTexture?.getHandle() || !model.labelOutlineThicknessTexture?.getHandle() || !model.pwfTexture?.getHandle();
574
+ publicAPI.getNeedToRebuildBufferObjects = (ren, actor) => model.VBOBuildTime.getMTime() < publicAPI.getMTime() || model.VBOBuildTime.getMTime() < actor.getMTime() || model.VBOBuildTime.getMTime() < model.renderable.getMTime() || model.VBOBuildTime.getMTime() < actor.getProperty().getMTime() || model.VBOBuildTime.getMTime() < model.currentInput.getMTime() || !model.openGLTexture?.getHandle() || !model.colorTexture?.getHandle() || actor.getProperty().getUseLabelOutline() && (!model.labelOutlineThicknessTexture?.getHandle() || !model.labelOutlineOpacityTexture?.getHandle()) || !model.pwfTexture?.getHandle();
564
575
  publicAPI.buildBufferObjects = (ren, actor) => {
565
576
  const image = model.currentInput;
566
577
  if (!image) {
@@ -740,9 +751,11 @@ function vtkOpenGLImageMapper(publicAPI, model) {
740
751
  } else {
741
752
  model.pwfTexture = pwfTex.oglObject;
742
753
  }
743
-
744
- // Build outline thickness buffer
745
- publicAPI.updatelabelOutlineThicknessTexture(actor);
754
+ if (actor.getProperty().getUseLabelOutline()) {
755
+ // Build outline thickness + opacity buffers
756
+ publicAPI.updatelabelOutlineThicknessTexture(actor);
757
+ publicAPI.updateLabelOutlineOpacityTexture(actor);
758
+ }
746
759
 
747
760
  // Find what IJK axis and what direction to slice along
748
761
  const {
@@ -955,6 +968,63 @@ function vtkOpenGLImageMapper(publicAPI, model) {
955
968
  model.VBOBuildString = toString;
956
969
  }
957
970
  };
971
+ publicAPI.updateLabelOutlineOpacityTexture = image => {
972
+ let labelOutlineOpacity = image.getProperty().getLabelOutlineOpacity();
973
+
974
+ // when the labelOutlineOpacity is a number, we use _cachedLabelOutlineOpacityObj
975
+ // as a stable object reference for `[labelOutlineOpacity]`.
976
+ if (typeof labelOutlineOpacity === 'number') {
977
+ if (model._cachedLabelOutlineOpacityObj?.[0] === labelOutlineOpacity) {
978
+ labelOutlineOpacity = model._cachedLabelOutlineOpacityObj;
979
+ } else {
980
+ labelOutlineOpacity = [labelOutlineOpacity];
981
+ }
982
+ model._cachedLabelOutlineOpacityObj = labelOutlineOpacity;
983
+ }
984
+ const lTex = model._openGLRenderWindow.getGraphicsResourceForObject(labelOutlineOpacity);
985
+ const toString = `${labelOutlineOpacity.join('-')}`;
986
+ const reBuildL = !lTex?.oglObject?.getHandle() || lTex?.hash !== toString;
987
+ if (reBuildL) {
988
+ let lWidth = model.renderable.getLabelOutlineTextureWidth();
989
+ if (lWidth <= 0) {
990
+ lWidth = model.context.getParameter(model.context.MAX_TEXTURE_SIZE);
991
+ }
992
+ const lHeight = 1;
993
+ const lSize = lWidth * lHeight;
994
+ const lTable = new Float32Array(lSize);
995
+ for (let i = 0; i < lWidth; ++i) {
996
+ // Retrieve the opacity value for the current segment index.
997
+ // If the value is undefined, use the first element's value as a default, otherwise use the value (even if 0)
998
+ lTable[i] = labelOutlineOpacity[i] ?? labelOutlineOpacity[0];
999
+ }
1000
+ model.labelOutlineOpacityTexture = vtkOpenGLTexture.newInstance({
1001
+ resizable: false
1002
+ });
1003
+ model.labelOutlineOpacityTexture.setOpenGLRenderWindow(model._openGLRenderWindow);
1004
+ model.labelOutlineOpacityTexture.resetFormatAndType();
1005
+ model.labelOutlineOpacityTexture.setMinificationFilter(Filter.NEAREST);
1006
+ model.labelOutlineOpacityTexture.setMagnificationFilter(Filter.NEAREST);
1007
+
1008
+ // Create a 2D texture (acting as 1D) from the raw data
1009
+ model.labelOutlineOpacityTexture.create2DFromRaw({
1010
+ width: lWidth,
1011
+ height: lHeight,
1012
+ numComps: 1,
1013
+ dataType: VtkDataTypes.FLOAT,
1014
+ data: lTable
1015
+ });
1016
+ if (labelOutlineOpacity) {
1017
+ model._openGLRenderWindow.setGraphicsResourceForObject(labelOutlineOpacity, model.labelOutlineOpacityTexture, toString);
1018
+ if (labelOutlineOpacity !== model._labelOutlineOpacity) {
1019
+ model._openGLRenderWindow.registerGraphicsResourceUser(labelOutlineOpacity, publicAPI);
1020
+ model._openGLRenderWindow.unregisterGraphicsResourceUser(model._labelOutlineOpacity, publicAPI);
1021
+ }
1022
+ model._labelOutlineOpacity = labelOutlineOpacity;
1023
+ }
1024
+ } else {
1025
+ model.labelOutlineOpacityTexture = lTex.oglObject;
1026
+ }
1027
+ };
958
1028
  publicAPI.updatelabelOutlineThicknessTexture = image => {
959
1029
  const labelOutlineThicknessArray = image.getProperty().getLabelOutlineThicknessByReference();
960
1030
  const lTex = model._openGLRenderWindow.getGraphicsResourceForObject(labelOutlineThicknessArray);
@@ -1046,7 +1116,7 @@ const DEFAULT_VALUES = {
1046
1116
  colorTexture: null,
1047
1117
  pwfTexture: null,
1048
1118
  labelOutlineThicknessTexture: null,
1049
- labelOutlineThicknessTextureString: null,
1119
+ labelOutlineOpacityTexture: null,
1050
1120
  lastHaveSeenDepthRequest: false,
1051
1121
  haveSeenDepthRequest: false,
1052
1122
  lastTextureComponents: 0
@@ -1,14 +1,14 @@
1
1
  import { mat4 } from 'gl-matrix';
2
2
  import { n as newInstance$1, e as setGet, o as obj, c as macro } from '../../macros2.js';
3
3
  import vtkHelper from './Helper.js';
4
- import vtkMapper2D from '../Core/Mapper2D.js';
5
4
  import vtkPoints from '../../Common/Core/Points.js';
6
5
  import { v as vtkPolyData2DFS } from './glsl/vtkPolyData2DFS.glsl.js';
7
6
  import { v as vtkPolyData2DVS } from './glsl/vtkPolyData2DVS.glsl.js';
8
7
  import vtkReplacementShaderMapper from './ReplacementShaderMapper.js';
9
8
  import vtkShaderProgram from './ShaderProgram.js';
10
9
  import vtkViewNode from '../SceneGraph/ViewNode.js';
11
- import { P as round } from '../../Common/Core/Math/index.js';
10
+ import vtkOpenGLTexture from './Texture.js';
11
+ import { Q as round } from '../../Common/Core/Math/index.js';
12
12
  import { DisplayLocation } from '../Core/Property2D/Constants.js';
13
13
  import { registerOverride } from './ViewNodeFactory.js';
14
14
 
@@ -17,8 +17,9 @@ const {
17
17
  primTypes
18
18
  } = vtkHelper;
19
19
  const {
20
- ScalarMode
21
- } = vtkMapper2D;
20
+ Filter,
21
+ Wrap
22
+ } = vtkOpenGLTexture;
22
23
  const {
23
24
  vtkErrorMacro
24
25
  } = macro;
@@ -82,6 +83,11 @@ function vtkOpenGLPolyDataMapper2D(publicAPI, model) {
82
83
  if (!model.currentInput.getPoints || !model.currentInput.getPoints().getNumberOfValues()) {
83
84
  return;
84
85
  }
86
+
87
+ // cull back face to avoid double drawing
88
+ const gl = model.context;
89
+ model._openGLRenderWindow.enableCullFace();
90
+ gl.cullFace(gl.BACK);
85
91
  publicAPI.renderPieceStart(ren, actor);
86
92
  publicAPI.renderPieceDraw(ren, actor);
87
93
  publicAPI.renderPieceFinish(ren, actor);
@@ -94,6 +100,13 @@ function vtkOpenGLPolyDataMapper2D(publicAPI, model) {
94
100
  model._openGLRenderer.getSelector().renderProp(actor);
95
101
  }
96
102
  }
103
+
104
+ // If we are coloring by texture, then load the texture map.
105
+ // Use Map as indicator, because texture hangs around.
106
+ if (model.renderable.getColorTextureMap()) {
107
+ model.internalColorTexture.activate();
108
+ }
109
+
97
110
  // make sure the BOs are up to date
98
111
  publicAPI.updateBufferObjects(ren, actor);
99
112
 
@@ -133,19 +146,44 @@ function vtkOpenGLPolyDataMapper2D(publicAPI, model) {
133
146
  }
134
147
  model.renderable.mapScalars(poly, actor.getProperty().getOpacity());
135
148
  const c = model.renderable.getColorMapColors();
136
- model.haveCellScalars = false;
137
- const scalarMode = model.renderable.getScalarMode();
138
- if (model.renderable.getScalarVisibility()) {
139
- // We must figure out how the scalars should be mapped to the polydata.
140
- if ((scalarMode === ScalarMode.USE_CELL_DATA || scalarMode === ScalarMode.USE_CELL_FIELD_DATA || scalarMode === ScalarMode.USE_FIELD_DATA || !poly.getPointData().getScalars()) && scalarMode !== ScalarMode.USE_POINT_FIELD_DATA && c) {
141
- model.haveCellScalars = true;
142
- }
143
- }
144
149
  const representation = actor.getProperty().getRepresentation();
145
150
  let tcoords = poly.getPointData().getTCoords();
146
151
  if (!model.openGLActor2D.getActiveTextures()) {
147
152
  tcoords = null;
148
153
  }
154
+
155
+ // Flag to check if tcoords are per cell instead of per point
156
+ let useTCoordsPerCell = false;
157
+ // handle color mapping via texture
158
+ if (model.renderable.getColorCoordinates()) {
159
+ tcoords = model.renderable.getColorCoordinates();
160
+ useTCoordsPerCell = model.renderable.getAreScalarsMappedFromCells();
161
+ if (!model.internalColorTexture) {
162
+ model.internalColorTexture = vtkOpenGLTexture.newInstance({
163
+ resizable: true
164
+ });
165
+ }
166
+ const tex = model.internalColorTexture;
167
+ // the following 4 lines allow for NPOT textures
168
+ tex.setMinificationFilter(Filter.NEAREST);
169
+ tex.setMagnificationFilter(Filter.NEAREST);
170
+ tex.setWrapS(Wrap.CLAMP_TO_EDGE);
171
+ tex.setWrapT(Wrap.CLAMP_TO_EDGE);
172
+ tex.setOpenGLRenderWindow(model._openGLRenderWindow);
173
+ const input = model.renderable.getColorTextureMap();
174
+ const ext = input.getExtent();
175
+ const inScalars = input.getPointData().getScalars();
176
+ tex.create2DFromRaw({
177
+ width: ext[1] - ext[0] + 1,
178
+ height: ext[3] - ext[2] + 1,
179
+ numComps: inScalars.getNumberOfComponents(),
180
+ dataType: inScalars.getDataType(),
181
+ data: inScalars.getData()
182
+ });
183
+ tex.activate();
184
+ tex.sendParameters();
185
+ tex.deactivate();
186
+ }
149
187
  const transformCoordinate = model.renderable.getTransformCoordinate();
150
188
  const view = ren.getRenderWindow().getViews()[0];
151
189
  const vsize = view.getViewportSize(ren);
@@ -171,7 +209,8 @@ function vtkOpenGLPolyDataMapper2D(publicAPI, model) {
171
209
  tcoords,
172
210
  colors: c,
173
211
  cellOffset: 0,
174
- haveCellScalars: model.haveCellSCalars,
212
+ useTCoordsPerCell,
213
+ haveCellScalars: model.renderable.getAreScalarsMappedFromCells(),
175
214
  customAttributes: model.renderable.getCustomShaderAttributes().map(arrayName => poly.getPointData().getArrayByName(arrayName))
176
215
  };
177
216
  options.cellOffset += model.primitives[primTypes.Points].getCABO().createVBO(poly.getVerts(), 'verts', representation, options);
@@ -201,6 +240,9 @@ function vtkOpenGLPolyDataMapper2D(publicAPI, model) {
201
240
  if (model.lastBoundBO) {
202
241
  model.lastBoundBO.getVAO().release();
203
242
  }
243
+ if (model.renderable.getColorTextureMap()) {
244
+ model.internalColorTexture.deactivate();
245
+ }
204
246
  };
205
247
  publicAPI.replaceShaderValues = (shaders, ren, actor) => {
206
248
  publicAPI.replaceShaderColor(shaders, ren, actor);
@@ -212,21 +254,28 @@ function vtkOpenGLPolyDataMapper2D(publicAPI, model) {
212
254
  let VSSource = shaders.Vertex;
213
255
  let GSSource = shaders.Geometry;
214
256
  let FSSource = shaders.Fragment;
215
- if (model.haveCellScalars) {
216
- FSSource = vtkShaderProgram.substitute(FSSource, '//VTK::Color::Dec', ['uniform samplerBuffer texture1;']).result;
217
- FSSource = vtkShaderProgram.substitute(FSSource, '//VTK::Color::Impl', ['gl_FragData[0] = texelFetchBuffer(texture1, gl_PrimitiveID + PrimitiveIDOffset);']).result;
218
- }
257
+
258
+ // create the color property declarations
259
+ // these are always defined
260
+ let colorDec = ['uniform vec3 diffuseColorUniform;', 'uniform float opacityUniform;'];
261
+
262
+ // now handle the more complex fragment shader implementation
263
+ let colorImpl = ['vec3 diffuseColor = diffuseColorUniform;', 'float opacity = opacityUniform;'];
264
+
265
+ // add scalar vertex colors
219
266
  if (model.lastBoundBO.getCABO().getColorComponents() !== 0) {
220
- VSSource = vtkShaderProgram.substitute(VSSource, '//VTK::Color::Dec', ['in vec4 diffuseColor;', 'out vec4 fcolorVSOutput;']).result;
221
- VSSource = vtkShaderProgram.substitute(VSSource, '//VTK::Color::Impl', ['fcolorVSOutput = diffuseColor;']).result;
222
- GSSource = vtkShaderProgram.substitute(GSSource, '//VTK::Color::Dec', ['in vec4 fcolorVSOutput[];\n', 'out vec4 fcolorGSOutput;']).result;
223
- GSSource = vtkShaderProgram.substitute(GSSource, '//VTK::Color::Impl', ['fcolorGSOutput = fcolorVSOutput[i];']).result;
224
- FSSource = vtkShaderProgram.substitute(FSSource, '//VTK::Color::Dec', ['in vec4 fcolorVSOutput;']).result;
225
- FSSource = vtkShaderProgram.substitute(FSSource, '//VTK::Color::Impl', ['gl_FragData[0] = fcolorVSOutput;']).result;
226
- } else {
227
- FSSource = vtkShaderProgram.substitute(FSSource, '//VTK::Color::Dec', ['uniform vec4 diffuseColor;']).result;
228
- FSSource = vtkShaderProgram.substitute(FSSource, '//VTK::Color::Impl', ['gl_FragData[0] = diffuseColor;']).result;
267
+ colorDec = colorDec.concat(['varying vec4 vertexColorVSOutput;']);
268
+ VSSource = vtkShaderProgram.substitute(VSSource, '//VTK::Color::Dec', ['attribute vec4 scalarColor;', 'varying vec4 vertexColorVSOutput;']).result;
269
+ VSSource = vtkShaderProgram.substitute(VSSource, '//VTK::Color::Impl', ['vertexColorVSOutput = scalarColor;']).result;
270
+ GSSource = vtkShaderProgram.substitute(GSSource, '//VTK::Color::Dec', ['in vec4 vertexColorVSOutput[];', 'out vec4 vertexColorGSOutput;']).result;
271
+ GSSource = vtkShaderProgram.substitute(GSSource, '//VTK::Color::Impl', ['vertexColorGSOutput = vertexColorVSOutput[i];']).result;
272
+ FSSource = vtkShaderProgram.substitute(FSSource, '//VTK::Color::Impl', colorImpl.concat([' diffuseColor = vertexColorVSOutput.rgb;', ' opacity = opacity*vertexColorVSOutput.a;'])).result;
273
+ } else if (model.renderable.getAreScalarsMappedFromCells()) {
274
+ colorImpl = colorImpl.concat([' vec4 texColor = texture2D(texture1, tcoordVCVSOutput.st);', ' diffuseColor = texColor.rgb;', ' opacity = opacity*texColor.a;']);
229
275
  }
276
+ colorImpl = colorImpl.concat(['gl_FragData[0] = vec4(diffuseColor, opacity);']);
277
+ FSSource = vtkShaderProgram.substitute(FSSource, '//VTK::Color::Dec', colorDec).result;
278
+ FSSource = vtkShaderProgram.substitute(FSSource, '//VTK::Color::Impl', colorImpl).result;
230
279
  shaders.Vertex = VSSource;
231
280
  shaders.Geometry = GSSource;
232
281
  shaders.Fragment = FSSource;
@@ -252,7 +301,7 @@ function vtkOpenGLPolyDataMapper2D(publicAPI, model) {
252
301
  FSSource = vtkShaderProgram.substitute(FSSource, '//VTK::TCoord::Dec', ['in vec2 tcoordVCVSOutput;', 'uniform sampler2D texture1;']).result;
253
302
  FSSource = vtkShaderProgram.substitute(FSSource, '//VTK::TCoord::Impl', ['gl_FragData[0] = gl_FragData[0]*texture2D(texture1, tcoordVCVSOutput.st);']).result;
254
303
  }
255
- if (model.haveCellScalars) {
304
+ if (model.renderable.getAreScalarsMappedFromCells()) {
256
305
  GSSource = vtkShaderProgram.substitute(GSSource, '//VTK::PrimID::Impl', ['gl_PrimitiveID = gl_PrimitiveIDIn;']).result;
257
306
  }
258
307
  shaders.Vertex = VSSource;
@@ -303,8 +352,18 @@ function vtkOpenGLPolyDataMapper2D(publicAPI, model) {
303
352
  } else {
304
353
  cellBO.getVAO().removeAttributeArray('tcoordMC');
305
354
  }
355
+ if (cellBO.getProgram().isAttributeUsed('scalarColor') && cellBO.getCABO().getColorComponents()) {
356
+ if (!cellBO.getVAO().addAttributeArray(cellBO.getProgram(), cellBO.getCABO().getColorBO(), 'scalarColor', cellBO.getCABO().getColorOffset(), cellBO.getCABO().getColorBOStride(), model.context.UNSIGNED_BYTE, 4, true)) {
357
+ vtkErrorMacro('Error setting scalarColor in shader VAO.');
358
+ }
359
+ } else {
360
+ cellBO.getVAO().removeAttributeArray('scalarColor');
361
+ }
306
362
  if (model.internalColorTexture && cellBO.getProgram().isUniformUsed('texture1')) {
307
- cellBO.getProgram().setUniformi('texture1', model.internalColorTexture.getTextureUnit());
363
+ const texUnit = model.internalColorTexture.getTextureUnit();
364
+ if (texUnit > -1) {
365
+ cellBO.getProgram().setUniformi('texture1', model.internalColorTexture.getTextureUnit());
366
+ }
308
367
  }
309
368
  const tus = model.openGLActor2D.getActiveTextures();
310
369
  if (tus) {
@@ -331,9 +390,9 @@ function vtkOpenGLPolyDataMapper2D(publicAPI, model) {
331
390
  const program = cellBO.getProgram();
332
391
  const ppty = actor.getProperty();
333
392
  const opacity = ppty.getOpacity();
393
+ program.setUniformf('opacityUniform', opacity);
334
394
  const dColor = ppty.getColor();
335
- const diffuseColor = [dColor[0], dColor[1], dColor[2], opacity];
336
- program.setUniform4f('diffuseColor', diffuseColor);
395
+ program.setUniform3fArray('diffuseColorUniform', dColor);
337
396
  }
338
397
  };
339
398
  publicAPI.setLightingShaderParameters = (cellBO, ren, actor) => {
@@ -3,7 +3,7 @@ import Constants from './Texture/Constants.js';
3
3
  import HalfFloat from '../../Common/Core/HalfFloat.js';
4
4
  import { n as newInstance$1, o as obj, s as set, e as setGet, g as get, i as moveToProtected, a as newTypedArray, c as macro } from '../../macros2.js';
5
5
  import vtkDataArray from '../../Common/Core/DataArray.js';
6
- import { W as isPowerOfTwo, R as nearestPowerOfTwo } from '../../Common/Core/Math/index.js';
6
+ import { X as isPowerOfTwo, S as nearestPowerOfTwo } from '../../Common/Core/Math/index.js';
7
7
  import vtkViewNode from '../SceneGraph/ViewNode.js';
8
8
  import { registerOverride } from './ViewNodeFactory.js';
9
9
  import supportsNorm16LinearCached from './Texture/supportsNorm16Linear.js';
@@ -958,20 +958,28 @@ function vtkOpenGLVolumeMapper(publicAPI, model) {
958
958
  });
959
959
  }
960
960
  }
961
- const volumeProperties = actor.getProperties();
962
- const firstValidInput = model.currentValidInputs[0];
963
- const firstImageData = firstValidInput.imageData;
964
- const firstScalars = firstImageData.getPointData().getScalars();
965
- const firstVolumeProperty = volumeProperties[firstValidInput.inputIndex];
966
-
967
- // Get the number of lights
968
961
  let newNumberOfLights = 0;
969
- if (firstVolumeProperty.getShade() && model.renderable.getBlendMode() === BlendMode.COMPOSITE_BLEND) {
970
- ren.getLights().forEach(light => {
971
- if (light.getSwitch() > 0) {
972
- newNumberOfLights++;
973
- }
974
- });
962
+ if (model.currentValidInputs.length > 0) {
963
+ const volumeProperties = actor.getProperties();
964
+ const firstValidInput = model.currentValidInputs[0];
965
+ const firstImageData = firstValidInput.imageData;
966
+ const firstScalars = firstImageData.getPointData().getScalars();
967
+ const firstVolumeProperty = volumeProperties[firstValidInput.inputIndex];
968
+
969
+ // Get the number of lights
970
+ if (firstVolumeProperty.getShade() && model.renderable.getBlendMode() === BlendMode.COMPOSITE_BLEND) {
971
+ ren.getLights().forEach(light => {
972
+ if (light.getSwitch() > 0) {
973
+ newNumberOfLights++;
974
+ }
975
+ });
976
+ }
977
+
978
+ // Number of components
979
+ const numberOfValidInputs = model.currentValidInputs.length;
980
+ const multiTexturePerVolumeEnabled = numberOfValidInputs > 1;
981
+ model.numberOfComponents = multiTexturePerVolumeEnabled ? numberOfValidInputs : firstScalars.getNumberOfComponents();
982
+ model.useIndependentComponents = getUseIndependentComponents(firstVolumeProperty, model.numberOfComponents);
975
983
  }
976
984
  if (newNumberOfLights !== model.numberOfLights) {
977
985
  model.numberOfLights = newNumberOfLights;
@@ -983,12 +991,6 @@ function vtkOpenGLVolumeMapper(publicAPI, model) {
983
991
  if (model.currentValidInputs.length === 0) {
984
992
  return;
985
993
  }
986
-
987
- // Number of components
988
- const numberOfValidInputs = model.currentValidInputs.length;
989
- const multiTexturePerVolumeEnabled = numberOfValidInputs > 1;
990
- model.numberOfComponents = multiTexturePerVolumeEnabled ? numberOfValidInputs : firstScalars.getNumberOfComponents();
991
- model.useIndependentComponents = getUseIndependentComponents(firstVolumeProperty, model.numberOfComponents);
992
994
  publicAPI.renderPieceStart(ren, actor);
993
995
  publicAPI.renderPieceDraw(ren, actor);
994
996
  publicAPI.renderPieceFinish(ren, actor);
@@ -1,5 +1,5 @@
1
1
  import { m as macro } from '../../macros2.js';
2
- import { d as dot, s as subtract, j as cross, w as multiplyScalar, k as add } from '../../Common/Core/Math/index.js';
2
+ import { d as dot, s as subtract, j as cross, x as multiplyScalar, k as add } from '../../Common/Core/Math/index.js';
3
3
  import vtkAbstractManipulator from './AbstractManipulator.js';
4
4
  import { EPSILON } from '../../Common/Core/Math/Constants.js';
5
5
 
@@ -1,7 +1,7 @@
1
1
  import { m as macro } from '../../macros2.js';
2
2
  import vtkActor from '../../Rendering/Core/Actor.js';
3
3
  import vtkMapper from '../../Rendering/Core/Mapper.js';
4
- import { D as areEquals } from '../../Common/Core/Math/index.js';
4
+ import { E as areEquals } from '../../Common/Core/Math/index.js';
5
5
  import vtkBoundingBox from '../../Common/DataModel/BoundingBox.js';
6
6
  import vtkTubeFilter from '../../Filters/General/TubeFilter.js';
7
7
  import { getPixelWorldHeightAtCoord } from '../Core/WidgetManager.js';
@@ -3,7 +3,7 @@ import vtkAbstractWidgetFactory from '../Core/AbstractWidgetFactory.js';
3
3
  import vtkPlanePointManipulator from '../Manipulators/PlaneManipulator.js';
4
4
  import vtkPolyLineRepresentation from '../Representations/PolyLineRepresentation.js';
5
5
  import vtkSphereHandleRepresentation from '../Representations/SphereHandleRepresentation.js';
6
- import { s as subtract, X as angleBetweenVectors } from '../../Common/Core/Math/index.js';
6
+ import { s as subtract, Y as angleBetweenVectors } from '../../Common/Core/Math/index.js';
7
7
  import widgetBehavior from './AngleWidget/behavior.js';
8
8
  import generateState from './AngleWidget/state.js';
9
9
  import { ViewTypes } from '../Core/WidgetManager/Constants.js';
@@ -1,4 +1,4 @@
1
- import { s as subtract, w as multiplyScalar, k as add, D as areEquals } from '../../../Common/Core/Math/index.js';
1
+ import { s as subtract, x as multiplyScalar, k as add, E as areEquals } from '../../../Common/Core/Math/index.js';
2
2
 
3
3
  function calculateTextPosition(model) {
4
4
  const vector = [0, 0, 0];
@@ -1,7 +1,7 @@
1
1
  import { m as macro } from '../../../macros2.js';
2
2
  import vtkBoundingBox from '../../../Common/DataModel/BoundingBox.js';
3
3
  import vtkLine from '../../../Common/DataModel/Line.js';
4
- import { k as add, l as normalize, s as subtract, d as dot, j as cross, m as multiplyAccumulate, w as multiplyScalar, Y as signedAngleBetweenVectors } from '../../../Common/Core/Math/index.js';
4
+ import { k as add, l as normalize, s as subtract, d as dot, j as cross, m as multiplyAccumulate, x as multiplyScalar, Z as signedAngleBetweenVectors } from '../../../Common/Core/Math/index.js';
5
5
  import { getLineNames, getOtherLineName, updateState, boundPointOnPlane, getLinePlaneName, getLineInPlaneName, rotateVector } from './helpers.js';
6
6
  import { InteractionMethodsName, ScrollingMethods, planeNameToViewType } from './Constants.js';
7
7
 
@@ -2,7 +2,7 @@ import vtkBoundingBox, { STATIC } from '../../../Common/DataModel/BoundingBox.js
2
2
  import vtkCubeSource from '../../../Filters/Sources/CubeSource.js';
3
3
  import vtkCutter from '../../../Filters/Core/Cutter.js';
4
4
  import vtkPlane from '../../../Common/DataModel/Plane.js';
5
- import { s as subtract, l as normalize, j as cross, w as multiplyScalar, m as multiplyAccumulate, Y as signedAngleBetweenVectors } from '../../../Common/Core/Math/index.js';
5
+ import { s as subtract, l as normalize, j as cross, x as multiplyScalar, m as multiplyAccumulate, Z as signedAngleBetweenVectors } from '../../../Common/Core/Math/index.js';
6
6
  import vtkMatrixBuilder from '../../../Common/Core/MatrixBuilder.js';
7
7
  import { viewTypeToPlaneName, planeNameToViewType, planeNames } from './Constants.js';
8
8
 
@@ -7,7 +7,7 @@ import vtkPlaneSource from '../../Filters/Sources/PlaneSource.js';
7
7
  import vtkPlanePointManipulator from '../Manipulators/PlaneManipulator.js';
8
8
  import vtkLineHandleRepresentation from '../Representations/LineHandleRepresentation.js';
9
9
  import vtkSphereHandleRepresentation from '../Representations/SphereHandleRepresentation.js';
10
- import { e as distance2BetweenPoints, m as multiplyAccumulate, s as subtract, l as normalize, w as multiplyScalar, k as add } from '../../Common/Core/Math/index.js';
10
+ import { e as distance2BetweenPoints, m as multiplyAccumulate, s as subtract, l as normalize, x as multiplyScalar, k as add } from '../../Common/Core/Math/index.js';
11
11
  import widgetBehavior from './ResliceCursorWidget/behavior.js';
12
12
  import generateState from './ResliceCursorWidget/state.js';
13
13
  import { updateState, transformPlane, boundPlane } from './ResliceCursorWidget/helpers.js';
package/index.d.ts CHANGED
@@ -52,6 +52,7 @@
52
52
  /// <reference path="./Common/DataModel/Spline3D/Constants.d.ts" />
53
53
  /// <reference path="./Common/DataModel/Spline3D.d.ts" />
54
54
  /// <reference path="./Common/DataModel/Triangle.d.ts" />
55
+ /// <reference path="./Common/DataModel/TriangleStrip.d.ts" />
55
56
  /// <reference path="./Common/Transform/LandmarkTransform.d.ts" />
56
57
  /// <reference path="./Common/Transform/Transform.d.ts" />
57
58
  /// <reference path="./Filters/Core/ThresholdPoints.d.ts" />
@@ -66,6 +67,7 @@
66
67
  /// <reference path="./Filters/General/ImageStreamline.d.ts" />
67
68
  /// <reference path="./Filters/General/LineFilter.d.ts" />
68
69
  /// <reference path="./Filters/General/OutlineFilter.d.ts" />
70
+ /// <reference path="./Filters/General/TransformPolyDataFilter.d.ts" />
69
71
  /// <reference path="./Filters/General/TriangleFilter.d.ts" />
70
72
  /// <reference path="./Filters/General/TubeFilter.d.ts" />
71
73
  /// <reference path="./Filters/Sources/Arrow2DSource.d.ts" />
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kitware/vtk.js",
3
- "version": "34.4.0",
3
+ "version": "34.6.0",
4
4
  "description": "Visualization Toolkit for the Web",
5
5
  "keywords": [
6
6
  "3d",