@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
@@ -39,6 +39,9 @@ export interface vtkCellArray extends vtkDataArray {
39
39
 
40
40
  /**
41
41
  * Insert a cell to this array in the next available slot.
42
+ * This may re-allocate a new typed array if the current one is not large enough.
43
+ * If the final size of the array is known up-front, it is more efficient to call
44
+ * `allocate()` before calling `insertNextCell()` multiple times.
42
45
  * @param {Number[]} cellPointIds The list of point ids (NOT prefixed with the number of points)
43
46
  * @returns {Number} Idx of where the cell was inserted
44
47
  */
@@ -2,6 +2,9 @@ import { m as macro } from '../../macros2.js';
2
2
  import vtkDataArray from './DataArray.js';
3
3
  import { VtkDataTypes } from './DataArray/Constants.js';
4
4
 
5
+ const {
6
+ isVtkObject
7
+ } = macro;
5
8
  // ----------------------------------------------------------------------------
6
9
  // Global methods
7
10
  // ----------------------------------------------------------------------------
@@ -65,6 +68,8 @@ function vtkCellArray(publicAPI, model) {
65
68
 
66
69
  /**
67
70
  * When `resize()` is being used, you then MUST use `insertNextCell()`.
71
+ * @see vtkCellArray#insertNextCell
72
+ * @see vtkDataArray#allocate
68
73
  */
69
74
  publicAPI.resize = requestedNumTuples => {
70
75
  const oldNumTuples = publicAPI.getNumberOfTuples();
@@ -92,7 +97,13 @@ function vtkCellArray(publicAPI, model) {
92
97
  const numberOfPoints = model.values[cellLoc++];
93
98
  return model.values.subarray(cellLoc, cellLoc + numberOfPoints);
94
99
  };
95
- publicAPI.insertNextCell = cellPointIds => {
100
+ publicAPI.insertNextCell = cell => {
101
+ let cellPointIds;
102
+ if (isVtkObject(cell)) {
103
+ cellPointIds = cell.getPointsIds();
104
+ } else {
105
+ cellPointIds = cell;
106
+ }
96
107
  const cellId = publicAPI.getNumberOfCells();
97
108
  publicAPI.insertNextTuples([cellPointIds.length, ...cellPointIds]);
98
109
  // By computing the number of cells earlier, we made sure that numberOfCells is defined
@@ -168,6 +168,7 @@ export interface vtkDataArray extends vtkObject {
168
168
  *
169
169
  * @see insertNextTuple
170
170
  * @see getNumberOfTuples
171
+ * @see allocate
171
172
  *
172
173
  * @param {Number} idx
173
174
  * @param {Array<Number>|TypedArray} tuple
@@ -189,6 +190,7 @@ export interface vtkDataArray extends vtkObject {
189
190
  * NOTE: May resize the data values array. "Safe" version of setTuple.
190
191
  *
191
192
  * @see insertTuple
193
+ * @see allocate
192
194
  *
193
195
  * @param {Array<Number>|TypedArray} tuple
194
196
  * @returns {Number} Index of the inserted tuple.
@@ -303,6 +305,18 @@ export interface vtkDataArray extends vtkObject {
303
305
  t: float
304
306
  ): void;
305
307
 
308
+ /**
309
+ * Resize the array to the requested number of extra tuples
310
+ * (added to the current number of tuples) and preserve data.
311
+ * model.size WILL NOT be modified.
312
+ * This is useful before multiple calls to `insertNextTuple()` or `insertNextTuples()`.
313
+ * @param {Number} extraNumTuples Number of tuples to allocate memory wise.
314
+ * @see insertNextTuple
315
+ * @see insertNextTuples
316
+ * @see allocate
317
+ */
318
+ allocate(extraNumTuples: number): void;
319
+
306
320
  /**
307
321
  * Resize the array to the requested number of tuples and preserve data.
308
322
  * Increasing the array size may allocate extra memory beyond what was
@@ -318,6 +332,7 @@ export interface vtkDataArray extends vtkObject {
318
332
  * @see insertNextTuple
319
333
  * @see insertNextTuples
320
334
  * @see initialize
335
+ * @see allocate
321
336
  */
322
337
  resize(requestedNumTuples: number): boolean;
323
338
 
@@ -156,17 +156,18 @@ function vtkDataArray(publicAPI, model) {
156
156
  return false;
157
157
  }
158
158
  const numComps = publicAPI.getNumberOfComponents();
159
- const curNumTuples = model.values.length / (numComps > 0 ? numComps : 1);
160
- if (requestedNumTuples === curNumTuples) {
159
+ const numAllocatedTuples = model.values.length / (numComps > 0 ? numComps : 1);
160
+ if (requestedNumTuples === numAllocatedTuples) {
161
161
  return true;
162
162
  }
163
- if (requestedNumTuples > curNumTuples) {
163
+ if (requestedNumTuples > numAllocatedTuples) {
164
164
  // Requested size is bigger than current size. Allocate enough
165
165
  // memory to fit the requested size and be more than double the
166
166
  // currently allocated memory.
167
167
  const oldValues = model.values;
168
- model.values = newTypedArray(model.dataType, (requestedNumTuples + curNumTuples) * numComps);
168
+ model.values = newTypedArray(model.dataType, (requestedNumTuples + numAllocatedTuples) * numComps);
169
169
  model.values.set(oldValues);
170
+ // The actual number of tuples is not increased, only memory is allocated.
170
171
  return true;
171
172
  }
172
173
 
@@ -181,6 +182,9 @@ function vtkDataArray(publicAPI, model) {
181
182
  model.ranges = null;
182
183
  publicAPI.modified();
183
184
  };
185
+ publicAPI.allocate = extraNumTuples => {
186
+ resize(publicAPI.getNumberOfTuples() + extraNumTuples);
187
+ };
184
188
  publicAPI.resize = requestedNumTuples => {
185
189
  resize(requestedNumTuples);
186
190
  const newSize = requestedNumTuples * publicAPI.getNumberOfComponents();
@@ -258,6 +258,16 @@ function normalize(x) {
258
258
  }
259
259
  return den;
260
260
  }
261
+ function normalize4D(x) {
262
+ const den = norm(x, 3);
263
+ if (den !== 0.0) {
264
+ x[0] /= den;
265
+ x[1] /= den;
266
+ x[2] /= den;
267
+ x[3] /= den;
268
+ }
269
+ return den;
270
+ }
261
271
  function perpendiculars(x, y, z, theta) {
262
272
  const x2 = x[0] * x[0];
263
273
  const y2 = x[1] * x[1];
@@ -2171,6 +2181,7 @@ var vtkMath$1 = /*#__PURE__*/Object.freeze({
2171
2181
  cross: cross,
2172
2182
  norm: norm,
2173
2183
  normalize: normalize,
2184
+ normalize4D: normalize4D,
2174
2185
  perpendiculars: perpendiculars,
2175
2186
  projectVector: projectVector,
2176
2187
  dot2D: dot2D,
@@ -2256,4 +2267,4 @@ var vtkMath$1 = /*#__PURE__*/Object.freeze({
2256
2267
  'default': vtkMath
2257
2268
  });
2258
2269
 
2259
- export { ceil as $, degreesFromRadians as A, ldexp as B, xyz2rgb as C, areEquals as D, clampValue as E, arrayRange as F, getMajorAxisIndex as G, createUninitializedBounds as H, identity as I, multiplyMatrix as J, floor as K, isInf as L, rgb2hsv as M, rgb2lab as N, lab2rgb as O, round as P, normalize2D as Q, nearestPowerOfTwo as R, multiply3x3_vect3 as S, getSparseOrthogonalMatrix as T, areBoundsInitialized as U, floatRGB2HexCode as V, isPowerOfTwo as W, angleBetweenVectors as X, signedAngleBetweenVectors as Y, createArray as Z, Pi as _, areMatricesEqual as a, floatToHex2 as a$, min as a0, max as a1, arrayMin as a2, arrayMax as a3, ceilLog2 as a4, factorial as a5, binomial as a6, beginCombination as a7, nextCombination as a8, randomSeed as a9, matrix3x3ToQuaternion as aA, multiplyQuaternion as aB, orthogonalize3x3 as aC, diagonalize3x3 as aD, singularValueDecomposition3x3 as aE, luFactorLinearSystem as aF, luSolveLinearSystem as aG, invertMatrix as aH, estimateMatrixCondition as aI, solveHomogeneousLeastSquares as aJ, solveLeastSquares as aK, hex2float as aL, lab2xyz as aM, xyz2lab as aN, rgb2xyz as aO, computeBoundsFromPoints as aP, clampAndNormalizeValue as aQ, getScalarTypeFittingRange as aR, getAdjustedScalarRange as aS, extentIsWithinOtherExtent as aT, boundsIsWithinOtherBounds as aU, pointIsWithinBounds as aV, solve3PointCircle as aW, inf as aX, negInf as aY, isFinite as aZ, isNaN as a_, getSeed as aa, gaussian as ab, multiplyScalar2D as ac, multiplyAccumulate2D as ad, outer as ae, projectVector as af, dot2D as ag, projectVector2D as ah, gaussianAmplitude as ai, gaussianWeight as aj, outer2D as ak, norm2D as al, rowsToMat4 as am, columnsToMat4 as an, columnsToMat3 as ao, LUFactor3x3 as ap, LUSolve3x3 as aq, linearSolve3x3 as ar, multiply3x3_mat3 as as, transpose3x3 as at, invert3x3 as au, identity3x3 as av, isIdentity as aw, isIdentity3x3 as ax, quaternionToMatrix3x3 as ay, roundNumber as az, roundVector as b, float2CssRGBA as b0, clampVector as c, dot as d, distance2BetweenPoints as e, vtkMath as f, solveLinearSystem as g, hsv2rgb as h, isNan as i, cross as j, add as k, normalize as l, multiplyAccumulate as m, norm as n, determinant2x2 as o, jacobiN as p, perpendiculars as q, radiansFromDegrees as r, subtract as s, jacobi as t, uninitializeBounds as u, vtkMath$1 as v, multiplyScalar as w, random as x, determinant3x3 as y, rowsToMat3 as z };
2270
+ export { createArray as $, rowsToMat3 as A, degreesFromRadians as B, ldexp as C, xyz2rgb as D, areEquals as E, clampValue as F, arrayRange as G, getMajorAxisIndex as H, createUninitializedBounds as I, normalize4D as J, identity as K, multiplyMatrix as L, floor as M, isInf as N, rgb2hsv as O, rgb2lab as P, lab2rgb as Q, round as R, normalize2D as S, nearestPowerOfTwo as T, multiply3x3_vect3 as U, getSparseOrthogonalMatrix as V, areBoundsInitialized as W, floatRGB2HexCode as X, isPowerOfTwo as Y, angleBetweenVectors as Z, signedAngleBetweenVectors as _, areMatricesEqual as a, isNaN as a$, Pi as a0, ceil as a1, min as a2, max as a3, arrayMin as a4, arrayMax as a5, ceilLog2 as a6, factorial as a7, binomial as a8, beginCombination as a9, quaternionToMatrix3x3 as aA, roundNumber as aB, matrix3x3ToQuaternion as aC, multiplyQuaternion as aD, orthogonalize3x3 as aE, diagonalize3x3 as aF, singularValueDecomposition3x3 as aG, luFactorLinearSystem as aH, luSolveLinearSystem as aI, estimateMatrixCondition as aJ, solveHomogeneousLeastSquares as aK, solveLeastSquares as aL, hex2float as aM, lab2xyz as aN, xyz2lab as aO, rgb2xyz as aP, computeBoundsFromPoints as aQ, clampAndNormalizeValue as aR, getScalarTypeFittingRange as aS, getAdjustedScalarRange as aT, extentIsWithinOtherExtent as aU, boundsIsWithinOtherBounds as aV, pointIsWithinBounds as aW, solve3PointCircle as aX, inf as aY, negInf as aZ, isFinite as a_, nextCombination as aa, randomSeed as ab, getSeed as ac, gaussian as ad, multiplyScalar2D as ae, multiplyAccumulate2D as af, outer as ag, projectVector as ah, dot2D as ai, projectVector2D as aj, gaussianAmplitude as ak, gaussianWeight as al, outer2D as am, norm2D as an, rowsToMat4 as ao, columnsToMat4 as ap, columnsToMat3 as aq, LUFactor3x3 as ar, LUSolve3x3 as as, linearSolve3x3 as at, multiply3x3_mat3 as au, transpose3x3 as av, invert3x3 as aw, identity3x3 as ax, isIdentity as ay, isIdentity3x3 as az, roundVector as b, floatToHex2 as b0, float2CssRGBA as b1, clampVector as c, dot as d, distance2BetweenPoints as e, vtkMath as f, solveLinearSystem as g, hsv2rgb as h, isNan as i, cross as j, add as k, normalize as l, multiplyAccumulate as m, norm as n, determinant2x2 as o, invertMatrix as p, jacobiN as q, radiansFromDegrees as r, subtract as s, perpendiculars as t, uninitializeBounds as u, vtkMath$1 as v, jacobi as w, multiplyScalar as x, random as y, determinant3x3 as z };
@@ -203,7 +203,7 @@ export function getSeed(): number;
203
203
  export function random(minValue: number, maxValue: number): number;
204
204
 
205
205
  /**
206
- * Addition of two 3-vectors.
206
+ * Add two 3-vectors.
207
207
  * @param {Vector3} a The first 3D vector.
208
208
  * @param {Vector3} b The second 3D vector.
209
209
  * @param {Vector3} out The output 3D vector.
@@ -215,7 +215,7 @@ export function random(minValue: number, maxValue: number): number;
215
215
  export function add(a: Vector3, b: Vector3, out: Vector3): Vector3;
216
216
 
217
217
  /**
218
- * Subtraction of two 3-vectors.
218
+ * Substract two 3-vectors.
219
219
  * @param {Vector3} a The first 3D vector.
220
220
  * @param {Vector3} b The second 3D vector.
221
221
  * @param {Vector3} out The output 3D vector.
@@ -227,7 +227,7 @@ export function add(a: Vector3, b: Vector3, out: Vector3): Vector3;
227
227
  export function subtract(a: Vector3, b: Vector3, out: Vector3): Vector3;
228
228
 
229
229
  /**
230
- *
230
+ * Multiply a 3-vector by a scalar.
231
231
  * @param {Vector3} vec
232
232
  * @param {Number} scalar
233
233
  * @example
@@ -238,7 +238,7 @@ export function subtract(a: Vector3, b: Vector3, out: Vector3): Vector3;
238
238
  export function multiplyScalar(vec: Vector3, scalar: number): Vector3;
239
239
 
240
240
  /**
241
- *
241
+ * Multiply a 3-vector by a scalar.
242
242
  * @param {Vector2} vec
243
243
  * @param {Number} scalar
244
244
  * @example
@@ -249,7 +249,7 @@ export function multiplyScalar(vec: Vector3, scalar: number): Vector3;
249
249
  export function multiplyScalar2D(vec: Vector2, scalar: number): Vector2;
250
250
 
251
251
  /**
252
- *
252
+ * Multiply two 3-vectors.
253
253
  * @param {Vector3} a
254
254
  * @param {Vector3} b
255
255
  * @param {Number} scalar
@@ -267,7 +267,7 @@ export function multiplyAccumulate(
267
267
  ): Vector3;
268
268
 
269
269
  /**
270
- *
270
+ * Multiply two 2-vectors.
271
271
  * @param {Vector2} a
272
272
  * @param {Vector2} b
273
273
  * @param {Number} scalar
@@ -285,7 +285,7 @@ export function multiplyAccumulate2D(
285
285
  ): Vector2;
286
286
 
287
287
  /**
288
- *
288
+ * Dot product of two 3-vectors.
289
289
  * @param {Vector3} x
290
290
  * @param {Vector3} y
291
291
  * @example
@@ -312,17 +312,23 @@ export function outer(x: Vector3, y: Vector3, out_3x3: Matrix3x3): void;
312
312
  export function cross(x: Vector3, y: Vector3, out: Vector3): Vector3;
313
313
 
314
314
  /**
315
- *
316
- * @param {Number[]} x
317
- * @param {Number} n
315
+ * Compute the norm of a vector.
316
+ * @param {Number[]} x The vector to compute the norm of.
317
+ * @param {Number} [n] The number of components to consider (default is 3).
318
318
  */
319
- export function norm(x: number[], n: number): number;
319
+ export function norm(x: number[], n?: number): number;
320
320
 
321
321
  /**
322
322
  * Normalize in place. Returns norm.
323
- * @param {Vector3} x The vector to normlize.
323
+ * @param {Number[]} x The vector to normalize.
324
324
  */
325
- export function normalize(x: Vector3): number;
325
+ export function normalize(x: number[]): number;
326
+
327
+ /**
328
+ * Normalize in place. Returns norm.
329
+ * @param {Number[]} x The vector to normalize.
330
+ */
331
+ export function normalize4D(x: number[]): number;
326
332
 
327
333
  /**
328
334
  * Given a unit vector v1, find two unit vectors v2 and v3 such that v1 cross v2 = v3
@@ -339,10 +345,10 @@ export function perpendiculars(
339
345
  ): void;
340
346
 
341
347
  /**
342
- *
343
- * @param {Vector3} a
344
- * @param {Vector3} b
345
- * @param {Vector3} projection
348
+ * Project vector `a` onto vector `b` and returns the result in projection vector.
349
+ * @param {Vector3} a The first 3D vector.
350
+ * @param {Vector3} b The second 3D vector.
351
+ * @param {Vector3} projection The projection 3D vector.
346
352
  */
347
353
  export function projectVector(
348
354
  a: Vector3,
@@ -351,7 +357,7 @@ export function projectVector(
351
357
  ): boolean;
352
358
 
353
359
  /**
354
- *
360
+ * Compute the dot product of two 2D vectors.
355
361
  * @param {Vector2} x
356
362
  * @param {Vector2} y
357
363
  */
@@ -1,4 +1,4 @@
1
1
  import 'seedrandom';
2
2
  import '../../macros2.js';
3
3
  import './Math/Constants.js';
4
- export { ap as LUFactor3x3, aq as LUSolve3x3, _ as Pi, k as add, X as angleBetweenVectors, U as areBoundsInitialized, D as areEquals, a as areMatricesEqual, a3 as arrayMax, a2 as arrayMin, F as arrayRange, a7 as beginCombination, a6 as binomial, aU as boundsIsWithinOtherBounds, $ as ceil, a4 as ceilLog2, aQ as clampAndNormalizeValue, E as clampValue, c as clampVector, ao as columnsToMat3, an as columnsToMat4, aP as computeBoundsFromPoints, Z as createArray, H as createUninitializedBounds, j as cross, f as default, A as degreesFromRadians, o as determinant2x2, y as determinant3x3, aD as diagonalize3x3, e as distance2BetweenPoints, d as dot, ag as dot2D, aI as estimateMatrixCondition, aT as extentIsWithinOtherExtent, a5 as factorial, b0 as float2CssRGBA, V as floatRGB2HexCode, a$ as floatToHex2, K as floor, ab as gaussian, ai as gaussianAmplitude, aj as gaussianWeight, aS as getAdjustedScalarRange, G as getMajorAxisIndex, aR as getScalarTypeFittingRange, aa as getSeed, T as getSparseOrthogonalMatrix, aL as hex2float, h as hsv2rgb, I as identity, av as identity3x3, aX as inf, au as invert3x3, aH as invertMatrix, aZ as isFinite, aw as isIdentity, ax as isIdentity3x3, L as isInf, a_ as isNaN, i as isNan, W as isPowerOfTwo, t as jacobi, p as jacobiN, O as lab2rgb, aM as lab2xyz, B as ldexp, ar as linearSolve3x3, aF as luFactorLinearSystem, aG as luSolveLinearSystem, aA as matrix3x3ToQuaternion, a1 as max, a0 as min, as as multiply3x3_mat3, S as multiply3x3_vect3, m as multiplyAccumulate, ad as multiplyAccumulate2D, J as multiplyMatrix, aB as multiplyQuaternion, w as multiplyScalar, ac as multiplyScalar2D, R as nearestPowerOfTwo, aY as negInf, a8 as nextCombination, n as norm, al as norm2D, l as normalize, Q as normalize2D, aC as orthogonalize3x3, ae as outer, ak as outer2D, q as perpendiculars, aV as pointIsWithinBounds, af as projectVector, ah as projectVector2D, ay as quaternionToMatrix3x3, r as radiansFromDegrees, x as random, a9 as randomSeed, M as rgb2hsv, N as rgb2lab, aO as rgb2xyz, P as round, az as roundNumber, b as roundVector, z as rowsToMat3, am as rowsToMat4, Y as signedAngleBetweenVectors, aE as singularValueDecomposition3x3, aW as solve3PointCircle, aJ as solveHomogeneousLeastSquares, aK as solveLeastSquares, g as solveLinearSystem, s as subtract, at as transpose3x3, u as uninitializeBounds, aN as xyz2lab, C as xyz2rgb } from './Math/index.js';
4
+ export { ar as LUFactor3x3, as as LUSolve3x3, a0 as Pi, k as add, Z as angleBetweenVectors, W as areBoundsInitialized, E as areEquals, a as areMatricesEqual, a5 as arrayMax, a4 as arrayMin, G as arrayRange, a9 as beginCombination, a8 as binomial, aV as boundsIsWithinOtherBounds, a1 as ceil, a6 as ceilLog2, aR as clampAndNormalizeValue, F as clampValue, c as clampVector, aq as columnsToMat3, ap as columnsToMat4, aQ as computeBoundsFromPoints, $ as createArray, I as createUninitializedBounds, j as cross, f as default, B as degreesFromRadians, o as determinant2x2, z as determinant3x3, aF as diagonalize3x3, e as distance2BetweenPoints, d as dot, ai as dot2D, aJ as estimateMatrixCondition, aU as extentIsWithinOtherExtent, a7 as factorial, b1 as float2CssRGBA, X as floatRGB2HexCode, b0 as floatToHex2, M as floor, ad as gaussian, ak as gaussianAmplitude, al as gaussianWeight, aT as getAdjustedScalarRange, H as getMajorAxisIndex, aS as getScalarTypeFittingRange, ac as getSeed, V as getSparseOrthogonalMatrix, aM as hex2float, h as hsv2rgb, K as identity, ax as identity3x3, aY as inf, aw as invert3x3, p as invertMatrix, a_ as isFinite, ay as isIdentity, az as isIdentity3x3, N as isInf, a$ as isNaN, i as isNan, Y as isPowerOfTwo, w as jacobi, q as jacobiN, Q as lab2rgb, aN as lab2xyz, C as ldexp, at as linearSolve3x3, aH as luFactorLinearSystem, aI as luSolveLinearSystem, aC as matrix3x3ToQuaternion, a3 as max, a2 as min, au as multiply3x3_mat3, U as multiply3x3_vect3, m as multiplyAccumulate, af as multiplyAccumulate2D, L as multiplyMatrix, aD as multiplyQuaternion, x as multiplyScalar, ae as multiplyScalar2D, T as nearestPowerOfTwo, aZ as negInf, aa as nextCombination, n as norm, an as norm2D, l as normalize, S as normalize2D, J as normalize4D, aE as orthogonalize3x3, ag as outer, am as outer2D, t as perpendiculars, aW as pointIsWithinBounds, ah as projectVector, aj as projectVector2D, aA as quaternionToMatrix3x3, r as radiansFromDegrees, y as random, ab as randomSeed, O as rgb2hsv, P as rgb2lab, aP as rgb2xyz, R as round, aB as roundNumber, b as roundVector, A as rowsToMat3, ao as rowsToMat4, _ as signedAngleBetweenVectors, aG as singularValueDecomposition3x3, aX as solve3PointCircle, aK as solveHomogeneousLeastSquares, aL as solveLeastSquares, g as solveLinearSystem, s as subtract, av as transpose3x3, u as uninitializeBounds, aO as xyz2lab, D as xyz2rgb } from './Math/index.js';
@@ -1,4 +1,4 @@
1
- import { Vector3 } from './../../types';
1
+ import { Vector2, Vector3 } from './../../types';
2
2
  import vtkCell, { ICellInitialValues } from './Cell';
3
3
 
4
4
  export interface ITriangleInitialValues extends ICellInitialValues {}
@@ -11,6 +11,14 @@ export interface IIntersectWithLine {
11
11
  betweenPoints?: boolean;
12
12
  }
13
13
 
14
+ export interface IIntersectWithTriangle {
15
+ intersect: boolean;
16
+ coplanar: boolean;
17
+ pt1: Vector3;
18
+ pt2: Vector3;
19
+ surfaceId: number;
20
+ }
21
+
14
22
  export interface vtkTriangle extends vtkCell {
15
23
  /**
16
24
  * Get the topological dimensional of the cell (0, 1, 2 or 3).
@@ -48,23 +56,36 @@ export interface vtkTriangle extends vtkCell {
48
56
  ): IIntersectWithLine;
49
57
 
50
58
  /**
51
- * Evaluate the position of x in relation with triangle.
52
- *
53
- * Compute the closest point in the cell.
54
- * - pccords parametric coordinate (computed in function)
55
- * - weights Interpolation weights in cell.
56
- * - the number of weights is equal to the number of points defining the
57
- * cell (computed in function).
58
- *
59
- * A javascript object is returned :
60
- *
61
- * ```js
62
- * {
63
- * evaluation: 1 = inside 0 = outside -1 = problem during execution
64
- * subId: always set to 0
65
- * dist2: squared distance from x to cell
66
- * }
67
- * ```
59
+ * Get the nearest cell boundary to the specified parametric
60
+ * coordinates and whether the point is inside or outside the cell.
61
+ * @param {Number} subId The sub-id of the cell.
62
+ * @param {Vector3} pcoords The parametric coordinates.
63
+ * @param {Vector2} pts The points of the cell.
64
+ */
65
+ cellBoundary(subId: number, pcoords: Vector3, pts: Vector2): boolean;
66
+
67
+ /**
68
+ * Get the derivatives of the triangle at the specified parametric
69
+ * coordinates.
70
+ * @param {Number} subId - The sub-id of the triangle.
71
+ * @param {Vector3} pcoords - The parametric coordinates.
72
+ * @param {Number[]} values - The values at the points.
73
+ * @param {Number} dim - The dimension.
74
+ * @param {Number[]} derivs - The derivatives.
75
+ */
76
+ derivatives(
77
+ subId: number,
78
+ pcoords: Vector3,
79
+ values: any,
80
+ dim: number,
81
+ derivs: number[]
82
+ ): void;
83
+
84
+ /**
85
+ * Evaluates whether the specified point is inside (1), outside (0), or
86
+ * indeterminate (-1) for the cell; computes parametric coordinates, sub-cell
87
+ * ID (if applicable), squared distance to the cell (and closest point if
88
+ * requested), and interpolation weights for the cell.
68
89
  *
69
90
  * @param {Vector3} x The x point coordinate.
70
91
  * @param {Vector3} closestPoint The closest point coordinate.
@@ -79,7 +100,8 @@ export interface vtkTriangle extends vtkCell {
79
100
  ): IIntersectWithLine;
80
101
 
81
102
  /**
82
- * Determine global coordinate (x]) from subId and parametric coordinates.
103
+ * Determine global coordinates (x) from the given subId and parametric
104
+ * coordinates.
83
105
  * @param {Vector3} pcoords The parametric coordinates.
84
106
  * @param {Vector3} x The x point coordinate.
85
107
  * @param {Number[]} weights The number of weights.
@@ -144,6 +166,31 @@ export function computeNormal(
144
166
  n: Vector3
145
167
  ): void;
146
168
 
169
+ /**
170
+ * Compute the interpolation functions/derivatives
171
+ * @param {Number[]} derivs - The derivatives.
172
+ */
173
+ export function interpolationDerivs(derivs: number[]): void;
174
+
175
+ /**
176
+ * Compute the intersection between two triangles.
177
+ * @param {Vector3} p1 The first point coordinate of the first triangle.
178
+ * @param {Vector3} q1 The second point coordinate of the first triangle.
179
+ * @param {Vector3} r1 The third point coordinate of the first triangle.
180
+ * @param {Vector3} p2 The first point coordinate of the second triangle.
181
+ * @param {Vector3} q2 The second point coordinate of the second triangle.
182
+ * @param {Vector3} r2 The third point coordinate of the second triangle.
183
+ */
184
+ export function intersectWithTriangle(
185
+ p1: Vector3,
186
+ q1: Vector3,
187
+ r1: Vector3,
188
+ p2: Vector3,
189
+ q2: Vector3,
190
+ r2: Vector3,
191
+ tolerance?: number
192
+ ): IIntersectWithTriangle;
193
+
147
194
  /**
148
195
  * vtkTriangle is a cell which representant a triangle. It contains static
149
196
  * method to make some computations directly link to triangle.
@@ -155,5 +202,7 @@ export declare const vtkTriangle: {
155
202
  extend: typeof extend;
156
203
  computeNormalDirection: typeof computeNormalDirection;
157
204
  computeNormal: typeof computeNormal;
205
+ interpolationDerivs: typeof interpolationDerivs;
206
+ intersectWithTriangle: typeof intersectWithTriangle;
158
207
  };
159
208
  export default vtkTriangle;
@@ -1,6 +1,6 @@
1
- import { m as macro } from '../../macros2.js';
1
+ import { m as macro, T as TYPED_ARRAYS } from '../../macros2.js';
2
2
  import vtkCell from './Cell.js';
3
- import { d as dot, j as cross, l as normalize, m as multiplyAccumulate, e as distance2BetweenPoints, o as determinant2x2 } from '../Core/Math/index.js';
3
+ import { d as dot, j as cross, l as normalize, m as multiplyAccumulate, e as distance2BetweenPoints, o as determinant2x2, s as subtract, p as invertMatrix } from '../Core/Math/index.js';
4
4
  import vtkLine from './Line.js';
5
5
  import vtkPlane from './Plane.js';
6
6
 
@@ -29,6 +29,18 @@ function computeNormal(v1, v2, v3, n) {
29
29
  n[2] /= length;
30
30
  }
31
31
  }
32
+ function interpolationDerivs(derivs) {
33
+ // Order: [dN1/dr, dN2/dr, dN3/dr, dN1/ds, dN2/ds, dN3/ds]
34
+ // r-derivatives
35
+ derivs[0] = -1.0;
36
+ derivs[1] = 1.0;
37
+ derivs[2] = 0.0;
38
+
39
+ // s-derivatives
40
+ derivs[3] = -1.0;
41
+ derivs[4] = 0.0;
42
+ derivs[5] = 1.0;
43
+ }
32
44
  function intersectWithTriangle(p1, q1, r1, p2, q2, r2) {
33
45
  let tolerance = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : 1e-6;
34
46
  let coplanar = false;
@@ -242,6 +254,7 @@ function intersectWithTriangle(p1, q1, r1, p2, q2, r2) {
242
254
  const STATIC = {
243
255
  computeNormalDirection,
244
256
  computeNormal,
257
+ interpolationDerivs,
245
258
  intersectWithTriangle
246
259
  };
247
260
 
@@ -343,6 +356,18 @@ function vtkTriangle(publicAPI, model) {
343
356
  outObj.intersect = 0;
344
357
  return outObj;
345
358
  };
359
+
360
+ /**
361
+ * Evaluates whether the specified point is inside (1), outside (0), or
362
+ * indeterminate (-1) for the cell; computes parametric coordinates, sub-cell
363
+ * ID (if applicable), squared distance to the cell (and closest point if
364
+ * requested), and interpolation weights for the cell.
365
+ *
366
+ * @param {Vector3} x The x point coordinate.
367
+ * @param {Vector3} closestPoint The closest point coordinate.
368
+ * @param {Vector3} pcoords The parametric coordinates.
369
+ * @param {Number[]} weights The number of weights.
370
+ */
346
371
  publicAPI.evaluatePosition = (x, closestPoint, pcoords, weights) => {
347
372
  // will return obj
348
373
  const outObj = {
@@ -505,6 +530,14 @@ function vtkTriangle(publicAPI, model) {
505
530
  }
506
531
  return outObj;
507
532
  };
533
+
534
+ /**
535
+ * Determine global coordinates (x) from the given subId and parametric
536
+ * coordinates.
537
+ * @param {Vector3} pcoords The parametric coordinates.
538
+ * @param {Vector3} x The x point coordinate.
539
+ * @param {Number[]} weights The number of weights.
540
+ */
508
541
  publicAPI.evaluateLocation = (pcoords, x, weights) => {
509
542
  const p0 = [];
510
543
  const p1 = [];
@@ -520,6 +553,11 @@ function vtkTriangle(publicAPI, model) {
520
553
  weights[1] = pcoords[0];
521
554
  weights[2] = pcoords[1];
522
555
  };
556
+
557
+ /**
558
+ * Get the distance of the parametric coordinate provided to the cell.
559
+ * @param {Vector3} pcoords The parametric coordinates.
560
+ */
523
561
  publicAPI.getParametricDistance = pcoords => {
524
562
  let pDist;
525
563
  let pDistMax = 0.0;
@@ -542,6 +580,102 @@ function vtkTriangle(publicAPI, model) {
542
580
  }
543
581
  return pDistMax;
544
582
  };
583
+
584
+ /**
585
+ * Get the derivatives of the triangle strip.
586
+ * @param {Number} subId - The sub-id of the triangle.
587
+ * @param {Vector3} pcoords - The parametric coordinates.
588
+ * @param {Number[]} values - The values at the points.
589
+ * @param {Number} dim - The dimension.
590
+ * @param {Number[]} derivs - The derivatives.
591
+ */
592
+ publicAPI.derivatives = (subId, pcoords, values, dim, derivs) => {
593
+ const x0 = model.points.getPoint(0);
594
+ const x1 = model.points.getPoint(1);
595
+ const x2 = model.points.getPoint(2);
596
+ const n = [];
597
+ const v10 = [];
598
+ const v20 = [];
599
+ const v = [];
600
+ computeNormal(x0, x1, x2, n);
601
+ subtract(x1, x0, v10);
602
+ subtract(x2, x0, v);
603
+ cross(n, v10, v20);
604
+ const lenX = normalize(v10); // check for degenerate triangle
605
+
606
+ if (lenX <= 0.0 || normalize(v20) <= 0.0) {
607
+ // degenerate
608
+ for (let j = 0; j < dim; j++) {
609
+ for (let i = 0; i < 3; i++) {
610
+ derivs[j * dim + i] = 0.0;
611
+ }
612
+ }
613
+ return;
614
+ }
615
+
616
+ // 2D coordinates
617
+ const v0 = [0, 0];
618
+ const v1 = [lenX, 0];
619
+ const v2 = [dot(v, v10), dot(v, v20)];
620
+ const functionDerivs = new Array(6);
621
+ interpolationDerivs(functionDerivs);
622
+
623
+ // Compute Jacobian: Jacobian is constant for a triangle.
624
+ const J = [v1[0] - v0[0], v1[1] - v0[1], v2[0] - v0[0], v2[1] - v0[1]];
625
+
626
+ // Compute inverse Jacobian (expects flat array)
627
+ const JI = macro.newTypedArray(TYPED_ARRAYS.Float64Array, 4);
628
+ invertMatrix(J, JI, 2); // returns flat array [JI00, JI01, JI10, JI11]
629
+
630
+ // Compute derivatives
631
+ for (let j = 0; j < dim; j++) {
632
+ let sum0 = 0.0;
633
+ let sum1 = 0.0;
634
+ for (let i = 0; i < 3; i++) {
635
+ sum0 += functionDerivs[i] * values[dim * i + j];
636
+ sum1 += functionDerivs[3 + i] * values[dim * i + j];
637
+ }
638
+ const dBydx = sum0 * JI[0] + sum1 * JI[1];
639
+ const dBydy = sum0 * JI[2] + sum1 * JI[3];
640
+
641
+ // Transform into global system (dot product with global axes)
642
+ derivs[3 * j] = dBydx * v10[0] + dBydy * v20[0];
643
+ derivs[3 * j + 1] = dBydx * v10[1] + dBydy * v20[1];
644
+ derivs[3 * j + 2] = dBydx * v10[2] + dBydy * v20[2];
645
+ }
646
+ };
647
+
648
+ /**
649
+ * Get the nearest cell boundary to the specified parametric
650
+ * coordinates and whether the point is inside or outside the cell.
651
+ * @param {Number} subId The sub-id of the cell.
652
+ * @param {Vector3} pcoords The parametric coordinates.
653
+ * @param {Vector2} pts The points of the cell.
654
+ */
655
+ publicAPI.cellBoundary = (subId, pcoords, pts) => {
656
+ const t1 = pcoords[0] - pcoords[1];
657
+ const t2 = 0.5 * (1.0 - pcoords[0]) - pcoords[1];
658
+ const t3 = 2.0 * pcoords[0] + pcoords[1] - 1.0;
659
+
660
+ // compare against three lines in parametric space that divide element
661
+ // into three pieces
662
+ if (t1 >= 0.0 && t2 >= 0.0) {
663
+ pts[0] = model.pointsIds[0];
664
+ pts[1] = model.pointsIds[1];
665
+ } else if (t2 < 0.0 && t3 >= 0.0) {
666
+ pts[0] = model.pointsIds[1];
667
+ pts[1] = model.pointsIds[2];
668
+ } // ( t1 < 0.0 && t3 < 0.0 )
669
+ else {
670
+ pts[0] = model.pointsIds[2];
671
+ pts[1] = model.pointsIds[0];
672
+ }
673
+ if (pcoords[0] < 0.0 || pcoords[1] < 0.0 || pcoords[0] > 1.0 || pcoords[1] > 1.0 || 1.0 - pcoords[0] - pcoords[1] < 0.0) {
674
+ return false; // outside of triangle
675
+ }
676
+
677
+ return true; // inside triangle
678
+ };
545
679
  }
546
680
 
547
681
  // ----------------------------------------------------------------------------