@kitware/vtk.js 34.5.0 → 34.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. package/Common/Core/CellArray.d.ts +3 -0
  2. package/Common/Core/CellArray.js +12 -1
  3. package/Common/Core/DataArray.d.ts +15 -0
  4. package/Common/Core/DataArray.js +8 -4
  5. package/Common/Core/Math/index.js +1 -1
  6. package/Common/Core/Math.js +1 -1
  7. package/Common/DataModel/Triangle.d.ts +68 -19
  8. package/Common/DataModel/Triangle.js +140 -1
  9. package/Common/DataModel/TriangleStrip.d.ts +180 -0
  10. package/Common/DataModel/TriangleStrip.js +396 -0
  11. package/Common/DataModel.js +3 -1
  12. package/Common/Transform/LandmarkTransform.js +1 -1
  13. package/Common/Transform/Transform.d.ts +112 -1
  14. package/Common/Transform/Transform.js +301 -2
  15. package/Filters/Core/Cutter.js +41 -0
  16. package/Filters/General/OBBTree.js +1 -1
  17. package/Filters/General/TransformPolyDataFilter.d.ts +75 -0
  18. package/Filters/General/TransformPolyDataFilter.js +194 -0
  19. package/Filters/General.js +2 -0
  20. package/Filters/Sources/CircleSource.js +1 -1
  21. package/Filters/Sources/PointSource.js +1 -1
  22. package/Filters/Texture/TextureMapToPlane.js +1 -1
  23. package/IO/Geometry/DracoReader.js +1 -1
  24. package/IO/Geometry/GLTFImporter/Animations.js +1 -1
  25. package/IO/Geometry/GLTFImporter/Reader.js +2 -2
  26. package/IO/Image/HDRReader/Utils.js +1 -1
  27. package/IO/Image/HDRReader.js +1 -1
  28. package/Interaction/Manipulators/MouseCameraTrackballRollManipulator.js +1 -1
  29. package/Interaction/Manipulators/MouseCameraTrackballRotateManipulator.js +1 -1
  30. package/Interaction/Manipulators/MouseCameraUnicamManipulator.js +1 -1
  31. package/Interaction/Manipulators/MouseCameraUnicamRotateManipulator.js +1 -1
  32. package/Interaction/Style/InteractorStyleTrackballCamera.js +1 -1
  33. package/Interaction/Widgets/PiecewiseGaussianWidget.js +1 -1
  34. package/Proxy/Core/View2DProxy.js +1 -1
  35. package/Rendering/Core/AbstractImageMapper.js +1 -1
  36. package/Rendering/Core/AbstractMapper3D.js +1 -1
  37. package/Rendering/Core/ColorTransferFunction/CssFilters.js +1 -1
  38. package/Rendering/Core/ColorTransferFunction.js +1 -1
  39. package/Rendering/Core/Coordinate.js +1 -1
  40. package/Rendering/Core/CubeAxesActor.js +1 -1
  41. package/Rendering/Core/Glyph3DMapper.js +1 -1
  42. package/Rendering/Core/ImageArrayMapper.js +1 -1
  43. package/Rendering/Core/ImageMapper.js +1 -1
  44. package/Rendering/Core/Mapper.js +1 -1
  45. package/Rendering/Core/Prop3D.js +1 -1
  46. package/Rendering/Core/RenderWindowInteractor.js +3 -3
  47. package/Rendering/Core/Renderer.js +1 -1
  48. package/Rendering/Core/ScalarBarActor.js +1 -1
  49. package/Rendering/Core/TextActor.js +1 -1
  50. package/Rendering/Core/VectorText/Utils.js +1 -1
  51. package/Rendering/Core/VolumeProperty.js +1 -1
  52. package/Rendering/OpenGL/PolyDataMapper2D.js +1 -1
  53. package/Rendering/OpenGL/Texture.js +1 -1
  54. package/Rendering/OpenGL/VolumeMapper.js +21 -19
  55. package/Widgets/Manipulators/LineManipulator.js +1 -1
  56. package/Widgets/Representations/PolyLineRepresentation.js +1 -1
  57. package/Widgets/Widgets3D/AngleWidget.js +1 -1
  58. package/Widgets/Widgets3D/LineWidget/helpers.js +1 -1
  59. package/Widgets/Widgets3D/ResliceCursorWidget/behavior.js +1 -1
  60. package/Widgets/Widgets3D/ResliceCursorWidget/helpers.js +1 -1
  61. package/Widgets/Widgets3D/ResliceCursorWidget.js +1 -1
  62. package/index.d.ts +2 -0
  63. package/package.json +1 -1
@@ -1,7 +1,11 @@
1
- import { IDENTITY } from '../Core/Math/Constants.js';
2
- import { vec3, mat4 } from 'gl-matrix';
3
1
  import { m as macro } from '../../macros2.js';
4
2
  import { f as vtkMath } from '../Core/Math/index.js';
3
+ import { IDENTITY } from '../Core/Math/Constants.js';
4
+ import { vec3, mat4, quat, mat3 } from 'gl-matrix';
5
+
6
+ const {
7
+ vtkWarningMacro
8
+ } = macro;
5
9
 
6
10
  // ----------------------------------------------------------------------------
7
11
  // vtkTransform methods
@@ -79,6 +83,301 @@ function vtkTransform(publicAPI, model) {
79
83
  matrix: vtkMath.invertMatrix(Array.from(model.matrix), [], 4),
80
84
  preMultiplyFlag: model.preMultiplyFlag
81
85
  });
86
+
87
+ /**
88
+ * Create a translation matrix and concatenate it with the current
89
+ * transformation according to preMultiply or postMultiply semantics.
90
+ * @param {Number} x X component of the translation
91
+ * @param {Number} y Y component of the translation
92
+ * @param {Number} z Z component of the translation
93
+ */
94
+ publicAPI.translate = (x, y, z) => {
95
+ if (x === 0 && y === 0 && z === 0) {
96
+ return;
97
+ }
98
+ const tMat = mat4.create();
99
+ mat4.fromTranslation(tMat, [x, y, z]);
100
+ if (model.preMultiplyFlag) {
101
+ mat4.multiply(model.matrix, model.matrix, tMat);
102
+ } else {
103
+ mat4.multiply(model.matrix, tMat, model.matrix);
104
+ }
105
+ publicAPI.modified();
106
+ };
107
+
108
+ /**
109
+ * Create a rotation matrix and concatenate it with the current transformation
110
+ * according to preMultiply or postMultiply semantics.
111
+ * The angle is expressed in degrees.
112
+ * @param {Number} angle Angle in degrees
113
+ * @param {Number} x X component of the rotation axis
114
+ * @param {Number} y Y component of the rotation axis
115
+ * @param {Number} z Z component of the rotation axis
116
+ */
117
+ publicAPI.rotateWXYZ = (degrees, x, y, z) => {
118
+ if (x === 0.0 && y === 0.0 && z === 0.0) {
119
+ vtkWarningMacro('No rotation applied, axis is zero vector.');
120
+ return;
121
+ }
122
+ if (degrees === 0.0) {
123
+ return;
124
+ }
125
+
126
+ // convert to radians
127
+ const angle = vtkMath.radiansFromDegrees(degrees);
128
+ const q = quat.create();
129
+ quat.setAxisAngle(q, [x, y, z], angle);
130
+ const quatMat = new Float64Array(16);
131
+ mat4.fromQuat(quatMat, q);
132
+ if (model.preMultiplyFlag) {
133
+ mat4.multiply(model.matrix, model.matrix, quatMat);
134
+ } else {
135
+ mat4.multiply(model.matrix, quatMat, model.matrix);
136
+ }
137
+ publicAPI.modified();
138
+ };
139
+
140
+ /**
141
+ * Create a rotation matrix about the X, Y, or Z axis and concatenate it with
142
+ * the current transformation according to preMultiply or postMultiply
143
+ * semantics.
144
+ * The angle is expressed in degrees.
145
+ * @param {Number} angle Angle in degrees
146
+ */
147
+ publicAPI.rotateX = angle => {
148
+ publicAPI.rotateWXYZ(angle, 1, 0, 0);
149
+ };
150
+
151
+ /**
152
+ * Create a rotation matrix about the X, Y, or Z axis and concatenate it with
153
+ * the current transformation according to preMultiply or postMultiply
154
+ * semantics.
155
+ * @param {Number} angle Angle in degrees
156
+ */
157
+ publicAPI.rotateY = angle => {
158
+ publicAPI.rotateWXYZ(angle, 0, 1, 0);
159
+ };
160
+
161
+ /**
162
+ * Create a rotation matrix about the X, Y, or Z axis and concatenate it with
163
+ * the current transformation according to preMultiply or postMultiply
164
+ * semantics.
165
+ * @param {Number} angle Angle in degrees
166
+ */
167
+ publicAPI.rotateZ = angle => {
168
+ publicAPI.rotateWXYZ(angle, 0, 0, 1);
169
+ };
170
+
171
+ /**
172
+ * Create a scale matrix (i.e. set the diagonal elements to x, y, z) and
173
+ * concatenate it with the current transformation according to preMultiply or
174
+ * postMultiply semantics.
175
+ * @param {Number} x Diagonal element for X axis
176
+ * @param {Number} y Diagonal element for Y axis
177
+ * @param {Number} z Diagonal element for Z axis
178
+ */
179
+ publicAPI.scale = (x, y, z) => {
180
+ if (x === 1 && y === 1 && z === 1) {
181
+ return;
182
+ }
183
+ const sMat = mat4.create();
184
+ mat4.fromScaling(sMat, [x, y, z]);
185
+ if (model.preMultiplyFlag) {
186
+ mat4.multiply(model.matrix, model.matrix, sMat);
187
+ } else {
188
+ mat4.multiply(model.matrix, sMat, model.matrix);
189
+ }
190
+ publicAPI.modified();
191
+ };
192
+
193
+ /**
194
+ * Apply the transformation to a normal.
195
+ * @param {vec3} inNormal The normal vector to transform
196
+ * @param {vec3} outNormal The output vector
197
+ * @returns {vec3} The transformed normal vector
198
+ */
199
+ publicAPI.transformNormal = function (inNormal) {
200
+ let outNormal = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
201
+ const matrix3x3 = mat3.fromMat4(mat3.create(), model.matrix);
202
+ // Invert the upper 3x3 part of the matrix
203
+ const invMat3 = mat3.create();
204
+ mat3.invert(invMat3, matrix3x3);
205
+ // Transpose
206
+ const tMat3 = mat3.create();
207
+ mat3.transpose(tMat3, invMat3);
208
+ // Multiply normal
209
+ publicAPI.transformVector(inNormal, outNormal, tMat3);
210
+ // Ensure the output normal is normalized
211
+ vtkMath.normalize(outNormal);
212
+ return outNormal;
213
+ };
214
+
215
+ /**
216
+ * Apply the transformation to a series of normals, and append the results to
217
+ * outNormals.
218
+ * @param {vtkDataArray} inNormals The normal vectors to transform
219
+ * @param {vtkDataArray} outNormals The output array
220
+ */
221
+ publicAPI.transformNormals = (inNormals, outNormals) => {
222
+ const inArr = inNormals.getData();
223
+ const outArr = outNormals.getData();
224
+ const tmp = [0, 0, 0];
225
+ const matrix3x3 = mat3.fromMat4(mat3.create(), model.matrix);
226
+ // Invert the upper 3x3 part of the matrix
227
+ const invMat3 = mat3.create();
228
+ mat3.invert(invMat3, matrix3x3);
229
+ // Transpose
230
+ const tMat3 = mat3.create();
231
+ mat3.transpose(tMat3, invMat3);
232
+ for (let i = 0; i < inArr.length; i += 3) {
233
+ tmp[0] = inArr[i];
234
+ tmp[1] = inArr[i + 1];
235
+ tmp[2] = inArr[i + 2];
236
+ // matrix has been transposed & inverted, so use transformVector directly
237
+ // to apply the transformation
238
+ publicAPI.transformVector(tmp, tmp, tMat3);
239
+ vtkMath.normalize(tmp);
240
+ outArr[i] = tmp[0];
241
+ outArr[i + 1] = tmp[1];
242
+ outArr[i + 2] = tmp[2];
243
+ }
244
+ };
245
+
246
+ /**
247
+ * Apply the transformation to a vector.
248
+ * @param {vec3} inVector The vector to transform
249
+ * @param {vec3} outVector The output vector
250
+ * @param {mat3} [matrix=null] if null (default), the Transform matrix is being used.
251
+ * @returns {vec3} The transformed vector
252
+ */
253
+ publicAPI.transformVector = function (inVector) {
254
+ let outVector = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
255
+ let matrix = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
256
+ const matrix3x3 = matrix || mat3.fromMat4(mat3.create(), model.matrix);
257
+ vec3.transformMat3(outVector, inVector, matrix3x3);
258
+ return outVector;
259
+ };
260
+
261
+ /**
262
+ * Apply the transformation to a series of vectors, and append the results to
263
+ * outVectors.
264
+ * @param {vtkDataArray} inVectors The vectors to transform
265
+ * @param {vtkDataArray} outVectors The output array
266
+ */
267
+ publicAPI.transformVectors = (inVectors, outVectors) => {
268
+ const inArr = inVectors.getData();
269
+ const outArr = outVectors.getData();
270
+ const tmp = [0, 0, 0];
271
+ for (let i = 0; i < inArr.length; i += 3) {
272
+ tmp[0] = inArr[i];
273
+ tmp[1] = inArr[i + 1];
274
+ tmp[2] = inArr[i + 2];
275
+ publicAPI.transformVector(tmp, tmp);
276
+ vtkMath.normalize(tmp);
277
+ outArr[i] = tmp[0];
278
+ outArr[i + 1] = tmp[1];
279
+ outArr[i + 2] = tmp[2];
280
+ }
281
+ };
282
+
283
+ /**
284
+ * Transform points, normals, and vectors simultaneously.
285
+ * @param {vtkPoints} inPoints Input points
286
+ * @param {vtkPoints} outPoints Output points
287
+ * @param {vtkDataArray} inNormals Input normals
288
+ * @param {vtkDataArray} outNormals Output normals
289
+ * @param {vtkDataArray} inVectors Input vectors
290
+ * @param {vtkDataArray} outVectors Output vectors
291
+ * @param {Array<vtkDataArray>} inVectorsArr Optional input vector arrays
292
+ * @param {Array<vtkDataArray>} outVectorsArr Optional output vector arrays
293
+ */
294
+ publicAPI.transformPointsNormalsVectors = function (inPoints, outPoints, inNormals, outNormals, inVectors, outVectors) {
295
+ let inVectorsArr = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : null;
296
+ let outVectorsArr = arguments.length > 7 && arguments[7] !== undefined ? arguments[7] : null;
297
+ const n = inPoints.getNumberOfPoints();
298
+ const nOptionalVectors = inVectorsArr?.length ?? 0;
299
+ const point = new Float64Array(3);
300
+ const oldPoint = new Float64Array(3);
301
+ const oldVector = new Float64Array(3);
302
+ const oldNormal = new Float64Array(3);
303
+ let modifiedPoint = false;
304
+ let modifiedVector = false;
305
+ let modifiedNormal = false;
306
+ const modifiedVectorsArr = [];
307
+ for (let ptId = 0; ptId < n; ptId++) {
308
+ // Transform point
309
+ inPoints.getPoint(ptId, point);
310
+ oldPoint.set(point);
311
+ publicAPI.transformPoint(point, point);
312
+ outPoints.setPoint(ptId, ...point);
313
+ if (!vtkMath.areEquals(oldPoint, point)) {
314
+ modifiedPoint = true;
315
+ }
316
+
317
+ // Transform vectors
318
+ if (inVectors) {
319
+ const inData = inVectors.getData();
320
+ const outData = outVectors.getData();
321
+ point[0] = inData[ptId * 3];
322
+ point[1] = inData[ptId * 3 + 1];
323
+ point[2] = inData[ptId * 3 + 2];
324
+ oldVector.set(point);
325
+ publicAPI.transformVector(point, point);
326
+ outData[ptId * 3] = point[0];
327
+ outData[ptId * 3 + 1] = point[1];
328
+ outData[ptId * 3 + 2] = point[2];
329
+ if (!vtkMath.areEquals(oldVector, point)) {
330
+ modifiedVector = true;
331
+ }
332
+ }
333
+
334
+ // Transform normals
335
+ if (inNormals) {
336
+ const inData = inNormals.getData();
337
+ const outData = outNormals.getData();
338
+ point[0] = inData[ptId * 3];
339
+ point[1] = inData[ptId * 3 + 1];
340
+ point[2] = inData[ptId * 3 + 2];
341
+ oldNormal.set(point);
342
+ publicAPI.transformNormal(point, point);
343
+ outData[ptId * 3] = point[0];
344
+ outData[ptId * 3 + 1] = point[1];
345
+ outData[ptId * 3 + 2] = point[2];
346
+ if (!vtkMath.areEquals(oldNormal, point)) {
347
+ modifiedNormal = true;
348
+ }
349
+ }
350
+
351
+ // Transform optional vectors
352
+ if (inVectorsArr) {
353
+ for (let iArr = 0; iArr < nOptionalVectors; iArr++) {
354
+ const inData = inVectorsArr[iArr].getData();
355
+ const outData = outVectorsArr[iArr].getData();
356
+ point[0] = inData[ptId * 3];
357
+ point[1] = inData[ptId * 3 + 1];
358
+ point[2] = inData[ptId * 3 + 2];
359
+ oldVector.set(point);
360
+ publicAPI.transformVector(point, point);
361
+ outData[ptId * 3] = point[0];
362
+ outData[ptId * 3 + 1] = point[1];
363
+ outData[ptId * 3 + 2] = point[2];
364
+ if (!vtkMath.arrayEqual(oldVector, point) && !modifiedVectorsArr.includes(iArr)) {
365
+ modifiedVectorsArr.push(iArr);
366
+ }
367
+ }
368
+ }
369
+ }
370
+ if (modifiedPoint) {
371
+ outPoints.modified();
372
+ }
373
+ if (modifiedVector) {
374
+ outVectors.modified();
375
+ }
376
+ if (modifiedNormal) {
377
+ outNormals.modified();
378
+ }
379
+ modifiedVectorsArr.forEach(idx => outVectorsArr[idx].modified());
380
+ };
82
381
  }
83
382
 
84
383
  // ----------------------------------------------------------------------------
@@ -1,4 +1,5 @@
1
1
  import { n as newInstance$1, o as obj, d as algo, e as setGet, c as macro, b as newTypedArrayFrom } from '../../macros2.js';
2
+ import vtkDataArray from '../../Common/Core/DataArray.js';
2
3
  import vtkPolyData from '../../Common/DataModel/PolyData.js';
3
4
 
4
5
  const {
@@ -74,10 +75,18 @@ function vtkCutter(publicAPI, model) {
74
75
  function dataSetCutter(input, output) {
75
76
  const points = input.getPoints();
76
77
  const pointsData = points.getData();
78
+ const pointData = input.getPointData();
77
79
  const numPts = points.getNumberOfPoints();
78
80
  const newPointsData = [];
79
81
  const newLinesData = [];
80
82
  const newPolysData = [];
83
+ const newPointData = {}; // TODO: cell data must also be processed
84
+
85
+ // Initialize arrays
86
+ const numberOfArrays = pointData.getNumberOfArrays();
87
+ for (let arrayIdx = 0; arrayIdx < numberOfArrays; arrayIdx++) {
88
+ newPointData[pointData.getArrayName(arrayIdx)] = [];
89
+ }
81
90
  if (!model.cutScalars || model.cutScalars.length < numPts) {
82
91
  model.cutScalars = new Float32Array(numPts);
83
92
  }
@@ -169,6 +178,21 @@ function vtkCutter(publicAPI, model) {
169
178
 
170
179
  // Compute the intersected point on edge
171
180
  const computedIntersectedPoint = [x1[0] + t * (x2[0] - x1[0]), x1[1] + t * (x2[1] - x1[1]), x1[2] + t * (x2[2] - x1[2])];
181
+ const computedIntersectedArrays = {};
182
+ for (let arrayIdx = 0; arrayIdx < numberOfArrays; arrayIdx++) {
183
+ const array = pointData.getArrayByIndex(arrayIdx);
184
+ const name = pointData.getArrayName(arrayIdx);
185
+ const data = array.getData();
186
+ const n = array.getNumberOfComponents();
187
+ const computedIntersectedArray = new Array(n);
188
+ for (let j = 0; j < n; j++) {
189
+ const scalar1 = data[n * pointID1 + j];
190
+ const scalar2 = data[n * pointID2 + j];
191
+ computedIntersectedArray.push(scalar1 + t * (scalar2 - scalar1)); // FIXME: won't work when the array contains "normals" or "IDs"
192
+ }
193
+
194
+ computedIntersectedArrays[name] = computedIntersectedArray;
195
+ }
172
196
 
173
197
  // Keep track of it
174
198
  intersectedEdgesList.push({
@@ -178,6 +202,8 @@ function vtkCutter(publicAPI, model) {
178
202
  // id of one point of the edge
179
203
  intersectedPoint: computedIntersectedPoint,
180
204
  // 3D coordinate of points that intersected edge
205
+ intersectedArrays: computedIntersectedArrays,
206
+ // value(s) of the intersected arrays
181
207
  newPointID: -1 // id of the intersected point when it will be added into vtkPoints
182
208
  });
183
209
  }
@@ -201,6 +227,9 @@ function vtkCutter(publicAPI, model) {
201
227
  newPointsData.push(intersectedEdge.intersectedPoint[0]);
202
228
  newPointsData.push(intersectedEdge.intersectedPoint[1]);
203
229
  newPointsData.push(intersectedEdge.intersectedPoint[2]);
230
+ Object.keys(intersectedEdge.intersectedArrays).forEach(name => {
231
+ newPointData[name].push(...intersectedEdge.intersectedArrays[name]);
232
+ });
204
233
  intersectedEdgesList[i].newPointID = newPointsData.length / 3 - 1;
205
234
  crossedEdges.push(intersectedEdgesList[i]);
206
235
  }
@@ -222,6 +251,18 @@ function vtkCutter(publicAPI, model) {
222
251
  const outputPoints = output.getPoints();
223
252
  outputPoints.setData(newTypedArrayFrom(points.getDataType(), newPointsData), 3);
224
253
 
254
+ // Set scalars
255
+ const outputPointData = output.getPointData();
256
+ for (let arrayIdx = 0; arrayIdx < numberOfArrays; arrayIdx++) {
257
+ const name = pointData.getArrayName(arrayIdx);
258
+ const array = vtkDataArray.newInstance({
259
+ name,
260
+ values: newPointData[name],
261
+ numberOfComponents: pointData.getArrayByIndex(arrayIdx).getNumberOfComponents()
262
+ });
263
+ outputPointData.addArray(array);
264
+ }
265
+
225
266
  // Set lines
226
267
  if (newLinesData.length !== 0) {
227
268
  output.getLines().setData(Uint16Array.from(newLinesData));
@@ -1,7 +1,7 @@
1
1
  import { m as macro } from '../../macros2.js';
2
2
  import vtkCellArray from '../../Common/Core/CellArray.js';
3
3
  import vtkLine from '../../Common/DataModel/Line.js';
4
- import { d as dot, j as cross, n as norm, t as jacobi, l as normalize, k as add } from '../../Common/Core/Math/index.js';
4
+ import { d as dot, j as cross, n as norm, w as jacobi, l as normalize, k as add } from '../../Common/Core/Math/index.js';
5
5
  import vtkMatrixBuilder from '../../Common/Core/MatrixBuilder.js';
6
6
  import vtkOBBNode from './OBBTree/OBBNode.js';
7
7
  import vtkPoints from '../../Common/Core/Points.js';
@@ -0,0 +1,75 @@
1
+ import { DesiredOutputPrecision } from './../../Common/DataModel/DataSetAttributes';
2
+ import vtkTransform from './../../Common/Transform/Transform';
3
+ import { vtkAlgorithm, vtkObject } from './../../interfaces';
4
+
5
+ export interface ITransformPolyDataFilterInitialValues {
6
+ transform?: vtkTransform;
7
+ outputPointsPrecision?: DesiredOutputPrecision;
8
+ }
9
+
10
+ type vtkTransformPolyDataFilterBase = vtkObject & vtkAlgorithm;
11
+
12
+ export interface vtkTransformPolyDataFilter
13
+ extends vtkTransformPolyDataFilterBase {
14
+ /**
15
+ * Get the transform used by this filter.
16
+ */
17
+ getTransform(): vtkTransform;
18
+
19
+ /**
20
+ * Get the output points precision.
21
+ */
22
+ getOutputPointsPrecision(): DesiredOutputPrecision;
23
+
24
+ /**
25
+ *
26
+ * @param inData
27
+ * @param outData
28
+ */
29
+ requestData(inData: any, outData: any): void;
30
+
31
+ /**
32
+ * Set the output points precision.
33
+ * @param {DesiredOutputPrecision} precision
34
+ */
35
+ setOutputPointsPrecision(precision: DesiredOutputPrecision): boolean;
36
+
37
+ /**
38
+ * Set the transform used by this filter.
39
+ * @param {vtkTransform} transform
40
+ */
41
+ setTransform(transform: vtkTransform): boolean;
42
+ }
43
+
44
+ /**
45
+ * Method used to decorate a given object (publicAPI+model) with vtkTransformPolyDataFilter characteristics.
46
+ *
47
+ * @param publicAPI object on which methods will be bounds (public)
48
+ * @param model object on which data structure will be bounds (protected)
49
+ * @param {ITransformPolyDataFilterInitialValues} [initialValues] (default: {})
50
+ */
51
+ export function extend(
52
+ publicAPI: object,
53
+ model: object,
54
+ initialValues?: ITransformPolyDataFilterInitialValues
55
+ ): void;
56
+
57
+ /**
58
+ * Method used to create a new instance of vtkTransformPolyDataFilter.
59
+ * @param {ITransformPolyDataFilterInitialValues} [initialValues] for pre-setting some of its content
60
+ */
61
+ export function newInstance(
62
+ initialValues?: ITransformPolyDataFilterInitialValues
63
+ ): vtkTransformPolyDataFilter;
64
+
65
+ /**
66
+ * vtkTransformPolyDataFilter is a filter to transform point coordinates and
67
+ * associated point and cell normals and vectors. Other point and cell data is
68
+ * passed through the filter unchanged. This filter is specialized for polygonal
69
+ * data.
70
+ */
71
+ export declare const vtkTransformPolyDataFilter: {
72
+ newInstance: typeof newInstance;
73
+ extend: typeof extend;
74
+ };
75
+ export default vtkTransformPolyDataFilter;
@@ -0,0 +1,194 @@
1
+ import { m as macro } from '../../macros2.js';
2
+ import vtkDataArray from '../../Common/Core/DataArray.js';
3
+ import vtkPoints from '../../Common/Core/Points.js';
4
+ import vtkPolyData from '../../Common/DataModel/PolyData.js';
5
+ import { DesiredOutputPrecision } from '../../Common/DataModel/DataSetAttributes/Constants.js';
6
+ import { VtkDataTypes } from '../../Common/Core/DataArray/Constants.js';
7
+
8
+ const {
9
+ vtkErrorMacro
10
+ } = macro;
11
+
12
+ // ----------------------------------------------------------------------------
13
+ // vtkTransformPolyDataFilter methods
14
+ // ----------------------------------------------------------------------------
15
+
16
+ function vtkTransformPolyDataFilter(publicAPI, model) {
17
+ // Set our className
18
+ model.classHierarchy.push('vtkTransformPolyDataFilter');
19
+
20
+ // Internal method to handle the actual transformation
21
+ function transformPolyData(input, output) {
22
+ if (!model.transform) {
23
+ vtkErrorMacro('No transform defined!');
24
+ return false;
25
+ }
26
+ const inPts = input.getPoints();
27
+ const inPtData = input.getPointData();
28
+ const outPD = output.getPointData();
29
+ const inCellData = input.getCellData();
30
+ const outCD = output.getCellData();
31
+ if (!inPts) {
32
+ // Input polydata is empty. This is not an error, the output will be just empty, too.
33
+ return true;
34
+ }
35
+ const numPoints = inPts.getNumberOfPoints();
36
+
37
+ // Get input vectors and normals (points and cells)
38
+ const inVectors = inPtData.getVectors();
39
+ const inNormals = inPtData.getNormals();
40
+ const inCellVectors = inCellData.getVectors();
41
+ const inCellNormals = inCellData.getNormals();
42
+
43
+ // Set the desired precision for the points in the output
44
+ let pointType = inPts.getDataType();
45
+ if (model.outputPointsPrecision === DesiredOutputPrecision.SINGLE) {
46
+ pointType = VtkDataTypes.FLOAT;
47
+ } else if (model.outputPointsPrecision === DesiredOutputPrecision.DOUBLE) {
48
+ pointType = VtkDataTypes.DOUBLE;
49
+ }
50
+
51
+ // Create output points with appropriate precision
52
+ const outPts = vtkPoints.newInstance({
53
+ dataType: pointType
54
+ });
55
+
56
+ // Transform points
57
+ const inPtsData = inPts.getData();
58
+ outPts.setNumberOfPoints(numPoints);
59
+ const outPtsData = outPts.getData();
60
+
61
+ // Transform vectors if present
62
+ let outVectors = null;
63
+ if (inVectors) {
64
+ outVectors = vtkDataArray.newInstance({
65
+ name: inVectors.getName(),
66
+ numberOfComponents: 3,
67
+ size: numPoints * 3
68
+ });
69
+ }
70
+
71
+ // Transform normals if present
72
+ let outNormals = null;
73
+ if (inNormals) {
74
+ outNormals = vtkDataArray.newInstance({
75
+ name: inNormals.getName(),
76
+ numberOfComponents: 3,
77
+ size: numPoints * 3
78
+ });
79
+ }
80
+ if (inVectors || inNormals) {
81
+ model.transform.transformPointsNormalsVectors(inPts, outPts, inNormals, outNormals, inVectors, outVectors);
82
+ } else {
83
+ model.transform.transformPoints(inPtsData, outPtsData);
84
+ }
85
+
86
+ // Transform cell vectors if present
87
+ let outCellVectors = null;
88
+ if (inCellVectors) {
89
+ const numCells = inCellVectors.getNumberOfTuples();
90
+ outCellVectors = vtkDataArray.newInstance({
91
+ name: inCellVectors.getName(),
92
+ numberOfComponents: 3,
93
+ size: numCells * 3
94
+ });
95
+ model.transform.transformVectors(inCellVectors, outCellVectors);
96
+ }
97
+
98
+ // Transform cell normals if present
99
+ let outCellNormals = null;
100
+ if (inCellNormals) {
101
+ const numCells = inCellNormals.getNumberOfTuples();
102
+ outCellNormals = vtkDataArray.newInstance({
103
+ name: inCellNormals.getName(),
104
+ numberOfComponents: 3,
105
+ size: numCells * 3
106
+ });
107
+ model.transform.transformNormals(inCellNormals, outCellNormals);
108
+ }
109
+
110
+ // Set output data
111
+ output.setPoints(outPts);
112
+
113
+ // Copy cell topology
114
+ output.setVerts(input.getVerts());
115
+ output.setLines(input.getLines());
116
+ output.setPolys(input.getPolys());
117
+ output.setStrips(input.getStrips());
118
+
119
+ // Set transformed point data
120
+ if (outNormals) {
121
+ outPD.setNormals(outNormals);
122
+ outPD.copyFieldOff(outNormals.getName());
123
+ }
124
+ if (outVectors) {
125
+ outPD.setVectors(outVectors);
126
+ outPD.copyFieldOff(outVectors.getName());
127
+ }
128
+
129
+ // Set transformed cell data
130
+ if (outCellNormals) {
131
+ outCD.setNormals(outCellNormals);
132
+ outCD.copyFieldOff(outCellNormals.getName());
133
+ }
134
+ if (outCellVectors) {
135
+ outCD.setVectors(outCellVectors);
136
+ outCD.copyFieldOff(outCellVectors.getName());
137
+ }
138
+
139
+ // Pass through other data
140
+ outPD.passData(inPtData);
141
+ outCD.passData(inCellData);
142
+ return true;
143
+ }
144
+ publicAPI.requestData = (inData, outData) => {
145
+ const input = inData[0];
146
+ const output = outData[0] || vtkPolyData.newInstance();
147
+ if (transformPolyData(input, output)) {
148
+ outData[0] = output;
149
+ } else {
150
+ vtkErrorMacro('TransformPolyDataFilter failed to transform input data.');
151
+ }
152
+ };
153
+ }
154
+
155
+ // ----------------------------------------------------------------------------
156
+ // Object factory
157
+ // ----------------------------------------------------------------------------
158
+
159
+ const DEFAULT_VALUES = {
160
+ transform: null,
161
+ outputPointsPrecision: DesiredOutputPrecision.DEFAULT
162
+ };
163
+
164
+ // ----------------------------------------------------------------------------
165
+
166
+ function extend(publicAPI, model) {
167
+ let initialValues = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
168
+ Object.assign(model, DEFAULT_VALUES, initialValues);
169
+
170
+ // Make this a VTK object
171
+ macro.obj(publicAPI, model);
172
+
173
+ // Also make it an algorithm with one input and one output
174
+ macro.algo(publicAPI, model, 1, 1);
175
+
176
+ // Set/Get methods
177
+ macro.setGet(publicAPI, model, ['transform', 'outputPointsPrecision']);
178
+
179
+ // Object specific methods
180
+ vtkTransformPolyDataFilter(publicAPI, model);
181
+ }
182
+
183
+ // ----------------------------------------------------------------------------
184
+
185
+ const newInstance = macro.newInstance(extend, 'vtkTransformPolyDataFilter');
186
+
187
+ // ----------------------------------------------------------------------------
188
+
189
+ var vtkTransformPolyDataFilter$1 = {
190
+ newInstance,
191
+ extend
192
+ };
193
+
194
+ export { vtkTransformPolyDataFilter$1 as default, extend, newInstance };
@@ -15,6 +15,7 @@ import vtkOBBTree from './General/OBBTree.js';
15
15
  import vtkOutlineFilter from './General/OutlineFilter.js';
16
16
  import vtkPaintFilter from './General/PaintFilter.js';
17
17
  import vtkScalarToRGBA from './General/ScalarToRGBA.js';
18
+ import vtkTransformPolyDataFilter from './General/TransformPolyDataFilter.js';
18
19
  import vtkTriangleFilter from './General/TriangleFilter.js';
19
20
  import vtkTubeFilter from './General/TubeFilter.js';
20
21
  import vtkWarpScalar from './General/WarpScalar.js';
@@ -38,6 +39,7 @@ var General = {
38
39
  vtkOutlineFilter,
39
40
  vtkPaintFilter,
40
41
  vtkScalarToRGBA,
42
+ vtkTransformPolyDataFilter,
41
43
  vtkTriangleFilter,
42
44
  vtkTubeFilter,
43
45
  vtkWarpScalar,