@kitware/vtk.js 34.10.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 (82) hide show
  1. package/Common/Core/DataArray.js +2 -1
  2. package/Common/Core/Points.d.ts +19 -1
  3. package/Common/Core/Points.js +35 -20
  4. package/Common/DataModel/AbstractPointLocator.d.ts +2 -2
  5. package/Common/DataModel/BoundingBox.d.ts +60 -7
  6. package/Common/DataModel/BoundingBox.js +190 -3
  7. package/Common/DataModel/Cell.js +4 -34
  8. package/Common/DataModel/DataSet.d.ts +7 -0
  9. package/Common/DataModel/DataSet.js +6 -0
  10. package/Common/DataModel/DataSetAttributes/FieldData.d.ts +6 -2
  11. package/Common/DataModel/DataSetAttributes.d.ts +2 -1
  12. package/Common/DataModel/ImageData.d.ts +7 -0
  13. package/Common/DataModel/ImageData.js +11 -0
  14. package/Common/DataModel/Locator.d.ts +97 -5
  15. package/Common/DataModel/MergePoints.d.ts +64 -0
  16. package/Common/DataModel/MergePoints.js +130 -0
  17. package/Common/DataModel/PointLocator.d.ts +217 -0
  18. package/Common/DataModel/PointLocator.js +751 -0
  19. package/Common/DataModel/PointSet.d.ts +6 -0
  20. package/Common/DataModel/PointSet.js +10 -0
  21. package/Common/DataModel/PolyData.d.ts +6 -0
  22. package/Common/DataModel/PolyData.js +7 -0
  23. package/Filters/Core/Cutter.js +1 -1
  24. package/Filters/Core/PolyDataNormals.js +1 -1
  25. package/Filters/Core/ThresholdPoints.js +1 -2
  26. package/Filters/General/AppendPolyData.js +1 -1
  27. package/Filters/General/Calculator.js +1 -1
  28. package/Filters/General/ClipClosedSurface.js +2 -2
  29. package/Filters/General/ClosedPolyLineToSurfaceFilter.js +1 -1
  30. package/Filters/General/ContourLoopExtraction.js +2 -4
  31. package/Filters/General/ContourTriangulator.js +1 -2
  32. package/Filters/General/ImageCropFilter.js +7 -10
  33. package/Filters/General/ImageMarchingCubes.js +1 -1
  34. package/Filters/General/ImageMarchingSquares.js +1 -1
  35. package/Filters/General/ImageOutlineFilter.js +2 -1
  36. package/Filters/General/ImageSliceFilter.js +2 -1
  37. package/Filters/General/ImageStreamline.js +1 -1
  38. package/Filters/General/LineFilter.js +1 -1
  39. package/Filters/General/MoleculeToRepresentation.js +2 -2
  40. package/Filters/General/OutlineFilter.js +1 -1
  41. package/Filters/General/ScalarToRGBA.js +2 -1
  42. package/Filters/General/ShrinkPolyData.js +1 -1
  43. package/Filters/General/TransformPolyDataFilter.js +1 -1
  44. package/Filters/General/TriangleFilter.js +1 -1
  45. package/Filters/General/TubeFilter.js +1 -2
  46. package/Filters/General/WarpScalar.js +1 -1
  47. package/Filters/General/WindowedSincPolyDataFilter.js +1 -1
  48. package/Filters/Sources/ArcSource.js +1 -1
  49. package/Filters/Sources/Arrow2DSource.js +6 -9
  50. package/Filters/Sources/ArrowSource.js +2 -8
  51. package/Filters/Sources/CircleSource.js +3 -10
  52. package/Filters/Sources/ConcentricCylinderSource.js +5 -8
  53. package/Filters/Sources/ConeSource.js +3 -10
  54. package/Filters/Sources/CubeSource.js +3 -9
  55. package/Filters/Sources/Cursor3D.js +1 -4
  56. package/Filters/Sources/CylinderSource.js +3 -10
  57. package/Filters/Sources/DiskSource.js +1 -5
  58. package/Filters/Sources/EllipseArcSource.js +1 -1
  59. package/Filters/Sources/FrustumSource.d.ts +111 -0
  60. package/Filters/Sources/FrustumSource.js +248 -0
  61. package/Filters/Sources/ImageGridSource.js +0 -3
  62. package/Filters/Sources/LineSource.js +1 -4
  63. package/Filters/Sources/PlaneSource.js +1 -4
  64. package/Filters/Sources/PlatonicSolidSource.js +1 -1
  65. package/Filters/Sources/PointSource.js +1 -4
  66. package/Filters/Sources/RTAnalyticSource.js +0 -3
  67. package/Filters/Sources/SLICSource.js +1 -4
  68. package/Filters/Sources/SphereSource.js +1 -4
  69. package/Filters/Sources/ViewFinderSource.js +1 -1
  70. package/Filters/Texture/TextureMapToPlane.js +1 -4
  71. package/Filters/Texture/TextureMapToSphere.js +1 -4
  72. package/Imaging/Core/ImageReslice.js +1 -1
  73. package/Imaging/Hybrid/SampleFunction.js +1 -1
  74. package/Rendering/Core/VectorText.js +4 -3
  75. package/Rendering/OpenGL/Glyph3DMapper.js +16 -0
  76. package/Rendering/OpenGL/glsl/vtkVolumeVS.glsl.js +1 -1
  77. package/Widgets/Representations/ImplicitPlaneRepresentation.js +1 -1
  78. package/Widgets/Representations/RectangleContextRepresentation.js +0 -3
  79. package/Widgets/Representations/SplineContextRepresentation.js +1 -5
  80. package/index.d.ts +3 -0
  81. package/macros2.js +1 -1
  82. package/package.json +1 -1
@@ -10,11 +10,7 @@ import vtkMatrixBuilder from '../../Common/Core/MatrixBuilder.js';
10
10
  function vtkCylinderSource(publicAPI, model) {
11
11
  // Set our classname
12
12
  model.classHierarchy.push('vtkCylinderSource');
13
- function requestData(inData, outData) {
14
- if (model.deleted) {
15
- return;
16
- }
17
- let dataset = outData[0];
13
+ publicAPI.requestData = (inData, outData) => {
18
14
  const angle = 2.0 * Math.PI / model.resolution;
19
15
  let numberOfPoints = 2 * model.resolution;
20
16
  let numberOfPolys = 5 * model.resolution;
@@ -147,7 +143,7 @@ function vtkCylinderSource(publicAPI, model) {
147
143
 
148
144
  // Apply transformation to the points coordinates
149
145
  vtkMatrixBuilder.buildFromRadian().translate(...model.center).rotateFromDirections([0, 1, 0], model.direction).translate(...model.center.map(c => c * -1)).apply(points);
150
- dataset = vtkPolyData.newInstance();
146
+ const dataset = outData[0]?.initialize() || vtkPolyData.newInstance();
151
147
  dataset.getPoints().setData(points, 3);
152
148
  dataset.getPolys().setData(polys, 1);
153
149
  dataset.getPointData().setNormals(normals);
@@ -155,10 +151,7 @@ function vtkCylinderSource(publicAPI, model) {
155
151
 
156
152
  // Update output
157
153
  outData[0] = dataset;
158
- }
159
-
160
- // Expose methods
161
- publicAPI.requestData = requestData;
154
+ };
162
155
  }
163
156
 
164
157
  // ----------------------------------------------------------------------------
@@ -25,10 +25,6 @@ function vtkDiskSource(publicAPI, model) {
25
25
  circumferentialResolution,
26
26
  pointType
27
27
  } = model;
28
- if (model.deleted) {
29
- return;
30
- }
31
- let dataset = outData[0];
32
28
 
33
29
  // Points
34
30
  const points = vtkPoints.newInstance({
@@ -83,7 +79,7 @@ function vtkDiskSource(publicAPI, model) {
83
79
  }
84
80
  }
85
81
  polys.setData(cellData, cellCount, 1);
86
- dataset = vtkPolyData.newInstance();
82
+ const dataset = outData[0]?.initialize() || vtkPolyData.newInstance();
87
83
  dataset.setPoints(points);
88
84
  dataset.setPolys(polys);
89
85
 
@@ -26,7 +26,7 @@ function vtkEllipseArcSource(publicAPI, model) {
26
26
  const numLines = resolution;
27
27
  const numPts = resolution + 1;
28
28
  const tc = [0.0, 0.0];
29
- const output = outData[0] || vtkPolyData.newInstance();
29
+ const output = outData[0]?.initialize() || vtkPolyData.newInstance();
30
30
 
31
31
  // Make sure the normal vector is normalized
32
32
  const normal = [...model.normal];
@@ -0,0 +1,111 @@
1
+ import { DesiredOutputPrecision } from './../../Common/DataModel/DataSetAttributes';
2
+ import { vtkAlgorithm, vtkObject } from './../../interfaces';
3
+ import vtkPlanes from './../../Common/DataModel/Planes';
4
+
5
+ /**
6
+ *
7
+ */
8
+ export interface IFrustumSourceInitialValues {
9
+ planes?: vtkPlanes;
10
+ showLines?: boolean;
11
+ outputPointsPrecision?: DesiredOutputPrecision;
12
+ }
13
+
14
+ type vtkFrustumSourceBase = vtkObject &
15
+ Omit<
16
+ vtkAlgorithm,
17
+ | 'getInputData'
18
+ | 'setInputData'
19
+ | 'setInputConnection'
20
+ | 'getInputConnection'
21
+ | 'addInputConnection'
22
+ | 'addInputData'
23
+ >;
24
+
25
+ export interface vtkFrustumSource extends vtkFrustumSourceBase {
26
+ /**
27
+ * Get the output points precision.
28
+ */
29
+ getOutputPointsPrecision(): DesiredOutputPrecision;
30
+
31
+ /**
32
+ * Get the planes defining the frustum.
33
+ */
34
+ getPlanes(): vtkPlanes;
35
+
36
+ /**
37
+ * Get whether to show lines.
38
+ */
39
+ getShowLines(): boolean;
40
+
41
+ /**
42
+ *
43
+ * @param inData
44
+ * @param outData
45
+ */
46
+ requestData(inData: any, outData: any): void;
47
+
48
+ /**
49
+ * Set the output points precision.
50
+ * @param {DesiredOutputPrecision} precision
51
+ */
52
+ setOutputPointsPrecision(precision: DesiredOutputPrecision): boolean;
53
+
54
+ /**
55
+ * Set the planes defining the frustum.
56
+ * @param {vtkPlanes} planes
57
+ */
58
+ setPlanes(planes: vtkPlanes): boolean;
59
+
60
+ /**
61
+ * Set whether to show lines.
62
+ * @param {Boolean} showLines
63
+ */
64
+ setShowLines(showLines: boolean): boolean;
65
+ }
66
+
67
+ /**
68
+ * Method used to decorate a given object (publicAPI+model) with vtkFrustumSource characteristics.
69
+ *
70
+ * @param publicAPI object on which methods will be bounds (public)
71
+ * @param model object on which data structure will be bounds (protected)
72
+ * @param {IFrustumSourceInitialValues} [initialValues] (default: {})
73
+ */
74
+ export function extend(
75
+ publicAPI: object,
76
+ model: object,
77
+ initialValues?: IFrustumSourceInitialValues
78
+ ): void;
79
+
80
+ /**
81
+ * Method used to create a new instance of vtkFrustumSource.
82
+ * @param {IFrustumSourceInitialValues} [initialValues] for pre-setting some of its content
83
+ */
84
+ export function newInstance(
85
+ initialValues?: IFrustumSourceInitialValues
86
+ ): vtkFrustumSource;
87
+
88
+ /**
89
+ * vtkFrustumSource creates a frustum defines by a set of planes. The frustum is
90
+ * represented with four-sided polygons. It is possible to specify extra lines
91
+ * to better visualize the field of view.
92
+ *
93
+ * @example
94
+ * ```js
95
+ * import vtkFrustumSource from '@kitware/vtk.js/Filters/Sources/FrustumSource';
96
+ *
97
+ * const frustum = vtkFrustumSource.newInstance();
98
+ * const camera = vtkCamera.newInstance();
99
+ * camera.setClippingRange(0.1, 0.4);
100
+ * const planesArray = camera.getFrustumPlanes(1.0);
101
+ * const planes = vtkPlanes.newInstance();
102
+ * planes.setFrustumPlanes(planesArray);
103
+ * frustum.setPlanes(planes);
104
+ * frustum.setShowLines(false);
105
+ * ```
106
+ */
107
+ export declare const vtkFrustumSource: {
108
+ newInstance: typeof newInstance;
109
+ extend: typeof extend;
110
+ };
111
+ export default vtkFrustumSource;
@@ -0,0 +1,248 @@
1
+ import { m as macro } from '../../macros2.js';
2
+ import { f as vtkMath } from '../../Common/Core/Math/index.js';
3
+ import vtkCellArray from '../../Common/Core/CellArray.js';
4
+ import vtkPoints from '../../Common/Core/Points.js';
5
+ import vtkPolyData from '../../Common/DataModel/PolyData.js';
6
+ import { DesiredOutputPrecision } from '../../Common/DataModel/DataSetAttributes/Constants.js';
7
+ import { VtkDataTypes } from '../../Common/Core/DataArray/Constants.js';
8
+
9
+ const {
10
+ vtkErrorMacro
11
+ } = macro;
12
+
13
+ // ----------------------------------------------------------------------------
14
+ // vtkFrustumSource methods
15
+ // ----------------------------------------------------------------------------
16
+
17
+ function vtkFrustumSource(publicAPI, model) {
18
+ // Set our className
19
+ model.classHierarchy.push('vtkFrustumSource');
20
+ function computePoint(planeIndices, pt) {
21
+ // Get planes and their normals/origins
22
+ const plane0 = model.planes.getPlane(planeIndices[0]);
23
+ const n0 = plane0.getNormal();
24
+ const p0 = plane0.getOrigin();
25
+ const plane1 = model.planes.getPlane(planeIndices[1]);
26
+ const n1 = plane1.getNormal();
27
+ const p1 = plane1.getOrigin();
28
+ const plane2 = model.planes.getPlane(planeIndices[2]);
29
+ const n2 = plane2.getNormal();
30
+ const p2 = plane2.getOrigin();
31
+
32
+ // Dot products
33
+ const d0 = vtkMath.dot(p0, n0);
34
+ const d1 = vtkMath.dot(p1, n1);
35
+ const d2 = vtkMath.dot(p2, n2);
36
+
37
+ // Cross products
38
+ const c12 = [0, 0, 0];
39
+ vtkMath.cross(n1, n2, c12);
40
+ const c20 = [0, 0, 0];
41
+ vtkMath.cross(n2, n0, c20);
42
+ const c01 = [0, 0, 0];
43
+ vtkMath.cross(n0, n1, c01);
44
+
45
+ // Determinant
46
+ const d = vtkMath.determinant3x3([...n0, ...n1, ...n2]);
47
+
48
+ // Intersection point
49
+ for (let i = 0; i < 3; ++i) {
50
+ pt[i] = (d0 * c12[i] + d1 * c20[i] + d2 * c01[i]) / d;
51
+ }
52
+ }
53
+ publicAPI.requestData = (inData, outData) => {
54
+ const output = outData[0] || vtkPolyData.newInstance();
55
+ if (!model.planes || model.planes.getNumberOfPlanes() !== 6) {
56
+ vtkErrorMacro('vtkFrustum requires 6 planes.');
57
+ return;
58
+ }
59
+ let nbPts = 8;
60
+ let leftRightNull = false;
61
+ let bottomTopNull = false;
62
+ let parallelFrustum = false;
63
+
64
+ // angle between left and right planes
65
+ const n0 = model.planes.getPlane(0).getNormal().slice();
66
+ const n1 = model.planes.getPlane(1).getNormal().slice();
67
+ const c = [0, 0, 0];
68
+ vtkMath.normalize(n0);
69
+ vtkMath.normalize(n1);
70
+ vtkMath.dot(n0, n1);
71
+ vtkMath.cross(n0, n1, c);
72
+ vtkMath.norm(c);
73
+
74
+ // angle between bottom and top planes
75
+ n0.splice(0, 3, ...model.planes.getPlane(2).getNormal());
76
+ n1.splice(0, 3, ...model.planes.getPlane(3).getNormal());
77
+ vtkMath.normalize(n0);
78
+ vtkMath.normalize(n1);
79
+ vtkMath.dot(n0, n1);
80
+ vtkMath.cross(n0, n1, c);
81
+ vtkMath.norm(c);
82
+ if (model.showLines) {
83
+ const left = model.planes.getPlane(0).getNormal();
84
+ const right = model.planes.getPlane(1).getNormal();
85
+ const bottom = model.planes.getPlane(2).getNormal();
86
+ const top = model.planes.getPlane(3).getNormal();
87
+ const leftRight = [0, 0, 0];
88
+ vtkMath.cross(left, right, leftRight);
89
+ leftRightNull = leftRight[0] === 0.0 && leftRight[1] === 0.0 && leftRight[2] === 0.0;
90
+ const bottomTop = [0, 0, 0];
91
+ vtkMath.cross(bottom, top, bottomTop);
92
+ bottomTopNull = bottomTop[0] === 0.0 && bottomTop[1] === 0.0 && bottomTop[2] === 0.0;
93
+ parallelFrustum = leftRightNull && bottomTopNull;
94
+ if (parallelFrustum) {
95
+ // start at near points, just add the 4 extra far points.
96
+ nbPts += 4;
97
+ } else if (leftRightNull || bottomTopNull) {
98
+ // two extra starting points, and 4 extra far points.
99
+ nbPts += 6;
100
+ } else {
101
+ // there is an apex, and 4 extra far points
102
+ nbPts += 5;
103
+ }
104
+ }
105
+ let pointType = 0;
106
+ if (model.outputPointsPrecision === DesiredOutputPrecision.SINGLE) {
107
+ pointType = VtkDataTypes.FLOAT;
108
+ } else if (model.outputPointsPrecision === DesiredOutputPrecision.DOUBLE) {
109
+ pointType = VtkDataTypes.DOUBLE;
110
+ }
111
+ const newPoints = vtkPoints.newInstance({
112
+ dataType: pointType
113
+ });
114
+ newPoints.setNumberOfPoints(nbPts);
115
+ const pt = [0.0, 0.0, 0.0];
116
+ const planes = [0, 0, 0];
117
+ planes[0] = 0; // left
118
+ planes[1] = 2; // bottom
119
+ planes[2] = 5; // near
120
+ computePoint(planes, pt);
121
+ newPoints.setPoint(0, ...pt);
122
+ planes[0] = 1;
123
+ computePoint(planes, pt);
124
+ newPoints.setPoint(1, ...pt);
125
+ planes[1] = 3;
126
+ computePoint(planes, pt);
127
+ newPoints.setPoint(2, ...pt);
128
+ planes[0] = 0;
129
+ computePoint(planes, pt);
130
+ newPoints.setPoint(3, ...pt);
131
+ planes[1] = 2;
132
+ planes[2] = 4; // far
133
+ computePoint(planes, pt);
134
+ newPoints.setPoint(4, ...pt);
135
+ planes[0] = 1;
136
+ computePoint(planes, pt);
137
+ newPoints.setPoint(5, ...pt);
138
+ planes[1] = 3;
139
+ computePoint(planes, pt);
140
+ newPoints.setPoint(6, ...pt);
141
+ planes[0] = 0;
142
+ computePoint(planes, pt);
143
+ newPoints.setPoint(7, ...pt);
144
+ const numPolys = 6;
145
+ const newPolys = vtkCellArray.newInstance();
146
+ newPolys.allocate(numPolys * 5);
147
+
148
+ // left
149
+ newPolys.insertNextCell([4, 0, 3, 7]);
150
+
151
+ // right
152
+ newPolys.insertNextCell([1, 5, 6, 2]);
153
+
154
+ // bottom
155
+ newPolys.insertNextCell([0, 4, 5, 1]);
156
+
157
+ // top
158
+ newPolys.insertNextCell([3, 2, 6, 7]);
159
+
160
+ // near
161
+ newPolys.insertNextCell([0, 1, 2, 3]);
162
+
163
+ // far
164
+ newPolys.insertNextCell([4, 7, 6, 5]);
165
+ let newLines = null;
166
+ if (model.showLines) {
167
+ const numLines = 4;
168
+ newLines = vtkCellArray.newInstance();
169
+ newLines.allocate(numLines * 3);
170
+ const pts = [12, 8]; // apex, or first of the two extra near points.
171
+
172
+ // line from lower-left corner
173
+ if (parallelFrustum) {
174
+ pts[0] = 0;
175
+ }
176
+ newLines.insertNextCell(pts);
177
+
178
+ // line from lower-right corner
179
+ if (parallelFrustum) {
180
+ pts[0]++;
181
+ } else if (leftRightNull) {
182
+ pts[0] = 13;
183
+ }
184
+ pts[1]++;
185
+ newLines.insertNextCell(pts);
186
+
187
+ // line from upper-right corner
188
+ if (parallelFrustum) {
189
+ pts[0]++;
190
+ } else if (bottomTopNull) {
191
+ pts[0] = 13;
192
+ }
193
+ pts[1]++;
194
+ newLines.insertNextCell(pts);
195
+
196
+ // line from upper-left corner
197
+ if (parallelFrustum) {
198
+ pts[0]++;
199
+ } else if (leftRightNull) {
200
+ pts[0] = 12;
201
+ }
202
+ pts[1]++;
203
+ newLines.insertNextCell(pts);
204
+ output.setLines(newLines);
205
+ }
206
+ output.setPoints(newPoints);
207
+ output.setPolys(newPolys);
208
+ outData[0] = output;
209
+ };
210
+ }
211
+
212
+ // ----------------------------------------------------------------------------
213
+ // Object factory
214
+ // ----------------------------------------------------------------------------
215
+
216
+ const DEFAULT_VALUES = {
217
+ planes: null,
218
+ showLines: true,
219
+ outputPointsPrecision: DesiredOutputPrecision.DEFAULT
220
+ };
221
+
222
+ // ----------------------------------------------------------------------------
223
+
224
+ function extend(publicAPI, model) {
225
+ let initialValues = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
226
+ Object.assign(model, DEFAULT_VALUES, initialValues);
227
+
228
+ // Build VTK API
229
+ macro.obj(publicAPI, model);
230
+
231
+ // Also make it an algorithm with no input and one output
232
+ macro.algo(publicAPI, model, 0, 1);
233
+ macro.setGet(publicAPI, model, ['showLines', 'outputPointsPrecision', 'planes']);
234
+ vtkFrustumSource(publicAPI, model);
235
+ }
236
+
237
+ // ----------------------------------------------------------------------------
238
+
239
+ const newInstance = macro.newInstance(extend, 'vtkFrustumSource');
240
+
241
+ // ----------------------------------------------------------------------------
242
+
243
+ var index = {
244
+ newInstance,
245
+ extend
246
+ };
247
+
248
+ export { index as default, extend, newInstance };
@@ -10,9 +10,6 @@ function vtkImageGridSource(publicAPI, model) {
10
10
  // Set our className
11
11
  model.classHierarchy.push('vtkImageGridSource');
12
12
  publicAPI.requestData = (inData, outData) => {
13
- if (model.deleted) {
14
- return;
15
- }
16
13
  const state = {};
17
14
  const dataset = {
18
15
  type: 'vtkImageData',
@@ -14,14 +14,11 @@ function vtkLineSource(publicAPI, model) {
14
14
  // Set our className
15
15
  model.classHierarchy.push('vtkLineSource');
16
16
  publicAPI.requestData = (inData, outData) => {
17
- if (model.deleted) {
18
- return;
19
- }
20
17
  const dataset = outData[0];
21
18
 
22
19
  // Check input
23
20
  const pointDataType = dataset ? dataset.getPoints().getDataType() : model.pointType;
24
- const pd = vtkPolyData.newInstance();
21
+ const pd = dataset?.initialize() || vtkPolyData.newInstance();
25
22
  const v21 = [];
26
23
  subtract(model.point2, model.point1, v21);
27
24
  if (norm(v21) <= 0.0) {
@@ -18,14 +18,11 @@ function vtkPlaneSource(publicAPI, model) {
18
18
  // Set our className
19
19
  model.classHierarchy.push('vtkPlaneSource');
20
20
  publicAPI.requestData = (inData, outData) => {
21
- if (model.deleted) {
22
- return;
23
- }
24
21
  const dataset = outData[0];
25
22
 
26
23
  // Check input
27
24
  const pointDataType = dataset ? dataset.getPoints().getDataType() : model.pointType;
28
- const pd = vtkPolyData.newInstance();
25
+ const pd = dataset?.initialize() || vtkPolyData.newInstance();
29
26
  const v10 = [];
30
27
  const v20 = [];
31
28
  subtract(model.point1, model.origin, v10);
@@ -63,7 +63,7 @@ function vtkPlatonicSolidSource(publicAPI, model) {
63
63
  // Set our className
64
64
  model.classHierarchy.push('vtkPlatonicSolidSource');
65
65
  publicAPI.requestData = (inData, outData) => {
66
- const output = outData[0] || vtkPolyData.newInstance();
66
+ const output = outData[0]?.initialize() || vtkPolyData.newInstance();
67
67
  let solidData;
68
68
  switch (model.solidType) {
69
69
  case SolidType.VTK_SOLID_TETRAHEDRON:
@@ -10,14 +10,11 @@ function vtkPointSource(publicAPI, model) {
10
10
  // Set our className
11
11
  model.classHierarchy.push('vtkPointSource');
12
12
  publicAPI.requestData = (inData, outData) => {
13
- if (model.deleted) {
14
- return;
15
- }
16
13
  const dataset = outData[0];
17
14
 
18
15
  // Check input
19
16
  const pointDataType = dataset ? dataset.getPoints().getDataType() : model.pointType;
20
- const pd = vtkPolyData.newInstance();
17
+ const pd = dataset?.initialize() || vtkPolyData.newInstance();
21
18
 
22
19
  // hand create a point cloud
23
20
  const numPts = model.numberOfPoints;
@@ -8,9 +8,6 @@ function vtkRTAnalyticSource(publicAPI, model) {
8
8
  // Set our className
9
9
  model.classHierarchy.push('vtkRTAnalyticSource');
10
10
  publicAPI.requestData = (inData, outData) => {
11
- if (model.deleted) {
12
- return;
13
- }
14
11
  const state = {};
15
12
  const dataset = {
16
13
  type: 'vtkImageData',
@@ -60,11 +60,8 @@ function vtkSLICSource(publicAPI, model) {
60
60
  };
61
61
  publicAPI.getNumberOfClusters = () => model.clusters.length;
62
62
  publicAPI.requestData = (inData, outData) => {
63
- if (model.deleted) {
64
- return;
65
- }
66
63
  const dataSize = model.dimensions[0] * model.dimensions[1] * model.dimensions[2];
67
- const imageData = vtkImageData.newInstance();
64
+ const imageData = outData[0]?.initialize() || vtkImageData.newInstance();
68
65
  imageData.setSpacing(...model.spacing);
69
66
  imageData.setExtent(0, model.dimensions[0] - 1, 0, model.dimensions[1] - 1, 0, model.dimensions[2] - 1);
70
67
  imageData.setOrigin(...model.origin);
@@ -10,12 +10,9 @@ function vtkSphereSource(publicAPI, model) {
10
10
  // Set our className
11
11
  model.classHierarchy.push('vtkSphereSource');
12
12
  publicAPI.requestData = (inData, outData) => {
13
- if (model.deleted) {
14
- return;
15
- }
16
13
  let dataset = outData[0];
17
14
  const pointDataType = dataset ? dataset.getPoints().getDataType() : model.pointType;
18
- dataset = vtkPolyData.newInstance();
15
+ dataset = dataset?.initialize() || vtkPolyData.newInstance();
19
16
 
20
17
  // ----------------------------------------------------------------------
21
18
  let numPoles = 0;
@@ -4,7 +4,7 @@ import vtkPolyData from '../../Common/DataModel/PolyData.js';
4
4
 
5
5
  function vtkViewFinderSource(publicAPI, model) {
6
6
  publicAPI.requestData = (inData, outData) => {
7
- const dataset = vtkPolyData.newInstance();
7
+ const dataset = outData[0]?.initialize() || vtkPolyData.newInstance();
8
8
  const points = macro.newTypedArray(model.pointType, 3 * 16);
9
9
  points[0] = model.radius;
10
10
  points[1] = model.radius / model.width;
@@ -90,16 +90,13 @@ function vtkTextureMapToPlane(publicAPI, model) {
90
90
  model.normal[2] = -1.0;
91
91
  }
92
92
  publicAPI.requestData = (inData, outData) => {
93
- if (model.deleted) {
94
- return;
95
- }
96
93
  const input = inData[0];
97
94
  const nbPoints = input.getPoints().getNumberOfPoints();
98
95
  if (nbPoints < 3 && model.automaticPlaneGeneration) {
99
96
  vtkErrorMacro("Can't generate texture coordinates without points");
100
97
  return;
101
98
  }
102
- const output = vtkPolyData.newInstance();
99
+ const output = outData[0]?.initialize() || vtkPolyData.newInstance();
103
100
  output.getPoints().setData(new Float32Array(input.getPoints().getData()), 3);
104
101
  output.getPolys().setData(new Uint32Array(input.getPolys().getData()));
105
102
  const tcoordsData = [];
@@ -15,9 +15,6 @@ function vtkTextureMapToSphere(publicAPI, model) {
15
15
  // Set our className
16
16
  model.classHierarchy.push('vtkTextureMapToSphere');
17
17
  publicAPI.requestData = (inData, outData) => {
18
- if (model.deleted) {
19
- return;
20
- }
21
18
  const input = inData[0];
22
19
  const nbPoints = input.getPoints().getNumberOfPoints();
23
20
  if (nbPoints <= 1) {
@@ -108,7 +105,7 @@ function vtkTextureMapToSphere(publicAPI, model) {
108
105
  size: nbPoints,
109
106
  values: tcoordsData
110
107
  });
111
- const output = vtkPolyData.newInstance();
108
+ const output = outData[0]?.initialize() || vtkPolyData.newInstance();
112
109
  output.getPoints().setData(new Float32Array(input.getPoints().getData()), 3);
113
110
  output.getPolys().setData(new Uint32Array(input.getPolys().getData()));
114
111
  output.getPointData().setTCoords(tCoords);
@@ -206,7 +206,7 @@ function vtkImageReslice(publicAPI, model) {
206
206
  });
207
207
 
208
208
  // Update output
209
- const output = vtkImageData.newInstance();
209
+ const output = outData[0]?.initialize() || vtkImageData.newInstance();
210
210
  output.setDimensions(outDims);
211
211
  output.setOrigin(outOrigin);
212
212
  output.setSpacing(outSpacing);
@@ -39,7 +39,7 @@ function vtkSampleFunction(publicAPI, model) {
39
39
  vtkErrorMacro('Bad volume dimensions');
40
40
  return;
41
41
  }
42
- const volume = vtkImageData.newInstance();
42
+ const volume = outData[0]?.initialize() || vtkImageData.newInstance();
43
43
  const origin = [model.modelBounds[0], model.modelBounds[2], model.modelBounds[4]];
44
44
  const spacing = [(model.modelBounds[1] - model.modelBounds[0]) / (dims[0] - 1), (model.modelBounds[3] - model.modelBounds[2]) / (dims[1] - 1), (model.modelBounds[5] - model.modelBounds[4]) / (dims[2] - 1)];
45
45
  const sliceSize = dims[0] * dims[1];
@@ -241,11 +241,10 @@ function vtkVectorText(publicAPI, model) {
241
241
  * Creates a vtkPolyData from the processed shapes
242
242
  * @returns {Object} vtkPolyData instance
243
243
  */
244
- function buildPolyData() {
244
+ function buildPolyData(polyData) {
245
245
  model.verticesArray = [];
246
246
  model.uvArray = [];
247
247
  model.colorArray = [];
248
- const polyData = vtkPolyData.newInstance();
249
248
  const cells = vtkCellArray.newInstance();
250
249
  const pointData = polyData.getPointData();
251
250
 
@@ -328,7 +327,9 @@ function vtkVectorText(publicAPI, model) {
328
327
  return;
329
328
  }
330
329
  buildShape();
331
- outData[0] = buildPolyData();
330
+ const polyData = outData[0]?.initialize() || vtkPolyData.newInstance();
331
+ buildPolyData(polyData);
332
+ outData[0] = polyData;
332
333
  };
333
334
  }
334
335
 
@@ -162,6 +162,22 @@ function vtkOpenGLGlyph3DMapper(publicAPI, model) {
162
162
  }
163
163
  superClass.replaceShaderNormal(shaders, ren, actor);
164
164
  };
165
+ publicAPI.replaceShaderClip = (shaders, ren, actor) => {
166
+ if (model.hardwareSupport) {
167
+ let VSSource = shaders.Vertex;
168
+ let FSSource = shaders.Fragment;
169
+ if (model.renderable.getNumberOfClippingPlanes()) {
170
+ const numClipPlanes = model.renderable.getNumberOfClippingPlanes();
171
+ VSSource = vtkShaderProgram.substitute(VSSource, '//VTK::Clip::Dec', ['uniform int numClipPlanes;', `uniform vec4 clipPlanes[${numClipPlanes}];`, `varying float clipDistancesVSOutput[${numClipPlanes}];`]).result;
172
+ VSSource = vtkShaderProgram.substitute(VSSource, '//VTK::Clip::Impl', [`for (int planeNum = 0; planeNum < ${numClipPlanes}; planeNum++)`, ' {', ' if (planeNum >= numClipPlanes)', ' {', ' break;', ' }', ' vec4 gVertex = gMatrix * vertexMC;', ' clipDistancesVSOutput[planeNum] = dot(clipPlanes[planeNum], gVertex);', ' }']).result;
173
+ FSSource = vtkShaderProgram.substitute(FSSource, '//VTK::Clip::Dec', ['uniform int numClipPlanes;', `varying float clipDistancesVSOutput[${numClipPlanes}];`]).result;
174
+ FSSource = vtkShaderProgram.substitute(FSSource, '//VTK::Clip::Impl', [`for (int planeNum = 0; planeNum < ${numClipPlanes}; planeNum++)`, ' {', ' if (planeNum >= numClipPlanes)', ' {', ' break;', ' }', ' if (clipDistancesVSOutput[planeNum] < 0.0) discard;', ' }']).result;
175
+ }
176
+ shaders.Vertex = VSSource;
177
+ shaders.Fragment = FSSource;
178
+ }
179
+ superClass.replaceShaderClip(shaders, ren, actor);
180
+ };
165
181
  publicAPI.replaceShaderColor = (shaders, ren, actor) => {
166
182
  if (model.hardwareSupport && model.renderable.getColorArray()) {
167
183
  let VSSource = shaders.Vertex;
@@ -1,3 +1,3 @@
1
- var vtkVolumeVS = "//VTK::System::Dec\n\n/*=========================================================================\n\n Program: Visualization Toolkit\n Module: vtkPolyDataVS.glsl\n\n Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen\n All rights reserved.\n See Copyright.txt or http://www.kitware.com/Copyright.htm for details.\n\n This software is distributed WITHOUT ANY WARRANTY; without even\n the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR\n PURPOSE. See the above copyright notice for more information.\n\n=========================================================================*/\n\nattribute vec4 vertexDC;\n\nvarying vec3 vertexVCVSOutput;\nuniform mat4 PCVCMatrix;\n\nuniform float dcxmin;\nuniform float dcxmax;\nuniform float dcymin;\nuniform float dcymax;\n\nvoid main()\n{\n // dcsmall is the device coords reduced to the\n // x y area covered by the volume\n vec4 dcsmall = vec4(\n dcxmin + 0.5 * (vertexDC.x + 1.0) * (dcxmax - dcxmin),\n dcymin + 0.5 * (vertexDC.y + 1.0) * (dcymax - dcymin),\n vertexDC.z,\n vertexDC.w);\n vec4 vcpos = PCVCMatrix * dcsmall;\n vertexVCVSOutput = vcpos.xyz/vcpos.w;\n gl_Position = dcsmall;\n}\n";
1
+ var vtkVolumeVS = "//VTK::System::Dec\n\n/*=========================================================================\n\n Program: Visualization Toolkit\n Module: vtkVolumeVS.glsl\n\n Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen\n All rights reserved.\n See Copyright.txt or http://www.kitware.com/Copyright.htm for details.\n\n This software is distributed WITHOUT ANY WARRANTY; without even\n the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR\n PURPOSE. See the above copyright notice for more information.\n\n=========================================================================*/\n\nattribute vec4 vertexDC;\n\nvarying vec3 vertexVCVSOutput;\nuniform mat4 PCVCMatrix;\n\nuniform float dcxmin;\nuniform float dcxmax;\nuniform float dcymin;\nuniform float dcymax;\n\nvoid main()\n{\n // dcsmall is the device coords reduced to the\n // x y area covered by the volume\n vec4 dcsmall = vec4(\n dcxmin + 0.5 * (vertexDC.x + 1.0) * (dcxmax - dcxmin),\n dcymin + 0.5 * (vertexDC.y + 1.0) * (dcymax - dcymin),\n vertexDC.z,\n vertexDC.w);\n vec4 vcpos = PCVCMatrix * dcsmall;\n vertexVCVSOutput = vcpos.xyz/vcpos.w;\n gl_Position = dcsmall;\n}\n";
2
2
 
3
3
  export { vtkVolumeVS as v };
@@ -221,7 +221,7 @@ function vtkImplicitPlaneRepresentation(publicAPI, model) {
221
221
  // --------------------------------
222
222
 
223
223
  vtkWidgetRepresentation.applyStyles(model._pipelines, model.representationStyle, state.getActive() && state.getActiveHandle());
224
- const output = vtkPolyData.newInstance();
224
+ const output = outData[0]?.initialize() || vtkPolyData.newInstance();
225
225
  output.shallowCopy(model._pipelines.plane.filter.getOutputData());
226
226
  outData[0] = output;
227
227
  };