@kitware/vtk.js 24.0.0-beta.1 → 24.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -53,6 +53,7 @@ function _addPoint(bounds) {
53
53
  bounds[3] = yMax > (arguments.length <= 2 ? undefined : arguments[2]) ? yMax : arguments.length <= 2 ? undefined : arguments[2];
54
54
  bounds[4] = zMin < (arguments.length <= 3 ? undefined : arguments[3]) ? zMin : arguments.length <= 3 ? undefined : arguments[3];
55
55
  bounds[5] = zMax > (arguments.length <= 3 ? undefined : arguments[3]) ? zMax : arguments.length <= 3 ? undefined : arguments[3];
56
+ return bounds;
56
57
  }
57
58
 
58
59
  function _addBounds(bounds, xMin, xMax, yMin, yMax, zMin, zMax) {
@@ -79,6 +80,8 @@ function _addBounds(bounds, xMin, xMax, yMin, yMax, zMin, zMax) {
79
80
  bounds[4] = Math.min(zMin, _zMin);
80
81
  bounds[5] = Math.max(zMax, _zMax);
81
82
  }
83
+
84
+ return bounds;
82
85
  }
83
86
 
84
87
  function _setMinPoint(bounds, x, y, z) {
@@ -124,6 +127,7 @@ function _inflate(bounds, delta) {
124
127
  bounds[3] += delta;
125
128
  bounds[4] -= delta;
126
129
  bounds[5] += delta;
130
+ return bounds;
127
131
  }
128
132
 
129
133
  function _scale(bounds, sx, sy, sz) {
@@ -233,6 +237,8 @@ function _getCorners(bounds, corners) {
233
237
  }
234
238
  }
235
239
  }
240
+
241
+ return corners;
236
242
  } // Computes the two corners with minimal and miximal coordinates
237
243
 
238
244
  function _computeCornerPoints(bounds, point1, point2) {
@@ -242,6 +248,7 @@ function _computeCornerPoints(bounds, point1, point2) {
242
248
  point2[0] = bounds[1];
243
249
  point2[1] = bounds[3];
244
250
  point2[2] = bounds[5];
251
+ return point1;
245
252
  }
246
253
 
247
254
  function _computeScale(bounds) {
@@ -557,9 +564,7 @@ var BoundingBox = /*#__PURE__*/function () {
557
564
  this.bounds = refBounds;
558
565
 
559
566
  if (!this.bounds) {
560
- this.bounds = new Float64Array(6);
561
-
562
- _setBounds(this.bounds, INIT_BOUNDS);
567
+ this.bounds = new Float64Array(INIT_BOUNDS);
563
568
  }
564
569
  }
565
570
 
@@ -1,5 +1,6 @@
1
1
  import macro from '../../macros.js';
2
2
  import vtkImageData from './ImageData.js';
3
+ import vtkPolyData from './PolyData.js';
3
4
  import vtkDataArray from '../Core/DataArray.js';
4
5
 
5
6
  var vtkErrorMacro = macro.vtkErrorMacro; // see itk.js PixelTypes.js
@@ -42,6 +43,7 @@ var ITKWASMPixelTypes = {
42
43
  VariableSizeMatrix: 'VariableSizeMatrix'
43
44
  };
44
45
  var vtkArrayTypeToItkComponentType = new Map([['Uint8Array', 'uint8'], ['Int8Array', 'int8'], ['Uint16Array', 'uint16'], ['Int16Array', 'int16'], ['Uint32Array', 'uint32'], ['Int32Array', 'int32'], ['Float32Array', 'float32'], ['Float64Array', 'float64']]);
46
+ var itkComponentTypeToVtkArrayType = new Map([['uint8', 'Uint8Array'], ['int8', 'Int8Array'], ['uint16', 'Uint16Array'], ['int16', 'Int16Array'], ['uint32', 'Uint32Array'], ['int32', 'Int32Array'], ['float32', 'Float32Array'], ['float64', 'Float64Array']]);
45
47
  /**
46
48
  * Converts an itk-wasm Image to a vtk.js vtkImageData.
47
49
  *
@@ -156,7 +158,7 @@ function convertItkToVtkImage(itkImage) {
156
158
  break;
157
159
 
158
160
  default:
159
- vtkErrorMacro("Cannot handle unexpected ITK.js pixel type ".concat(itkImage.imageType.pixelType));
161
+ vtkErrorMacro("Cannot handle unexpected itk-wasm pixel type ".concat(itkImage.imageType.pixelType));
160
162
  return null;
161
163
  }
162
164
 
@@ -218,10 +220,352 @@ function convertVtkToItkImage(vtkImage) {
218
220
 
219
221
  return itkImage;
220
222
  }
223
+ /**
224
+ * Converts an itk-wasm PolyData to a vtk.js vtkPolyData.
225
+ *
226
+ * Requires an itk-wasm PolyData as input.
227
+ */
228
+
229
+
230
+ function convertItkToVtkPolyData(itkPolyData) {
231
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
232
+ var pointDataArrays = [];
233
+
234
+ if (itkPolyData.pointData.length) {
235
+ pointDataArrays.push({
236
+ data: {
237
+ vtkClass: 'vtkDataArray',
238
+ name: options.pointDataName || 'PointData',
239
+ numberOfComponents: itkPolyData.polyDataType.pointPixelComponents,
240
+ size: itkPolyData.pointData.length,
241
+ dataType: itkComponentTypeToVtkArrayType.get(itkPolyData.polyDataType.pointPixelComponentType),
242
+ buffer: itkPolyData.pointData.buffer,
243
+ values: itkPolyData.pointData
244
+ }
245
+ });
246
+ }
247
+
248
+ var cellDataArrays = [];
249
+
250
+ if (itkPolyData.cellData.length) {
251
+ cellDataArrays.push({
252
+ data: {
253
+ vtkClass: 'vtkDataArray',
254
+ name: options.cellDataName || 'CellData',
255
+ numberOfComponents: itkPolyData.polyDataType.pointPixelComponents,
256
+ size: itkPolyData.cellData.length,
257
+ dataType: itkComponentTypeToVtkArrayType.get(itkPolyData.polyDataType.pointPixelComponentType),
258
+ buffer: itkPolyData.cellData.buffer,
259
+ values: itkPolyData.cellData
260
+ }
261
+ });
262
+ }
263
+
264
+ var vtkPolyDataModel = {
265
+ points: {
266
+ vtkClass: 'vtkPoints',
267
+ name: '_points',
268
+ numberOfComponents: 3,
269
+ size: itkPolyData.numberOfPoints,
270
+ dataType: 'Float32Array',
271
+ buffer: itkPolyData.points.buffer,
272
+ values: itkPolyData.points
273
+ },
274
+ verts: {
275
+ vtkClass: 'vtkCellArray',
276
+ name: '_verts',
277
+ numberOfComponents: 1,
278
+ size: itkPolyData.verticesBufferSize,
279
+ dataType: 'Uint32Array',
280
+ buffer: itkPolyData.vertices.buffer,
281
+ values: itkPolyData.vertices
282
+ },
283
+ lines: {
284
+ vtkClass: 'vtkCellArray',
285
+ name: '_lines',
286
+ numberOfComponents: 1,
287
+ size: itkPolyData.linesBufferSize,
288
+ dataType: 'Uint32Array',
289
+ buffer: itkPolyData.lines.buffer,
290
+ values: itkPolyData.lines
291
+ },
292
+ polys: {
293
+ vtkClass: 'vtkCellArray',
294
+ name: '_polys',
295
+ numberOfComponents: 1,
296
+ size: itkPolyData.polygonsBufferSize,
297
+ dataType: 'Uint32Array',
298
+ buffer: itkPolyData.polygons.buffer,
299
+ values: itkPolyData.polygons
300
+ },
301
+ strips: {
302
+ vtkClass: 'vtkCellArray',
303
+ name: '_strips',
304
+ numberOfComponents: 1,
305
+ size: itkPolyData.triangleStripsBufferSize,
306
+ dataType: 'Uint32Array',
307
+ buffer: itkPolyData.triangleStrips.buffer,
308
+ values: itkPolyData.triangleStrips
309
+ },
310
+ pointData: {
311
+ vtkClass: 'vtkDataSetAttributes',
312
+ activeGlobalIds: -1,
313
+ activeNormals: -1,
314
+ activePedigreeIds: -1,
315
+ activeScalars: -1,
316
+ activeTCoords: -1,
317
+ activeTensors: -1,
318
+ activeVectors: -1,
319
+ copyFieldFlags: [],
320
+ doCopyAllOff: false,
321
+ doCopyAllOn: true,
322
+ arrays: pointDataArrays
323
+ },
324
+ cellData: {
325
+ vtkClass: 'vtkDataSetAttributes',
326
+ activeGlobalIds: -1,
327
+ activeNormals: -1,
328
+ activePedigreeIds: -1,
329
+ activeScalars: -1,
330
+ activeTCoords: -1,
331
+ activeTensors: -1,
332
+ activeVectors: -1,
333
+ copyFieldFlags: [],
334
+ doCopyAllOff: false,
335
+ doCopyAllOn: true,
336
+ arrays: cellDataArrays
337
+ }
338
+ }; // Create VTK PolyData
339
+
340
+ var polyData = vtkPolyData.newInstance(vtkPolyDataModel);
341
+ var pd = polyData.getPointData();
342
+ var cd = polyData.getCellData();
343
+
344
+ if (itkPolyData.pointData.length) {
345
+ // Associate the point data that are 3D vectors / tensors
346
+ switch (ITKWASMPixelTypes[itkPolyData.polyDataType.pointPixelType]) {
347
+ case ITKWASMPixelTypes.Scalar:
348
+ pd.setScalars(pd.getArrayByIndex(0));
349
+ break;
350
+
351
+ case ITKWASMPixelTypes.RGB:
352
+ break;
353
+
354
+ case ITKWASMPixelTypes.RGBA:
355
+ break;
356
+
357
+ case ITKWASMPixelTypes.Offset:
358
+ break;
359
+
360
+ case ITKWASMPixelTypes.Vector:
361
+ if (itkPolyData.polyDataType.pointPixelComponents === 3) {
362
+ pd.setVectors(pd.getArrayByIndex(0));
363
+ }
364
+
365
+ break;
366
+
367
+ case ITKWASMPixelTypes.Point:
368
+ break;
369
+
370
+ case ITKWASMPixelTypes.CovariantVector:
371
+ if (itkPolyData.polyDataType.pointPixelComponents === 3) {
372
+ pd.setVectors(pd.getArrayByIndex(0));
373
+ }
374
+
375
+ break;
376
+
377
+ case ITKWASMPixelTypes.SymmetricSecondRankTensor:
378
+ if (itkPolyData.polyDataType.pointPixelComponents === 6) {
379
+ pd.setTensors(pd.getArrayByIndex(0));
380
+ }
381
+
382
+ break;
383
+
384
+ case ITKWASMPixelTypes.DiffusionTensor3D:
385
+ if (itkPolyData.polyDataType.pointPixelComponents === 6) {
386
+ pd.setTensors(pd.getArrayByIndex(0));
387
+ }
388
+
389
+ break;
390
+
391
+ case ITKWASMPixelTypes.Complex:
392
+ break;
393
+
394
+ case ITKWASMPixelTypes.FixedArray:
395
+ break;
396
+
397
+ case ITKWASMPixelTypes.Array:
398
+ break;
399
+
400
+ case ITKWASMPixelTypes.Matrix:
401
+ break;
402
+
403
+ case ITKWASMPixelTypes.VariableLengthVector:
404
+ break;
405
+
406
+ case ITKWASMPixelTypes.VariableSizeMatrix:
407
+ break;
408
+
409
+ default:
410
+ vtkErrorMacro("Cannot handle unexpected itk-wasm pixel type ".concat(itkPolyData.polyDataType.pointPixelType));
411
+ return null;
412
+ }
413
+ }
414
+
415
+ if (itkPolyData.cellData.length) {
416
+ // Associate the cell data that are 3D vectors / tensors
417
+ switch (ITKWASMPixelTypes[itkPolyData.polyDataType.cellPixelType]) {
418
+ case ITKWASMPixelTypes.Scalar:
419
+ cd.setScalars(cd.getArrayByIndex(0));
420
+ break;
421
+
422
+ case ITKWASMPixelTypes.RGB:
423
+ break;
424
+
425
+ case ITKWASMPixelTypes.RGBA:
426
+ break;
427
+
428
+ case ITKWASMPixelTypes.Offset:
429
+ break;
430
+
431
+ case ITKWASMPixelTypes.Vector:
432
+ if (itkPolyData.polyDataType.pointPixelComponents === 3) {
433
+ cd.setVectors(cd.getArrayByIndex(0));
434
+ }
435
+
436
+ break;
437
+
438
+ case ITKWASMPixelTypes.Point:
439
+ break;
440
+
441
+ case ITKWASMPixelTypes.CovariantVector:
442
+ if (itkPolyData.polyDataType.pointPixelComponents === 3) {
443
+ cd.setVectors(cd.getArrayByIndex(0));
444
+ }
445
+
446
+ break;
447
+
448
+ case ITKWASMPixelTypes.SymmetricSecondRankTensor:
449
+ if (itkPolyData.polyDataType.pointPixelComponents === 6) {
450
+ cd.setTensors(cd.getArrayByIndex(0));
451
+ }
452
+
453
+ break;
454
+
455
+ case ITKWASMPixelTypes.DiffusionTensor3D:
456
+ if (itkPolyData.polyDataType.pointPixelComponents === 6) {
457
+ cd.setTensors(cd.getArrayByIndex(0));
458
+ }
459
+
460
+ break;
461
+
462
+ case ITKWASMPixelTypes.Complex:
463
+ break;
464
+
465
+ case ITKWASMPixelTypes.FixedArray:
466
+ break;
467
+
468
+ case ITKWASMPixelTypes.Array:
469
+ break;
470
+
471
+ case ITKWASMPixelTypes.Matrix:
472
+ break;
473
+
474
+ case ITKWASMPixelTypes.VariableLengthVector:
475
+ break;
476
+
477
+ case ITKWASMPixelTypes.VariableSizeMatrix:
478
+ break;
479
+
480
+ default:
481
+ vtkErrorMacro("Cannot handle unexpected itk-wasm pixel type ".concat(itkPolyData.polyDataType.pointPixelType));
482
+ return null;
483
+ }
484
+ }
485
+
486
+ return polyData;
487
+ }
488
+ /**
489
+ * Converts a vtk.js vtkPolyData to an itk-wasm PolyData.
490
+ *
491
+ * Requires a vtk.js vtkPolyData as input.
492
+ *
493
+ */
494
+
495
+
496
+ function convertVtkToItkPolyData(polyData) {
497
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
498
+ var itkPolyData = {
499
+ polyDataType: {
500
+ pointPixelComponentType: 'float32',
501
+ pointPixelComponents: 1,
502
+ pointPixelType: 'Scalar',
503
+ cellPixelComponentType: 'float32',
504
+ cellPixelComponents: 1,
505
+ cellPixelType: 'Scalar'
506
+ },
507
+ numberOfPoints: polyData.getNumberOfPoints(),
508
+ points: polyData.getPoints().getData(),
509
+ verticesBufferSize: polyData.getVerts().getNumberOfValues(),
510
+ vertices: polyData.getVerts().getData(),
511
+ linesBufferSize: polyData.getLines().getNumberOfValues(),
512
+ lines: polyData.getLines().getData(),
513
+ polygonsBufferSize: polyData.getPolys().getNumberOfValues(),
514
+ polygons: polyData.getPolys().getData(),
515
+ triangleStripsBufferSize: polyData.getStrips().getNumberOfValues(),
516
+ triangleStrips: polyData.getStrips().getData(),
517
+ numberOfPointPixels: 0,
518
+ pointData: new Float32Array(),
519
+ numberOfCellPixels: 0,
520
+ cellData: new Float32Array()
521
+ };
522
+ var pd = polyData.getPointData();
523
+
524
+ if (pd.getNumberOfArrays()) {
525
+ var pdArray = options.pointDataName ? pd.getArrayByName(options.pointDataName) : pd.getArrayByIndex(0);
526
+ itkPolyData.numberOfPointPixels = pdArray.getNumberOfTuples();
527
+ itkPolyData.pointData = pdArray.getData();
528
+ itkPolyData.polyDataType.pointPixelComponentType = vtkArrayTypeToItkComponentType.get(pdArray.getDataType()); // default to the same type
529
+
530
+ itkPolyData.polyDataType.cellPixelComponentType = itkPolyData.polyDataType.pointPixelComponentType;
531
+ itkPolyData.polyDataType.pointPixelComponents = pdArray.getNumberOfComponents();
532
+ itkPolyData.polyDataType.cellPixelComponents = itkPolyData.polyDataType.pointPixelComponents;
533
+
534
+ if (pd.getTensors() === pdArray) {
535
+ itkPolyData.polyDataType.pointPixelType = ITKWASMPixelTypes.SymmetricSecondRankTensor;
536
+ } else if (pd.getVectors() === pdArray) {
537
+ itkPolyData.polyDataType.pointPixelType = ITKWASMPixelTypes.Vector;
538
+ }
539
+
540
+ itkPolyData.polyDataType.cellPixelType = itkPolyData.polyDataType.pointPixelType;
541
+ }
542
+
543
+ var cd = polyData.getCellData();
544
+
545
+ if (cd.getNumberOfArrays()) {
546
+ var cdArray = options.cellDataName ? pd.getArrayByName(options.cellDataName) : pd.getArrayByIndex(0);
547
+ itkPolyData.numberOfCellPixels = cdArray.getNumberOfTuples();
548
+ itkPolyData.cellData = cdArray.getData();
549
+ itkPolyData.polyDataType.cellPixelComponentType = vtkArrayTypeToItkComponentType.get(cdArray.getDataType());
550
+ itkPolyData.polyDataType.cellPixelComponents = cdArray.getNumberOfComponents();
551
+
552
+ if (cd.getTensors() === cdArray) {
553
+ itkPolyData.polyDataType.cellPixelType = ITKWASMPixelTypes.SymmetricSecondRankTensor;
554
+ } else if (cd.getVectors() === cdArray) {
555
+ itkPolyData.polyDataType.cellPixelType = ITKWASMPixelTypes.Vector;
556
+ } else {
557
+ itkPolyData.polyDataType.cellPixelType = ITKWASMPixelTypes.Scalar;
558
+ }
559
+ }
560
+
561
+ return itkPolyData;
562
+ }
221
563
 
222
564
  var ITKHelper = {
223
565
  convertItkToVtkImage: convertItkToVtkImage,
224
- convertVtkToItkImage: convertVtkToItkImage
566
+ convertVtkToItkImage: convertVtkToItkImage,
567
+ convertItkToVtkPolyData: convertItkToVtkPolyData,
568
+ convertVtkToItkPolyData: convertVtkToItkPolyData
225
569
  };
226
570
 
227
571
  export { ITKHelper as default };
@@ -29,4 +29,10 @@ export interface DataAccessHelper {
29
29
  registerType(type: string, fn: any): void;
30
30
  }
31
31
 
32
+ export declare const DataAccessHelper: {
33
+ has: typeof has,
34
+ get: typeof get,
35
+ registerType: typeof registerType,
36
+ }
37
+
32
38
  export default DataAccessHelper;
@@ -19,7 +19,7 @@ function vtkActor(publicAPI, model) {
19
19
  var superClass = _objectSpread({}, publicAPI);
20
20
 
21
21
  publicAPI.getActors = function () {
22
- return publicAPI;
22
+ return [publicAPI];
23
23
  };
24
24
 
25
25
  publicAPI.getIsOpaque = function () {
@@ -14,7 +14,7 @@ export interface IPropInitialValues {
14
14
  estimatedRenderTime?: number;
15
15
  savedEstimatedRenderTime?: number;
16
16
  renderTimeMultiplier?: number;
17
- textures?: Array<any>;
17
+ textures?: vtkTexture[];
18
18
  }
19
19
 
20
20
  export interface vtkProp extends vtkObject {
@@ -141,20 +141,20 @@ export interface vtkProp extends vtkObject {
141
141
 
142
142
  /**
143
143
  *
144
- * @param texture
144
+ * @param {vtkTexture} texture The vtkTexture instance.
145
145
  *
146
146
  */
147
147
  hasTexture(texture: vtkTexture): boolean;
148
148
 
149
149
  /**
150
150
  *
151
- * @param texture
151
+ * @param {vtkTexture} texture The vtkTexture instance.
152
152
  */
153
153
  addTexture(texture: vtkTexture): void;
154
154
 
155
155
  /**
156
156
  *
157
- * @param texture
157
+ * @param {vtkTexture} texture The vtkTexture instance.
158
158
  */
159
159
  removeTexture(texture: vtkTexture): void;
160
160
 
@@ -230,9 +230,9 @@ export interface vtkProp extends vtkObject {
230
230
 
231
231
  /**
232
232
  * This is used for culling and is a number between 0 and 1. It is used to create the allocated render time value.
233
- * @param renderTimeMultiplier
233
+ * @param {Number} renderTimeMultiplier
234
234
  */
235
- setRendertimemultiplier(renderTimeMultiplier): boolean;
235
+ setRenderTimeMultiplier(renderTimeMultiplier: number): boolean;
236
236
 
237
237
  /**
238
238
  * Not Implemented yet
@@ -545,18 +545,18 @@ function vtkOpenGLPolyDataMapper2D(publicAPI, model) {
545
545
  var shiftScaleEnabled = cellBO.getCABO().getCoordShiftAndScaleEnabled();
546
546
  var inverseShiftScaleMatrix = shiftScaleEnabled ? cellBO.getCABO().getInverseShiftAndScaleMatrix() : null; // Get the position of the actor
547
547
 
548
- var size = model.openGLRenderer.getTiledSizeAndOrigin();
548
+ var view = ren.getRenderWindow().getViews()[0];
549
+ var size = view.getViewportSize(ren);
549
550
  var vport = ren.getViewport();
550
- var actorPos = actor.getActualPositionCoordinate().getComputedViewportValue(ren); // Get the window info
551
- // const tileViewport = ren.getVTKWindow().getTileViewport();
551
+ var actorPos = actor.getActualPositionCoordinate().getComputedDoubleViewportValue(ren); // Get the window info
552
552
  // Assume tile viewport is 0 1 based on vtkOpenGLRenderer
553
553
 
554
554
  var tileViewport = [0.0, 0.0, 1.0, 1.0];
555
- var visVP = [0, 1, 0, 1];
555
+ var visVP = [0.0, 0.0, 1.0, 1.0];
556
556
  visVP[0] = vport[0] >= tileViewport[0] ? vport[0] : tileViewport[0];
557
557
  visVP[1] = vport[1] >= tileViewport[1] ? vport[1] : tileViewport[1];
558
- visVP[2] = vport[2] >= tileViewport[2] ? vport[2] : tileViewport[2];
559
- visVP[3] = vport[3] >= tileViewport[3] ? vport[3] : tileViewport[3];
558
+ visVP[2] = vport[2] <= tileViewport[2] ? vport[2] : tileViewport[2];
559
+ visVP[3] = vport[3] <= tileViewport[3] ? vport[3] : tileViewport[3];
560
560
 
561
561
  if (visVP[0] >= visVP[2]) {
562
562
  return;
@@ -566,16 +566,16 @@ function vtkOpenGLPolyDataMapper2D(publicAPI, model) {
566
566
  return;
567
567
  }
568
568
 
569
- size.usize = round(size.usize * (visVP[2] - visVP[0]) / (vport[2] - vport[0]));
570
- size.vsize = round(size.vsize * (visVP[3] - visVP[1]) / (vport[3] - vport[1]));
569
+ size[0] = round(size[0] * (visVP[2] - visVP[0]) / (vport[2] - vport[0]));
570
+ size[1] = round(size[1] * (visVP[3] - visVP[1]) / (vport[3] - vport[1]));
571
571
  var winSize = model.openGLRenderer.getParent().getSize();
572
572
  var xoff = round(actorPos[0] - (visVP[0] - vport[0]) * winSize[0]);
573
573
  var yoff = round(actorPos[1] - (visVP[1] - vport[1]) * winSize[1]); // set ortho projection
574
574
 
575
575
  var left = -xoff;
576
- var right = -xoff + size.usize;
576
+ var right = -xoff + size[0];
577
577
  var bottom = -yoff;
578
- var top = -yoff + size.vsize; // it's an error to call glOrtho with
578
+ var top = -yoff + size[1]; // it's an error to call glOrtho with
579
579
  // either left==right or top==bottom
580
580
 
581
581
  if (left === right) {
@@ -21,6 +21,13 @@ export interface IOptions {
21
21
  scale: number
22
22
  }
23
23
 
24
+ export interface I3DContextOptions {
25
+ preserveDrawingBuffer?: boolean;
26
+ depth?: boolean;
27
+ alpha?: boolean;
28
+ powerPreference?: string;
29
+ }
30
+
24
31
  type vtkOpenGLRenderWindowBase = vtkObject & Omit<vtkAlgorithm,
25
32
  | 'getInputData'
26
33
  | 'setInputData'
@@ -197,9 +204,9 @@ export interface vtkOpenGLRenderWindow extends vtkOpenGLRenderWindowBase {
197
204
 
198
205
  /**
199
206
  *
200
- * @param options
207
+ * @param {I3DContextOptions} options
201
208
  */
202
- get3DContext(options: object): Nullable<WebGLRenderingContext>;
209
+ get3DContext(options: I3DContextOptions): Nullable<WebGLRenderingContext>;
203
210
 
204
211
  /**
205
212
  *
@@ -223,7 +223,8 @@ function vtkOpenGLRenderWindow(publicAPI, model) {
223
223
  var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {
224
224
  preserveDrawingBuffer: false,
225
225
  depth: true,
226
- alpha: true
226
+ alpha: true,
227
+ powerPreference: 'high-performance'
227
228
  };
228
229
  var result = null; // Do we have webxr support
229
230
 
@@ -199,7 +199,9 @@ function vtkWebGPURenderWindow(publicAPI, model) {
199
199
  switch (_context.prev = _context.next) {
200
200
  case 0:
201
201
  _context.next = 2;
202
- return navigator.gpu.requestAdapter();
202
+ return navigator.gpu.requestAdapter({
203
+ powerPreference: 'high-performance'
204
+ });
203
205
 
204
206
  case 2:
205
207
  model.adapter = _context.sent;
@@ -0,0 +1,131 @@
1
+ import vtkDataArray from '../../Common/Core/DataArray.js';
2
+ import vtkPolyData from '../../Common/DataModel/PolyData.js';
3
+ import vtkSphereSource from '../../Filters/Sources/SphereSource.js';
4
+ import vtkActor from '../../Rendering/Core/Actor.js';
5
+ import vtkGlyph3DMapper from '../../Rendering/Core/Glyph3DMapper.js';
6
+ import { ScalarMode } from '../../Rendering/Core/Mapper/Constants.js';
7
+ import vtkContextRepresentation from './ContextRepresentation.js';
8
+ import vtkWidgetRepresentation from './WidgetRepresentation.js';
9
+ import macro from '../../macros.js';
10
+
11
+ function vtkSphereContextRepresentation(publicAPI, model) {
12
+ model.classHierarchy.push('vtkSphereContextRepresentation');
13
+ model.internalPolyData = vtkPolyData.newInstance({
14
+ mtime: 0
15
+ });
16
+ model.internalArrays = {
17
+ points: model.internalPolyData.getPoints(),
18
+ scale: vtkDataArray.newInstance({
19
+ name: 'scale',
20
+ numberOfComponents: 3,
21
+ empty: true
22
+ }),
23
+ color: vtkDataArray.newInstance({
24
+ name: 'color',
25
+ numberOfComponents: 1,
26
+ empty: true
27
+ })
28
+ };
29
+ model.internalPolyData.getPointData().addArray(model.internalArrays.scale);
30
+ model.internalPolyData.getPointData().addArray(model.internalArrays.color);
31
+ model.pipelines = {
32
+ circle: {
33
+ source: publicAPI,
34
+ glyph: vtkSphereSource.newInstance({
35
+ phiResolution: model.glyphResolution,
36
+ thetaResolution: model.glyphResolution
37
+ }),
38
+ mapper: vtkGlyph3DMapper.newInstance({
39
+ scaleArray: 'scale',
40
+ scaleMode: vtkGlyph3DMapper.ScaleModes.SCALE_BY_MAGNITUDE,
41
+ colorByArrayName: 'color',
42
+ scalarMode: ScalarMode.USE_POINT_FIELD_DATA
43
+ }),
44
+ actor: vtkActor.newInstance({
45
+ pickable: false,
46
+ parentProp: publicAPI
47
+ })
48
+ }
49
+ };
50
+ model.pipelines.circle.actor.getProperty().setOpacity(0.2);
51
+ vtkWidgetRepresentation.connectPipeline(model.pipelines.circle);
52
+ publicAPI.addActor(model.pipelines.circle.actor);
53
+ publicAPI.setGlyphResolution = macro.chain(publicAPI.setGlyphResolution, function (r) {
54
+ return model.pipelines.circle.glyph.setResolution(r);
55
+ });
56
+
57
+ publicAPI.setDrawBorder = function (draw) {
58
+ model.pipelines.circle.glyph.setLines(draw);
59
+ };
60
+
61
+ publicAPI.setDrawFace = function (draw) {
62
+ model.pipelines.circle.glyph.setFace(draw);
63
+ };
64
+
65
+ publicAPI.setOpacity = function (opacity) {
66
+ model.pipelines.circle.actor.getProperty().setOpacity(opacity);
67
+ };
68
+
69
+ publicAPI.requestData = function (inData, outData) {
70
+ var _model$internalArrays = model.internalArrays,
71
+ points = _model$internalArrays.points,
72
+ scale = _model$internalArrays.scale,
73
+ color = _model$internalArrays.color;
74
+ var list = publicAPI.getRepresentationStates(inData[0]).filter(function (state) {
75
+ return state.getOrigin && state.getOrigin() && state.isVisible && state.isVisible();
76
+ });
77
+ var totalCount = list.length;
78
+
79
+ if (color.getNumberOfValues() !== totalCount) {
80
+ // Need to resize dataset
81
+ points.setData(new Float32Array(3 * totalCount));
82
+ scale.setData(new Float32Array(3 * totalCount));
83
+ color.setData(new Float32Array(totalCount));
84
+ }
85
+
86
+ var typedArray = {
87
+ points: points.getData(),
88
+ scale: scale.getData(),
89
+ color: color.getData()
90
+ };
91
+
92
+ for (var i = 0; i < totalCount; i += 1) {
93
+ var state = list[i];
94
+ var isActive = state.getActive();
95
+ var scaleFactor = isActive ? model.activeScaleFactor : 1;
96
+ var coord = state.getOrigin();
97
+ typedArray.points[i * 3 + 0] = coord[0];
98
+ typedArray.points[i * 3 + 1] = coord[1];
99
+ typedArray.points[i * 3 + 2] = coord[2];
100
+ typedArray.scale[i] = scaleFactor * (state.getScale1 ? state.getScale1() : model.defaultScale);
101
+ typedArray.color[i] = model.useActiveColor && isActive ? model.activeColor : state.getColor();
102
+ }
103
+
104
+ model.internalPolyData.modified();
105
+ outData[0] = model.internalPolyData;
106
+ };
107
+ }
108
+
109
+ var DEFAULT_VALUES = {
110
+ glyphResolution: 32,
111
+ defaultScale: 1,
112
+ drawBorder: false,
113
+ drawFace: true
114
+ }; // ----------------------------------------------------------------------------
115
+
116
+ function extend(publicAPI, model) {
117
+ var initialValues = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
118
+ Object.assign(model, DEFAULT_VALUES, initialValues);
119
+ vtkContextRepresentation.extend(publicAPI, model, initialValues);
120
+ macro.setGet(publicAPI, model, ['glyphResolution', 'defaultScale']);
121
+ macro.get(publicAPI, model, ['glyph', 'mapper', 'actor']);
122
+ vtkSphereContextRepresentation(publicAPI, model);
123
+ } // ----------------------------------------------------------------------------
124
+
125
+ var newInstance = macro.newInstance(extend, 'vtkSphereContextRepresentation');
126
+ var vtkSphereContextRepresentation$1 = {
127
+ newInstance: newInstance,
128
+ extend: extend
129
+ };
130
+
131
+ export { vtkSphereContextRepresentation$1 as default, extend, newInstance };
@@ -0,0 +1,177 @@
1
+ import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
2
+ import macro from '../../../macros.js';
3
+ import { vec3 } from 'gl-matrix';
4
+
5
+ function widgetBehavior(publicAPI, model) {
6
+ var state = model.widgetState;
7
+ var moveHandle = state.getMoveHandle();
8
+ var centerHandle = state.getCenterHandle();
9
+ var borderHandle = state.getBorderHandle();
10
+ var shapeHandle = state.getSphereHandle(); // Set while moving the center or border handle.
11
+
12
+ model.isDragging = false; // The last world coordinate of the mouse cursor during dragging.
13
+
14
+ model.previousPosition = null;
15
+ centerHandle.setManipulator(model.manipulator);
16
+ borderHandle.setManipulator(model.manipulator);
17
+ model.classHierarchy.push('vtkSphereWidgetProp');
18
+ moveHandle.setVisible(true);
19
+ centerHandle.setVisible(false);
20
+ borderHandle.setVisible(false);
21
+ shapeHandle.setVisible(true);
22
+
23
+ function isValidHandle(handle) {
24
+ return handle === centerHandle || handle === borderHandle || handle === moveHandle;
25
+ }
26
+
27
+ function isPlaced() {
28
+ return !!centerHandle.getOrigin() && !!borderHandle.getOrigin();
29
+ } // Update the sphereHandle parameters from {center,border}Handle.
30
+
31
+
32
+ function updateSphere() {
33
+ var center = centerHandle.getOrigin();
34
+ if (!center) return;
35
+ centerHandle.setVisible(true);
36
+ var border = borderHandle.getOrigin();
37
+
38
+ if (border) {
39
+ borderHandle.setVisible(true);
40
+ } else {
41
+ border = moveHandle.getOrigin();
42
+ if (!border) return;
43
+ }
44
+
45
+ if (isPlaced()) {
46
+ moveHandle.setVisible(false);
47
+ }
48
+
49
+ var radius = vec3.distance(center, border);
50
+ shapeHandle.setVisible(true);
51
+ shapeHandle.setOrigin(center);
52
+ shapeHandle.setScale1(radius * 2);
53
+ model.interactor.render();
54
+ }
55
+
56
+ function currentWorldCoords(e) {
57
+ return model.manipulator.handleEvent(e, model.apiSpecificRenderWindow);
58
+ } // Update the sphere's center and radius. Example:
59
+ // handle.setCenterAndRadius([1,2,3], 10);
60
+
61
+
62
+ publicAPI.setCenterAndRadius = function (newCenter, newRadius) {
63
+ var oldCenter = centerHandle.getOrigin();
64
+ var oldBorder = borderHandle.getOrigin();
65
+ var newBorder = [newCenter[0] + newRadius, newCenter[1], newCenter[2]];
66
+
67
+ if (oldBorder) {
68
+ // Move the boundary handle to reflect the new radius, while preserving
69
+ // its direction relative to the center.
70
+ var direction = vec3.sub(vec3.create(), oldBorder, oldCenter);
71
+ var oldRadius = vec3.length(direction);
72
+
73
+ if (oldRadius > 1e-10) {
74
+ newBorder = vec3.add(vec3.create(), newCenter, vec3.scale(vec3.create(), direction, newRadius / oldRadius));
75
+ }
76
+ }
77
+
78
+ centerHandle.setOrigin(newCenter);
79
+ borderHandle.setOrigin(newBorder);
80
+ updateSphere();
81
+ model.widgetManager.enablePicking();
82
+ };
83
+
84
+ publicAPI.handleLeftButtonPress = function (e) {
85
+ if (!isValidHandle(model.activeState)) {
86
+ model.activeState = null;
87
+ return macro.VOID;
88
+ }
89
+
90
+ var worldCoords = currentWorldCoords(e);
91
+
92
+ if (model.activeState === moveHandle) {
93
+ // Initial sphere placement.
94
+ if (!centerHandle.getOrigin()) {
95
+ centerHandle.setOrigin(worldCoords);
96
+ } else if (!borderHandle.getOrigin()) {
97
+ borderHandle.setOrigin(worldCoords);
98
+ }
99
+
100
+ updateSphere();
101
+ }
102
+
103
+ model.isDragging = true;
104
+ model.apiSpecificRenderWindow.setCursor('grabbing');
105
+ model.previousPosition = _toConsumableArray(currentWorldCoords(e));
106
+ publicAPI.invokeStartInteractionEvent();
107
+ return macro.EVENT_ABORT;
108
+ };
109
+
110
+ publicAPI.handleLeftButtonRelease = function (e) {
111
+ if (!model.isDragging) {
112
+ model.activeState = null;
113
+ return macro.VOID;
114
+ }
115
+
116
+ if (isPlaced()) {
117
+ model.previousPosition = null;
118
+ model.widgetManager.enablePicking();
119
+ model.apiSpecificRenderWindow.setCursor('pointer');
120
+ model.isDragging = false;
121
+ model.activeState = null;
122
+ state.deactivate();
123
+ }
124
+
125
+ publicAPI.invokeEndInteractionEvent();
126
+ return macro.EVENT_ABORT;
127
+ };
128
+
129
+ publicAPI.handleMouseMove = function (e) {
130
+ if (!model.isDragging) {
131
+ model.activeState = null;
132
+ return macro.VOID;
133
+ }
134
+
135
+ if (!model.activeState) throw Error('no activestate');
136
+ var worldCoords = currentWorldCoords(e);
137
+ model.activeState.setOrigin(worldCoords);
138
+
139
+ if (model.activeState === centerHandle) {
140
+ // When the sphere is fully placed, and the user is moving the
141
+ // center, we move the whole sphere.
142
+ if (borderHandle.getOrigin()) {
143
+ if (!model.previousPosition) {
144
+ // !previousPosition here happens only immediately
145
+ // after grabFocus, but grabFocus resets
146
+ // borderHandle.origin.
147
+ throw Error("no pos ".concat(model.activeState, " ").concat(model.previousPosition));
148
+ }
149
+
150
+ var translation = vec3.sub(vec3.create(), worldCoords, model.previousPosition);
151
+ borderHandle.setOrigin(vec3.add(vec3.create(), borderHandle.getOrigin(), translation));
152
+ }
153
+ }
154
+
155
+ model.previousPosition = worldCoords;
156
+ updateSphere();
157
+ return macro.VOID;
158
+ };
159
+
160
+ publicAPI.grabFocus = function () {
161
+ moveHandle.setVisible(true);
162
+ centerHandle.setVisible(false);
163
+ borderHandle.setVisible(false);
164
+ centerHandle.setOrigin(null);
165
+ borderHandle.setOrigin(null);
166
+ model.isDragging = true;
167
+ model.activeState = moveHandle;
168
+ model.interactor.render();
169
+ };
170
+
171
+ publicAPI.loseFocus = function () {
172
+ model.isDragging = false;
173
+ model.activeState = null;
174
+ };
175
+ }
176
+
177
+ export { widgetBehavior as default };
@@ -0,0 +1,45 @@
1
+ import vtkStateBuilder from '../../Core/StateBuilder.js';
2
+
3
+ // See https://kitware.github.io/vtk-js/docs/concepts_widgets.html.
4
+
5
+ function stateGenerator() {
6
+ return vtkStateBuilder.createBuilder() // The handle used only for during initial placement.
7
+ .addStateFromMixin({
8
+ labels: ['moveHandle'],
9
+ mixins: ['origin', 'color', 'scale1', 'visible', 'manipulator'],
10
+ name: 'moveHandle',
11
+ initialValues: {
12
+ scale1: 20,
13
+ visible: true
14
+ }
15
+ }) // The handle for the center of the sphere.
16
+ .addStateFromMixin({
17
+ labels: ['centerHandle'],
18
+ mixins: ['origin', 'color', 'scale1', 'visible', 'manipulator'],
19
+ name: 'centerHandle',
20
+ initialValues: {
21
+ scale1: 20,
22
+ visible: true
23
+ }
24
+ }) // The handle for a border point of the sphere.
25
+ .addStateFromMixin({
26
+ labels: ['borderHandle'],
27
+ mixins: ['origin', 'color', 'scale1', 'visible', 'manipulator'],
28
+ name: 'borderHandle',
29
+ initialValues: {
30
+ scale1: 20,
31
+ visible: true
32
+ }
33
+ }) // For displaying the sphere.
34
+ .addStateFromMixin({
35
+ labels: ['sphereHandle'],
36
+ mixins: ['origin', 'color', 'scale1', 'visible', 'orientation'],
37
+ name: 'sphereHandle',
38
+ initialValues: {
39
+ visible: true,
40
+ radius: 1
41
+ }
42
+ }).build();
43
+ }
44
+
45
+ export { stateGenerator as default };
@@ -0,0 +1,50 @@
1
+ import vtkAbstractWidget from '../Core/AbstractWidget';
2
+ import { Vector3, Bounds } from '../../types';
3
+
4
+ export interface ISphereWidgetHandleState {
5
+ getOrigin(): Vector3;
6
+ setOrigin(arg: Vector3): void;
7
+ getColor(): string;
8
+ setColor(arg: string):void;
9
+ getScale1(): number;
10
+ setScale1(arg: number): void;
11
+ getVisible(): boolean;
12
+ setVisible(arg: boolean):void
13
+ setShape(arg: string): void;
14
+ getShape(): string;
15
+ }
16
+
17
+ // The internal state of the widget.
18
+ export interface vtkSphereWidgetState {
19
+ // A handle that defines the center of the sphere.
20
+ getCenterHandle(): ISphereWidgetHandleState;
21
+ // An arbitrary point at the sphere border. Used only to set the radius.
22
+ getBorderHandle(): ISphereWidgetHandleState;
23
+ }
24
+
25
+ // The type of object returned by vtkWidgetManager.addWidget()
26
+ export interface vtkSphereWidgetHandle {
27
+ // Set the sphere parameters.
28
+ setCenterAndRadius(center: Vector3, radius: number): void;
29
+ }
30
+
31
+ export interface vtkSphereWidget {
32
+ // Abstract widget methods.
33
+ getWidgetState(): vtkSphereWidgetState;
34
+ onWidgetChange(fn: () => void): void;
35
+ placeWidget(bounds: Bounds): void;
36
+ setPlaceFactor(factor: number): void;
37
+
38
+ // Methods specific to vtkSphereWidget.
39
+ getRadius(): number;
40
+ }
41
+
42
+ export interface ISphereWidgetInitialValues {}
43
+
44
+ export function newInstance(props?: ISphereWidgetInitialValues): vtkSphereWidget;
45
+
46
+ export const vtkSphereWidget: {
47
+ newInstance: typeof newInstance;
48
+ };
49
+
50
+ export default vtkSphereWidget;
@@ -0,0 +1,62 @@
1
+ import { f as distance2BetweenPoints } from '../../Common/Core/Math/index.js';
2
+ import vtkAbstractWidgetFactory from '../Core/AbstractWidgetFactory.js';
3
+ import vtkPlanePointManipulator from '../Manipulators/PlaneManipulator.js';
4
+ import vtkSphereHandleRepresentation from '../Representations/SphereHandleRepresentation.js';
5
+ import vtkSphereContextRepresentation from '../Representations/SphereContextRepresentation.js';
6
+ import macro from '../../macros.js';
7
+ import widgetBehavior from './SphereWidget/behavior.js';
8
+ import stateGenerator from './SphereWidget/state.js';
9
+
10
+ function vtkSphereWidget(publicAPI, model) {
11
+ model.classHierarchy.push('vtkSphereWidget');
12
+ model.behavior = widgetBehavior;
13
+
14
+ publicAPI.getRepresentationsForViewType = function (viewType) {
15
+ return [{
16
+ builder: vtkSphereHandleRepresentation,
17
+ labels: ['moveHandle'],
18
+ initialValues: {
19
+ scaleInPixels: true
20
+ }
21
+ }, {
22
+ builder: vtkSphereHandleRepresentation,
23
+ labels: ['centerHandle'],
24
+ initialValues: {
25
+ scaleInPixels: true
26
+ }
27
+ }, {
28
+ builder: vtkSphereHandleRepresentation,
29
+ labels: ['borderHandle'],
30
+ initialValues: {
31
+ scaleInPixels: true
32
+ }
33
+ }, {
34
+ builder: vtkSphereContextRepresentation,
35
+ labels: ['sphereHandle']
36
+ }];
37
+ };
38
+
39
+ publicAPI.getRadius = function () {
40
+ var h1 = model.widgetState.getCenterHandle();
41
+ var h2 = model.widgetState.getBorderHandle();
42
+ return Math.sqrt(distance2BetweenPoints(h1.getOrigin(), h2.getOrigin()));
43
+ };
44
+
45
+ model.manipulator = vtkPlanePointManipulator.newInstance();
46
+ model.widgetState = stateGenerator();
47
+ }
48
+
49
+ function extend(publicAPI, model) {
50
+ var initialValues = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
51
+ Object.assign(model, {}, initialValues);
52
+ vtkAbstractWidgetFactory.extend(publicAPI, model, initialValues);
53
+ macro.setGet(publicAPI, model, ['manipulator', 'widgetState']);
54
+ vtkSphereWidget(publicAPI, model);
55
+ }
56
+ var newInstance = macro.newInstance(extend, 'vtkSphereWidget');
57
+ var index = {
58
+ newInstance: newInstance,
59
+ extend: extend
60
+ };
61
+
62
+ export { index as default, extend, newInstance };
package/index.d.ts CHANGED
@@ -46,8 +46,8 @@
46
46
  /// <reference path="./Filters/General/ImageStreamline.d.ts" />
47
47
  /// <reference path="./Filters/General/LineFilter.d.ts" />
48
48
  /// <reference path="./Filters/General/OutlineFilter.d.ts" />
49
- /// <reference path="./Filters/General/TubeFilter.d.ts" />
50
49
  /// <reference path="./Filters/General/TriangleFilter.d.ts" />
50
+ /// <reference path="./Filters/General/TubeFilter.d.ts" />
51
51
  /// <reference path="./Filters/Sources/Arrow2DSource.d.ts" />
52
52
  /// <reference path="./Filters/Sources/ArrowSource.d.ts" />
53
53
  /// <reference path="./Filters/Sources/CircleSource.d.ts" />
@@ -143,4 +143,5 @@
143
143
  /// <reference path="./Widgets/Manipulators/TrackballManipulator.d.ts" />
144
144
  /// <reference path="./Widgets/Representations/ResliceCursorContextRepresentation.d.ts" />
145
145
  /// <reference path="./Widgets/Representations/WidgetRepresentation.d.ts" />
146
+ /// <reference path="./Widgets/Widgets3D/SphereWidget.d.ts" />
146
147
  /// <reference path="./Common/Core/Math.d.ts" />
package/interfaces.d.ts CHANGED
@@ -1,6 +1,4 @@
1
1
  import vtkDataArray from '././Common/Core/DataArray';
2
- import vtkImageData from '././Common/DataModel/ImageData';
3
- import vtkPolyData from '././Common/DataModel/PolyData';
4
2
  import { vtkPipelineConnection } from '././types';
5
3
 
6
4
  /**
@@ -37,10 +35,10 @@ export interface vtkAlgorithm {
37
35
 
38
36
  /**
39
37
  * Assign a data object as input.
40
- * @param {vtkPolyData} dataset
38
+ * @param dataset The dataset object.
41
39
  * @param {Number} [port] The port number (default 0).
42
40
  */
43
- setInputData(dataset: vtkPolyData, port?: number): void;
41
+ setInputData(dataset: any, port?: number): void;
44
42
 
45
43
  /**
46
44
  * @param {Number} [port] The port number (default 0).
@@ -75,7 +73,7 @@ export interface vtkAlgorithm {
75
73
  * port.
76
74
  * @param {Number} [port] The port number (default 0).
77
75
  */
78
- getOutputData(port?: number): vtkImageData | vtkPolyData;
76
+ getOutputData(port?: number): any;
79
77
 
80
78
  /**
81
79
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kitware/vtk.js",
3
- "version": "24.0.0-beta.1",
3
+ "version": "24.0.1",
4
4
  "description": "Visualization Toolkit for the Web",
5
5
  "keywords": [
6
6
  "3d",