@kitware/vtk.js 25.10.1 → 25.11.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.
@@ -1,7 +1,9 @@
1
1
  import _defineProperty from '@babel/runtime/helpers/defineProperty';
2
2
  import { mat4, vec4 } from 'gl-matrix';
3
- import macro from '../../macros.js';
3
+ import macro, { vtkWarningMacro } from '../../macros.js';
4
4
  import vtkDataArray from '../../Common/Core/DataArray.js';
5
+ import { g as vtkMath } from '../../Common/Core/Math/index.js';
6
+ import vtkMatrixBuilder from '../../Common/Core/MatrixBuilder.js';
5
7
  import { VtkDataTypes } from '../../Common/Core/DataArray/Constants.js';
6
8
  import vtkBoundingBox from '../../Common/DataModel/BoundingBox.js';
7
9
  import vtkImageData from '../../Common/DataModel/ImageData.js';
@@ -15,14 +17,16 @@ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (O
15
17
 
16
18
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
17
19
  var SlabMode = Constants.SlabMode;
18
- var capitalize = macro.capitalize,
19
- vtkErrorMacro = macro.vtkErrorMacro; // ----------------------------------------------------------------------------
20
+ var vtkErrorMacro = macro.vtkErrorMacro; // ----------------------------------------------------------------------------
20
21
  // vtkImageReslice methods
21
22
  // ----------------------------------------------------------------------------
22
23
 
23
24
  function vtkImageReslice(publicAPI, model) {
24
25
  // Set our className
25
26
  model.classHierarchy.push('vtkImageReslice');
27
+
28
+ var superClass = _objectSpread({}, publicAPI);
29
+
26
30
  var indexMatrix = null;
27
31
  var optimizedTransform = null;
28
32
 
@@ -97,6 +101,16 @@ function vtkImageReslice(publicAPI, model) {
97
101
  getImageResliceSlabTrap(tmpPtr, inComponents, sampleCount, f);
98
102
  }
99
103
 
104
+ publicAPI.getMTime = function () {
105
+ var mTime = superClass.getMTime();
106
+
107
+ if (model.resliceTransform) {
108
+ mTime = Math.max(mTime, model.resliceTransform.getMTime());
109
+ }
110
+
111
+ return mTime;
112
+ };
113
+
100
114
  publicAPI.setResliceAxes = function (resliceAxes) {
101
115
  if (!model.resliceAxes) {
102
116
  model.resliceAxes = mat4.identity(new Float64Array(16));
@@ -131,12 +145,10 @@ function vtkImageReslice(publicAPI, model) {
131
145
  var outSpacing = [1, 1, 1];
132
146
  var outWholeExt = [0, 0, 0, 0, 0, 0];
133
147
  var outDims = [0, 0, 0];
134
- var matrix = null;
148
+ var matrix = mat4.identity(new Float64Array(16));
135
149
 
136
150
  if (model.resliceAxes) {
137
- matrix = model.resliceAxes;
138
- } else {
139
- matrix = mat4.identity(new Float64Array(16));
151
+ mat4.multiply(matrix, matrix, model.resliceAxes);
140
152
  }
141
153
 
142
154
  var imatrix = new Float64Array(16);
@@ -236,6 +248,11 @@ function vtkImageReslice(publicAPI, model) {
236
248
  output.setDimensions(outDims);
237
249
  output.setOrigin(outOrigin);
238
250
  output.setSpacing(outSpacing);
251
+
252
+ if (model.outputDirection) {
253
+ output.setDirection(model.outputDirection);
254
+ }
255
+
239
256
  output.getPointData().setScalars(outScalars);
240
257
  publicAPI.getIndexMatrix(input, output);
241
258
  var interpolationMode = model.interpolationMode;
@@ -340,7 +357,7 @@ function vtkImageReslice(publicAPI, model) {
340
357
  var floatPtr = null;
341
358
 
342
359
  if (!optimizeNearest) {
343
- floatPtr = new Float64Array(inComponents * (outExt[1] - outExt[0]));
360
+ floatPtr = new Float64Array(inComponents * (outExt[1] - outExt[0] + nsamples));
344
361
  }
345
362
 
346
363
  var background = macro.newTypedArray(inputScalarType, model.backgroundColor); // set color for area outside of input volume extent
@@ -577,6 +594,20 @@ function vtkImageReslice(publicAPI, model) {
577
594
  }
578
595
  }
579
596
  };
597
+ /**
598
+ * The transform matrix supplied by the user converts output coordinates
599
+ * to input coordinates.
600
+ * To speed up the pixel lookup, the following function provides a
601
+ * matrix which converts output pixel indices to input pixel indices.
602
+ * This will also concatenate the ResliceAxes and the ResliceTransform
603
+ * if possible (if the ResliceTransform is a 4x4 matrix transform).
604
+ * If it does, this->OptimizedTransform will be set to nullptr, otherwise
605
+ * this->OptimizedTransform will be equal to this->ResliceTransform.
606
+ * @param {vtkPolyData} input
607
+ * @param {vtkPolyData} output
608
+ * @returns
609
+ */
610
+
580
611
 
581
612
  publicAPI.getIndexMatrix = function (input, output) {
582
613
  // first verify that we have to update the matrix
@@ -586,6 +617,7 @@ function vtkImageReslice(publicAPI, model) {
586
617
 
587
618
  var inOrigin = input.getOrigin();
588
619
  var inSpacing = input.getSpacing();
620
+ var inDirection = input.getDirection();
589
621
  var outOrigin = output.getOrigin();
590
622
  var outSpacing = output.getSpacing();
591
623
  var transform = mat4.identity(new Float64Array(16));
@@ -596,14 +628,29 @@ function vtkImageReslice(publicAPI, model) {
596
628
  mat4.copy(transform, model.resliceAxes);
597
629
  }
598
630
 
599
- if (model.resliceTransform) ; // check to see if we have an identity matrix
631
+ if (model.resliceTransform) {
632
+ if (model.resliceTransform.isA('vtkHomogeneousTransform')) {
633
+ // transform->PostMultiply();
634
+ // transform->Concatenate(
635
+ // mat4.multiply(transform, transform, model.resliceTransform.getMatrix());
636
+ mat4.multiply(transform, model.resliceTransform.getMatrix(), transform);
637
+ } else {
638
+ // TODO
639
+ vtkWarningMacro('Non homogeneous transform have not yet been ported');
640
+ }
641
+ }
642
+
643
+ if (!vtkMath.isIdentity3x3(inDirection)) {
644
+ var imageTransform = vtkMatrixBuilder.buildFromRadian().translate(inOrigin[0], inOrigin[1], inOrigin[2]).multiply3x3(inDirection).translate(-inOrigin[0], -inOrigin[1], -inOrigin[2]);
645
+ mat4.multiply(transform, imageTransform.getMatrix(), transform);
646
+ } // check to see if we have an identity matrix
600
647
 
601
648
 
602
- var isIdentity = publicAPI.isIdentityMatrix(transform); // the outMatrix takes OutputData indices to OutputData coordinates,
649
+ var isIdentity = vtkMath.isIdentity(transform); // the outMatrix takes OutputData indices to OutputData coordinates,
603
650
  // the inMatrix takes InputData coordinates to InputData indices
604
651
 
605
652
  for (var i = 0; i < 3; i++) {
606
- if ((inSpacing[i] !== outSpacing[i] || inOrigin[i] !== outOrigin[i]) || optimizedTransform !== null ) {
653
+ if ((inSpacing[i] !== outSpacing[i] || inOrigin[i] !== outOrigin[i]) || optimizedTransform != null ) {
607
654
  isIdentity = false;
608
655
  }
609
656
 
@@ -633,6 +680,7 @@ function vtkImageReslice(publicAPI, model) {
633
680
  publicAPI.getAutoCroppedOutputBounds = function (input) {
634
681
  var inOrigin = input.getOrigin();
635
682
  var inSpacing = input.getSpacing();
683
+ var inDirection = input.getDirection();
636
684
  var dims = input.getDimensions();
637
685
  var inWholeExt = [0, dims[0] - 1, 0, dims[1] - 1, 0, dims[2] - 1];
638
686
  var matrix = new Float64Array(16);
@@ -643,6 +691,18 @@ function vtkImageReslice(publicAPI, model) {
643
691
  mat4.identity(matrix);
644
692
  }
645
693
 
694
+ var transform = null;
695
+
696
+ if (model.resliceTransform) {
697
+ transform = model.resliceTransform.getInverse();
698
+ }
699
+
700
+ var imageTransform = null;
701
+
702
+ if (!vtkMath.isIdentity3x3(inDirection)) {
703
+ imageTransform = vtkMatrixBuilder.buildFromRadian().translate(inOrigin[0], inOrigin[1], inOrigin[2]).multiply3x3(inDirection).translate(-inOrigin[0], -inOrigin[1], -inOrigin[2]).invert().getMatrix();
704
+ }
705
+
646
706
  var bounds = [Number.MAX_VALUE, -Number.MAX_VALUE, Number.MAX_VALUE, -Number.MAX_VALUE, Number.MAX_VALUE, -Number.MAX_VALUE];
647
707
  var point = [0, 0, 0, 0];
648
708
 
@@ -652,7 +712,13 @@ function vtkImageReslice(publicAPI, model) {
652
712
  point[2] = inOrigin[2] + inWholeExt[4 + Math.floor(i / 4) % 2] * inSpacing[2];
653
713
  point[3] = 1.0;
654
714
 
655
- if (model.resliceTransform) ;
715
+ if (imageTransform) {
716
+ vec4.transformMat4(point, point, imageTransform);
717
+ }
718
+
719
+ if (model.resliceTransform) {
720
+ transform.transformPoint(point, point);
721
+ }
656
722
 
657
723
  vec4.transformMat4(point, point, matrix);
658
724
  var f = 1.0 / point[3];
@@ -931,27 +997,6 @@ function vtkImageReslice(publicAPI, model) {
931
997
 
932
998
  return 1;
933
999
  };
934
- }
935
-
936
- function setNullArray(publicAPI, model, fieldNames) {
937
- fieldNames.forEach(function (field) {
938
- var setterName = "set".concat(capitalize(field));
939
- var superSet = publicAPI[setterName];
940
-
941
- publicAPI[setterName] = function () {
942
- if (arguments.length === 1 && (arguments.length <= 0 ? undefined : arguments[0]) == null || model[field] == null) {
943
- if ((arguments.length <= 0 ? undefined : arguments[0]) !== model[field]) {
944
- model[field] = arguments.length <= 0 ? undefined : arguments[0];
945
- publicAPI.modified();
946
- return true;
947
- }
948
-
949
- return null;
950
- }
951
-
952
- return superSet.apply(void 0, arguments);
953
- };
954
- });
955
1000
  } // ----------------------------------------------------------------------------
956
1001
  // Object factory
957
1002
  // ----------------------------------------------------------------------------
@@ -965,6 +1010,8 @@ var DEFAULT_VALUES = {
965
1010
  // automatically computed if null
966
1011
  outputOrigin: null,
967
1012
  // automatically computed if null
1013
+ outputDirection: null,
1014
+ // identity if null
968
1015
  outputExtent: null,
969
1016
  // automatically computed if null
970
1017
  outputScalarType: null,
@@ -987,7 +1034,7 @@ var DEFAULT_VALUES = {
987
1034
  scalarScale: 1,
988
1035
  backgroundColor: [0, 0, 0, 0],
989
1036
  resliceAxes: null,
990
- resliceTransform: null,
1037
+ // resliceTransform: null,
991
1038
  interpolator: vtkImageInterpolator.newInstance(),
992
1039
  usePermuteExecute: false // no supported yet
993
1040
 
@@ -1000,10 +1047,11 @@ function extend(publicAPI, model) {
1000
1047
  macro.obj(publicAPI, model); // Also make it an algorithm with one input and one output
1001
1048
 
1002
1049
  macro.algo(publicAPI, model, 1, 1);
1003
- macro.setGet(publicAPI, model, ['outputDimensionality', 'outputScalarType', 'scalarShift', 'scalarScale', 'transformInputSampling', 'autoCropOutput', 'wrap', 'mirror', 'border', 'backgroundColor', 'interpolationMode', 'slabMode', 'slabTrapezoidIntegration', 'slabNumberOfSlices', 'slabSliceSpacingFraction']);
1050
+ macro.setGet(publicAPI, model, ['outputDimensionality', 'outputScalarType', 'scalarShift', 'scalarScale', 'transformInputSampling', 'autoCropOutput', 'wrap', 'mirror', 'border', 'interpolationMode', 'resliceTransform', 'slabMode', 'slabTrapezoidIntegration', 'slabNumberOfSlices', 'slabSliceSpacingFraction']);
1004
1051
  macro.setGetArray(publicAPI, model, ['outputOrigin', 'outputSpacing'], 3);
1005
1052
  macro.setGetArray(publicAPI, model, ['outputExtent'], 6);
1006
- setNullArray(publicAPI, model, ['outputOrigin', 'outputSpacing', 'outputExtent']);
1053
+ macro.setGetArray(publicAPI, model, ['outputDirection'], 9);
1054
+ macro.setGetArray(publicAPI, model, ['backgroundColor'], 4);
1007
1055
  macro.get(publicAPI, model, ['resliceAxes']); // Object specific methods
1008
1056
 
1009
1057
  macro.algo(publicAPI, model, 1, 1);
@@ -298,7 +298,7 @@ function vtkOpenGLTexture(publicAPI, model) {
298
298
 
299
299
 
300
300
  publicAPI.getInternalFormat = function (vtktype, numComps) {
301
- if (!model.internalFormat) {
301
+ if (!model._forceInternalFormat) {
302
302
  model.internalFormat = publicAPI.getDefaultInternalFormat(vtktype, numComps);
303
303
  }
304
304
 
@@ -332,6 +332,8 @@ function vtkOpenGLTexture(publicAPI, model) {
332
332
 
333
333
 
334
334
  publicAPI.setInternalFormat = function (iFormat) {
335
+ model._forceInternalFormat = true;
336
+
335
337
  if (iFormat !== model.internalFormat) {
336
338
  model.internalFormat = iFormat;
337
339
  publicAPI.modified();
@@ -388,6 +390,7 @@ function vtkOpenGLTexture(publicAPI, model) {
388
390
  publicAPI.resetFormatAndType = function () {
389
391
  model.format = 0;
390
392
  model.internalFormat = 0;
393
+ model._forceInternalFormat = false;
391
394
  model.openGLDataType = 0;
392
395
  }; //----------------------------------------------------------------------------
393
396
 
@@ -1288,6 +1291,7 @@ function vtkOpenGLTexture(publicAPI, model) {
1288
1291
 
1289
1292
  var DEFAULT_VALUES = {
1290
1293
  _openGLRenderWindow: null,
1294
+ _forceInternalFormat: false,
1291
1295
  context: null,
1292
1296
  handle: 0,
1293
1297
  sendParametersTime: null,
@@ -459,7 +459,7 @@ function vtkOpenGLVolumeMapper(publicAPI, model) {
459
459
  var i2wmat4 = model.currentInput.getIndexToWorld();
460
460
  mat4.multiply(model.idxToView, model.modelToView, i2wmat4);
461
461
  mat3.multiply(model.idxNormalMatrix, keyMats.normalMatrix, actMats.normalMatrix);
462
- mat3.multiply(model.idxNormalMatrix, model.idxNormalMatrix, model.currentInput.getDirection());
462
+ mat3.multiply(model.idxNormalMatrix, model.idxNormalMatrix, model.currentInput.getDirectionByReference());
463
463
  var maxSamples = vec3.length(vsize) / model.renderable.getSampleDistance();
464
464
 
465
465
  if (maxSamples > model.renderable.getMaximumSamplesPerRay()) {
@@ -181,6 +181,7 @@ function vtkViewNode(publicAPI, model) {
181
181
  }
182
182
 
183
183
  deleted.push(child);
184
+ child.delete();
184
185
  } else {
185
186
  child.setVisited(false);
186
187
  }
@@ -208,6 +209,16 @@ function vtkViewNode(publicAPI, model) {
208
209
 
209
210
  return ret;
210
211
  };
212
+
213
+ var parentDelete = publicAPI.delete;
214
+
215
+ publicAPI.delete = function () {
216
+ for (var i = 0; i < model.children.length; i++) {
217
+ model.children[i].delete();
218
+ }
219
+
220
+ parentDelete();
221
+ };
211
222
  } // ----------------------------------------------------------------------------
212
223
  // Object factory
213
224
  // ----------------------------------------------------------------------------
package/index.d.ts CHANGED
@@ -26,6 +26,7 @@
26
26
  /// <reference path="./Common/DataModel/DataSet.d.ts" />
27
27
  /// <reference path="./Common/DataModel/DataSetAttributes/FieldData.d.ts" />
28
28
  /// <reference path="./Common/DataModel/DataSetAttributes.d.ts" />
29
+ /// <reference path="./Common/DataModel/EdgeLocator.d.ts" />
29
30
  /// <reference path="./Common/DataModel/ITKHelper.d.ts" />
30
31
  /// <reference path="./Common/DataModel/ImageData.d.ts" />
31
32
  /// <reference path="./Common/DataModel/IncrementalOctreeNode.d.ts" />
package/macros.js CHANGED
@@ -580,7 +580,7 @@ function setGet(publicAPI, model, fieldNames) {
580
580
  function getArray(publicAPI, model, fieldNames) {
581
581
  fieldNames.forEach(function (field) {
582
582
  publicAPI["get".concat(_capitalize(field))] = function () {
583
- return model[field] ? [].concat(model[field]) : model[field];
583
+ return model[field] ? Array.from(model[field]) : model[field];
584
584
  };
585
585
 
586
586
  publicAPI["get".concat(_capitalize(field), "ByReference")] = function () {
@@ -638,9 +638,11 @@ function setArray(publicAPI, model, fieldNames, size) {
638
638
  }
639
639
  }
640
640
 
641
- changeDetected = model[field] == null || model[field].some(function (item, index) {
642
- return item !== array[index];
643
- }) || model[field].length !== array.length;
641
+ changeDetected = model[field] == null || model[field].length !== array.length;
642
+
643
+ for (var i = 0; !changeDetected && i < array.length; ++i) {
644
+ changeDetected = model[field][i] !== array[i];
645
+ }
644
646
 
645
647
  if (changeDetected && needCopy) {
646
648
  array = Array.from(array);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kitware/vtk.js",
3
- "version": "25.10.1",
3
+ "version": "25.11.1",
4
4
  "description": "Visualization Toolkit for the Web",
5
5
  "keywords": [
6
6
  "3d",
@@ -140,6 +140,7 @@
140
140
  "doc:publish": "kw-doc -c ./Documentation/config.js -mp",
141
141
  "doc:generate-api": "node ./Documentation/generate-api-docs.js",
142
142
  "example": "node ./Utilities/ExampleRunner/example-runner-cli.js -c ./Documentation/config.js",
143
+ "example:webgpu": "cross-env WEBGPU=1 NO_WEBGL=1 node ./Utilities/ExampleRunner/example-runner-cli.js -c ./Documentation/config.js",
143
144
  "dev:esm": "npm run build:esm -- -w",
144
145
  "dev:umd": "webpack --watch --config webpack.dev.js --progress",
145
146
  "build": "npm run build:release",
@@ -1,40 +0,0 @@
1
- import _classCallCheck from '@babel/runtime/helpers/classCallCheck';
2
- import _createClass from '@babel/runtime/helpers/createClass';
3
-
4
- var CCSEdgeLocator = /*#__PURE__*/function () {
5
- function CCSEdgeLocator() {
6
- _classCallCheck(this, CCSEdgeLocator);
7
-
8
- this._edgeMap = new Map();
9
- }
10
-
11
- _createClass(CCSEdgeLocator, [{
12
- key: "initialize",
13
- value: function initialize() {
14
- this._edgeMap.clear();
15
- }
16
- }, {
17
- key: "insertUniqueEdge",
18
- value: function insertUniqueEdge(i0, i1) {
19
- // Generate key, which is unique, since we order the edges
20
- var key = i1 < i0 ? "".concat(i1, "-").concat(i0) : "".concat(i0, "-").concat(i1);
21
-
22
- var node = this._edgeMap.get(key);
23
-
24
- if (!node) {
25
- // Didn't find key, so add a new edge entry
26
- node = {
27
- edgeId: -1
28
- };
29
-
30
- this._edgeMap.set(key, node);
31
- }
32
-
33
- return node;
34
- }
35
- }]);
36
-
37
- return CCSEdgeLocator;
38
- }();
39
-
40
- export { CCSEdgeLocator as default };