@kitware/vtk.js 23.4.3 → 23.4.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (177) hide show
  1. package/Common/Core/Math/Constants.js +12 -0
  2. package/Common/Core/Math/index.js +1 -1
  3. package/Common/Core/Math.js +1 -1
  4. package/Common/Core/ScalarsToColors/Constants.d.ts +18 -0
  5. package/Common/DataModel/AbstractPointLocator.d.ts +54 -0
  6. package/Common/DataModel/AbstractPointLocator.js +40 -0
  7. package/Common/DataModel/BoundingBox.d.ts +659 -0
  8. package/Common/DataModel/Collection.d.ts +118 -0
  9. package/Common/DataModel/Collection.js +113 -0
  10. package/Common/DataModel/DataSet/Constants.d.ts +27 -0
  11. package/Common/DataModel/EdgeLocator.d.ts +79 -0
  12. package/Common/DataModel/EdgeLocator.js +85 -0
  13. package/Common/DataModel/ITKHelper.d.ts +54 -0
  14. package/Common/DataModel/IncrementalOctreeNode.d.ts +297 -0
  15. package/Common/DataModel/IncrementalOctreeNode.js +640 -0
  16. package/Common/DataModel/IncrementalOctreePointLocator.d.ts +61 -0
  17. package/Common/DataModel/IncrementalOctreePointLocator.js +398 -0
  18. package/Common/DataModel/Locator.d.ts +43 -0
  19. package/Common/DataModel/Locator.js +37 -0
  20. package/Common/DataModel/Plane.js +1 -1
  21. package/Common/DataModel/PolyData/Constants.d.ts +6 -0
  22. package/Common/DataModel/PolyLine.d.ts +63 -0
  23. package/Common/DataModel/PolyLine.js +77 -0
  24. package/Common/DataModel/Polygon/Constants.js +12 -0
  25. package/Common/DataModel/Polygon.js +1 -1
  26. package/Common/DataModel/Quad/Constants.js +9 -0
  27. package/Common/DataModel/Quad.d.ts +91 -0
  28. package/Common/DataModel/Quad.js +235 -0
  29. package/Common/DataModel/SelectionNode/Constants.d.ts +27 -0
  30. package/Common/DataModel/Spline1D/Constants.js +17 -0
  31. package/Common/DataModel/Spline3D/Constants.d.ts +9 -0
  32. package/Common/Transform/Transform.js +51 -0
  33. package/Filters/Core/PolyDataNormals.js +124 -0
  34. package/Filters/General/ClipClosedSurface/Constants.js +10 -0
  35. package/Filters/General/ClipClosedSurface.d.ts +95 -0
  36. package/Filters/General/ClipClosedSurface.js +972 -0
  37. package/Filters/General/ContourTriangulator/Constants.js +6 -0
  38. package/Filters/General/ContourTriangulator/helper.js +1951 -0
  39. package/Filters/General/ContourTriangulator.d.ts +136 -0
  40. package/Filters/General/ContourTriangulator.js +202 -0
  41. package/Filters/General/ImageMarchingCubes.js +1 -1
  42. package/Filters/General/MoleculeToRepresentation.js +1 -1
  43. package/Filters/General/OBBTree/OBBNode.js +82 -0
  44. package/Filters/General/OBBTree/helper.js +92 -0
  45. package/Filters/General/OBBTree.js +1243 -0
  46. package/Filters/General/TubeFilter.js +1 -1
  47. package/Filters/Sources/LineSource.js +1 -1
  48. package/Filters/Sources/PlaneSource.js +1 -1
  49. package/Filters/Texture/TextureMapToPlane.js +1 -1
  50. package/Interaction/Manipulators/CompositeCameraManipulator.d.ts +68 -0
  51. package/Interaction/Manipulators/CompositeGestureManipulator.d.ts +168 -0
  52. package/Interaction/Manipulators/CompositeKeyboardManipulator.d.ts +48 -0
  53. package/Interaction/Manipulators/CompositeMouseManipulator.d.ts +149 -0
  54. package/Interaction/Manipulators/CompositeVRManipulator.d.ts +44 -0
  55. package/Interaction/Manipulators/GestureCameraManipulator.d.ts +34 -0
  56. package/Interaction/Manipulators/KeyboardCameraManipulator.js +1 -1
  57. package/Interaction/Manipulators/MouseBoxSelectorManipulator.d.ts +88 -0
  58. package/Interaction/Manipulators/MouseCameraAxisRotateManipulator.js +1 -1
  59. package/Interaction/Manipulators/MouseCameraTrackballMultiRotateManipulator.d.ts +32 -0
  60. package/Interaction/Manipulators/MouseCameraTrackballPanManipulator.d.ts +33 -0
  61. package/Interaction/Manipulators/MouseCameraTrackballPanManipulator.js +1 -1
  62. package/Interaction/Manipulators/MouseCameraTrackballRollManipulator.d.ts +33 -0
  63. package/Interaction/Manipulators/MouseCameraTrackballRotateManipulator.d.ts +67 -0
  64. package/Interaction/Manipulators/MouseCameraTrackballRotateManipulator.js +1 -1
  65. package/Interaction/Manipulators/MouseCameraTrackballZoomManipulator.d.ts +45 -0
  66. package/Interaction/Manipulators/MouseCameraTrackballZoomToMouseManipulator.d.ts +26 -0
  67. package/Interaction/Manipulators/MouseCameraUnicamManipulator.js +1 -1
  68. package/Interaction/Manipulators/MouseCameraUnicamRotateManipulator.js +1 -1
  69. package/Interaction/Manipulators/MouseRangeManipulator.d.ts +53 -0
  70. package/Interaction/Style/InteractorStyleImage.d.ts +107 -0
  71. package/Interaction/Style/InteractorStyleMPRSlice.js +1 -1
  72. package/Interaction/Style/InteractorStyleManipulator.d.ts +348 -0
  73. package/Interaction/Style/InteractorStyleTrackballCamera.d.ts +170 -0
  74. package/Interaction/Widgets/ImageCroppingRegionsWidget.js +1 -1
  75. package/Interaction/Widgets/LabelRepresentation.js +1 -1
  76. package/Interaction/Widgets/OrientationMarkerWidget/Constants.d.ts +11 -0
  77. package/Interaction/Widgets/ResliceCursor/ResliceCursor.js +1 -1
  78. package/Interaction/Widgets/ResliceCursor/ResliceCursorLineRepresentation.js +1 -1
  79. package/Interaction/Widgets/ResliceCursor/ResliceCursorRepresentation.js +1 -1
  80. package/Proxy/Core/AbstractRepresentationProxy.d.ts +24 -0
  81. package/Proxy/Core/LookupTableProxy.d.ts +45 -0
  82. package/Proxy/Core/PiecewiseFunctionProxy.d.ts +62 -0
  83. package/Proxy/Core/ProxyManager.d.ts +115 -0
  84. package/Proxy/Core/SourceProxy.d.ts +22 -0
  85. package/Proxy/Core/View2DProxy.d.ts +7 -0
  86. package/Proxy/Core/View2DProxy.js +1 -1
  87. package/Proxy/Core/ViewProxy.d.ts +86 -0
  88. package/Proxy/Representations/SliceRepresentationProxy.d.ts +27 -0
  89. package/Proxy/Representations/VolumeRepresentationProxy.d.ts +44 -0
  90. package/README.md +2 -2
  91. package/Rendering/Core/AbstractImageMapper/helper.js +127 -0
  92. package/Rendering/Core/AbstractImageMapper.d.ts +82 -0
  93. package/Rendering/Core/AbstractImageMapper.js +44 -0
  94. package/Rendering/Core/Camera.js +1 -1
  95. package/Rendering/Core/CellPicker.js +1 -1
  96. package/Rendering/Core/ColorTransferFunction/ColorMaps.d.ts +24 -0
  97. package/Rendering/Core/ColorTransferFunction/Constants.d.ts +17 -0
  98. package/Rendering/Core/ColorTransferFunction.js +1 -1
  99. package/Rendering/Core/Coordinate/Constants.d.ts +14 -0
  100. package/Rendering/Core/Coordinate.js +1 -1
  101. package/Rendering/Core/Glyph3DMapper/Constants.d.ts +17 -0
  102. package/Rendering/Core/Glyph3DMapper.js +1 -1
  103. package/Rendering/Core/HardwareSelector.d.ts +84 -0
  104. package/Rendering/Core/ImageArrayMapper.d.ts +253 -0
  105. package/Rendering/Core/ImageArrayMapper.js +242 -0
  106. package/Rendering/Core/ImageMapper/Constants.d.ts +14 -0
  107. package/Rendering/Core/ImageMapper.js +1 -1
  108. package/Rendering/Core/ImageProperty/Constants.d.ts +9 -0
  109. package/Rendering/Core/ImageResliceMapper/Constants.d.ts +11 -0
  110. package/Rendering/Core/ImageResliceMapper/Constants.js +11 -0
  111. package/Rendering/Core/ImageResliceMapper.d.ts +245 -0
  112. package/Rendering/Core/ImageResliceMapper.js +70 -0
  113. package/Rendering/Core/InteractorObserver.d.ts +132 -0
  114. package/Rendering/Core/InteractorStyle/Constants.d.ts +16 -0
  115. package/Rendering/Core/InteractorStyle.d.ts +229 -0
  116. package/Rendering/Core/Light.js +1 -1
  117. package/Rendering/Core/Mapper/Constants.d.ts +26 -0
  118. package/Rendering/Core/Mapper.js +1 -1
  119. package/Rendering/Core/Picker.js +1 -1
  120. package/Rendering/Core/Prop/Constants.d.ts +9 -0
  121. package/Rendering/Core/Prop/Constants.js +9 -0
  122. package/Rendering/Core/Property/Constants.d.ts +24 -0
  123. package/Rendering/Core/Property2D/Constants.d.ts +9 -0
  124. package/Rendering/Core/RenderWindow.js +1 -1
  125. package/Rendering/Core/RenderWindowInteractor/Constants.d.ts +31 -0
  126. package/Rendering/Core/Renderer.js +1 -1
  127. package/Rendering/Core/VolumeMapper/Constants.d.ts +20 -0
  128. package/Rendering/Core/VolumeMapper.js +1 -1
  129. package/Rendering/Core/VolumeProperty/Constants.d.ts +16 -0
  130. package/Rendering/Misc/SynchronizableRenderWindow/BehaviorManager/CameraSynchronizer.js +129 -0
  131. package/Rendering/Misc/SynchronizableRenderWindow/BehaviorManager.js +131 -0
  132. package/Rendering/Misc/SynchronizableRenderWindow/ObjectManager.d.ts +80 -0
  133. package/Rendering/Misc/SynchronizableRenderWindow/ObjectManager.js +763 -0
  134. package/Rendering/OpenGL/HardwareSelector/Constants.d.ts +8 -0
  135. package/Rendering/OpenGL/HardwareSelector.d.ts +339 -0
  136. package/Rendering/OpenGL/ImageResliceMapper.js +996 -0
  137. package/Rendering/OpenGL/PolyDataMapper.js +1 -1
  138. package/Rendering/OpenGL/PolyDataMapper2D.js +1 -1
  139. package/Rendering/OpenGL/RenderWindow/Constants.d.ts +10 -0
  140. package/Rendering/OpenGL/RenderWindow/Constants.js +13 -0
  141. package/Rendering/OpenGL/RenderWindow/ContextProxy.js +70 -0
  142. package/Rendering/OpenGL/glsl/vtkImageResliceMapperFS.glsl.js +3 -0
  143. package/Rendering/OpenGL/glsl/vtkImageResliceMapperVS.glsl.js +3 -0
  144. package/Rendering/WebGPU/Actor2D.js +151 -0
  145. package/Rendering/WebGPU/BufferManager.js +1 -1
  146. package/Rendering/WebGPU/CellArrayMapper.js +853 -0
  147. package/Rendering/WebGPU/IndexBuffer.js +397 -0
  148. package/Rendering/WebGPU/PolyDataMapper2D.js +99 -0
  149. package/Rendering/WebGPU/SimpleMapper.js +290 -0
  150. package/Widgets/Core/AbstractWidget.d.ts +187 -0
  151. package/Widgets/Core/AbstractWidgetFactory.d.ts +131 -0
  152. package/Widgets/Core/StateBuilder/color3Mixin.js +24 -0
  153. package/Widgets/Core/StateBuilder/orientationMixin.js +1 -1
  154. package/Widgets/Core/StateBuilder.d.ts +29 -0
  155. package/Widgets/Core/WidgetManager/Constants.d.ts +27 -0
  156. package/Widgets/Core/WidgetManager.d.ts +231 -0
  157. package/Widgets/Core/WidgetState.d.ts +81 -0
  158. package/Widgets/Manipulators/AbstractManipulator.d.ts +221 -0
  159. package/Widgets/Manipulators/AbstractManipulator.js +57 -0
  160. package/Widgets/Manipulators/LineManipulator.js +1 -1
  161. package/Widgets/Manipulators/TrackballManipulator.js +1 -1
  162. package/Widgets/Representations/GlyphRepresentation.js +325 -0
  163. package/Widgets/Representations/LineHandleRepresentation.js +116 -0
  164. package/Widgets/Representations/ResliceCursorContextRepresentation.js +1 -1
  165. package/Widgets/Representations/WidgetRepresentation.js +1 -1
  166. package/Widgets/Widgets3D/AngleWidget.js +1 -1
  167. package/Widgets/Widgets3D/InteractiveOrientationWidget.d.ts +40 -0
  168. package/Widgets/Widgets3D/LabelWidget/behavior.js +157 -0
  169. package/Widgets/Widgets3D/LabelWidget/state.js +22 -0
  170. package/Widgets/Widgets3D/LabelWidget.js +78 -0
  171. package/Widgets/Widgets3D/LineWidget/behavior.js +1 -1
  172. package/Widgets/Widgets3D/LineWidget/helpers.js +1 -1
  173. package/Widgets/Widgets3D/ResliceCursorWidget/behavior.js +1 -1
  174. package/Widgets/Widgets3D/ResliceCursorWidget/helpers.js +1 -1
  175. package/Widgets/Widgets3D/ResliceCursorWidget.js +1 -1
  176. package/index.d.ts +133 -74
  177. package/package.json +1 -1
@@ -0,0 +1,763 @@
1
+ import _defineProperty from '@babel/runtime/helpers/defineProperty';
2
+ import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
3
+ import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
4
+ import { capitalize } from '../../../macros.js';
5
+ import vtkActor from '../../Core/Actor.js';
6
+ import vtkCamera from '../../Core/Camera.js';
7
+ import vtkColorTransferFunction from '../../Core/ColorTransferFunction.js';
8
+ import vtkDataArray from '../../../Common/Core/DataArray.js';
9
+ import vtkPoints from '../../../Common/Core/Points.js';
10
+ import vtkCellArray from '../../../Common/Core/CellArray.js';
11
+ import vtkGlyph3DMapper from '../../Core/Glyph3DMapper.js';
12
+ import vtkLight from '../../Core/Light.js';
13
+ import vtkLookupTable from '../../../Common/Core/LookupTable.js';
14
+ import vtkMapper from '../../Core/Mapper.js';
15
+ import vtkPolyData from '../../../Common/DataModel/PolyData.js';
16
+ import vtkImageData from '../../../Common/DataModel/ImageData.js';
17
+ import vtkProperty from '../../Core/Property.js';
18
+ import vtkRenderer from '../../Core/Renderer.js';
19
+ import vtkRenderWindow from '../../Core/RenderWindow.js';
20
+ import vtkTexture from '../../Core/Texture.js';
21
+ import vtkVolume from '../../Core/Volume.js';
22
+ import vtkVolumeMapper from '../../Core/VolumeMapper.js';
23
+ import vtkVolumeProperty from '../../Core/VolumeProperty.js';
24
+ import vtkImageSlice from '../../Core/ImageSlice.js';
25
+ import vtkImageMapper from '../../Core/ImageMapper.js';
26
+ import vtkImageProperty from '../../Core/ImageProperty.js';
27
+ import vtkPiecewiseFunction from '../../../Common/DataModel/PiecewiseFunction.js';
28
+ import vtkCubeAxesActor from '../../Core/CubeAxesActor.js';
29
+ import vtkScalarBarActor from '../../Core/ScalarBarActor.js';
30
+ import vtkAxesActor from '../../Core/AxesActor.js';
31
+ import BehaviorManager from './BehaviorManager.js';
32
+
33
+ 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; }
34
+
35
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
36
+ // Some internal, module-level variables and methods
37
+ // ----------------------------------------------------------------------------
38
+
39
+ var TYPE_HANDLERS = {};
40
+ var WRAPPED_ID_RE = /instance:\${([^}]+)}/;
41
+
42
+ var WRAP_ID = function WRAP_ID(id) {
43
+ return "instance:${".concat(id, "}");
44
+ };
45
+
46
+ var ONE_TIME_INSTANCE_TRACKERS = {};
47
+ var SKIPPED_INSTANCE_IDS = [];
48
+ var EXCLUDE_INSTANCE_MAP = {};
49
+ var DATA_ARRAY_MAPPER = {
50
+ vtkPoints: vtkPoints,
51
+ vtkCellArray: vtkCellArray,
52
+ vtkDataArray: vtkDataArray
53
+ }; // ----------------------------------------------------------------------------
54
+
55
+ function extractCallArgs(synchronizerContext, argList) {
56
+ return argList.map(function (arg) {
57
+ var m = WRAPPED_ID_RE.exec(arg);
58
+
59
+ if (m) {
60
+ return synchronizerContext.getInstance(m[1]);
61
+ }
62
+
63
+ return arg;
64
+ });
65
+ } // ----------------------------------------------------------------------------
66
+
67
+
68
+ function extractInstanceIds(argList) {
69
+ return argList.map(function (arg) {
70
+ return WRAPPED_ID_RE.exec(arg);
71
+ }).filter(function (m) {
72
+ return m;
73
+ }).map(function (m) {
74
+ return m[1];
75
+ });
76
+ } // ----------------------------------------------------------------------------
77
+
78
+
79
+ function extractDependencyIds(state) {
80
+ var depList = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
81
+
82
+ if (state.dependencies) {
83
+ state.dependencies.forEach(function (childState) {
84
+ depList.push(childState.id);
85
+ extractDependencyIds(childState, depList);
86
+ });
87
+ }
88
+
89
+ return depList;
90
+ } // ----------------------------------------------------------------------------
91
+
92
+
93
+ function bindArrays(arraysToBind) {
94
+ while (arraysToBind.length) {
95
+ var _arraysToBind$shift = arraysToBind.shift(),
96
+ _arraysToBind$shift2 = _slicedToArray(_arraysToBind$shift, 2),
97
+ fn = _arraysToBind$shift2[0],
98
+ args = _arraysToBind$shift2[1];
99
+
100
+ fn.apply(void 0, _toConsumableArray(args));
101
+ }
102
+ } // ----------------------------------------------------------------------------
103
+
104
+
105
+ function createNewArrayHandler(instance, arrayMetadata, arraysToBind) {
106
+ return function (values) {
107
+ var regMethod = arrayMetadata.registration ? arrayMetadata.registration : 'addArray';
108
+ var location = arrayMetadata.location ? instance.getReferenceByName(arrayMetadata.location) : instance; // Try to prevent unncessary modified
109
+
110
+ var previousArray = null;
111
+
112
+ if (arrayMetadata.location) {
113
+ previousArray = instance.getReferenceByName(arrayMetadata.location).getArray(arrayMetadata.name);
114
+ } else {
115
+ previousArray = instance["get".concat(regMethod.substring(3))]();
116
+ }
117
+
118
+ if (previousArray) {
119
+ if (previousArray.getData() !== values) {
120
+ arraysToBind.push([previousArray.setData, [values, arrayMetadata.numberOfComponents]]);
121
+ }
122
+
123
+ return previousArray;
124
+ }
125
+
126
+ var vtkClass = arrayMetadata.vtkClass ? arrayMetadata.vtkClass : 'vtkDataArray';
127
+ var array = DATA_ARRAY_MAPPER[vtkClass].newInstance(_objectSpread(_objectSpread({}, arrayMetadata), {}, {
128
+ values: values
129
+ }));
130
+ arraysToBind.push([location[regMethod], [array]]);
131
+ return array;
132
+ };
133
+ } // ----------------------------------------------------------------------------
134
+ // Static methods for export
135
+ // ----------------------------------------------------------------------------
136
+
137
+
138
+ function update(type, instance, props, context) {
139
+ if (!instance) {
140
+ return Promise.reject(new Error("No instance provided."));
141
+ }
142
+
143
+ var handler = TYPE_HANDLERS[type];
144
+
145
+ if (handler && handler.update) {
146
+ return handler.update(instance, props, context);
147
+ }
148
+
149
+ return Promise.reject(new Error("No updater for ".concat(type)));
150
+ } // ----------------------------------------------------------------------------
151
+
152
+
153
+ function build(type) {
154
+ var initialProps = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
155
+ var handler = TYPE_HANDLERS[type];
156
+
157
+ if (handler && handler.build) {
158
+ // DEBUG console.log(`new ${type} - ${initialProps.managedInstanceId}`);
159
+ return handler.build(initialProps);
160
+ }
161
+
162
+ console.log('No builder for', type);
163
+ return null;
164
+ } // ----------------------------------------------------------------------------
165
+
166
+
167
+ function excludeInstance(type, propertyName, propertyValue) {
168
+ EXCLUDE_INSTANCE_MAP[type] = {
169
+ key: propertyName,
170
+ value: propertyValue
171
+ };
172
+ } // ----------------------------------------------------------------------------
173
+
174
+
175
+ function getSupportedTypes() {
176
+ return Object.keys(TYPE_HANDLERS);
177
+ } // ----------------------------------------------------------------------------
178
+
179
+
180
+ function clearTypeMapping() {
181
+ Object.keys(TYPE_HANDLERS).forEach(function (key) {
182
+ delete TYPE_HANDLERS[key];
183
+ });
184
+ } // ----------------------------------------------------------------------------
185
+
186
+
187
+ function updateRenderWindow(instance, props, context) {
188
+ return update('vtkRenderWindow', instance, props, context);
189
+ } // ----------------------------------------------------------------------------
190
+
191
+
192
+ function clearAllOneTimeUpdaters() {
193
+ Object.keys(ONE_TIME_INSTANCE_TRACKERS).forEach(function (key) {
194
+ delete ONE_TIME_INSTANCE_TRACKERS[key];
195
+ });
196
+ } // ----------------------------------------------------------------------------
197
+
198
+
199
+ function clearOneTimeUpdaters() {
200
+ for (var _len = arguments.length, ids = new Array(_len), _key = 0; _key < _len; _key++) {
201
+ ids[_key] = arguments[_key];
202
+ }
203
+
204
+ if (ids.length === 0) {
205
+ return clearAllOneTimeUpdaters();
206
+ }
207
+
208
+ var array = ids; // allow an array passed as a single arg.
209
+
210
+ if (array.length === 1 && Array.isArray(array[0])) {
211
+ array = array[0];
212
+ }
213
+
214
+ array.forEach(function (instanceId) {
215
+ delete ONE_TIME_INSTANCE_TRACKERS[instanceId];
216
+ });
217
+ return array;
218
+ } // ----------------------------------------------------------------------------
219
+
220
+
221
+ function notSkippedInstance(call) {
222
+ if (call[1].length === 1) {
223
+ return SKIPPED_INSTANCE_IDS.indexOf(call[1][0]) === -1;
224
+ }
225
+
226
+ var keep = false;
227
+
228
+ for (var i = 0; i < call[1].length; i++) {
229
+ keep = keep || SKIPPED_INSTANCE_IDS.indexOf(call[1][i]) === -1;
230
+ }
231
+
232
+ return keep;
233
+ } // ----------------------------------------------------------------------------
234
+ // Updater functions
235
+ // ----------------------------------------------------------------------------
236
+
237
+
238
+ function genericUpdater(instance, state, context) {
239
+ context.start(); // -> start(generic-updater)
240
+ // First update our own properties
241
+
242
+ instance.set(state.properties); // Now handle dependencies
243
+
244
+ if (state.dependencies) {
245
+ state.dependencies.forEach(function (childState) {
246
+ var id = childState.id,
247
+ type = childState.type;
248
+
249
+ if (EXCLUDE_INSTANCE_MAP[type]) {
250
+ var _EXCLUDE_INSTANCE_MAP = EXCLUDE_INSTANCE_MAP[type],
251
+ key = _EXCLUDE_INSTANCE_MAP.key,
252
+ value = _EXCLUDE_INSTANCE_MAP.value;
253
+
254
+ if (!key || childState.properties[key] === value) {
255
+ SKIPPED_INSTANCE_IDS.push(WRAP_ID(id));
256
+ return;
257
+ }
258
+ }
259
+
260
+ var childInstance = context.getInstance(id);
261
+
262
+ if (!childInstance) {
263
+ childInstance = build(type, {
264
+ managedInstanceId: id
265
+ });
266
+ context.registerInstance(id, childInstance);
267
+ }
268
+
269
+ update(type, childInstance, childState, context);
270
+ });
271
+ }
272
+
273
+ if (state.calls) {
274
+ state.calls.filter(notSkippedInstance).forEach(function (call) {
275
+ // DEBUG console.log('==>', call[0], extractCallArgs(context, call[1]));
276
+ instance[call[0]].apply(null, extractCallArgs(context, call[1]));
277
+ });
278
+ } // if some arrays need to be be fetch
279
+
280
+
281
+ var dependencies = [];
282
+
283
+ if (state.arrays) {
284
+ var arraysToBind = [];
285
+ var promises = Object.values(state.arrays).map(function (arrayMetadata) {
286
+ context.start(); // -> start(arrays)
287
+
288
+ return context.getArray(arrayMetadata.hash, arrayMetadata.dataType, context).then(createNewArrayHandler(instance, arrayMetadata, arraysToBind)).catch(function (error) {
289
+ console.log('Error fetching array', JSON.stringify(arrayMetadata), error);
290
+ }).finally(context.end); // -> end(arrays)
291
+ });
292
+ context.start(); // -> start(arraysToBind)
293
+
294
+ dependencies.push(Promise.all(promises).then(function () {
295
+ // Since some arrays are getting updated, we should modify our dataset
296
+ if (arraysToBind.length) {
297
+ instance.modified();
298
+ }
299
+
300
+ bindArrays(arraysToBind);
301
+ return true;
302
+ }).catch(function (error) {
303
+ console.error('Error in array handling for state', JSON.stringify(state), error);
304
+ }).finally(context.end) // -> end(arraysToBind)
305
+ );
306
+ }
307
+
308
+ context.end(); // -> end(generic-updater)
309
+
310
+ return Promise.all(dependencies);
311
+ } // ----------------------------------------------------------------------------
312
+
313
+
314
+ function oneTimeGenericUpdater(instance, state, context) {
315
+ if (!ONE_TIME_INSTANCE_TRACKERS[state.id]) {
316
+ genericUpdater(instance, state, context);
317
+ }
318
+
319
+ ONE_TIME_INSTANCE_TRACKERS[state.id] = true;
320
+ } // ----------------------------------------------------------------------------
321
+
322
+
323
+ function rendererUpdater(instance, state, context) {
324
+ // Don't do start/end on the context here because we don't need to hold up
325
+ // rendering for the book-keeping we do after the genericUpdater finishes.
326
+ // First allow generic update process to happen as usual
327
+ genericUpdater(instance, state, context); // Any view props that were removed in the previous phase, genericUpdater(...),
328
+ // may have left orphaned children in our instance cache. Below is where those
329
+ // refs can be tracked in the first place, and then later removed as necessary
330
+ // to allow garbage collection.
331
+ // In some cases, seemingly with 'vtkColorTransferFunction', the server side
332
+ // object id may be conserved even though the actor and mapper containing or
333
+ // using it were deleted. In this case we must not unregister an instance
334
+ // which is depended upon by an incoming actor just because it was also
335
+ // depended upon by an outgoing one.
336
+
337
+ var allActorsDeps = new Set(); // Here we gather the list of dependencies (instance ids) for each view prop and
338
+ // store them on the instance, in case that view prop is later removed.
339
+
340
+ if (state.dependencies) {
341
+ state.dependencies.forEach(function (childState) {
342
+ var viewPropInstance = context.getInstance(childState.id);
343
+
344
+ if (viewPropInstance) {
345
+ var flattenedDepIds = extractDependencyIds(childState);
346
+ viewPropInstance.set({
347
+ flattenedDepIds: flattenedDepIds
348
+ }, true);
349
+ flattenedDepIds.forEach(function (depId) {
350
+ return allActorsDeps.add(depId);
351
+ });
352
+ }
353
+ });
354
+ } // Look for 'removeViewProp' calls and clean up references to dependencies of
355
+ // those view props.
356
+
357
+
358
+ var unregisterCandidates = new Set();
359
+
360
+ if (state.calls) {
361
+ state.calls.filter(notSkippedInstance).filter(function (call) {
362
+ return call[0] === 'removeViewProp';
363
+ }).forEach(function (call) {
364
+ // extract any ids associated with a 'removeViewProp' call (though really there
365
+ // should just be a single one), and use them to build a flat list of all
366
+ // representation dependency ids which we can then use our synchronizer context
367
+ // to unregister
368
+ extractInstanceIds(call[1]).forEach(function (vpId) {
369
+ var deps = context.getInstance(vpId).get('flattenedDepIds').flattenedDepIds;
370
+
371
+ if (deps) {
372
+ // Consider each dependency for un-registering
373
+ deps.forEach(function (depId) {
374
+ return unregisterCandidates.add(depId);
375
+ });
376
+ } // Consider the viewProp itself for un-registering
377
+
378
+
379
+ unregisterCandidates.add(vpId);
380
+ });
381
+ });
382
+ } // Now unregister any instances that are no longer needed
383
+
384
+
385
+ var idsToUnregister = _toConsumableArray(unregisterCandidates).filter(function (depId) {
386
+ return !allActorsDeps.has(depId);
387
+ });
388
+
389
+ idsToUnregister.forEach(function (depId) {
390
+ return context.unregisterInstance(depId);
391
+ });
392
+ } // ----------------------------------------------------------------------------
393
+
394
+
395
+ function vtkRenderWindowUpdater(instance, state, context) {
396
+ // For each renderer we may be removing from this render window, we should first
397
+ // remove all of the renderer's view props, then have the render window re-render
398
+ // itself. This will clear the screen, at which point we can go about the normal
399
+ // updater process.
400
+ if (state.calls) {
401
+ state.calls.filter(notSkippedInstance).filter(function (call) {
402
+ return call[0] === 'removeRenderer';
403
+ }).forEach(function (call) {
404
+ extractInstanceIds(call[1]).forEach(function (renId) {
405
+ var renderer = context.getInstance(renId); // Take brief detour through the view props to unregister the dependencies
406
+ // of each one
407
+
408
+ var viewProps = renderer.getViewProps();
409
+ viewProps.forEach(function (viewProp) {
410
+ var deps = viewProp.get('flattenedDepIds').flattenedDepIds;
411
+
412
+ if (deps) {
413
+ deps.forEach(function (depId) {
414
+ return context.unregisterInstance(depId);
415
+ });
416
+ }
417
+
418
+ context.unregisterInstance(context.getInstanceId(viewProp));
419
+ });
420
+ });
421
+ });
422
+ }
423
+
424
+ instance.render(); // Now just do normal update process
425
+
426
+ genericUpdater(instance, state, context); // Manage any associated behaviors
427
+
428
+ BehaviorManager.applyBehaviors(instance, state, context);
429
+ } // ----------------------------------------------------------------------------
430
+
431
+
432
+ function colorTransferFunctionUpdater(instance, state, context) {
433
+ context.start(); // -> start(colorTransferFunctionUpdater)
434
+
435
+ var nodes = state.properties.nodes.map(function (_ref) {
436
+ var _ref2 = _slicedToArray(_ref, 6),
437
+ x = _ref2[0],
438
+ r = _ref2[1],
439
+ g = _ref2[2],
440
+ b = _ref2[3],
441
+ midpoint = _ref2[4],
442
+ sharpness = _ref2[5];
443
+
444
+ return {
445
+ x: x,
446
+ r: r,
447
+ g: g,
448
+ b: b,
449
+ midpoint: midpoint,
450
+ sharpness: sharpness
451
+ };
452
+ });
453
+ instance.set(_objectSpread(_objectSpread({}, state.properties), {}, {
454
+ nodes: nodes
455
+ }), true);
456
+ context.end(); // -> end(colorTransferFunctionUpdater)
457
+ }
458
+
459
+ function piecewiseFunctionUpdater(instance, state, context) {
460
+ context.start(); // -> start(piecewiseFunctionUpdater)
461
+
462
+ var nodes = state.properties.nodes.map(function (_ref3) {
463
+ var _ref4 = _slicedToArray(_ref3, 4),
464
+ x = _ref4[0],
465
+ y = _ref4[1],
466
+ midpoint = _ref4[2],
467
+ sharpness = _ref4[3];
468
+
469
+ return {
470
+ x: x,
471
+ y: y,
472
+ midpoint: midpoint,
473
+ sharpness: sharpness
474
+ };
475
+ });
476
+ instance.set(_objectSpread(_objectSpread({}, state.properties), {}, {
477
+ nodes: nodes
478
+ }), true);
479
+ instance.sortAndUpdateRange(); // instance.modified();
480
+
481
+ context.end(); // -> end(piecewiseFunctionUpdater)
482
+ } // ----------------------------------------------------------------------------
483
+
484
+
485
+ function removeUnavailableArrays(fields, availableNames) {
486
+ var namesToDelete = [];
487
+ var size = fields.getNumberOfArrays();
488
+
489
+ for (var i = 0; i < size; i++) {
490
+ var array = fields.getArray(i);
491
+ var name = array.getName();
492
+
493
+ if (!availableNames.has(name)) {
494
+ namesToDelete.push(name);
495
+ }
496
+ }
497
+
498
+ for (var _i = 0; _i < namesToDelete.length; _i++) {
499
+ fields.removeArray(namesToDelete[_i]);
500
+ }
501
+ }
502
+ /**
503
+ * Get a unique string suitable for use as state.arrays key.
504
+ * @param {object} arrayMeta
505
+ * @returns {string} array key
506
+ */
507
+
508
+
509
+ function getArrayKey(arrayMeta) {
510
+ // Two arrays can have exactly the same hash so try to distinquish with name.
511
+ var namePart = arrayMeta.name ? "_".concat(arrayMeta.name) : '';
512
+ return "".concat(arrayMeta.hash, "_").concat(arrayMeta.dataType).concat(namePart);
513
+ }
514
+
515
+ function createDataSetUpdate() {
516
+ var piecesToFetch = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
517
+ return function (instance, state, context) {
518
+ context.start(); // -> start(dataset-update)
519
+ // Make sure we provide container for std arrays
520
+
521
+ var localProperties = _objectSpread({}, state.properties);
522
+
523
+ if (!state.arrays) {
524
+ state.arrays = {};
525
+ } // Array members
526
+ // => convert old format to generic state.arrays
527
+
528
+
529
+ for (var i = 0; i < piecesToFetch.length; i++) {
530
+ var key = piecesToFetch[i];
531
+
532
+ if (state.properties[key]) {
533
+ var arrayMeta = state.properties[key];
534
+ arrayMeta.registration = "set".concat(capitalize(key));
535
+ var arrayKey = getArrayKey(arrayMeta);
536
+ state.arrays[arrayKey] = arrayMeta;
537
+ delete localProperties[key];
538
+ }
539
+ } // Extract dataset fields
540
+
541
+
542
+ var fieldsArrays = state.properties.fields || [];
543
+
544
+ for (var _i2 = 0; _i2 < fieldsArrays.length; _i2++) {
545
+ var _arrayMeta = fieldsArrays[_i2];
546
+
547
+ var _arrayKey = getArrayKey(_arrayMeta);
548
+
549
+ state.arrays[_arrayKey] = _arrayMeta;
550
+ }
551
+
552
+ delete localProperties.fields; // Reset any pre-existing fields array
553
+
554
+ var arrayToKeep = {
555
+ pointData: new Set(),
556
+ cellData: new Set(),
557
+ fieldData: new Set()
558
+ };
559
+ fieldsArrays.forEach(function (_ref5) {
560
+ var location = _ref5.location,
561
+ name = _ref5.name;
562
+ arrayToKeep[location].add(name);
563
+ });
564
+ removeUnavailableArrays(instance.getPointData(), arrayToKeep.pointData);
565
+ removeUnavailableArrays(instance.getCellData(), arrayToKeep.cellData); // Generic handling
566
+
567
+ var cleanState = _objectSpread({}, state);
568
+
569
+ cleanState.properties = localProperties;
570
+ var res = genericUpdater(instance, cleanState, context); // Finish what we started
571
+
572
+ context.end(); // -> end(dataset-update)
573
+
574
+ return res;
575
+ };
576
+ }
577
+
578
+ var polydataUpdater = createDataSetUpdate(['points', 'polys', 'verts', 'lines', 'strips']);
579
+ var imageDataUpdater = createDataSetUpdate([]); // ----------------------------------------------------------------------------
580
+ // Construct the type mapping
581
+ // ----------------------------------------------------------------------------
582
+
583
+ function setTypeMapping(type) {
584
+ var buildFn = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
585
+ var updateFn = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : genericUpdater;
586
+
587
+ if (!build && !update) {
588
+ delete TYPE_HANDLERS[type];
589
+ return;
590
+ }
591
+
592
+ TYPE_HANDLERS[type] = {
593
+ build: buildFn,
594
+ update: updateFn
595
+ };
596
+ } // ----------------------------------------------------------------------------
597
+
598
+
599
+ var DEFAULT_ALIASES = {
600
+ vtkMapper: ['vtkOpenGLPolyDataMapper', 'vtkCompositePolyDataMapper2', 'vtkDataSetMapper'],
601
+ vtkProperty: ['vtkOpenGLProperty'],
602
+ vtkRenderer: ['vtkOpenGLRenderer'],
603
+ vtkCamera: ['vtkOpenGLCamera'],
604
+ vtkColorTransferFunction: ['vtkPVDiscretizableColorTransferFunction'],
605
+ vtkActor: ['vtkOpenGLActor', 'vtkPVLODActor'],
606
+ vtkLight: ['vtkOpenGLLight', 'vtkPVLight'],
607
+ vtkTexture: ['vtkOpenGLTexture'],
608
+ vtkImageMapper: ['vtkOpenGLImageSliceMapper'],
609
+ vtkVolumeMapper: ['vtkFixedPointVolumeRayCastMapper']
610
+ }; // ----------------------------------------------------------------------------
611
+
612
+ var DEFAULT_MAPPING = {
613
+ vtkAxesActor: {
614
+ build: vtkAxesActor.newInstance,
615
+ update: genericUpdater
616
+ },
617
+ vtkRenderWindow: {
618
+ build: vtkRenderWindow.newInstance,
619
+ update: vtkRenderWindowUpdater
620
+ },
621
+ vtkRenderer: {
622
+ build: vtkRenderer.newInstance,
623
+ update: rendererUpdater
624
+ },
625
+ vtkLookupTable: {
626
+ build: vtkLookupTable.newInstance,
627
+ update: genericUpdater
628
+ },
629
+ vtkCamera: {
630
+ build: vtkCamera.newInstance,
631
+ update: oneTimeGenericUpdater
632
+ },
633
+ vtkPolyData: {
634
+ build: vtkPolyData.newInstance,
635
+ update: polydataUpdater
636
+ },
637
+ vtkImageData: {
638
+ build: vtkImageData.newInstance,
639
+ update: imageDataUpdater
640
+ },
641
+ vtkMapper: {
642
+ build: vtkMapper.newInstance,
643
+ update: genericUpdater
644
+ },
645
+ vtkGlyph3DMapper: {
646
+ build: vtkGlyph3DMapper.newInstance,
647
+ update: genericUpdater
648
+ },
649
+ vtkProperty: {
650
+ build: vtkProperty.newInstance,
651
+ update: genericUpdater
652
+ },
653
+ vtkActor: {
654
+ build: vtkActor.newInstance,
655
+ update: genericUpdater
656
+ },
657
+ vtkLight: {
658
+ build: vtkLight.newInstance,
659
+ update: genericUpdater
660
+ },
661
+ vtkColorTransferFunction: {
662
+ build: vtkColorTransferFunction.newInstance,
663
+ update: colorTransferFunctionUpdater
664
+ },
665
+ vtkTexture: {
666
+ build: vtkTexture.newInstance,
667
+ update: genericUpdater
668
+ },
669
+ vtkVolume: {
670
+ build: vtkVolume.newInstance,
671
+ update: genericUpdater
672
+ },
673
+ vtkVolumeMapper: {
674
+ build: vtkVolumeMapper.newInstance,
675
+ update: genericUpdater
676
+ },
677
+ vtkVolumeProperty: {
678
+ build: vtkVolumeProperty.newInstance,
679
+ update: genericUpdater
680
+ },
681
+ vtkImageSlice: {
682
+ build: vtkImageSlice.newInstance,
683
+ update: genericUpdater
684
+ },
685
+ vtkImageMapper: {
686
+ build: vtkImageMapper.newInstance,
687
+ update: genericUpdater
688
+ },
689
+ vtkImageProperty: {
690
+ build: vtkImageProperty.newInstance,
691
+ update: genericUpdater
692
+ },
693
+ vtkPiecewiseFunction: {
694
+ build: vtkPiecewiseFunction.newInstance,
695
+ update: piecewiseFunctionUpdater
696
+ },
697
+ vtkCubeAxesActor: {
698
+ build: vtkCubeAxesActor.newInstance,
699
+ update: genericUpdater
700
+ },
701
+ vtkScalarBarActor: {
702
+ build: vtkScalarBarActor.newInstance,
703
+ update: genericUpdater
704
+ }
705
+ }; // ----------------------------------------------------------------------------
706
+
707
+ function setDefaultMapping() {
708
+ var reset = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
709
+
710
+ if (reset) {
711
+ clearTypeMapping();
712
+ }
713
+
714
+ Object.keys(DEFAULT_MAPPING).forEach(function (type) {
715
+ var mapping = DEFAULT_MAPPING[type];
716
+ setTypeMapping(type, mapping.build, mapping.update);
717
+ });
718
+ } // ----------------------------------------------------------------------------
719
+
720
+
721
+ function applyDefaultAliases() {
722
+ // Add aliases
723
+ Object.keys(DEFAULT_ALIASES).forEach(function (name) {
724
+ var aliases = DEFAULT_ALIASES[name];
725
+ aliases.forEach(function (alias) {
726
+ TYPE_HANDLERS[alias] = TYPE_HANDLERS[name];
727
+ });
728
+ });
729
+ } // ----------------------------------------------------------------------------
730
+
731
+
732
+ function alwaysUpdateCamera() {
733
+ setTypeMapping('vtkCamera', vtkCamera.newInstance);
734
+ applyDefaultAliases();
735
+ } // ----------------------------------------------------------------------------
736
+
737
+
738
+ setDefaultMapping();
739
+ applyDefaultAliases(); // ----------------------------------------------------------------------------
740
+ // Avoid handling any lights at the moment
741
+ // => vtk seems fine and PV could be fine as well but not tested so keeping PV exclude
742
+
743
+ EXCLUDE_INSTANCE_MAP.vtkPVLight = {}; // ----------------------------------------------------------------------------
744
+ // Publicly exposed methods
745
+ // ----------------------------------------------------------------------------
746
+
747
+ var vtkObjectManager = {
748
+ build: build,
749
+ update: update,
750
+ genericUpdater: genericUpdater,
751
+ oneTimeGenericUpdater: oneTimeGenericUpdater,
752
+ setTypeMapping: setTypeMapping,
753
+ clearTypeMapping: clearTypeMapping,
754
+ getSupportedTypes: getSupportedTypes,
755
+ clearOneTimeUpdaters: clearOneTimeUpdaters,
756
+ updateRenderWindow: updateRenderWindow,
757
+ excludeInstance: excludeInstance,
758
+ setDefaultMapping: setDefaultMapping,
759
+ applyDefaultAliases: applyDefaultAliases,
760
+ alwaysUpdateCamera: alwaysUpdateCamera
761
+ };
762
+
763
+ export { vtkObjectManager as default };