@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.
- package/Common/Core/Base64.js +53 -82
- package/Common/Core/CellArray.js +52 -60
- package/Common/Core/ClassHierarchy.js +8 -36
- package/Common/Core/DataArray/Constants.js +6 -6
- package/Common/Core/DataArray.js +193 -277
- package/Common/Core/Endian.js +14 -17
- package/Common/Core/HalfFloat.js +17 -34
- package/Common/Core/ImageHelper.js +17 -25
- package/Common/Core/LookupTable.js +131 -144
- package/Common/Core/Math/Constants.js +8 -8
- package/Common/Core/Math/index.js +754 -942
- package/Common/Core/Math.js +2 -4
- package/Common/Core/MatrixBuilder.js +99 -151
- package/Common/Core/Points.js +43 -43
- package/Common/Core/PriorityQueue.js +30 -28
- package/Common/Core/ProgressHandler.js +31 -32
- package/Common/Core/ScalarsToColors/Constants.js +4 -4
- package/Common/Core/ScalarsToColors.js +196 -253
- package/Common/Core/StringArray.js +48 -73
- package/Common/Core/URLExtract.js +10 -29
- package/Common/Core/VariantArray.js +48 -73
- package/Common/Core.js +11 -11
- package/Common/DataModel/AbstractPointLocator.js +19 -17
- package/Common/DataModel/BoundingBox.js +322 -490
- package/Common/DataModel/Box.js +46 -63
- package/Common/DataModel/CardinalSpline1D.js +92 -102
- package/Common/DataModel/Cell.js +41 -61
- package/Common/DataModel/CellLinks.js +91 -127
- package/Common/DataModel/CellTypes/Constants.js +7 -6
- package/Common/DataModel/CellTypes.js +55 -74
- package/Common/DataModel/Collection.js +45 -61
- package/Common/DataModel/Cone.js +28 -20
- package/Common/DataModel/Cylinder.js +41 -35
- package/Common/DataModel/DataSet/Constants.js +11 -5
- package/Common/DataModel/DataSet.js +37 -25
- package/Common/DataModel/DataSetAttributes/Constants.js +18 -18
- package/Common/DataModel/DataSetAttributes/FieldData.js +103 -194
- package/Common/DataModel/DataSetAttributes.js +96 -138
- package/Common/DataModel/EdgeLocator.js +45 -70
- package/Common/DataModel/ITKHelper.js +67 -137
- package/Common/DataModel/ImageData.js +115 -172
- package/Common/DataModel/ImplicitBoolean/Constants.js +2 -2
- package/Common/DataModel/ImplicitBoolean.js +66 -96
- package/Common/DataModel/IncrementalOctreeNode.js +201 -231
- package/Common/DataModel/IncrementalOctreePointLocator.js +160 -198
- package/Common/DataModel/KochanekSpline1D.js +78 -81
- package/Common/DataModel/Line/Constants.js +2 -2
- package/Common/DataModel/Line.js +82 -105
- package/Common/DataModel/Locator.js +17 -10
- package/Common/DataModel/Molecule.js +26 -17
- package/Common/DataModel/PiecewiseFunction.js +218 -239
- package/Common/DataModel/Plane.js +90 -113
- package/Common/DataModel/PointSet.js +30 -26
- package/Common/DataModel/PolyData/Constants.js +2 -2
- package/Common/DataModel/PolyData.js +95 -120
- package/Common/DataModel/PolyLine.js +44 -61
- package/Common/DataModel/Polygon/Constants.js +4 -4
- package/Common/DataModel/Polygon.js +128 -169
- package/Common/DataModel/Quad/Constants.js +2 -2
- package/Common/DataModel/Quad.js +61 -100
- package/Common/DataModel/SelectionNode/Constants.js +5 -4
- package/Common/DataModel/SelectionNode.js +25 -21
- package/Common/DataModel/Sphere.js +40 -35
- package/Common/DataModel/Spline1D/Constants.js +3 -2
- package/Common/DataModel/Spline1D.js +34 -18
- package/Common/DataModel/Spline3D/Constants.js +2 -2
- package/Common/DataModel/Spline3D.js +46 -41
- package/Common/DataModel/StructuredData/Constants.js +2 -2
- package/Common/DataModel/StructuredData.js +9 -20
- package/Common/DataModel/Triangle.js +207 -250
- package/Common/DataModel.js +19 -19
- package/Common/System/MobileVR.js +56 -61
- package/Common/System/TimerLog.js +1 -1
- package/Common/System.js +2 -2
- package/Common/Transform/LandmarkTransform/Constants.js +2 -2
- package/Common/Transform/LandmarkTransform.js +133 -117
- package/Common/Transform/Transform.js +42 -57
- package/Common/Transform.js +2 -2
- package/Common/index.js +4 -4
- package/Filters/Core/Cutter.js +134 -146
- package/Filters/Core/PolyDataNormals.js +44 -50
- package/Filters/Core.js +2 -2
- package/Filters/Cornerstone/ImageDataToCornerstoneImage.js +45 -33
- package/Filters/Cornerstone.js +1 -1
- package/Filters/General/AppendPolyData.js +84 -100
- package/Filters/General/Calculator.js +95 -163
- package/Filters/General/ClipClosedSurface/Constants.js +2 -2
- package/Filters/General/ClipClosedSurface.js +341 -416
- package/Filters/General/ClosedPolyLineToSurfaceFilter.js +141 -156
- package/Filters/General/ContourTriangulator/Constants.js +2 -2
- package/Filters/General/ContourTriangulator/helper.js +684 -812
- package/Filters/General/ContourTriangulator.js +92 -89
- package/Filters/General/ImageCropFilter.js +77 -78
- package/Filters/General/ImageDataOutlineFilter.js +42 -36
- package/Filters/General/ImageMarchingCubes/caseTable.js +9 -521
- package/Filters/General/ImageMarchingCubes.js +99 -112
- package/Filters/General/ImageMarchingSquares/caseTable.js +9 -41
- package/Filters/General/ImageMarchingSquares.js +93 -118
- package/Filters/General/ImageOutlineFilter.js +53 -54
- package/Filters/General/ImageSliceFilter.js +39 -30
- package/Filters/General/ImageStreamline.js +107 -124
- package/Filters/General/LineFilter.js +26 -15
- package/Filters/General/MoleculeToRepresentation.js +136 -149
- package/Filters/General/OBBTree/OBBNode.js +36 -34
- package/Filters/General/OBBTree/helper.js +19 -24
- package/Filters/General/OBBTree.js +396 -488
- package/Filters/General/OutlineFilter.js +52 -34
- package/Filters/General/PaintFilter/PaintFilter.worker.js +93 -130
- package/Filters/General/PaintFilter.js +150 -162
- package/Filters/General/ScalarToRGBA.js +38 -33
- package/Filters/General/TriangleFilter.js +65 -62
- package/Filters/General/TubeFilter/Constants.js +4 -4
- package/Filters/General/TubeFilter.js +376 -496
- package/Filters/General/WarpScalar.js +58 -60
- package/Filters/General/WindowedSincPolyDataFilter.js +258 -330
- package/Filters/General.js +21 -21
- package/Filters/Sources/Arrow2DSource/Constants.js +2 -2
- package/Filters/Sources/Arrow2DSource.js +56 -56
- package/Filters/Sources/ArrowSource.js +39 -29
- package/Filters/Sources/CircleSource.js +43 -43
- package/Filters/Sources/ConcentricCylinderSource.js +151 -174
- package/Filters/Sources/ConeSource.js +51 -42
- package/Filters/Sources/CubeSource.js +75 -96
- package/Filters/Sources/Cursor3D.js +94 -109
- package/Filters/Sources/CylinderSource.js +90 -90
- package/Filters/Sources/ImageGridSource.js +43 -43
- package/Filters/Sources/LineSource.js +49 -39
- package/Filters/Sources/PlaneSource.js +97 -104
- package/Filters/Sources/PointSource.js +46 -37
- package/Filters/Sources/RTAnalyticSource.js +50 -48
- package/Filters/Sources/SLICSource.js +63 -73
- package/Filters/Sources/SphereSource.js +88 -78
- package/Filters/Sources/ViewFinderSource.js +26 -23
- package/Filters/Sources.js +14 -14
- package/Filters/Texture/TextureMapToPlane.js +95 -97
- package/Filters/Texture/TextureMapToSphere.js +46 -54
- package/Filters/Texture.js +2 -2
- package/Filters/index.js +5 -5
- package/IO/Core/BinaryHelper.js +12 -18
- package/IO/Core/DataAccessHelper/HtmlDataAccessHelper.js +43 -59
- package/IO/Core/DataAccessHelper/HttpDataAccessHelper.js +76 -113
- package/IO/Core/DataAccessHelper/JSZipDataAccessHelper.js +62 -112
- package/IO/Core/DataAccessHelper/LiteHttpDataAccessHelper.js +76 -113
- package/IO/Core/DataAccessHelper.js +6 -6
- package/IO/Core/HttpDataSetReader.js +136 -139
- package/IO/Core/HttpDataSetSeriesReader.js +64 -75
- package/IO/Core/HttpSceneLoader.js +130 -179
- package/IO/Core/ImageStream/DefaultProtocol.js +29 -43
- package/IO/Core/ImageStream/ViewStream.js +100 -103
- package/IO/Core/ImageStream.js +62 -54
- package/IO/Core/ResourceLoader.js +10 -9
- package/IO/Core/Serializer/ArraySerializer.js +40 -40
- package/IO/Core/Serializer/FieldDataSerializer.js +18 -28
- package/IO/Core/Serializer/ImageDataSerializer.js +22 -23
- package/IO/Core/Serializer/PolyDataSerializer.js +17 -21
- package/IO/Core/Serializer.js +6 -13
- package/IO/Core/WSLinkClient.js +90 -76
- package/IO/Core/ZipMultiDataSetReader.js +46 -44
- package/IO/Core/ZipMultiDataSetWriter.js +43 -34
- package/IO/Core.js +7 -7
- package/IO/Geometry/DracoReader.js +118 -121
- package/IO/Geometry/PLYReader.js +163 -223
- package/IO/Geometry/PLYWriter/Constants.js +5 -5
- package/IO/Geometry/PLYWriter.js +139 -154
- package/IO/Geometry/STLReader.js +123 -146
- package/IO/Geometry/STLWriter/Constants.js +2 -2
- package/IO/Geometry/STLWriter.js +83 -82
- package/IO/Geometry.js +5 -5
- package/IO/Legacy/LegacyAsciiParser.js +78 -139
- package/IO/Legacy/PolyDataReader.js +48 -36
- package/IO/Legacy.js +2 -2
- package/IO/Misc/ElevationReader.js +67 -60
- package/IO/Misc/HttpDataSetLODsLoader.js +41 -38
- package/IO/Misc/ITKImageReader.js +58 -45
- package/IO/Misc/ITKPolyDataReader.js +50 -38
- package/IO/Misc/JSONNucleoReader.js +49 -42
- package/IO/Misc/JSONReader.js +38 -33
- package/IO/Misc/MTLReader.js +74 -119
- package/IO/Misc/OBJReader.js +153 -206
- package/IO/Misc/PDBReader.js +70 -68
- package/IO/Misc/SkyboxReader.js +77 -82
- package/IO/Misc.js +9 -9
- package/IO/XML/XMLImageDataReader.js +36 -38
- package/IO/XML/XMLImageDataWriter.js +28 -21
- package/IO/XML/XMLPolyDataReader.js +49 -46
- package/IO/XML/XMLPolyDataWriter.js +43 -42
- package/IO/XML/XMLReader.js +262 -304
- package/IO/XML/XMLWriter/Constants.js +3 -3
- package/IO/XML/XMLWriter.js +70 -84
- package/IO/XML.js +6 -6
- package/IO/index.js +5 -5
- package/Imaging/Core/AbstractImageInterpolator/Constants.js +4 -4
- package/Imaging/Core/AbstractImageInterpolator/InterpolationInfo.js +30 -27
- package/Imaging/Core/AbstractImageInterpolator.js +74 -87
- package/Imaging/Core/ImageInterpolator.js +201 -252
- package/Imaging/Core/ImagePointDataIterator.js +96 -122
- package/Imaging/Core/ImageReslice/Constants.js +2 -2
- package/Imaging/Core/ImageReslice.js +327 -464
- package/Imaging/Core.js +4 -4
- package/Imaging/Hybrid/SampleFunction.js +58 -51
- package/Imaging/Hybrid.js +1 -1
- package/Imaging/index.js +2 -2
- package/Interaction/Animations/TimeStepBasedAnimationHandler.js +39 -54
- package/Interaction/Manipulators/CompositeCameraManipulator.js +22 -13
- package/Interaction/Manipulators/CompositeGestureManipulator.js +31 -43
- package/Interaction/Manipulators/CompositeKeyboardManipulator.js +15 -11
- package/Interaction/Manipulators/CompositeMouseManipulator.js +27 -33
- package/Interaction/Manipulators/CompositeVRManipulator.js +22 -15
- package/Interaction/Manipulators/GestureCameraManipulator.js +54 -36
- package/Interaction/Manipulators/KeyboardCameraManipulator.js +95 -97
- package/Interaction/Manipulators/MouseBoxSelectorManipulator.js +70 -89
- package/Interaction/Manipulators/MouseCameraAxisRotateManipulator.js +67 -54
- package/Interaction/Manipulators/MouseCameraSliceManipulator.js +40 -38
- package/Interaction/Manipulators/MouseCameraTrackballFirstPersonManipulator.js +83 -68
- package/Interaction/Manipulators/MouseCameraTrackballMultiRotateManipulator.js +32 -28
- package/Interaction/Manipulators/MouseCameraTrackballPanManipulator.js +47 -40
- package/Interaction/Manipulators/MouseCameraTrackballRollManipulator.js +55 -43
- package/Interaction/Manipulators/MouseCameraTrackballRotateManipulator.js +56 -46
- package/Interaction/Manipulators/MouseCameraTrackballZoomManipulator.js +41 -46
- package/Interaction/Manipulators/MouseCameraTrackballZoomToMouseManipulator.js +29 -27
- package/Interaction/Manipulators/MouseCameraUnicamManipulator.js +123 -146
- package/Interaction/Manipulators/MouseCameraUnicamRotateManipulator.js +144 -166
- package/Interaction/Manipulators/MouseRangeManipulator.js +127 -132
- package/Interaction/Manipulators/VRButtonPanManipulator.js +33 -23
- package/Interaction/Manipulators.js +21 -21
- package/Interaction/Misc/DeviceOrientationToCamera.js +25 -47
- package/Interaction/Misc.js +1 -1
- package/Interaction/Style/InteractorStyleImage.js +101 -121
- package/Interaction/Style/InteractorStyleMPRSlice.js +111 -128
- package/Interaction/Style/InteractorStyleManipulator/Presets.js +9 -17
- package/Interaction/Style/InteractorStyleManipulator.js +254 -329
- package/Interaction/Style/InteractorStyleRemoteMouse.js +195 -180
- package/Interaction/Style/InteractorStyleTrackballCamera.js +154 -157
- package/Interaction/Style/InteractorStyleUnicam.js +30 -38
- package/Interaction/Style.js +5 -5
- package/Interaction/UI/CornerAnnotation/CornerAnnotation.module.css.js +1 -1
- package/Interaction/UI/CornerAnnotation.js +65 -48
- package/Interaction/UI/FPSMonitor.js +104 -105
- package/Interaction/UI/Icons.js +1 -1
- package/Interaction/UI/Slider/Constants.js +2 -2
- package/Interaction/UI/Slider.js +78 -95
- package/Interaction/UI/VolumeController.js +104 -97
- package/Interaction/UI.js +5 -5
- package/Interaction/Widgets/OrientationMarkerWidget/Constants.js +2 -2
- package/Interaction/Widgets/OrientationMarkerWidget.js +90 -135
- package/Interaction/Widgets/PiecewiseGaussianWidget/ComputeHistogram.worker.js +0 -3
- package/Interaction/Widgets/PiecewiseGaussianWidget.js +381 -498
- package/Interaction/Widgets.js +2 -2
- package/Interaction/index.js +5 -5
- package/Proxy/Animation/AbstractAnimationProxy.js +22 -15
- package/Proxy/Animation/AnimationProxyManager.js +43 -51
- package/Proxy/Animation/TimeStepBasedAnimationHandlerProxy.js +26 -19
- package/Proxy/Core/AbstractRepresentationProxy.js +97 -151
- package/Proxy/Core/LookupTableProxy/Constants.js +4 -4
- package/Proxy/Core/LookupTableProxy.js +49 -52
- package/Proxy/Core/PiecewiseFunctionProxy/Constants.js +4 -4
- package/Proxy/Core/PiecewiseFunctionProxy.js +63 -72
- package/Proxy/Core/ProxyManager/core.js +83 -106
- package/Proxy/Core/ProxyManager/properties.js +53 -76
- package/Proxy/Core/ProxyManager/state.js +100 -110
- package/Proxy/Core/ProxyManager/view.js +45 -55
- package/Proxy/Core/ProxyManager.js +16 -8
- package/Proxy/Core/SourceProxy.js +41 -38
- package/Proxy/Core/View2DProxy.js +143 -199
- package/Proxy/Core/ViewProxy.js +223 -269
- package/Proxy/Core.js +7 -7
- package/Proxy/Representations/GeometryRepresentationProxy.js +34 -20
- package/Proxy/Representations/GlyphRepresentationProxy.js +42 -41
- package/Proxy/Representations/MoleculeRepresentationProxy.js +32 -22
- package/Proxy/Representations/ResliceRepresentationProxy.js +48 -32
- package/Proxy/Representations/SkyboxRepresentationProxy.js +30 -29
- package/Proxy/Representations/SliceRepresentationProxy.js +93 -112
- package/Proxy/Representations/SlicedGeometryRepresentationProxy.js +46 -42
- package/Proxy/Representations/VolumeRepresentationProxy.js +108 -133
- package/Proxy/Representations.js +7 -7
- package/Proxy/index.js +2 -2
- package/README.md +1 -1
- package/Rendering/Core/AbstractImageMapper/helper.js +44 -49
- package/Rendering/Core/AbstractImageMapper.js +18 -19
- package/Rendering/Core/AbstractMapper.js +39 -55
- package/Rendering/Core/AbstractMapper3D.js +26 -31
- package/Rendering/Core/AbstractPicker.js +25 -21
- package/Rendering/Core/Actor.js +71 -93
- package/Rendering/Core/Actor2D.js +64 -78
- package/Rendering/Core/AnnotatedCubeActor/Presets.js +5 -11
- package/Rendering/Core/AnnotatedCubeActor.js +94 -79
- package/Rendering/Core/AxesActor.js +65 -87
- package/Rendering/Core/Camera.js +246 -271
- package/Rendering/Core/CellPicker.js +125 -148
- package/Rendering/Core/ColorTransferFunction/ColorMaps.js +20 -21
- package/Rendering/Core/ColorTransferFunction/ColorMapsLite.js +20 -21
- package/Rendering/Core/ColorTransferFunction/Constants.js +4 -4
- package/Rendering/Core/ColorTransferFunction.js +460 -546
- package/Rendering/Core/Coordinate/Constants.js +2 -2
- package/Rendering/Core/Coordinate.js +119 -198
- package/Rendering/Core/CubeAxesActor.js +294 -320
- package/Rendering/Core/Follower.js +46 -45
- package/Rendering/Core/Glyph3DMapper/Constants.js +4 -4
- package/Rendering/Core/Glyph3DMapper.js +96 -148
- package/Rendering/Core/HardwareSelector.js +36 -69
- package/Rendering/Core/ImageArrayMapper.js +87 -126
- package/Rendering/Core/ImageCPRMapper.js +134 -209
- package/Rendering/Core/ImageMapper/Constants.js +2 -2
- package/Rendering/Core/ImageMapper.js +85 -144
- package/Rendering/Core/ImageProperty/Constants.js +2 -2
- package/Rendering/Core/ImageProperty.js +66 -81
- package/Rendering/Core/ImageResliceMapper/Constants.js +2 -2
- package/Rendering/Core/ImageResliceMapper.js +36 -29
- package/Rendering/Core/ImageSlice.js +85 -127
- package/Rendering/Core/InteractorObserver.js +82 -73
- package/Rendering/Core/InteractorStyle/Constants.js +2 -2
- package/Rendering/Core/InteractorStyle.js +56 -58
- package/Rendering/Core/Light.js +43 -49
- package/Rendering/Core/Mapper/CoincidentTopologyHelper.js +37 -48
- package/Rendering/Core/Mapper/Constants.js +6 -6
- package/Rendering/Core/Mapper/Static.js +15 -12
- package/Rendering/Core/Mapper.js +194 -259
- package/Rendering/Core/Mapper2D.js +61 -100
- package/Rendering/Core/Picker.js +124 -143
- package/Rendering/Core/PixelSpaceCallbackMapper.js +40 -37
- package/Rendering/Core/PointPicker.js +68 -79
- package/Rendering/Core/Prop/Constants.js +2 -2
- package/Rendering/Core/Prop.js +58 -106
- package/Rendering/Core/Prop3D.js +54 -83
- package/Rendering/Core/Property/Constants.js +6 -6
- package/Rendering/Core/Property.js +45 -74
- package/Rendering/Core/Property2D/Constants.js +2 -2
- package/Rendering/Core/Property2D.js +33 -42
- package/Rendering/Core/RenderWindow.js +70 -82
- package/Rendering/Core/RenderWindowInteractor/Constants.js +7 -7
- package/Rendering/Core/RenderWindowInteractor.js +324 -439
- package/Rendering/Core/Renderer.js +192 -256
- package/Rendering/Core/ScalarBarActor.js +267 -272
- package/Rendering/Core/Skybox.js +26 -24
- package/Rendering/Core/SphereMapper.js +22 -12
- package/Rendering/Core/StickMapper.js +22 -12
- package/Rendering/Core/SurfaceLICInterface/Constants.js +6 -6
- package/Rendering/Core/SurfaceLICInterface.js +13 -9
- package/Rendering/Core/SurfaceLICMapper.js +23 -15
- package/Rendering/Core/Texture.js +99 -141
- package/Rendering/Core/Viewport.js +60 -88
- package/Rendering/Core/Volume.js +55 -77
- package/Rendering/Core/VolumeMapper/Constants.js +4 -4
- package/Rendering/Core/VolumeMapper.js +59 -91
- package/Rendering/Core/VolumeProperty/Constants.js +4 -4
- package/Rendering/Core/VolumeProperty.js +78 -115
- package/Rendering/Core.js +47 -49
- package/Rendering/Misc/CanvasView.js +62 -61
- package/Rendering/Misc/FullScreenRenderWindow.js +60 -62
- package/Rendering/Misc/GenericRenderWindow.js +48 -37
- package/Rendering/Misc/RemoteView.js +86 -80
- package/Rendering/Misc/RenderWindowWithControlBar.js +54 -48
- package/Rendering/Misc/SynchronizableRenderWindow/BehaviorManager/CameraSynchronizer.js +43 -51
- package/Rendering/Misc/SynchronizableRenderWindow/BehaviorManager.js +52 -82
- package/Rendering/Misc/SynchronizableRenderWindow/ObjectManager.js +258 -308
- package/Rendering/Misc/SynchronizableRenderWindow.js +133 -163
- package/Rendering/Misc/TextureLODsDownloader.js +72 -74
- package/Rendering/Misc.js +7 -7
- package/Rendering/OpenGL/Actor.js +57 -68
- package/Rendering/OpenGL/Actor2D.js +56 -56
- package/Rendering/OpenGL/BufferObject/Constants.js +2 -2
- package/Rendering/OpenGL/BufferObject.js +50 -65
- package/Rendering/OpenGL/Camera.js +35 -29
- package/Rendering/OpenGL/CellArrayBufferObject.js +119 -149
- package/Rendering/OpenGL/Convolution2DPass.js +87 -81
- package/Rendering/OpenGL/CubeAxesActor.js +28 -21
- package/Rendering/OpenGL/ForwardPass.js +53 -64
- package/Rendering/OpenGL/Framebuffer.js +61 -101
- package/Rendering/OpenGL/Glyph3DMapper.js +165 -196
- package/Rendering/OpenGL/HardwareSelector/Constants.js +2 -2
- package/Rendering/OpenGL/HardwareSelector.js +272 -397
- package/Rendering/OpenGL/Helper.js +58 -73
- package/Rendering/OpenGL/ImageCPRMapper.js +339 -421
- package/Rendering/OpenGL/ImageMapper.js +268 -361
- package/Rendering/OpenGL/ImageResliceMapper.js +306 -438
- package/Rendering/OpenGL/ImageSlice.js +48 -54
- package/Rendering/OpenGL/OrderIndependentTranslucentPass.js +102 -84
- package/Rendering/OpenGL/PixelSpaceCallbackMapper.js +43 -42
- package/Rendering/OpenGL/PolyDataMapper.js +358 -492
- package/Rendering/OpenGL/PolyDataMapper2D.js +153 -205
- package/Rendering/OpenGL/RadialDistortionPass.js +86 -89
- package/Rendering/OpenGL/RenderWindow/Constants.js +2 -2
- package/Rendering/OpenGL/RenderWindow/ContextProxy.js +20 -29
- package/Rendering/OpenGL/RenderWindow.js +356 -510
- package/Rendering/OpenGL/Renderer.js +77 -89
- package/Rendering/OpenGL/ReplacementShaderMapper.js +28 -46
- package/Rendering/OpenGL/ScalarBarActor.js +28 -21
- package/Rendering/OpenGL/Shader.js +37 -31
- package/Rendering/OpenGL/ShaderCache.js +67 -74
- package/Rendering/OpenGL/ShaderProgram.js +136 -248
- package/Rendering/OpenGL/Skybox.js +99 -60
- package/Rendering/OpenGL/SphereMapper.js +94 -108
- package/Rendering/OpenGL/StickMapper.js +110 -114
- package/Rendering/OpenGL/SurfaceLIC/LineIntegralConvolution2D/pingpong.js +91 -157
- package/Rendering/OpenGL/SurfaceLIC/LineIntegralConvolution2D.js +142 -151
- package/Rendering/OpenGL/SurfaceLIC/SurfaceLICInterface.js +142 -216
- package/Rendering/OpenGL/SurfaceLIC/SurfaceLICMapper.js +79 -100
- package/Rendering/OpenGL/SurfaceLIC.js +2 -2
- package/Rendering/OpenGL/Texture/Constants.js +4 -4
- package/Rendering/OpenGL/Texture.js +443 -608
- package/Rendering/OpenGL/TextureUnitManager.js +47 -43
- package/Rendering/OpenGL/VertexArrayObject.js +92 -131
- package/Rendering/OpenGL/ViewNodeFactory.js +25 -13
- package/Rendering/OpenGL/Volume.js +38 -34
- package/Rendering/OpenGL/VolumeMapper.js +437 -547
- package/Rendering/OpenGL.js +28 -28
- package/Rendering/SceneGraph/RenderPass.js +34 -31
- package/Rendering/SceneGraph/RenderWindowViewNode.js +68 -94
- package/Rendering/SceneGraph/ViewNode.js +82 -111
- package/Rendering/SceneGraph/ViewNodeFactory.js +31 -26
- package/Rendering/SceneGraph.js +4 -4
- package/Rendering/WebGPU/Actor.js +49 -49
- package/Rendering/WebGPU/Actor2D.js +45 -44
- package/Rendering/WebGPU/BindGroup.js +43 -50
- package/Rendering/WebGPU/Buffer.js +41 -50
- package/Rendering/WebGPU/BufferManager/Constants.js +4 -4
- package/Rendering/WebGPU/BufferManager.js +111 -141
- package/Rendering/WebGPU/Camera.js +65 -67
- package/Rendering/WebGPU/CellArrayMapper.js +621 -388
- package/Rendering/WebGPU/CubeAxesActor.js +28 -19
- package/Rendering/WebGPU/Device.js +78 -133
- package/Rendering/WebGPU/ForwardPass.js +75 -72
- package/Rendering/WebGPU/FullScreenQuad.js +25 -18
- package/Rendering/WebGPU/Glyph3DMapper.js +62 -74
- package/Rendering/WebGPU/HardwareSelectionPass.js +45 -38
- package/Rendering/WebGPU/HardwareSelector.js +200 -276
- package/Rendering/WebGPU/ImageMapper.js +180 -171
- package/Rendering/WebGPU/ImageSlice.js +45 -44
- package/Rendering/WebGPU/IndexBuffer.js +166 -200
- package/Rendering/WebGPU/OpaquePass.js +37 -36
- package/Rendering/WebGPU/OrderIndependentTranslucentPass.js +72 -45
- package/Rendering/WebGPU/Pipeline.js +37 -51
- package/Rendering/WebGPU/PixelSpaceCallbackMapper.js +27 -19
- package/Rendering/WebGPU/PolyDataMapper.js +50 -53
- package/Rendering/WebGPU/PolyDataMapper2D.js +39 -39
- package/Rendering/WebGPU/RenderEncoder.js +68 -88
- package/Rendering/WebGPU/RenderWindow.js +262 -376
- package/Rendering/WebGPU/Renderer.js +224 -208
- package/Rendering/WebGPU/Sampler.js +27 -21
- package/Rendering/WebGPU/ScalarBarActor.js +28 -19
- package/Rendering/WebGPU/ShaderCache.js +43 -41
- package/Rendering/WebGPU/ShaderDescription.js +52 -59
- package/Rendering/WebGPU/ShaderModule.js +26 -17
- package/Rendering/WebGPU/SimpleMapper.js +185 -121
- package/Rendering/WebGPU/SphereMapper.js +200 -130
- package/Rendering/WebGPU/StickMapper.js +289 -152
- package/Rendering/WebGPU/StorageBuffer.js +100 -115
- package/Rendering/WebGPU/Texture.js +79 -99
- package/Rendering/WebGPU/TextureManager.js +52 -54
- package/Rendering/WebGPU/TextureView.js +40 -43
- package/Rendering/WebGPU/Types.js +53 -70
- package/Rendering/WebGPU/UniformBuffer.js +158 -184
- package/Rendering/WebGPU/VertexInput.js +64 -90
- package/Rendering/WebGPU/ViewNodeFactory.js +25 -13
- package/Rendering/WebGPU/Volume.js +52 -51
- package/Rendering/WebGPU/VolumePass.js +218 -239
- package/Rendering/WebGPU/VolumePassFSQ.js +625 -306
- package/Rendering/WebGPU.js +1 -1
- package/Rendering/index.js +5 -5
- package/Widgets/Core/AbstractWidget/Constants.js +2 -2
- package/Widgets/Core/AbstractWidget.js +49 -58
- package/Widgets/Core/AbstractWidgetFactory.js +101 -122
- package/Widgets/Core/StateBuilder/boundsMixin.js +23 -28
- package/Widgets/Core/StateBuilder/color3Mixin.js +10 -7
- package/Widgets/Core/StateBuilder/colorMixin.js +10 -6
- package/Widgets/Core/StateBuilder/cornerMixin.js +16 -15
- package/Widgets/Core/StateBuilder/directionMixin.js +20 -18
- package/Widgets/Core/StateBuilder/manipulatorMixin.js +26 -18
- package/Widgets/Core/StateBuilder/nameMixin.js +10 -6
- package/Widgets/Core/StateBuilder/orientationMixin.js +19 -16
- package/Widgets/Core/StateBuilder/originMixin.js +25 -32
- package/Widgets/Core/StateBuilder/scale1Mixin.js +10 -6
- package/Widgets/Core/StateBuilder/scale3Mixin.js +10 -6
- package/Widgets/Core/StateBuilder/shapeMixin.js +12 -6
- package/Widgets/Core/StateBuilder/textMixin.js +10 -6
- package/Widgets/Core/StateBuilder/visibleMixin.js +10 -6
- package/Widgets/Core/StateBuilder.js +120 -149
- package/Widgets/Core/WidgetManager/Constants.js +7 -7
- package/Widgets/Core/WidgetManager.js +249 -421
- package/Widgets/Core/WidgetState.js +48 -57
- package/Widgets/Core.js +5 -5
- package/Widgets/Manipulators/AbstractManipulator.js +20 -14
- package/Widgets/Manipulators/CPRManipulator.js +55 -71
- package/Widgets/Manipulators/LineManipulator.js +31 -28
- package/Widgets/Manipulators/PickerManipulator.d.ts +48 -0
- package/Widgets/Manipulators/PickerManipulator.js +65 -0
- package/Widgets/Manipulators/PlaneManipulator.js +26 -23
- package/Widgets/Manipulators/TrackballManipulator.js +39 -35
- package/Widgets/Manipulators.js +4 -2
- package/Widgets/Representations/ArrowHandleRepresentation.js +148 -162
- package/Widgets/Representations/CircleContextRepresentation.js +44 -38
- package/Widgets/Representations/ContextRepresentation.js +17 -14
- package/Widgets/Representations/ConvexFaceContextRepresentation.js +50 -47
- package/Widgets/Representations/CroppingOutlineRepresentation.js +38 -27
- package/Widgets/Representations/CubeHandleRepresentation.js +21 -18
- package/Widgets/Representations/GlyphRepresentation.js +107 -152
- package/Widgets/Representations/HandleRepresentation.js +17 -14
- package/Widgets/Representations/ImplicitPlaneRepresentation.js +97 -91
- package/Widgets/Representations/LineHandleRepresentation.js +44 -41
- package/Widgets/Representations/OutlineContextRepresentation.js +42 -36
- package/Widgets/Representations/PolyLineRepresentation.js +60 -75
- package/Widgets/Representations/RectangleContextRepresentation.js +42 -37
- package/Widgets/Representations/SphereContextRepresentation.js +19 -27
- package/Widgets/Representations/SphereHandleRepresentation.js +31 -27
- package/Widgets/Representations/SplineContextRepresentation.js +46 -70
- package/Widgets/Representations/WidgetRepresentation/Constants.js +2 -2
- package/Widgets/Representations/WidgetRepresentation.js +99 -134
- package/Widgets/Representations.js +13 -13
- package/Widgets/Widgets3D/AngleWidget/behavior.js +41 -63
- package/Widgets/Widgets3D/AngleWidget.js +40 -38
- package/Widgets/Widgets3D/DistanceWidget/behavior.js +40 -61
- package/Widgets/Widgets3D/DistanceWidget.js +38 -36
- package/Widgets/Widgets3D/EllipseWidget/behavior.js +14 -19
- package/Widgets/Widgets3D/EllipseWidget/state.js +4 -2
- package/Widgets/Widgets3D/EllipseWidget.js +37 -26
- package/Widgets/Widgets3D/ImageCroppingWidget/behavior.js +26 -56
- package/Widgets/Widgets3D/ImageCroppingWidget/helpers.js +14 -17
- package/Widgets/Widgets3D/ImageCroppingWidget/state.js +20 -16
- package/Widgets/Widgets3D/ImageCroppingWidget.js +80 -98
- package/Widgets/Widgets3D/ImplicitPlaneWidget.js +55 -77
- package/Widgets/Widgets3D/InteractiveOrientationWidget/behavior.js +17 -18
- package/Widgets/Widgets3D/InteractiveOrientationWidget/state.js +15 -7
- package/Widgets/Widgets3D/InteractiveOrientationWidget.js +30 -29
- package/Widgets/Widgets3D/LabelWidget/behavior.js +37 -62
- package/Widgets/Widgets3D/LabelWidget.js +31 -25
- package/Widgets/Widgets3D/LineWidget/Constants.js +8 -8
- package/Widgets/Widgets3D/LineWidget/behavior.js +77 -114
- package/Widgets/Widgets3D/LineWidget/helpers.js +13 -20
- package/Widgets/Widgets3D/LineWidget/state.js +2 -1
- package/Widgets/Widgets3D/LineWidget.js +39 -35
- package/Widgets/Widgets3D/PaintWidget/behavior.js +24 -59
- package/Widgets/Widgets3D/PaintWidget.js +39 -37
- package/Widgets/Widgets3D/PolyLineWidget/behavior.js +44 -68
- package/Widgets/Widgets3D/PolyLineWidget.js +36 -31
- package/Widgets/Widgets3D/RectangleWidget/behavior.js +6 -11
- package/Widgets/Widgets3D/RectangleWidget/state.js +4 -2
- package/Widgets/Widgets3D/RectangleWidget.js +37 -25
- package/Widgets/Widgets3D/ResliceCursorWidget/Constants.js +35 -21
- package/Widgets/Widgets3D/ResliceCursorWidget/behavior.js +133 -209
- package/Widgets/Widgets3D/ResliceCursorWidget/cprBehavior.js +26 -41
- package/Widgets/Widgets3D/ResliceCursorWidget/helpers.js +89 -116
- package/Widgets/Widgets3D/ResliceCursorWidget/state.js +33 -40
- package/Widgets/Widgets3D/ResliceCursorWidget.js +186 -227
- package/Widgets/Widgets3D/SeedWidget/behavior.js +82 -0
- package/Widgets/Widgets3D/SeedWidget/state.js +18 -0
- package/Widgets/Widgets3D/SeedWidget.d.ts +44 -0
- package/Widgets/Widgets3D/SeedWidget.js +43 -0
- package/Widgets/Widgets3D/ShapeWidget/Constants.js +19 -19
- package/Widgets/Widgets3D/ShapeWidget/behavior.js +150 -252
- package/Widgets/Widgets3D/ShapeWidget.js +24 -27
- package/Widgets/Widgets3D/SphereWidget/behavior.js +35 -69
- package/Widgets/Widgets3D/SphereWidget/state.js +9 -5
- package/Widgets/Widgets3D/SphereWidget.js +34 -44
- package/Widgets/Widgets3D/SplineWidget/behavior.js +85 -120
- package/Widgets/Widgets3D/SplineWidget.js +43 -39
- package/Widgets/Widgets3D.js +15 -15
- package/Widgets/index.js +4 -4
- package/_virtual/rollup-plugin-worker-loader__module_Sources/Filters/General/PaintFilter/PaintFilter.worker.js +95 -207
- package/_virtual/rollup-plugin-worker-loader__module_Sources/Interaction/Widgets/PiecewiseGaussianWidget/ComputeHistogram.worker.js +0 -3
- package/favicon.js +5 -6
- package/index.d.ts +4 -2
- package/index.js +4 -3
- package/macros.js +4 -1931
- package/macros2.js +1684 -0
- package/package.json +6 -6
- package/vtk.js +18 -31
|
@@ -1,180 +1,153 @@
|
|
|
1
|
-
import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
|
|
2
|
-
import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
|
|
3
1
|
import seedrandom from 'seedrandom';
|
|
4
|
-
import macro from '../../../
|
|
2
|
+
import { m as macro } from '../../../macros2.js';
|
|
5
3
|
import { IDENTITY, IDENTITY_3X3, VTK_SMALL_NUMBER, EPSILON } from './Constants.js';
|
|
6
4
|
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
const {
|
|
6
|
+
vtkErrorMacro,
|
|
7
|
+
vtkWarningMacro
|
|
8
|
+
} = macro;
|
|
9
9
|
|
|
10
|
+
// ----------------------------------------------------------------------------
|
|
10
11
|
/* eslint-disable camelcase */
|
|
11
|
-
|
|
12
12
|
/* eslint-disable no-cond-assign */
|
|
13
|
-
|
|
14
13
|
/* eslint-disable no-bitwise */
|
|
15
|
-
|
|
16
14
|
/* eslint-disable no-multi-assign */
|
|
17
15
|
// ----------------------------------------------------------------------------
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
var VTK_MAX_ROTATIONS = 20;
|
|
21
|
-
|
|
16
|
+
let randomSeedValue = 0;
|
|
17
|
+
const VTK_MAX_ROTATIONS = 20;
|
|
22
18
|
function notImplemented(method) {
|
|
23
|
-
return
|
|
24
|
-
|
|
25
|
-
};
|
|
26
|
-
} // Swap rows for n by n matrix
|
|
27
|
-
|
|
19
|
+
return () => vtkErrorMacro(`vtkMath::${method} - NOT IMPLEMENTED`);
|
|
20
|
+
}
|
|
28
21
|
|
|
22
|
+
// Swap rows for n by n matrix
|
|
29
23
|
function swapRowsMatrix_nxn(matrix, n, row1, row2) {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
for (var i = 0; i < n; i++) {
|
|
24
|
+
let tmp;
|
|
25
|
+
for (let i = 0; i < n; i++) {
|
|
33
26
|
tmp = matrix[row1 * n + i];
|
|
34
27
|
matrix[row1 * n + i] = matrix[row2 * n + i];
|
|
35
28
|
matrix[row2 * n + i] = tmp;
|
|
36
29
|
}
|
|
37
|
-
}
|
|
38
|
-
|
|
30
|
+
}
|
|
39
31
|
|
|
32
|
+
// Swap columns for n by n matrix
|
|
40
33
|
function swapColumnsMatrix_nxn(matrix, n, column1, column2) {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
for (var i = 0; i < n; i++) {
|
|
34
|
+
let tmp;
|
|
35
|
+
for (let i = 0; i < n; i++) {
|
|
44
36
|
tmp = matrix[i * n + column1];
|
|
45
37
|
matrix[i * n + column1] = matrix[i * n + column2];
|
|
46
38
|
matrix[i * n + column2] = tmp;
|
|
47
39
|
}
|
|
48
|
-
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// ----------------------------------------------------------------------------
|
|
49
43
|
// Global methods
|
|
50
44
|
// ----------------------------------------------------------------------------
|
|
51
45
|
|
|
52
|
-
|
|
53
46
|
function createArray() {
|
|
54
|
-
|
|
47
|
+
let size = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 3;
|
|
55
48
|
// faster than Array.from and/or while loop
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
for (var i = 0; i < size; ++i) {
|
|
49
|
+
const res = Array(size);
|
|
50
|
+
for (let i = 0; i < size; ++i) {
|
|
59
51
|
res[i] = 0;
|
|
60
52
|
}
|
|
61
|
-
|
|
62
53
|
return res;
|
|
63
54
|
}
|
|
64
|
-
|
|
65
|
-
return Math.PI;
|
|
66
|
-
};
|
|
55
|
+
const Pi = () => Math.PI;
|
|
67
56
|
function radiansFromDegrees(deg) {
|
|
68
57
|
return deg / 180 * Math.PI;
|
|
69
58
|
}
|
|
70
59
|
function degreesFromRadians(rad) {
|
|
71
60
|
return rad * 180 / Math.PI;
|
|
72
61
|
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
62
|
+
const {
|
|
63
|
+
round,
|
|
64
|
+
floor,
|
|
65
|
+
ceil,
|
|
66
|
+
min,
|
|
67
|
+
max
|
|
68
|
+
} = Math;
|
|
78
69
|
function arrayMin(arr) {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
for (var i = offset, len = arr.length; i < len; i += stride) {
|
|
70
|
+
let offset = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
71
|
+
let stride = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
|
|
72
|
+
let minValue = Infinity;
|
|
73
|
+
for (let i = offset, len = arr.length; i < len; i += stride) {
|
|
84
74
|
if (arr[i] < minValue) {
|
|
85
75
|
minValue = arr[i];
|
|
86
76
|
}
|
|
87
77
|
}
|
|
88
|
-
|
|
89
78
|
return minValue;
|
|
90
79
|
}
|
|
91
80
|
function arrayMax(arr) {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
for (var i = offset, len = arr.length; i < len; i += stride) {
|
|
81
|
+
let offset = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
82
|
+
let stride = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
|
|
83
|
+
let maxValue = -Infinity;
|
|
84
|
+
for (let i = offset, len = arr.length; i < len; i += stride) {
|
|
97
85
|
if (maxValue < arr[i]) {
|
|
98
86
|
maxValue = arr[i];
|
|
99
87
|
}
|
|
100
88
|
}
|
|
101
|
-
|
|
102
89
|
return maxValue;
|
|
103
90
|
}
|
|
104
91
|
function arrayRange(arr) {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
for (var i = offset, len = arr.length; i < len; i += stride) {
|
|
92
|
+
let offset = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
93
|
+
let stride = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
|
|
94
|
+
let minValue = Infinity;
|
|
95
|
+
let maxValue = -Infinity;
|
|
96
|
+
for (let i = offset, len = arr.length; i < len; i += stride) {
|
|
111
97
|
if (arr[i] < minValue) {
|
|
112
98
|
minValue = arr[i];
|
|
113
99
|
}
|
|
114
|
-
|
|
115
100
|
if (maxValue < arr[i]) {
|
|
116
101
|
maxValue = arr[i];
|
|
117
102
|
}
|
|
118
103
|
}
|
|
119
|
-
|
|
120
104
|
return [minValue, maxValue];
|
|
121
105
|
}
|
|
122
|
-
|
|
123
|
-
|
|
106
|
+
const ceilLog2 = notImplemented('ceilLog2');
|
|
107
|
+
const factorial = notImplemented('factorial');
|
|
124
108
|
function nearestPowerOfTwo(xi) {
|
|
125
|
-
|
|
126
|
-
|
|
109
|
+
let v = 1;
|
|
127
110
|
while (v < xi) {
|
|
128
111
|
v *= 2;
|
|
129
112
|
}
|
|
130
|
-
|
|
131
113
|
return v;
|
|
132
114
|
}
|
|
133
115
|
function isPowerOfTwo(x) {
|
|
134
116
|
return x === nearestPowerOfTwo(x);
|
|
135
117
|
}
|
|
136
118
|
function binomial(m, n) {
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
for (var i = 1; i <= n; ++i) {
|
|
119
|
+
let r = 1;
|
|
120
|
+
for (let i = 1; i <= n; ++i) {
|
|
140
121
|
r *= (m - i + 1) / i;
|
|
141
122
|
}
|
|
142
|
-
|
|
143
123
|
return Math.floor(r);
|
|
144
124
|
}
|
|
145
125
|
function beginCombination(m, n) {
|
|
146
126
|
if (m < n) {
|
|
147
127
|
return 0;
|
|
148
128
|
}
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
for (var i = 0; i < n; ++i) {
|
|
129
|
+
const r = createArray(n);
|
|
130
|
+
for (let i = 0; i < n; ++i) {
|
|
153
131
|
r[i] = i;
|
|
154
132
|
}
|
|
155
|
-
|
|
156
133
|
return r;
|
|
157
134
|
}
|
|
158
135
|
function nextCombination(m, n, r) {
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
for (var i = n - 1; i >= 0; --i) {
|
|
136
|
+
let status = 0;
|
|
137
|
+
for (let i = n - 1; i >= 0; --i) {
|
|
162
138
|
if (r[i] < m - n + i) {
|
|
163
|
-
|
|
164
|
-
|
|
139
|
+
let j = r[i] + 1;
|
|
165
140
|
while (i < n) {
|
|
166
141
|
r[i++] = j++;
|
|
167
142
|
}
|
|
168
|
-
|
|
169
143
|
status = 1;
|
|
170
144
|
break;
|
|
171
145
|
}
|
|
172
146
|
}
|
|
173
|
-
|
|
174
147
|
return status;
|
|
175
148
|
}
|
|
176
149
|
function randomSeed(seed) {
|
|
177
|
-
seedrandom(
|
|
150
|
+
seedrandom(`${seed}`, {
|
|
178
151
|
global: true
|
|
179
152
|
});
|
|
180
153
|
randomSeedValue = seed;
|
|
@@ -183,13 +156,14 @@ function getSeed() {
|
|
|
183
156
|
return randomSeedValue;
|
|
184
157
|
}
|
|
185
158
|
function random() {
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
159
|
+
let minValue = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
|
|
160
|
+
let maxValue = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
|
|
161
|
+
const delta = maxValue - minValue;
|
|
189
162
|
return minValue + delta * Math.random();
|
|
190
163
|
}
|
|
191
|
-
|
|
164
|
+
const gaussian = notImplemented('gaussian');
|
|
192
165
|
|
|
166
|
+
// Vect3 operations
|
|
193
167
|
function add(a, b, out) {
|
|
194
168
|
out[0] = a[0] + b[0];
|
|
195
169
|
out[1] = a[1] + b[1];
|
|
@@ -239,59 +213,52 @@ function outer(x, y, out_3x3) {
|
|
|
239
213
|
out_3x3[8] = x[2] * y[2];
|
|
240
214
|
}
|
|
241
215
|
function cross(x, y, out) {
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
216
|
+
const Zx = x[1] * y[2] - x[2] * y[1];
|
|
217
|
+
const Zy = x[2] * y[0] - x[0] * y[2];
|
|
218
|
+
const Zz = x[0] * y[1] - x[1] * y[0];
|
|
245
219
|
out[0] = Zx;
|
|
246
220
|
out[1] = Zy;
|
|
247
221
|
out[2] = Zz;
|
|
248
222
|
return out;
|
|
249
223
|
}
|
|
250
224
|
function norm(x) {
|
|
251
|
-
|
|
252
|
-
|
|
225
|
+
let n = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 3;
|
|
253
226
|
switch (n) {
|
|
254
227
|
case 1:
|
|
255
228
|
return Math.abs(x);
|
|
256
|
-
|
|
257
229
|
case 2:
|
|
258
230
|
return Math.sqrt(x[0] * x[0] + x[1] * x[1]);
|
|
259
|
-
|
|
260
231
|
case 3:
|
|
261
232
|
return Math.sqrt(x[0] * x[0] + x[1] * x[1] + x[2] * x[2]);
|
|
262
|
-
|
|
263
233
|
default:
|
|
264
234
|
{
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
for (var i = 0; i < n; i++) {
|
|
235
|
+
let sum = 0;
|
|
236
|
+
for (let i = 0; i < n; i++) {
|
|
268
237
|
sum += x[i] * x[i];
|
|
269
238
|
}
|
|
270
|
-
|
|
271
239
|
return Math.sqrt(sum);
|
|
272
240
|
}
|
|
273
241
|
}
|
|
274
242
|
}
|
|
275
243
|
function normalize(x) {
|
|
276
|
-
|
|
277
|
-
|
|
244
|
+
const den = norm(x);
|
|
278
245
|
if (den !== 0.0) {
|
|
279
246
|
x[0] /= den;
|
|
280
247
|
x[1] /= den;
|
|
281
248
|
x[2] /= den;
|
|
282
249
|
}
|
|
283
|
-
|
|
284
250
|
return den;
|
|
285
251
|
}
|
|
286
252
|
function perpendiculars(x, y, z, theta) {
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
253
|
+
const x2 = x[0] * x[0];
|
|
254
|
+
const y2 = x[1] * x[1];
|
|
255
|
+
const z2 = x[2] * x[2];
|
|
256
|
+
const r = Math.sqrt(x2 + y2 + z2);
|
|
257
|
+
let dx;
|
|
258
|
+
let dy;
|
|
259
|
+
let dz;
|
|
260
|
+
|
|
261
|
+
// transpose the vector to avoid divide-by-zero error
|
|
295
262
|
if (x2 > y2 && x2 > z2) {
|
|
296
263
|
dx = 0;
|
|
297
264
|
dy = 1;
|
|
@@ -305,22 +272,18 @@ function perpendiculars(x, y, z, theta) {
|
|
|
305
272
|
dy = 0;
|
|
306
273
|
dz = 1;
|
|
307
274
|
}
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
var tmp = Math.sqrt(a * a + c * c);
|
|
313
|
-
|
|
275
|
+
const a = x[dx] / r;
|
|
276
|
+
const b = x[dy] / r;
|
|
277
|
+
const c = x[dz] / r;
|
|
278
|
+
const tmp = Math.sqrt(a * a + c * c);
|
|
314
279
|
if (theta !== 0) {
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
280
|
+
const sintheta = Math.sin(theta);
|
|
281
|
+
const costheta = Math.cos(theta);
|
|
318
282
|
if (y) {
|
|
319
283
|
y[dx] = (c * costheta - a * b * sintheta) / tmp;
|
|
320
284
|
y[dy] = sintheta * tmp;
|
|
321
285
|
y[dz] = (-(a * costheta) - b * c * sintheta) / tmp;
|
|
322
286
|
}
|
|
323
|
-
|
|
324
287
|
if (z) {
|
|
325
288
|
z[dx] = (-(c * sintheta) - a * b * costheta) / tmp;
|
|
326
289
|
z[dy] = costheta * tmp;
|
|
@@ -332,7 +295,6 @@ function perpendiculars(x, y, z, theta) {
|
|
|
332
295
|
y[dy] = 0;
|
|
333
296
|
y[dz] = -a / tmp;
|
|
334
297
|
}
|
|
335
|
-
|
|
336
298
|
if (z) {
|
|
337
299
|
z[dx] = -a * b / tmp;
|
|
338
300
|
z[dy] = tmp;
|
|
@@ -341,21 +303,17 @@ function perpendiculars(x, y, z, theta) {
|
|
|
341
303
|
}
|
|
342
304
|
}
|
|
343
305
|
function projectVector(a, b, projection) {
|
|
344
|
-
|
|
345
|
-
|
|
306
|
+
const bSquared = dot(b, b);
|
|
346
307
|
if (bSquared === 0) {
|
|
347
308
|
projection[0] = 0;
|
|
348
309
|
projection[1] = 0;
|
|
349
310
|
projection[2] = 0;
|
|
350
311
|
return false;
|
|
351
312
|
}
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
for (var i = 0; i < 3; i++) {
|
|
313
|
+
const scale = dot(a, b) / bSquared;
|
|
314
|
+
for (let i = 0; i < 3; i++) {
|
|
356
315
|
projection[i] = b[i];
|
|
357
316
|
}
|
|
358
|
-
|
|
359
317
|
multiplyScalar(projection, scale);
|
|
360
318
|
return true;
|
|
361
319
|
}
|
|
@@ -363,20 +321,16 @@ function dot2D(x, y) {
|
|
|
363
321
|
return x[0] * y[0] + x[1] * y[1];
|
|
364
322
|
}
|
|
365
323
|
function projectVector2D(a, b, projection) {
|
|
366
|
-
|
|
367
|
-
|
|
324
|
+
const bSquared = dot2D(b, b);
|
|
368
325
|
if (bSquared === 0) {
|
|
369
326
|
projection[0] = 0;
|
|
370
327
|
projection[1] = 0;
|
|
371
328
|
return false;
|
|
372
329
|
}
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
for (var i = 0; i < 2; i++) {
|
|
330
|
+
const scale = dot2D(a, b) / bSquared;
|
|
331
|
+
for (let i = 0; i < 2; i++) {
|
|
377
332
|
projection[i] = b[i];
|
|
378
333
|
}
|
|
379
|
-
|
|
380
334
|
multiplyScalar2D(projection, scale);
|
|
381
335
|
return true;
|
|
382
336
|
}
|
|
@@ -384,23 +338,23 @@ function distance2BetweenPoints(x, y) {
|
|
|
384
338
|
return (x[0] - y[0]) * (x[0] - y[0]) + (x[1] - y[1]) * (x[1] - y[1]) + (x[2] - y[2]) * (x[2] - y[2]);
|
|
385
339
|
}
|
|
386
340
|
function angleBetweenVectors(v1, v2) {
|
|
387
|
-
|
|
341
|
+
const crossVect = [0, 0, 0];
|
|
388
342
|
cross(v1, v2, crossVect);
|
|
389
343
|
return Math.atan2(norm(crossVect), dot(v1, v2));
|
|
390
344
|
}
|
|
391
345
|
function signedAngleBetweenVectors(v1, v2, vN) {
|
|
392
|
-
|
|
346
|
+
const crossVect = [0, 0, 0];
|
|
393
347
|
cross(v1, v2, crossVect);
|
|
394
|
-
|
|
348
|
+
const angle = Math.atan2(norm(crossVect), dot(v1, v2));
|
|
395
349
|
return dot(crossVect, vN) >= 0 ? angle : -angle;
|
|
396
350
|
}
|
|
397
351
|
function gaussianAmplitude(mean, variance, position) {
|
|
398
|
-
|
|
399
|
-
return 1 / Math.sqrt(2 * Math.PI * variance) * Math.exp(-
|
|
352
|
+
const distanceFromMean = Math.abs(mean - position);
|
|
353
|
+
return 1 / Math.sqrt(2 * Math.PI * variance) * Math.exp(-(distanceFromMean ** 2) / (2 * variance));
|
|
400
354
|
}
|
|
401
355
|
function gaussianWeight(mean, variance, position) {
|
|
402
|
-
|
|
403
|
-
return Math.exp(-
|
|
356
|
+
const distanceFromMean = Math.abs(mean - position);
|
|
357
|
+
return Math.exp(-(distanceFromMean ** 2) / (2 * variance));
|
|
404
358
|
}
|
|
405
359
|
function outer2D(x, y, out_2x2) {
|
|
406
360
|
out_2x2[0] = x[0] * y[0];
|
|
@@ -412,132 +366,118 @@ function norm2D(x2D) {
|
|
|
412
366
|
return Math.sqrt(x2D[0] * x2D[0] + x2D[1] * x2D[1]);
|
|
413
367
|
}
|
|
414
368
|
function normalize2D(x) {
|
|
415
|
-
|
|
416
|
-
|
|
369
|
+
const den = norm2D(x);
|
|
417
370
|
if (den !== 0.0) {
|
|
418
371
|
x[0] /= den;
|
|
419
372
|
x[1] /= den;
|
|
420
373
|
}
|
|
421
|
-
|
|
422
374
|
return den;
|
|
423
375
|
}
|
|
424
376
|
function rowsToMat4(row0, row1, row2, row3, mat) {
|
|
425
|
-
for (
|
|
377
|
+
for (let i = 0; i < 4; i++) {
|
|
426
378
|
mat[i] = row0[i];
|
|
427
379
|
mat[4 + i] = row1[i];
|
|
428
380
|
mat[8 + i] = row2[i];
|
|
429
381
|
mat[12 + i] = row3[i];
|
|
430
382
|
}
|
|
431
|
-
|
|
432
383
|
return mat;
|
|
433
384
|
}
|
|
434
385
|
function columnsToMat4(column0, column1, column2, column3, mat) {
|
|
435
|
-
for (
|
|
386
|
+
for (let i = 0; i < 4; i++) {
|
|
436
387
|
mat[4 * i] = column0[i];
|
|
437
388
|
mat[4 * i + 1] = column1[i];
|
|
438
389
|
mat[4 * i + 2] = column2[i];
|
|
439
390
|
mat[4 * i + 3] = column3[i];
|
|
440
391
|
}
|
|
441
|
-
|
|
442
392
|
return mat;
|
|
443
393
|
}
|
|
444
394
|
function rowsToMat3(row0, row1, row2, mat) {
|
|
445
|
-
for (
|
|
395
|
+
for (let i = 0; i < 3; i++) {
|
|
446
396
|
mat[i] = row0[i];
|
|
447
397
|
mat[3 + i] = row1[i];
|
|
448
398
|
mat[6 + i] = row2[i];
|
|
449
399
|
}
|
|
450
|
-
|
|
451
400
|
return mat;
|
|
452
401
|
}
|
|
453
402
|
function columnsToMat3(column0, column1, column2, mat) {
|
|
454
|
-
for (
|
|
403
|
+
for (let i = 0; i < 3; i++) {
|
|
455
404
|
mat[3 * i] = column0[i];
|
|
456
405
|
mat[3 * i + 1] = column1[i];
|
|
457
406
|
mat[3 * i + 2] = column2[i];
|
|
458
407
|
}
|
|
459
|
-
|
|
460
408
|
return mat;
|
|
461
409
|
}
|
|
462
410
|
function determinant2x2() {
|
|
463
411
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
464
412
|
args[_key] = arguments[_key];
|
|
465
413
|
}
|
|
466
|
-
|
|
467
414
|
if (args.length === 2) {
|
|
468
415
|
return args[0][0] * args[1][1] - args[1][0] * args[0][1];
|
|
469
416
|
}
|
|
470
|
-
|
|
471
417
|
if (args.length === 4) {
|
|
472
418
|
return args[0] * args[3] - args[1] * args[2];
|
|
473
419
|
}
|
|
474
|
-
|
|
475
420
|
return Number.NaN;
|
|
476
421
|
}
|
|
477
422
|
function LUFactor3x3(mat_3x3, index_3) {
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
423
|
+
let maxI;
|
|
424
|
+
let tmp;
|
|
425
|
+
let largest;
|
|
426
|
+
const scale = [0, 0, 0];
|
|
482
427
|
|
|
483
|
-
|
|
428
|
+
// Loop over rows to get implicit scaling information
|
|
429
|
+
for (let i = 0; i < 3; i++) {
|
|
484
430
|
largest = Math.abs(mat_3x3[i * 3]);
|
|
485
|
-
|
|
486
431
|
if ((tmp = Math.abs(mat_3x3[i * 3 + 1])) > largest) {
|
|
487
432
|
largest = tmp;
|
|
488
433
|
}
|
|
489
|
-
|
|
490
434
|
if ((tmp = Math.abs(mat_3x3[i * 3 + 2])) > largest) {
|
|
491
435
|
largest = tmp;
|
|
492
436
|
}
|
|
493
|
-
|
|
494
437
|
scale[i] = 1 / largest;
|
|
495
|
-
}
|
|
496
|
-
// first column
|
|
438
|
+
}
|
|
497
439
|
|
|
440
|
+
// Loop over all columns using Crout's method
|
|
498
441
|
|
|
442
|
+
// first column
|
|
499
443
|
largest = scale[0] * Math.abs(mat_3x3[0]);
|
|
500
444
|
maxI = 0;
|
|
501
|
-
|
|
502
445
|
if ((tmp = scale[1] * Math.abs(mat_3x3[3])) >= largest) {
|
|
503
446
|
largest = tmp;
|
|
504
447
|
maxI = 1;
|
|
505
448
|
}
|
|
506
|
-
|
|
507
449
|
if ((tmp = scale[2] * Math.abs(mat_3x3[6])) >= largest) {
|
|
508
450
|
maxI = 2;
|
|
509
451
|
}
|
|
510
|
-
|
|
511
452
|
if (maxI !== 0) {
|
|
512
453
|
swapRowsMatrix_nxn(mat_3x3, 3, maxI, 0);
|
|
513
454
|
scale[maxI] = scale[0];
|
|
514
455
|
}
|
|
515
|
-
|
|
516
456
|
index_3[0] = maxI;
|
|
517
457
|
mat_3x3[3] /= mat_3x3[0];
|
|
518
|
-
mat_3x3[6] /= mat_3x3[0];
|
|
458
|
+
mat_3x3[6] /= mat_3x3[0];
|
|
519
459
|
|
|
460
|
+
// second column
|
|
520
461
|
mat_3x3[4] -= mat_3x3[3] * mat_3x3[1];
|
|
521
462
|
mat_3x3[7] -= mat_3x3[6] * mat_3x3[1];
|
|
522
463
|
largest = scale[1] * Math.abs(mat_3x3[4]);
|
|
523
464
|
maxI = 1;
|
|
524
|
-
|
|
525
465
|
if ((tmp = scale[2] * Math.abs(mat_3x3[7])) >= largest) {
|
|
526
466
|
maxI = 2;
|
|
527
467
|
swapRowsMatrix_nxn(mat_3x3, 3, 1, 2);
|
|
528
468
|
scale[2] = scale[1];
|
|
529
469
|
}
|
|
530
|
-
|
|
531
470
|
index_3[1] = maxI;
|
|
532
|
-
mat_3x3[7] /= mat_3x3[4];
|
|
471
|
+
mat_3x3[7] /= mat_3x3[4];
|
|
533
472
|
|
|
473
|
+
// third column
|
|
534
474
|
mat_3x3[5] -= mat_3x3[3] * mat_3x3[2];
|
|
535
475
|
mat_3x3[8] -= mat_3x3[6] * mat_3x3[2] + mat_3x3[7] * mat_3x3[5];
|
|
536
476
|
index_3[2] = 2;
|
|
537
477
|
}
|
|
538
478
|
function LUSolve3x3(mat_3x3, index_3, x_3) {
|
|
539
479
|
// forward substitution
|
|
540
|
-
|
|
480
|
+
let sum = x_3[index_3[0]];
|
|
541
481
|
x_3[index_3[0]] = x_3[0];
|
|
542
482
|
x_3[0] = sum;
|
|
543
483
|
sum = x_3[index_3[1]];
|
|
@@ -545,57 +485,60 @@ function LUSolve3x3(mat_3x3, index_3, x_3) {
|
|
|
545
485
|
x_3[1] = sum - mat_3x3[3] * x_3[0];
|
|
546
486
|
sum = x_3[index_3[2]];
|
|
547
487
|
x_3[index_3[2]] = x_3[2];
|
|
548
|
-
x_3[2] = sum - mat_3x3[6] * x_3[0] - mat_3x3[7] * x_3[1];
|
|
488
|
+
x_3[2] = sum - mat_3x3[6] * x_3[0] - mat_3x3[7] * x_3[1];
|
|
549
489
|
|
|
490
|
+
// back substitution
|
|
550
491
|
x_3[2] /= mat_3x3[8];
|
|
551
492
|
x_3[1] = (x_3[1] - mat_3x3[5] * x_3[2]) / mat_3x3[4];
|
|
552
493
|
x_3[0] = (x_3[0] - mat_3x3[1] * x_3[1] - mat_3x3[2] * x_3[2]) / mat_3x3[0];
|
|
553
494
|
}
|
|
554
495
|
function linearSolve3x3(mat_3x3, x_3, y_3) {
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
496
|
+
const a1 = mat_3x3[0];
|
|
497
|
+
const b1 = mat_3x3[1];
|
|
498
|
+
const c1 = mat_3x3[2];
|
|
499
|
+
const a2 = mat_3x3[3];
|
|
500
|
+
const b2 = mat_3x3[4];
|
|
501
|
+
const c2 = mat_3x3[5];
|
|
502
|
+
const a3 = mat_3x3[6];
|
|
503
|
+
const b3 = mat_3x3[7];
|
|
504
|
+
const c3 = mat_3x3[8];
|
|
505
|
+
|
|
506
|
+
// Compute the adjoint
|
|
507
|
+
const d1 = +determinant2x2(b2, b3, c2, c3);
|
|
508
|
+
const d2 = -determinant2x2(a2, a3, c2, c3);
|
|
509
|
+
const d3 = +determinant2x2(a2, a3, b2, b3);
|
|
510
|
+
const e1 = -determinant2x2(b1, b3, c1, c3);
|
|
511
|
+
const e2 = +determinant2x2(a1, a3, c1, c3);
|
|
512
|
+
const e3 = -determinant2x2(a1, a3, b1, b3);
|
|
513
|
+
const f1 = +determinant2x2(b1, b2, c1, c2);
|
|
514
|
+
const f2 = -determinant2x2(a1, a2, c1, c2);
|
|
515
|
+
const f3 = +determinant2x2(a1, a2, b1, b2);
|
|
516
|
+
|
|
517
|
+
// Compute the determinant
|
|
518
|
+
const det = a1 * d1 + b1 * d2 + c1 * d3;
|
|
519
|
+
|
|
520
|
+
// Multiply by the adjoint
|
|
521
|
+
const v1 = d1 * x_3[0] + e1 * x_3[1] + f1 * x_3[2];
|
|
522
|
+
const v2 = d2 * x_3[0] + e2 * x_3[1] + f2 * x_3[2];
|
|
523
|
+
const v3 = d3 * x_3[0] + e3 * x_3[1] + f3 * x_3[2];
|
|
524
|
+
|
|
525
|
+
// Divide by the determinant
|
|
581
526
|
y_3[0] = v1 / det;
|
|
582
527
|
y_3[1] = v2 / det;
|
|
583
528
|
y_3[2] = v3 / det;
|
|
584
529
|
}
|
|
585
530
|
function multiply3x3_vect3(mat_3x3, in_3, out_3) {
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
531
|
+
const x = mat_3x3[0] * in_3[0] + mat_3x3[1] * in_3[1] + mat_3x3[2] * in_3[2];
|
|
532
|
+
const y = mat_3x3[3] * in_3[0] + mat_3x3[4] * in_3[1] + mat_3x3[5] * in_3[2];
|
|
533
|
+
const z = mat_3x3[6] * in_3[0] + mat_3x3[7] * in_3[1] + mat_3x3[8] * in_3[2];
|
|
589
534
|
out_3[0] = x;
|
|
590
535
|
out_3[1] = y;
|
|
591
536
|
out_3[2] = z;
|
|
592
537
|
}
|
|
593
538
|
function multiply3x3_mat3(a_3x3, b_3x3, out_3x3) {
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
for (var i = 0; i < 3; i++) {
|
|
539
|
+
const copyA = [...a_3x3];
|
|
540
|
+
const copyB = [...b_3x3];
|
|
541
|
+
for (let i = 0; i < 3; i++) {
|
|
599
542
|
out_3x3[i] = copyA[0] * copyB[i] + copyA[1] * copyB[i + 3] + copyA[2] * copyB[i + 6];
|
|
600
543
|
out_3x3[i + 3] = copyA[3] * copyB[i] + copyA[4] * copyB[i + 3] + copyA[5] * copyB[i + 6];
|
|
601
544
|
out_3x3[i + 6] = copyA[6] * copyB[i] + copyA[7] * copyB[i + 3] + copyA[8] * copyB[i + 6];
|
|
@@ -605,29 +548,28 @@ function multiplyMatrix(a, b, rowA, colA, rowB, colB, out_rowXcol) {
|
|
|
605
548
|
// we need colA == rowB
|
|
606
549
|
if (colA !== rowB) {
|
|
607
550
|
vtkErrorMacro('Number of columns of A must match number of rows of B.');
|
|
608
|
-
}
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
var copyA = _toConsumableArray(a);
|
|
551
|
+
}
|
|
612
552
|
|
|
613
|
-
|
|
553
|
+
// If a or b is used to store the result, copying them is required
|
|
554
|
+
const copyA = [...a];
|
|
555
|
+
const copyB = [...b];
|
|
556
|
+
// output matrix is rowA*colB
|
|
614
557
|
// output row
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
for (var i = 0; i < rowA; i++) {
|
|
558
|
+
for (let i = 0; i < rowA; i++) {
|
|
618
559
|
// output col
|
|
619
|
-
for (
|
|
620
|
-
out_rowXcol[i * colB + j] = 0;
|
|
621
|
-
|
|
622
|
-
for (
|
|
560
|
+
for (let j = 0; j < colB; j++) {
|
|
561
|
+
out_rowXcol[i * colB + j] = 0;
|
|
562
|
+
// sum for this point
|
|
563
|
+
for (let k = 0; k < colA; k++) {
|
|
623
564
|
out_rowXcol[i * colB + j] += copyA[i * colA + k] * copyB[j + colB * k];
|
|
624
565
|
}
|
|
625
566
|
}
|
|
626
567
|
}
|
|
627
568
|
}
|
|
628
569
|
function transpose3x3(in_3x3, outT_3x3) {
|
|
629
|
-
|
|
570
|
+
let tmp;
|
|
630
571
|
|
|
572
|
+
// off-diagonal elements
|
|
631
573
|
tmp = in_3x3[3];
|
|
632
574
|
outT_3x3[3] = in_3x3[1];
|
|
633
575
|
outT_3x3[1] = tmp;
|
|
@@ -636,39 +578,40 @@ function transpose3x3(in_3x3, outT_3x3) {
|
|
|
636
578
|
outT_3x3[2] = tmp;
|
|
637
579
|
tmp = in_3x3[7];
|
|
638
580
|
outT_3x3[7] = in_3x3[5];
|
|
639
|
-
outT_3x3[5] = tmp;
|
|
581
|
+
outT_3x3[5] = tmp;
|
|
640
582
|
|
|
583
|
+
// on-diagonal elements
|
|
641
584
|
outT_3x3[0] = in_3x3[0];
|
|
642
585
|
outT_3x3[4] = in_3x3[4];
|
|
643
586
|
outT_3x3[8] = in_3x3[8];
|
|
644
587
|
}
|
|
645
588
|
function invert3x3(in_3x3, outI_3x3) {
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
589
|
+
const a1 = in_3x3[0];
|
|
590
|
+
const b1 = in_3x3[1];
|
|
591
|
+
const c1 = in_3x3[2];
|
|
592
|
+
const a2 = in_3x3[3];
|
|
593
|
+
const b2 = in_3x3[4];
|
|
594
|
+
const c2 = in_3x3[5];
|
|
595
|
+
const a3 = in_3x3[6];
|
|
596
|
+
const b3 = in_3x3[7];
|
|
597
|
+
const c3 = in_3x3[8];
|
|
598
|
+
|
|
599
|
+
// Compute the adjoint
|
|
600
|
+
const d1 = +determinant2x2(b2, b3, c2, c3);
|
|
601
|
+
const d2 = -determinant2x2(a2, a3, c2, c3);
|
|
602
|
+
const d3 = +determinant2x2(a2, a3, b2, b3);
|
|
603
|
+
const e1 = -determinant2x2(b1, b3, c1, c3);
|
|
604
|
+
const e2 = +determinant2x2(a1, a3, c1, c3);
|
|
605
|
+
const e3 = -determinant2x2(a1, a3, b1, b3);
|
|
606
|
+
const f1 = +determinant2x2(b1, b2, c1, c2);
|
|
607
|
+
const f2 = -determinant2x2(a1, a2, c1, c2);
|
|
608
|
+
const f3 = +determinant2x2(a1, a2, b1, b2);
|
|
609
|
+
|
|
610
|
+
// Divide by the determinant
|
|
611
|
+
const det = a1 * d1 + b1 * d2 + c1 * d3;
|
|
668
612
|
if (det === 0) {
|
|
669
613
|
vtkWarningMacro('Matrix has 0 determinant');
|
|
670
614
|
}
|
|
671
|
-
|
|
672
615
|
outI_3x3[0] = d1 / det;
|
|
673
616
|
outI_3x3[3] = d2 / det;
|
|
674
617
|
outI_3x3[6] = d3 / det;
|
|
@@ -682,68 +625,63 @@ function invert3x3(in_3x3, outI_3x3) {
|
|
|
682
625
|
function determinant3x3(mat_3x3) {
|
|
683
626
|
return mat_3x3[0] * mat_3x3[4] * mat_3x3[8] + mat_3x3[3] * mat_3x3[7] * mat_3x3[2] + mat_3x3[6] * mat_3x3[1] * mat_3x3[5] - mat_3x3[0] * mat_3x3[7] * mat_3x3[5] - mat_3x3[3] * mat_3x3[1] * mat_3x3[8] - mat_3x3[6] * mat_3x3[4] * mat_3x3[2];
|
|
684
627
|
}
|
|
628
|
+
|
|
685
629
|
/**
|
|
686
630
|
* Returns true if elements of both arrays are equals.
|
|
687
631
|
* @param {Array} a an array of numbers (vector, point, matrix...)
|
|
688
632
|
* @param {Array} b an array of numbers (vector, point, matrix...)
|
|
689
633
|
* @param {Number} eps tolerance
|
|
690
634
|
*/
|
|
691
|
-
|
|
692
635
|
function areEquals(a, b) {
|
|
693
|
-
|
|
694
|
-
|
|
636
|
+
let eps = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : EPSILON;
|
|
695
637
|
if (a.length !== b.length) {
|
|
696
638
|
return false;
|
|
697
639
|
}
|
|
698
|
-
|
|
699
640
|
function isEqual(element, index) {
|
|
700
641
|
return Math.abs(element - b[index]) <= eps;
|
|
701
642
|
}
|
|
702
|
-
|
|
703
643
|
return a.every(isEqual);
|
|
704
644
|
}
|
|
705
|
-
|
|
645
|
+
const areMatricesEqual = areEquals;
|
|
706
646
|
function identity3x3(mat_3x3) {
|
|
707
|
-
for (
|
|
647
|
+
for (let i = 0; i < 3; i++) {
|
|
708
648
|
/* eslint-disable-next-line no-multi-assign */
|
|
709
649
|
mat_3x3[i * 3] = mat_3x3[i * 3 + 1] = mat_3x3[i * 3 + 2] = 0;
|
|
710
650
|
mat_3x3[i * 3 + i] = 1;
|
|
711
651
|
}
|
|
712
652
|
}
|
|
713
653
|
function identity(n, mat) {
|
|
714
|
-
for (
|
|
715
|
-
for (
|
|
654
|
+
for (let i = 0; i < n; i++) {
|
|
655
|
+
for (let j = 0; j < n; j++) {
|
|
716
656
|
mat[i * n + j] = 0;
|
|
717
657
|
}
|
|
718
|
-
|
|
719
658
|
mat[i * n + i] = 1;
|
|
720
659
|
}
|
|
721
|
-
|
|
722
660
|
return mat;
|
|
723
661
|
}
|
|
724
662
|
function isIdentity(mat) {
|
|
725
|
-
|
|
663
|
+
let eps = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : EPSILON;
|
|
726
664
|
return areMatricesEqual(mat, IDENTITY, eps);
|
|
727
665
|
}
|
|
728
666
|
function isIdentity3x3(mat) {
|
|
729
|
-
|
|
667
|
+
let eps = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : EPSILON;
|
|
730
668
|
return areMatricesEqual(mat, IDENTITY_3X3, eps);
|
|
731
669
|
}
|
|
732
670
|
function quaternionToMatrix3x3(quat_4, mat_3x3) {
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
671
|
+
const ww = quat_4[0] * quat_4[0];
|
|
672
|
+
const wx = quat_4[0] * quat_4[1];
|
|
673
|
+
const wy = quat_4[0] * quat_4[2];
|
|
674
|
+
const wz = quat_4[0] * quat_4[3];
|
|
675
|
+
const xx = quat_4[1] * quat_4[1];
|
|
676
|
+
const yy = quat_4[2] * quat_4[2];
|
|
677
|
+
const zz = quat_4[3] * quat_4[3];
|
|
678
|
+
const xy = quat_4[1] * quat_4[2];
|
|
679
|
+
const xz = quat_4[1] * quat_4[3];
|
|
680
|
+
const yz = quat_4[2] * quat_4[3];
|
|
681
|
+
const rr = xx + yy + zz;
|
|
682
|
+
// normalization factor, just in case quaternion was not normalized
|
|
683
|
+
let f = 1 / (ww + rr);
|
|
684
|
+
const s = (ww - rr) * f;
|
|
747
685
|
f *= 2;
|
|
748
686
|
mat_3x3[0] = xx * f + s;
|
|
749
687
|
mat_3x3[3] = (xy + wz) * f;
|
|
@@ -756,105 +694,94 @@ function quaternionToMatrix3x3(quat_4, mat_3x3) {
|
|
|
756
694
|
mat_3x3[8] = zz * f + s;
|
|
757
695
|
}
|
|
758
696
|
function roundNumber(num) {
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
return +"".concat(Math.round("".concat(num, "e+").concat(digits)), "e-").concat(digits);
|
|
697
|
+
let digits = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
698
|
+
if (!`${num}`.includes('e')) {
|
|
699
|
+
return +`${Math.round(`${num}e+${digits}`)}e-${digits}`;
|
|
763
700
|
}
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
var sig = '';
|
|
767
|
-
|
|
701
|
+
const arr = `${num}`.split('e');
|
|
702
|
+
let sig = '';
|
|
768
703
|
if (+arr[1] + digits > 0) {
|
|
769
704
|
sig = '+';
|
|
770
705
|
}
|
|
771
|
-
|
|
772
|
-
return +"".concat(Math.round("".concat(+arr[0], "e").concat(sig).concat(+arr[1] + digits)), "e-").concat(digits);
|
|
706
|
+
return +`${Math.round(`${+arr[0]}e${sig}${+arr[1] + digits}`)}e-${digits}`;
|
|
773
707
|
}
|
|
774
708
|
function roundVector(vector) {
|
|
775
|
-
|
|
776
|
-
|
|
709
|
+
let out = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [0, 0, 0];
|
|
710
|
+
let digits = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
|
|
777
711
|
out[0] = roundNumber(vector[0], digits);
|
|
778
712
|
out[1] = roundNumber(vector[1], digits);
|
|
779
713
|
out[2] = roundNumber(vector[2], digits);
|
|
780
714
|
return out;
|
|
781
715
|
}
|
|
782
716
|
function jacobiN(a, n, w, v) {
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
var vtkROTATE = function vtkROTATE(aa, ii, jj) {
|
|
717
|
+
let i;
|
|
718
|
+
let j;
|
|
719
|
+
let k;
|
|
720
|
+
let iq;
|
|
721
|
+
let ip;
|
|
722
|
+
let numPos;
|
|
723
|
+
let tresh;
|
|
724
|
+
let theta;
|
|
725
|
+
let t;
|
|
726
|
+
let tau;
|
|
727
|
+
let sm;
|
|
728
|
+
let s;
|
|
729
|
+
let h;
|
|
730
|
+
let g;
|
|
731
|
+
let c;
|
|
732
|
+
let tmp;
|
|
733
|
+
const b = createArray(n);
|
|
734
|
+
const z = createArray(n);
|
|
735
|
+
const vtkROTATE = (aa, ii, jj) => {
|
|
803
736
|
g = aa[ii];
|
|
804
737
|
h = aa[jj];
|
|
805
738
|
aa[ii] = g - s * (h + g * tau);
|
|
806
739
|
aa[jj] = h + s * (g - h * tau);
|
|
807
|
-
};
|
|
808
|
-
|
|
740
|
+
};
|
|
809
741
|
|
|
742
|
+
// initialize
|
|
810
743
|
identity(n, v);
|
|
811
|
-
|
|
812
744
|
for (ip = 0; ip < n; ip++) {
|
|
813
745
|
b[ip] = w[ip] = a[ip + ip * n];
|
|
814
746
|
z[ip] = 0.0;
|
|
815
|
-
}
|
|
816
|
-
|
|
747
|
+
}
|
|
817
748
|
|
|
749
|
+
// begin rotation sequence
|
|
818
750
|
for (i = 0; i < VTK_MAX_ROTATIONS; i++) {
|
|
819
751
|
sm = 0.0;
|
|
820
|
-
|
|
821
752
|
for (ip = 0; ip < n - 1; ip++) {
|
|
822
753
|
for (iq = ip + 1; iq < n; iq++) {
|
|
823
754
|
sm += Math.abs(a[ip * n + iq]);
|
|
824
755
|
}
|
|
825
756
|
}
|
|
826
|
-
|
|
827
757
|
if (sm === 0.0) {
|
|
828
758
|
break;
|
|
829
|
-
}
|
|
830
|
-
|
|
759
|
+
}
|
|
831
760
|
|
|
761
|
+
// first 3 sweeps
|
|
832
762
|
if (i < 3) {
|
|
833
763
|
tresh = 0.2 * sm / (n * n);
|
|
834
764
|
} else {
|
|
835
765
|
tresh = 0.0;
|
|
836
766
|
}
|
|
837
|
-
|
|
838
767
|
for (ip = 0; ip < n - 1; ip++) {
|
|
839
768
|
for (iq = ip + 1; iq < n; iq++) {
|
|
840
|
-
g = 100.0 * Math.abs(a[ip * n + iq]);
|
|
769
|
+
g = 100.0 * Math.abs(a[ip * n + iq]);
|
|
841
770
|
|
|
771
|
+
// after 4 sweeps
|
|
842
772
|
if (i > 3 && Math.abs(w[ip]) + g === Math.abs(w[ip]) && Math.abs(w[iq]) + g === Math.abs(w[iq])) {
|
|
843
773
|
a[ip * n + iq] = 0.0;
|
|
844
774
|
} else if (Math.abs(a[ip * n + iq]) > tresh) {
|
|
845
775
|
h = w[iq] - w[ip];
|
|
846
|
-
|
|
847
776
|
if (Math.abs(h) + g === Math.abs(h)) {
|
|
848
777
|
t = a[ip * n + iq] / h;
|
|
849
778
|
} else {
|
|
850
779
|
theta = 0.5 * h / a[ip * n + iq];
|
|
851
780
|
t = 1.0 / (Math.abs(theta) + Math.sqrt(1.0 + theta * theta));
|
|
852
|
-
|
|
853
781
|
if (theta < 0.0) {
|
|
854
782
|
t = -t;
|
|
855
783
|
}
|
|
856
784
|
}
|
|
857
|
-
|
|
858
785
|
c = 1.0 / Math.sqrt(1 + t * t);
|
|
859
786
|
s = t * c;
|
|
860
787
|
tau = s / (1.0 + c);
|
|
@@ -863,48 +790,44 @@ function jacobiN(a, n, w, v) {
|
|
|
863
790
|
z[iq] += h;
|
|
864
791
|
w[ip] -= h;
|
|
865
792
|
w[iq] += h;
|
|
866
|
-
a[ip * n + iq] = 0.0;
|
|
793
|
+
a[ip * n + iq] = 0.0;
|
|
867
794
|
|
|
795
|
+
// ip already shifted left by 1 unit
|
|
868
796
|
for (j = 0; j <= ip - 1; j++) {
|
|
869
797
|
vtkROTATE(a, j * n + ip, j * n + iq);
|
|
870
|
-
}
|
|
871
|
-
|
|
872
|
-
|
|
798
|
+
}
|
|
799
|
+
// ip and iq already shifted left by 1 unit
|
|
873
800
|
for (j = ip + 1; j <= iq - 1; j++) {
|
|
874
801
|
vtkROTATE(a, ip * n + j, j * n + iq);
|
|
875
|
-
}
|
|
876
|
-
|
|
877
|
-
|
|
802
|
+
}
|
|
803
|
+
// iq already shifted left by 1 unit
|
|
878
804
|
for (j = iq + 1; j < n; j++) {
|
|
879
805
|
vtkROTATE(a, ip * n + j, iq * n + j);
|
|
880
806
|
}
|
|
881
|
-
|
|
882
807
|
for (j = 0; j < n; j++) {
|
|
883
808
|
vtkROTATE(v, j * n + ip, j * n + iq);
|
|
884
809
|
}
|
|
885
810
|
}
|
|
886
811
|
}
|
|
887
812
|
}
|
|
888
|
-
|
|
889
813
|
for (ip = 0; ip < n; ip++) {
|
|
890
814
|
b[ip] += z[ip];
|
|
891
815
|
w[ip] = b[ip];
|
|
892
816
|
z[ip] = 0.0;
|
|
893
817
|
}
|
|
894
|
-
}
|
|
895
|
-
|
|
818
|
+
}
|
|
896
819
|
|
|
820
|
+
// this is NEVER called
|
|
897
821
|
if (i >= VTK_MAX_ROTATIONS) {
|
|
898
822
|
vtkWarningMacro('vtkMath::Jacobi: Error extracting eigenfunctions');
|
|
899
823
|
return 0;
|
|
900
|
-
}
|
|
901
|
-
|
|
824
|
+
}
|
|
902
825
|
|
|
826
|
+
// sort eigenfunctions: these changes do not affect accuracy
|
|
903
827
|
for (j = 0; j < n - 1; j++) {
|
|
904
828
|
// boundary incorrect
|
|
905
829
|
k = j;
|
|
906
830
|
tmp = w[k];
|
|
907
|
-
|
|
908
831
|
for (i = j + 1; i < n; i++) {
|
|
909
832
|
// boundary incorrect, shifted already
|
|
910
833
|
if (w[i] >= tmp || Math.abs(w[i] - tmp) < VTK_SMALL_NUMBER) {
|
|
@@ -913,79 +836,78 @@ function jacobiN(a, n, w, v) {
|
|
|
913
836
|
tmp = w[k];
|
|
914
837
|
}
|
|
915
838
|
}
|
|
916
|
-
|
|
917
839
|
if (k !== j) {
|
|
918
840
|
w[k] = w[j];
|
|
919
841
|
w[j] = tmp;
|
|
920
842
|
swapColumnsMatrix_nxn(v, n, j, k);
|
|
921
843
|
}
|
|
922
|
-
}
|
|
844
|
+
}
|
|
845
|
+
// ensure eigenvector consistency (i.e., Jacobi can compute vectors that
|
|
923
846
|
// are negative of one another (.707,.707,0) and (-.707,-.707,0). This can
|
|
924
847
|
// reek havoc in hyperstreamline/other stuff. We will select the most
|
|
925
848
|
// positive eigenvector.
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
var ceil_half_n = (n >> 1) + (n & 1);
|
|
929
|
-
|
|
849
|
+
const ceil_half_n = (n >> 1) + (n & 1);
|
|
930
850
|
for (numPos = 0, i = 0; i < n * n; i++) {
|
|
931
851
|
if (v[i] >= 0.0) {
|
|
932
852
|
numPos++;
|
|
933
853
|
}
|
|
934
|
-
}
|
|
935
|
-
|
|
936
|
-
|
|
854
|
+
}
|
|
855
|
+
// if ( numPos < ceil(double(n)/double(2.0)) )
|
|
937
856
|
if (numPos < ceil_half_n) {
|
|
938
857
|
for (i = 0; i < n; i++) {
|
|
939
858
|
v[i * n + j] *= -1.0;
|
|
940
859
|
}
|
|
941
860
|
}
|
|
942
|
-
|
|
943
861
|
return 1;
|
|
944
862
|
}
|
|
945
863
|
function matrix3x3ToQuaternion(mat_3x3, quat_4) {
|
|
946
|
-
|
|
864
|
+
const tmp = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
|
|
947
865
|
|
|
866
|
+
// on-diagonal elements
|
|
948
867
|
tmp[0] = mat_3x3[0] + mat_3x3[4] + mat_3x3[8];
|
|
949
868
|
tmp[5] = mat_3x3[0] - mat_3x3[4] - mat_3x3[8];
|
|
950
869
|
tmp[10] = -mat_3x3[0] + mat_3x3[4] - mat_3x3[8];
|
|
951
|
-
tmp[15] = -mat_3x3[0] - mat_3x3[4] + mat_3x3[8];
|
|
870
|
+
tmp[15] = -mat_3x3[0] - mat_3x3[4] + mat_3x3[8];
|
|
952
871
|
|
|
872
|
+
// off-diagonal elements
|
|
953
873
|
tmp[1] = tmp[4] = mat_3x3[7] - mat_3x3[5];
|
|
954
874
|
tmp[2] = tmp[8] = mat_3x3[2] - mat_3x3[6];
|
|
955
875
|
tmp[3] = tmp[12] = mat_3x3[3] - mat_3x3[1];
|
|
956
876
|
tmp[6] = tmp[9] = mat_3x3[3] + mat_3x3[1];
|
|
957
877
|
tmp[7] = tmp[13] = mat_3x3[2] + mat_3x3[6];
|
|
958
878
|
tmp[11] = tmp[14] = mat_3x3[7] + mat_3x3[5];
|
|
959
|
-
|
|
960
|
-
|
|
879
|
+
const eigenvectors = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
|
|
880
|
+
const eigenvalues = [0, 0, 0, 0];
|
|
881
|
+
|
|
882
|
+
// convert into format that JacobiN can use,
|
|
961
883
|
// then use Jacobi to find eigenvalues and eigenvectors
|
|
962
884
|
// tmp is copied because jacobiN may modify it
|
|
885
|
+
const NTemp = [...tmp];
|
|
886
|
+
jacobiN(NTemp, 4, eigenvalues, eigenvectors);
|
|
963
887
|
|
|
964
|
-
|
|
965
|
-
jacobiN(NTemp, 4, eigenvalues, eigenvectors); // the first eigenvector is the one we want
|
|
966
|
-
|
|
888
|
+
// the first eigenvector is the one we want
|
|
967
889
|
quat_4[0] = eigenvectors[0];
|
|
968
890
|
quat_4[1] = eigenvectors[4];
|
|
969
891
|
quat_4[2] = eigenvectors[8];
|
|
970
892
|
quat_4[3] = eigenvectors[12];
|
|
971
893
|
}
|
|
972
894
|
function multiplyQuaternion(quat_1, quat_2, quat_out) {
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
895
|
+
const ww = quat_1[0] * quat_2[0];
|
|
896
|
+
const wx = quat_1[0] * quat_2[1];
|
|
897
|
+
const wy = quat_1[0] * quat_2[2];
|
|
898
|
+
const wz = quat_1[0] * quat_2[3];
|
|
899
|
+
const xw = quat_1[1] * quat_2[0];
|
|
900
|
+
const xx = quat_1[1] * quat_2[1];
|
|
901
|
+
const xy = quat_1[1] * quat_2[2];
|
|
902
|
+
const xz = quat_1[1] * quat_2[3];
|
|
903
|
+
const yw = quat_1[2] * quat_2[0];
|
|
904
|
+
const yx = quat_1[2] * quat_2[1];
|
|
905
|
+
const yy = quat_1[2] * quat_2[2];
|
|
906
|
+
const yz = quat_1[2] * quat_2[3];
|
|
907
|
+
const zw = quat_1[3] * quat_2[0];
|
|
908
|
+
const zx = quat_1[3] * quat_2[1];
|
|
909
|
+
const zy = quat_1[3] * quat_2[2];
|
|
910
|
+
const zz = quat_1[3] * quat_2[3];
|
|
989
911
|
quat_out[0] = ww - xx - yy - zz;
|
|
990
912
|
quat_out[1] = wx + xw + yz - zy;
|
|
991
913
|
quat_out[2] = wy - xz + yw + zx;
|
|
@@ -993,369 +915,341 @@ function multiplyQuaternion(quat_1, quat_2, quat_out) {
|
|
|
993
915
|
}
|
|
994
916
|
function orthogonalize3x3(a_3x3, out_3x3) {
|
|
995
917
|
// copy the matrix
|
|
996
|
-
for (
|
|
918
|
+
for (let i = 0; i < 9; i++) {
|
|
997
919
|
out_3x3[i] = a_3x3[i];
|
|
998
|
-
}
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
var scale = createArray(3);
|
|
1002
|
-
var index = createArray(3);
|
|
1003
|
-
var largest; // Loop over rows to get implicit scaling information
|
|
1004
|
-
|
|
1005
|
-
for (var _i = 0; _i < 3; _i++) {
|
|
1006
|
-
var _x = Math.abs(out_3x3[_i * 3]);
|
|
1007
|
-
|
|
1008
|
-
var _x2 = Math.abs(out_3x3[_i * 3 + 1]);
|
|
1009
|
-
|
|
1010
|
-
var _x3 = Math.abs(out_3x3[_i * 3 + 2]);
|
|
920
|
+
}
|
|
1011
921
|
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
922
|
+
// Pivot the matrix to improve accuracy
|
|
923
|
+
const scale = createArray(3);
|
|
924
|
+
const index = createArray(3);
|
|
925
|
+
let largest;
|
|
1015
926
|
|
|
927
|
+
// Loop over rows to get implicit scaling information
|
|
928
|
+
for (let i = 0; i < 3; i++) {
|
|
929
|
+
const x1 = Math.abs(out_3x3[i * 3]);
|
|
930
|
+
const x2 = Math.abs(out_3x3[i * 3 + 1]);
|
|
931
|
+
const x3 = Math.abs(out_3x3[i * 3 + 2]);
|
|
932
|
+
largest = x2 > x1 ? x2 : x1;
|
|
933
|
+
largest = x3 > largest ? x3 : largest;
|
|
934
|
+
scale[i] = 1;
|
|
1016
935
|
if (largest !== 0) {
|
|
1017
|
-
scale[
|
|
936
|
+
scale[i] /= largest;
|
|
1018
937
|
}
|
|
1019
|
-
}
|
|
1020
|
-
|
|
938
|
+
}
|
|
1021
939
|
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
940
|
+
// first column
|
|
941
|
+
const x1 = Math.abs(out_3x3[0]) * scale[0];
|
|
942
|
+
const x2 = Math.abs(out_3x3[3]) * scale[1];
|
|
943
|
+
const x3 = Math.abs(out_3x3[6]) * scale[2];
|
|
1025
944
|
index[0] = 0;
|
|
1026
945
|
largest = x1;
|
|
1027
|
-
|
|
1028
946
|
if (x2 >= largest) {
|
|
1029
947
|
largest = x2;
|
|
1030
948
|
index[0] = 1;
|
|
1031
949
|
}
|
|
1032
|
-
|
|
1033
950
|
if (x3 >= largest) {
|
|
1034
951
|
index[0] = 2;
|
|
1035
952
|
}
|
|
1036
|
-
|
|
1037
953
|
if (index[0] !== 0) {
|
|
1038
954
|
// swap vectors
|
|
1039
955
|
swapColumnsMatrix_nxn(out_3x3, 3, index[0], 0);
|
|
1040
956
|
scale[index[0]] = scale[0];
|
|
1041
|
-
}
|
|
1042
|
-
|
|
957
|
+
}
|
|
1043
958
|
|
|
1044
|
-
|
|
1045
|
-
|
|
959
|
+
// second column
|
|
960
|
+
const y2 = Math.abs(out_3x3[4]) * scale[1];
|
|
961
|
+
const y3 = Math.abs(out_3x3[7]) * scale[2];
|
|
1046
962
|
index[1] = 1;
|
|
1047
963
|
largest = y2;
|
|
1048
|
-
|
|
1049
964
|
if (y3 >= largest) {
|
|
1050
|
-
index[1] = 2;
|
|
1051
|
-
|
|
965
|
+
index[1] = 2;
|
|
966
|
+
// swap vectors
|
|
1052
967
|
swapColumnsMatrix_nxn(out_3x3, 3, 1, 2);
|
|
1053
|
-
}
|
|
968
|
+
}
|
|
1054
969
|
|
|
970
|
+
// third column
|
|
971
|
+
index[2] = 2;
|
|
1055
972
|
|
|
1056
|
-
|
|
973
|
+
// A quaternion can only describe a pure rotation, not
|
|
1057
974
|
// a rotation with a flip, therefore the flip must be
|
|
1058
975
|
// removed before the matrix is converted to a quaternion.
|
|
1059
|
-
|
|
1060
|
-
var flip = 0;
|
|
1061
|
-
|
|
976
|
+
let flip = 0;
|
|
1062
977
|
if (determinant3x3(out_3x3) < 0) {
|
|
1063
978
|
flip = 1;
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
out_3x3[_i2] = -out_3x3[_i2];
|
|
979
|
+
for (let i = 0; i < 9; i++) {
|
|
980
|
+
out_3x3[i] = -out_3x3[i];
|
|
1067
981
|
}
|
|
1068
|
-
}
|
|
982
|
+
}
|
|
983
|
+
|
|
984
|
+
// Do orthogonalization using a quaternion intermediate
|
|
1069
985
|
// (this, essentially, does the orthogonalization via
|
|
1070
986
|
// diagonalization of an appropriately constructed symmetric
|
|
1071
987
|
// 4x4 matrix rather than by doing SVD of the 3x3 matrix)
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
var quat = createArray(4);
|
|
988
|
+
const quat = createArray(4);
|
|
1075
989
|
matrix3x3ToQuaternion(out_3x3, quat);
|
|
1076
|
-
quaternionToMatrix3x3(quat, out_3x3);
|
|
990
|
+
quaternionToMatrix3x3(quat, out_3x3);
|
|
1077
991
|
|
|
992
|
+
// Put the flip back into the orthogonalized matrix.
|
|
1078
993
|
if (flip) {
|
|
1079
|
-
for (
|
|
1080
|
-
out_3x3[
|
|
994
|
+
for (let i = 0; i < 9; i++) {
|
|
995
|
+
out_3x3[i] = -out_3x3[i];
|
|
1081
996
|
}
|
|
1082
|
-
}
|
|
1083
|
-
|
|
997
|
+
}
|
|
1084
998
|
|
|
999
|
+
// Undo the pivoting
|
|
1085
1000
|
if (index[1] !== 1) {
|
|
1086
1001
|
swapColumnsMatrix_nxn(out_3x3, 3, index[1], 1);
|
|
1087
1002
|
}
|
|
1088
|
-
|
|
1089
1003
|
if (index[0] !== 0) {
|
|
1090
1004
|
swapColumnsMatrix_nxn(out_3x3, 3, index[0], 0);
|
|
1091
1005
|
}
|
|
1092
1006
|
}
|
|
1093
1007
|
function diagonalize3x3(a_3x3, w_3, v_3x3) {
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1008
|
+
let i;
|
|
1009
|
+
let j;
|
|
1010
|
+
let k;
|
|
1011
|
+
let maxI;
|
|
1012
|
+
let tmp;
|
|
1013
|
+
let maxVal;
|
|
1100
1014
|
|
|
1101
|
-
|
|
1015
|
+
// a is copied because jacobiN may modify it
|
|
1016
|
+
const copyA = [...a_3x3];
|
|
1102
1017
|
|
|
1018
|
+
// diagonalize using Jacobi
|
|
1019
|
+
jacobiN(copyA, 3, w_3, v_3x3);
|
|
1103
1020
|
|
|
1104
|
-
|
|
1105
|
-
|
|
1021
|
+
// if all the eigenvalues are the same, return identity matrix
|
|
1106
1022
|
if (w_3[0] === w_3[1] && w_3[0] === w_3[2]) {
|
|
1107
1023
|
identity3x3(v_3x3);
|
|
1108
1024
|
return;
|
|
1109
|
-
}
|
|
1025
|
+
}
|
|
1110
1026
|
|
|
1027
|
+
// transpose temporarily, it makes it easier to sort the eigenvectors
|
|
1028
|
+
transpose3x3(v_3x3, v_3x3);
|
|
1111
1029
|
|
|
1112
|
-
|
|
1030
|
+
// if two eigenvalues are the same, re-orthogonalize to optimally line
|
|
1113
1031
|
// up the eigenvectors with the x, y, and z axes
|
|
1114
|
-
|
|
1115
1032
|
for (i = 0; i < 3; i++) {
|
|
1116
1033
|
// two eigenvalues are the same
|
|
1117
1034
|
if (w_3[(i + 1) % 3] === w_3[(i + 2) % 3]) {
|
|
1118
1035
|
// find maximum element of the independent eigenvector
|
|
1119
1036
|
maxVal = Math.abs(v_3x3[i * 3]);
|
|
1120
1037
|
maxI = 0;
|
|
1121
|
-
|
|
1122
1038
|
for (j = 1; j < 3; j++) {
|
|
1123
1039
|
if (maxVal < (tmp = Math.abs(v_3x3[i * 3 + j]))) {
|
|
1124
1040
|
maxVal = tmp;
|
|
1125
1041
|
maxI = j;
|
|
1126
1042
|
}
|
|
1127
|
-
}
|
|
1128
|
-
|
|
1129
|
-
|
|
1043
|
+
}
|
|
1044
|
+
// swap the eigenvector into its proper position
|
|
1130
1045
|
if (maxI !== i) {
|
|
1131
1046
|
tmp = w_3[maxI];
|
|
1132
1047
|
w_3[maxI] = w_3[i];
|
|
1133
1048
|
w_3[i] = tmp;
|
|
1134
1049
|
swapRowsMatrix_nxn(v_3x3, 3, i, maxI);
|
|
1135
|
-
}
|
|
1136
|
-
|
|
1137
|
-
|
|
1050
|
+
}
|
|
1051
|
+
// maximum element of eigenvector should be positive
|
|
1138
1052
|
if (v_3x3[maxI * 3 + maxI] < 0) {
|
|
1139
1053
|
v_3x3[maxI * 3] = -v_3x3[maxI * 3];
|
|
1140
1054
|
v_3x3[maxI * 3 + 1] = -v_3x3[maxI * 3 + 1];
|
|
1141
1055
|
v_3x3[maxI * 3 + 2] = -v_3x3[maxI * 3 + 2];
|
|
1142
|
-
}
|
|
1143
|
-
|
|
1056
|
+
}
|
|
1144
1057
|
|
|
1058
|
+
// re-orthogonalize the other two eigenvectors
|
|
1145
1059
|
j = (maxI + 1) % 3;
|
|
1146
1060
|
k = (maxI + 2) % 3;
|
|
1147
1061
|
v_3x3[j * 3] = 0.0;
|
|
1148
1062
|
v_3x3[j * 3 + 1] = 0.0;
|
|
1149
1063
|
v_3x3[j * 3 + 2] = 0.0;
|
|
1150
1064
|
v_3x3[j * 3 + j] = 1.0;
|
|
1151
|
-
|
|
1065
|
+
const vectTmp1 = cross([v_3x3[maxI * 3], v_3x3[maxI * 3 + 1], v_3x3[maxI * 3 + 2]], [v_3x3[j * 3], v_3x3[j * 3 + 1], v_3x3[j * 3 + 2]], []);
|
|
1152
1066
|
normalize(vectTmp1);
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
for (var t = 0; t < 3; t++) {
|
|
1067
|
+
const vectTmp2 = cross(vectTmp1, [v_3x3[maxI * 3], v_3x3[maxI * 3 + 1], v_3x3[maxI * 3 + 2]], []);
|
|
1068
|
+
for (let t = 0; t < 3; t++) {
|
|
1156
1069
|
v_3x3[k * 3 + t] = vectTmp1[t];
|
|
1157
1070
|
v_3x3[j * 3 + t] = vectTmp2[t];
|
|
1158
|
-
}
|
|
1159
|
-
|
|
1071
|
+
}
|
|
1160
1072
|
|
|
1073
|
+
// transpose vectors back to columns
|
|
1161
1074
|
transpose3x3(v_3x3, v_3x3);
|
|
1162
1075
|
return;
|
|
1163
1076
|
}
|
|
1164
|
-
}
|
|
1077
|
+
}
|
|
1078
|
+
|
|
1079
|
+
// the three eigenvalues are different, just sort the eigenvectors
|
|
1165
1080
|
// to align them with the x, y, and z axes
|
|
1081
|
+
|
|
1166
1082
|
// find the vector with the largest x element, make that vector
|
|
1167
1083
|
// the first vector
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
1084
|
maxVal = Math.abs(v_3x3[0]);
|
|
1171
1085
|
maxI = 0;
|
|
1172
|
-
|
|
1173
1086
|
for (i = 1; i < 3; i++) {
|
|
1174
1087
|
if (maxVal < (tmp = Math.abs(v_3x3[i * 3]))) {
|
|
1175
1088
|
maxVal = tmp;
|
|
1176
1089
|
maxI = i;
|
|
1177
1090
|
}
|
|
1178
|
-
}
|
|
1179
|
-
|
|
1180
|
-
|
|
1091
|
+
}
|
|
1092
|
+
// swap eigenvalue and eigenvector
|
|
1181
1093
|
if (maxI !== 0) {
|
|
1182
|
-
|
|
1094
|
+
const eigenValTmp = w_3[maxI];
|
|
1183
1095
|
w_3[maxI] = w_3[0];
|
|
1184
1096
|
w_3[0] = eigenValTmp;
|
|
1185
1097
|
swapRowsMatrix_nxn(v_3x3, 3, maxI, 0);
|
|
1186
|
-
}
|
|
1187
|
-
|
|
1188
|
-
|
|
1098
|
+
}
|
|
1099
|
+
// do the same for the y element
|
|
1189
1100
|
if (Math.abs(v_3x3[4]) < Math.abs(v_3x3[7])) {
|
|
1190
|
-
|
|
1101
|
+
const eigenValTmp = w_3[2];
|
|
1191
1102
|
w_3[2] = w_3[1];
|
|
1192
|
-
w_3[1] =
|
|
1103
|
+
w_3[1] = eigenValTmp;
|
|
1193
1104
|
swapRowsMatrix_nxn(v_3x3, 3, 1, 2);
|
|
1194
|
-
}
|
|
1195
|
-
|
|
1105
|
+
}
|
|
1196
1106
|
|
|
1107
|
+
// ensure that the sign of the eigenvectors is correct
|
|
1197
1108
|
for (i = 0; i < 2; i++) {
|
|
1198
1109
|
if (v_3x3[i * 3 + i] < 0) {
|
|
1199
1110
|
v_3x3[i * 3] = -v_3x3[i * 3];
|
|
1200
1111
|
v_3x3[i * 3 + 1] = -v_3x3[i * 3 + 1];
|
|
1201
1112
|
v_3x3[i * 3 + 2] = -v_3x3[i * 3 + 2];
|
|
1202
1113
|
}
|
|
1203
|
-
}
|
|
1204
|
-
|
|
1205
|
-
|
|
1114
|
+
}
|
|
1115
|
+
// set sign of final eigenvector to ensure that determinant is positive
|
|
1206
1116
|
if (determinant3x3(v_3x3) < 0) {
|
|
1207
1117
|
v_3x3[6] = -v_3x3[6];
|
|
1208
1118
|
v_3x3[7] = -v_3x3[7];
|
|
1209
1119
|
v_3x3[8] = -v_3x3[8];
|
|
1210
|
-
}
|
|
1211
|
-
|
|
1120
|
+
}
|
|
1212
1121
|
|
|
1122
|
+
// transpose the eigenvectors back again
|
|
1213
1123
|
transpose3x3(v_3x3, v_3x3);
|
|
1214
1124
|
}
|
|
1215
1125
|
function singularValueDecomposition3x3(a_3x3, u_3x3, w_3, vT_3x3) {
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
var d = determinant3x3(B);
|
|
1126
|
+
let i;
|
|
1127
|
+
// copy so that A can be used for U or VT without risk
|
|
1128
|
+
const B = [...a_3x3];
|
|
1222
1129
|
|
|
1130
|
+
// temporarily flip if determinant is negative
|
|
1131
|
+
const d = determinant3x3(B);
|
|
1223
1132
|
if (d < 0) {
|
|
1224
1133
|
for (i = 0; i < 9; i++) {
|
|
1225
1134
|
B[i] = -B[i];
|
|
1226
1135
|
}
|
|
1227
|
-
}
|
|
1228
|
-
|
|
1136
|
+
}
|
|
1229
1137
|
|
|
1138
|
+
// orthogonalize, diagonalize, etc.
|
|
1230
1139
|
orthogonalize3x3(B, u_3x3);
|
|
1231
1140
|
transpose3x3(B, B);
|
|
1232
1141
|
multiply3x3_mat3(B, u_3x3, vT_3x3);
|
|
1233
1142
|
diagonalize3x3(vT_3x3, w_3, vT_3x3);
|
|
1234
1143
|
multiply3x3_mat3(u_3x3, vT_3x3, u_3x3);
|
|
1235
|
-
transpose3x3(vT_3x3, vT_3x3);
|
|
1144
|
+
transpose3x3(vT_3x3, vT_3x3);
|
|
1236
1145
|
|
|
1146
|
+
// re-create the flip
|
|
1237
1147
|
if (d < 0) {
|
|
1238
1148
|
w_3[0] = -w_3[0];
|
|
1239
1149
|
w_3[1] = -w_3[1];
|
|
1240
1150
|
w_3[2] = -w_3[2];
|
|
1241
1151
|
}
|
|
1242
1152
|
}
|
|
1153
|
+
|
|
1243
1154
|
/**
|
|
1244
1155
|
* Factor linear equations Ax = b using LU decomposition A = LU. Output factorization LU is in matrix A.
|
|
1245
1156
|
* @param {Matrix} A square matrix
|
|
1246
1157
|
* @param {Number} index integer array of pivot indices index[0->n-1]
|
|
1247
1158
|
* @param {Number} size matrix size
|
|
1248
1159
|
*/
|
|
1249
|
-
|
|
1250
1160
|
function luFactorLinearSystem(A, index, size) {
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1161
|
+
let i;
|
|
1162
|
+
let j;
|
|
1163
|
+
let k;
|
|
1164
|
+
let largest;
|
|
1165
|
+
let maxI = 0;
|
|
1166
|
+
let sum;
|
|
1167
|
+
let temp1;
|
|
1168
|
+
let temp2;
|
|
1169
|
+
const scale = createArray(size);
|
|
1170
|
+
|
|
1171
|
+
//
|
|
1260
1172
|
// Loop over rows to get implicit scaling information
|
|
1261
1173
|
//
|
|
1262
|
-
|
|
1263
1174
|
for (i = 0; i < size; i++) {
|
|
1264
1175
|
for (largest = 0.0, j = 0; j < size; j++) {
|
|
1265
1176
|
if ((temp2 = Math.abs(A[i * size + j])) > largest) {
|
|
1266
1177
|
largest = temp2;
|
|
1267
1178
|
}
|
|
1268
1179
|
}
|
|
1269
|
-
|
|
1270
1180
|
if (largest === 0.0) {
|
|
1271
1181
|
vtkWarningMacro('Unable to factor linear system');
|
|
1272
1182
|
return 0;
|
|
1273
1183
|
}
|
|
1274
|
-
|
|
1275
1184
|
scale[i] = 1.0 / largest;
|
|
1276
|
-
}
|
|
1185
|
+
}
|
|
1186
|
+
//
|
|
1277
1187
|
// Loop over all columns using Crout's method
|
|
1278
1188
|
//
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
1189
|
for (j = 0; j < size; j++) {
|
|
1282
1190
|
for (i = 0; i < j; i++) {
|
|
1283
1191
|
sum = A[i * size + j];
|
|
1284
|
-
|
|
1285
1192
|
for (k = 0; k < i; k++) {
|
|
1286
1193
|
sum -= A[i * size + k] * A[k * size + j];
|
|
1287
1194
|
}
|
|
1288
|
-
|
|
1289
1195
|
A[i * size + j] = sum;
|
|
1290
|
-
}
|
|
1196
|
+
}
|
|
1197
|
+
//
|
|
1291
1198
|
// Begin search for largest pivot element
|
|
1292
1199
|
//
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
1200
|
for (largest = 0.0, i = j; i < size; i++) {
|
|
1296
1201
|
sum = A[i * size + j];
|
|
1297
|
-
|
|
1298
1202
|
for (k = 0; k < j; k++) {
|
|
1299
1203
|
sum -= A[i * size + k] * A[k * size + j];
|
|
1300
1204
|
}
|
|
1301
|
-
|
|
1302
1205
|
A[i * size + j] = sum;
|
|
1303
|
-
|
|
1304
1206
|
if ((temp1 = scale[i] * Math.abs(sum)) >= largest) {
|
|
1305
1207
|
largest = temp1;
|
|
1306
1208
|
maxI = i;
|
|
1307
1209
|
}
|
|
1308
|
-
}
|
|
1210
|
+
}
|
|
1211
|
+
//
|
|
1309
1212
|
// Check for row interchange
|
|
1310
1213
|
//
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
1214
|
if (j !== maxI) {
|
|
1314
1215
|
for (k = 0; k < size; k++) {
|
|
1315
1216
|
temp1 = A[maxI * size + k];
|
|
1316
1217
|
A[maxI * size + k] = A[j * size + k];
|
|
1317
1218
|
A[j * size + k] = temp1;
|
|
1318
1219
|
}
|
|
1319
|
-
|
|
1320
1220
|
scale[maxI] = scale[j];
|
|
1321
|
-
}
|
|
1221
|
+
}
|
|
1222
|
+
//
|
|
1322
1223
|
// Divide by pivot element and perform elimination
|
|
1323
1224
|
//
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
1225
|
index[j] = maxI;
|
|
1327
|
-
|
|
1328
1226
|
if (Math.abs(A[j * size + j]) <= VTK_SMALL_NUMBER) {
|
|
1329
1227
|
vtkWarningMacro('Unable to factor linear system');
|
|
1330
1228
|
return 0;
|
|
1331
1229
|
}
|
|
1332
|
-
|
|
1333
1230
|
if (j !== size - 1) {
|
|
1334
1231
|
temp1 = 1.0 / A[j * size + j];
|
|
1335
|
-
|
|
1336
1232
|
for (i = j + 1; i < size; i++) {
|
|
1337
1233
|
A[i * size + j] *= temp1;
|
|
1338
1234
|
}
|
|
1339
1235
|
}
|
|
1340
1236
|
}
|
|
1341
|
-
|
|
1342
1237
|
return 1;
|
|
1343
1238
|
}
|
|
1344
1239
|
function luSolveLinearSystem(A, index, x, size) {
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1240
|
+
let i;
|
|
1241
|
+
let j;
|
|
1242
|
+
let ii;
|
|
1243
|
+
let idx;
|
|
1244
|
+
let sum;
|
|
1245
|
+
//
|
|
1350
1246
|
// Proceed with forward and backsubstitution for L and U
|
|
1351
1247
|
// matrices. First, forward substitution.
|
|
1352
1248
|
//
|
|
1353
|
-
|
|
1354
1249
|
for (ii = -1, i = 0; i < size; i++) {
|
|
1355
1250
|
idx = index[i];
|
|
1356
1251
|
sum = x[idx];
|
|
1357
1252
|
x[idx] = x[i];
|
|
1358
|
-
|
|
1359
1253
|
if (ii >= 0) {
|
|
1360
1254
|
for (j = ii; j <= i - 1; j++) {
|
|
1361
1255
|
sum -= A[i * size + j] * x[j];
|
|
@@ -1363,115 +1257,105 @@ function luSolveLinearSystem(A, index, x, size) {
|
|
|
1363
1257
|
} else if (sum !== 0.0) {
|
|
1364
1258
|
ii = i;
|
|
1365
1259
|
}
|
|
1366
|
-
|
|
1367
1260
|
x[i] = sum;
|
|
1368
|
-
}
|
|
1261
|
+
}
|
|
1262
|
+
//
|
|
1369
1263
|
// Now, back substitution
|
|
1370
1264
|
//
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
1265
|
for (i = size - 1; i >= 0; i--) {
|
|
1374
1266
|
sum = x[i];
|
|
1375
|
-
|
|
1376
1267
|
for (j = i + 1; j < size; j++) {
|
|
1377
1268
|
sum -= A[i * size + j] * x[j];
|
|
1378
1269
|
}
|
|
1379
|
-
|
|
1380
1270
|
x[i] = sum / A[i * size + i];
|
|
1381
1271
|
}
|
|
1382
1272
|
}
|
|
1383
1273
|
function solveLinearSystem(A, x, size) {
|
|
1384
1274
|
// if we solving something simple, just solve it
|
|
1385
1275
|
if (size === 2) {
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1276
|
+
const y = createArray(2);
|
|
1277
|
+
const det = determinant2x2(A[0], A[1], A[2], A[3]);
|
|
1389
1278
|
if (det === 0.0) {
|
|
1390
1279
|
// Unable to solve linear system
|
|
1391
1280
|
return 0;
|
|
1392
1281
|
}
|
|
1393
|
-
|
|
1394
1282
|
y[0] = (A[3] * x[0] - A[1] * x[1]) / det;
|
|
1395
1283
|
y[1] = (-(A[2] * x[0]) + A[0] * x[1]) / det;
|
|
1396
1284
|
x[0] = y[0];
|
|
1397
1285
|
x[1] = y[1];
|
|
1398
1286
|
return 1;
|
|
1399
1287
|
}
|
|
1400
|
-
|
|
1401
1288
|
if (size === 1) {
|
|
1402
1289
|
if (A[0] === 0.0) {
|
|
1403
1290
|
// Unable to solve linear system
|
|
1404
1291
|
return 0;
|
|
1405
1292
|
}
|
|
1406
|
-
|
|
1407
1293
|
x[0] /= A[0];
|
|
1408
1294
|
return 1;
|
|
1409
|
-
}
|
|
1295
|
+
}
|
|
1296
|
+
|
|
1297
|
+
//
|
|
1410
1298
|
// System of equations is not trivial, use Crout's method
|
|
1411
1299
|
//
|
|
1412
|
-
// Check on allocation of working vectors
|
|
1413
|
-
|
|
1414
1300
|
|
|
1415
|
-
|
|
1301
|
+
// Check on allocation of working vectors
|
|
1302
|
+
const index = createArray(size);
|
|
1416
1303
|
|
|
1304
|
+
// Factor and solve matrix
|
|
1417
1305
|
if (luFactorLinearSystem(A, index, size) === 0) {
|
|
1418
1306
|
return 0;
|
|
1419
1307
|
}
|
|
1420
|
-
|
|
1421
1308
|
luSolveLinearSystem(A, index, x, size);
|
|
1422
1309
|
return 1;
|
|
1423
|
-
}
|
|
1310
|
+
}
|
|
1424
1311
|
|
|
1312
|
+
// Note that A is modified during the inversion !
|
|
1425
1313
|
function invertMatrix(A, AI, size) {
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1314
|
+
let index = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null;
|
|
1315
|
+
let column = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : null;
|
|
1316
|
+
const tmp1Size = index || createArray(size);
|
|
1317
|
+
const tmp2Size = column || createArray(size);
|
|
1318
|
+
|
|
1319
|
+
// Factor matrix; then begin solving for inverse one column at a time.
|
|
1430
1320
|
// Note: tmp1Size returned value is used later, tmp2Size is just working
|
|
1431
1321
|
// memory whose values are not used in LUSolveLinearSystem
|
|
1432
|
-
|
|
1433
1322
|
if (luFactorLinearSystem(A, tmp1Size, size) === 0) {
|
|
1434
1323
|
return null;
|
|
1435
1324
|
}
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
for (var i = 0; i < size; i++) {
|
|
1325
|
+
for (let j = 0; j < size; j++) {
|
|
1326
|
+
for (let i = 0; i < size; i++) {
|
|
1439
1327
|
tmp2Size[i] = 0.0;
|
|
1440
1328
|
}
|
|
1441
|
-
|
|
1442
1329
|
tmp2Size[j] = 1.0;
|
|
1443
1330
|
luSolveLinearSystem(A, tmp1Size, tmp2Size, size);
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
AI[_i4 * size + j] = tmp2Size[_i4];
|
|
1331
|
+
for (let i = 0; i < size; i++) {
|
|
1332
|
+
AI[i * size + j] = tmp2Size[i];
|
|
1447
1333
|
}
|
|
1448
1334
|
}
|
|
1449
|
-
|
|
1450
1335
|
return AI;
|
|
1451
1336
|
}
|
|
1452
1337
|
function estimateMatrixCondition(A, size) {
|
|
1453
|
-
|
|
1454
|
-
|
|
1338
|
+
let minValue = +Number.MAX_VALUE;
|
|
1339
|
+
let maxValue = -Number.MAX_VALUE;
|
|
1455
1340
|
|
|
1456
|
-
|
|
1457
|
-
|
|
1341
|
+
// find the maximum value
|
|
1342
|
+
for (let i = 0; i < size; i++) {
|
|
1343
|
+
for (let j = i; j < size; j++) {
|
|
1458
1344
|
if (Math.abs(A[i * size + j]) > maxValue) {
|
|
1459
1345
|
maxValue = Math.abs(A[i * size + j]);
|
|
1460
1346
|
}
|
|
1461
1347
|
}
|
|
1462
|
-
}
|
|
1463
|
-
|
|
1348
|
+
}
|
|
1464
1349
|
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1350
|
+
// find the minimum diagonal value
|
|
1351
|
+
for (let i = 0; i < size; i++) {
|
|
1352
|
+
if (Math.abs(A[i * size + i]) < minValue) {
|
|
1353
|
+
minValue = Math.abs(A[i * size + i]);
|
|
1468
1354
|
}
|
|
1469
1355
|
}
|
|
1470
|
-
|
|
1471
1356
|
if (minValue === 0.0) {
|
|
1472
1357
|
return Number.MAX_VALUE;
|
|
1473
1358
|
}
|
|
1474
|
-
|
|
1475
1359
|
return maxValue / minValue;
|
|
1476
1360
|
}
|
|
1477
1361
|
function jacobi(a_3x3, w, v) {
|
|
@@ -1483,61 +1367,60 @@ function solveHomogeneousLeastSquares(numberOfSamples, xt, xOrder, mt) {
|
|
|
1483
1367
|
vtkWarningMacro('Insufficient number of samples. Underdetermined.');
|
|
1484
1368
|
return 0;
|
|
1485
1369
|
}
|
|
1370
|
+
let i;
|
|
1371
|
+
let j;
|
|
1372
|
+
let k;
|
|
1486
1373
|
|
|
1487
|
-
|
|
1488
|
-
var j;
|
|
1489
|
-
var k; // set up intermediate variables
|
|
1374
|
+
// set up intermediate variables
|
|
1490
1375
|
// Allocate matrix to hold X times transpose of X
|
|
1491
|
-
|
|
1492
|
-
var XXt = createArray(xOrder * xOrder); // size x by x
|
|
1376
|
+
const XXt = createArray(xOrder * xOrder); // size x by x
|
|
1493
1377
|
// Allocate the array of eigenvalues and eigenvectors
|
|
1378
|
+
const eigenvals = createArray(xOrder);
|
|
1379
|
+
const eigenvecs = createArray(xOrder * xOrder);
|
|
1494
1380
|
|
|
1495
|
-
|
|
1496
|
-
var eigenvecs = createArray(xOrder * xOrder); // Calculate XXt upper half only, due to symmetry
|
|
1497
|
-
|
|
1381
|
+
// Calculate XXt upper half only, due to symmetry
|
|
1498
1382
|
for (k = 0; k < numberOfSamples; k++) {
|
|
1499
1383
|
for (i = 0; i < xOrder; i++) {
|
|
1500
1384
|
for (j = i; j < xOrder; j++) {
|
|
1501
1385
|
XXt[i * xOrder + j] += xt[k * xOrder + i] * xt[k * xOrder + j];
|
|
1502
1386
|
}
|
|
1503
1387
|
}
|
|
1504
|
-
}
|
|
1505
|
-
|
|
1388
|
+
}
|
|
1506
1389
|
|
|
1390
|
+
// now fill in the lower half of the XXt matrix
|
|
1507
1391
|
for (i = 0; i < xOrder; i++) {
|
|
1508
1392
|
for (j = 0; j < i; j++) {
|
|
1509
1393
|
XXt[i * xOrder + j] = XXt[j * xOrder + i];
|
|
1510
1394
|
}
|
|
1511
|
-
}
|
|
1395
|
+
}
|
|
1512
1396
|
|
|
1397
|
+
// Compute the eigenvectors and eigenvalues
|
|
1398
|
+
jacobiN(XXt, xOrder, eigenvals, eigenvecs);
|
|
1513
1399
|
|
|
1514
|
-
|
|
1400
|
+
// Smallest eigenval is at the end of the list (xOrder-1), and solution is
|
|
1515
1401
|
// corresponding eigenvec.
|
|
1516
|
-
|
|
1517
1402
|
for (i = 0; i < xOrder; i++) {
|
|
1518
1403
|
mt[i] = eigenvecs[i * xOrder + xOrder - 1];
|
|
1519
1404
|
}
|
|
1520
|
-
|
|
1521
1405
|
return 1;
|
|
1522
1406
|
}
|
|
1523
1407
|
function solveLeastSquares(numberOfSamples, xt, xOrder, yt, yOrder, mt) {
|
|
1524
|
-
|
|
1525
|
-
|
|
1408
|
+
let checkHomogeneous = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : true;
|
|
1526
1409
|
// check dimensional consistency
|
|
1527
1410
|
if (numberOfSamples < xOrder || numberOfSamples < yOrder) {
|
|
1528
1411
|
vtkWarningMacro('Insufficient number of samples. Underdetermined.');
|
|
1529
1412
|
return 0;
|
|
1530
1413
|
}
|
|
1414
|
+
const homogenFlags = createArray(yOrder);
|
|
1415
|
+
let allHomogeneous = 1;
|
|
1416
|
+
let hmt;
|
|
1417
|
+
let homogRC = 0;
|
|
1418
|
+
let i;
|
|
1419
|
+
let j;
|
|
1420
|
+
let k;
|
|
1421
|
+
let someHomogeneous = 0;
|
|
1531
1422
|
|
|
1532
|
-
|
|
1533
|
-
var allHomogeneous = 1;
|
|
1534
|
-
var hmt;
|
|
1535
|
-
var homogRC = 0;
|
|
1536
|
-
var i;
|
|
1537
|
-
var j;
|
|
1538
|
-
var k;
|
|
1539
|
-
var someHomogeneous = 0; // Ok, first init some flags check and see if all the systems are homogeneous
|
|
1540
|
-
|
|
1423
|
+
// Ok, first init some flags check and see if all the systems are homogeneous
|
|
1541
1424
|
if (checkHomogeneous) {
|
|
1542
1425
|
// If Y' is zero, it's a homogeneous system and can't be solved via
|
|
1543
1426
|
// the pseudoinverse method. Detect this case, warn the user, and
|
|
@@ -1545,11 +1428,11 @@ function solveLeastSquares(numberOfSamples, xt, xOrder, yt, yOrder, mt) {
|
|
|
1545
1428
|
// really make much sense for yOrder to be greater than one in this case,
|
|
1546
1429
|
// since that's just yOrder occurrences of a 0 vector on the RHS, but
|
|
1547
1430
|
// we allow it anyway. N
|
|
1431
|
+
|
|
1548
1432
|
// Initialize homogeneous flags on a per-right-hand-side basis
|
|
1549
1433
|
for (j = 0; j < yOrder; j++) {
|
|
1550
1434
|
homogenFlags[j] = 1;
|
|
1551
1435
|
}
|
|
1552
|
-
|
|
1553
1436
|
for (i = 0; i < numberOfSamples; i++) {
|
|
1554
1437
|
for (j = 0; j < yOrder; j++) {
|
|
1555
1438
|
if (Math.abs(yt[i * yOrder + j]) > VTK_SMALL_NUMBER) {
|
|
@@ -1557,17 +1440,17 @@ function solveLeastSquares(numberOfSamples, xt, xOrder, yt, yOrder, mt) {
|
|
|
1557
1440
|
homogenFlags[j] = 0;
|
|
1558
1441
|
}
|
|
1559
1442
|
}
|
|
1560
|
-
}
|
|
1561
|
-
|
|
1443
|
+
}
|
|
1562
1444
|
|
|
1445
|
+
// If we've got one system, and it's homogeneous, do it and bail out quickly.
|
|
1563
1446
|
if (allHomogeneous && yOrder === 1) {
|
|
1564
1447
|
vtkWarningMacro('Detected homogeneous system (Y=0), calling SolveHomogeneousLeastSquares()');
|
|
1565
1448
|
return solveHomogeneousLeastSquares(numberOfSamples, xt, xOrder, mt);
|
|
1566
|
-
}
|
|
1449
|
+
}
|
|
1450
|
+
|
|
1451
|
+
// Ok, we've got more than one system of equations.
|
|
1567
1452
|
// Figure out if we need to calculate the homogeneous equation solution for
|
|
1568
1453
|
// any of them.
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
1454
|
if (allHomogeneous) {
|
|
1572
1455
|
someHomogeneous = 1;
|
|
1573
1456
|
} else {
|
|
@@ -1577,62 +1460,60 @@ function solveLeastSquares(numberOfSamples, xt, xOrder, yt, yOrder, mt) {
|
|
|
1577
1460
|
}
|
|
1578
1461
|
}
|
|
1579
1462
|
}
|
|
1580
|
-
}
|
|
1581
|
-
|
|
1463
|
+
}
|
|
1582
1464
|
|
|
1465
|
+
// If necessary, solve the homogeneous problem
|
|
1583
1466
|
if (someHomogeneous) {
|
|
1584
1467
|
// hmt is the homogeneous equation version of mt, the general solution.
|
|
1585
1468
|
// hmt should be xOrder x yOrder, but since we are solving only the homogeneous part, here it is xOrder x 1
|
|
1586
|
-
hmt = createArray(xOrder);
|
|
1469
|
+
hmt = createArray(xOrder);
|
|
1587
1470
|
|
|
1471
|
+
// Ok, solve the homogeneous problem
|
|
1588
1472
|
homogRC = solveHomogeneousLeastSquares(numberOfSamples, xt, xOrder, hmt);
|
|
1589
|
-
}
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
var XXt = createArray(xOrder * xOrder); // size x by x
|
|
1473
|
+
}
|
|
1593
1474
|
|
|
1594
|
-
|
|
1475
|
+
// set up intermediate variables
|
|
1476
|
+
const XXt = createArray(xOrder * xOrder); // size x by x
|
|
1477
|
+
const XXtI = createArray(xOrder * xOrder); // size x by x
|
|
1478
|
+
const XYt = createArray(xOrder * yOrder); // size x by y
|
|
1595
1479
|
|
|
1596
|
-
var XYt = createArray(xOrder * yOrder); // size x by y
|
|
1597
1480
|
// first find the pseudoinverse matrix
|
|
1598
|
-
|
|
1599
1481
|
for (k = 0; k < numberOfSamples; k++) {
|
|
1600
1482
|
for (i = 0; i < xOrder; i++) {
|
|
1601
1483
|
// first calculate the XXt matrix, only do the upper half (symmetrical)
|
|
1602
1484
|
for (j = i; j < xOrder; j++) {
|
|
1603
1485
|
XXt[i * xOrder + j] += xt[k * xOrder + i] * xt[k * xOrder + j];
|
|
1604
|
-
}
|
|
1605
|
-
|
|
1486
|
+
}
|
|
1606
1487
|
|
|
1488
|
+
// now calculate the XYt matrix
|
|
1607
1489
|
for (j = 0; j < yOrder; j++) {
|
|
1608
1490
|
XYt[i * yOrder + j] += xt[k * xOrder + i] * yt[k * yOrder + j];
|
|
1609
1491
|
}
|
|
1610
1492
|
}
|
|
1611
|
-
}
|
|
1612
|
-
|
|
1493
|
+
}
|
|
1613
1494
|
|
|
1495
|
+
// now fill in the lower half of the XXt matrix
|
|
1614
1496
|
for (i = 0; i < xOrder; i++) {
|
|
1615
1497
|
for (j = 0; j < i; j++) {
|
|
1616
1498
|
XXt[i * xOrder + j] = XXt[j * xOrder + i];
|
|
1617
1499
|
}
|
|
1618
1500
|
}
|
|
1501
|
+
const successFlag = invertMatrix(XXt, XXtI, xOrder);
|
|
1619
1502
|
|
|
1620
|
-
|
|
1621
|
-
|
|
1503
|
+
// next get the inverse of XXt
|
|
1622
1504
|
if (successFlag) {
|
|
1623
1505
|
for (i = 0; i < xOrder; i++) {
|
|
1624
1506
|
for (j = 0; j < yOrder; j++) {
|
|
1625
1507
|
mt[i * yOrder + j] = 0.0;
|
|
1626
|
-
|
|
1627
1508
|
for (k = 0; k < xOrder; k++) {
|
|
1628
1509
|
mt[i * yOrder + j] += XXtI[i * xOrder + k] * XYt[k * yOrder + j];
|
|
1629
1510
|
}
|
|
1630
1511
|
}
|
|
1631
1512
|
}
|
|
1632
|
-
}
|
|
1633
|
-
// problem.
|
|
1634
|
-
|
|
1513
|
+
}
|
|
1635
1514
|
|
|
1515
|
+
// Fix up any of the solutions that correspond to the homogeneous equation
|
|
1516
|
+
// problem.
|
|
1636
1517
|
if (someHomogeneous) {
|
|
1637
1518
|
for (j = 0; j < yOrder; j++) {
|
|
1638
1519
|
if (homogenFlags[j]) {
|
|
@@ -1643,16 +1524,13 @@ function solveLeastSquares(numberOfSamples, xt, xOrder, yt, yOrder, mt) {
|
|
|
1643
1524
|
}
|
|
1644
1525
|
}
|
|
1645
1526
|
}
|
|
1646
|
-
|
|
1647
1527
|
if (someHomogeneous) {
|
|
1648
1528
|
return homogRC && successFlag;
|
|
1649
1529
|
}
|
|
1650
|
-
|
|
1651
1530
|
return successFlag;
|
|
1652
1531
|
}
|
|
1653
1532
|
function hex2float(hexStr) {
|
|
1654
|
-
|
|
1655
|
-
|
|
1533
|
+
let outFloatArray = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [0, 0.5, 1];
|
|
1656
1534
|
switch (hexStr.length) {
|
|
1657
1535
|
case 3:
|
|
1658
1536
|
// abc => #aabbcc
|
|
@@ -1660,28 +1538,24 @@ function hex2float(hexStr) {
|
|
|
1660
1538
|
outFloatArray[1] = parseInt(hexStr[1], 16) * 17 / 255;
|
|
1661
1539
|
outFloatArray[2] = parseInt(hexStr[2], 16) * 17 / 255;
|
|
1662
1540
|
return outFloatArray;
|
|
1663
|
-
|
|
1664
1541
|
case 4:
|
|
1665
1542
|
// #abc => #aabbcc
|
|
1666
1543
|
outFloatArray[0] = parseInt(hexStr[1], 16) * 17 / 255;
|
|
1667
1544
|
outFloatArray[1] = parseInt(hexStr[2], 16) * 17 / 255;
|
|
1668
1545
|
outFloatArray[2] = parseInt(hexStr[3], 16) * 17 / 255;
|
|
1669
1546
|
return outFloatArray;
|
|
1670
|
-
|
|
1671
1547
|
case 6:
|
|
1672
1548
|
// ab01df => #ab01df
|
|
1673
1549
|
outFloatArray[0] = parseInt(hexStr.substr(0, 2), 16) / 255;
|
|
1674
1550
|
outFloatArray[1] = parseInt(hexStr.substr(2, 2), 16) / 255;
|
|
1675
1551
|
outFloatArray[2] = parseInt(hexStr.substr(4, 2), 16) / 255;
|
|
1676
1552
|
return outFloatArray;
|
|
1677
|
-
|
|
1678
1553
|
case 7:
|
|
1679
1554
|
// #ab01df
|
|
1680
1555
|
outFloatArray[0] = parseInt(hexStr.substr(1, 2), 16) / 255;
|
|
1681
1556
|
outFloatArray[1] = parseInt(hexStr.substr(3, 2), 16) / 255;
|
|
1682
1557
|
outFloatArray[2] = parseInt(hexStr.substr(5, 2), 16) / 255;
|
|
1683
1558
|
return outFloatArray;
|
|
1684
|
-
|
|
1685
1559
|
case 9:
|
|
1686
1560
|
// #ab01df00
|
|
1687
1561
|
outFloatArray[0] = parseInt(hexStr.substr(1, 2), 16) / 255;
|
|
@@ -1689,46 +1563,35 @@ function hex2float(hexStr) {
|
|
|
1689
1563
|
outFloatArray[2] = parseInt(hexStr.substr(5, 2), 16) / 255;
|
|
1690
1564
|
outFloatArray[3] = parseInt(hexStr.substr(7, 2), 16) / 255;
|
|
1691
1565
|
return outFloatArray;
|
|
1692
|
-
|
|
1693
1566
|
default:
|
|
1694
1567
|
return outFloatArray;
|
|
1695
1568
|
}
|
|
1696
1569
|
}
|
|
1697
1570
|
function rgb2hsv(rgb, hsv) {
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
var onethird = 1.0 / 3.0;
|
|
1707
|
-
var onesixth = 1.0 / 6.0;
|
|
1708
|
-
var twothird = 2.0 / 3.0;
|
|
1709
|
-
var cmax = r;
|
|
1710
|
-
var cmin = r;
|
|
1711
|
-
|
|
1571
|
+
let h;
|
|
1572
|
+
let s;
|
|
1573
|
+
const [r, g, b] = rgb;
|
|
1574
|
+
const onethird = 1.0 / 3.0;
|
|
1575
|
+
const onesixth = 1.0 / 6.0;
|
|
1576
|
+
const twothird = 2.0 / 3.0;
|
|
1577
|
+
let cmax = r;
|
|
1578
|
+
let cmin = r;
|
|
1712
1579
|
if (g > cmax) {
|
|
1713
1580
|
cmax = g;
|
|
1714
1581
|
} else if (g < cmin) {
|
|
1715
1582
|
cmin = g;
|
|
1716
1583
|
}
|
|
1717
|
-
|
|
1718
1584
|
if (b > cmax) {
|
|
1719
1585
|
cmax = b;
|
|
1720
1586
|
} else if (b < cmin) {
|
|
1721
1587
|
cmin = b;
|
|
1722
1588
|
}
|
|
1723
|
-
|
|
1724
|
-
var v = cmax;
|
|
1725
|
-
|
|
1589
|
+
const v = cmax;
|
|
1726
1590
|
if (v > 0.0) {
|
|
1727
1591
|
s = (cmax - cmin) / cmax;
|
|
1728
1592
|
} else {
|
|
1729
1593
|
s = 0.0;
|
|
1730
1594
|
}
|
|
1731
|
-
|
|
1732
1595
|
if (s > 0) {
|
|
1733
1596
|
if (r === cmax) {
|
|
1734
1597
|
h = onesixth * (g - b) / (cmax - cmin);
|
|
@@ -1737,33 +1600,29 @@ function rgb2hsv(rgb, hsv) {
|
|
|
1737
1600
|
} else {
|
|
1738
1601
|
h = twothird + onesixth * (r - g) / (cmax - cmin);
|
|
1739
1602
|
}
|
|
1740
|
-
|
|
1741
1603
|
if (h < 0.0) {
|
|
1742
1604
|
h += 1.0;
|
|
1743
1605
|
}
|
|
1744
1606
|
} else {
|
|
1745
1607
|
h = 0.0;
|
|
1746
|
-
}
|
|
1747
|
-
|
|
1608
|
+
}
|
|
1748
1609
|
|
|
1610
|
+
// Set the values back to the array
|
|
1749
1611
|
hsv[0] = h;
|
|
1750
1612
|
hsv[1] = s;
|
|
1751
1613
|
hsv[2] = v;
|
|
1752
1614
|
}
|
|
1753
1615
|
function hsv2rgb(hsv, rgb) {
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
var g;
|
|
1765
|
-
var b; // compute RGB from HSV
|
|
1766
|
-
|
|
1616
|
+
const [h, s, v] = hsv;
|
|
1617
|
+
const onethird = 1.0 / 3.0;
|
|
1618
|
+
const onesixth = 1.0 / 6.0;
|
|
1619
|
+
const twothird = 2.0 / 3.0;
|
|
1620
|
+
const fivesixth = 5.0 / 6.0;
|
|
1621
|
+
let r;
|
|
1622
|
+
let g;
|
|
1623
|
+
let b;
|
|
1624
|
+
|
|
1625
|
+
// compute RGB from HSV
|
|
1767
1626
|
if (h > onesixth && h <= onethird) {
|
|
1768
1627
|
// green/red
|
|
1769
1628
|
g = 1.0;
|
|
@@ -1794,89 +1653,73 @@ function hsv2rgb(hsv, rgb) {
|
|
|
1794
1653
|
r = 1.0;
|
|
1795
1654
|
g = h / onesixth;
|
|
1796
1655
|
b = 0.0;
|
|
1797
|
-
}
|
|
1798
|
-
|
|
1656
|
+
}
|
|
1799
1657
|
|
|
1658
|
+
// add Saturation to the equation.
|
|
1800
1659
|
r = s * r + (1.0 - s);
|
|
1801
1660
|
g = s * g + (1.0 - s);
|
|
1802
1661
|
b = s * b + (1.0 - s);
|
|
1803
1662
|
r *= v;
|
|
1804
1663
|
g *= v;
|
|
1805
|
-
b *= v;
|
|
1664
|
+
b *= v;
|
|
1806
1665
|
|
|
1666
|
+
// Assign back to the array
|
|
1807
1667
|
rgb[0] = r;
|
|
1808
1668
|
rgb[1] = g;
|
|
1809
1669
|
rgb[2] = b;
|
|
1810
1670
|
}
|
|
1811
1671
|
function lab2xyz(lab, xyz) {
|
|
1812
1672
|
// LAB to XYZ
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
var var_X = a / 500 + var_Y;
|
|
1820
|
-
var var_Z = var_Y - b / 200;
|
|
1821
|
-
|
|
1822
|
-
if (Math.pow(var_Y, 3) > 0.008856) {
|
|
1823
|
-
var_Y = Math.pow(var_Y, 3);
|
|
1673
|
+
const [L, a, b] = lab;
|
|
1674
|
+
let var_Y = (L + 16) / 116;
|
|
1675
|
+
let var_X = a / 500 + var_Y;
|
|
1676
|
+
let var_Z = var_Y - b / 200;
|
|
1677
|
+
if (var_Y ** 3 > 0.008856) {
|
|
1678
|
+
var_Y **= 3;
|
|
1824
1679
|
} else {
|
|
1825
1680
|
var_Y = (var_Y - 16.0 / 116.0) / 7.787;
|
|
1826
1681
|
}
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
var_X = Math.pow(var_X, 3);
|
|
1682
|
+
if (var_X ** 3 > 0.008856) {
|
|
1683
|
+
var_X **= 3;
|
|
1830
1684
|
} else {
|
|
1831
1685
|
var_X = (var_X - 16.0 / 116.0) / 7.787;
|
|
1832
1686
|
}
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
var_Z = Math.pow(var_Z, 3);
|
|
1687
|
+
if (var_Z ** 3 > 0.008856) {
|
|
1688
|
+
var_Z **= 3;
|
|
1836
1689
|
} else {
|
|
1837
1690
|
var_Z = (var_Z - 16.0 / 116.0) / 7.787;
|
|
1838
1691
|
}
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
var ref_Z = 1.089;
|
|
1692
|
+
const ref_X = 0.9505;
|
|
1693
|
+
const ref_Y = 1.0;
|
|
1694
|
+
const ref_Z = 1.089;
|
|
1843
1695
|
xyz[0] = ref_X * var_X; // ref_X = 0.9505 Observer= 2 deg Illuminant= D65
|
|
1844
|
-
|
|
1845
1696
|
xyz[1] = ref_Y * var_Y; // ref_Y = 1.000
|
|
1846
|
-
|
|
1847
1697
|
xyz[2] = ref_Z * var_Z; // ref_Z = 1.089
|
|
1848
1698
|
}
|
|
1849
|
-
function xyz2lab(xyz, lab) {
|
|
1850
|
-
var _xyz = _slicedToArray(xyz, 3),
|
|
1851
|
-
x = _xyz[0],
|
|
1852
|
-
y = _xyz[1],
|
|
1853
|
-
z = _xyz[2];
|
|
1854
1699
|
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
if (var_X > 0.008856) var_X
|
|
1865
|
-
if (var_Y > 0.008856) var_Y
|
|
1866
|
-
if (var_Z > 0.008856) var_Z
|
|
1700
|
+
function xyz2lab(xyz, lab) {
|
|
1701
|
+
const [x, y, z] = xyz;
|
|
1702
|
+
const ref_X = 0.9505;
|
|
1703
|
+
const ref_Y = 1.0;
|
|
1704
|
+
const ref_Z = 1.089;
|
|
1705
|
+
let var_X = x / ref_X; // ref_X = 0.9505 Observer= 2 deg, Illuminant= D65
|
|
1706
|
+
let var_Y = y / ref_Y; // ref_Y = 1.000
|
|
1707
|
+
let var_Z = z / ref_Z; // ref_Z = 1.089
|
|
1708
|
+
|
|
1709
|
+
if (var_X > 0.008856) var_X **= 1.0 / 3.0;else var_X = 7.787 * var_X + 16.0 / 116.0;
|
|
1710
|
+
if (var_Y > 0.008856) var_Y **= 1.0 / 3.0;else var_Y = 7.787 * var_Y + 16.0 / 116.0;
|
|
1711
|
+
if (var_Z > 0.008856) var_Z **= 1.0 / 3.0;else var_Z = 7.787 * var_Z + 16.0 / 116.0;
|
|
1867
1712
|
lab[0] = 116 * var_Y - 16;
|
|
1868
1713
|
lab[1] = 500 * (var_X - var_Y);
|
|
1869
1714
|
lab[2] = 200 * (var_Y - var_Z);
|
|
1870
1715
|
}
|
|
1871
1716
|
function xyz2rgb(xyz, rgb) {
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
|
|
1878
|
-
var g = x * -0.9689 + y * 1.8758 + z * 0.0415;
|
|
1879
|
-
var b = x * 0.0557 + y * -0.204 + z * 1.057; // The following performs a "gamma correction" specified by the sRGB color
|
|
1717
|
+
const [x, y, z] = xyz;
|
|
1718
|
+
let r = x * 3.2406 + y * -1.5372 + z * -0.4986;
|
|
1719
|
+
let g = x * -0.9689 + y * 1.8758 + z * 0.0415;
|
|
1720
|
+
let b = x * 0.0557 + y * -0.204 + z * 1.057;
|
|
1721
|
+
|
|
1722
|
+
// The following performs a "gamma correction" specified by the sRGB color
|
|
1880
1723
|
// space. sRGB is defined by a canonical definition of a display monitor and
|
|
1881
1724
|
// has been standardized by the International Electrotechnical Commission (IEC
|
|
1882
1725
|
// 61966-2-1). The nonlinearity of the correction is designed to make the
|
|
@@ -1884,36 +1727,33 @@ function xyz2rgb(xyz, rgb) {
|
|
|
1884
1727
|
// several applications including Adobe Photoshop and Microsoft Windows color
|
|
1885
1728
|
// management. OpenGL is agnostic on its RGB color space, but it is reasonable
|
|
1886
1729
|
// to assume it is close to this one.
|
|
1730
|
+
if (r > 0.0031308) r = 1.055 * r ** (1 / 2.4) - 0.055;else r *= 12.92;
|
|
1731
|
+
if (g > 0.0031308) g = 1.055 * g ** (1 / 2.4) - 0.055;else g *= 12.92;
|
|
1732
|
+
if (b > 0.0031308) b = 1.055 * b ** (1 / 2.4) - 0.055;else b *= 12.92;
|
|
1887
1733
|
|
|
1888
|
-
|
|
1889
|
-
if (g > 0.0031308) g = 1.055 * Math.pow(g, 1 / 2.4) - 0.055;else g *= 12.92;
|
|
1890
|
-
if (b > 0.0031308) b = 1.055 * Math.pow(b, 1 / 2.4) - 0.055;else b *= 12.92; // Clip colors. ideally we would do something that is perceptually closest
|
|
1734
|
+
// Clip colors. ideally we would do something that is perceptually closest
|
|
1891
1735
|
// (since we can see colors outside of the display gamut), but this seems to
|
|
1892
1736
|
// work well enough.
|
|
1893
|
-
|
|
1894
|
-
var maxVal = r;
|
|
1737
|
+
let maxVal = r;
|
|
1895
1738
|
if (maxVal < g) maxVal = g;
|
|
1896
1739
|
if (maxVal < b) maxVal = b;
|
|
1897
|
-
|
|
1898
1740
|
if (maxVal > 1.0) {
|
|
1899
1741
|
r /= maxVal;
|
|
1900
1742
|
g /= maxVal;
|
|
1901
1743
|
b /= maxVal;
|
|
1902
1744
|
}
|
|
1903
|
-
|
|
1904
1745
|
if (r < 0) r = 0;
|
|
1905
1746
|
if (g < 0) g = 0;
|
|
1906
|
-
if (b < 0) b = 0;
|
|
1747
|
+
if (b < 0) b = 0;
|
|
1907
1748
|
|
|
1749
|
+
// Push values back to array
|
|
1908
1750
|
rgb[0] = r;
|
|
1909
1751
|
rgb[1] = g;
|
|
1910
1752
|
rgb[2] = b;
|
|
1911
1753
|
}
|
|
1912
1754
|
function rgb2xyz(rgb, xyz) {
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
g = _rgb2[1],
|
|
1916
|
-
b = _rgb2[2]; // The following performs a "gamma correction" specified by the sRGB color
|
|
1755
|
+
let [r, g, b] = rgb;
|
|
1756
|
+
// The following performs a "gamma correction" specified by the sRGB color
|
|
1917
1757
|
// space. sRGB is defined by a canonical definition of a display monitor and
|
|
1918
1758
|
// has been standardized by the International Electrotechnical Commission (IEC
|
|
1919
1759
|
// 61966-2-1). The nonlinearity of the correction is designed to make the
|
|
@@ -1921,23 +1761,22 @@ function rgb2xyz(rgb, xyz) {
|
|
|
1921
1761
|
// several applications including Adobe Photoshop and Microsoft Windows color
|
|
1922
1762
|
// management. OpenGL is agnostic on its RGB color space, but it is reasonable
|
|
1923
1763
|
// to assume it is close to this one.
|
|
1764
|
+
if (r > 0.04045) r = ((r + 0.055) / 1.055) ** 2.4;else r /= 12.92;
|
|
1765
|
+
if (g > 0.04045) g = ((g + 0.055) / 1.055) ** 2.4;else g /= 12.92;
|
|
1766
|
+
if (b > 0.04045) b = ((b + 0.055) / 1.055) ** 2.4;else b /= 12.92;
|
|
1924
1767
|
|
|
1925
|
-
|
|
1926
|
-
if (r > 0.04045) r = Math.pow((r + 0.055) / 1.055, 2.4);else r /= 12.92;
|
|
1927
|
-
if (g > 0.04045) g = Math.pow((g + 0.055) / 1.055, 2.4);else g /= 12.92;
|
|
1928
|
-
if (b > 0.04045) b = Math.pow((b + 0.055) / 1.055, 2.4);else b /= 12.92; // Observer. = 2 deg, Illuminant = D65
|
|
1929
|
-
|
|
1768
|
+
// Observer. = 2 deg, Illuminant = D65
|
|
1930
1769
|
xyz[0] = r * 0.4124 + g * 0.3576 + b * 0.1805;
|
|
1931
1770
|
xyz[1] = r * 0.2126 + g * 0.7152 + b * 0.0722;
|
|
1932
1771
|
xyz[2] = r * 0.0193 + g * 0.1192 + b * 0.9505;
|
|
1933
1772
|
}
|
|
1934
1773
|
function rgb2lab(rgb, lab) {
|
|
1935
|
-
|
|
1774
|
+
const xyz = [0, 0, 0];
|
|
1936
1775
|
rgb2xyz(rgb, xyz);
|
|
1937
1776
|
xyz2lab(xyz, lab);
|
|
1938
1777
|
}
|
|
1939
1778
|
function lab2rgb(lab, rgb) {
|
|
1940
|
-
|
|
1779
|
+
const xyz = [0, 0, 0];
|
|
1941
1780
|
lab2xyz(lab, xyz);
|
|
1942
1781
|
xyz2rgb(xyz, rgb);
|
|
1943
1782
|
}
|
|
@@ -1953,10 +1792,10 @@ function uninitializeBounds(bounds) {
|
|
|
1953
1792
|
function areBoundsInitialized(bounds) {
|
|
1954
1793
|
return !(bounds[1] - bounds[0] < 0.0);
|
|
1955
1794
|
}
|
|
1795
|
+
|
|
1956
1796
|
/**
|
|
1957
1797
|
* @deprecated please use vtkBoundingBox.addPoints(vtkBoundingBox.reset([]), points)
|
|
1958
1798
|
*/
|
|
1959
|
-
|
|
1960
1799
|
function computeBoundsFromPoints(point1, point2, bounds) {
|
|
1961
1800
|
bounds[0] = Math.min(point1[0], point2[0]);
|
|
1962
1801
|
bounds[1] = Math.max(point1[0], point2[0]);
|
|
@@ -1970,23 +1809,20 @@ function clampValue(value, minValue, maxValue) {
|
|
|
1970
1809
|
if (value < minValue) {
|
|
1971
1810
|
return minValue;
|
|
1972
1811
|
}
|
|
1973
|
-
|
|
1974
1812
|
if (value > maxValue) {
|
|
1975
1813
|
return maxValue;
|
|
1976
1814
|
}
|
|
1977
|
-
|
|
1978
1815
|
return value;
|
|
1979
1816
|
}
|
|
1980
1817
|
function clampVector(vector, minVector, maxVector) {
|
|
1981
|
-
|
|
1818
|
+
let out = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : [0, 0, 0];
|
|
1982
1819
|
out[0] = clampValue(vector[0], minVector[0], maxVector[0]);
|
|
1983
1820
|
out[1] = clampValue(vector[1], minVector[1], maxVector[1]);
|
|
1984
1821
|
out[2] = clampValue(vector[2], minVector[2], maxVector[2]);
|
|
1985
1822
|
return out;
|
|
1986
1823
|
}
|
|
1987
1824
|
function clampAndNormalizeValue(value, range) {
|
|
1988
|
-
|
|
1989
|
-
|
|
1825
|
+
let result = 0;
|
|
1990
1826
|
if (range[0] !== range[1]) {
|
|
1991
1827
|
// clamp
|
|
1992
1828
|
if (value < range[0]) {
|
|
@@ -1995,64 +1831,55 @@ function clampAndNormalizeValue(value, range) {
|
|
|
1995
1831
|
result = range[1];
|
|
1996
1832
|
} else {
|
|
1997
1833
|
result = value;
|
|
1998
|
-
}
|
|
1999
|
-
|
|
2000
|
-
|
|
1834
|
+
}
|
|
1835
|
+
// normalize
|
|
2001
1836
|
result = (result - range[0]) / (range[1] - range[0]);
|
|
2002
1837
|
}
|
|
2003
|
-
|
|
2004
1838
|
return result;
|
|
2005
1839
|
}
|
|
2006
|
-
|
|
2007
|
-
|
|
1840
|
+
const getScalarTypeFittingRange = notImplemented('GetScalarTypeFittingRange');
|
|
1841
|
+
const getAdjustedScalarRange = notImplemented('GetAdjustedScalarRange');
|
|
2008
1842
|
function extentIsWithinOtherExtent(extent1, extent2) {
|
|
2009
1843
|
if (!extent1 || !extent2) {
|
|
2010
1844
|
return 0;
|
|
2011
1845
|
}
|
|
2012
|
-
|
|
2013
|
-
for (var i = 0; i < 6; i += 2) {
|
|
1846
|
+
for (let i = 0; i < 6; i += 2) {
|
|
2014
1847
|
if (extent1[i] < extent2[i] || extent1[i] > extent2[i + 1] || extent1[i + 1] < extent2[i] || extent1[i + 1] > extent2[i + 1]) {
|
|
2015
1848
|
return 0;
|
|
2016
1849
|
}
|
|
2017
1850
|
}
|
|
2018
|
-
|
|
2019
1851
|
return 1;
|
|
2020
1852
|
}
|
|
2021
1853
|
function boundsIsWithinOtherBounds(bounds1_6, bounds2_6, delta_3) {
|
|
2022
1854
|
if (!bounds1_6 || !bounds2_6) {
|
|
2023
1855
|
return 0;
|
|
2024
1856
|
}
|
|
2025
|
-
|
|
2026
|
-
for (var i = 0; i < 6; i += 2) {
|
|
1857
|
+
for (let i = 0; i < 6; i += 2) {
|
|
2027
1858
|
if (bounds1_6[i] + delta_3[i / 2] < bounds2_6[i] || bounds1_6[i] - delta_3[i / 2] > bounds2_6[i + 1] || bounds1_6[i + 1] + delta_3[i / 2] < bounds2_6[i] || bounds1_6[i + 1] - delta_3[i / 2] > bounds2_6[i + 1]) {
|
|
2028
1859
|
return 0;
|
|
2029
1860
|
}
|
|
2030
1861
|
}
|
|
2031
|
-
|
|
2032
1862
|
return 1;
|
|
2033
1863
|
}
|
|
2034
1864
|
function pointIsWithinBounds(point_3, bounds_6, delta_3) {
|
|
2035
1865
|
if (!point_3 || !bounds_6 || !delta_3) {
|
|
2036
1866
|
return 0;
|
|
2037
1867
|
}
|
|
2038
|
-
|
|
2039
|
-
for (var i = 0; i < 3; i++) {
|
|
1868
|
+
for (let i = 0; i < 3; i++) {
|
|
2040
1869
|
if (point_3[i] + delta_3[i] < bounds_6[2 * i] || point_3[i] - delta_3[i] > bounds_6[2 * i + 1]) {
|
|
2041
1870
|
return 0;
|
|
2042
1871
|
}
|
|
2043
1872
|
}
|
|
2044
|
-
|
|
2045
1873
|
return 1;
|
|
2046
1874
|
}
|
|
2047
1875
|
function solve3PointCircle(p1, p2, p3, center) {
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
|
|
2055
|
-
for (var i = 0; i < 3; ++i) {
|
|
1876
|
+
const v21 = createArray(3);
|
|
1877
|
+
const v32 = createArray(3);
|
|
1878
|
+
const v13 = createArray(3);
|
|
1879
|
+
const v12 = createArray(3);
|
|
1880
|
+
const v23 = createArray(3);
|
|
1881
|
+
const v31 = createArray(3);
|
|
1882
|
+
for (let i = 0; i < 3; ++i) {
|
|
2056
1883
|
v21[i] = p1[i] - p2[i];
|
|
2057
1884
|
v32[i] = p2[i] - p3[i];
|
|
2058
1885
|
v13[i] = p3[i] - p1[i];
|
|
@@ -2060,256 +1887,241 @@ function solve3PointCircle(p1, p2, p3, center) {
|
|
|
2060
1887
|
v23[i] = -v32[i];
|
|
2061
1888
|
v31[i] = -v13[i];
|
|
2062
1889
|
}
|
|
2063
|
-
|
|
2064
|
-
|
|
2065
|
-
|
|
2066
|
-
|
|
2067
|
-
var crossv21v32 = createArray(3);
|
|
1890
|
+
const norm12 = norm(v12);
|
|
1891
|
+
const norm23 = norm(v23);
|
|
1892
|
+
const norm13 = norm(v13);
|
|
1893
|
+
const crossv21v32 = createArray(3);
|
|
2068
1894
|
cross(v21, v32, crossv21v32);
|
|
2069
|
-
|
|
2070
|
-
|
|
2071
|
-
|
|
2072
|
-
|
|
2073
|
-
|
|
2074
|
-
|
|
2075
|
-
|
|
2076
|
-
|
|
2077
|
-
center[_i6] = alpha * p1[_i6] + beta * p2[_i6] + gamma * p3[_i6];
|
|
1895
|
+
const normCross = norm(crossv21v32);
|
|
1896
|
+
const radius = norm12 * norm23 * norm13 / (2 * normCross);
|
|
1897
|
+
const normCross22 = 2 * normCross * normCross;
|
|
1898
|
+
const alpha = norm23 * norm23 * dot(v21, v31) / normCross22;
|
|
1899
|
+
const beta = norm13 * norm13 * dot(v12, v32) / normCross22;
|
|
1900
|
+
const gamma = norm12 * norm12 * dot(v13, v23) / normCross22;
|
|
1901
|
+
for (let i = 0; i < 3; ++i) {
|
|
1902
|
+
center[i] = alpha * p1[i] + beta * p2[i] + gamma * p3[i];
|
|
2078
1903
|
}
|
|
2079
|
-
|
|
2080
1904
|
return radius;
|
|
2081
1905
|
}
|
|
2082
|
-
|
|
2083
|
-
|
|
2084
|
-
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
|
|
2089
|
-
|
|
1906
|
+
const inf = Infinity;
|
|
1907
|
+
const negInf = -Infinity;
|
|
1908
|
+
const isInf = value => !Number.isFinite(value);
|
|
1909
|
+
const {
|
|
1910
|
+
isFinite,
|
|
1911
|
+
isNaN
|
|
1912
|
+
} = Number;
|
|
1913
|
+
const isNan = isNaN;
|
|
1914
|
+
|
|
1915
|
+
// JavaScript - add-on ----------------------
|
|
2090
1916
|
|
|
2091
1917
|
function createUninitializedBounds() {
|
|
2092
|
-
return [].concat([Number.MAX_VALUE, -Number.MAX_VALUE,
|
|
2093
|
-
|
|
1918
|
+
return [].concat([Number.MAX_VALUE, -Number.MAX_VALUE,
|
|
1919
|
+
// X
|
|
1920
|
+
Number.MAX_VALUE, -Number.MAX_VALUE,
|
|
1921
|
+
// Y
|
|
2094
1922
|
Number.MAX_VALUE, -Number.MAX_VALUE // Z
|
|
2095
1923
|
]);
|
|
2096
1924
|
}
|
|
2097
|
-
function getMajorAxisIndex(vector) {
|
|
2098
|
-
var maxValue = -1;
|
|
2099
|
-
var axisIndex = -1;
|
|
2100
|
-
|
|
2101
|
-
for (var i = 0; i < vector.length; i++) {
|
|
2102
|
-
var value = Math.abs(vector[i]);
|
|
2103
1925
|
|
|
1926
|
+
function getMajorAxisIndex(vector) {
|
|
1927
|
+
let maxValue = -1;
|
|
1928
|
+
let axisIndex = -1;
|
|
1929
|
+
for (let i = 0; i < vector.length; i++) {
|
|
1930
|
+
const value = Math.abs(vector[i]);
|
|
2104
1931
|
if (value > maxValue) {
|
|
2105
1932
|
axisIndex = i;
|
|
2106
1933
|
maxValue = value;
|
|
2107
1934
|
}
|
|
2108
1935
|
}
|
|
2109
|
-
|
|
2110
1936
|
return axisIndex;
|
|
2111
|
-
}
|
|
1937
|
+
}
|
|
1938
|
+
|
|
1939
|
+
// Return the closest orthogonal matrix of 1, -1 and 0
|
|
2112
1940
|
// It works for both column major and row major matrices
|
|
2113
1941
|
// This function iteratively associate a column with a row by choosing
|
|
2114
1942
|
// the greatest absolute value from the remaining row and columns
|
|
2115
1943
|
// For each association, a -1 or a 1 is set in the output, depending on
|
|
2116
1944
|
// the sign of the value in the original matrix
|
|
2117
|
-
|
|
2118
1945
|
function getSparseOrthogonalMatrix(matrix) {
|
|
2119
|
-
|
|
1946
|
+
let n = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 3;
|
|
2120
1947
|
// Initialize rows and columns to available indices
|
|
2121
|
-
|
|
2122
|
-
|
|
2123
|
-
|
|
2124
|
-
for (var i = 0; i < n; ++i) {
|
|
1948
|
+
const rows = new Array(n);
|
|
1949
|
+
const cols = new Array(n);
|
|
1950
|
+
for (let i = 0; i < n; ++i) {
|
|
2125
1951
|
rows[i] = i;
|
|
2126
1952
|
cols[i] = i;
|
|
2127
|
-
}
|
|
2128
|
-
|
|
2129
|
-
|
|
2130
|
-
for (var _i7 = n - 1; _i7 > 0; _i7--) {
|
|
1953
|
+
}
|
|
1954
|
+
// No need for the last iteration: i = 0
|
|
1955
|
+
for (let i = n - 1; i > 0; i--) {
|
|
2131
1956
|
// Loop invariant:
|
|
2132
1957
|
// rows[0:i] and cols[0:i] contain the remaining rows and columns
|
|
2133
1958
|
// rows]i:n[ and cols]i:n[ contain the associations found (rows[k] is associated with cols[k])
|
|
2134
|
-
|
|
2135
|
-
|
|
2136
|
-
|
|
2137
|
-
|
|
2138
|
-
|
|
2139
|
-
|
|
2140
|
-
|
|
2141
|
-
|
|
2142
|
-
var col = cols[colI];
|
|
2143
|
-
var absVal = Math.abs(matrix[row + n * col]);
|
|
2144
|
-
|
|
1959
|
+
let bestValue = -Infinity;
|
|
1960
|
+
let bestRowI = 0;
|
|
1961
|
+
let bestColI = 0;
|
|
1962
|
+
for (let rowI = 0; rowI <= i; ++rowI) {
|
|
1963
|
+
const row = rows[rowI];
|
|
1964
|
+
for (let colI = 0; colI <= i; ++colI) {
|
|
1965
|
+
const col = cols[colI];
|
|
1966
|
+
const absVal = Math.abs(matrix[row + n * col]);
|
|
2145
1967
|
if (absVal > bestValue) {
|
|
2146
1968
|
bestValue = absVal;
|
|
2147
1969
|
bestRowI = rowI;
|
|
2148
1970
|
bestColI = colI;
|
|
2149
1971
|
}
|
|
2150
1972
|
}
|
|
2151
|
-
}
|
|
1973
|
+
}
|
|
1974
|
+
// Found an association between rows[bestRowI] and cols[bestColI]
|
|
2152
1975
|
// Put both at the end of their array by swapping with i
|
|
1976
|
+
[rows[i], rows[bestRowI]] = [rows[bestRowI], rows[i]];
|
|
1977
|
+
[cols[i], cols[bestColI]] = [cols[bestColI], cols[i]];
|
|
1978
|
+
}
|
|
2153
1979
|
|
|
2154
|
-
|
|
2155
|
-
|
|
2156
|
-
|
|
2157
|
-
rows[
|
|
2158
|
-
var _ref2 = [cols[bestColI], cols[_i7]];
|
|
2159
|
-
cols[_i7] = _ref2[0];
|
|
2160
|
-
cols[bestColI] = _ref2[1];
|
|
2161
|
-
} // Convert row/column association to a matrix
|
|
2162
|
-
|
|
2163
|
-
|
|
2164
|
-
var output = new Array(n * n).fill(0);
|
|
2165
|
-
|
|
2166
|
-
for (var _i8 = 0; _i8 < n; ++_i8) {
|
|
2167
|
-
var matIdx = rows[_i8] + n * cols[_i8];
|
|
1980
|
+
// Convert row/column association to a matrix
|
|
1981
|
+
const output = new Array(n * n).fill(0);
|
|
1982
|
+
for (let i = 0; i < n; ++i) {
|
|
1983
|
+
const matIdx = rows[i] + n * cols[i];
|
|
2168
1984
|
output[matIdx] = matrix[matIdx] < 0 ? -1 : 1;
|
|
2169
1985
|
}
|
|
2170
|
-
|
|
2171
1986
|
return output;
|
|
2172
1987
|
}
|
|
2173
1988
|
function floatToHex2(value) {
|
|
2174
|
-
|
|
2175
|
-
|
|
1989
|
+
const integer = Math.floor(value * 255);
|
|
2176
1990
|
if (integer > 15) {
|
|
2177
1991
|
return integer.toString(16);
|
|
2178
1992
|
}
|
|
2179
|
-
|
|
2180
|
-
return "0".concat(integer.toString(16));
|
|
1993
|
+
return `0${integer.toString(16)}`;
|
|
2181
1994
|
}
|
|
2182
1995
|
function floatRGB2HexCode(rgbArray) {
|
|
2183
|
-
|
|
2184
|
-
return
|
|
1996
|
+
let prefix = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '#';
|
|
1997
|
+
return `${prefix}${rgbArray.map(floatToHex2).join('')}`;
|
|
2185
1998
|
}
|
|
2186
|
-
|
|
2187
1999
|
function floatToChar(f) {
|
|
2188
2000
|
return Math.round(f * 255);
|
|
2189
2001
|
}
|
|
2190
|
-
|
|
2191
2002
|
function float2CssRGBA(rgbArray) {
|
|
2192
2003
|
if (rgbArray.length === 3) {
|
|
2193
|
-
return
|
|
2004
|
+
return `rgb(${rgbArray.map(floatToChar).join(', ')})`;
|
|
2194
2005
|
}
|
|
2006
|
+
return `rgba(${floatToChar(rgbArray[0] || 0)}, ${floatToChar(rgbArray[1] || 0)}, ${floatToChar(rgbArray[2] || 0)}, ${rgbArray[3] || 0})`;
|
|
2007
|
+
}
|
|
2195
2008
|
|
|
2196
|
-
|
|
2197
|
-
} // ----------------------------------------------------------------------------
|
|
2009
|
+
// ----------------------------------------------------------------------------
|
|
2198
2010
|
// Only Static API
|
|
2199
2011
|
// ----------------------------------------------------------------------------
|
|
2200
2012
|
|
|
2201
2013
|
var vtkMath = {
|
|
2202
|
-
Pi
|
|
2203
|
-
radiansFromDegrees
|
|
2204
|
-
degreesFromRadians
|
|
2205
|
-
round
|
|
2206
|
-
floor
|
|
2207
|
-
ceil
|
|
2208
|
-
ceilLog2
|
|
2209
|
-
min
|
|
2210
|
-
max
|
|
2211
|
-
arrayMin
|
|
2212
|
-
arrayMax
|
|
2213
|
-
arrayRange
|
|
2214
|
-
isPowerOfTwo
|
|
2215
|
-
nearestPowerOfTwo
|
|
2216
|
-
factorial
|
|
2217
|
-
binomial
|
|
2218
|
-
beginCombination
|
|
2219
|
-
nextCombination
|
|
2220
|
-
randomSeed
|
|
2221
|
-
getSeed
|
|
2222
|
-
random
|
|
2223
|
-
gaussian
|
|
2224
|
-
add
|
|
2225
|
-
subtract
|
|
2226
|
-
multiplyScalar
|
|
2227
|
-
multiplyScalar2D
|
|
2228
|
-
multiplyAccumulate
|
|
2229
|
-
multiplyAccumulate2D
|
|
2230
|
-
dot
|
|
2231
|
-
outer
|
|
2232
|
-
cross
|
|
2233
|
-
norm
|
|
2234
|
-
normalize
|
|
2235
|
-
perpendiculars
|
|
2236
|
-
projectVector
|
|
2237
|
-
projectVector2D
|
|
2238
|
-
distance2BetweenPoints
|
|
2239
|
-
angleBetweenVectors
|
|
2240
|
-
gaussianAmplitude
|
|
2241
|
-
gaussianWeight
|
|
2242
|
-
dot2D
|
|
2243
|
-
outer2D
|
|
2244
|
-
norm2D
|
|
2245
|
-
normalize2D
|
|
2246
|
-
determinant2x2
|
|
2247
|
-
LUFactor3x3
|
|
2248
|
-
LUSolve3x3
|
|
2249
|
-
linearSolve3x3
|
|
2250
|
-
multiply3x3_vect3
|
|
2251
|
-
multiply3x3_mat3
|
|
2252
|
-
multiplyMatrix
|
|
2253
|
-
transpose3x3
|
|
2254
|
-
invert3x3
|
|
2255
|
-
identity3x3
|
|
2256
|
-
identity
|
|
2257
|
-
isIdentity
|
|
2258
|
-
isIdentity3x3
|
|
2259
|
-
determinant3x3
|
|
2260
|
-
quaternionToMatrix3x3
|
|
2261
|
-
areEquals
|
|
2262
|
-
areMatricesEqual
|
|
2263
|
-
roundNumber
|
|
2264
|
-
roundVector
|
|
2265
|
-
matrix3x3ToQuaternion
|
|
2266
|
-
multiplyQuaternion
|
|
2267
|
-
orthogonalize3x3
|
|
2268
|
-
diagonalize3x3
|
|
2269
|
-
singularValueDecomposition3x3
|
|
2270
|
-
solveLinearSystem
|
|
2271
|
-
invertMatrix
|
|
2272
|
-
luFactorLinearSystem
|
|
2273
|
-
luSolveLinearSystem
|
|
2274
|
-
estimateMatrixCondition
|
|
2275
|
-
jacobi
|
|
2276
|
-
jacobiN
|
|
2277
|
-
solveHomogeneousLeastSquares
|
|
2278
|
-
solveLeastSquares
|
|
2279
|
-
hex2float
|
|
2280
|
-
rgb2hsv
|
|
2281
|
-
hsv2rgb
|
|
2282
|
-
lab2xyz
|
|
2283
|
-
xyz2lab
|
|
2284
|
-
xyz2rgb
|
|
2285
|
-
rgb2xyz
|
|
2286
|
-
rgb2lab
|
|
2287
|
-
lab2rgb
|
|
2288
|
-
uninitializeBounds
|
|
2289
|
-
areBoundsInitialized
|
|
2290
|
-
computeBoundsFromPoints
|
|
2291
|
-
clampValue
|
|
2292
|
-
clampVector
|
|
2293
|
-
clampAndNormalizeValue
|
|
2294
|
-
getScalarTypeFittingRange
|
|
2295
|
-
getAdjustedScalarRange
|
|
2296
|
-
extentIsWithinOtherExtent
|
|
2297
|
-
boundsIsWithinOtherBounds
|
|
2298
|
-
pointIsWithinBounds
|
|
2299
|
-
solve3PointCircle
|
|
2300
|
-
inf
|
|
2301
|
-
negInf
|
|
2302
|
-
isInf
|
|
2014
|
+
Pi,
|
|
2015
|
+
radiansFromDegrees,
|
|
2016
|
+
degreesFromRadians,
|
|
2017
|
+
round,
|
|
2018
|
+
floor,
|
|
2019
|
+
ceil,
|
|
2020
|
+
ceilLog2,
|
|
2021
|
+
min,
|
|
2022
|
+
max,
|
|
2023
|
+
arrayMin,
|
|
2024
|
+
arrayMax,
|
|
2025
|
+
arrayRange,
|
|
2026
|
+
isPowerOfTwo,
|
|
2027
|
+
nearestPowerOfTwo,
|
|
2028
|
+
factorial,
|
|
2029
|
+
binomial,
|
|
2030
|
+
beginCombination,
|
|
2031
|
+
nextCombination,
|
|
2032
|
+
randomSeed,
|
|
2033
|
+
getSeed,
|
|
2034
|
+
random,
|
|
2035
|
+
gaussian,
|
|
2036
|
+
add,
|
|
2037
|
+
subtract,
|
|
2038
|
+
multiplyScalar,
|
|
2039
|
+
multiplyScalar2D,
|
|
2040
|
+
multiplyAccumulate,
|
|
2041
|
+
multiplyAccumulate2D,
|
|
2042
|
+
dot,
|
|
2043
|
+
outer,
|
|
2044
|
+
cross,
|
|
2045
|
+
norm,
|
|
2046
|
+
normalize,
|
|
2047
|
+
perpendiculars,
|
|
2048
|
+
projectVector,
|
|
2049
|
+
projectVector2D,
|
|
2050
|
+
distance2BetweenPoints,
|
|
2051
|
+
angleBetweenVectors,
|
|
2052
|
+
gaussianAmplitude,
|
|
2053
|
+
gaussianWeight,
|
|
2054
|
+
dot2D,
|
|
2055
|
+
outer2D,
|
|
2056
|
+
norm2D,
|
|
2057
|
+
normalize2D,
|
|
2058
|
+
determinant2x2,
|
|
2059
|
+
LUFactor3x3,
|
|
2060
|
+
LUSolve3x3,
|
|
2061
|
+
linearSolve3x3,
|
|
2062
|
+
multiply3x3_vect3,
|
|
2063
|
+
multiply3x3_mat3,
|
|
2064
|
+
multiplyMatrix,
|
|
2065
|
+
transpose3x3,
|
|
2066
|
+
invert3x3,
|
|
2067
|
+
identity3x3,
|
|
2068
|
+
identity,
|
|
2069
|
+
isIdentity,
|
|
2070
|
+
isIdentity3x3,
|
|
2071
|
+
determinant3x3,
|
|
2072
|
+
quaternionToMatrix3x3,
|
|
2073
|
+
areEquals,
|
|
2074
|
+
areMatricesEqual,
|
|
2075
|
+
roundNumber,
|
|
2076
|
+
roundVector,
|
|
2077
|
+
matrix3x3ToQuaternion,
|
|
2078
|
+
multiplyQuaternion,
|
|
2079
|
+
orthogonalize3x3,
|
|
2080
|
+
diagonalize3x3,
|
|
2081
|
+
singularValueDecomposition3x3,
|
|
2082
|
+
solveLinearSystem,
|
|
2083
|
+
invertMatrix,
|
|
2084
|
+
luFactorLinearSystem,
|
|
2085
|
+
luSolveLinearSystem,
|
|
2086
|
+
estimateMatrixCondition,
|
|
2087
|
+
jacobi,
|
|
2088
|
+
jacobiN,
|
|
2089
|
+
solveHomogeneousLeastSquares,
|
|
2090
|
+
solveLeastSquares,
|
|
2091
|
+
hex2float,
|
|
2092
|
+
rgb2hsv,
|
|
2093
|
+
hsv2rgb,
|
|
2094
|
+
lab2xyz,
|
|
2095
|
+
xyz2lab,
|
|
2096
|
+
xyz2rgb,
|
|
2097
|
+
rgb2xyz,
|
|
2098
|
+
rgb2lab,
|
|
2099
|
+
lab2rgb,
|
|
2100
|
+
uninitializeBounds,
|
|
2101
|
+
areBoundsInitialized,
|
|
2102
|
+
computeBoundsFromPoints,
|
|
2103
|
+
clampValue,
|
|
2104
|
+
clampVector,
|
|
2105
|
+
clampAndNormalizeValue,
|
|
2106
|
+
getScalarTypeFittingRange,
|
|
2107
|
+
getAdjustedScalarRange,
|
|
2108
|
+
extentIsWithinOtherExtent,
|
|
2109
|
+
boundsIsWithinOtherBounds,
|
|
2110
|
+
pointIsWithinBounds,
|
|
2111
|
+
solve3PointCircle,
|
|
2112
|
+
inf,
|
|
2113
|
+
negInf,
|
|
2114
|
+
isInf,
|
|
2303
2115
|
isNan: isNaN,
|
|
2304
|
-
isNaN
|
|
2305
|
-
isFinite
|
|
2116
|
+
isNaN,
|
|
2117
|
+
isFinite,
|
|
2306
2118
|
// JS add-on
|
|
2307
|
-
createUninitializedBounds
|
|
2308
|
-
getMajorAxisIndex
|
|
2309
|
-
getSparseOrthogonalMatrix
|
|
2310
|
-
floatToHex2
|
|
2311
|
-
floatRGB2HexCode
|
|
2312
|
-
float2CssRGBA
|
|
2119
|
+
createUninitializedBounds,
|
|
2120
|
+
getMajorAxisIndex,
|
|
2121
|
+
getSparseOrthogonalMatrix,
|
|
2122
|
+
floatToHex2,
|
|
2123
|
+
floatRGB2HexCode,
|
|
2124
|
+
float2CssRGBA
|
|
2313
2125
|
};
|
|
2314
2126
|
|
|
2315
2127
|
var vtkMath$1 = /*#__PURE__*/Object.freeze({
|
|
@@ -2433,4 +2245,4 @@ var vtkMath$1 = /*#__PURE__*/Object.freeze({
|
|
|
2433
2245
|
'default': vtkMath
|
|
2434
2246
|
});
|
|
2435
2247
|
|
|
2436
|
-
export { ceilLog2 as $, degreesFromRadians as A, areEquals as B, clampValue as C, arrayRange as D, getMajorAxisIndex as E, createUninitializedBounds as F,
|
|
2248
|
+
export { ceilLog2 as $, degreesFromRadians as A, areEquals as B, clampValue as C, arrayRange as D, getMajorAxisIndex as E, createUninitializedBounds as F, floor as G, isInf as H, rgb2hsv as I, rgb2lab as J, lab2rgb as K, round as L, normalize2D as M, nearestPowerOfTwo as N, multiply3x3_vect3 as O, getSparseOrthogonalMatrix as P, areBoundsInitialized as Q, isPowerOfTwo as R, angleBetweenVectors as S, signedAngleBetweenVectors as T, createArray as U, Pi as V, ceil as W, min as X, max as Y, arrayMin as Z, arrayMax as _, areMatricesEqual as a, float2CssRGBA as a$, factorial as a0, binomial as a1, beginCombination as a2, nextCombination as a3, randomSeed as a4, getSeed as a5, gaussian as a6, multiplyScalar2D as a7, multiplyAccumulate2D as a8, outer as a9, diagonalize3x3 as aA, singularValueDecomposition3x3 as aB, luFactorLinearSystem as aC, luSolveLinearSystem as aD, invertMatrix as aE, estimateMatrixCondition as aF, solveHomogeneousLeastSquares as aG, solveLeastSquares as aH, hex2float as aI, lab2xyz as aJ, xyz2lab as aK, xyz2rgb as aL, rgb2xyz as aM, computeBoundsFromPoints as aN, clampAndNormalizeValue as aO, getScalarTypeFittingRange as aP, getAdjustedScalarRange as aQ, extentIsWithinOtherExtent as aR, boundsIsWithinOtherBounds as aS, pointIsWithinBounds as aT, solve3PointCircle as aU, inf as aV, negInf as aW, isFinite as aX, isNaN as aY, floatToHex2 as aZ, floatRGB2HexCode as a_, projectVector as aa, dot2D as ab, projectVector2D as ac, gaussianAmplitude as ad, gaussianWeight as ae, outer2D as af, norm2D as ag, rowsToMat4 as ah, columnsToMat4 as ai, columnsToMat3 as aj, LUFactor3x3 as ak, LUSolve3x3 as al, linearSolve3x3 as am, multiply3x3_mat3 as an, multiplyMatrix as ao, transpose3x3 as ap, invert3x3 as aq, identity3x3 as ar, identity as as, isIdentity as at, isIdentity3x3 as au, quaternionToMatrix3x3 as av, roundNumber as aw, matrix3x3ToQuaternion as ax, multiplyQuaternion as ay, orthogonalize3x3 as az, roundVector as b, clampVector as c, dot as d, distance2BetweenPoints as e, vtkMath as f, solveLinearSystem as g, hsv2rgb as h, isNan as i, cross as j, add as k, normalize as l, multiplyAccumulate as m, norm as n, determinant2x2 as o, jacobiN as p, perpendiculars as q, radiansFromDegrees as r, subtract as s, jacobi as t, uninitializeBounds as u, vtkMath$1 as v, multiplyScalar as w, random as x, determinant3x3 as y, rowsToMat3 as z };
|