@kitware/vtk.js 21.3.0 → 21.5.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.
@@ -1,5 +1,4 @@
1
- import { mat2, mat3, vec2, vec3, vec4 } from "gl-matrix";
2
- import { Bounds, Extent, RGBAColor, RGBColor } from '@kitware/vtk.js/types';
1
+ import { Bounds, Extent, HSVColor, RGBAColor, RGBColor, Matrix, Matrix3x3, Range, Vector2, Vector3, Vector4 } from '@kitware/vtk.js/types';
3
2
 
4
3
  /**
5
4
  *
@@ -156,102 +155,102 @@ export function random(minValue: number, maxValue: number): number;
156
155
 
157
156
  /**
158
157
  * Addition of two 3-vectors.
159
- * @param {vec3} a The first 3D vector.
160
- * @param {vec3} b The second 3D vector.
161
- * @param {vec3} out The output 3D vector.
158
+ * @param {Vector3} a The first 3D vector.
159
+ * @param {Vector3} b The second 3D vector.
160
+ * @param {Vector3} out The output 3D vector.
162
161
  * @example
163
162
  * ```js
164
163
  * a[3] + b[3] => out[3]
165
164
  * ```
166
165
  */
167
- export function add(a: vec3, b: vec3, out: vec3): vec3;
166
+ export function add(a: Vector3, b: Vector3, out: Vector3): Vector3;
168
167
 
169
168
  /**
170
169
  * Subtraction of two 3-vectors.
171
- * @param {vec3} a The first 3D vector.
172
- * @param {vec3} b The second 3D vector.
173
- * @param {vec3} out The output 3D vector.
170
+ * @param {Vector3} a The first 3D vector.
171
+ * @param {Vector3} b The second 3D vector.
172
+ * @param {Vector3} out The output 3D vector.
174
173
  * @example
175
174
  * ```js
176
175
  * a[3] - b[3] => out[3]
177
176
  * ```
178
177
  */
179
- export function subtract(a: vec3, b: vec3, out: vec3): vec3;
178
+ export function subtract(a: Vector3, b: Vector3, out: Vector3): Vector3;
180
179
 
181
180
  /**
182
181
  *
183
- * @param {vec3} vec
182
+ * @param {Vector3} vec
184
183
  * @param {Number} scalar
185
184
  * @example
186
185
  * ```js
187
186
  * vec[3] * scalar => vec[3]
188
187
  * ```
189
188
  */
190
- export function multiplyScalar(vec: vec3, scalar: number): vec3;
189
+ export function multiplyScalar(vec: Vector3, scalar: number): Vector3;
191
190
 
192
191
  /**
193
192
  *
194
- * @param {vec2} vec
193
+ * @param {Vector2} vec
195
194
  * @param {Number} scalar
196
195
  * @example
197
196
  * ```js
198
197
  * vec[3] * scalar => vec[3]
199
198
  * ```
200
199
  */
201
- export function multiplyScalar2D(vec: vec2, scalar: number): vec2;
200
+ export function multiplyScalar2D(vec: Vector2, scalar: number): Vector2;
202
201
 
203
202
  /**
204
203
  *
205
- * @param {vec3} a
206
- * @param {vec3} b
204
+ * @param {Vector3} a
205
+ * @param {Vector3} b
207
206
  * @param {Number} scalar
208
- * @param {vec3} out
207
+ * @param {Vector3} out
209
208
  * @example
210
209
  * ```js
211
210
  * a[3] + b[3] * scalar => out[3]
212
211
  * ```
213
212
  */
214
- export function multiplyAccumulate(a: vec3, b: vec3, scalar: number, out: vec3): vec3;
213
+ export function multiplyAccumulate(a: Vector3, b: Vector3, scalar: number, out: Vector3): Vector3;
215
214
 
216
215
  /**
217
216
  *
218
- * @param {vec2} a
219
- * @param {vec2} b
217
+ * @param {Vector2} a
218
+ * @param {Vector2} b
220
219
  * @param {Number} scalar
221
- * @param {vec2} out
220
+ * @param {Vector2} out
222
221
  * @example
223
222
  * ```js
224
223
  * a[2] + b[2] * scalar => out[2]
225
224
  * ```
226
225
  */
227
- export function multiplyAccumulate2D(a: vec2, b: vec2, scalar: number, out: vec2): vec2;
226
+ export function multiplyAccumulate2D(a: Vector2, b: Vector2, scalar: number, out: Vector2): Vector2;
228
227
 
229
228
  /**
230
229
  *
231
- * @param {vec3} x
232
- * @param {vec3} y
230
+ * @param {Vector3} x
231
+ * @param {Vector3} y
233
232
  * @example
234
233
  * ```js
235
234
  * a[2] + b[2] * scalar => out[2]
236
235
  * ```
237
236
  */
238
- export function dot(x: vec3, y: vec3): number;
237
+ export function dot(x: Vector3, y: Vector3): number;
239
238
 
240
239
  /**
241
240
  * Outer product of two 3-vectors.
242
- * @param {vec3} x The first 3D vector.
243
- * @param {vec3} y The second 3D vector.
244
- * @param {mat3} out_3x3 The output 3x3 matrix.
241
+ * @param {Vector3} x The first 3D vector.
242
+ * @param {Vector3} y The second 3D vector.
243
+ * @param {Matrix3x3} out_3x3 The output 3x3 matrix.
245
244
  */
246
- export function outer(x: vec3, y: vec3, out_3x3: mat3): void;
245
+ export function outer(x: Vector3, y: Vector3, out_3x3: Matrix3x3): void;
247
246
 
248
247
  /**
249
248
  * Computes cross product of 3D vectors x and y.
250
- * @param {vec3} x The first 3D vector.
251
- * @param {vec3} y The second 3D vector.
252
- * @param {vec3} out The output 3D vector.
249
+ * @param {Vector3} x The first 3D vector.
250
+ * @param {Vector3} y The second 3D vector.
251
+ * @param {Vector3} out The output 3D vector.
253
252
  */
254
- export function cross(x: vec3, y: vec3, out: vec3): vec3;
253
+ export function cross(x: Vector3, y: Vector3, out: Vector3): Vector3;
255
254
 
256
255
  /**
257
256
  *
@@ -262,56 +261,56 @@ export function norm(x: number[], n: number): number;
262
261
 
263
262
  /**
264
263
  * Normalize in place. Returns norm.
265
- * @param {vec3} x The vector to normlize.
264
+ * @param {Vector3} x The vector to normlize.
266
265
  */
267
- export function normalize(x: vec3): number;
266
+ export function normalize(x: Vector3): number;
268
267
 
269
268
  /**
270
269
  * Given a unit vector v1, find two unit vectors v2 and v3 such that v1 cross v2 = v3
271
- * @param {vec3} x The first vector.
272
- * @param {vec3} y The second vector.
273
- * @param {vec3} z The third vector.
270
+ * @param {Vector3} x The first vector.
271
+ * @param {Vector3} y The second vector.
272
+ * @param {Vector3} z The third vector.
274
273
  * @param {Number} theta
275
274
  */
276
- export function perpendiculars(x: vec3, y: vec3, z: vec3, theta: number): void;
275
+ export function perpendiculars(x: Vector3, y: Vector3, z: Vector3, theta: number): void;
277
276
 
278
277
  /**
279
278
  *
280
- * @param {vec3} a
281
- * @param {vec3} b
282
- * @param {vec3} projection
279
+ * @param {Vector3} a
280
+ * @param {Vector3} b
281
+ * @param {Vector3} projection
283
282
  */
284
- export function projectVector(a: vec3, b: vec3, projection: vec3): boolean;
283
+ export function projectVector(a: Vector3, b: Vector3, projection: Vector3): boolean;
285
284
 
286
285
  /**
287
286
  *
288
- * @param {vec2} x
289
- * @param {vec2} y
287
+ * @param {Vector2} x
288
+ * @param {Vector2} y
290
289
  */
291
- export function dot2D(x: vec2, y: vec2): number;
290
+ export function dot2D(x: Vector2, y: Vector2): number;
292
291
 
293
292
  /**
294
293
  * Compute the projection of 2D vector `a` on 2D vector `b` and returns the
295
294
  * result in projection vector.
296
- * @param {vec2} a The first 2D vector.
297
- * @param {vec2} b The second 2D vector.
298
- * @param {vec2} projection The projection 2D vector.
295
+ * @param {Vector2} a The first 2D vector.
296
+ * @param {Vector2} b The second 2D vector.
297
+ * @param {Vector2} projection The projection 2D vector.
299
298
  */
300
- export function projectVector2D(a: vec2, b: vec2, projection: vec2): boolean;
299
+ export function projectVector2D(a: Vector2, b: Vector2, projection: Vector2): boolean;
301
300
 
302
301
  /**
303
302
  * Compute distance squared between two points p1 and p2.
304
- * @param {vec3} x The first 3D vector.
305
- * @param {vec3} y The second 3D vector.
303
+ * @param {Vector3} x The first 3D vector.
304
+ * @param {Vector3} y The second 3D vector.
306
305
  */
307
- export function distance2BetweenPoints(x: vec3, y: vec3): number;
306
+ export function distance2BetweenPoints(x: Vector3, y: Vector3): number;
308
307
 
309
308
  /**
310
309
  * Angle between 3D vectors.
311
- * @param {vec3} v1 The first 3D vector.
312
- * @param {vec3} v2 The second 3D vector.
310
+ * @param {Vector3} v1 The first 3D vector.
311
+ * @param {Vector3} v2 The second 3D vector.
313
312
  */
314
- export function angleBetweenVectors(v1: vec3, v2: vec3): number;
313
+ export function angleBetweenVectors(v1: Vector3, v2: Vector3): number;
315
314
 
316
315
 
317
316
  /**
@@ -319,11 +318,11 @@ export function angleBetweenVectors(v1: vec3, v2: vec3): number;
319
318
  * angle between v1 and v2 with regards to plane defined by normal vN.Signed
320
319
  * angle between v1 and v2 with regards to plane defined by normal
321
320
  * vN.t3(mat_3x3, in_3, out_3)
322
- * @param {vec3} v1 The first 3D vector.
323
- * @param {vec3} v2 The second 3D vector.
324
- * @param {vec3} vN
321
+ * @param {Vector3} v1 The first 3D vector.
322
+ * @param {Vector3} v2 The second 3D vector.
323
+ * @param {Vector3} vN
325
324
  */
326
- export function signedAngleBetweenVectors(v1: vec3, v2: vec3, vN: vec3): number;
325
+ export function signedAngleBetweenVectors(v1: Vector3, v2: Vector3, vN: Vector3): number;
327
326
 
328
327
 
329
328
  /**
@@ -345,121 +344,121 @@ export function gaussianWeight(mean: number, variance: number, position: number)
345
344
 
346
345
  /**
347
346
  * Outer product of two 2-vectors.
348
- * @param {vec2} x The first 2D vector.
349
- * @param {vec2} y The second 2D vector.
350
- * @param {mat2} out_2x2 The output 2x2 matrix.
347
+ * @param {Vector2} x The first 2D vector.
348
+ * @param {Vector2} y The second 2D vector.
349
+ * @param {Matrix} out_2x2 The output 2x2 matrix.
351
350
  */
352
- export function outer2D(x: vec2, y: vec2, out_2x2: mat2): void;
351
+ export function outer2D(x: Vector2, y: Vector2, out_2x2: Matrix): void;
353
352
 
354
353
  /**
355
354
  * Compute the norm of a 2-vector.
356
- * @param {vec2} x2D x The 2D vector.
355
+ * @param {Vector2} x2D x The 2D vector.
357
356
  */
358
- export function norm2D(x2D: vec2): number;
357
+ export function norm2D(x2D: Vector2): number;
359
358
 
360
359
  /**
361
360
  * Normalize (in place) a 2-vector.
362
- * @param {vec2} x The 2D vector.
361
+ * @param {Vector2} x The 2D vector.
363
362
  */
364
- export function normalize2D(x: vec2): number;
363
+ export function normalize2D(x: Vector2): number;
365
364
 
366
365
  /**
367
366
  *
368
- * @param {Number[]} args
367
+ * @param {Number[][]|Number[]} args
369
368
  */
370
- export function determinant2x2(args: number[]): number;
369
+ export function determinant2x2(args: number[][]|number[]): number;
371
370
 
372
371
  /**
373
372
  * LU Factorization of a 3x3 matrix.
374
- * @param {mat3} mat_3x3
375
- * @param {vec3} index_3
373
+ * @param {Matrix3x3} mat_3x3
374
+ * @param {Vector3} index_3
376
375
  */
377
- export function LUFactor3x3(mat_3x3: mat3, index_3: vec3): void;
376
+ export function LUFactor3x3(mat_3x3: Matrix3x3, index_3: Vector3): void;
378
377
 
379
378
  /**
380
379
  * LU back substitution for a 3x3 matrix.
381
- * @param {mat3} mat_3x3
382
- * @param {vec3} index_3
383
- * @param {vec3} x_3
380
+ * @param {Matrix3x3} mat_3x3
381
+ * @param {Vector3} index_3
382
+ * @param {Vector3} x_3
384
383
  */
385
- export function LUSolve3x3(mat_3x3: mat3, index_3: vec3, x_3: vec3): void;
384
+ export function LUSolve3x3(mat_3x3: Matrix3x3, index_3: Vector3, x_3: Vector3): void;
386
385
 
387
386
  /**
388
387
  * Solve mat_3x3y_3 = x_3 for y and place the result in y.
389
- * @param {mat3} mat_3x3
390
- * @param {vec3} x_3
391
- * @param {vec3} y_3
388
+ * @param {Matrix3x3} mat_3x3
389
+ * @param {Vector3} x_3
390
+ * @param {Vector3} y_3
392
391
  */
393
- export function linearSolve3x3(mat_3x3: mat3, x_3: vec3, y_3: vec3): void;
392
+ export function linearSolve3x3(mat_3x3: Matrix3x3, x_3: Vector3, y_3: Vector3): void;
394
393
 
395
394
  /**
396
395
  *
397
- * @param {mat3} mat_3x3
398
- * @param {vec3} in_3
399
- * @param {vec3} out_3
396
+ * @param {Matrix3x3} mat_3x3
397
+ * @param {Vector3} in_3
398
+ * @param {Vector3} out_3
400
399
  */
401
- export function multiply3x3_vect3(mat_3x3: mat3, in_3: vec3, out_3: vec3): void;
400
+ export function multiply3x3_vect3(mat_3x3: Matrix3x3, in_3: Vector3, out_3: Vector3): void;
402
401
 
403
402
  /**
404
403
  *
405
- * @param {mat3} a_3x3
406
- * @param {mat3} b_3x3
407
- * @param {mat3} out_3x3
404
+ * @param {Matrix3x3} a_3x3
405
+ * @param {Matrix3x3} b_3x3
406
+ * @param {Matrix3x3} out_3x3
408
407
  */
409
- export function multiply3x3_mat3(a_3x3: mat3, b_3x3: mat3, out_3x3: mat3): void;
408
+ export function multiply3x3_mat3(a_3x3: Matrix3x3, b_3x3: Matrix3x3, out_3x3: Matrix3x3): void;
410
409
 
411
410
  /**
412
- *
413
- * @param {Number[]} a
414
- * @param {Number[]} b
411
+ * Multiply two matrices.
412
+ * @param {Matrix} a
413
+ * @param {Matrix} b
415
414
  * @param {Number} rowA
416
415
  * @param {Number} colA
417
416
  * @param {Number} rowB
418
417
  * @param {Number} colB
419
- * @param {Number[]} out_rowXcol
418
+ * @param {Matrix} out_rowXcol
420
419
  */
421
- export function multiplyMatrix(a: number[], b: number[], rowA: number, colA: number, rowB: number, colB: number, out_rowXcol: number[]): void;
420
+ export function multiplyMatrix(a: Matrix, b: Matrix, rowA: number, colA: number, rowB: number, colB: number, out_rowXcol: Matrix): void;
422
421
 
423
422
  /**
424
423
  * Transpose a 3x3 matrix.
425
- * @param {mat3} in_3x3 The input 3x3 matrix.
426
- * @param {mat3} outT_3x3 The output 3x3 matrix.
424
+ * @param {Matrix3x3} in_3x3 The input 3x3 matrix.
425
+ * @param {Matrix3x3} outT_3x3 The output 3x3 matrix.
427
426
  */
428
- export function transpose3x3(in_3x3: mat3, outT_3x3: mat3): void;
427
+ export function transpose3x3(in_3x3: Matrix3x3, outT_3x3: Matrix3x3): void;
429
428
 
430
429
  /**
431
430
  * Invert a 3x3 matrix.
432
- * @param {mat3} in_3x3 The input 3x3 matrix.
433
- * @param {mat3} outI_3x3 The output 3x3 matrix.
431
+ * @param {Matrix3x3} in_3x3 The input 3x3 matrix.
432
+ * @param {Matrix3x3} outI_3x3 The output 3x3 matrix.
434
433
  */
435
- export function invert3x3(in_3x3: mat3, outI_3x3: mat3): void;
434
+ export function invert3x3(in_3x3: Matrix3x3, outI_3x3: Matrix3x3): void;
436
435
 
437
436
  /**
438
437
  * Set mat_3x3 to the identity matrix.
439
- * @param {mat3} mat_3x3 The input 3x3 matrix.
438
+ * @param {Matrix3x3} mat_3x3 The input 3x3 matrix.
440
439
  */
441
- export function identity3x3(mat_3x3: mat3): void;
440
+ export function identity3x3(mat_3x3: Matrix3x3): void;
442
441
 
443
442
  /**
444
443
  * Calculate the determinant of a 3x3 matrix.
445
- * @param {mat3} mat_3x3 The input 3x3 matrix.
444
+ * @param {Matrix3x3} mat_3x3 The input 3x3 matrix.
446
445
  */
447
- export function determinant3x3(mat_3x3: mat3): number;
446
+ export function determinant3x3(mat_3x3: Matrix3x3): number;
448
447
 
449
448
  /**
450
449
  *
451
- * @param {vec4} quat_4
452
- * @param {mat3} mat_3x3
450
+ * @param {Vector4} quat_4
451
+ * @param {Matrix3x3} mat_3x3
453
452
  */
454
- export function quaternionToMatrix3x3(quat_4: vec4, mat_3x3: mat3): void;
453
+ export function quaternionToMatrix3x3(quat_4: Vector4, mat_3x3: Matrix3x3): void;
455
454
 
456
455
  /**
457
- *
458
- * @param {Number[]} a
459
- * @param {Number[]} b
460
- * @param {Number} eps
456
+ * Returns true if elements of both arrays are equals.
457
+ * @param {Number[]} a An array of numbers (vector, point, matrix...)
458
+ * @param {Number[]} b An array of numbers (vector, point, matrix...)
459
+ * @param {Number} [eps] The tolerance value.
461
460
  */
462
- export function areEquals(a: number[], b: number[], eps: number): boolean;
461
+ export function areEquals(a: number[], b: number[], eps?: number): boolean;
463
462
 
464
463
  /**
465
464
  *
@@ -470,213 +469,229 @@ export function roundNumber(num: number, digits?: number): number;
470
469
 
471
470
  /**
472
471
  *
473
- * @param {vec3} vector
474
- * @param {vec3} [out]
472
+ * @param {Vector3} vector
473
+ * @param {Vector3} [out]
475
474
  * @param {Number} [digits]
476
475
  */
477
- export function roundVector(vector: vec3, out?: vec3, digits?: number): vec3;
476
+ export function roundVector(vector: Vector3, out?: Vector3, digits?: number): Vector3;
478
477
 
479
478
  /**
480
479
  *
481
- * @param {Number[]} a
480
+ * @param {Matrix} a
482
481
  * @param {Number} n
483
482
  * @param {Number[]} w
484
483
  * @param {Number[]} v
485
484
  */
486
- export function jacobiN(a: number[], n: number, w: number[], v: number[]): number;
485
+ export function jacobiN(a: Matrix, n: number, w: number[], v: number[]): number;
487
486
 
488
487
  /**
489
488
  *
490
- * @param {mat3} mat_3x3
491
- * @param {vec4} quat_4
489
+ * @param {Matrix3x3} mat_3x3
490
+ * @param {Vector4} quat_4
492
491
  */
493
- export function matrix3x3ToQuaternion(mat_3x3: mat3, quat_4: vec4): void;
492
+ export function matrix3x3ToQuaternion(mat_3x3: Matrix3x3, quat_4: Vector4): void;
494
493
 
495
494
  /**
496
495
  *
497
- * @param {vec4} quat_1
498
- * @param {vec4} quat_2
499
- * @param {vec4} quat_out
496
+ * @param {Vector4} quat_1
497
+ * @param {Vector4} quat_2
498
+ * @param {Vector4} quat_out
500
499
  */
501
- export function multiplyQuaternion(quat_1: vec4, quat_2: vec4, quat_out: vec4): void;
500
+ export function multiplyQuaternion(quat_1: Vector4, quat_2: Vector4, quat_out: Vector4): void;
502
501
 
503
502
  /**
504
503
  *
505
- * @param {mat3} a_3x3
506
- * @param {mat3} out_3x3
504
+ * @param {Matrix3x3} a_3x3
505
+ * @param {Matrix3x3} out_3x3
507
506
  */
508
- export function orthogonalize3x3(a_3x3: mat3, out_3x3: mat3): void;
507
+ export function orthogonalize3x3(a_3x3: Matrix3x3, out_3x3: Matrix3x3): void;
509
508
 
510
509
  /**
511
510
  *
512
- * @param {mat3} a_3x3
513
- * @param {vec3} w_3
514
- * @param {mat3} v_3x3
511
+ * @param {Matrix3x3} a_3x3
512
+ * @param {Vector3} w_3
513
+ * @param {Matrix3x3} v_3x3
515
514
  */
516
- export function diagonalize3x3(a_3x3: mat3, w_3: vec3, v_3x3: mat3): void;
515
+ export function diagonalize3x3(a_3x3: Matrix3x3, w_3: Vector3, v_3x3: Matrix3x3): void;
517
516
 
518
517
  /**
519
518
  *
520
- * @param {mat3} a_3x3
521
- * @param {mat3} u_3x3
522
- * @param {vec3} w_3
523
- * @param {mat3} vT_3x3
519
+ * @param {Matrix3x3} a_3x3
520
+ * @param {Matrix3x3} u_3x3
521
+ * @param {Vector3} w_3
522
+ * @param {Matrix3x3} vT_3x3
524
523
  */
525
- export function singularValueDecomposition3x3(a_3x3: mat3, u_3x3: mat3, w_3: vec3, vT_3x3: mat3): void;
524
+ export function singularValueDecomposition3x3(a_3x3: Matrix3x3, u_3x3: Matrix3x3, w_3: Vector3, vT_3x3: Matrix3x3): void;
526
525
 
527
526
  /**
528
527
  *
529
- * @param {Number[]} A
528
+ * @param {Matrix} A
530
529
  * @param {Number[]} index
531
530
  * @param {Number} size
532
531
  */
533
- export function luFactorLinearSystem(A: number[], index: number[], size: number): number;
532
+ export function luFactorLinearSystem(A: Matrix, index: number[], size: number): number;
534
533
 
535
534
  /**
536
535
  *
537
- * @param {Number[]} A
536
+ * @param {Matrix} A
538
537
  * @param {Number[]} index
539
538
  * @param {Number[]} x
540
539
  * @param {Number} size
541
540
  */
542
- export function luSolveLinearSystem(A: number[], index: number[], x: number[], size: number): void;
541
+ export function luSolveLinearSystem(A: Matrix, index: number[], x: number[], size: number): void;
543
542
 
544
543
  /**
545
544
  *
546
- * @param {Number[]} A
545
+ * @param {Matrix} A
547
546
  * @param {Number[]} x
548
547
  * @param {Number} size
549
548
  */
550
- export function solveLinearSystem(A: number[], x: number[], size: number): number;
549
+ export function solveLinearSystem(A: Matrix, x: number[], size: number): number;
551
550
 
552
551
  /**
553
552
  *
554
- * @param {Number[]} A
555
- * @param {Number[]} AI
556
- * @param {Number} size
557
- * @param {?} [index]
558
- * @param {?} [column]
553
+ * @param {Matrix} A
554
+ * @param {Matrix} AI
555
+ * @param {Number} [size]
556
+ * @param {Number[]} [index]
557
+ * @param {Number[]} [column]
559
558
  */
560
- export function invertMatrix(A: number[], AI: number[], size: number, index?: any, column?: any): number;
559
+ export function invertMatrix(A: Matrix, AI: Matrix, size?: number, index?: number[], column?: number[]): number;
561
560
 
562
561
  /**
563
562
  *
564
- * @param {Number[]} A
563
+ * @param {Matrix} A
565
564
  * @param {Number} size
566
565
  */
567
- export function estimateMatrixCondition(A: number[], size: number): number;
566
+ export function estimateMatrixCondition(A: Matrix, size: number): number;
568
567
 
569
568
  /**
570
569
  *
571
- * @param {mat3} a_3x3
570
+ * @param {Matrix3x3} a_3x3
572
571
  * @param {Number[]} w
573
572
  * @param {Number[]} v
574
573
  */
575
- export function jacobi(a_3x3: mat3, w: number[], v: number[]): number;
574
+ export function jacobi(a_3x3: Matrix3x3, w: number[], v: number[]): number;
576
575
 
577
576
  /**
578
- *
577
+ * Solves for the least squares best fit matrix for the homogeneous equation
578
+ * X'M' = 0'. Uses the method described on pages 40-41 of Computer Vision by
579
+ * Forsyth and Ponce, which is that the solution is the eigenvector associated
580
+ * with the minimum eigenvalue of T(X)X, where T(X) is the transpose of X. The
581
+ * inputs and output are transposed matrices. Dimensions: X' is numberOfSamples
582
+ * by xOrder, M' dimension is xOrder by yOrder. M' should be pre-allocated. All
583
+ * matrices are row major. The resultant matrix M' should be pre-multiplied to
584
+ * X' to get 0', or transposed and then post multiplied to X to get 0
579
585
  * @param {Number} numberOfSamples
580
- * @param {Number[]} xt
586
+ * @param {Matrix} xt
581
587
  * @param {Number} xOrder
582
- * @param {Number[]} mt
588
+ * @param {Matrix} mt
583
589
  */
584
- export function solveHomogeneousLeastSquares(numberOfSamples: number, xt: number[], xOrder: number, mt: number[]): number;
590
+ export function solveHomogeneousLeastSquares(numberOfSamples: number, xt: Matrix, xOrder: number, mt: Matrix): number;
585
591
 
586
592
  /**
587
- *
593
+ * Solves for the least squares best fit matrix for the equation X'M' = Y'. Uses
594
+ * pseudoinverse to get the ordinary least squares. The inputs and output are
595
+ * transposed matrices. Dimensions: X' is numberOfSamples by xOrder, Y' is
596
+ * numberOfSamples by yOrder, M' dimension is xOrder by yOrder. M' should be
597
+ * pre-allocated. All matrices are row major. The resultant matrix M' should be
598
+ * pre-multiplied to X' to get Y', or transposed and then post multiplied to X
599
+ * to get Y By default, this method checks for the homogeneous condition where
600
+ * Y==0, and if so, invokes SolveHomogeneousLeastSquares. For better performance
601
+ * when the system is known not to be homogeneous, invoke with
602
+ * checkHomogeneous=0.
588
603
  * @param {Number} numberOfSamples
589
- * @param {Number[]} xt
604
+ * @param {Matrix} xt
590
605
  * @param {Number} xOrder
591
- * @param {Number[]} yt
606
+ * @param {Matrix} yt
592
607
  * @param {Number} yOrder
593
- * @param {Number[]} mt
594
- * @param {Boolean} checkHomogeneous
608
+ * @param {Matrix} mt
609
+ * @param {Boolean} [checkHomogeneous]
595
610
  */
596
- export function solveLeastSquares(numberOfSamples: number, xt: number[], xOrder: number, yt: number[], yOrder: number, mt: number[], checkHomogeneous: boolean): number;
611
+ export function solveLeastSquares(numberOfSamples: number, xt: Matrix, xOrder: number, yt: Matrix, yOrder: number, mt: Matrix, checkHomogeneous?: boolean): number;
597
612
 
598
613
  /**
599
614
  *
600
615
  * @param {String} hexStr
601
- * @param {Number[]} outFloatArray
616
+ * @param {Number[]} [outFloatArray]
602
617
  */
603
- export function hex2float(hexStr: string, outFloatArray: number[]): number[];
618
+ export function hex2float(hexStr: string, outFloatArray?: number[]): number[];
604
619
 
605
620
  /**
606
621
  *
607
- * @param {vec3} rgb An Array of the RGB color.
608
- * @param {vec3} hsv An Array of the HSV color.
622
+ * @param {RGBColor} rgb An Array of the RGB color.
623
+ * @param {HSVColor} hsv An Array of the HSV color.
609
624
  */
610
- export function rgb2hsv(rgb: vec3, hsv: vec3): void;
625
+ export function rgb2hsv(rgb: RGBColor, hsv: HSVColor): void;
611
626
 
612
627
  /**
613
628
  *
614
- * @param {vec3} hsv An Array of the HSV color.
615
- * @param {vec3} rgb An Array of the RGB color.
629
+ * @param {HSVColor} hsv An Array of the HSV color.
630
+ * @param {RGBColor} rgb An Array of the RGB color.
616
631
  */
617
- export function hsv2rgb(hsv: vec3, rgb: vec3): void;
632
+ export function hsv2rgb(hsv: HSVColor, rgb: RGBColor): void;
618
633
 
619
634
  /**
620
635
  *
621
- * @param {vec3} lab
622
- * @param {vec3} xyz
636
+ * @param {Vector3} lab
637
+ * @param {Vector3} xyz
623
638
  */
624
- export function lab2xyz(lab: vec3, xyz: vec3): void;
639
+ export function lab2xyz(lab: Vector3, xyz: Vector3): void;
625
640
 
626
641
  /**
627
642
  *
628
- * @param {vec3} xyz
629
- * @param {vec3} lab
643
+ * @param {Vector3} xyz
644
+ * @param {Vector3} lab
630
645
  */
631
- export function xyz2lab(xyz: vec3, lab: vec3): void;
646
+ export function xyz2lab(xyz: Vector3, lab: Vector3): void;
632
647
 
633
648
  /**
634
649
  *
635
- * @param {vec3} xyz
636
- * @param {vec3} rgb An Array of the RGB color.
650
+ * @param {Vector3} xyz
651
+ * @param {RGBColor} rgb An Array of the RGB color.
637
652
  */
638
- export function xyz2rgb(xyz: vec3, rgb: vec3): void;
653
+ export function xyz2rgb(xyz: Vector3, rgb: RGBColor): void;
639
654
 
640
655
  /**
641
656
  *
642
- * @param {vec3} rgb An Array of the RGB color.
643
- * @param {vec3} xyz
657
+ * @param {RGBColor} rgb An Array of the RGB color.
658
+ * @param {Vector3} xyz
644
659
  */
645
- export function rgb2xyz(rgb: vec3, xyz: vec3): void;
660
+ export function rgb2xyz(rgb: RGBColor, xyz: Vector3): void;
646
661
 
647
662
  /**
648
663
  *
649
- * @param {vec3} rgb
650
- * @param {vec3} lab
664
+ * @param {RGBColor} rgb
665
+ * @param {Vector3} lab
651
666
  */
652
- export function rgb2lab(rgb: vec3, lab: vec3): void;
667
+ export function rgb2lab(rgb: RGBColor, lab: Vector3): void;
653
668
 
654
669
  /**
655
670
  *
656
- * @param {vec3} lab
657
- * @param {vec3} rgb An Array of the RGB color.
671
+ * @param {Vector3} lab
672
+ * @param {RGBColor} rgb An Array of the RGB color.
658
673
  */
659
- export function lab2rgb(lab: vec3, rgb: vec3): void;
674
+ export function lab2rgb(lab: Vector3, rgb: RGBColor): void;
660
675
 
661
676
  /**
662
677
  * Returns bounds.
663
- * @param {Number[]} bounds Output array that hold bounds, optionally empty.
678
+ * @param {Bounds} bounds Output array that hold bounds, optionally empty.
664
679
  */
665
- export function uninitializeBounds(bounds: number[]): number[];
680
+ export function uninitializeBounds(bounds: Bounds): Bounds;
666
681
 
667
682
  /**
668
683
  *
669
- * @param {vec2} bounds The bounds to check.
684
+ * @param {Bounds} bounds The bounds to check.
670
685
  */
671
- export function areBoundsInitialized(bounds: vec2): boolean;
686
+ export function areBoundsInitialized(bounds: Bounds): boolean;
672
687
 
673
688
  /**
674
689
  * Compute the bounds from points.
675
- * @param {vec3} point1 The coordinate of the first point.
676
- * @param {vec3} point2 The coordinate of the second point.
677
- * @param {Number[]} bounds Output array that hold bounds, optionally empty.
690
+ * @param {Vector3} point1 The coordinate of the first point.
691
+ * @param {Vector3} point2 The coordinate of the second point.
692
+ * @param {Bounds} bounds Output array that hold bounds, optionally empty.
678
693
  */
679
- export function computeBoundsFromPoints(point1: vec3, point2: vec3, bounds: number[]): number[];
694
+ export function computeBoundsFromPoints(point1: Vector3, point2: Vector3, bounds: Bounds): Bounds;
680
695
 
681
696
  /**
682
697
  * Clamp some value against a range.
@@ -688,26 +703,26 @@ export function clampValue(value: number, minValue: number, maxValue: number): n
688
703
 
689
704
  /**
690
705
  * Clamp some vector against a range.
691
- * @param {vec3} vector The vector to clamp.
692
- * @param {vec3} minVector The minimum vector.
693
- * @param {vec3} maxVector The maximum vector.
694
- * @param {vec3} out The output vector.
706
+ * @param {Vector3} vector The vector to clamp.
707
+ * @param {Vector3} minVector The minimum vector.
708
+ * @param {Vector3} maxVector The maximum vector.
709
+ * @param {Vector3} out The output vector.
695
710
  */
696
- export function clampVector(vector: vec3, minVector: vec3, maxVector: vec3, out: vec3): vec3;
711
+ export function clampVector(vector: Vector3, minVector: Vector3, maxVector: Vector3, out: Vector3): Vector3;
697
712
 
698
713
  /**
699
714
  *
700
- * @param {vec3} vector
701
- * @param {vec3} out
715
+ * @param {Vector3} vector
716
+ * @param {Vector3} out
702
717
  */
703
- export function roundVector(vector: vec3, out: vec3): vec3;
718
+ export function roundVector(vector: Vector3, out: Vector3): Vector3;
704
719
 
705
720
  /**
706
721
  *
707
722
  * @param {Number} value
708
- * @param {vec2} range
723
+ * @param {Range} range
709
724
  */
710
- export function clampAndNormalizeValue(value: number, range: vec2): number;
725
+ export function clampAndNormalizeValue(value: number, range: Range): number;
711
726
 
712
727
  /**
713
728
  * Get the scalar type that is most likely to have enough precision to store a
@@ -731,17 +746,17 @@ export function extentIsWithinOtherExtent(extent1: Extent, extent2: Extent): num
731
746
  * Check if first 3D bounds is within the second 3D bounds.
732
747
  * @param {Bounds} bounds1_6 The first bounds.
733
748
  * @param {Bounds} bounds2_6 The second bounds.
734
- * @param {vec3} delta_3 The error margin along each axis.
749
+ * @param {Vector3} delta_3 The error margin along each axis.
735
750
  */
736
- export function boundsIsWithinOtherBounds(bounds1_6: Bounds, bounds2_6: Bounds, delta_3: vec3): number;
751
+ export function boundsIsWithinOtherBounds(bounds1_6: Bounds, bounds2_6: Bounds, delta_3: Vector3): number;
737
752
 
738
753
  /**
739
754
  * Check if point is within the given 3D bounds.
740
- * @param {vec3} point_3 The coordinate of the point.
755
+ * @param {Vector3} point_3 The coordinate of the point.
741
756
  * @param {Bounds} bounds_6 The bounds.
742
- * @param {vec3} delta_3 The error margin along each axis.
757
+ * @param {Vector3} delta_3 The error margin along each axis.
743
758
  */
744
- export function pointIsWithinBounds(point_3: vec3, bounds_6: Bounds, delta_3: vec3): number;
759
+ export function pointIsWithinBounds(point_3: Vector3, bounds_6: Bounds, delta_3: Vector3): number;
745
760
 
746
761
  /**
747
762
  * In Euclidean space, there is a unique circle passing through any given three
@@ -752,12 +767,12 @@ export function pointIsWithinBounds(point_3: vec3, bounds_6: Bounds, delta_3: ve
752
767
  * and center of the circle. See:
753
768
  * http://en.wikipedia.org/wiki/Circumscribed_circle and more specifically the
754
769
  * section Barycentric coordinates from cross- and dot-products
755
- * @param {vec3} p1 The coordinate of the first point.
756
- * @param {vec3} p2 The coordinate of the second point.
757
- * @param {vec3} p3 The coordinate of the third point.
758
- * @param {vec3} center The coordinate of the center point.
770
+ * @param {Vector3} p1 The coordinate of the first point.
771
+ * @param {Vector3} p2 The coordinate of the second point.
772
+ * @param {Vector3} p3 The coordinate of the third point.
773
+ * @param {Vector3} center The coordinate of the center point.
759
774
  */
760
- export function solve3PointCircle(p1: vec3, p2: vec3, p3: vec3, center: vec3): number;
775
+ export function solve3PointCircle(p1: Vector3, p2: Vector3, p3: Vector3, center: Vector3): number;
761
776
 
762
777
  /**
763
778
  * Determines whether the passed value is a infinite number.
@@ -784,10 +799,10 @@ export function floatToHex2(value: number): string;
784
799
 
785
800
  /**
786
801
  *
787
- * @param {Number[]} rgbArray
802
+ * @param {RGBColor} rgbArray
788
803
  * @param {string} [prefix]
789
804
  */
790
- export function floatRGB2HexCode(rgbArray: number[], prefix?: string): string;
805
+ export function floatRGB2HexCode(rgbArray: RGBColor | RGBAColor, prefix?: string): string;
791
806
 
792
807
  /**
793
808
  * Convert RGB or RGBA color array to CSS representation
@@ -2,9 +2,9 @@ import macro from '../../macros.js';
2
2
  import vtkImageData from './ImageData.js';
3
3
  import vtkDataArray from '../Core/DataArray.js';
4
4
 
5
- var vtkErrorMacro = macro.vtkErrorMacro; // see itk.js/PixelTypes.js
5
+ var vtkErrorMacro = macro.vtkErrorMacro; // see itk.js PixelTypes.js
6
6
 
7
- var ITKPixelTypes = {
7
+ var ITKJSPixelTypes = {
8
8
  Unknown: 0,
9
9
  Scalar: 1,
10
10
  RGB: 2,
@@ -21,6 +21,25 @@ var ITKPixelTypes = {
21
21
  Matrix: 13,
22
22
  VariableLengthVector: 14,
23
23
  VariableSizeMatrix: 15
24
+ }; // itk-wasm pixel types from https://github.com/InsightSoftwareConsortium/itk-wasm/blob/master/src/core/PixelTypes.ts
25
+
26
+ var ITKWASMPixelTypes = {
27
+ Unknown: 'Unknown',
28
+ Scalar: 'Scalar',
29
+ RGB: 'RGB',
30
+ RGBA: 'RGBA',
31
+ Offset: 'Offset',
32
+ Vector: 'Vector',
33
+ Point: 'Point',
34
+ CovariantVector: 'CovariantVector',
35
+ SymmetricSecondRankTensor: 'SymmetricSecondRankTensor',
36
+ DiffusionTensor3D: 'DiffusionTensor3D',
37
+ Complex: 'Complex',
38
+ FixedArray: 'FixedArray',
39
+ Array: 'Array',
40
+ Matrix: 'Matrix',
41
+ VariableLengthVector: 'VariableLengthVector',
42
+ VariableSizeMatrix: 'VariableSizeMatrix'
24
43
  };
25
44
  /**
26
45
  * Converts an itk.js image to a vtk.js image.
@@ -35,7 +54,10 @@ function convertItkToVtkImage(itkImage) {
35
54
  spacing: [1, 1, 1]
36
55
  };
37
56
  var dimensions = [1, 1, 1];
38
- var direction = [1, 0, 0, 0, 1, 0, 0, 0, 1];
57
+ var direction = [1, 0, 0, 0, 1, 0, 0, 0, 1]; // Check whether itkImage is an itk.js Image or an itk-wasm Image?
58
+
59
+ var isITKWasm = itkImage.direction.data === undefined;
60
+ var ITKPixelTypes = isITKWasm ? ITKWASMPixelTypes : ITKJSPixelTypes;
39
61
 
40
62
  for (var idx = 0; idx < itkImage.imageType.dimension; ++idx) {
41
63
  vtkImage.origin[idx] = itkImage.origin[idx];
@@ -47,7 +69,11 @@ function convertItkToVtkImage(itkImage) {
47
69
  // matrix on the vtkImageData is a webGL matrix, which uses a
48
70
  // column-major data layout. Transpose the direction matrix from
49
71
  // itkImage when instantiating that vtkImageData direction matrix.
50
- direction[col + idx * 3] = itkImage.direction.data[idx + col * itkImage.imageType.dimension];
72
+ if (isITKWasm) {
73
+ direction[col + idx * 3] = itkImage.direction[idx + col * itkImage.imageType.dimension];
74
+ } else {
75
+ direction[col + idx * 3] = itkImage.direction.data[idx + col * itkImage.imageType.dimension];
76
+ }
51
77
  }
52
78
  } // Create VTK Image Data
53
79
 
@@ -66,7 +92,7 @@ function convertItkToVtkImage(itkImage) {
66
92
  imageData.getPointData().setScalars(pointData); // Associate the point data that are 3D vectors / tensors
67
93
  // Refer to itk-js/src/PixelTypes.js for numerical values
68
94
 
69
- switch (itkImage.imageType.pixelType) {
95
+ switch (ITKPixelTypes[itkImage.imageType.pixelType]) {
70
96
  case ITKPixelTypes.Scalar:
71
97
  break;
72
98
 
@@ -148,7 +174,7 @@ function convertVtkToItkImage(vtkImage) {
148
174
  var itkImage = {
149
175
  imageType: {
150
176
  dimension: 3,
151
- pixelType: ITKPixelTypes.Scalar,
177
+ pixelType: ITKJSPixelTypes.Scalar,
152
178
  componentType: '',
153
179
  components: 1
154
180
  },
@@ -176,10 +202,10 @@ function convertVtkToItkImage(vtkImage) {
176
202
  var vtkArray;
177
203
 
178
204
  if (pointData.getTensors() !== null) {
179
- itkImage.imageType.pixelType = ITKPixelTypes.DiffusionTensor3D;
205
+ itkImage.imageType.pixelType = ITKJSPixelTypes.DiffusionTensor3D;
180
206
  vtkArray = pointData.getTensors();
181
207
  } else if (pointData.getVectors() != null) {
182
- itkImage.imageType.pixelType = ITKPixelTypes.Vector;
208
+ itkImage.imageType.pixelType = ITKJSPixelTypes.Vector;
183
209
  vtkArray = pointData.getVectors();
184
210
  } else {
185
211
  vtkArray = pointData.getScalars();
@@ -53,12 +53,12 @@ function vtkInteractorStyleTrackballCamera(publicAPI, model) {
53
53
 
54
54
 
55
55
  publicAPI.handleButton3D = function (ed) {
56
- if (ed && ed.pressed && ed.device === Device.RightController && ed.input === Input.TrackPad) {
56
+ if (ed && ed.pressed && ed.device === Device.RightController && (ed.input === Input.Trigger || ed.input === Input.TrackPad)) {
57
57
  publicAPI.startCameraPose();
58
58
  return;
59
59
  }
60
60
 
61
- if (ed && !ed.pressed && ed.device === Device.RightController && ed.input === Input.TrackPad && model.state === States.IS_CAMERA_POSE) {
61
+ if (ed && !ed.pressed && ed.device === Device.RightController && (ed.input === Input.Trigger || ed.input === Input.TrackPad) && model.state === States.IS_CAMERA_POSE) {
62
62
  publicAPI.endCameraPose(); // return;
63
63
  }
64
64
  };
@@ -77,11 +77,12 @@ function vtkInteractorStyleTrackballCamera(publicAPI, model) {
77
77
  var camera = ed.pokedRenderer.getActiveCamera();
78
78
  var oldTrans = camera.getPhysicalTranslation(); // look at the y axis to determine how fast / what direction to move
79
79
 
80
- var speed = ed.gamepad.axes[1]; // 0.05 meters / frame movement
80
+ var speed = 0.5; // ed.gamepad.axes[1];
81
+ // 0.05 meters / frame movement
81
82
 
82
83
  var pscale = speed * 0.05 * camera.getPhysicalScale(); // convert orientation to world coordinate direction
83
84
 
84
- var dir = camera.physicalOrientationToWorldDirection(ed.orientation);
85
+ var dir = camera.physicalOrientationToWorldDirection([ed.orientation.x, ed.orientation.y, ed.orientation.z, ed.orientation.w]);
85
86
  camera.setPhysicalTranslation(oldTrans[0] + dir[0] * pscale, oldTrans[1] + dir[1] * pscale, oldTrans[2] + dir[2] * pscale);
86
87
  }; //----------------------------------------------------------------------------
87
88
 
@@ -8,11 +8,23 @@ var Input = {
8
8
  Trigger: 1,
9
9
  TrackPad: 2,
10
10
  Grip: 3,
11
- ApplicationMenu: 4
11
+ Thumbstick: 4,
12
+ A: 5,
13
+ B: 6,
14
+ ApplicationMenu: 7 // Not exposed in WebXR API
15
+
16
+ };
17
+ var Axis = {
18
+ Unknown: 0,
19
+ TouchpadX: 1,
20
+ TouchpadY: 2,
21
+ ThumbstickX: 3,
22
+ ThumbstickY: 4
12
23
  };
13
24
  var Constants = {
14
25
  Device: Device,
15
- Input: Input
26
+ Input: Input,
27
+ Axis: Axis
16
28
  };
17
29
 
18
- export { Device, Input, Constants as default };
30
+ export { Axis, Device, Input, Constants as default };
@@ -16,7 +16,7 @@ var vtkWarningMacro = macro.vtkWarningMacro,
16
16
  // ----------------------------------------------------------------------------
17
17
 
18
18
  var deviceInputMap = {
19
- 'OpenVR Gamepad': [Input.TrackPad, Input.Trigger, Input.Grip, Input.ApplicationMenu]
19
+ 'xr-standard': [Input.Trigger, Input.Grip, Input.TrackPad, Input.Thumbstick, Input.A, Input.B]
20
20
  };
21
21
  var handledEvents = ['StartAnimation', 'Animation', 'EndAnimation', 'MouseEnter', 'MouseLeave', 'StartMouseMove', 'MouseMove', 'EndMouseMove', 'LeftButtonPress', 'LeftButtonRelease', 'MiddleButtonPress', 'MiddleButtonRelease', 'RightButtonPress', 'RightButtonRelease', 'KeyPress', 'KeyDown', 'KeyUp', 'StartMouseWheel', 'MouseWheel', 'EndMouseWheel', 'StartPinch', 'Pinch', 'EndPinch', 'StartPan', 'Pan', 'EndPan', 'StartRotate', 'Rotate', 'EndRotate', 'Button3D', 'Move3D', 'StartPointerLock', 'EndPointerLock', 'StartInteraction', 'Interaction', 'EndInteraction'];
22
22
 
@@ -378,47 +378,53 @@ function vtkRenderWindowInteractor(publicAPI, model) {
378
378
  }
379
379
  };
380
380
 
381
- publicAPI.updateGamepads = function (displayId) {
382
- var gamepads = navigator.getGamepads(); // watch for when buttons change state and fire events
381
+ publicAPI.updateXRGamepads = function (xrSession, xrFrame, xrRefSpace) {
382
+ // watch for when buttons change state and fire events
383
+ xrSession.inputSources.forEach(function (inputSource) {
384
+ var pose = xrFrame.getPose(inputSource.gripSpace, xrRefSpace);
385
+ var gp = inputSource.gamepad;
386
+ var hand = inputSource.handedness;
383
387
 
384
- for (var i = 0; i < gamepads.length; ++i) {
385
- var gp = gamepads[i];
386
-
387
- if (gp && gp.displayId === displayId) {
388
+ if (gp) {
388
389
  if (!(gp.index in model.lastGamepadValues)) {
389
390
  model.lastGamepadValues[gp.index] = {
390
- buttons: {}
391
+ left: {
392
+ buttons: {}
393
+ },
394
+ right: {
395
+ buttons: {}
396
+ }
391
397
  };
392
398
  }
393
399
 
394
400
  for (var b = 0; b < gp.buttons.length; ++b) {
395
- if (!(b in model.lastGamepadValues[gp.index].buttons)) {
396
- model.lastGamepadValues[gp.index].buttons[b] = false;
401
+ if (!(b in model.lastGamepadValues[gp.index][hand].buttons)) {
402
+ model.lastGamepadValues[gp.index][hand].buttons[b] = false;
397
403
  }
398
404
 
399
- if (model.lastGamepadValues[gp.index].buttons[b] !== gp.buttons[b].pressed) {
405
+ if (model.lastGamepadValues[gp.index][hand].buttons[b] !== gp.buttons[b].pressed) {
400
406
  publicAPI.button3DEvent({
401
407
  gamepad: gp,
402
- position: gp.pose.position,
403
- orientation: gp.pose.orientation,
408
+ position: pose.transform.position,
409
+ orientation: pose.transform.orientation,
404
410
  pressed: gp.buttons[b].pressed,
405
- device: gp.hand === 'left' ? Device.LeftController : Device.RightController,
406
- input: deviceInputMap[gp.id] && deviceInputMap[gp.id][b] ? deviceInputMap[gp.id][b] : Input.Trigger
411
+ device: inputSource.handedness === 'left' ? Device.LeftController : Device.RightController,
412
+ input: deviceInputMap[gp.mapping] && deviceInputMap[gp.mapping][b] ? deviceInputMap[gp.mapping][b] : Input.Trigger
407
413
  });
408
- model.lastGamepadValues[gp.index].buttons[b] = gp.buttons[b].pressed;
414
+ model.lastGamepadValues[gp.index][hand].buttons[b] = gp.buttons[b].pressed;
409
415
  }
410
416
 
411
- if (model.lastGamepadValues[gp.index].buttons[b]) {
417
+ if (model.lastGamepadValues[gp.index][hand].buttons[b]) {
412
418
  publicAPI.move3DEvent({
413
419
  gamepad: gp,
414
- position: gp.pose.position,
415
- orientation: gp.pose.orientation,
416
- device: gp.hand === 'left' ? Device.LeftController : Device.RightController
420
+ position: pose.transform.position,
421
+ orientation: pose.transform.orientation,
422
+ device: inputSource.handedness === 'left' ? Device.LeftController : Device.RightController
417
423
  });
418
424
  }
419
425
  }
420
426
  }
421
- }
427
+ });
422
428
  };
423
429
 
424
430
  publicAPI.handleMouseMove = function (event) {
@@ -245,21 +245,28 @@ function vtkOpenGLRenderWindow(publicAPI, model) {
245
245
  // typically in response to a user request such as a button press
246
246
 
247
247
 
248
- publicAPI.startXR = function () {
248
+ publicAPI.startXR = function (isAR) {
249
249
  if (navigator.xr === undefined) {
250
250
  throw new Error('WebXR is not available');
251
251
  }
252
252
 
253
- if (!navigator.xr.isSessionSupported('immersive-vr')) {
254
- throw new Error('VR display is not available');
253
+ model.xrSessionIsAR = isAR;
254
+ var sessionType = isAR ? 'immersive-ar' : 'immersive-vr';
255
+
256
+ if (!navigator.xr.isSessionSupported(sessionType)) {
257
+ if (isAR) {
258
+ throw new Error('Device does not support AR session');
259
+ } else {
260
+ throw new Error('VR display is not available');
261
+ }
255
262
  }
256
263
 
257
264
  if (model.xrSession === null) {
258
- navigator.xr.requestSession('immersive-vr').then(publicAPI.enterXR, function () {
259
- throw new Error('Failed to create VR session!');
265
+ navigator.xr.requestSession(sessionType).then(publicAPI.enterXR, function () {
266
+ throw new Error('Failed to create XR session!');
260
267
  });
261
268
  } else {
262
- throw new Error('VR Session already exists!');
269
+ throw new Error('XR Session already exists!');
263
270
  }
264
271
  }; // When an XR session is available, set up the XRWebGLLayer
265
272
  // and request the first animation frame for the device
@@ -348,7 +355,10 @@ function vtkOpenGLRenderWindow(publicAPI, model) {
348
355
  model.xrSession = null;
349
356
 
350
357
  case 10:
351
- publicAPI.setSize.apply(publicAPI, _toConsumableArray(model.oldCanvasSize)); // Reset to default canvas
358
+ if (model.oldCanvasSize !== undefined) {
359
+ publicAPI.setSize.apply(publicAPI, _toConsumableArray(model.oldCanvasSize));
360
+ } // Reset to default canvas
361
+
352
362
 
353
363
  ren = model.renderable.getRenderers()[0];
354
364
  ren.getActiveCamera().setProjectionMatrix(null);
@@ -372,11 +382,18 @@ function vtkOpenGLRenderWindow(publicAPI, model) {
372
382
  switch (_context3.prev = _context3.next) {
373
383
  case 0:
374
384
  xrSession = frame.session;
385
+ model.renderable.getInteractor().updateXRGamepads(xrSession, frame, model.xrReferenceSpace);
375
386
  model.xrSceneFrame = model.xrSession.requestAnimationFrame(publicAPI.xrRender);
376
387
  xrPose = frame.getViewerPose(model.xrReferenceSpace);
377
388
 
378
389
  if (xrPose) {
379
390
  gl = publicAPI.get3DContext();
391
+
392
+ if (model.xrSessionIsAR && model.oldCanvasSize !== undefined) {
393
+ gl.canvas.width = model.oldCanvasSize[0];
394
+ gl.canvas.height = model.oldCanvasSize[1];
395
+ }
396
+
380
397
  glLayer = xrSession.renderState.baseLayer;
381
398
  gl.bindFramebuffer(gl.FRAMEBUFFER, glLayer.framebuffer);
382
399
  gl.clear(gl.COLOR_BUFFER_BIT);
@@ -386,15 +403,18 @@ function vtkOpenGLRenderWindow(publicAPI, model) {
386
403
 
387
404
  xrPose.views.forEach(function (view) {
388
405
  var viewport = glLayer.getViewport(view);
389
- gl.viewport(viewport.x, viewport.y, viewport.width, viewport.height);
390
-
391
- if (view.eye === 'left') {
392
- ren.setViewport(0, 0, 0.5, 1.0);
393
- } else if (view.eye === 'right') {
394
- ren.setViewport(0.5, 0, 1.0, 1.0);
395
- } else {
396
- // No handling for non-eye viewport
397
- return;
406
+ gl.viewport(viewport.x, viewport.y, viewport.width, viewport.height); // TODO: Appropriate handling for AR passthrough on HMDs
407
+ // with two eyes will require further investigation.
408
+
409
+ if (!model.xrSessionIsAR) {
410
+ if (view.eye === 'left') {
411
+ ren.setViewport(0, 0, 0.5, 1.0);
412
+ } else if (view.eye === 'right') {
413
+ ren.setViewport(0.5, 0, 1.0, 1.0);
414
+ } else {
415
+ // No handling for non-eye viewport
416
+ return;
417
+ }
398
418
  }
399
419
 
400
420
  ren.getActiveCamera().computeViewParametersFromPhysicalMatrix(view.transform.inverse.matrix);
@@ -403,7 +423,7 @@ function vtkOpenGLRenderWindow(publicAPI, model) {
403
423
  });
404
424
  }
405
425
 
406
- case 4:
426
+ case 5:
407
427
  case "end":
408
428
  return _context3.stop();
409
429
  }
@@ -776,7 +796,9 @@ var DEFAULT_VALUES = {
776
796
  // attempt webgl2 on by default
777
797
  activeFramebuffer: null,
778
798
  xrSession: null,
799
+ xrSessionIsAR: false,
779
800
  xrReferenceSpace: null,
801
+ xrSupported: true,
780
802
  imageFormat: 'image/png',
781
803
  useOffScreen: false,
782
804
  useBackgroundImage: false
@@ -819,7 +841,7 @@ function extend(publicAPI, model) {
819
841
  macro.event(publicAPI, model, 'imageReady');
820
842
  macro.event(publicAPI, model, 'haveVRDisplay'); // Build VTK API
821
843
 
822
- macro.get(publicAPI, model, ['shaderCache', 'textureUnitManager', 'webgl2', 'vrDisplay', 'useBackgroundImage']);
844
+ macro.get(publicAPI, model, ['shaderCache', 'textureUnitManager', 'webgl2', 'vrDisplay', 'useBackgroundImage', 'xrSupported']);
823
845
  macro.setGet(publicAPI, model, ['initialized', 'context', 'canvas', 'renderPasses', 'notifyStartCaptureImage', 'defaultToWebgl2', 'cursor', 'useOffScreen', // might want to make this not call modified as
824
846
  // we change the active framebuffer a lot. Or maybe
825
847
  // only mark modified if the size or depth
@@ -616,7 +616,8 @@ var DEFAULT_VALUES = {
616
616
  imageFormat: 'image/png',
617
617
  useOffScreen: false,
618
618
  useBackgroundImage: false,
619
- nextPropID: 1
619
+ nextPropID: 1,
620
+ xrSupported: false
620
621
  }; // ----------------------------------------------------------------------------
621
622
 
622
623
  function extend(publicAPI, model) {
@@ -652,7 +653,7 @@ function extend(publicAPI, model) {
652
653
  macro.event(publicAPI, model, 'imageReady');
653
654
  macro.event(publicAPI, model, 'initialized'); // Build VTK API
654
655
 
655
- macro.get(publicAPI, model, ['commandEncoder', 'device', 'useBackgroundImage']);
656
+ macro.get(publicAPI, model, ['commandEncoder', 'device', 'useBackgroundImage', 'xrSupported']);
656
657
  macro.setGet(publicAPI, model, ['initialized', 'context', 'canvas', 'device', 'renderPasses', 'notifyStartCaptureImage', 'cursor', 'useOffScreen']);
657
658
  macro.setGetArray(publicAPI, model, ['size'], 2); // Object methods
658
659
 
package/macros.js CHANGED
@@ -553,12 +553,15 @@ function setArray(publicAPI, model, fieldNames, size) {
553
553
  }
554
554
 
555
555
  var array = args;
556
- var changeDetected; // allow null or an array to be passed as a single arg.
556
+ var changeDetected;
557
+ var needCopy = false; // allow null or an array to be passed as a single arg.
557
558
 
558
559
  if (array.length === 1 && (array[0] == null || array[0].length >= 0)) {
559
560
  /* eslint-disable prefer-destructuring */
560
561
  array = array[0];
561
562
  /* eslint-enable prefer-destructuring */
563
+
564
+ needCopy = true;
562
565
  }
563
566
 
564
567
  if (array == null) {
@@ -567,6 +570,7 @@ function setArray(publicAPI, model, fieldNames, size) {
567
570
  if (size && array.length !== size) {
568
571
  if (array.length < size && defaultVal !== undefined) {
569
572
  array = Array.from(array);
573
+ needCopy = false;
570
574
 
571
575
  while (array.length < size) {
572
576
  array.push(defaultVal);
@@ -580,7 +584,7 @@ function setArray(publicAPI, model, fieldNames, size) {
580
584
  return item !== array[index];
581
585
  }) || model[field].length !== array.length;
582
586
 
583
- if (changeDetected && !Array.isArray(array)) {
587
+ if (changeDetected && needCopy) {
584
588
  array = Array.from(array);
585
589
  }
586
590
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kitware/vtk.js",
3
- "version": "21.3.0",
3
+ "version": "21.5.0",
4
4
  "description": "Visualization Toolkit for the Web",
5
5
  "keywords": [
6
6
  "3d",
package/types.d.ts CHANGED
@@ -19,6 +19,11 @@ declare type Size = [number, number];
19
19
  declare type Range = [number, number];
20
20
  declare type Vector2 = [number, number];
21
21
  declare type Vector3 = [number, number, number];
22
+ declare type Vector4 = [number, number, number, number];
23
+
24
+ declare type Matrix = number[][];
25
+ declare type Matrix2x2 = [Vector2, Vector2];
26
+ declare type Matrix3x3 = [Vector3, Vector3, Vector3];
22
27
  /**
23
28
  * @deprecated The `Point` type is depracted, please use `Vector3` instead.
24
29
  */