@kitware/vtk.js 23.2.0 → 23.4.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.
@@ -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 };
@@ -1,7 +1,7 @@
1
1
  import _defineProperty from '@babel/runtime/helpers/defineProperty';
2
2
  import macro from '../../macros.js';
3
3
  import vtkAbstractImageInterpolator from './AbstractImageInterpolator.js';
4
- import { vtkInterpolationMathRound, vtkInterpolationMathClamp, vtkInterpolationMathMirror, vtkInterpolationMathWrap, vtkInterpolationWeights, vtkInterpolationMathFloor } from './AbstractImageInterpolator/InterpolationInfo.js';
4
+ import { vtkInterpolationMathRound, vtkInterpolationMathClamp, vtkInterpolationMathMirror, vtkInterpolationMathWrap, vtkInterpolationMathFloor, vtkInterpolationWeights } from './AbstractImageInterpolator/InterpolationInfo.js';
5
5
  import { InterpolationMode, ImageBorderMode } from './AbstractImageInterpolator/Constants.js';
6
6
 
7
7
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
@@ -92,10 +92,80 @@ function vtkImageInterpolator(publicAPI, model) {
92
92
  }
93
93
  };
94
94
 
95
+ publicAPI.interpolateLinear = function (interpolationInfo, point, value) {
96
+ var inExt = interpolationInfo.extent;
97
+ var inInc = interpolationInfo.increments;
98
+ var numscalars = interpolationInfo.numberOfComponents;
99
+ var floorX = vtkInterpolationMathFloor(point[0]);
100
+ var floorY = vtkInterpolationMathFloor(point[1]);
101
+ var floorZ = vtkInterpolationMathFloor(point[2]);
102
+ var inIdX0 = floorX.floored;
103
+ var inIdY0 = floorY.floored;
104
+ var inIdZ0 = floorZ.floored;
105
+ var fx = floorX.error;
106
+ var fy = floorY.error;
107
+ var fz = floorZ.error;
108
+ var inIdX1 = inIdX0 + (fx !== 0);
109
+ var inIdY1 = inIdY0 + (fy !== 0);
110
+ var inIdZ1 = inIdZ0 + (fz !== 0);
111
+
112
+ switch (interpolationInfo.borderMode) {
113
+ case ImageBorderMode.REPEAT:
114
+ inIdX0 = vtkInterpolationMathWrap(inIdX0, inExt[0], inExt[1]);
115
+ inIdY0 = vtkInterpolationMathWrap(inIdY0, inExt[2], inExt[3]);
116
+ inIdZ0 = vtkInterpolationMathWrap(inIdZ0, inExt[4], inExt[5]);
117
+ inIdX1 = vtkInterpolationMathWrap(inIdX1, inExt[0], inExt[1]);
118
+ inIdY1 = vtkInterpolationMathWrap(inIdY1, inExt[2], inExt[3]);
119
+ inIdZ1 = vtkInterpolationMathWrap(inIdZ1, inExt[4], inExt[5]);
120
+ break;
121
+
122
+ case ImageBorderMode.MIRROR:
123
+ inIdX0 = vtkInterpolationMathMirror(inIdX0, inExt[0], inExt[1]);
124
+ inIdY0 = vtkInterpolationMathMirror(inIdY0, inExt[2], inExt[3]);
125
+ inIdZ0 = vtkInterpolationMathMirror(inIdZ0, inExt[4], inExt[5]);
126
+ inIdX1 = vtkInterpolationMathMirror(inIdX1, inExt[0], inExt[1]);
127
+ inIdY1 = vtkInterpolationMathMirror(inIdY1, inExt[2], inExt[3]);
128
+ inIdZ1 = vtkInterpolationMathMirror(inIdZ1, inExt[4], inExt[5]);
129
+ break;
130
+
131
+ default:
132
+ inIdX0 = vtkInterpolationMathClamp(inIdX0, inExt[0], inExt[1]);
133
+ inIdY0 = vtkInterpolationMathClamp(inIdY0, inExt[2], inExt[3]);
134
+ inIdZ0 = vtkInterpolationMathClamp(inIdZ0, inExt[4], inExt[5]);
135
+ inIdX1 = vtkInterpolationMathClamp(inIdX1, inExt[0], inExt[1]);
136
+ inIdY1 = vtkInterpolationMathClamp(inIdY1, inExt[2], inExt[3]);
137
+ inIdZ1 = vtkInterpolationMathClamp(inIdZ1, inExt[4], inExt[5]);
138
+ break;
139
+ }
140
+
141
+ var factX0 = inIdX0 * inInc[0];
142
+ var factX1 = inIdX1 * inInc[0];
143
+ var factY0 = inIdY0 * inInc[1];
144
+ var factY1 = inIdY1 * inInc[1];
145
+ var factZ0 = inIdZ0 * inInc[2];
146
+ var factZ1 = inIdZ1 * inInc[2];
147
+ var i00 = factY0 + factZ0;
148
+ var i01 = factY0 + factZ1;
149
+ var i10 = factY1 + factZ0;
150
+ var i11 = factY1 + factZ1;
151
+ var rx = 1 - fx;
152
+ var ry = 1 - fy;
153
+ var rz = 1 - fz;
154
+ var ryrz = ry * rz;
155
+ var fyrz = fy * rz;
156
+ var ryfz = ry * fz;
157
+ var fyfz = fy * fz;
158
+ var inPtr = interpolationInfo.pointer;
159
+
160
+ for (var i = 0; i < numscalars; ++i) {
161
+ value[i] = rx * (ryrz * inPtr[factX0 + i00 + i * 4] + ryfz * inPtr[factX0 + i01 + i * 4] + fyrz * inPtr[factX0 + i10 + i * 4] + fyfz * inPtr[factX0 + i11 + i * 4]) + fx * (ryrz * inPtr[factX1 + i00 + i * 4] + ryfz * inPtr[factX1 + i01 + i * 4] + fyrz * inPtr[factX1 + i10 + i * 4] + fyfz * inPtr[factX1 + i11 + i * 4]);
162
+ }
163
+ };
164
+
95
165
  publicAPI.interpolatePoint = function (interpolationInfo, point, value) {
96
166
  switch (model.interpolationMode) {
97
167
  case InterpolationMode.LINEAR:
98
- console.log('LINEAR not implemented');
168
+ publicAPI.interpolateLinear(interpolationInfo, point, value);
99
169
  break;
100
170
 
101
171
  case InterpolationMode.CUBIC:
@@ -123,10 +193,115 @@ function vtkImageInterpolator(publicAPI, model) {
123
193
  }
124
194
  };
125
195
 
196
+ publicAPI.interpolateRowLinear = function (weights, idX, idY, idZ, outPtr, n) {
197
+ var stepX = weights.kernelSize[0];
198
+ var stepY = weights.kernelSize[1];
199
+ var stepZ = weights.kernelSize[2];
200
+ var idXtemp = idX * stepX;
201
+ var idYtemp = idY * stepY;
202
+ var idZtemp = idZ * stepZ;
203
+ var fX = weights.weights[0].subarray(idXtemp);
204
+ var fY = weights.weights[1].subarray(idYtemp);
205
+ var fZ = weights.weights[2].subarray(idZtemp);
206
+ var iX = weights.positions[0].subarray(idXtemp);
207
+ var iY = weights.positions[1].subarray(idYtemp);
208
+ var iZ = weights.positions[2].subarray(idZtemp);
209
+ var inPtr = weights.pointer; // get the number of components per pixel
210
+
211
+ var numscalars = weights.numberOfComponents; // create a 2x2 bilinear kernel in local variables
212
+
213
+ var i00 = iY.subarray(iZ[0]);
214
+ var i01 = i00;
215
+ var i10 = i00;
216
+ var i11 = i00;
217
+ var ry = 1;
218
+ var fy = 0;
219
+ var rz = 1;
220
+ var fz = 0;
221
+
222
+ if (stepY === 2) {
223
+ i10 = iY[1].subarray(iZ[0]);
224
+ i11 = i10;
225
+ ry = fY[0];
226
+ fy = fY[1];
227
+ }
228
+
229
+ if (stepZ === 2) {
230
+ i01 = iY[0].subarray(iZ[1]);
231
+ i11 = i01;
232
+ rz = fZ[0];
233
+ fz = fZ[1];
234
+ }
235
+
236
+ if (stepY + stepZ === 4) {
237
+ i11 = iY[1].subarray(iZ[1]);
238
+ }
239
+
240
+ var ryrz = ry * rz;
241
+ var ryfz = ry * fz;
242
+ var fyrz = fy * rz;
243
+ var fyfz = fy * fz;
244
+
245
+ if (stepX === 1) {
246
+ if (fy === 0 && fz === 0) {
247
+ // no interpolation needed at all
248
+ for (var i = n; i > 0; --i) {
249
+ for (var j = 0; j < numscalars; j++) {
250
+ outPtr[j + n - i] = inPtr[i00 + iX[n - i] + j];
251
+ }
252
+ }
253
+ } else if (fy === 0) {
254
+ // only need linear z interpolation
255
+ for (var _i = n; _i > 0; --_i) {
256
+ for (var _j = 0; _j < numscalars; _j++) {
257
+ outPtr[_j + n - _i] = rz * inPtr[iX[n - _i] + i00 + _j * 4] + fz * inPtr[iX[n - _i] + i01 + _j * 4];
258
+ }
259
+ }
260
+ } else {
261
+ // interpolate in y and z but not in x
262
+ for (var _i2 = n; _i2 > 0; --_i2) {
263
+ for (var _j2 = 0; _j2 < numscalars; _j2++) {
264
+ outPtr[_j2 + n - _i2] = ryrz * inPtr[iX[n - _i2] + i00 + _j2 * 4] + ryfz * inPtr[iX[n - _i2] + i01 + _j2 * 4] + fyrz * inPtr[iX[n - _i2] + i10 + _j2 * 4] + fyfz * inPtr[iX[n - _i2] + i11 + _j2 * 4];
265
+ }
266
+ }
267
+ }
268
+ } else if (fz === 0) {
269
+ var x = 0; // bilinear interpolation in x,y
270
+
271
+ for (var _i3 = n; _i3 > 0; --_i3) {
272
+ var rx = fX[0 + 2 * x];
273
+ var fx = fX[1 + 2 * x];
274
+ var t0 = iX[0 + 2 * x];
275
+ var t1 = iX[1 + 2 * x];
276
+
277
+ for (var _j3 = 0; _j3 < numscalars; _j3++) {
278
+ outPtr[_j3 + n - _i3] = rx * (ry * inPtr[t0 + i00 + _j3 * 4] + fy * inPtr[t0 + i10 + _j3 * 4]) + fx * (ry * inPtr[t1 + i00 + _j3 * 4] + fy * inPtr[t1 + i10 + _j3 * 4]);
279
+ }
280
+
281
+ x++;
282
+ }
283
+ } else {
284
+ var _x = 0; // do full trilinear interpolation
285
+
286
+ for (var _i4 = n; _i4 > 0; --_i4) {
287
+ var _rx = fX[0 + 2 * _x];
288
+ var _fx = fX[1 + 2 * _x];
289
+ var _t = iX[0 + 2 * _x];
290
+ var _t2 = iX[1 + 2 * _x];
291
+
292
+ for (var _j4 = 0; _j4 < numscalars; _j4++) {
293
+ outPtr[_j4] = _rx * (ryrz * inPtr[_t + i00 + _j4 * 4] + ryfz * inPtr[_t + i01 + _j4 * 4] + fyrz * inPtr[_t + i10 + _j4 * 4] + fyfz * inPtr[_t + i11 + _j4 * 4]) + _fx * (ryrz * inPtr[_t2 + i00 + _j4 * 4] + ryfz * inPtr[_t2 + i01 + _j4 * 4] + fyrz * inPtr[_t2 + i10 + _j4 * 4] + fyfz * inPtr[_t2 + i11 + _j4 * 4]);
294
+ }
295
+
296
+ _x++;
297
+ }
298
+ }
299
+ };
300
+
126
301
  publicAPI.interpolateRow = function (weights, xIdx, yIdx, zIdx, value, n) {
127
302
  switch (model.interpolationMode) {
128
303
  case InterpolationMode.LINEAR:
129
- console.log('LINEAR not implemented');
304
+ publicAPI.interpolateRowLinear(weights, xIdx, yIdx, zIdx, value, n);
130
305
  break;
131
306
 
132
307
  case InterpolationMode.CUBIC:
@@ -311,9 +486,9 @@ function vtkImageInterpolator(publicAPI, model) {
311
486
 
312
487
  if (!validClip) {
313
488
  // output extent doesn't itersect input extent
314
- for (var _j = 0; _j < 3; _j++) {
315
- clipExt[2 * _j] = outExt[2 * _j];
316
- clipExt[2 * _j + 1] = outExt[2 * _j] - 1;
489
+ for (var _j5 = 0; _j5 < 3; _j5++) {
490
+ clipExt[2 * _j5] = outExt[2 * _j5];
491
+ clipExt[2 * _j5 + 1] = outExt[2 * _j5] - 1;
317
492
  }
318
493
  }
319
494
  };
@@ -1000,7 +1000,7 @@ function extend(publicAPI, model) {
1000
1000
  macro.obj(publicAPI, model); // Also make it an algorithm with one input and one output
1001
1001
 
1002
1002
  macro.algo(publicAPI, model, 1, 1);
1003
- macro.setGet(publicAPI, model, ['outputDimensionality', 'outputScalarType', 'scalarShift', 'scalarScale', 'transformInputSampling', 'autoCropOutput', 'wrap', 'mirror', 'border', 'backgroundColor', 'slabMode', 'slabTrapezoidIntegration', 'slabNumberOfSlices', 'slabSliceSpacingFraction']);
1003
+ macro.setGet(publicAPI, model, ['outputDimensionality', 'outputScalarType', 'scalarShift', 'scalarScale', 'transformInputSampling', 'autoCropOutput', 'wrap', 'mirror', 'border', 'backgroundColor', 'interpolationMode', 'slabMode', 'slabTrapezoidIntegration', 'slabNumberOfSlices', 'slabSliceSpacingFraction']);
1004
1004
  macro.setGetArray(publicAPI, model, ['outputOrigin', 'outputSpacing'], 3);
1005
1005
  macro.setGetArray(publicAPI, model, ['outputExtent'], 6);
1006
1006
  setNullArray(publicAPI, model, ['outputOrigin', 'outputSpacing', 'outputExtent']);
@@ -544,18 +544,18 @@ function vtkOpenGLPolyDataMapper2D(publicAPI, model) {
544
544
  var shiftScaleEnabled = cellBO.getCABO().getCoordShiftAndScaleEnabled();
545
545
  var inverseShiftScaleMatrix = shiftScaleEnabled ? cellBO.getCABO().getInverseShiftAndScaleMatrix() : null; // Get the position of the actor
546
546
 
547
- var size = model.openGLRenderer.getTiledSizeAndOrigin();
547
+ var view = ren.getRenderWindow().getViews()[0];
548
+ var size = view.getViewportSize(ren);
548
549
  var vport = ren.getViewport();
549
- var actorPos = actor.getActualPositionCoordinate().getComputedViewportValue(ren); // Get the window info
550
- // const tileViewport = ren.getVTKWindow().getTileViewport();
550
+ var actorPos = actor.getActualPositionCoordinate().getComputedDoubleViewportValue(ren); // Get the window info
551
551
  // Assume tile viewport is 0 1 based on vtkOpenGLRenderer
552
552
 
553
553
  var tileViewport = [0.0, 0.0, 1.0, 1.0];
554
- var visVP = [0, 1, 0, 1];
554
+ var visVP = [0.0, 0.0, 1.0, 1.0];
555
555
  visVP[0] = vport[0] >= tileViewport[0] ? vport[0] : tileViewport[0];
556
556
  visVP[1] = vport[1] >= tileViewport[1] ? vport[1] : tileViewport[1];
557
- visVP[2] = vport[2] >= tileViewport[2] ? vport[2] : tileViewport[2];
558
- visVP[3] = vport[3] >= tileViewport[3] ? vport[3] : tileViewport[3];
557
+ visVP[2] = vport[2] <= tileViewport[2] ? vport[2] : tileViewport[2];
558
+ visVP[3] = vport[3] <= tileViewport[3] ? vport[3] : tileViewport[3];
559
559
 
560
560
  if (visVP[0] >= visVP[2]) {
561
561
  return;
@@ -565,16 +565,16 @@ function vtkOpenGLPolyDataMapper2D(publicAPI, model) {
565
565
  return;
566
566
  }
567
567
 
568
- size.usize = round(size.usize * (visVP[2] - visVP[0]) / (vport[2] - vport[0]));
569
- size.vsize = round(size.vsize * (visVP[3] - visVP[1]) / (vport[3] - vport[1]));
568
+ size[0] = round(size[0] * (visVP[2] - visVP[0]) / (vport[2] - vport[0]));
569
+ size[1] = round(size[1] * (visVP[3] - visVP[1]) / (vport[3] - vport[1]));
570
570
  var winSize = model.openGLRenderer.getParent().getSize();
571
571
  var xoff = round(actorPos[0] - (visVP[0] - vport[0]) * winSize[0]);
572
572
  var yoff = round(actorPos[1] - (visVP[1] - vport[1]) * winSize[1]); // set ortho projection
573
573
 
574
574
  var left = -xoff;
575
- var right = -xoff + size.usize;
575
+ var right = -xoff + size[0];
576
576
  var bottom = -yoff;
577
- var top = -yoff + size.vsize; // it's an error to call glOrtho with
577
+ var top = -yoff + size[1]; // it's an error to call glOrtho with
578
578
  // either left==right or top==bottom
579
579
 
580
580
  if (left === right) {
@@ -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
@@ -90,7 +90,6 @@
90
90
  /// <reference path="./IO/XML/XMLPolyDataReader.d.ts" />
91
91
  /// <reference path="./IO/XML/XMLReader.d.ts" />
92
92
  /// <reference path="./Rendering/Core/AbstractMapper.d.ts" />
93
- /// <reference path="./Rendering/Core/AbstractMapper3D.d.ts" />
94
93
  /// <reference path="./Rendering/Core/AbstractPicker.d.ts" />
95
94
  /// <reference path="./Rendering/Core/Actor.d.ts" />
96
95
  /// <reference path="./Rendering/Core/Actor2D.d.ts" />
@@ -131,7 +130,6 @@
131
130
  /// <reference path="./Rendering/Misc/FullScreenRenderWindow.d.ts" />
132
131
  /// <reference path="./Rendering/Misc/GenericRenderWindow.d.ts" />
133
132
  /// <reference path="./Rendering/Misc/RemoteView.d.ts" />
134
- /// <reference path="./Rendering/Misc/RenderWindowWithControlBar.d.ts" />
135
133
  /// <reference path="./Rendering/Misc/SynchronizableRenderWindow.d.ts" />
136
134
  /// <reference path="./Rendering/Misc/TextureLODsDownloader.d.ts" />
137
135
  /// <reference path="./Rendering/OpenGL/RenderWindow.d.ts" />
@@ -143,4 +141,7 @@
143
141
  /// <reference path="./Widgets/Manipulators/TrackballManipulator.d.ts" />
144
142
  /// <reference path="./Widgets/Representations/ResliceCursorContextRepresentation.d.ts" />
145
143
  /// <reference path="./Widgets/Representations/WidgetRepresentation.d.ts" />
144
+ /// <reference path="./Widgets/Widgets3D/SphereWidget.d.ts" />
145
+ /// <reference path="./Rendering/Core/AbstractMapper3D.d.ts" />
146
+ /// <reference path="./Rendering/Misc/RenderWindowWithControlBar.d.ts" />
146
147
  /// <reference path="./Common/Core/Math.d.ts" />
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kitware/vtk.js",
3
- "version": "23.2.0",
3
+ "version": "23.4.0",
4
4
  "description": "Visualization Toolkit for the Web",
5
5
  "keywords": [
6
6
  "3d",