@kitware/vtk.js 34.11.0 → 34.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.
Files changed (71) hide show
  1. package/Common/Core/DataArray.js +2 -1
  2. package/Common/Core/Points.d.ts +11 -1
  3. package/Common/Core/Points.js +33 -18
  4. package/Common/DataModel/BoundingBox.d.ts +18 -4
  5. package/Common/DataModel/BoundingBox.js +10 -3
  6. package/Common/DataModel/Cell.js +4 -34
  7. package/Common/DataModel/DataSet.d.ts +7 -0
  8. package/Common/DataModel/DataSet.js +6 -0
  9. package/Common/DataModel/DataSetAttributes/FieldData.d.ts +6 -2
  10. package/Common/DataModel/DataSetAttributes.d.ts +2 -1
  11. package/Common/DataModel/ImageData.d.ts +7 -0
  12. package/Common/DataModel/ImageData.js +11 -0
  13. package/Common/DataModel/PointSet.d.ts +6 -0
  14. package/Common/DataModel/PointSet.js +10 -0
  15. package/Common/DataModel/PolyData.d.ts +6 -0
  16. package/Common/DataModel/PolyData.js +7 -0
  17. package/Filters/Core/Cutter.js +1 -1
  18. package/Filters/Core/PolyDataNormals.js +1 -1
  19. package/Filters/Core/ThresholdPoints.js +1 -2
  20. package/Filters/General/AppendPolyData.js +1 -1
  21. package/Filters/General/Calculator.js +1 -1
  22. package/Filters/General/ClipClosedSurface.js +2 -2
  23. package/Filters/General/ClosedPolyLineToSurfaceFilter.js +1 -1
  24. package/Filters/General/ContourLoopExtraction.js +2 -4
  25. package/Filters/General/ContourTriangulator.js +1 -2
  26. package/Filters/General/ImageCropFilter.js +7 -10
  27. package/Filters/General/ImageMarchingCubes.js +1 -1
  28. package/Filters/General/ImageMarchingSquares.js +1 -1
  29. package/Filters/General/ImageOutlineFilter.js +2 -1
  30. package/Filters/General/ImageSliceFilter.js +2 -1
  31. package/Filters/General/ImageStreamline.js +1 -1
  32. package/Filters/General/LineFilter.js +1 -1
  33. package/Filters/General/MoleculeToRepresentation.js +2 -2
  34. package/Filters/General/OutlineFilter.js +1 -1
  35. package/Filters/General/ScalarToRGBA.js +2 -1
  36. package/Filters/General/ShrinkPolyData.js +1 -1
  37. package/Filters/General/TransformPolyDataFilter.js +1 -1
  38. package/Filters/General/TriangleFilter.js +1 -1
  39. package/Filters/General/TubeFilter.js +1 -2
  40. package/Filters/General/WarpScalar.js +1 -1
  41. package/Filters/General/WindowedSincPolyDataFilter.js +1 -1
  42. package/Filters/Sources/ArcSource.js +1 -1
  43. package/Filters/Sources/Arrow2DSource.js +6 -9
  44. package/Filters/Sources/ArrowSource.js +2 -8
  45. package/Filters/Sources/CircleSource.js +3 -10
  46. package/Filters/Sources/ConcentricCylinderSource.js +5 -8
  47. package/Filters/Sources/ConeSource.js +3 -10
  48. package/Filters/Sources/CubeSource.js +3 -9
  49. package/Filters/Sources/Cursor3D.js +1 -4
  50. package/Filters/Sources/CylinderSource.js +3 -10
  51. package/Filters/Sources/DiskSource.js +1 -5
  52. package/Filters/Sources/EllipseArcSource.js +1 -1
  53. package/Filters/Sources/ImageGridSource.js +0 -3
  54. package/Filters/Sources/LineSource.js +1 -4
  55. package/Filters/Sources/PlaneSource.js +1 -4
  56. package/Filters/Sources/PlatonicSolidSource.js +1 -1
  57. package/Filters/Sources/PointSource.js +1 -4
  58. package/Filters/Sources/RTAnalyticSource.js +0 -3
  59. package/Filters/Sources/SLICSource.js +1 -4
  60. package/Filters/Sources/SphereSource.js +1 -4
  61. package/Filters/Sources/ViewFinderSource.js +1 -1
  62. package/Filters/Texture/TextureMapToPlane.js +1 -4
  63. package/Filters/Texture/TextureMapToSphere.js +1 -4
  64. package/Imaging/Core/ImageReslice.js +1 -1
  65. package/Imaging/Hybrid/SampleFunction.js +1 -1
  66. package/Rendering/Core/VectorText.js +4 -3
  67. package/Widgets/Representations/ImplicitPlaneRepresentation.js +1 -1
  68. package/Widgets/Representations/RectangleContextRepresentation.js +0 -3
  69. package/Widgets/Representations/SplineContextRepresentation.js +1 -5
  70. package/macros2.js +1 -1
  71. package/package.json +1 -1
@@ -196,9 +196,10 @@ function vtkDataArray(publicAPI, model) {
196
196
  return false;
197
197
  };
198
198
 
199
- // FIXME, to rename into "clear()" or "reset()"
199
+ // Restore the array to initial state
200
200
  publicAPI.initialize = () => {
201
201
  publicAPI.resize(0);
202
+ return publicAPI;
202
203
  };
203
204
  publicAPI.getElementComponentSize = () => model.values.BYTES_PER_ELEMENT;
204
205
 
@@ -17,11 +17,21 @@ export interface vtkPoints extends vtkDataArray {
17
17
  computeBounds(): Bounds;
18
18
 
19
19
  /**
20
- * Get the bounds for this mapper as [xmin, xmax, ymin, ymax,zmin, zmax].
20
+ * Get a copy of the bounds of the array.
21
+ * Bounds are [xmin, xmax, ymin, ymax,zmin, zmax].
22
+ * Will recompute the bounds if necessary.
21
23
  * @return {Bounds} The bounds for the mapper.
22
24
  */
23
25
  getBounds(): Bounds;
24
26
 
27
+ /**
28
+ * Get a reference to the model bounds of the array.
29
+ * Bounds are [xmin, xmax, ymin, ymax,zmin, zmax].
30
+ * Will recompute the bounds if necessary.
31
+ * @return {Bounds} The bounds for the mapper.
32
+ */
33
+ getBoundsByReference(): Bounds;
34
+
25
35
  /**
26
36
  * Get the coordinate of a point.
27
37
  * @param {Number} idx The index of point.
@@ -1,17 +1,19 @@
1
1
  import { m as macro } from '../../macros2.js';
2
2
  import vtkDataArray from './DataArray.js';
3
3
  import { VtkDataTypes } from './DataArray/Constants.js';
4
+ import { u as uninitializeBounds } from './Math/index.js';
4
5
 
5
6
  const {
6
7
  vtkErrorMacro
7
8
  } = macro;
8
- const INVALID_BOUNDS = [1, -1, 1, -1, 1, -1];
9
-
10
9
  // ----------------------------------------------------------------------------
11
10
  // vtkPoints methods
12
11
  // ----------------------------------------------------------------------------
13
12
 
14
13
  function vtkPoints(publicAPI, model) {
14
+ // Keep track of modified time for bounds computation
15
+ let boundMTime = 0;
16
+
15
17
  // Set our className
16
18
  model.classHierarchy.push('vtkPoints');
17
19
 
@@ -36,7 +38,23 @@ function vtkPoints(publicAPI, model) {
36
38
  publicAPI.findPoint = publicAPI.findTuple;
37
39
  publicAPI.insertNextPoint = (x, y, z) => publicAPI.insertNextTuple([x, y, z]);
38
40
  publicAPI.insertPoint = (ptId, point) => publicAPI.insertTuple(ptId, point);
41
+ const superGetBounds = publicAPI.getBounds;
39
42
  publicAPI.getBounds = () => {
43
+ if (boundMTime < model.mtime) {
44
+ publicAPI.computeBounds();
45
+ }
46
+ return superGetBounds();
47
+ };
48
+ const superGetBoundsByReference = publicAPI.getBoundsByReference;
49
+ publicAPI.getBoundsByReference = () => {
50
+ if (boundMTime < model.mtime) {
51
+ publicAPI.computeBounds();
52
+ }
53
+ return superGetBoundsByReference();
54
+ };
55
+
56
+ // Trigger the computation of bounds
57
+ publicAPI.computeBounds = () => {
40
58
  if (publicAPI.getNumberOfComponents() === 3) {
41
59
  const xRange = publicAPI.getRange(0);
42
60
  model.bounds[0] = xRange[0];
@@ -47,26 +65,22 @@ function vtkPoints(publicAPI, model) {
47
65
  const zRange = publicAPI.getRange(2);
48
66
  model.bounds[4] = zRange[0];
49
67
  model.bounds[5] = zRange[1];
50
- return model.bounds;
51
- }
52
- if (publicAPI.getNumberOfComponents() !== 2) {
68
+ } else if (publicAPI.getNumberOfComponents() === 2) {
69
+ const xRange = publicAPI.getRange(0);
70
+ model.bounds[0] = xRange[0];
71
+ model.bounds[1] = xRange[1];
72
+ const yRange = publicAPI.getRange(1);
73
+ model.bounds[2] = yRange[0];
74
+ model.bounds[3] = yRange[1];
75
+ model.bounds[4] = 0;
76
+ model.bounds[5] = 0;
77
+ } else {
53
78
  vtkErrorMacro(`getBounds called on an array with components of ${publicAPI.getNumberOfComponents()}`);
54
- return INVALID_BOUNDS;
79
+ uninitializeBounds(model.bounds);
55
80
  }
56
- const xRange = publicAPI.getRange(0);
57
- model.bounds[0] = xRange[0];
58
- model.bounds[1] = xRange[1];
59
- const yRange = publicAPI.getRange(1);
60
- model.bounds[2] = yRange[0];
61
- model.bounds[3] = yRange[1];
62
- model.bounds[4] = 0;
63
- model.bounds[5] = 0;
64
- return model.bounds;
81
+ boundMTime = macro.getCurrentGlobalMTime();
65
82
  };
66
83
 
67
- // Trigger the computation of bounds
68
- publicAPI.computeBounds = publicAPI.getBounds;
69
-
70
84
  // Initialize
71
85
  publicAPI.setNumberOfComponents(model.numberOfComponents < 2 ? 3 : model.numberOfComponents);
72
86
  }
@@ -88,6 +102,7 @@ function extend(publicAPI, model) {
88
102
  let initialValues = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
89
103
  Object.assign(model, DEFAULT_VALUES, initialValues);
90
104
  vtkDataArray.extend(publicAPI, model, initialValues);
105
+ macro.getArray(publicAPI, model, ['bounds'], 6);
91
106
  vtkPoints(publicAPI, model);
92
107
  }
93
108
 
@@ -1,6 +1,7 @@
1
1
  import { mat4 } from 'gl-matrix';
2
2
  import { Bounds, Vector2, Vector3 } from './../../types';
3
3
  import vtkPoints from './../Core/Points';
4
+ import { Nullable } from './../../types';
4
5
 
5
6
  /**
6
7
  * Tests whether two bounds equal.
@@ -176,10 +177,16 @@ export function getZRange(bounds: Bounds): Vector2;
176
177
  export function getMaxLength(bounds: Bounds): number;
177
178
 
178
179
  /**
179
- * Gets the diagonal of the bounding box.
180
+ * Gets the diagonal length of the bounding box.
180
181
  * @param {Bounds} bounds
181
182
  */
182
- export function getDiagonalLength(bounds: Bounds): number;
183
+ export function getDiagonalLength(bounds: Bounds): Nullable<number>;
184
+
185
+ /**
186
+ * Gets the squared diagonal length of the bounding box.
187
+ * @param {Bounds} bounds
188
+ */
189
+ export function getDiagonalLength2(bounds: Bounds): Nullable<number>;
183
190
 
184
191
  /**
185
192
  * Gets the min point.
@@ -506,10 +513,16 @@ declare class BoundingBox {
506
513
  getMaxLength(bounds: Bounds): number;
507
514
 
508
515
  /**
509
- * Gets the diagonal of the bounding box.
516
+ * Gets the diagonal length of the bounding box.
517
+ * @param {Bounds} bounds
518
+ */
519
+ getDiagonalLength(bounds: Bounds): Nullable<number>;
520
+
521
+ /**
522
+ * Gets the squared diagonal length of the bounding box.
510
523
  * @param {Bounds} bounds
511
524
  */
512
- getDiagonalLength(bounds: Bounds): number;
525
+ getDiagonalLength2(bounds: Bounds): Nullable<number>;
513
526
 
514
527
  /**
515
528
  * Gets the min point.
@@ -674,6 +687,7 @@ declare const vtkBoundingBox: {
674
687
  getLengths: typeof getLengths;
675
688
  getMaxLength: typeof getMaxLength;
676
689
  getDiagonalLength: typeof getDiagonalLength;
690
+ getDiagonalLength2: typeof getDiagonalLength2;
677
691
  getMinPoint: typeof getMinPoint;
678
692
  getMaxPoint: typeof getMaxPoint;
679
693
  getXRange: typeof getXRange;
@@ -213,13 +213,17 @@ function getMaxLength(bounds) {
213
213
  }
214
214
  return l[2];
215
215
  }
216
- function getDiagonalLength(bounds) {
216
+ function getDiagonalLength2(bounds) {
217
217
  if (isValid(bounds)) {
218
218
  const l = getLengths(bounds);
219
- return Math.sqrt(l[0] * l[0] + l[1] * l[1] + l[2] * l[2]);
219
+ return l[0] * l[0] + l[1] * l[1] + l[2] * l[2];
220
220
  }
221
221
  return null;
222
222
  }
223
+ function getDiagonalLength(bounds) {
224
+ const lenght2 = getDiagonalLength2(bounds);
225
+ return lenght2 !== null ? Math.sqrt(lenght2) : null;
226
+ }
223
227
  function getMinPoint(bounds) {
224
228
  return [bounds[0], bounds[2], bounds[4]];
225
229
  }
@@ -748,6 +752,9 @@ class BoundingBox {
748
752
  getDiagonalLength() {
749
753
  return getDiagonalLength(this.bounds);
750
754
  }
755
+ getDiagonalLength2() {
756
+ return getDiagonalLength2(this.bounds);
757
+ }
751
758
  getMinPoint() {
752
759
  return getMinPoint(this.bounds);
753
760
  }
@@ -862,4 +869,4 @@ var vtkBoundingBox = {
862
869
  ...STATIC
863
870
  };
864
871
 
865
- export { STATIC, addBounds, addPoint, addPoints, clampDivisions, computeCornerPoints, computeDivisions, computeLocalBounds, computeScale3, contains, containsPoint, cutWithPlane, vtkBoundingBox as default, distance2ToBounds, equals, getCenter, getCorners, getDiagonalLength, getLength, getLengths, getMaxLength, getMaxPoint, getMinPoint, getXRange, getYRange, getZRange, intersect, intersectBox, intersectPlane, intersects, isValid, reset, scale, scaleAboutCenter, setBounds, setMaxPoint, setMinPoint, transformBounds };
872
+ export { STATIC, addBounds, addPoint, addPoints, clampDivisions, computeCornerPoints, computeDivisions, computeLocalBounds, computeScale3, contains, containsPoint, cutWithPlane, vtkBoundingBox as default, distance2ToBounds, equals, getCenter, getCorners, getDiagonalLength, getDiagonalLength2, getLength, getLengths, getMaxLength, getMaxPoint, getMinPoint, getXRange, getYRange, getZRange, intersect, intersectBox, intersectPlane, intersects, isValid, reset, scale, scaleAboutCenter, setBounds, setMaxPoint, setMinPoint, transformBounds };
@@ -1,5 +1,5 @@
1
1
  import { m as macro } from '../../macros2.js';
2
- import { u as uninitializeBounds } from '../Core/Math/index.js';
2
+ import vtkBoundingBox from './BoundingBox.js';
3
3
  import vtkPoints from '../Core/Points.js';
4
4
 
5
5
  // ----------------------------------------------------------------------------
@@ -36,40 +36,10 @@ function vtkCell(publicAPI, model) {
36
36
  model.points.setData(triangleData);
37
37
  }
38
38
  };
39
- publicAPI.getBounds = () => {
40
- const nbPoints = model.points.getNumberOfPoints();
41
- const x = [];
42
- if (nbPoints) {
43
- model.points.getPoint(0, x);
44
- model.bounds[0] = x[0];
45
- model.bounds[1] = x[0];
46
- model.bounds[2] = x[1];
47
- model.bounds[3] = x[1];
48
- model.bounds[4] = x[2];
49
- model.bounds[5] = x[2];
50
- for (let i = 1; i < nbPoints; i++) {
51
- model.points.getPoint(i, x);
52
- model.bounds[0] = x[0] < model.bounds[0] ? x[0] : model.bounds[0];
53
- model.bounds[1] = x[0] > model.bounds[1] ? x[0] : model.bounds[1];
54
- model.bounds[2] = x[1] < model.bounds[2] ? x[1] : model.bounds[2];
55
- model.bounds[3] = x[1] > model.bounds[3] ? x[1] : model.bounds[3];
56
- model.bounds[4] = x[2] < model.bounds[4] ? x[2] : model.bounds[4];
57
- model.bounds[5] = x[2] > model.bounds[5] ? x[2] : model.bounds[5];
58
- }
59
- } else {
60
- uninitializeBounds(model.bounds);
61
- }
62
- return model.bounds;
63
- };
39
+ publicAPI.getBounds = () => model.points.getBounds();
64
40
  publicAPI.getLength2 = () => {
65
- publicAPI.getBounds();
66
- let length = 0.0;
67
- let diff = 0;
68
- for (let i = 0; i < 3; i++) {
69
- diff = model.bounds[2 * i + 1] - model.bounds[2 * i];
70
- length += diff * diff;
71
- }
72
- return length;
41
+ const lengths = vtkBoundingBox.getLengths(publicAPI.getBounds());
42
+ return lengths[0] * lengths[0] + lengths[1] * lengths[1] + lengths[2] * lengths[2];
73
43
  };
74
44
  publicAPI.getParametricDistance = pcoords => {
75
45
  let pDist;
@@ -8,6 +8,13 @@ import { FieldAssociations, FieldDataTypes } from './DataSet/Constants';
8
8
  export interface IDataSetInitialValues {}
9
9
 
10
10
  export interface vtkDataSet extends vtkObject {
11
+ /**
12
+ * Initialize the field, cell and point data.
13
+ * @see vtkDataSetAttributes::initialize()
14
+ * @see vtkFieldData::initialize()
15
+ */
16
+ initialize(): void;
17
+
11
18
  /**
12
19
  * Get dataset's cell data
13
20
  */
@@ -65,6 +65,12 @@ function vtkDataSet(publicAPI, model) {
65
65
  model[fieldName].shallowCopy(other.getReferenceByName(fieldName));
66
66
  });
67
67
  };
68
+ const superGetMTime = publicAPI.getMTime;
69
+ publicAPI.getMTime = () => DATASET_FIELDS.reduce((mTime, fieldName) => Math.max(mTime, model[fieldName]?.getMTime() ?? mTime), superGetMTime());
70
+ publicAPI.initialize = () => {
71
+ DATASET_FIELDS.forEach(fieldName => model[fieldName]?.initialize());
72
+ return publicAPI;
73
+ };
68
74
  }
69
75
 
70
76
  // ----------------------------------------------------------------------------
@@ -22,12 +22,16 @@ interface IArrayWithIndex {
22
22
 
23
23
  export interface vtkFieldData extends vtkObject {
24
24
  /**
25
- *
25
+ * Initialize fields, clear flags and restore copy beahvior.
26
+ * @see initializeFields
27
+ * @see clearFieldFlags
28
+ * @see copyAllOn
26
29
  */
27
30
  initialize(): void;
28
31
 
29
32
  /**
30
- *
33
+ * Delete all arrays and clear flags.
34
+ * @see initialize
31
35
  */
32
36
  initializeFields(): void;
33
37
 
@@ -229,7 +229,8 @@ export interface vtkDataSetAttributes extends vtkFieldData {
229
229
  removeArrayByIndex(arrayIdx: number): void;
230
230
 
231
231
  /**
232
- *
232
+ * Called when initialize() is called.
233
+ * @see initialize
233
234
  */
234
235
  initializeAttributeCopyFlags(): void;
235
236
 
@@ -20,6 +20,13 @@ interface IComputeHistogram {
20
20
  }
21
21
 
22
22
  export interface vtkImageData extends vtkDataSet {
23
+ /**
24
+ * Reinitialize the state (direction, spacing, origin, extent, etc.)
25
+ * and the data set.
26
+ * @see vtkDataSet::initialize()
27
+ */
28
+ initialize(): void;
29
+
23
30
  /**
24
31
  * Returns an object with `{ minimum, maximum, average, variance, sigma, count }`
25
32
  * of the imageData points found within the provided `worldBounds`.
@@ -314,6 +314,17 @@ function vtkImageData(publicAPI, model) {
314
314
  }
315
315
  return publicAPI.getPointData().getScalars().getComponent(offsetIndex, comp);
316
316
  };
317
+ const superInitialize = publicAPI.initialize;
318
+ publicAPI.initialize = () => {
319
+ publicAPI.set({
320
+ direction: mat3.identity(model.direction),
321
+ spacing: [1.0, 1.0, 1.0],
322
+ origin: [0.0, 0.0, 0.0],
323
+ extent: [0, -1, 0, -1, 0, -1],
324
+ dataDescription: StructuredType.EMPTY
325
+ });
326
+ return superInitialize();
327
+ };
317
328
  }
318
329
 
319
330
  // ----------------------------------------------------------------------------
@@ -8,6 +8,12 @@ import vtkDataSet, { IDataSetInitialValues } from './DataSet';
8
8
  export interface IPointSetInitialValues extends IDataSetInitialValues {}
9
9
 
10
10
  export interface vtkPointSet extends vtkDataSet {
11
+ /**
12
+ * Empty the points and initialize the data set and .
13
+ * @see vtkDataSet::initialize()
14
+ */
15
+ initialize(): void;
16
+
11
17
  /**
12
18
  * Compute the (X, Y, Z) bounds of the data.
13
19
  */
@@ -33,6 +33,16 @@ function vtkPointSet(publicAPI, model) {
33
33
  model.points = vtkPoints.newInstance();
34
34
  model.points.shallowCopy(other.getPoints());
35
35
  };
36
+ const superGetMTime = publicAPI.getMTime;
37
+ publicAPI.getMTime = () => {
38
+ const mTime = superGetMTime();
39
+ return Math.max(mTime, model.points?.getMTime() ?? mTime);
40
+ };
41
+ const superInitialize = publicAPI.initialize;
42
+ publicAPI.initialize = () => {
43
+ model.points?.initialize();
44
+ return superInitialize();
45
+ };
36
46
  }
37
47
 
38
48
  // ----------------------------------------------------------------------------
@@ -8,6 +8,12 @@ import vtkPointSet, { IPointSetInitialValues } from './PointSet';
8
8
  export interface IPolyDataInitialValues extends IPointSetInitialValues {}
9
9
 
10
10
  export interface vtkPolyData extends vtkPointSet {
11
+ /**
12
+ * Empty the cells and initialize the point set.
13
+ * @see vtkPointSet::initialize()
14
+ */
15
+ initialize(): void;
16
+
11
17
  /**
12
18
  * Create data structure that allows random access of cells.
13
19
  */
@@ -48,6 +48,13 @@ function vtkPolyData(publicAPI, model) {
48
48
  model[type].shallowCopy(other.getReferenceByName(type));
49
49
  });
50
50
  };
51
+ const superGetMTime = publicAPI.getMTime;
52
+ publicAPI.getMTime = () => POLYDATA_FIELDS.reduce((mTime, type) => Math.max(mTime, model[type]?.getMTime() ?? mTime), superGetMTime());
53
+ const superInitialize = publicAPI.initialize;
54
+ publicAPI.initialize = () => {
55
+ POLYDATA_FIELDS.forEach(type => model[type]?.initialize());
56
+ return superInitialize();
57
+ };
51
58
  publicAPI.buildCells = () => {
52
59
  // here are the number of cells we have
53
60
  const nVerts = publicAPI.getNumberOfVerts();
@@ -287,7 +287,7 @@ function vtkCutter(publicAPI, model) {
287
287
  vtkErrorMacro('Missing cut function');
288
288
  return;
289
289
  }
290
- const output = vtkPolyData.newInstance();
290
+ const output = outData[0]?.initialize() || vtkPolyData.newInstance();
291
291
  dataSetCutter(input, output);
292
292
  outData[0] = output;
293
293
  };
@@ -70,7 +70,7 @@ function vtkPolyDataNormals(publicAPI, model) {
70
70
  if (!input) {
71
71
  return;
72
72
  }
73
- const output = vtkPolyData.newInstance();
73
+ const output = outData[0]?.initialize() || vtkPolyData.newInstance();
74
74
  output.setPoints(input.getPoints());
75
75
  output.setVerts(input.getVerts());
76
76
  output.setLines(input.getLines());
@@ -43,7 +43,7 @@ function vtkThresholdPoints(publicAPI, model) {
43
43
  model.classHierarchy.push('vtkThresholdPoints');
44
44
  publicAPI.requestData = (inData, outData) => {
45
45
  const input = inData[0];
46
- const output = vtkPolyData.newInstance();
46
+ const output = outData[0]?.initialize() || vtkPolyData.newInstance();
47
47
  outData[0] = output;
48
48
  if (model.criterias.length === 0) {
49
49
  output.shallowCopy(input);
@@ -170,7 +170,6 @@ function vtkThresholdPoints(publicAPI, model) {
170
170
  dataType: input.getPolys().getDataType()
171
171
  }));
172
172
  });
173
- outData[0] = output;
174
173
  };
175
174
  }
176
175
 
@@ -43,7 +43,7 @@ function vtkAppendPolyData(publicAPI, model) {
43
43
  }
44
44
 
45
45
  // Allocate output
46
- const output = vtkPolyData.newInstance();
46
+ const output = outData[0] && inData[0] !== outData[0] ? outData[0].initialize() : vtkPolyData.newInstance();
47
47
  let numPts = 0;
48
48
  let pointType = 0;
49
49
  let ttype = 1;
@@ -172,7 +172,7 @@ function vtkCalculator(publicAPI, model) {
172
172
  return 0;
173
173
  }
174
174
  const arraySpec = model.formula.getArrays(inData);
175
- const newDataSet = vtk({
175
+ const newDataSet = outData[0]?.initialize() || vtk({
176
176
  vtkClass: inData[0].getClassName()
177
177
  });
178
178
  newDataSet.shallowCopy(inData[0]);
@@ -499,7 +499,7 @@ function vtkClipClosedSurface(publicAPI, model) {
499
499
  publicAPI.requestData = (inData, outData) => {
500
500
  // implement requestData
501
501
  const input = inData[0];
502
- const output = vtkPolyData.newInstance();
502
+ const output = outData[0]?.initialize() || vtkPolyData.newInstance();
503
503
  outData[0] = output;
504
504
  if (!input) {
505
505
  vtkErrorMacro('Invalid or missing input');
@@ -830,8 +830,8 @@ function vtkClipClosedSurface(publicAPI, model) {
830
830
  squeezeOutputPoints(output, points, pointData, inputPointsType);
831
831
  // TODO: Check
832
832
  // output.squeeze();
833
- outData[0] = output;
834
833
  };
834
+
835
835
  Object.keys(ScalarMode).forEach(key => {
836
836
  const name = capitalize(key.toLowerCase());
837
837
  publicAPI[`setScalarModeTo${name}`] = () => {
@@ -125,7 +125,7 @@ function vtkClosedPolyLineToSurfaceFilter(publicAPI, model) {
125
125
  vtkErrorMacro('Invalid or missing input');
126
126
  return;
127
127
  }
128
- const output = vtkPolyData.newInstance();
128
+ const output = outData[0]?.initialize() || vtkPolyData.newInstance();
129
129
  output.shallowCopy(input);
130
130
 
131
131
  // Extract faces
@@ -9,10 +9,8 @@ const visited = new Set();
9
9
  function vtkContourLoopExtraction(publicAPI, model) {
10
10
  publicAPI.requestData = (inData, outData) => {
11
11
  const [input] = inData;
12
- if (!outData[0]) {
13
- outData[0] = vtkPolyData.newInstance();
14
- }
15
- const [output] = outData;
12
+ const output = outData[0]?.initialize() || vtkPolyData.newInstance();
13
+ outData[0] = output;
16
14
  publicAPI.extractContours(input, output);
17
15
  output.modified();
18
16
  };
@@ -137,8 +137,7 @@ function vtkContourTriangulator(publicAPI, model) {
137
137
  publicAPI.requestData = (inData, outData) => {
138
138
  // implement requestData
139
139
  const input = inData[0];
140
- // FIXME: do not instantiate a new polydata each time the filter is executed.
141
- const output = vtkPolyData.newInstance();
140
+ const output = outData[0]?.initialize() || vtkPolyData.newInstance();
142
141
  outData[0] = output;
143
142
  if (!input) {
144
143
  vtkErrorMacro('Invalid or missing input');
@@ -32,6 +32,8 @@ function vtkImageCropFilter(publicAPI, model) {
32
32
  vtkErrorMacro('Invalid or missing input');
33
33
  return;
34
34
  }
35
+ const outImage = outData[0]?.initialize() || vtkImageData.newInstance();
36
+ outData[0] = outImage;
35
37
  const scalars = input.getPointData().getScalars();
36
38
  if (!scalars) {
37
39
  vtkErrorMacro('No scalars from input');
@@ -47,9 +49,7 @@ function vtkImageCropFilter(publicAPI, model) {
47
49
  return Math.min(e, Math.round(model.croppingPlanes[i]));
48
50
  }) : extent.slice();
49
51
  if (cropped[0] === extent[0] && cropped[1] === extent[1] && cropped[2] === extent[2] && cropped[3] === extent[3] && cropped[4] === extent[4] && cropped[5] === extent[5]) {
50
- const sameAsInput = vtkImageData.newInstance();
51
- sameAsInput.shallowCopy(input); // Force new mtime
52
- outData[0] = sameAsInput;
52
+ outImage.shallowCopy(input); // Force new mtime
53
53
  return;
54
54
  }
55
55
 
@@ -88,19 +88,16 @@ function vtkImageCropFilter(publicAPI, model) {
88
88
  index += slice.length;
89
89
  }
90
90
  }
91
- const outImage = vtkImageData.newInstance({
92
- extent: cropped,
93
- origin: input.getOrigin(),
94
- direction: input.getDirection(),
95
- spacing: input.getSpacing()
96
- });
91
+ outImage.setExtent(cropped);
92
+ outImage.setOrigin(input.getOrigin());
93
+ outImage.setSpacing(input.getSpacing());
94
+ outImage.setDirection(input.getDirection());
97
95
  const croppedScalars = vtkDataArray.newInstance({
98
96
  name: scalars.getName(),
99
97
  numberOfComponents,
100
98
  values: croppedArray
101
99
  });
102
100
  outImage.getPointData().setScalars(croppedScalars);
103
- outData[0] = outImage;
104
101
  };
105
102
  publicAPI.isResetAvailable = () => {
106
103
  if (model.croppingPlanes == null || model.croppingPlanes.length === 0) {
@@ -251,7 +251,7 @@ function vtkImageMarchingCubes(publicAPI, model) {
251
251
  edgeLocator.initialize();
252
252
 
253
253
  // Update output
254
- const polydata = vtkPolyData.newInstance();
254
+ const polydata = outData[0]?.initialize() || vtkPolyData.newInstance();
255
255
  polydata.getPoints().setData(new Float32Array(pBuffer), 3);
256
256
  polydata.getPolys().setData(new Uint32Array(tBuffer));
257
257
  if (model.computeNormals) {
@@ -207,7 +207,7 @@ function vtkImageMarchingSquares(publicAPI, model) {
207
207
  }
208
208
 
209
209
  // Update output
210
- const polydata = vtkPolyData.newInstance();
210
+ const polydata = outData[0]?.initialize() || vtkPolyData.newInstance();
211
211
  polydata.getPoints().setData(new Float32Array(points), 3);
212
212
  polydata.getLines().setData(new Uint32Array(lines));
213
213
  outData[0] = polydata;
@@ -19,7 +19,8 @@ function vtkImageOutlineFilter(publicAPI, model) {
19
19
  vtkErrorMacro('Invalid or missing input');
20
20
  return;
21
21
  }
22
- const output = vtkImageData.newInstance(input.get('spacing', 'origin', 'direction'));
22
+ const output = outData[0]?.initialize() || vtkImageData.newInstance();
23
+ output.set(input.get('spacing', 'origin', 'direction'));
23
24
  const getIndex = (point, dims) => point[0] + point[1] * dims[0] + point[2] * dims[0] * dims[1];
24
25
  const getIJK = (index, dims) => {
25
26
  const ijk = [0, 0, 0];
@@ -37,7 +37,8 @@ function vtkImageSliceFilter(publicAPI, model) {
37
37
  numberOfComponents,
38
38
  values: sliceRawArray
39
39
  });
40
- const output = vtkImageData.newInstance(datasetDefinition);
40
+ const output = outData[0]?.initialize() || vtkImageData.newInstance();
41
+ output.set(datasetDefinition);
41
42
  output.getPointData().setScalars(sliceArray);
42
43
  outData[0] = output;
43
44
  };
@@ -210,7 +210,7 @@ function vtkImageStreamline(publicAPI, model) {
210
210
  pointArray.set(data[0], offset2);
211
211
  offset2 += data[0].length;
212
212
  });
213
- const output = vtkPolyData.newInstance();
213
+ const output = outData[0]?.initialize() || vtkPolyData.newInstance();
214
214
  output.getPoints().setData(pointArray, 3);
215
215
  output.getLines().setData(cellArray);
216
216
  outData[0] = output;
@@ -9,7 +9,7 @@ function vtkLineFilter(publicAPI, model) {
9
9
  // Set our classname
10
10
  model.classHierarchy.push('vtkLineFilter');
11
11
  publicAPI.requestData = (inData, outData) => {
12
- const dataset = vtkPolyData.newInstance();
12
+ const dataset = outData[0]?.initialize() || vtkPolyData.newInstance();
13
13
  dataset.getPoints().setData(inData[0].getPoints().getData());
14
14
  dataset.getLines().setData(inData[0].getLines().getData());
15
15
  outData[0] = dataset;
@@ -54,8 +54,8 @@ function vtkMoleculeToRepresentation(publicAPI, model) {
54
54
  }
55
55
 
56
56
  // output
57
- const SphereData = vtkPolyData.newInstance();
58
- const StickData = vtkPolyData.newInstance();
57
+ const SphereData = outData[0]?.initialize() || vtkPolyData.newInstance();
58
+ const StickData = outData[1]?.initialize() || vtkPolyData.newInstance();
59
59
 
60
60
  // Fetch from input molecule data
61
61
  let numPts = 0;