@kitware/vtk.js 26.9.9 → 26.9.12

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.
@@ -63,6 +63,12 @@ export interface vtkRenderer extends vtkViewport {
63
63
  */
64
64
  addActor(actor: vtkProp): boolean;
65
65
 
66
+ /**
67
+ * Check if the renderer already has the specified light.
68
+ * @param {vtkLight} light The vtkLight instance.
69
+ */
70
+ hasLight(light: vtkLight): boolean;
71
+
66
72
  /**
67
73
  * Add a light to the list of lights.
68
74
  * @param {vtkLight} light The vtkLight instance.
@@ -192,9 +192,15 @@ function vtkRenderer(publicAPI, model) {
192
192
  publicAPI.modified();
193
193
  };
194
194
 
195
+ publicAPI.hasLight = function (light) {
196
+ return model.lights.includes(light);
197
+ };
198
+
195
199
  publicAPI.addLight = function (light) {
196
- model.lights = [].concat(model.lights, light);
197
- publicAPI.modified();
200
+ if (light && !publicAPI.hasLight(light)) {
201
+ model.lights.push(light);
202
+ publicAPI.modified();
203
+ }
198
204
  };
199
205
 
200
206
  publicAPI.removeLight = function (light) {
@@ -20,14 +20,12 @@ function vtkViewport(publicAPI, model) {
20
20
  };
21
21
 
22
22
  publicAPI.hasViewProp = function (prop) {
23
- return !!model.props.filter(function (item) {
24
- return item === prop;
25
- }).length;
23
+ return model.props.includes(prop);
26
24
  };
27
25
 
28
26
  publicAPI.addViewProp = function (prop) {
29
27
  if (prop && !publicAPI.hasViewProp(prop)) {
30
- model.props = model.props.concat(prop);
28
+ model.props.push(prop);
31
29
  }
32
30
  };
33
31
 
@@ -1,6 +1,54 @@
1
+ import _classCallCheck from '@babel/runtime/helpers/classCallCheck';
2
+ import _createClass from '@babel/runtime/helpers/createClass';
1
3
  import vtkCameraSynchronizer from './BehaviorManager/CameraSynchronizer.js';
2
4
 
3
5
  var BEHAVIORS = {};
6
+
7
+ var CameraSync = /*#__PURE__*/function () {
8
+ function CameraSync(ctx, config) {
9
+ _classCallCheck(this, CameraSync);
10
+
11
+ this.ctx = ctx;
12
+ this.behavior = vtkCameraSynchronizer.newInstance(this.getProperties(config));
13
+ this.behavior.update();
14
+ }
15
+
16
+ _createClass(CameraSync, [{
17
+ key: "getProperties",
18
+ value: function getProperties(_ref) {
19
+ var actorBounds = _ref.actorBounds,
20
+ srcRenderer = _ref.srcRenderer,
21
+ dstRenderer = _ref.dstRenderer;
22
+ var distance = 3.4 * Math.max(actorBounds[1] - actorBounds[0], actorBounds[3] - actorBounds[2], actorBounds[5] - actorBounds[4]);
23
+ var focalPoint = [0.5 * (actorBounds[0] + actorBounds[1]), 0.5 * (actorBounds[2] + actorBounds[3]), 0.5 * (actorBounds[4] + actorBounds[5])];
24
+ var mode = vtkCameraSynchronizer.SynchronizationMode.MODE_ORIENTATION;
25
+ return {
26
+ distance: distance,
27
+ focalPoint: focalPoint,
28
+ mode: mode,
29
+ srcRenderer: this.ctx.getInstance(srcRenderer),
30
+ dstRenderer: this.ctx.getInstance(dstRenderer)
31
+ };
32
+ }
33
+ }, {
34
+ key: "update",
35
+ value: function update(config) {
36
+ this.behavior.set(this.getProperties(config));
37
+ this.behavior.update();
38
+ }
39
+ }, {
40
+ key: "delete",
41
+ value: function _delete() {
42
+ this.behavior.delete();
43
+ }
44
+ }]);
45
+
46
+ return CameraSync;
47
+ }();
48
+
49
+ var BEHAVIORS_TYPES = {
50
+ CameraSync: CameraSync
51
+ };
4
52
  function applyBehaviors(renderWindow, state, context) {
5
53
  if (!state.behaviors || !renderWindow.getSynchronizedViewId) {
6
54
  return;
@@ -44,9 +92,37 @@ function applyBehaviors(renderWindow, state, context) {
44
92
  localBehaviors.autoOrientationAxes.delete();
45
93
  delete localBehaviors.autoOrientationAxes;
46
94
  }
47
- } // Process remaining behaviors...
48
- // TODO - widgets(orientation, ...)
95
+ }
96
+
97
+ var currentSets = Object.keys(state.behaviors);
98
+ var existingSets = Object.keys(localBehaviors);
99
+
100
+ for (var _i = 0; _i < currentSets.length; _i++) {
101
+ var key = currentSets[_i];
102
+
103
+ if (!localBehaviors[key]) {
104
+ var config = state.behaviors[key];
105
+
106
+ if (BEHAVIORS_TYPES[config.type]) {
107
+ localBehaviors[key] = new BEHAVIORS_TYPES[config.type](context, config);
108
+ } else {
109
+ console.log('No mapping for', config);
110
+ }
111
+ } else {
112
+ localBehaviors[key].update(state.behaviors[key]);
113
+ }
114
+ }
115
+
116
+ for (var _i2 = 0; _i2 < existingSets.length; _i2++) {
117
+ var _key = currentSets[_i2];
118
+
119
+ if (!state.behaviors[_key]) {
120
+ // Need to delete previously created behavior
121
+ localBehaviors[_key].delete();
49
122
 
123
+ delete localBehaviors[_key];
124
+ }
125
+ }
50
126
  }
51
127
  var BehaviorManager = {
52
128
  applyBehaviors: applyBehaviors
@@ -282,7 +282,7 @@ function genericUpdater(instance, state, context) {
282
282
 
283
283
  if (state.arrays) {
284
284
  var arraysToBind = [];
285
- var promises = state.arrays.map(function (arrayMetadata) {
285
+ var promises = Object.values(state.arrays).map(function (arrayMetadata) {
286
286
  context.start(); // -> start(arrays)
287
287
 
288
288
  return context.getArray(arrayMetadata.hash, arrayMetadata.dataType, context).then(createNewArrayHandler(instance, arrayMetadata, arraysToBind)).catch(function (error) {
@@ -416,9 +416,7 @@ function vtkRenderWindowUpdater(instance, state, context) {
416
416
  }
417
417
 
418
418
  context.unregisterInstance(context.getInstanceId(viewProp));
419
- }); // Now just remove all the view props
420
-
421
- renderer.removeAllViewProps();
419
+ });
422
420
  });
423
421
  });
424
422
  }
@@ -505,31 +503,41 @@ function removeUnavailableArrays(fields, availableNames) {
505
503
  function createDataSetUpdate() {
506
504
  var piecesToFetch = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
507
505
  return function (instance, state, context) {
508
- var _state$arrays;
509
-
510
506
  context.start(); // -> start(dataset-update)
511
507
  // Make sure we provide container for std arrays
512
508
 
509
+ var localProperties = _objectSpread({}, state.properties);
510
+
513
511
  if (!state.arrays) {
514
- state.arrays = [];
512
+ state.arrays = {};
515
513
  } // Array members
516
514
  // => convert old format to generic state.arrays
517
515
 
518
516
 
519
- piecesToFetch.forEach(function (key) {
517
+ for (var i = 0; i < piecesToFetch.length; i++) {
518
+ var key = piecesToFetch[i];
519
+
520
520
  if (state.properties[key]) {
521
521
  var arrayMeta = state.properties[key];
522
522
  arrayMeta.registration = "set".concat(capitalize(key));
523
- state.arrays.push(arrayMeta);
524
- delete state.properties[key];
523
+ var arrayKey = "".concat(arrayMeta.hash, "_").concat(arrayMeta.dataType);
524
+ state.arrays[arrayKey] = arrayMeta;
525
+ delete localProperties[key];
525
526
  }
526
- }); // Extract dataset fields
527
+ } // Extract dataset fields
528
+
527
529
 
528
530
  var fieldsArrays = state.properties.fields || [];
529
531
 
530
- (_state$arrays = state.arrays).push.apply(_state$arrays, _toConsumableArray(fieldsArrays));
532
+ for (var _i2 = 0; _i2 < fieldsArrays.length; _i2++) {
533
+ var _arrayMeta = fieldsArrays[_i2];
534
+
535
+ var _arrayKey = "".concat(_arrayMeta.hash, "_").concat(_arrayMeta.dataType);
531
536
 
532
- delete state.properties.fields; // Reset any pre-existing fields array
537
+ state.arrays[_arrayKey] = _arrayMeta;
538
+ }
539
+
540
+ delete localProperties.fields; // Reset any pre-existing fields array
533
541
 
534
542
  var arrayToKeep = {
535
543
  pointData: new Set(),
@@ -544,7 +552,10 @@ function createDataSetUpdate() {
544
552
  removeUnavailableArrays(instance.getPointData(), arrayToKeep.pointData);
545
553
  removeUnavailableArrays(instance.getCellData(), arrayToKeep.cellData); // Generic handling
546
554
 
547
- var res = genericUpdater(instance, state, context); // Finish what we started
555
+ var cleanState = _objectSpread({}, state);
556
+
557
+ cleanState.properties = localProperties;
558
+ var res = genericUpdater(instance, cleanState, context); // Finish what we started
548
559
 
549
560
  context.end(); // -> end(dataset-update)
550
561
 
@@ -121,6 +121,9 @@ function createInstanceMap() {
121
121
 
122
122
  function registerInstance(id, instance) {
123
123
  instances[id] = instance;
124
+ instance.set({
125
+ remoteId: id
126
+ }, true, true);
124
127
  }
125
128
 
126
129
  function unregisterInstance(id) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kitware/vtk.js",
3
- "version": "26.9.9",
3
+ "version": "26.9.12",
4
4
  "description": "Visualization Toolkit for the Web",
5
5
  "keywords": [
6
6
  "3d",