@kitware/vtk.js 24.13.0 → 24.14.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.
@@ -12,7 +12,10 @@ import { v as vtkPolyDataVS } from './glsl/vtkPolyDataVS.glsl.js';
12
12
  import { v as vtkPolyDataFS } from './glsl/vtkPolyDataFS.glsl.js';
13
13
  import vtkReplacementShaderMapper from './ReplacementShaderMapper.js';
14
14
  import { registerOverride } from './ViewNodeFactory.js';
15
+ import { PassTypes } from './HardwareSelector/Constants.js';
16
+ import vtkDataSet from '../../Common/DataModel/DataSet.js';
15
17
 
18
+ var FieldAssociations = vtkDataSet.FieldAssociations;
16
19
  /* eslint-disable no-lonely-if */
17
20
 
18
21
  var primTypes = vtkHelper.primTypes;
@@ -31,6 +34,16 @@ var EndEvent = {
31
34
  // vtkOpenGLPolyDataMapper methods
32
35
  // ----------------------------------------------------------------------------
33
36
 
37
+ function getPickState(renderer) {
38
+ var selector = renderer.getSelector();
39
+
40
+ if (selector) {
41
+ return selector.getCurrentPass();
42
+ }
43
+
44
+ return PassTypes.MIN_KNOWN_PASS - 1;
45
+ }
46
+
34
47
  function vtkOpenGLPolyDataMapper(publicAPI, model) {
35
48
  // Set our className
36
49
  model.classHierarchy.push('vtkOpenGLPolyDataMapper');
@@ -475,7 +488,10 @@ function vtkOpenGLPolyDataMapper(publicAPI, model) {
475
488
  publicAPI.getCoincidentParameters = function (ren, actor) {
476
489
  // 1. ResolveCoincidentTopology is On and non zero for this primitive
477
490
  // type
478
- var cp = null;
491
+ var cp = {
492
+ factor: 0.0,
493
+ offset: 0.0
494
+ };
479
495
  var prop = actor.getProperty();
480
496
 
481
497
  if (model.renderable.getResolveCoincidentTopology() || prop.getEdgeVisibility() && prop.getRepresentation() === Representation.SURFACE) {
@@ -496,23 +512,49 @@ function vtkOpenGLPolyDataMapper(publicAPI, model) {
496
512
  }
497
513
  } // hardware picking always offset due to saved zbuffer
498
514
  // This gets you above the saved surface depth buffer.
499
- // vtkHardwareSelector* selector = ren->GetSelector();
500
- // if (selector &&
501
- // selector->GetFieldAssociation() == vtkDataObject::FIELD_ASSOCIATION_POINTS)
502
- // {
503
- // offset -= 2.0;
504
- // return;
505
- // }
506
515
 
507
516
 
517
+ var selector = model.openGLRenderer.getSelector();
518
+
519
+ if (selector && selector.getFieldAssociation() === FieldAssociations.FIELD_ASSOCIATION_POINTS) {
520
+ cp.offset -= 2.0;
521
+ }
522
+
508
523
  return cp;
509
524
  };
510
525
 
511
526
  publicAPI.replaceShaderPicking = function (shaders, ren, actor) {
512
527
  var FSSource = shaders.Fragment;
513
- FSSource = vtkShaderProgram.substitute(FSSource, '//VTK::Picking::Dec', ['uniform vec3 mapperIndex;', 'uniform int picking;']).result;
514
- FSSource = vtkShaderProgram.substitute(FSSource, '//VTK::Picking::Impl', ' gl_FragData[0] = picking != 0 ? vec4(mapperIndex,1.0) : gl_FragData[0];').result;
528
+ var VSSource = shaders.Vertex;
529
+ FSSource = vtkShaderProgram.substitute(FSSource, '//VTK::Picking::Dec', ['uniform int picking;', '//VTK::Picking::Dec']).result;
530
+
531
+ if (!model.openGLRenderer.getSelector()) {
532
+ return;
533
+ }
534
+
535
+ if (model.lastSelectionState === PassTypes.ID_LOW24 || model.lastSelectionState === PassTypes.ID_HIGH24) {
536
+ VSSource = vtkShaderProgram.substitute(VSSource, '//VTK::Picking::Dec', ['flat out int vertexIDVSOutput;\n', 'uniform int VertexIDOffset;\n']).result;
537
+ VSSource = vtkShaderProgram.substitute(VSSource, '//VTK::Picking::Impl', ' vertexIDVSOutput = gl_VertexID + VertexIDOffset;\n').result;
538
+ FSSource = vtkShaderProgram.substitute(FSSource, '//VTK::Picking::Dec', 'flat in int vertexIDVSOutput;\n').result;
539
+ FSSource = vtkShaderProgram.substitute(FSSource, '//VTK::Picking::Impl', [' int idx = vertexIDVSOutput;', '//VTK::Picking::Impl']).result;
540
+ }
541
+
542
+ switch (model.lastSelectionState) {
543
+ case PassTypes.ID_LOW24:
544
+ FSSource = vtkShaderProgram.substitute(FSSource, '//VTK::Picking::Impl', ' gl_FragData[0] = vec4(float(idx%256)/255.0, float((idx/256)%256)/255.0, float((idx/65536)%256)/255.0, 1.0);').result;
545
+ break;
546
+
547
+ case PassTypes.ID_HIGH24:
548
+ FSSource = vtkShaderProgram.substitute(FSSource, '//VTK::Picking::Impl', ' gl_FragData[0] = vec4(float(idx)/255.0, 0.0, 0.0, 1.0);').result;
549
+ break;
550
+
551
+ default:
552
+ FSSource = vtkShaderProgram.substitute(FSSource, '//VTK::Picking::Dec', 'uniform vec3 mapperIndex;').result;
553
+ FSSource = vtkShaderProgram.substitute(FSSource, '//VTK::Picking::Impl', ' gl_FragData[0] = picking != 0 ? vec4(mapperIndex,1.0) : gl_FragData[0];').result;
554
+ }
555
+
515
556
  shaders.Fragment = FSSource;
557
+ shaders.Vertex = VSSource;
516
558
  };
517
559
 
518
560
  publicAPI.replaceShaderValues = function (shaders, ren, actor) {
@@ -616,7 +658,7 @@ function vtkOpenGLPolyDataMapper(publicAPI, model) {
616
658
  // light complexity changed
617
659
 
618
660
 
619
- if (model.lastHaveSeenDepthRequest !== model.haveSeenDepthRequest || cellBO.getShaderSourceTime().getMTime() < model.renderable.getMTime() || cellBO.getShaderSourceTime().getMTime() < model.currentInput.getMTime() || needRebuild) {
661
+ if (model.lastHaveSeenDepthRequest !== model.haveSeenDepthRequest || cellBO.getShaderSourceTime().getMTime() < model.renderable.getMTime() || cellBO.getShaderSourceTime().getMTime() < model.currentInput.getMTime() || cellBO.getShaderSourceTime().getMTime() < model.selectionStateChanged.getMTime() || needRebuild) {
620
662
  model.lastHaveSeenDepthRequest = model.haveSeenDepthRequest;
621
663
  return true;
622
664
  }
@@ -640,6 +682,10 @@ function vtkOpenGLPolyDataMapper(publicAPI, model) {
640
682
  cellBO.getProgram().setUniformi('PrimitiveIDOffset', model.primitiveIDOffset);
641
683
  }
642
684
 
685
+ if (cellBO.getProgram().isUniformUsed('VertexIDOffset')) {
686
+ cellBO.getProgram().setUniformi('VertexIDOffset', model.vertexIDOffset);
687
+ }
688
+
643
689
  if (cellBO.getCABO().getElementCount() && (model.VBOBuildTime.getMTime() > cellBO.getAttributeUpdateTime().getMTime() || cellBO.getShaderSourceTime().getMTime() > cellBO.getAttributeUpdateTime().getMTime())) {
644
690
  var lastLightComplexity = model.lastBoundBO.getReferenceByName('lastLightComplexity');
645
691
 
@@ -934,11 +980,44 @@ function vtkOpenGLPolyDataMapper(publicAPI, model) {
934
980
  }
935
981
  };
936
982
 
983
+ publicAPI.updateMaximumPointCellIds = function (ren, actor) {
984
+ var _model$selectionWebGL, _model$selectionWebGL2, _model$selectionWebGL3, _model$selectionWebGL4;
985
+
986
+ var selector = model.openGLRenderer.getSelector();
987
+
988
+ if (!selector) {
989
+ return;
990
+ }
991
+
992
+ if ((_model$selectionWebGL = model.selectionWebGLIdsToVTKIds) !== null && _model$selectionWebGL !== void 0 && (_model$selectionWebGL2 = _model$selectionWebGL.points) !== null && _model$selectionWebGL2 !== void 0 && _model$selectionWebGL2.length) {
993
+ var length = model.selectionWebGLIdsToVTKIds.points.length;
994
+ selector.setMaximumPointId(length - 1);
995
+ }
996
+
997
+ if ((_model$selectionWebGL3 = model.selectionWebGLIdsToVTKIds) !== null && _model$selectionWebGL3 !== void 0 && (_model$selectionWebGL4 = _model$selectionWebGL3.cells) !== null && _model$selectionWebGL4 !== void 0 && _model$selectionWebGL4.length) {
998
+ var _length = model.selectionWebGLIdsToVTKIds.cells.length;
999
+ selector.setMaximumCellId(_length - 1);
1000
+ }
1001
+
1002
+ var fieldAssociation = selector.getFieldAssociation();
1003
+
1004
+ if (fieldAssociation === FieldAssociations.FIELD_ASSOCIATION_POINTS) {
1005
+ model.pointPicking = true;
1006
+ }
1007
+ };
1008
+
937
1009
  publicAPI.renderPieceStart = function (ren, actor) {
938
1010
  model.primitiveIDOffset = 0;
1011
+ model.vertexIDOffset = 0;
1012
+ var picking = getPickState(model.openGLRenderer);
1013
+
1014
+ if (model.lastSelectionState !== picking) {
1015
+ model.selectionStateChanged.modified();
1016
+ model.lastSelectionState = picking;
1017
+ }
939
1018
 
940
1019
  if (model.openGLRenderer.getSelector()) {
941
- switch (model.openGLRenderer.getSelector().getCurrentPass()) {
1020
+ switch (picking) {
942
1021
  default:
943
1022
  model.openGLRenderer.getSelector().renderProp(actor);
944
1023
  }
@@ -958,10 +1037,13 @@ function vtkOpenGLPolyDataMapper(publicAPI, model) {
958
1037
 
959
1038
  publicAPI.renderPieceDraw = function (ren, actor) {
960
1039
  var representation = actor.getProperty().getRepresentation();
961
- var drawSurfaceWithEdges = actor.getProperty().getEdgeVisibility() && representation === Representation.SURFACE; // for every primitive type
1040
+ var drawSurfaceWithEdges = actor.getProperty().getEdgeVisibility() && representation === Representation.SURFACE;
1041
+ var selector = model.openGLRenderer.getSelector(); // If we are picking points, we need to tell it to the helper
1042
+
1043
+ var pointPicking = selector && selector.getFieldAssociation() === FieldAssociations.FIELD_ASSOCIATION_POINTS && (model.lastSelectionState === PassTypes.ID_LOW24 || model.lastSelectionState === PassTypes.ID_HIGH24); // for every primitive type
962
1044
 
963
1045
  for (var i = primTypes.Start; i < primTypes.End; i++) {
964
- // if there are entries
1046
+ model.primitives[i].setPointPicking(pointPicking);
965
1047
  var cabo = model.primitives[i].getCABO();
966
1048
 
967
1049
  if (cabo.getElementCount()) {
@@ -971,6 +1053,7 @@ function vtkOpenGLPolyDataMapper(publicAPI, model) {
971
1053
  if (!model.drawingEdges || !model.renderDepth) {
972
1054
  model.lastBoundBO = model.primitives[i];
973
1055
  model.primitiveIDOffset += model.primitives[i].drawArrays(ren, actor, representation, publicAPI);
1056
+ model.vertexIDOffset += model.primitives[i].getCABO().getElementCount();
974
1057
  }
975
1058
  }
976
1059
  }
@@ -1134,41 +1217,70 @@ function vtkOpenGLPolyDataMapper(publicAPI, model) {
1134
1217
  tcoords: tcoords,
1135
1218
  colors: c,
1136
1219
  cellOffset: 0,
1220
+ vertexOffset: 0,
1221
+ // Used to keep track of vertex ids across primitives for selection
1137
1222
  haveCellScalars: model.haveCellScalars,
1138
1223
  haveCellNormals: model.haveCellNormals,
1139
1224
  customAttributes: model.renderable.getCustomShaderAttributes().map(function (arrayName) {
1140
1225
  return poly.getPointData().getArrayByName(arrayName);
1141
1226
  })
1142
1227
  };
1143
- options.cellOffset += model.primitives[primTypes.Points].getCABO().createVBO(poly.getVerts(), 'verts', representation, options);
1144
- options.cellOffset += model.primitives[primTypes.Lines].getCABO().createVBO(poly.getLines(), 'lines', representation, options);
1145
- options.cellOffset += model.primitives[primTypes.Tris].getCABO().createVBO(poly.getPolys(), 'polys', representation, options);
1146
- options.cellOffset += model.primitives[primTypes.TriStrips].getCABO().createVBO(poly.getStrips(), 'strips', representation, options);
1147
- var drawSurfaceWithEdges = actor.getProperty().getEdgeVisibility() && representation === Representation.SURFACE; // if we have edge visibility build the edge VBOs
1148
-
1149
- if (drawSurfaceWithEdges) {
1150
- model.primitives[primTypes.TrisEdges].getCABO().createVBO(poly.getPolys(), 'polys', Representation.WIREFRAME, {
1151
- points: points,
1152
- normals: n,
1153
- tcoords: null,
1154
- colors: null,
1155
- cellOffset: 0,
1156
- haveCellScalars: false,
1157
- haveCellNormals: false
1158
- });
1159
- model.primitives[primTypes.TriStripsEdges].getCABO().createVBO(poly.getStrips(), 'strips', Representation.WIREFRAME, {
1160
- points: points,
1161
- normals: n,
1162
- tcoords: null,
1163
- colors: null,
1164
- cellOffset: 0,
1165
- haveCellScalars: false,
1166
- haveCellNormals: false
1167
- });
1168
- } else {
1169
- // otherwise free them
1170
- model.primitives[primTypes.TrisEdges].releaseGraphicsResources(model._openGLRenderWindow);
1171
- model.primitives[primTypes.TriStripsEdges].releaseGraphicsResources(model._openGLRenderWindow);
1228
+
1229
+ if (model.renderable.getPopulateSelectionSettings()) {
1230
+ model.selectionWebGLIdsToVTKIds = {
1231
+ points: null,
1232
+ cells: null
1233
+ };
1234
+ }
1235
+
1236
+ var primitives = [{
1237
+ inRep: 'verts',
1238
+ cells: poly.getVerts()
1239
+ }, {
1240
+ inRep: 'lines',
1241
+ cells: poly.getLines()
1242
+ }, {
1243
+ inRep: 'polys',
1244
+ cells: poly.getPolys()
1245
+ }, {
1246
+ inRep: 'strips',
1247
+ cells: poly.getStrips()
1248
+ }, {
1249
+ inRep: 'polys',
1250
+ cells: poly.getPolys()
1251
+ }, {
1252
+ inRep: 'strips',
1253
+ cells: poly.getStrips()
1254
+ }];
1255
+ var drawSurfaceWithEdges = // TODO: false if picking
1256
+ actor.getProperty().getEdgeVisibility() && representation === Representation.SURFACE;
1257
+
1258
+ for (var i = primTypes.Start; i < primTypes.End; i++) {
1259
+ if (i !== primTypes.TrisEdges && i !== primTypes.TriStripsEdges) {
1260
+ options.cellOffset += model.primitives[i].getCABO().createVBO(primitives[i].cells, primitives[i].inRep, representation, options, model.selectionWebGLIdsToVTKIds);
1261
+ options.vertexOffset += model.primitives[i].getCABO().getElementCount();
1262
+ } else {
1263
+ // if we have edge visibility build the edge VBOs
1264
+ if (drawSurfaceWithEdges) {
1265
+ model.primitives[i].getCABO().createVBO(primitives[i].cells, primitives[i].inRep, Representation.WIREFRAME, {
1266
+ points: points,
1267
+ normals: n,
1268
+ tcoords: null,
1269
+ colors: null,
1270
+ cellOffset: 0,
1271
+ haveCellScalars: false,
1272
+ haveCellNormals: false
1273
+ });
1274
+ } else {
1275
+ // otherwise free them
1276
+ model.primitives[i].releaseGraphicsResources();
1277
+ }
1278
+ }
1279
+ }
1280
+
1281
+ if (model.renderable.getPopulateSelectionSettings()) {
1282
+ model.renderable.setSelectionWebGLIdsToVTKIds(model.selectionWebGLIdsToVTKIds);
1283
+ publicAPI.updateMaximumPointCellIds();
1172
1284
  }
1173
1285
 
1174
1286
  model.VBOBuildTime.modified();
@@ -1201,7 +1313,11 @@ var DEFAULT_VALUES = {
1201
1313
  lightDirection: [],
1202
1314
  // used internally
1203
1315
  lastHaveSeenDepthRequest: false,
1204
- haveSeenDepthRequest: false
1316
+ haveSeenDepthRequest: false,
1317
+ lastSelectionState: PassTypes.MIN_KNOWN_PASS - 1,
1318
+ selectionStateChanged: null,
1319
+ selectionWebGLIdsToVTKIds: null,
1320
+ pointPicking: false
1205
1321
  }; // ----------------------------------------------------------------------------
1206
1322
 
1207
1323
  function extend(publicAPI, model) {
@@ -1230,6 +1346,10 @@ function extend(publicAPI, model) {
1230
1346
  model.VBOBuildTime = {};
1231
1347
  obj(model.VBOBuildTime, {
1232
1348
  mtime: 0
1349
+ });
1350
+ model.selectionStateChanged = {};
1351
+ obj(model.selectionStateChanged, {
1352
+ mtime: 0
1233
1353
  }); // Object methods
1234
1354
 
1235
1355
  vtkOpenGLPolyDataMapper(publicAPI, model);
@@ -321,7 +321,9 @@ function vtkArrowHandleRepresentation(publicAPI, model) {
321
321
  };
322
322
 
323
323
  publicAPI.requestData = function (inData, outData) {
324
- var shape = publicAPI.getRepresentationStates(inData[0])[0].getShape();
324
+ var _publicAPI$getReprese;
325
+
326
+ var shape = (_publicAPI$getReprese = publicAPI.getRepresentationStates(inData[0])[0]) === null || _publicAPI$getReprese === void 0 ? void 0 : _publicAPI$getReprese.getShape();
325
327
  var shouldCreateGlyph = model.glyph == null;
326
328
 
327
329
  if (model.shape !== shape && Object.values(ShapeType).includes(shape)) {
@@ -329,7 +331,7 @@ function vtkArrowHandleRepresentation(publicAPI, model) {
329
331
  shouldCreateGlyph = true;
330
332
  }
331
333
 
332
- if (shouldCreateGlyph) {
334
+ if (shouldCreateGlyph && model.shape) {
333
335
  model.glyph = createGlyph(model.shape);
334
336
  model.mapper.setInputConnection(model.glyph.getOutputPort(), 1);
335
337
  }
@@ -341,8 +343,8 @@ function vtkArrowHandleRepresentation(publicAPI, model) {
341
343
  var renderingType = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : RenderingTypes.FRONT_BUFFER;
342
344
  var ctxVisible = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
343
345
  var handleVisible = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
344
- var state = publicAPI.getRepresentationStates()[0];
345
- superClass.updateActorVisibility(renderingType, ctxVisible, handleVisible && state.isVisible());
346
+ var hasValidState = publicAPI.getRepresentationStates().length > 0;
347
+ superClass.updateActorVisibility(renderingType, ctxVisible, handleVisible && hasValidState);
346
348
  };
347
349
  } // ----------------------------------------------------------------------------
348
350
  // Object factory
package/index.d.ts CHANGED
@@ -102,11 +102,16 @@
102
102
  /// <reference path="./Rendering/Core/AxesActor.d.ts" />
103
103
  /// <reference path="./Rendering/Core/Camera.d.ts" />
104
104
  /// <reference path="./Rendering/Core/CellPicker.d.ts" />
105
+ /// <reference path="./Rendering/Core/ColorTransferFunction/Constants.d.ts" />
105
106
  /// <reference path="./Rendering/Core/ColorTransferFunction.d.ts" />
107
+ /// <reference path="./Rendering/Core/Coordinate/Constants.d.ts" />
106
108
  /// <reference path="./Rendering/Core/Coordinate.d.ts" />
107
109
  /// <reference path="./Rendering/Core/Follower.d.ts" />
110
+ /// <reference path="./Rendering/Core/Glyph3DMapper/Constants.d.ts" />
108
111
  /// <reference path="./Rendering/Core/Glyph3DMapper.d.ts" />
112
+ /// <reference path="./Rendering/Core/ImageMapper/Constants.d.ts" />
109
113
  /// <reference path="./Rendering/Core/ImageMapper.d.ts" />
114
+ /// <reference path="./Rendering/Core/ImageProperty/Constants.d.ts" />
110
115
  /// <reference path="./Rendering/Core/ImageProperty.d.ts" />
111
116
  /// <reference path="./Rendering/Core/ImageSlice.d.ts" />
112
117
  /// <reference path="./Rendering/Core/Light.d.ts" />
@@ -120,6 +125,7 @@
120
125
  /// <reference path="./Rendering/Core/Prop3D.d.ts" />
121
126
  /// <reference path="./Rendering/Core/Property/Constants.d.ts" />
122
127
  /// <reference path="./Rendering/Core/Property.d.ts" />
128
+ /// <reference path="./Rendering/Core/Property2D/Constants.d.ts" />
123
129
  /// <reference path="./Rendering/Core/Property2D.d.ts" />
124
130
  /// <reference path="./Rendering/Core/RenderWindow.d.ts" />
125
131
  /// <reference path="./Rendering/Core/RenderWindowInteractor/Constants.d.ts" />
@@ -134,6 +140,7 @@
134
140
  /// <reference path="./Rendering/Core/Volume.d.ts" />
135
141
  /// <reference path="./Rendering/Core/VolumeMapper/Constants.d.ts" />
136
142
  /// <reference path="./Rendering/Core/VolumeMapper.d.ts" />
143
+ /// <reference path="./Rendering/Core/VolumeProperty/Constants.d.ts" />
137
144
  /// <reference path="./Rendering/Core/VolumeProperty.d.ts" />
138
145
  /// <reference path="./Rendering/Misc/CanvasView.d.ts" />
139
146
  /// <reference path="./Rendering/Misc/FullScreenRenderWindow.d.ts" />
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kitware/vtk.js",
3
- "version": "24.13.0",
3
+ "version": "24.14.1",
4
4
  "description": "Visualization Toolkit for the Web",
5
5
  "keywords": [
6
6
  "3d",