@kitware/vtk.js 28.10.2 → 28.11.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (566) hide show
  1. package/Common/Core/Base64.js +53 -82
  2. package/Common/Core/CellArray.js +52 -60
  3. package/Common/Core/ClassHierarchy.js +8 -36
  4. package/Common/Core/DataArray/Constants.js +6 -6
  5. package/Common/Core/DataArray.js +193 -277
  6. package/Common/Core/Endian.js +14 -17
  7. package/Common/Core/HalfFloat.js +17 -34
  8. package/Common/Core/ImageHelper.js +17 -25
  9. package/Common/Core/LookupTable.js +131 -144
  10. package/Common/Core/Math/Constants.js +8 -8
  11. package/Common/Core/Math/index.js +754 -942
  12. package/Common/Core/Math.js +2 -4
  13. package/Common/Core/MatrixBuilder.js +99 -151
  14. package/Common/Core/Points.js +43 -43
  15. package/Common/Core/PriorityQueue.js +30 -28
  16. package/Common/Core/ProgressHandler.js +31 -32
  17. package/Common/Core/ScalarsToColors/Constants.js +4 -4
  18. package/Common/Core/ScalarsToColors.js +196 -253
  19. package/Common/Core/StringArray.js +48 -73
  20. package/Common/Core/URLExtract.js +10 -29
  21. package/Common/Core/VariantArray.js +48 -73
  22. package/Common/Core.js +11 -11
  23. package/Common/DataModel/AbstractPointLocator.js +19 -17
  24. package/Common/DataModel/BoundingBox.js +322 -490
  25. package/Common/DataModel/Box.js +46 -63
  26. package/Common/DataModel/CardinalSpline1D.js +92 -102
  27. package/Common/DataModel/Cell.js +41 -61
  28. package/Common/DataModel/CellLinks.js +91 -127
  29. package/Common/DataModel/CellTypes/Constants.js +7 -6
  30. package/Common/DataModel/CellTypes.js +55 -74
  31. package/Common/DataModel/Collection.js +45 -61
  32. package/Common/DataModel/Cone.js +28 -20
  33. package/Common/DataModel/Cylinder.js +41 -35
  34. package/Common/DataModel/DataSet/Constants.js +11 -5
  35. package/Common/DataModel/DataSet.js +37 -25
  36. package/Common/DataModel/DataSetAttributes/Constants.js +18 -18
  37. package/Common/DataModel/DataSetAttributes/FieldData.js +103 -194
  38. package/Common/DataModel/DataSetAttributes.js +96 -138
  39. package/Common/DataModel/EdgeLocator.js +45 -70
  40. package/Common/DataModel/ITKHelper.js +67 -137
  41. package/Common/DataModel/ImageData.js +115 -172
  42. package/Common/DataModel/ImplicitBoolean/Constants.js +2 -2
  43. package/Common/DataModel/ImplicitBoolean.js +66 -96
  44. package/Common/DataModel/IncrementalOctreeNode.js +201 -231
  45. package/Common/DataModel/IncrementalOctreePointLocator.js +160 -198
  46. package/Common/DataModel/KochanekSpline1D.js +78 -81
  47. package/Common/DataModel/Line/Constants.js +2 -2
  48. package/Common/DataModel/Line.js +82 -105
  49. package/Common/DataModel/Locator.js +17 -10
  50. package/Common/DataModel/Molecule.js +26 -17
  51. package/Common/DataModel/PiecewiseFunction.js +218 -239
  52. package/Common/DataModel/Plane.js +90 -113
  53. package/Common/DataModel/PointSet.js +30 -26
  54. package/Common/DataModel/PolyData/Constants.js +2 -2
  55. package/Common/DataModel/PolyData.js +95 -120
  56. package/Common/DataModel/PolyLine.js +44 -61
  57. package/Common/DataModel/Polygon/Constants.js +4 -4
  58. package/Common/DataModel/Polygon.js +128 -169
  59. package/Common/DataModel/Quad/Constants.js +2 -2
  60. package/Common/DataModel/Quad.js +61 -100
  61. package/Common/DataModel/SelectionNode/Constants.js +5 -4
  62. package/Common/DataModel/SelectionNode.js +25 -21
  63. package/Common/DataModel/Sphere.js +40 -35
  64. package/Common/DataModel/Spline1D/Constants.js +3 -2
  65. package/Common/DataModel/Spline1D.js +34 -18
  66. package/Common/DataModel/Spline3D/Constants.js +2 -2
  67. package/Common/DataModel/Spline3D.js +46 -41
  68. package/Common/DataModel/StructuredData/Constants.js +2 -2
  69. package/Common/DataModel/StructuredData.js +9 -20
  70. package/Common/DataModel/Triangle.js +207 -250
  71. package/Common/DataModel.js +19 -19
  72. package/Common/System/MobileVR.js +56 -61
  73. package/Common/System/TimerLog.js +1 -1
  74. package/Common/System.js +2 -2
  75. package/Common/Transform/LandmarkTransform/Constants.js +2 -2
  76. package/Common/Transform/LandmarkTransform.js +133 -117
  77. package/Common/Transform/Transform.js +42 -57
  78. package/Common/Transform.js +2 -2
  79. package/Common/index.js +4 -4
  80. package/Filters/Core/Cutter.js +134 -146
  81. package/Filters/Core/PolyDataNormals.js +44 -50
  82. package/Filters/Core.js +2 -2
  83. package/Filters/Cornerstone/ImageDataToCornerstoneImage.js +45 -33
  84. package/Filters/Cornerstone.js +1 -1
  85. package/Filters/General/AppendPolyData.js +84 -100
  86. package/Filters/General/Calculator.js +95 -163
  87. package/Filters/General/ClipClosedSurface/Constants.js +2 -2
  88. package/Filters/General/ClipClosedSurface.js +341 -416
  89. package/Filters/General/ClosedPolyLineToSurfaceFilter.js +141 -156
  90. package/Filters/General/ContourTriangulator/Constants.js +2 -2
  91. package/Filters/General/ContourTriangulator/helper.js +684 -812
  92. package/Filters/General/ContourTriangulator.js +92 -89
  93. package/Filters/General/ImageCropFilter.js +77 -78
  94. package/Filters/General/ImageDataOutlineFilter.js +42 -36
  95. package/Filters/General/ImageMarchingCubes/caseTable.js +9 -521
  96. package/Filters/General/ImageMarchingCubes.js +99 -112
  97. package/Filters/General/ImageMarchingSquares/caseTable.js +9 -41
  98. package/Filters/General/ImageMarchingSquares.js +93 -118
  99. package/Filters/General/ImageOutlineFilter.js +53 -54
  100. package/Filters/General/ImageSliceFilter.js +39 -30
  101. package/Filters/General/ImageStreamline.js +107 -124
  102. package/Filters/General/LineFilter.js +26 -15
  103. package/Filters/General/MoleculeToRepresentation.js +136 -149
  104. package/Filters/General/OBBTree/OBBNode.js +36 -34
  105. package/Filters/General/OBBTree/helper.js +19 -24
  106. package/Filters/General/OBBTree.js +396 -488
  107. package/Filters/General/OutlineFilter.js +52 -34
  108. package/Filters/General/PaintFilter/PaintFilter.worker.js +93 -130
  109. package/Filters/General/PaintFilter.js +150 -162
  110. package/Filters/General/ScalarToRGBA.js +38 -33
  111. package/Filters/General/TriangleFilter.js +65 -62
  112. package/Filters/General/TubeFilter/Constants.js +4 -4
  113. package/Filters/General/TubeFilter.js +376 -496
  114. package/Filters/General/WarpScalar.js +58 -60
  115. package/Filters/General/WindowedSincPolyDataFilter.js +258 -330
  116. package/Filters/General.js +21 -21
  117. package/Filters/Sources/Arrow2DSource/Constants.js +2 -2
  118. package/Filters/Sources/Arrow2DSource.js +56 -56
  119. package/Filters/Sources/ArrowSource.js +39 -29
  120. package/Filters/Sources/CircleSource.js +43 -43
  121. package/Filters/Sources/ConcentricCylinderSource.js +151 -174
  122. package/Filters/Sources/ConeSource.js +51 -42
  123. package/Filters/Sources/CubeSource.js +75 -96
  124. package/Filters/Sources/Cursor3D.js +94 -109
  125. package/Filters/Sources/CylinderSource.js +90 -90
  126. package/Filters/Sources/ImageGridSource.js +43 -43
  127. package/Filters/Sources/LineSource.js +49 -39
  128. package/Filters/Sources/PlaneSource.js +97 -104
  129. package/Filters/Sources/PointSource.js +46 -37
  130. package/Filters/Sources/RTAnalyticSource.js +50 -48
  131. package/Filters/Sources/SLICSource.js +63 -73
  132. package/Filters/Sources/SphereSource.js +88 -78
  133. package/Filters/Sources/ViewFinderSource.js +26 -23
  134. package/Filters/Sources.js +14 -14
  135. package/Filters/Texture/TextureMapToPlane.js +95 -97
  136. package/Filters/Texture/TextureMapToSphere.js +46 -54
  137. package/Filters/Texture.js +2 -2
  138. package/Filters/index.js +5 -5
  139. package/IO/Core/BinaryHelper.js +12 -18
  140. package/IO/Core/DataAccessHelper/HtmlDataAccessHelper.js +43 -59
  141. package/IO/Core/DataAccessHelper/HttpDataAccessHelper.js +76 -113
  142. package/IO/Core/DataAccessHelper/JSZipDataAccessHelper.js +62 -112
  143. package/IO/Core/DataAccessHelper/LiteHttpDataAccessHelper.js +76 -113
  144. package/IO/Core/DataAccessHelper.js +6 -6
  145. package/IO/Core/HttpDataSetReader.js +136 -139
  146. package/IO/Core/HttpDataSetSeriesReader.js +64 -75
  147. package/IO/Core/HttpSceneLoader.js +130 -179
  148. package/IO/Core/ImageStream/DefaultProtocol.js +29 -43
  149. package/IO/Core/ImageStream/ViewStream.js +100 -103
  150. package/IO/Core/ImageStream.js +62 -54
  151. package/IO/Core/ResourceLoader.js +10 -9
  152. package/IO/Core/Serializer/ArraySerializer.js +40 -40
  153. package/IO/Core/Serializer/FieldDataSerializer.js +18 -28
  154. package/IO/Core/Serializer/ImageDataSerializer.js +22 -23
  155. package/IO/Core/Serializer/PolyDataSerializer.js +17 -21
  156. package/IO/Core/Serializer.js +6 -13
  157. package/IO/Core/WSLinkClient.js +90 -76
  158. package/IO/Core/ZipMultiDataSetReader.js +46 -44
  159. package/IO/Core/ZipMultiDataSetWriter.js +43 -34
  160. package/IO/Core.js +7 -7
  161. package/IO/Geometry/DracoReader.js +118 -121
  162. package/IO/Geometry/PLYReader.js +163 -223
  163. package/IO/Geometry/PLYWriter/Constants.js +5 -5
  164. package/IO/Geometry/PLYWriter.js +139 -154
  165. package/IO/Geometry/STLReader.js +123 -146
  166. package/IO/Geometry/STLWriter/Constants.js +2 -2
  167. package/IO/Geometry/STLWriter.js +83 -82
  168. package/IO/Geometry.js +5 -5
  169. package/IO/Legacy/LegacyAsciiParser.js +78 -139
  170. package/IO/Legacy/PolyDataReader.js +48 -36
  171. package/IO/Legacy.js +2 -2
  172. package/IO/Misc/ElevationReader.js +67 -60
  173. package/IO/Misc/HttpDataSetLODsLoader.js +41 -38
  174. package/IO/Misc/ITKImageReader.js +58 -45
  175. package/IO/Misc/ITKPolyDataReader.js +50 -38
  176. package/IO/Misc/JSONNucleoReader.js +49 -42
  177. package/IO/Misc/JSONReader.js +38 -33
  178. package/IO/Misc/MTLReader.js +74 -119
  179. package/IO/Misc/OBJReader.js +153 -206
  180. package/IO/Misc/PDBReader.js +70 -68
  181. package/IO/Misc/SkyboxReader.js +77 -82
  182. package/IO/Misc.js +9 -9
  183. package/IO/XML/XMLImageDataReader.js +36 -38
  184. package/IO/XML/XMLImageDataWriter.js +28 -21
  185. package/IO/XML/XMLPolyDataReader.js +49 -46
  186. package/IO/XML/XMLPolyDataWriter.js +43 -42
  187. package/IO/XML/XMLReader.js +262 -304
  188. package/IO/XML/XMLWriter/Constants.js +3 -3
  189. package/IO/XML/XMLWriter.js +70 -84
  190. package/IO/XML.js +6 -6
  191. package/IO/index.js +5 -5
  192. package/Imaging/Core/AbstractImageInterpolator/Constants.js +4 -4
  193. package/Imaging/Core/AbstractImageInterpolator/InterpolationInfo.js +30 -27
  194. package/Imaging/Core/AbstractImageInterpolator.js +74 -87
  195. package/Imaging/Core/ImageInterpolator.js +201 -252
  196. package/Imaging/Core/ImagePointDataIterator.js +96 -122
  197. package/Imaging/Core/ImageReslice/Constants.js +2 -2
  198. package/Imaging/Core/ImageReslice.js +327 -464
  199. package/Imaging/Core.js +4 -4
  200. package/Imaging/Hybrid/SampleFunction.js +58 -51
  201. package/Imaging/Hybrid.js +1 -1
  202. package/Imaging/index.js +2 -2
  203. package/Interaction/Animations/TimeStepBasedAnimationHandler.js +39 -54
  204. package/Interaction/Manipulators/CompositeCameraManipulator.js +22 -13
  205. package/Interaction/Manipulators/CompositeGestureManipulator.js +31 -43
  206. package/Interaction/Manipulators/CompositeKeyboardManipulator.js +15 -11
  207. package/Interaction/Manipulators/CompositeMouseManipulator.js +27 -33
  208. package/Interaction/Manipulators/CompositeVRManipulator.js +22 -15
  209. package/Interaction/Manipulators/GestureCameraManipulator.js +54 -36
  210. package/Interaction/Manipulators/KeyboardCameraManipulator.js +95 -97
  211. package/Interaction/Manipulators/MouseBoxSelectorManipulator.js +70 -89
  212. package/Interaction/Manipulators/MouseCameraAxisRotateManipulator.js +67 -54
  213. package/Interaction/Manipulators/MouseCameraSliceManipulator.js +40 -38
  214. package/Interaction/Manipulators/MouseCameraTrackballFirstPersonManipulator.js +83 -68
  215. package/Interaction/Manipulators/MouseCameraTrackballMultiRotateManipulator.js +32 -28
  216. package/Interaction/Manipulators/MouseCameraTrackballPanManipulator.js +47 -40
  217. package/Interaction/Manipulators/MouseCameraTrackballRollManipulator.js +55 -43
  218. package/Interaction/Manipulators/MouseCameraTrackballRotateManipulator.js +56 -46
  219. package/Interaction/Manipulators/MouseCameraTrackballZoomManipulator.js +41 -46
  220. package/Interaction/Manipulators/MouseCameraTrackballZoomToMouseManipulator.js +29 -27
  221. package/Interaction/Manipulators/MouseCameraUnicamManipulator.js +123 -146
  222. package/Interaction/Manipulators/MouseCameraUnicamRotateManipulator.js +144 -166
  223. package/Interaction/Manipulators/MouseRangeManipulator.js +127 -132
  224. package/Interaction/Manipulators/VRButtonPanManipulator.js +33 -23
  225. package/Interaction/Manipulators.js +21 -21
  226. package/Interaction/Misc/DeviceOrientationToCamera.js +25 -47
  227. package/Interaction/Misc.js +1 -1
  228. package/Interaction/Style/InteractorStyleImage.js +101 -121
  229. package/Interaction/Style/InteractorStyleMPRSlice.js +111 -128
  230. package/Interaction/Style/InteractorStyleManipulator/Presets.js +9 -17
  231. package/Interaction/Style/InteractorStyleManipulator.js +254 -329
  232. package/Interaction/Style/InteractorStyleRemoteMouse.js +195 -180
  233. package/Interaction/Style/InteractorStyleTrackballCamera.js +154 -157
  234. package/Interaction/Style/InteractorStyleUnicam.js +30 -38
  235. package/Interaction/Style.js +5 -5
  236. package/Interaction/UI/CornerAnnotation/CornerAnnotation.module.css.js +1 -1
  237. package/Interaction/UI/CornerAnnotation.js +65 -48
  238. package/Interaction/UI/FPSMonitor.js +104 -105
  239. package/Interaction/UI/Icons.js +1 -1
  240. package/Interaction/UI/Slider/Constants.js +2 -2
  241. package/Interaction/UI/Slider.js +78 -95
  242. package/Interaction/UI/VolumeController.js +104 -97
  243. package/Interaction/UI.js +5 -5
  244. package/Interaction/Widgets/OrientationMarkerWidget/Constants.js +2 -2
  245. package/Interaction/Widgets/OrientationMarkerWidget.js +90 -135
  246. package/Interaction/Widgets/PiecewiseGaussianWidget/ComputeHistogram.worker.js +0 -3
  247. package/Interaction/Widgets/PiecewiseGaussianWidget.js +381 -498
  248. package/Interaction/Widgets.js +2 -2
  249. package/Interaction/index.js +5 -5
  250. package/Proxy/Animation/AbstractAnimationProxy.js +22 -15
  251. package/Proxy/Animation/AnimationProxyManager.js +43 -51
  252. package/Proxy/Animation/TimeStepBasedAnimationHandlerProxy.js +26 -19
  253. package/Proxy/Core/AbstractRepresentationProxy.js +97 -151
  254. package/Proxy/Core/LookupTableProxy/Constants.js +4 -4
  255. package/Proxy/Core/LookupTableProxy.js +49 -52
  256. package/Proxy/Core/PiecewiseFunctionProxy/Constants.js +4 -4
  257. package/Proxy/Core/PiecewiseFunctionProxy.js +63 -72
  258. package/Proxy/Core/ProxyManager/core.js +83 -106
  259. package/Proxy/Core/ProxyManager/properties.js +53 -76
  260. package/Proxy/Core/ProxyManager/state.js +100 -110
  261. package/Proxy/Core/ProxyManager/view.js +45 -55
  262. package/Proxy/Core/ProxyManager.js +16 -8
  263. package/Proxy/Core/SourceProxy.js +41 -38
  264. package/Proxy/Core/View2DProxy.js +143 -199
  265. package/Proxy/Core/ViewProxy.js +223 -269
  266. package/Proxy/Core.js +7 -7
  267. package/Proxy/Representations/GeometryRepresentationProxy.js +34 -20
  268. package/Proxy/Representations/GlyphRepresentationProxy.js +42 -41
  269. package/Proxy/Representations/MoleculeRepresentationProxy.js +32 -22
  270. package/Proxy/Representations/ResliceRepresentationProxy.js +48 -32
  271. package/Proxy/Representations/SkyboxRepresentationProxy.js +30 -29
  272. package/Proxy/Representations/SliceRepresentationProxy.js +93 -112
  273. package/Proxy/Representations/SlicedGeometryRepresentationProxy.js +46 -42
  274. package/Proxy/Representations/VolumeRepresentationProxy.js +108 -133
  275. package/Proxy/Representations.js +7 -7
  276. package/Proxy/index.js +2 -2
  277. package/README.md +1 -1
  278. package/Rendering/Core/AbstractImageMapper/helper.js +44 -49
  279. package/Rendering/Core/AbstractImageMapper.js +18 -19
  280. package/Rendering/Core/AbstractMapper.js +39 -55
  281. package/Rendering/Core/AbstractMapper3D.js +26 -31
  282. package/Rendering/Core/AbstractPicker.js +25 -21
  283. package/Rendering/Core/Actor.js +71 -93
  284. package/Rendering/Core/Actor2D.js +64 -78
  285. package/Rendering/Core/AnnotatedCubeActor/Presets.js +5 -11
  286. package/Rendering/Core/AnnotatedCubeActor.js +94 -79
  287. package/Rendering/Core/AxesActor.js +65 -87
  288. package/Rendering/Core/Camera.js +246 -271
  289. package/Rendering/Core/CellPicker.js +125 -148
  290. package/Rendering/Core/ColorTransferFunction/ColorMaps.js +20 -21
  291. package/Rendering/Core/ColorTransferFunction/ColorMapsLite.js +20 -21
  292. package/Rendering/Core/ColorTransferFunction/Constants.js +4 -4
  293. package/Rendering/Core/ColorTransferFunction.js +460 -546
  294. package/Rendering/Core/Coordinate/Constants.js +2 -2
  295. package/Rendering/Core/Coordinate.js +119 -198
  296. package/Rendering/Core/CubeAxesActor.js +294 -320
  297. package/Rendering/Core/Follower.js +46 -45
  298. package/Rendering/Core/Glyph3DMapper/Constants.js +4 -4
  299. package/Rendering/Core/Glyph3DMapper.js +96 -148
  300. package/Rendering/Core/HardwareSelector.js +36 -69
  301. package/Rendering/Core/ImageArrayMapper.js +87 -126
  302. package/Rendering/Core/ImageCPRMapper.js +134 -209
  303. package/Rendering/Core/ImageMapper/Constants.js +2 -2
  304. package/Rendering/Core/ImageMapper.js +85 -144
  305. package/Rendering/Core/ImageProperty/Constants.js +2 -2
  306. package/Rendering/Core/ImageProperty.js +66 -81
  307. package/Rendering/Core/ImageResliceMapper/Constants.js +2 -2
  308. package/Rendering/Core/ImageResliceMapper.js +36 -29
  309. package/Rendering/Core/ImageSlice.js +85 -127
  310. package/Rendering/Core/InteractorObserver.js +82 -73
  311. package/Rendering/Core/InteractorStyle/Constants.js +2 -2
  312. package/Rendering/Core/InteractorStyle.js +56 -58
  313. package/Rendering/Core/Light.js +43 -49
  314. package/Rendering/Core/Mapper/CoincidentTopologyHelper.js +37 -48
  315. package/Rendering/Core/Mapper/Constants.js +6 -6
  316. package/Rendering/Core/Mapper/Static.js +15 -12
  317. package/Rendering/Core/Mapper.js +194 -259
  318. package/Rendering/Core/Mapper2D.js +61 -100
  319. package/Rendering/Core/Picker.js +124 -143
  320. package/Rendering/Core/PixelSpaceCallbackMapper.js +40 -37
  321. package/Rendering/Core/PointPicker.js +68 -79
  322. package/Rendering/Core/Prop/Constants.js +2 -2
  323. package/Rendering/Core/Prop.js +58 -106
  324. package/Rendering/Core/Prop3D.js +54 -83
  325. package/Rendering/Core/Property/Constants.js +6 -6
  326. package/Rendering/Core/Property.js +45 -74
  327. package/Rendering/Core/Property2D/Constants.js +2 -2
  328. package/Rendering/Core/Property2D.js +33 -42
  329. package/Rendering/Core/RenderWindow.js +70 -82
  330. package/Rendering/Core/RenderWindowInteractor/Constants.js +7 -7
  331. package/Rendering/Core/RenderWindowInteractor.js +324 -439
  332. package/Rendering/Core/Renderer.js +192 -256
  333. package/Rendering/Core/ScalarBarActor.js +267 -272
  334. package/Rendering/Core/Skybox.js +26 -24
  335. package/Rendering/Core/SphereMapper.js +22 -12
  336. package/Rendering/Core/StickMapper.js +22 -12
  337. package/Rendering/Core/SurfaceLICInterface/Constants.js +6 -6
  338. package/Rendering/Core/SurfaceLICInterface.js +13 -9
  339. package/Rendering/Core/SurfaceLICMapper.js +23 -15
  340. package/Rendering/Core/Texture.js +99 -141
  341. package/Rendering/Core/Viewport.js +60 -88
  342. package/Rendering/Core/Volume.js +55 -77
  343. package/Rendering/Core/VolumeMapper/Constants.js +4 -4
  344. package/Rendering/Core/VolumeMapper.js +59 -91
  345. package/Rendering/Core/VolumeProperty/Constants.js +4 -4
  346. package/Rendering/Core/VolumeProperty.js +78 -115
  347. package/Rendering/Core.js +47 -49
  348. package/Rendering/Misc/CanvasView.js +62 -61
  349. package/Rendering/Misc/FullScreenRenderWindow.js +60 -62
  350. package/Rendering/Misc/GenericRenderWindow.js +48 -37
  351. package/Rendering/Misc/RemoteView.js +86 -80
  352. package/Rendering/Misc/RenderWindowWithControlBar.js +54 -48
  353. package/Rendering/Misc/SynchronizableRenderWindow/BehaviorManager/CameraSynchronizer.js +43 -51
  354. package/Rendering/Misc/SynchronizableRenderWindow/BehaviorManager.js +52 -82
  355. package/Rendering/Misc/SynchronizableRenderWindow/ObjectManager.js +258 -308
  356. package/Rendering/Misc/SynchronizableRenderWindow.js +133 -163
  357. package/Rendering/Misc/TextureLODsDownloader.js +72 -74
  358. package/Rendering/Misc.js +7 -7
  359. package/Rendering/OpenGL/Actor.js +57 -68
  360. package/Rendering/OpenGL/Actor2D.js +56 -56
  361. package/Rendering/OpenGL/BufferObject/Constants.js +2 -2
  362. package/Rendering/OpenGL/BufferObject.js +50 -65
  363. package/Rendering/OpenGL/Camera.js +35 -29
  364. package/Rendering/OpenGL/CellArrayBufferObject.js +119 -149
  365. package/Rendering/OpenGL/Convolution2DPass.js +87 -81
  366. package/Rendering/OpenGL/CubeAxesActor.js +28 -21
  367. package/Rendering/OpenGL/ForwardPass.js +53 -64
  368. package/Rendering/OpenGL/Framebuffer.js +61 -101
  369. package/Rendering/OpenGL/Glyph3DMapper.js +165 -196
  370. package/Rendering/OpenGL/HardwareSelector/Constants.js +2 -2
  371. package/Rendering/OpenGL/HardwareSelector.js +272 -397
  372. package/Rendering/OpenGL/Helper.js +58 -73
  373. package/Rendering/OpenGL/ImageCPRMapper.js +339 -421
  374. package/Rendering/OpenGL/ImageMapper.js +268 -361
  375. package/Rendering/OpenGL/ImageResliceMapper.js +306 -438
  376. package/Rendering/OpenGL/ImageSlice.js +48 -54
  377. package/Rendering/OpenGL/OrderIndependentTranslucentPass.js +102 -84
  378. package/Rendering/OpenGL/PixelSpaceCallbackMapper.js +43 -42
  379. package/Rendering/OpenGL/PolyDataMapper.js +358 -492
  380. package/Rendering/OpenGL/PolyDataMapper2D.js +153 -205
  381. package/Rendering/OpenGL/RadialDistortionPass.js +86 -89
  382. package/Rendering/OpenGL/RenderWindow/Constants.js +2 -2
  383. package/Rendering/OpenGL/RenderWindow/ContextProxy.js +20 -29
  384. package/Rendering/OpenGL/RenderWindow.js +356 -510
  385. package/Rendering/OpenGL/Renderer.js +77 -89
  386. package/Rendering/OpenGL/ReplacementShaderMapper.js +28 -46
  387. package/Rendering/OpenGL/ScalarBarActor.js +28 -21
  388. package/Rendering/OpenGL/Shader.js +37 -31
  389. package/Rendering/OpenGL/ShaderCache.js +67 -74
  390. package/Rendering/OpenGL/ShaderProgram.js +136 -248
  391. package/Rendering/OpenGL/Skybox.js +99 -60
  392. package/Rendering/OpenGL/SphereMapper.js +94 -108
  393. package/Rendering/OpenGL/StickMapper.js +110 -114
  394. package/Rendering/OpenGL/SurfaceLIC/LineIntegralConvolution2D/pingpong.js +91 -157
  395. package/Rendering/OpenGL/SurfaceLIC/LineIntegralConvolution2D.js +142 -151
  396. package/Rendering/OpenGL/SurfaceLIC/SurfaceLICInterface.js +142 -216
  397. package/Rendering/OpenGL/SurfaceLIC/SurfaceLICMapper.js +79 -100
  398. package/Rendering/OpenGL/SurfaceLIC.js +2 -2
  399. package/Rendering/OpenGL/Texture/Constants.js +4 -4
  400. package/Rendering/OpenGL/Texture.js +443 -608
  401. package/Rendering/OpenGL/TextureUnitManager.js +47 -43
  402. package/Rendering/OpenGL/VertexArrayObject.js +92 -131
  403. package/Rendering/OpenGL/ViewNodeFactory.js +25 -13
  404. package/Rendering/OpenGL/Volume.js +38 -34
  405. package/Rendering/OpenGL/VolumeMapper.js +437 -547
  406. package/Rendering/OpenGL.js +28 -28
  407. package/Rendering/SceneGraph/RenderPass.js +34 -31
  408. package/Rendering/SceneGraph/RenderWindowViewNode.js +68 -94
  409. package/Rendering/SceneGraph/ViewNode.js +82 -111
  410. package/Rendering/SceneGraph/ViewNodeFactory.js +31 -26
  411. package/Rendering/SceneGraph.js +4 -4
  412. package/Rendering/WebGPU/Actor.js +49 -49
  413. package/Rendering/WebGPU/Actor2D.js +45 -44
  414. package/Rendering/WebGPU/BindGroup.js +43 -50
  415. package/Rendering/WebGPU/Buffer.js +41 -50
  416. package/Rendering/WebGPU/BufferManager/Constants.js +4 -4
  417. package/Rendering/WebGPU/BufferManager.js +111 -141
  418. package/Rendering/WebGPU/Camera.js +65 -67
  419. package/Rendering/WebGPU/CellArrayMapper.js +621 -388
  420. package/Rendering/WebGPU/CubeAxesActor.js +28 -19
  421. package/Rendering/WebGPU/Device.js +78 -133
  422. package/Rendering/WebGPU/ForwardPass.js +75 -72
  423. package/Rendering/WebGPU/FullScreenQuad.js +25 -18
  424. package/Rendering/WebGPU/Glyph3DMapper.js +62 -74
  425. package/Rendering/WebGPU/HardwareSelectionPass.js +45 -38
  426. package/Rendering/WebGPU/HardwareSelector.js +200 -276
  427. package/Rendering/WebGPU/ImageMapper.js +180 -171
  428. package/Rendering/WebGPU/ImageSlice.js +45 -44
  429. package/Rendering/WebGPU/IndexBuffer.js +166 -200
  430. package/Rendering/WebGPU/OpaquePass.js +37 -36
  431. package/Rendering/WebGPU/OrderIndependentTranslucentPass.js +72 -45
  432. package/Rendering/WebGPU/Pipeline.js +37 -51
  433. package/Rendering/WebGPU/PixelSpaceCallbackMapper.js +27 -19
  434. package/Rendering/WebGPU/PolyDataMapper.js +50 -53
  435. package/Rendering/WebGPU/PolyDataMapper2D.js +39 -39
  436. package/Rendering/WebGPU/RenderEncoder.js +68 -88
  437. package/Rendering/WebGPU/RenderWindow.js +262 -376
  438. package/Rendering/WebGPU/Renderer.js +224 -208
  439. package/Rendering/WebGPU/Sampler.js +27 -21
  440. package/Rendering/WebGPU/ScalarBarActor.js +28 -19
  441. package/Rendering/WebGPU/ShaderCache.js +43 -41
  442. package/Rendering/WebGPU/ShaderDescription.js +52 -59
  443. package/Rendering/WebGPU/ShaderModule.js +26 -17
  444. package/Rendering/WebGPU/SimpleMapper.js +185 -121
  445. package/Rendering/WebGPU/SphereMapper.js +200 -130
  446. package/Rendering/WebGPU/StickMapper.js +289 -152
  447. package/Rendering/WebGPU/StorageBuffer.js +100 -115
  448. package/Rendering/WebGPU/Texture.js +79 -99
  449. package/Rendering/WebGPU/TextureManager.js +52 -54
  450. package/Rendering/WebGPU/TextureView.js +40 -43
  451. package/Rendering/WebGPU/Types.js +53 -70
  452. package/Rendering/WebGPU/UniformBuffer.js +158 -184
  453. package/Rendering/WebGPU/VertexInput.js +64 -90
  454. package/Rendering/WebGPU/ViewNodeFactory.js +25 -13
  455. package/Rendering/WebGPU/Volume.js +52 -51
  456. package/Rendering/WebGPU/VolumePass.js +218 -239
  457. package/Rendering/WebGPU/VolumePassFSQ.js +625 -306
  458. package/Rendering/WebGPU.js +1 -1
  459. package/Rendering/index.js +5 -5
  460. package/Widgets/Core/AbstractWidget/Constants.js +2 -2
  461. package/Widgets/Core/AbstractWidget.js +49 -58
  462. package/Widgets/Core/AbstractWidgetFactory.js +101 -122
  463. package/Widgets/Core/StateBuilder/boundsMixin.js +23 -28
  464. package/Widgets/Core/StateBuilder/color3Mixin.js +10 -7
  465. package/Widgets/Core/StateBuilder/colorMixin.js +10 -6
  466. package/Widgets/Core/StateBuilder/cornerMixin.js +16 -15
  467. package/Widgets/Core/StateBuilder/directionMixin.js +20 -18
  468. package/Widgets/Core/StateBuilder/manipulatorMixin.js +26 -18
  469. package/Widgets/Core/StateBuilder/nameMixin.js +10 -6
  470. package/Widgets/Core/StateBuilder/orientationMixin.js +19 -16
  471. package/Widgets/Core/StateBuilder/originMixin.js +25 -32
  472. package/Widgets/Core/StateBuilder/scale1Mixin.js +10 -6
  473. package/Widgets/Core/StateBuilder/scale3Mixin.js +10 -6
  474. package/Widgets/Core/StateBuilder/shapeMixin.js +12 -6
  475. package/Widgets/Core/StateBuilder/textMixin.js +10 -6
  476. package/Widgets/Core/StateBuilder/visibleMixin.js +10 -6
  477. package/Widgets/Core/StateBuilder.js +120 -149
  478. package/Widgets/Core/WidgetManager/Constants.js +7 -7
  479. package/Widgets/Core/WidgetManager.js +249 -421
  480. package/Widgets/Core/WidgetState.js +48 -57
  481. package/Widgets/Core.js +5 -5
  482. package/Widgets/Manipulators/AbstractManipulator.js +20 -14
  483. package/Widgets/Manipulators/CPRManipulator.js +55 -71
  484. package/Widgets/Manipulators/LineManipulator.js +31 -28
  485. package/Widgets/Manipulators/PickerManipulator.d.ts +48 -0
  486. package/Widgets/Manipulators/PickerManipulator.js +65 -0
  487. package/Widgets/Manipulators/PlaneManipulator.js +26 -23
  488. package/Widgets/Manipulators/TrackballManipulator.js +39 -35
  489. package/Widgets/Manipulators.js +4 -2
  490. package/Widgets/Representations/ArrowHandleRepresentation.js +148 -162
  491. package/Widgets/Representations/CircleContextRepresentation.js +44 -38
  492. package/Widgets/Representations/ContextRepresentation.js +17 -14
  493. package/Widgets/Representations/ConvexFaceContextRepresentation.js +50 -47
  494. package/Widgets/Representations/CroppingOutlineRepresentation.js +38 -27
  495. package/Widgets/Representations/CubeHandleRepresentation.js +21 -18
  496. package/Widgets/Representations/GlyphRepresentation.js +107 -152
  497. package/Widgets/Representations/HandleRepresentation.js +17 -14
  498. package/Widgets/Representations/ImplicitPlaneRepresentation.js +97 -91
  499. package/Widgets/Representations/LineHandleRepresentation.js +44 -41
  500. package/Widgets/Representations/OutlineContextRepresentation.js +42 -36
  501. package/Widgets/Representations/PolyLineRepresentation.js +60 -75
  502. package/Widgets/Representations/RectangleContextRepresentation.js +42 -37
  503. package/Widgets/Representations/SphereContextRepresentation.js +19 -27
  504. package/Widgets/Representations/SphereHandleRepresentation.js +31 -27
  505. package/Widgets/Representations/SplineContextRepresentation.js +46 -70
  506. package/Widgets/Representations/WidgetRepresentation/Constants.js +2 -2
  507. package/Widgets/Representations/WidgetRepresentation.js +99 -134
  508. package/Widgets/Representations.js +13 -13
  509. package/Widgets/Widgets3D/AngleWidget/behavior.js +41 -63
  510. package/Widgets/Widgets3D/AngleWidget.js +40 -38
  511. package/Widgets/Widgets3D/DistanceWidget/behavior.js +40 -61
  512. package/Widgets/Widgets3D/DistanceWidget.js +38 -36
  513. package/Widgets/Widgets3D/EllipseWidget/behavior.js +14 -19
  514. package/Widgets/Widgets3D/EllipseWidget/state.js +4 -2
  515. package/Widgets/Widgets3D/EllipseWidget.js +37 -26
  516. package/Widgets/Widgets3D/ImageCroppingWidget/behavior.js +26 -56
  517. package/Widgets/Widgets3D/ImageCroppingWidget/helpers.js +14 -17
  518. package/Widgets/Widgets3D/ImageCroppingWidget/state.js +20 -16
  519. package/Widgets/Widgets3D/ImageCroppingWidget.js +80 -98
  520. package/Widgets/Widgets3D/ImplicitPlaneWidget.js +55 -77
  521. package/Widgets/Widgets3D/InteractiveOrientationWidget/behavior.js +17 -18
  522. package/Widgets/Widgets3D/InteractiveOrientationWidget/state.js +15 -7
  523. package/Widgets/Widgets3D/InteractiveOrientationWidget.js +30 -29
  524. package/Widgets/Widgets3D/LabelWidget/behavior.js +37 -62
  525. package/Widgets/Widgets3D/LabelWidget.js +31 -25
  526. package/Widgets/Widgets3D/LineWidget/Constants.js +8 -8
  527. package/Widgets/Widgets3D/LineWidget/behavior.js +77 -114
  528. package/Widgets/Widgets3D/LineWidget/helpers.js +13 -20
  529. package/Widgets/Widgets3D/LineWidget/state.js +2 -1
  530. package/Widgets/Widgets3D/LineWidget.js +39 -35
  531. package/Widgets/Widgets3D/PaintWidget/behavior.js +24 -59
  532. package/Widgets/Widgets3D/PaintWidget.js +39 -37
  533. package/Widgets/Widgets3D/PolyLineWidget/behavior.js +44 -68
  534. package/Widgets/Widgets3D/PolyLineWidget.js +36 -31
  535. package/Widgets/Widgets3D/RectangleWidget/behavior.js +6 -11
  536. package/Widgets/Widgets3D/RectangleWidget/state.js +4 -2
  537. package/Widgets/Widgets3D/RectangleWidget.js +37 -25
  538. package/Widgets/Widgets3D/ResliceCursorWidget/Constants.js +35 -21
  539. package/Widgets/Widgets3D/ResliceCursorWidget/behavior.js +133 -209
  540. package/Widgets/Widgets3D/ResliceCursorWidget/cprBehavior.js +26 -41
  541. package/Widgets/Widgets3D/ResliceCursorWidget/helpers.js +89 -116
  542. package/Widgets/Widgets3D/ResliceCursorWidget/state.js +33 -40
  543. package/Widgets/Widgets3D/ResliceCursorWidget.js +186 -227
  544. package/Widgets/Widgets3D/SeedWidget/behavior.js +82 -0
  545. package/Widgets/Widgets3D/SeedWidget/state.js +18 -0
  546. package/Widgets/Widgets3D/SeedWidget.d.ts +44 -0
  547. package/Widgets/Widgets3D/SeedWidget.js +43 -0
  548. package/Widgets/Widgets3D/ShapeWidget/Constants.js +19 -19
  549. package/Widgets/Widgets3D/ShapeWidget/behavior.js +150 -252
  550. package/Widgets/Widgets3D/ShapeWidget.js +24 -27
  551. package/Widgets/Widgets3D/SphereWidget/behavior.js +35 -69
  552. package/Widgets/Widgets3D/SphereWidget/state.js +9 -5
  553. package/Widgets/Widgets3D/SphereWidget.js +34 -44
  554. package/Widgets/Widgets3D/SplineWidget/behavior.js +85 -120
  555. package/Widgets/Widgets3D/SplineWidget.js +43 -39
  556. package/Widgets/Widgets3D.js +15 -15
  557. package/Widgets/index.js +4 -4
  558. package/_virtual/rollup-plugin-worker-loader__module_Sources/Filters/General/PaintFilter/PaintFilter.worker.js +95 -207
  559. package/_virtual/rollup-plugin-worker-loader__module_Sources/Interaction/Widgets/PiecewiseGaussianWidget/ComputeHistogram.worker.js +0 -3
  560. package/favicon.js +5 -6
  561. package/index.d.ts +4 -2
  562. package/index.js +4 -3
  563. package/macros.js +4 -1931
  564. package/macros2.js +1684 -0
  565. package/package.json +6 -6
  566. package/vtk.js +18 -31
package/macros2.js ADDED
@@ -0,0 +1,1684 @@
1
+ import DeepEqual from 'fast-deep-equal';
2
+ import vtk, { vtkGlobal } from './vtk.js';
3
+ import ClassHierarchy from './Common/Core/ClassHierarchy.js';
4
+
5
+ /**
6
+ * macros.js is the old macro.js.
7
+ * The name change is so we do not get eaten by babel-plugin-macros.
8
+ */
9
+ let globalMTime = 0;
10
+ const VOID = Symbol('void');
11
+ function getCurrentGlobalMTime() {
12
+ return globalMTime;
13
+ }
14
+
15
+ // ----------------------------------------------------------------------------
16
+ // Logging function calls
17
+ // ----------------------------------------------------------------------------
18
+ /* eslint-disable no-prototype-builtins */
19
+
20
+ const fakeConsole = {};
21
+ function noOp() {}
22
+ const consoleMethods = ['log', 'debug', 'info', 'warn', 'error', 'time', 'timeEnd', 'group', 'groupEnd'];
23
+ consoleMethods.forEach(methodName => {
24
+ fakeConsole[methodName] = noOp;
25
+ });
26
+ vtkGlobal.console = console.hasOwnProperty('log') ? console : fakeConsole;
27
+ const loggerFunctions = {
28
+ debug: noOp,
29
+ // Don't print debug by default
30
+ error: vtkGlobal.console.error || noOp,
31
+ info: vtkGlobal.console.info || noOp,
32
+ log: vtkGlobal.console.log || noOp,
33
+ warn: vtkGlobal.console.warn || noOp
34
+ };
35
+ function setLoggerFunction(name, fn) {
36
+ if (loggerFunctions[name]) {
37
+ loggerFunctions[name] = fn || noOp;
38
+ }
39
+ }
40
+ function vtkLogMacro() {
41
+ loggerFunctions.log(...arguments);
42
+ }
43
+ function vtkInfoMacro() {
44
+ loggerFunctions.info(...arguments);
45
+ }
46
+ function vtkDebugMacro() {
47
+ loggerFunctions.debug(...arguments);
48
+ }
49
+ function vtkErrorMacro() {
50
+ loggerFunctions.error(...arguments);
51
+ }
52
+ function vtkWarningMacro() {
53
+ loggerFunctions.warn(...arguments);
54
+ }
55
+ const ERROR_ONCE_MAP = {};
56
+ function vtkOnceErrorMacro(str) {
57
+ if (!ERROR_ONCE_MAP[str]) {
58
+ loggerFunctions.error(str);
59
+ ERROR_ONCE_MAP[str] = true;
60
+ }
61
+ }
62
+
63
+ // ----------------------------------------------------------------------------
64
+ // TypedArray
65
+ // ----------------------------------------------------------------------------
66
+
67
+ const TYPED_ARRAYS = Object.create(null);
68
+ TYPED_ARRAYS.Float32Array = Float32Array;
69
+ TYPED_ARRAYS.Float64Array = Float64Array;
70
+ TYPED_ARRAYS.Uint8Array = Uint8Array;
71
+ TYPED_ARRAYS.Int8Array = Int8Array;
72
+ TYPED_ARRAYS.Uint16Array = Uint16Array;
73
+ TYPED_ARRAYS.Int16Array = Int16Array;
74
+ TYPED_ARRAYS.Uint32Array = Uint32Array;
75
+ TYPED_ARRAYS.Int32Array = Int32Array;
76
+ TYPED_ARRAYS.Uint8ClampedArray = Uint8ClampedArray;
77
+ try {
78
+ TYPED_ARRAYS.BigInt64Array = BigInt64Array;
79
+ TYPED_ARRAYS.BigUint64Array = BigUint64Array;
80
+ } catch {
81
+ // ignore
82
+ }
83
+ function newTypedArray(type) {
84
+ for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
85
+ args[_key - 1] = arguments[_key];
86
+ }
87
+ return new (TYPED_ARRAYS[type] || Float64Array)(...args);
88
+ }
89
+ function newTypedArrayFrom(type) {
90
+ for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
91
+ args[_key2 - 1] = arguments[_key2];
92
+ }
93
+ return (TYPED_ARRAYS[type] || Float64Array).from(...args);
94
+ }
95
+
96
+ // ----------------------------------------------------------------------------
97
+ // capitilize provided string
98
+ // ----------------------------------------------------------------------------
99
+
100
+ function capitalize(str) {
101
+ return str.charAt(0).toUpperCase() + str.slice(1);
102
+ }
103
+ function _capitalize(str) {
104
+ return capitalize(str[0] === '_' ? str.slice(1) : str);
105
+ }
106
+ function uncapitalize(str) {
107
+ return str.charAt(0).toLowerCase() + str.slice(1);
108
+ }
109
+
110
+ // ----------------------------------------------------------------------------
111
+ // Convert byte size into a well formatted string
112
+ // ----------------------------------------------------------------------------
113
+
114
+ function formatBytesToProperUnit(size) {
115
+ let precision = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 2;
116
+ let chunkSize = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1000;
117
+ const units = ['TB', 'GB', 'MB', 'KB'];
118
+ let value = Number(size);
119
+ let currentUnit = 'B';
120
+ while (value > chunkSize) {
121
+ value /= chunkSize;
122
+ currentUnit = units.pop();
123
+ }
124
+ return `${value.toFixed(precision)} ${currentUnit}`;
125
+ }
126
+
127
+ // ----------------------------------------------------------------------------
128
+ // Convert thousand number with proper separator
129
+ // ----------------------------------------------------------------------------
130
+
131
+ function formatNumbersWithThousandSeparator(n) {
132
+ let separator = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : ' ';
133
+ const sections = [];
134
+ let size = n;
135
+ while (size > 1000) {
136
+ sections.push(`000${size % 1000}`.slice(-3));
137
+ size = Math.floor(size / 1000);
138
+ }
139
+ if (size > 0) {
140
+ sections.push(size);
141
+ }
142
+ sections.reverse();
143
+ return sections.join(separator);
144
+ }
145
+
146
+ // ----------------------------------------------------------------------------
147
+ // Array helper
148
+ // ----------------------------------------------------------------------------
149
+
150
+ function safeArrays(model) {
151
+ Object.keys(model).forEach(key => {
152
+ if (Array.isArray(model[key])) {
153
+ model[key] = [].concat(model[key]);
154
+ }
155
+ });
156
+ }
157
+
158
+ // ----------------------------------------------------------------------------
159
+ // shallow equals
160
+ // ----------------------------------------------------------------------------
161
+
162
+ function shallowEquals(a, b) {
163
+ if (a === b) {
164
+ return true;
165
+ }
166
+ if (Array.isArray(a) && Array.isArray(b)) {
167
+ if (a.length !== b.length) {
168
+ return false;
169
+ }
170
+ for (let i = 0; i < a.length; i++) {
171
+ if (a[i] !== b[i]) {
172
+ return false;
173
+ }
174
+ }
175
+ return true;
176
+ }
177
+ return false;
178
+ }
179
+
180
+ // ----------------------------------------------------------------------------
181
+
182
+ function enumToString(e, value) {
183
+ return Object.keys(e).find(key => e[key] === value);
184
+ }
185
+ function getStateArrayMapFunc(item) {
186
+ if (item && item.isA) {
187
+ return item.getState();
188
+ }
189
+ return item;
190
+ }
191
+
192
+ // ----------------------------------------------------------------------------
193
+ // setImmediate
194
+ // ----------------------------------------------------------------------------
195
+
196
+ function setImmediateVTK(fn) {
197
+ setTimeout(fn, 0);
198
+ }
199
+
200
+ // ----------------------------------------------------------------------------
201
+ // measurePromiseExecution
202
+ //
203
+ // Measures the time it takes for a promise to finish from
204
+ // the time this function is invoked.
205
+ // The callback receives the time it took for the promise to resolve or reject.
206
+ // ----------------------------------------------------------------------------
207
+
208
+ function measurePromiseExecution(promise, callback) {
209
+ const start = performance.now();
210
+ promise.finally(() => {
211
+ const delta = performance.now() - start;
212
+ callback(delta);
213
+ });
214
+ }
215
+
216
+ // ----------------------------------------------------------------------------
217
+ // vtkObject: modified(), onModified(callback), delete()
218
+ // ----------------------------------------------------------------------------
219
+
220
+ function obj() {
221
+ let publicAPI = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
222
+ let model = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
223
+ // Ensure each instance as a unique ref of array
224
+ safeArrays(model);
225
+ const callbacks = [];
226
+ if (!Number.isInteger(model.mtime)) {
227
+ model.mtime = ++globalMTime;
228
+ }
229
+ if (!('classHierarchy' in model)) {
230
+ model.classHierarchy = new ClassHierarchy('vtkObject');
231
+ } else if (!(model.classHierarchy instanceof ClassHierarchy)) {
232
+ const hierarchy = new ClassHierarchy();
233
+ for (let i = 0; i < model.classHierarchy.length; i++) {
234
+ hierarchy.push(model.classHierarchy[i]);
235
+ }
236
+ model.classHierarchy = hierarchy;
237
+ }
238
+ function off(index) {
239
+ callbacks[index] = null;
240
+ }
241
+ function on(index) {
242
+ function unsubscribe() {
243
+ off(index);
244
+ }
245
+ return Object.freeze({
246
+ unsubscribe
247
+ });
248
+ }
249
+ publicAPI.isDeleted = () => !!model.deleted;
250
+ publicAPI.modified = otherMTime => {
251
+ if (model.deleted) {
252
+ vtkErrorMacro('instance deleted - cannot call any method');
253
+ return;
254
+ }
255
+ if (otherMTime && otherMTime < publicAPI.getMTime()) {
256
+ return;
257
+ }
258
+ model.mtime = ++globalMTime;
259
+ callbacks.forEach(callback => callback && callback(publicAPI));
260
+ };
261
+ publicAPI.onModified = callback => {
262
+ if (model.deleted) {
263
+ vtkErrorMacro('instance deleted - cannot call any method');
264
+ return null;
265
+ }
266
+ const index = callbacks.length;
267
+ callbacks.push(callback);
268
+ return on(index);
269
+ };
270
+ publicAPI.getMTime = () => model.mtime;
271
+ publicAPI.isA = className => {
272
+ let count = model.classHierarchy.length;
273
+ // we go backwards as that is more likely for
274
+ // early termination
275
+ while (count--) {
276
+ if (model.classHierarchy[count] === className) {
277
+ return true;
278
+ }
279
+ }
280
+ return false;
281
+ };
282
+ publicAPI.getClassName = function () {
283
+ let depth = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
284
+ return model.classHierarchy[model.classHierarchy.length - 1 - depth];
285
+ };
286
+ publicAPI.set = function () {
287
+ let map = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
288
+ let noWarning = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
289
+ let noFunction = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
290
+ let ret = false;
291
+ Object.keys(map).forEach(name => {
292
+ const fn = noFunction ? null : publicAPI[`set${capitalize(name)}`];
293
+ if (fn && Array.isArray(map[name]) && fn.length > 1) {
294
+ ret = fn(...map[name]) || ret;
295
+ } else if (fn) {
296
+ ret = fn(map[name]) || ret;
297
+ } else {
298
+ // Set data on model directly
299
+ if (['mtime'].indexOf(name) === -1 && !noWarning) {
300
+ vtkWarningMacro(`Warning: Set value to model directly ${name}, ${map[name]}`);
301
+ }
302
+ ret = model[name] !== map[name] || ret;
303
+ model[name] = map[name];
304
+ }
305
+ });
306
+ return ret;
307
+ };
308
+ publicAPI.get = function () {
309
+ for (var _len3 = arguments.length, list = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
310
+ list[_key3] = arguments[_key3];
311
+ }
312
+ if (!list.length) {
313
+ return model;
314
+ }
315
+ const subset = {};
316
+ list.forEach(name => {
317
+ subset[name] = model[name];
318
+ });
319
+ return subset;
320
+ };
321
+ publicAPI.getReferenceByName = val => model[val];
322
+ publicAPI.delete = () => {
323
+ Object.keys(model).forEach(field => delete model[field]);
324
+ callbacks.forEach((el, index) => off(index));
325
+
326
+ // Flag the instance being deleted
327
+ model.deleted = true;
328
+ };
329
+
330
+ // Add serialization support
331
+ publicAPI.getState = () => {
332
+ if (model.deleted) {
333
+ return null;
334
+ }
335
+ const jsonArchive = {
336
+ ...model,
337
+ vtkClass: publicAPI.getClassName()
338
+ };
339
+
340
+ // Convert every vtkObject to its serializable form
341
+ Object.keys(jsonArchive).forEach(keyName => {
342
+ if (jsonArchive[keyName] === null || jsonArchive[keyName] === undefined || keyName[0] === '_' // protected members start with _
343
+ ) {
344
+ delete jsonArchive[keyName];
345
+ } else if (jsonArchive[keyName].isA) {
346
+ jsonArchive[keyName] = jsonArchive[keyName].getState();
347
+ } else if (Array.isArray(jsonArchive[keyName])) {
348
+ jsonArchive[keyName] = jsonArchive[keyName].map(getStateArrayMapFunc);
349
+ }
350
+ });
351
+
352
+ // Sort resulting object by key name
353
+ const sortedObj = {};
354
+ Object.keys(jsonArchive).sort().forEach(name => {
355
+ sortedObj[name] = jsonArchive[name];
356
+ });
357
+
358
+ // Remove mtime
359
+ if (sortedObj.mtime) {
360
+ delete sortedObj.mtime;
361
+ }
362
+ return sortedObj;
363
+ };
364
+
365
+ // Add shallowCopy(otherInstance) support
366
+ publicAPI.shallowCopy = function (other) {
367
+ let debug = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
368
+ if (other.getClassName() !== publicAPI.getClassName()) {
369
+ throw new Error(`Cannot ShallowCopy ${other.getClassName()} into ${publicAPI.getClassName()}`);
370
+ }
371
+ const otherModel = other.get();
372
+ const keyList = Object.keys(model).sort();
373
+ const otherKeyList = Object.keys(otherModel).sort();
374
+ otherKeyList.forEach(key => {
375
+ const keyIdx = keyList.indexOf(key);
376
+ if (keyIdx === -1) {
377
+ if (debug) {
378
+ vtkDebugMacro(`add ${key} in shallowCopy`);
379
+ }
380
+ } else {
381
+ keyList.splice(keyIdx, 1);
382
+ }
383
+ model[key] = otherModel[key];
384
+ });
385
+ if (keyList.length && debug) {
386
+ vtkDebugMacro(`Untouched keys: ${keyList.join(', ')}`);
387
+ }
388
+ publicAPI.modified();
389
+ };
390
+
391
+ // This function will get called when one invoke JSON.stringify(vtkObject)
392
+ // JSON.stringify will only stringify the return value of this function
393
+ publicAPI.toJSON = function vtkObjToJSON() {
394
+ return publicAPI.getState();
395
+ };
396
+
397
+ // Allow usage as decorator
398
+ return publicAPI;
399
+ }
400
+
401
+ // ----------------------------------------------------------------------------
402
+ // getXXX: add getters
403
+ // ----------------------------------------------------------------------------
404
+
405
+ const objectGetterMap = {
406
+ object(publicAPI, model, field) {
407
+ return function getter() {
408
+ return {
409
+ ...model[field.name]
410
+ };
411
+ };
412
+ }
413
+ };
414
+ function get(publicAPI, model, fieldNames) {
415
+ fieldNames.forEach(field => {
416
+ if (typeof field === 'object') {
417
+ const getter = objectGetterMap[field.type];
418
+ if (getter) {
419
+ publicAPI[`get${_capitalize(field.name)}`] = getter(publicAPI, model, field);
420
+ } else {
421
+ publicAPI[`get${_capitalize(field.name)}`] = () => model[field.name];
422
+ }
423
+ } else {
424
+ publicAPI[`get${_capitalize(field)}`] = () => model[field];
425
+ }
426
+ });
427
+ }
428
+
429
+ // ----------------------------------------------------------------------------
430
+ // setXXX: add setters
431
+ // ----------------------------------------------------------------------------
432
+
433
+ const objectSetterMap = {
434
+ enum(publicAPI, model, field) {
435
+ const onChanged = `_on${_capitalize(field.name)}Changed`;
436
+ return value => {
437
+ if (typeof value === 'string') {
438
+ if (field.enum[value] !== undefined) {
439
+ if (model[field.name] !== field.enum[value]) {
440
+ model[field.name] = field.enum[value];
441
+ publicAPI.modified();
442
+ return true;
443
+ }
444
+ return false;
445
+ }
446
+ vtkErrorMacro(`Set Enum with invalid argument ${field}, ${value}`);
447
+ throw new RangeError('Set Enum with invalid string argument');
448
+ }
449
+ if (typeof value === 'number') {
450
+ if (model[field.name] !== value) {
451
+ if (Object.keys(field.enum).map(key => field.enum[key]).indexOf(value) !== -1) {
452
+ const previousValue = model[field.name];
453
+ model[field.name] = value;
454
+ model[onChanged]?.(publicAPI, model, value, previousValue);
455
+ publicAPI.modified();
456
+ return true;
457
+ }
458
+ vtkErrorMacro(`Set Enum outside numeric range ${field}, ${value}`);
459
+ throw new RangeError('Set Enum outside numeric range');
460
+ }
461
+ return false;
462
+ }
463
+ vtkErrorMacro(`Set Enum with invalid argument (String/Number) ${field}, ${value}`);
464
+ throw new TypeError('Set Enum with invalid argument (String/Number)');
465
+ };
466
+ },
467
+ object(publicAPI, model, field) {
468
+ const onChanged = `_on${_capitalize(field.name)}Changed`;
469
+ return value => {
470
+ if (!DeepEqual(model[field.name], value)) {
471
+ const previousValue = model[field.name];
472
+ model[field.name] = value;
473
+ model[onChanged]?.(publicAPI, model, value, previousValue);
474
+ publicAPI.modified();
475
+ return true;
476
+ }
477
+ return false;
478
+ };
479
+ }
480
+ };
481
+ function findSetter(field) {
482
+ if (typeof field === 'object') {
483
+ const fn = objectSetterMap[field.type];
484
+ if (fn) {
485
+ return (publicAPI, model) => fn(publicAPI, model, field);
486
+ }
487
+ vtkErrorMacro(`No setter for field ${field}`);
488
+ throw new TypeError('No setter for field');
489
+ }
490
+ return function getSetter(publicAPI, model) {
491
+ const onChanged = `_on${_capitalize(field)}Changed`;
492
+ return function setter(value) {
493
+ if (model.deleted) {
494
+ vtkErrorMacro('instance deleted - cannot call any method');
495
+ return false;
496
+ }
497
+ if (model[field] !== value) {
498
+ const previousValue = model[field.name];
499
+ model[field] = value;
500
+ model[onChanged]?.(publicAPI, model, value, previousValue);
501
+ publicAPI.modified();
502
+ return true;
503
+ }
504
+ return false;
505
+ };
506
+ };
507
+ }
508
+ function set(publicAPI, model, fields) {
509
+ fields.forEach(field => {
510
+ if (typeof field === 'object') {
511
+ publicAPI[`set${_capitalize(field.name)}`] = findSetter(field)(publicAPI, model);
512
+ } else {
513
+ publicAPI[`set${_capitalize(field)}`] = findSetter(field)(publicAPI, model);
514
+ }
515
+ });
516
+ }
517
+
518
+ // ----------------------------------------------------------------------------
519
+ // set/get XXX: add both setters and getters
520
+ // ----------------------------------------------------------------------------
521
+
522
+ function setGet(publicAPI, model, fieldNames) {
523
+ get(publicAPI, model, fieldNames);
524
+ set(publicAPI, model, fieldNames);
525
+ }
526
+
527
+ // ----------------------------------------------------------------------------
528
+ // getXXX: add getters for object of type array with copy to be safe
529
+ // getXXXByReference: add getters for object of type array without copy
530
+ // ----------------------------------------------------------------------------
531
+
532
+ function getArray(publicAPI, model, fieldNames) {
533
+ fieldNames.forEach(field => {
534
+ publicAPI[`get${_capitalize(field)}`] = () => model[field] ? Array.from(model[field]) : model[field];
535
+ publicAPI[`get${_capitalize(field)}ByReference`] = () => model[field];
536
+ });
537
+ }
538
+
539
+ // ----------------------------------------------------------------------------
540
+ // setXXX: add setter for object of type array
541
+ // if 'defaultVal' is supplied, shorter arrays will be padded to 'size' with 'defaultVal'
542
+ // set...From: fast path to copy the content of an array to the current one without call to modified.
543
+ // ----------------------------------------------------------------------------
544
+
545
+ function setArray(publicAPI, model, fieldNames, size) {
546
+ let defaultVal = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : undefined;
547
+ fieldNames.forEach(field => {
548
+ if (model[field] && size && model[field].length !== size) {
549
+ throw new RangeError(`Invalid initial number of values for array (${field})`);
550
+ }
551
+ const onChanged = `_on${_capitalize(field)}Changed`;
552
+ publicAPI[`set${_capitalize(field)}`] = function () {
553
+ if (model.deleted) {
554
+ vtkErrorMacro('instance deleted - cannot call any method');
555
+ return false;
556
+ }
557
+ for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
558
+ args[_key4] = arguments[_key4];
559
+ }
560
+ let array = args;
561
+ let changeDetected;
562
+ let needCopy = false;
563
+ // allow null or an array to be passed as a single arg.
564
+ if (array.length === 1 && (array[0] == null || array[0].length >= 0)) {
565
+ /* eslint-disable prefer-destructuring */
566
+ array = array[0];
567
+ /* eslint-enable prefer-destructuring */
568
+ needCopy = true;
569
+ }
570
+ if (array == null) {
571
+ changeDetected = model[field] !== array;
572
+ } else {
573
+ if (size && array.length !== size) {
574
+ if (array.length < size && defaultVal !== undefined) {
575
+ array = Array.from(array);
576
+ needCopy = false;
577
+ while (array.length < size) array.push(defaultVal);
578
+ } else {
579
+ throw new RangeError(`Invalid number of values for array setter (${field})`);
580
+ }
581
+ }
582
+ changeDetected = model[field] == null || model[field].length !== array.length;
583
+ for (let i = 0; !changeDetected && i < array.length; ++i) {
584
+ changeDetected = model[field][i] !== array[i];
585
+ }
586
+ if (changeDetected && needCopy) {
587
+ array = Array.from(array);
588
+ }
589
+ }
590
+ if (changeDetected) {
591
+ const previousValue = model[field.name];
592
+ model[field] = array;
593
+ model[onChanged]?.(publicAPI, model, array, previousValue);
594
+ publicAPI.modified();
595
+ }
596
+ return changeDetected;
597
+ };
598
+ publicAPI[`set${_capitalize(field)}From`] = otherArray => {
599
+ const target = model[field];
600
+ otherArray.forEach((v, i) => {
601
+ target[i] = v;
602
+ });
603
+ };
604
+ });
605
+ }
606
+
607
+ // ----------------------------------------------------------------------------
608
+ // set/get XXX: add setter and getter for object of type array
609
+ // ----------------------------------------------------------------------------
610
+
611
+ function setGetArray(publicAPI, model, fieldNames, size) {
612
+ let defaultVal = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : undefined;
613
+ getArray(publicAPI, model, fieldNames);
614
+ setArray(publicAPI, model, fieldNames, size, defaultVal);
615
+ }
616
+ function moveToProtected(publicAPI, model, fieldNames) {
617
+ for (let i = 0; i < fieldNames.length; i++) {
618
+ const fieldName = fieldNames[i];
619
+ if (model[fieldName] !== undefined) {
620
+ model[`_${fieldName}`] = model[fieldName];
621
+ delete model[fieldName];
622
+ }
623
+ }
624
+ }
625
+ // ----------------------------------------------------------------------------
626
+ // vtkAlgorithm: setInputData(), setInputConnection(), getOutputData(), getOutputPort()
627
+ // ----------------------------------------------------------------------------
628
+
629
+ function algo(publicAPI, model, numberOfInputs, numberOfOutputs) {
630
+ if (model.inputData) {
631
+ model.inputData = model.inputData.map(vtk);
632
+ } else {
633
+ model.inputData = [];
634
+ }
635
+ if (model.inputConnection) {
636
+ model.inputConnection = model.inputConnection.map(vtk);
637
+ } else {
638
+ model.inputConnection = [];
639
+ }
640
+ if (model.output) {
641
+ model.output = model.output.map(vtk);
642
+ } else {
643
+ model.output = [];
644
+ }
645
+ if (model.inputArrayToProcess) {
646
+ model.inputArrayToProcess = model.inputArrayToProcess.map(vtk);
647
+ } else {
648
+ model.inputArrayToProcess = [];
649
+ }
650
+
651
+ // Cache the argument for later manipulation
652
+ model.numberOfInputs = numberOfInputs;
653
+
654
+ // Methods
655
+ function setInputData(dataset) {
656
+ let port = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
657
+ if (model.deleted) {
658
+ vtkErrorMacro('instance deleted - cannot call any method');
659
+ return;
660
+ }
661
+ if (port >= model.numberOfInputs) {
662
+ vtkErrorMacro(`algorithm ${publicAPI.getClassName()} only has ${model.numberOfInputs} input ports. To add more input ports, use addInputData()`);
663
+ return;
664
+ }
665
+ if (model.inputData[port] !== dataset || model.inputConnection[port]) {
666
+ model.inputData[port] = dataset;
667
+ model.inputConnection[port] = null;
668
+ if (publicAPI.modified) {
669
+ publicAPI.modified();
670
+ }
671
+ }
672
+ }
673
+ function getInputData() {
674
+ let port = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
675
+ if (model.inputConnection[port]) {
676
+ model.inputData[port] = model.inputConnection[port]();
677
+ }
678
+ return model.inputData[port];
679
+ }
680
+ function setInputConnection(outputPort) {
681
+ let port = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
682
+ if (model.deleted) {
683
+ vtkErrorMacro('instance deleted - cannot call any method');
684
+ return;
685
+ }
686
+ if (port >= model.numberOfInputs) {
687
+ let msg = `algorithm ${publicAPI.getClassName()} only has `;
688
+ msg += `${model.numberOfInputs}`;
689
+ msg += ' input ports. To add more input ports, use addInputConnection()';
690
+ vtkErrorMacro(msg);
691
+ return;
692
+ }
693
+ model.inputData[port] = null;
694
+ model.inputConnection[port] = outputPort;
695
+ }
696
+ function getInputConnection() {
697
+ let port = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
698
+ return model.inputConnection[port];
699
+ }
700
+ function getPortToFill() {
701
+ let portToFill = model.numberOfInputs;
702
+ while (portToFill && !model.inputData[portToFill - 1] && !model.inputConnection[portToFill - 1]) {
703
+ portToFill--;
704
+ }
705
+ if (portToFill === model.numberOfInputs) {
706
+ model.numberOfInputs++;
707
+ }
708
+ return portToFill;
709
+ }
710
+ function addInputConnection(outputPort) {
711
+ if (model.deleted) {
712
+ vtkErrorMacro('instance deleted - cannot call any method');
713
+ return;
714
+ }
715
+ setInputConnection(outputPort, getPortToFill());
716
+ }
717
+ function addInputData(dataset) {
718
+ if (model.deleted) {
719
+ vtkErrorMacro('instance deleted - cannot call any method');
720
+ return;
721
+ }
722
+ setInputData(dataset, getPortToFill());
723
+ }
724
+ function getOutputData() {
725
+ let port = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
726
+ if (model.deleted) {
727
+ vtkErrorMacro('instance deleted - cannot call any method');
728
+ return null;
729
+ }
730
+ if (publicAPI.shouldUpdate()) {
731
+ publicAPI.update();
732
+ }
733
+ return model.output[port];
734
+ }
735
+ publicAPI.shouldUpdate = () => {
736
+ const localMTime = publicAPI.getMTime();
737
+ let minOutputMTime = Infinity;
738
+ let count = numberOfOutputs;
739
+ while (count--) {
740
+ if (!model.output[count] || model.output[count].isDeleted()) {
741
+ return true;
742
+ }
743
+ const mt = model.output[count].getMTime();
744
+ if (mt < localMTime) {
745
+ return true;
746
+ }
747
+ if (mt < minOutputMTime) {
748
+ minOutputMTime = mt;
749
+ }
750
+ }
751
+ count = model.numberOfInputs;
752
+ while (count--) {
753
+ if (model.inputConnection[count]?.filter.shouldUpdate() || publicAPI.getInputData(count)?.getMTime() > minOutputMTime) {
754
+ return true;
755
+ }
756
+ }
757
+ return false;
758
+ };
759
+ function getOutputPort() {
760
+ let port = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
761
+ const outputPortAccess = () => getOutputData(port);
762
+ // Add reference to filter
763
+ outputPortAccess.filter = publicAPI;
764
+ return outputPortAccess;
765
+ }
766
+
767
+ // Handle input if needed
768
+ if (model.numberOfInputs) {
769
+ // Reserve inputs
770
+ let count = model.numberOfInputs;
771
+ while (count--) {
772
+ model.inputData.push(null);
773
+ model.inputConnection.push(null);
774
+ }
775
+
776
+ // Expose public methods
777
+ publicAPI.setInputData = setInputData;
778
+ publicAPI.setInputConnection = setInputConnection;
779
+ publicAPI.addInputData = addInputData;
780
+ publicAPI.addInputConnection = addInputConnection;
781
+ publicAPI.getInputData = getInputData;
782
+ publicAPI.getInputConnection = getInputConnection;
783
+ }
784
+ if (numberOfOutputs) {
785
+ publicAPI.getOutputData = getOutputData;
786
+ publicAPI.getOutputPort = getOutputPort;
787
+ }
788
+ publicAPI.update = () => {
789
+ const ins = [];
790
+ if (model.numberOfInputs) {
791
+ let count = 0;
792
+ while (count < model.numberOfInputs) {
793
+ ins[count] = publicAPI.getInputData(count);
794
+ count++;
795
+ }
796
+ }
797
+ if (publicAPI.shouldUpdate() && publicAPI.requestData) {
798
+ publicAPI.requestData(ins, model.output);
799
+ }
800
+ };
801
+ publicAPI.getNumberOfInputPorts = () => model.numberOfInputs;
802
+ publicAPI.getNumberOfOutputPorts = () => numberOfOutputs || model.output.length;
803
+ publicAPI.getInputArrayToProcess = inputPort => {
804
+ const arrayDesc = model.inputArrayToProcess[inputPort];
805
+ const ds = model.inputData[inputPort];
806
+ if (arrayDesc && ds) {
807
+ return ds[`get${arrayDesc.fieldAssociation}`]().getArray(arrayDesc.arrayName);
808
+ }
809
+ return null;
810
+ };
811
+ publicAPI.setInputArrayToProcess = function (inputPort, arrayName, fieldAssociation) {
812
+ let attributeType = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 'Scalars';
813
+ while (model.inputArrayToProcess.length < inputPort) {
814
+ model.inputArrayToProcess.push(null);
815
+ }
816
+ model.inputArrayToProcess[inputPort] = {
817
+ arrayName,
818
+ fieldAssociation,
819
+ attributeType
820
+ };
821
+ };
822
+ }
823
+
824
+ // ----------------------------------------------------------------------------
825
+ // Event handling: onXXX(callback), invokeXXX(args...)
826
+ // ----------------------------------------------------------------------------
827
+
828
+ const EVENT_ABORT = Symbol('Event abort');
829
+ function event(publicAPI, model, eventName) {
830
+ const callbacks = [];
831
+ const previousDelete = publicAPI.delete;
832
+ let curCallbackID = 1;
833
+ function off(callbackID) {
834
+ for (let i = 0; i < callbacks.length; ++i) {
835
+ const [cbID] = callbacks[i];
836
+ if (cbID === callbackID) {
837
+ callbacks.splice(i, 1);
838
+ return;
839
+ }
840
+ }
841
+ }
842
+ function on(callbackID) {
843
+ function unsubscribe() {
844
+ off(callbackID);
845
+ }
846
+ return Object.freeze({
847
+ unsubscribe
848
+ });
849
+ }
850
+ function invoke() {
851
+ if (model.deleted) {
852
+ vtkErrorMacro('instance deleted - cannot call any method');
853
+ return;
854
+ }
855
+ /* eslint-disable prefer-rest-params */
856
+ // Go through a copy of the callbacks array in case new callbacks
857
+ // get prepended within previous callbacks
858
+ const currentCallbacks = callbacks.slice();
859
+ for (let index = 0; index < currentCallbacks.length; ++index) {
860
+ const [, cb, priority] = currentCallbacks[index];
861
+ if (!cb) {
862
+ continue; // eslint-disable-line
863
+ }
864
+
865
+ if (priority < 0) {
866
+ setTimeout(() => cb.apply(publicAPI, arguments), 1 - priority);
867
+ } else {
868
+ // Abort only if the callback explicitly returns false
869
+ const continueNext = cb.apply(publicAPI, arguments);
870
+ if (continueNext === EVENT_ABORT) {
871
+ break;
872
+ }
873
+ }
874
+ }
875
+ /* eslint-enable prefer-rest-params */
876
+ }
877
+
878
+ publicAPI[`invoke${_capitalize(eventName)}`] = invoke;
879
+ publicAPI[`on${_capitalize(eventName)}`] = function (callback) {
880
+ let priority = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0.0;
881
+ if (!callback.apply) {
882
+ console.error(`Invalid callback for event ${eventName}`);
883
+ return null;
884
+ }
885
+ if (model.deleted) {
886
+ vtkErrorMacro('instance deleted - cannot call any method');
887
+ return null;
888
+ }
889
+ const callbackID = curCallbackID++;
890
+ callbacks.push([callbackID, callback, priority]);
891
+ callbacks.sort((cb1, cb2) => cb2[2] - cb1[2]);
892
+ return on(callbackID);
893
+ };
894
+ publicAPI.delete = () => {
895
+ previousDelete();
896
+ callbacks.forEach(_ref => {
897
+ let [cbID] = _ref;
898
+ return off(cbID);
899
+ });
900
+ };
901
+ }
902
+
903
+ // ----------------------------------------------------------------------------
904
+ // newInstance
905
+ // ----------------------------------------------------------------------------
906
+
907
+ function newInstance(extend, className) {
908
+ const constructor = function () {
909
+ let initialValues = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
910
+ const model = {};
911
+ const publicAPI = {};
912
+ extend(publicAPI, model, initialValues);
913
+ return Object.freeze(publicAPI);
914
+ };
915
+
916
+ // Register constructor to factory
917
+ if (className) {
918
+ vtk.register(className, constructor);
919
+ }
920
+ return constructor;
921
+ }
922
+
923
+ // ----------------------------------------------------------------------------
924
+ // Chain function calls
925
+ // ----------------------------------------------------------------------------
926
+
927
+ function chain() {
928
+ for (var _len5 = arguments.length, fn = new Array(_len5), _key5 = 0; _key5 < _len5; _key5++) {
929
+ fn[_key5] = arguments[_key5];
930
+ }
931
+ return function () {
932
+ for (var _len6 = arguments.length, args = new Array(_len6), _key6 = 0; _key6 < _len6; _key6++) {
933
+ args[_key6] = arguments[_key6];
934
+ }
935
+ return fn.filter(i => !!i).map(i => i(...args));
936
+ };
937
+ }
938
+
939
+ // ----------------------------------------------------------------------------
940
+ // Some utility methods for vtk objects
941
+ // ----------------------------------------------------------------------------
942
+
943
+ function isVtkObject(instance) {
944
+ return instance && instance.isA && instance.isA('vtkObject');
945
+ }
946
+ function traverseInstanceTree(instance, extractFunction) {
947
+ let accumulator = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
948
+ let visitedInstances = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : [];
949
+ if (isVtkObject(instance)) {
950
+ if (visitedInstances.indexOf(instance) >= 0) {
951
+ // avoid cycles
952
+ return accumulator;
953
+ }
954
+ visitedInstances.push(instance);
955
+ const result = extractFunction(instance);
956
+ if (result !== undefined) {
957
+ accumulator.push(result);
958
+ }
959
+
960
+ // Now go through this instance's model
961
+ const model = instance.get();
962
+ Object.keys(model).forEach(key => {
963
+ const modelObj = model[key];
964
+ if (Array.isArray(modelObj)) {
965
+ modelObj.forEach(subObj => {
966
+ traverseInstanceTree(subObj, extractFunction, accumulator, visitedInstances);
967
+ });
968
+ } else {
969
+ traverseInstanceTree(modelObj, extractFunction, accumulator, visitedInstances);
970
+ }
971
+ });
972
+ }
973
+ return accumulator;
974
+ }
975
+
976
+ // ----------------------------------------------------------------------------
977
+ // Returns a function, that, as long as it continues to be invoked, will not
978
+ // be triggered. The function will be called after it stops being called for
979
+ // N milliseconds. If `immediate` is passed, trigger the function on the
980
+ // leading edge, instead of the trailing.
981
+
982
+ function debounce(func, wait, immediate) {
983
+ var _this = this;
984
+ let timeout;
985
+ const debounced = function () {
986
+ for (var _len7 = arguments.length, args = new Array(_len7), _key7 = 0; _key7 < _len7; _key7++) {
987
+ args[_key7] = arguments[_key7];
988
+ }
989
+ const context = _this;
990
+ const later = () => {
991
+ timeout = null;
992
+ if (!immediate) {
993
+ func.apply(context, args);
994
+ }
995
+ };
996
+ const callNow = immediate && !timeout;
997
+ clearTimeout(timeout);
998
+ timeout = setTimeout(later, wait);
999
+ if (callNow) {
1000
+ func.apply(context, args);
1001
+ }
1002
+ };
1003
+ debounced.cancel = () => clearTimeout(timeout);
1004
+ return debounced;
1005
+ }
1006
+
1007
+ // ----------------------------------------------------------------------------
1008
+ // Creates a throttled function that only invokes `func` at most once per
1009
+ // every `wait` milliseconds.
1010
+
1011
+ function throttle(callback, delay) {
1012
+ let isThrottled = false;
1013
+ let argsToUse = null;
1014
+ function next() {
1015
+ isThrottled = false;
1016
+ if (argsToUse !== null) {
1017
+ wrapper(...argsToUse); // eslint-disable-line
1018
+ argsToUse = null;
1019
+ }
1020
+ }
1021
+ function wrapper() {
1022
+ for (var _len8 = arguments.length, args = new Array(_len8), _key8 = 0; _key8 < _len8; _key8++) {
1023
+ args[_key8] = arguments[_key8];
1024
+ }
1025
+ if (isThrottled) {
1026
+ argsToUse = args;
1027
+ return;
1028
+ }
1029
+ isThrottled = true;
1030
+ callback(...args);
1031
+ setTimeout(next, delay);
1032
+ }
1033
+ return wrapper;
1034
+ }
1035
+
1036
+ // ----------------------------------------------------------------------------
1037
+ // keystore(publicAPI, model, initialKeystore)
1038
+ //
1039
+ // - initialKeystore: Initial keystore. This can be either a Map or an
1040
+ // object.
1041
+ //
1042
+ // Generated API
1043
+ // setKey(key, value) : mixed (returns value)
1044
+ // getKey(key) : mixed
1045
+ // getAllKeys() : [mixed]
1046
+ // deleteKey(key) : Boolean
1047
+ // ----------------------------------------------------------------------------
1048
+
1049
+ function keystore(publicAPI, model) {
1050
+ let initialKeystore = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
1051
+ model.keystore = Object.assign(model.keystore || {}, initialKeystore);
1052
+ publicAPI.setKey = (key, value) => {
1053
+ model.keystore[key] = value;
1054
+ };
1055
+ publicAPI.getKey = key => model.keystore[key];
1056
+ publicAPI.getAllKeys = () => Object.keys(model.keystore);
1057
+ publicAPI.deleteKey = key => delete model.keystore[key];
1058
+ publicAPI.clearKeystore = () => publicAPI.getAllKeys().forEach(key => delete model.keystore[key]);
1059
+ }
1060
+
1061
+ // ----------------------------------------------------------------------------
1062
+ // proxy(publicAPI, model, sectionName, propertyUI)
1063
+ //
1064
+ // - sectionName: Name of the section for UI
1065
+ // - propertyUI: List of props with their UI description
1066
+ //
1067
+ // Generated API
1068
+ // getProxyId() : String
1069
+ // listProxyProperties() : [string]
1070
+ // updateProxyProperty(name, prop)
1071
+ // getProxySection() => List of properties for UI generation
1072
+ // ----------------------------------------------------------------------------
1073
+ let nextProxyId = 1;
1074
+ const ROOT_GROUP_NAME = '__root__';
1075
+ function proxy(publicAPI, model) {
1076
+ // Proxies are keystores
1077
+ keystore(publicAPI, model);
1078
+ const parentDelete = publicAPI.delete;
1079
+
1080
+ // getProxyId
1081
+ model.proxyId = `${nextProxyId++}`;
1082
+
1083
+ // ui handling
1084
+ model.ui = JSON.parse(JSON.stringify(model.ui || [])); // deep copy
1085
+ get(publicAPI, model, ['proxyId', 'proxyGroup', 'proxyName']);
1086
+ setGet(publicAPI, model, ['proxyManager']);
1087
+
1088
+ // group properties
1089
+ const propertyMap = {};
1090
+ const groupChildrenNames = {};
1091
+ function registerProperties(descriptionList, currentGroupName) {
1092
+ if (!groupChildrenNames[currentGroupName]) {
1093
+ groupChildrenNames[currentGroupName] = [];
1094
+ }
1095
+ const childrenNames = groupChildrenNames[currentGroupName];
1096
+ for (let i = 0; i < descriptionList.length; i++) {
1097
+ childrenNames.push(descriptionList[i].name);
1098
+ propertyMap[descriptionList[i].name] = descriptionList[i];
1099
+ if (descriptionList[i].children && descriptionList[i].children.length) {
1100
+ registerProperties(descriptionList[i].children, descriptionList[i].name);
1101
+ }
1102
+ }
1103
+ }
1104
+ registerProperties(model.ui, ROOT_GROUP_NAME);
1105
+ publicAPI.updateUI = ui => {
1106
+ model.ui = JSON.parse(JSON.stringify(ui || [])); // deep copy
1107
+ Object.keys(propertyMap).forEach(k => delete propertyMap[k]);
1108
+ Object.keys(groupChildrenNames).forEach(k => delete groupChildrenNames[k]);
1109
+ registerProperties(model.ui, ROOT_GROUP_NAME);
1110
+ publicAPI.modified();
1111
+ };
1112
+ function listProxyProperties() {
1113
+ let gName = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ROOT_GROUP_NAME;
1114
+ return groupChildrenNames[gName];
1115
+ }
1116
+ publicAPI.updateProxyProperty = (propertyName, propUI) => {
1117
+ const prop = propertyMap[propertyName];
1118
+ if (prop) {
1119
+ Object.assign(prop, propUI);
1120
+ } else {
1121
+ propertyMap[propertyName] = {
1122
+ ...propUI
1123
+ };
1124
+ }
1125
+ };
1126
+ publicAPI.activate = () => {
1127
+ if (model.proxyManager) {
1128
+ const setActiveMethod = `setActive${_capitalize(publicAPI.getProxyGroup().slice(0, -1))}`;
1129
+ if (model.proxyManager[setActiveMethod]) {
1130
+ model.proxyManager[setActiveMethod](publicAPI);
1131
+ }
1132
+ }
1133
+ };
1134
+
1135
+ // property link
1136
+ model.propertyLinkSubscribers = {};
1137
+ publicAPI.registerPropertyLinkForGC = (otherLink, type) => {
1138
+ if (!(type in model.propertyLinkSubscribers)) {
1139
+ model.propertyLinkSubscribers[type] = [];
1140
+ }
1141
+ model.propertyLinkSubscribers[type].push(otherLink);
1142
+ };
1143
+ publicAPI.gcPropertyLinks = type => {
1144
+ const subscribers = model.propertyLinkSubscribers[type] || [];
1145
+ while (subscribers.length) {
1146
+ subscribers.pop().unbind(publicAPI);
1147
+ }
1148
+ };
1149
+ model.propertyLinkMap = {};
1150
+ publicAPI.getPropertyLink = function (id) {
1151
+ let persistent = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
1152
+ if (model.propertyLinkMap[id]) {
1153
+ return model.propertyLinkMap[id];
1154
+ }
1155
+ let value = null;
1156
+ const links = [];
1157
+ let count = 0;
1158
+ let updateInProgress = false;
1159
+ function update(source) {
1160
+ let force = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
1161
+ if (updateInProgress) {
1162
+ return null;
1163
+ }
1164
+ const needUpdate = [];
1165
+ let sourceLink = null;
1166
+ count = links.length;
1167
+ while (count--) {
1168
+ const link = links[count];
1169
+ if (link.instance === source) {
1170
+ sourceLink = link;
1171
+ } else {
1172
+ needUpdate.push(link);
1173
+ }
1174
+ }
1175
+ if (!sourceLink) {
1176
+ return null;
1177
+ }
1178
+ const newValue = sourceLink.instance[`get${_capitalize(sourceLink.propertyName)}`]();
1179
+ if (!shallowEquals(newValue, value) || force) {
1180
+ value = newValue;
1181
+ updateInProgress = true;
1182
+ while (needUpdate.length) {
1183
+ const linkToUpdate = needUpdate.pop();
1184
+ linkToUpdate.instance.set({
1185
+ [linkToUpdate.propertyName]: value
1186
+ });
1187
+ }
1188
+ updateInProgress = false;
1189
+ }
1190
+ if (model.propertyLinkMap[id].persistent) {
1191
+ model.propertyLinkMap[id].value = newValue;
1192
+ }
1193
+ return newValue;
1194
+ }
1195
+ function unbind(instance, propertyName) {
1196
+ const indexToDelete = [];
1197
+ count = links.length;
1198
+ while (count--) {
1199
+ const link = links[count];
1200
+ if (link.instance === instance && (link.propertyName === propertyName || propertyName === undefined)) {
1201
+ link.subscription.unsubscribe();
1202
+ indexToDelete.push(count);
1203
+ }
1204
+ }
1205
+ while (indexToDelete.length) {
1206
+ links.splice(indexToDelete.pop(), 1);
1207
+ }
1208
+ }
1209
+ function bind(instance, propertyName) {
1210
+ let updateMe = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
1211
+ const subscription = instance.onModified(update);
1212
+ const other = links[0];
1213
+ links.push({
1214
+ instance,
1215
+ propertyName,
1216
+ subscription
1217
+ });
1218
+ if (updateMe) {
1219
+ if (model.propertyLinkMap[id].persistent && model.propertyLinkMap[id].value !== undefined) {
1220
+ instance.set({
1221
+ [propertyName]: model.propertyLinkMap[id].value
1222
+ });
1223
+ } else if (other) {
1224
+ update(other.instance, true);
1225
+ }
1226
+ }
1227
+ return {
1228
+ unsubscribe: () => unbind(instance, propertyName)
1229
+ };
1230
+ }
1231
+ function unsubscribe() {
1232
+ while (links.length) {
1233
+ links.pop().subscription.unsubscribe();
1234
+ }
1235
+ }
1236
+ const linkHandler = {
1237
+ bind,
1238
+ unbind,
1239
+ unsubscribe,
1240
+ persistent
1241
+ };
1242
+ model.propertyLinkMap[id] = linkHandler;
1243
+ return linkHandler;
1244
+ };
1245
+
1246
+ // extract values
1247
+ function getProperties() {
1248
+ let groupName = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ROOT_GROUP_NAME;
1249
+ const values = [];
1250
+ const id = model.proxyId;
1251
+ const propertyNames = listProxyProperties(groupName) || [];
1252
+ for (let i = 0; i < propertyNames.length; i++) {
1253
+ const name = propertyNames[i];
1254
+ const method = publicAPI[`get${_capitalize(name)}`];
1255
+ const value = method ? method() : undefined;
1256
+ const prop = {
1257
+ id,
1258
+ name,
1259
+ value
1260
+ };
1261
+ const children = getProperties(name);
1262
+ if (children.length) {
1263
+ prop.children = children;
1264
+ }
1265
+ values.push(prop);
1266
+ }
1267
+ return values;
1268
+ }
1269
+ publicAPI.listPropertyNames = () => getProperties().map(p => p.name);
1270
+ publicAPI.getPropertyByName = name => getProperties().find(p => p.name === name);
1271
+ publicAPI.getPropertyDomainByName = name => (propertyMap[name] || {}).domain;
1272
+
1273
+ // ui section
1274
+ publicAPI.getProxySection = () => ({
1275
+ id: model.proxyId,
1276
+ name: model.proxyGroup,
1277
+ ui: model.ui,
1278
+ properties: getProperties()
1279
+ });
1280
+
1281
+ // free resources
1282
+ publicAPI.delete = () => {
1283
+ const list = Object.keys(model.propertyLinkMap);
1284
+ let count = list.length;
1285
+ while (count--) {
1286
+ model.propertyLinkMap[list[count]].unsubscribe();
1287
+ }
1288
+ Object.keys(model.propertyLinkSubscribers).forEach(publicAPI.gcPropertyLinks);
1289
+ parentDelete();
1290
+ };
1291
+
1292
+ // @todo fix infinite recursion due to active source
1293
+ publicAPI.getState = () => null;
1294
+ function registerLinks() {
1295
+ // Allow dynamic registration of links at the application level
1296
+ if (model.links) {
1297
+ for (let i = 0; i < model.links.length; i++) {
1298
+ const {
1299
+ link,
1300
+ property,
1301
+ persistent,
1302
+ updateOnBind,
1303
+ type
1304
+ } = model.links[i];
1305
+ if (type === 'application') {
1306
+ const sLink = model.proxyManager.getPropertyLink(link, persistent);
1307
+ publicAPI.registerPropertyLinkForGC(sLink, 'application');
1308
+ sLink.bind(publicAPI, property, updateOnBind);
1309
+ }
1310
+ }
1311
+ }
1312
+ }
1313
+ setImmediateVTK(registerLinks);
1314
+ }
1315
+
1316
+ // ----------------------------------------------------------------------------
1317
+ // proxyPropertyMapping(publicAPI, model, map)
1318
+ //
1319
+ // map = {
1320
+ // opacity: { modelKey: 'property', property: 'opacity' },
1321
+ // }
1322
+ //
1323
+ // Generated API:
1324
+ // Elevate set/get methods from internal object stored in the model to current one
1325
+ // ----------------------------------------------------------------------------
1326
+
1327
+ function proxyPropertyMapping(publicAPI, model, map) {
1328
+ const parentDelete = publicAPI.delete;
1329
+ const subscriptions = [];
1330
+ const propertyNames = Object.keys(map);
1331
+ let count = propertyNames.length;
1332
+ while (count--) {
1333
+ const propertyName = propertyNames[count];
1334
+ const {
1335
+ modelKey,
1336
+ property,
1337
+ modified = true
1338
+ } = map[propertyName];
1339
+ const methodSrc = _capitalize(property);
1340
+ const methodDst = _capitalize(propertyName);
1341
+ publicAPI[`get${methodDst}`] = model[modelKey][`get${methodSrc}`];
1342
+ publicAPI[`set${methodDst}`] = model[modelKey][`set${methodSrc}`];
1343
+ if (modified) {
1344
+ subscriptions.push(model[modelKey].onModified(publicAPI.modified));
1345
+ }
1346
+ }
1347
+ publicAPI.delete = () => {
1348
+ while (subscriptions.length) {
1349
+ subscriptions.pop().unsubscribe();
1350
+ }
1351
+ parentDelete();
1352
+ };
1353
+ }
1354
+
1355
+ // ----------------------------------------------------------------------------
1356
+ // proxyPropertyState(publicAPI, model, state, defaults)
1357
+ //
1358
+ // state = {
1359
+ // representation: {
1360
+ // 'Surface with edges': { property: { edgeVisibility: true, representation: 2 } },
1361
+ // Surface: { property: { edgeVisibility: false, representation: 2 } },
1362
+ // Wireframe: { property: { edgeVisibility: false, representation: 1 } },
1363
+ // Points: { property: { edgeVisibility: false, representation: 0 } },
1364
+ // },
1365
+ // }
1366
+ //
1367
+ // defaults = {
1368
+ // representation: 'Surface',
1369
+ // }
1370
+ //
1371
+ // Generated API
1372
+ // get / set Representation ( string ) => push state to various internal objects
1373
+ // ----------------------------------------------------------------------------
1374
+
1375
+ function proxyPropertyState(publicAPI, model) {
1376
+ let state = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
1377
+ let defaults = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
1378
+ model.this = publicAPI;
1379
+ function applyState(map) {
1380
+ const modelKeys = Object.keys(map);
1381
+ let count = modelKeys.length;
1382
+ while (count--) {
1383
+ const modelKey = modelKeys[count];
1384
+ model[modelKey].set(map[modelKey]);
1385
+ }
1386
+ }
1387
+ const modelKeys = Object.keys(defaults);
1388
+ let count = modelKeys.length;
1389
+ while (count--) {
1390
+ // Add default
1391
+ const key = modelKeys[count];
1392
+ model[key] = defaults[key];
1393
+
1394
+ // Add set method
1395
+ const mapping = state[key];
1396
+ publicAPI[`set${_capitalize(key)}`] = value => {
1397
+ if (value !== model[key]) {
1398
+ model[key] = value;
1399
+ const propValues = mapping[value];
1400
+ applyState(propValues);
1401
+ publicAPI.modified();
1402
+ }
1403
+ };
1404
+ }
1405
+
1406
+ // Add getter
1407
+ if (modelKeys.length) {
1408
+ get(publicAPI, model, modelKeys);
1409
+ }
1410
+ }
1411
+
1412
+ // ----------------------------------------------------------------------------
1413
+ // From : https://github.com/facebookarchive/fixed-data-table/blob/master/src/vendor_upstream/dom/normalizeWheel.js
1414
+ //
1415
+ //
1416
+ // Copyright (c) 2015, Facebook, Inc.
1417
+ // All rights reserved.
1418
+ //
1419
+ // This source code is licensed under the BSD-style license found in the
1420
+ // LICENSE file in the root directory of this source tree. An additional grant
1421
+ // of patent rights can be found in the PATENTS file in the same directory.
1422
+ //
1423
+ //
1424
+ // Mouse wheel (and 2-finger trackpad) support on the web sucks. It is
1425
+ // complicated, thus this doc is long and (hopefully) detailed enough to answer
1426
+ // your questions.
1427
+ //
1428
+ // If you need to react to the mouse wheel in a predictable way, this code is
1429
+ // like your bestest friend.// hugs//
1430
+ //
1431
+ // As of today, there are 4 DOM event types you can listen to:
1432
+ //
1433
+ // 'wheel' -- Chrome(31+), FF(17+), IE(9+)
1434
+ // 'mousewheel' -- Chrome, IE(6+), Opera, Safari
1435
+ // 'MozMousePixelScroll' -- FF(3.5 only!) (2010-2013) -- don't bother!
1436
+ // 'DOMMouseScroll' -- FF(0.9.7+) since 2003
1437
+ //
1438
+ // So what to do? The is the best:
1439
+ //
1440
+ // normalizeWheel.getEventType();
1441
+ //
1442
+ // In your event callback, use this code to get sane interpretation of the
1443
+ // deltas. This code will return an object with properties:
1444
+ //
1445
+ // spinX -- normalized spin speed (use for zoom) - x plane
1446
+ // spinY -- " - y plane
1447
+ // pixelX -- normalized distance (to pixels) - x plane
1448
+ // pixelY -- " - y plane
1449
+ //
1450
+ // Wheel values are provided by the browser assuming you are using the wheel to
1451
+ // scroll a web page by a number of lines or pixels (or pages). Values can vary
1452
+ // significantly on different platforms and browsers, forgetting that you can
1453
+ // scroll at different speeds. Some devices (like trackpads) emit more events
1454
+ // at smaller increments with fine granularity, and some emit massive jumps with
1455
+ // linear speed or acceleration.
1456
+ //
1457
+ // This code does its best to normalize the deltas for you:
1458
+ //
1459
+ // - spin is trying to normalize how far the wheel was spun (or trackpad
1460
+ // dragged). This is super useful for zoom support where you want to
1461
+ // throw away the chunky scroll steps on the PC and make those equal to
1462
+ // the slow and smooth tiny steps on the Mac. Key data: This code tries to
1463
+ // resolve a single slow step on a wheel to 1.
1464
+ //
1465
+ // - pixel is normalizing the desired scroll delta in pixel units. You'll
1466
+ // get the crazy differences between browsers, but at least it'll be in
1467
+ // pixels!
1468
+ //
1469
+ // - positive value indicates scrolling DOWN/RIGHT, negative UP/LEFT. This
1470
+ // should translate to positive value zooming IN, negative zooming OUT.
1471
+ // This matches the newer 'wheel' event.
1472
+ //
1473
+ // Why are there spinX, spinY (or pixels)?
1474
+ //
1475
+ // - spinX is a 2-finger side drag on the trackpad, and a shift + wheel turn
1476
+ // with a mouse. It results in side-scrolling in the browser by default.
1477
+ //
1478
+ // - spinY is what you expect -- it's the classic axis of a mouse wheel.
1479
+ //
1480
+ // - I dropped spinZ/pixelZ. It is supported by the DOM 3 'wheel' event and
1481
+ // probably is by browsers in conjunction with fancy 3D controllers .. but
1482
+ // you know.
1483
+ //
1484
+ // Implementation info:
1485
+ //
1486
+ // Examples of 'wheel' event if you scroll slowly (down) by one step with an
1487
+ // average mouse:
1488
+ //
1489
+ // OS X + Chrome (mouse) - 4 pixel delta (wheelDelta -120)
1490
+ // OS X + Safari (mouse) - N/A pixel delta (wheelDelta -12)
1491
+ // OS X + Firefox (mouse) - 0.1 line delta (wheelDelta N/A)
1492
+ // Win8 + Chrome (mouse) - 100 pixel delta (wheelDelta -120)
1493
+ // Win8 + Firefox (mouse) - 3 line delta (wheelDelta -120)
1494
+ //
1495
+ // On the trackpad:
1496
+ //
1497
+ // OS X + Chrome (trackpad) - 2 pixel delta (wheelDelta -6)
1498
+ // OS X + Firefox (trackpad) - 1 pixel delta (wheelDelta N/A)
1499
+ //
1500
+ // On other/older browsers.. it's more complicated as there can be multiple and
1501
+ // also missing delta values.
1502
+ //
1503
+ // The 'wheel' event is more standard:
1504
+ //
1505
+ // http://www.w3.org/TR/DOM-Level-3-Events/#events-wheelevents
1506
+ //
1507
+ // The basics is that it includes a unit, deltaMode (pixels, lines, pages), and
1508
+ // deltaX, deltaY and deltaZ. Some browsers provide other values to maintain
1509
+ // backward compatibility with older events. Those other values help us
1510
+ // better normalize spin speed. Example of what the browsers provide:
1511
+ //
1512
+ // | event.wheelDelta | event.detail
1513
+ // ------------------+------------------+--------------
1514
+ // Safari v5/OS X | -120 | 0
1515
+ // Safari v5/Win7 | -120 | 0
1516
+ // Chrome v17/OS X | -120 | 0
1517
+ // Chrome v17/Win7 | -120 | 0
1518
+ // IE9/Win7 | -120 | undefined
1519
+ // Firefox v4/OS X | undefined | 1
1520
+ // Firefox v4/Win7 | undefined | 3
1521
+ //
1522
+ // ----------------------------------------------------------------------------
1523
+
1524
+ // Reasonable defaults
1525
+ const PIXEL_STEP = 10;
1526
+ const LINE_HEIGHT = 40;
1527
+ const PAGE_HEIGHT = 800;
1528
+ function normalizeWheel(wheelEvent) {
1529
+ let sX = 0; // spinX
1530
+ let sY = 0; // spinY
1531
+ let pX = 0; // pixelX
1532
+ let pY = 0; // pixelY
1533
+
1534
+ // Legacy
1535
+ if ('detail' in wheelEvent) {
1536
+ sY = wheelEvent.detail;
1537
+ }
1538
+ if ('wheelDelta' in wheelEvent) {
1539
+ sY = -wheelEvent.wheelDelta / 120;
1540
+ }
1541
+ if ('wheelDeltaY' in wheelEvent) {
1542
+ sY = -wheelEvent.wheelDeltaY / 120;
1543
+ }
1544
+ if ('wheelDeltaX' in wheelEvent) {
1545
+ sX = -wheelEvent.wheelDeltaX / 120;
1546
+ }
1547
+
1548
+ // side scrolling on FF with DOMMouseScroll
1549
+ if ('axis' in wheelEvent && wheelEvent.axis === wheelEvent.HORIZONTAL_AXIS) {
1550
+ sX = sY;
1551
+ sY = 0;
1552
+ }
1553
+ pX = sX * PIXEL_STEP;
1554
+ pY = sY * PIXEL_STEP;
1555
+ if ('deltaY' in wheelEvent) {
1556
+ pY = wheelEvent.deltaY;
1557
+ }
1558
+ if ('deltaX' in wheelEvent) {
1559
+ pX = wheelEvent.deltaX;
1560
+ }
1561
+ if ((pX || pY) && wheelEvent.deltaMode) {
1562
+ if (wheelEvent.deltaMode === 1) {
1563
+ // delta in LINE units
1564
+ pX *= LINE_HEIGHT;
1565
+ pY *= LINE_HEIGHT;
1566
+ } else {
1567
+ // delta in PAGE units
1568
+ pX *= PAGE_HEIGHT;
1569
+ pY *= PAGE_HEIGHT;
1570
+ }
1571
+ }
1572
+
1573
+ // Fall-back if spin cannot be determined
1574
+ if (pX && !sX) {
1575
+ sX = pX < 1 ? -1 : 1;
1576
+ }
1577
+ if (pY && !sY) {
1578
+ sY = pY < 1 ? -1 : 1;
1579
+ }
1580
+ return {
1581
+ spinX: sX,
1582
+ spinY: sY,
1583
+ pixelX: pX,
1584
+ pixelY: pY
1585
+ };
1586
+ }
1587
+
1588
+ // ----------------------------------------------------------------------------
1589
+ // Default export
1590
+ // ----------------------------------------------------------------------------
1591
+
1592
+ var macro = {
1593
+ algo,
1594
+ capitalize,
1595
+ chain,
1596
+ debounce,
1597
+ enumToString,
1598
+ event,
1599
+ EVENT_ABORT,
1600
+ formatBytesToProperUnit,
1601
+ formatNumbersWithThousandSeparator,
1602
+ get,
1603
+ getArray,
1604
+ getCurrentGlobalMTime,
1605
+ getStateArrayMapFunc,
1606
+ isVtkObject,
1607
+ keystore,
1608
+ measurePromiseExecution,
1609
+ moveToProtected,
1610
+ newInstance,
1611
+ newTypedArray,
1612
+ newTypedArrayFrom,
1613
+ normalizeWheel,
1614
+ obj,
1615
+ proxy,
1616
+ proxyPropertyMapping,
1617
+ proxyPropertyState,
1618
+ safeArrays,
1619
+ set,
1620
+ setArray,
1621
+ setGet,
1622
+ setGetArray,
1623
+ setImmediate: setImmediateVTK,
1624
+ setLoggerFunction,
1625
+ throttle,
1626
+ traverseInstanceTree,
1627
+ TYPED_ARRAYS,
1628
+ // deprecated todo remove on breaking API revision
1629
+ uncapitalize,
1630
+ VOID,
1631
+ vtkDebugMacro,
1632
+ vtkErrorMacro,
1633
+ vtkInfoMacro,
1634
+ vtkLogMacro,
1635
+ vtkOnceErrorMacro,
1636
+ vtkWarningMacro
1637
+ };
1638
+
1639
+ var macro$1 = /*#__PURE__*/Object.freeze({
1640
+ __proto__: null,
1641
+ VOID: VOID,
1642
+ setLoggerFunction: setLoggerFunction,
1643
+ vtkLogMacro: vtkLogMacro,
1644
+ vtkInfoMacro: vtkInfoMacro,
1645
+ vtkDebugMacro: vtkDebugMacro,
1646
+ vtkErrorMacro: vtkErrorMacro,
1647
+ vtkWarningMacro: vtkWarningMacro,
1648
+ vtkOnceErrorMacro: vtkOnceErrorMacro,
1649
+ TYPED_ARRAYS: TYPED_ARRAYS,
1650
+ newTypedArray: newTypedArray,
1651
+ newTypedArrayFrom: newTypedArrayFrom,
1652
+ capitalize: capitalize,
1653
+ _capitalize: _capitalize,
1654
+ uncapitalize: uncapitalize,
1655
+ formatBytesToProperUnit: formatBytesToProperUnit,
1656
+ formatNumbersWithThousandSeparator: formatNumbersWithThousandSeparator,
1657
+ setImmediateVTK: setImmediateVTK,
1658
+ measurePromiseExecution: measurePromiseExecution,
1659
+ obj: obj,
1660
+ get: get,
1661
+ set: set,
1662
+ setGet: setGet,
1663
+ getArray: getArray,
1664
+ setArray: setArray,
1665
+ setGetArray: setGetArray,
1666
+ moveToProtected: moveToProtected,
1667
+ algo: algo,
1668
+ EVENT_ABORT: EVENT_ABORT,
1669
+ event: event,
1670
+ newInstance: newInstance,
1671
+ chain: chain,
1672
+ isVtkObject: isVtkObject,
1673
+ traverseInstanceTree: traverseInstanceTree,
1674
+ debounce: debounce,
1675
+ throttle: throttle,
1676
+ keystore: keystore,
1677
+ proxy: proxy,
1678
+ proxyPropertyMapping: proxyPropertyMapping,
1679
+ proxyPropertyState: proxyPropertyState,
1680
+ normalizeWheel: normalizeWheel,
1681
+ 'default': macro
1682
+ });
1683
+
1684
+ export { uncapitalize as A, formatBytesToProperUnit as B, formatNumbersWithThousandSeparator as C, setImmediateVTK as D, measurePromiseExecution as E, setArray as F, EVENT_ABORT as G, isVtkObject as H, debounce as I, throttle as J, keystore as K, proxyPropertyState as L, normalizeWheel as M, TYPED_ARRAYS as T, VOID as V, _capitalize as _, newTypedArray as a, newTypedArrayFrom as b, macro$1 as c, algo as d, setGet as e, event as f, get as g, chain as h, moveToProtected as i, proxyPropertyMapping as j, getArray as k, setGetArray as l, macro as m, newInstance as n, obj as o, proxy as p, capitalize as q, vtkErrorMacro as r, set as s, traverseInstanceTree as t, setLoggerFunction as u, vtkWarningMacro as v, vtkLogMacro as w, vtkInfoMacro as x, vtkDebugMacro as y, vtkOnceErrorMacro as z };