@kitware/vtk.js 34.5.0 → 34.7.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 (70) 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 +12 -1
  6. package/Common/Core/Math.d.ts +24 -18
  7. package/Common/Core/Math.js +1 -1
  8. package/Common/DataModel/Triangle.d.ts +68 -19
  9. package/Common/DataModel/Triangle.js +136 -2
  10. package/Common/DataModel/TriangleStrip.d.ts +180 -0
  11. package/Common/DataModel/TriangleStrip.js +396 -0
  12. package/Common/DataModel.js +3 -1
  13. package/Common/Transform/LandmarkTransform.js +1 -1
  14. package/Common/Transform/Transform.d.ts +112 -1
  15. package/Common/Transform/Transform.js +301 -2
  16. package/Filters/Core/Cutter.js +42 -0
  17. package/Filters/General/OBBTree.js +1 -1
  18. package/Filters/General/TransformPolyDataFilter.d.ts +75 -0
  19. package/Filters/General/TransformPolyDataFilter.js +194 -0
  20. package/Filters/General.js +2 -0
  21. package/Filters/Sources/CircleSource.js +1 -1
  22. package/Filters/Sources/PointSource.js +1 -1
  23. package/Filters/Texture/TextureMapToPlane.js +1 -1
  24. package/IO/Geometry/DracoReader.js +1 -1
  25. package/IO/Geometry/GLTFImporter/Animations.js +1 -1
  26. package/IO/Geometry/GLTFImporter/Reader.js +2 -2
  27. package/IO/Image/HDRReader/Utils.js +1 -1
  28. package/IO/Image/HDRReader.js +1 -1
  29. package/IO/Misc/OBJWriter.d.ts +103 -0
  30. package/IO/Misc/OBJWriter.js +235 -0
  31. package/IO/Misc.js +2 -0
  32. package/Interaction/Manipulators/MouseCameraTrackballRollManipulator.js +1 -1
  33. package/Interaction/Manipulators/MouseCameraTrackballRotateManipulator.js +1 -1
  34. package/Interaction/Manipulators/MouseCameraUnicamManipulator.js +1 -1
  35. package/Interaction/Manipulators/MouseCameraUnicamRotateManipulator.js +1 -1
  36. package/Interaction/Style/InteractorStyleManipulator.js +75 -2
  37. package/Interaction/Style/InteractorStyleTrackballCamera.js +1 -1
  38. package/Interaction/Widgets/PiecewiseGaussianWidget.js +1 -1
  39. package/Proxy/Core/View2DProxy.js +1 -1
  40. package/Rendering/Core/AbstractImageMapper.js +1 -1
  41. package/Rendering/Core/AbstractMapper3D.js +1 -1
  42. package/Rendering/Core/Camera.d.ts +3 -3
  43. package/Rendering/Core/Camera.js +33 -3
  44. package/Rendering/Core/ColorTransferFunction/CssFilters.js +1 -1
  45. package/Rendering/Core/ColorTransferFunction.js +1 -1
  46. package/Rendering/Core/Coordinate.js +1 -1
  47. package/Rendering/Core/CubeAxesActor.js +1 -1
  48. package/Rendering/Core/Glyph3DMapper.js +1 -1
  49. package/Rendering/Core/ImageArrayMapper.js +1 -1
  50. package/Rendering/Core/ImageMapper.js +1 -1
  51. package/Rendering/Core/Mapper.js +1 -1
  52. package/Rendering/Core/Prop3D.js +1 -1
  53. package/Rendering/Core/RenderWindowInteractor.js +3 -3
  54. package/Rendering/Core/Renderer.js +1 -1
  55. package/Rendering/Core/ScalarBarActor.js +1 -1
  56. package/Rendering/Core/TextActor.js +1 -1
  57. package/Rendering/Core/VectorText/Utils.js +1 -1
  58. package/Rendering/Core/VolumeProperty.js +1 -1
  59. package/Rendering/OpenGL/PolyDataMapper2D.js +1 -1
  60. package/Rendering/OpenGL/Texture.js +1 -1
  61. package/Rendering/OpenGL/VolumeMapper.js +21 -19
  62. package/Widgets/Manipulators/LineManipulator.js +1 -1
  63. package/Widgets/Representations/PolyLineRepresentation.js +1 -1
  64. package/Widgets/Widgets3D/AngleWidget.js +1 -1
  65. package/Widgets/Widgets3D/LineWidget/helpers.js +1 -1
  66. package/Widgets/Widgets3D/ResliceCursorWidget/behavior.js +1 -1
  67. package/Widgets/Widgets3D/ResliceCursorWidget/helpers.js +1 -1
  68. package/Widgets/Widgets3D/ResliceCursorWidget.js +1 -1
  69. package/index.d.ts +3 -0
  70. package/package.json +1 -1
@@ -1,6 +1,8 @@
1
- import { mat4, vec3 } from 'gl-matrix';
1
+ import { mat3, mat4, vec3 } from 'gl-matrix';
2
2
  import { vtkObject } from './../../interfaces';
3
3
  import { TypedArray } from './../../types';
4
+ import vtkDataArray from './../Core/DataArray';
5
+ import vtkPoints from './../Core/Points';
4
6
 
5
7
  export interface ITransformInitialValues {
6
8
  preMultiplyFlag?: boolean;
@@ -144,6 +146,115 @@ export interface vtkTransform extends vtkObject {
144
146
  * @returns A new transform with an inversed internal matrix. Also copy the premultiply flag @see getPreMultiplyFlag.
145
147
  */
146
148
  getInverse(): vtkTransform;
149
+
150
+ /**
151
+ * Create a translation matrix and concatenate it with the current
152
+ * transformation according to preMultiply or postMultiply semantics.
153
+ * @param {Number} x X component of the translation
154
+ * @param {Number} y Y component of the translation
155
+ * @param {Number} z Z component of the translation
156
+ */
157
+ translate(x: number, y: number, z: number): void;
158
+
159
+ /**
160
+ * Create a rotation matrix and concatenate it with the current transformation
161
+ * according to preMultiply or postMultiply semantics.
162
+ * The angle is expressed in degrees.
163
+ * @param {Number} angle Angle in degrees
164
+ * @param {Number} x X component of the rotation axis
165
+ * @param {Number} y Y component of the rotation axis
166
+ * @param {Number} z Z component of the rotation axis
167
+ */
168
+ rotateWXYZ(angle: number, x: number, y: number, z: number): void;
169
+
170
+ /**
171
+ * Create a rotation matrix and concatenate it with the current transformation
172
+ * according to preMultiply or postMultiply semantics.
173
+ * The angle is expressed in degrees.
174
+ * @param {Number} angle Angle in degrees
175
+ */
176
+ rotateX(angle: number): void;
177
+
178
+ /**
179
+ * Create a rotation matrix about the X, Y, or Z axis and concatenate it with
180
+ * the current transformation according to preMultiply or postMultiply
181
+ * semantics.
182
+ * @param {Number} angle Angle in degrees
183
+ */
184
+ rotateY(angle: number): void;
185
+
186
+ /**
187
+ * Create a rotation matrix about the X, Y, or Z axis and concatenate it with
188
+ * the current transformation according to preMultiply or postMultiply
189
+ * semantics.
190
+ * @param {Number} angle Angle in degrees
191
+ */
192
+ rotateZ(angle: number): void;
193
+
194
+ /**
195
+ * Create a scale matrix (i.e. set the diagonal elements to x, y, z) and
196
+ * concatenate it with the current transformation according to preMultiply or
197
+ * postMultiply semantics.
198
+ * @param {Number} x Diagonal element for X axis
199
+ * @param {Number} y Diagonal element for Y axis
200
+ * @param {Number} z Diagonal element for Z axis
201
+ */
202
+ scale(x: number, y: number, z: number): void;
203
+
204
+ /**
205
+ * Apply the transformation to a normal.
206
+ * @param {vec3} inNormal The normal vector to transform
207
+ * @param {vec3} outNormal The output vector
208
+ * @returns {vec3} The transformed normal vector
209
+ */
210
+ transformNormal(inNormal: vec3, outNormal?: vec3): vec3;
211
+
212
+ /**
213
+ * Apply the transformation to a series of normals, and append the results to
214
+ * outNormals.
215
+ * @param {vtkDataArray} inNormals The normal vectors to transform
216
+ * @param {vtkDataArray} outNormals The output array
217
+ */
218
+ transformNormals(inNormals: vtkDataArray, outNormals: vtkDataArray): void;
219
+
220
+ /**
221
+ * Transform points, normals, and vectors simultaneously.
222
+ * @param {vtkPoints} inPoints Input points
223
+ * @param {vtkPoints} outPoints Output points
224
+ * @param {vtkDataArray} inNormals Input normals
225
+ * @param {vtkDataArray} outNormals Output normals
226
+ * @param {vtkDataArray} inVectors Input vectors
227
+ * @param {vtkDataArray} outVectors Output vectors
228
+ * @param {Array<vtkDataArray>} inVectorsArr Optional input vectors arrays
229
+ * @param {Array<vtkDataArray>} outVectorsArr Optional output vectors arrays
230
+ */
231
+ transformPointsNormalsVectors(
232
+ inPoints: vtkPoints,
233
+ outPoints: vtkPoints,
234
+ inNormals: vtkDataArray,
235
+ outNormals: vtkDataArray,
236
+ inVectors: vtkDataArray,
237
+ outVectors: vtkDataArray,
238
+ inVectorsArr?: Array<vtkDataArray>,
239
+ outVectorsArr?: Array<vtkDataArray>
240
+ ): void;
241
+
242
+ /**
243
+ * Apply the transformation to a vector.
244
+ * @param {vec3} inVector The vector to transform
245
+ * @param {vec3} outVector The output vector
246
+ * @param {mat3} [matrix=null] if null (default), the Transform matrix is being used.
247
+ * @returns {vec3} The transformed vector
248
+ */
249
+ transformVector(inVector: vec3, outVector?: vec3, matrix?: mat3): vec3;
250
+
251
+ /**
252
+ * Apply the transformation to a series of vectors, and append the results to
253
+ * outVectors.
254
+ * @param {vtkDataArray} inVectors The vectors to transform
255
+ * @param {vtkDataArray} outVectors The output array
256
+ */
257
+ transformVectors(inVectors: vtkDataArray, outVectors: vtkDataArray): void;
147
258
  }
148
259
 
149
260
  /**
@@ -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,19 @@ 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
+ dataType: pointData.getArrayByIndex(arrayIdx).getDataType(),
261
+ values: newPointData[name],
262
+ numberOfComponents: pointData.getArrayByIndex(arrayIdx).getNumberOfComponents()
263
+ });
264
+ outputPointData.addArray(array);
265
+ }
266
+
225
267
  // Set lines
226
268
  if (newLinesData.length !== 0) {
227
269
  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;