@cornerstonejs/core 0.36.2 → 0.36.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (233) hide show
  1. package/dist/cjs/loaders/volumeLoader.d.ts +1 -0
  2. package/dist/cjs/loaders/volumeLoader.js +5 -1
  3. package/dist/cjs/loaders/volumeLoader.js.map +1 -1
  4. package/dist/cjs/utilities/getSliceRange.js +3 -1
  5. package/dist/cjs/utilities/getSliceRange.js.map +1 -1
  6. package/dist/cjs/utilities/getTargetVolumeAndSpacingInNormalDir.js +7 -0
  7. package/dist/cjs/utilities/getTargetVolumeAndSpacingInNormalDir.js.map +1 -1
  8. package/dist/esm/loaders/volumeLoader.d.ts +1 -0
  9. package/dist/esm/loaders/volumeLoader.js +3 -0
  10. package/dist/esm/loaders/volumeLoader.js.map +1 -1
  11. package/dist/esm/utilities/getSliceRange.js +3 -1
  12. package/dist/esm/utilities/getSliceRange.js.map +1 -1
  13. package/dist/esm/utilities/getTargetVolumeAndSpacingInNormalDir.js +7 -0
  14. package/dist/esm/utilities/getTargetVolumeAndSpacingInNormalDir.js.map +1 -1
  15. package/dist/umd/index.js +1 -1
  16. package/dist/umd/index.js.map +1 -1
  17. package/package.json +4 -3
  18. package/src/RenderingEngine/BaseVolumeViewport.ts +847 -0
  19. package/src/RenderingEngine/RenderingEngine.ts +1364 -0
  20. package/src/RenderingEngine/StackViewport.ts +2690 -0
  21. package/src/RenderingEngine/Viewport.ts +1244 -0
  22. package/src/RenderingEngine/VolumeViewport.ts +420 -0
  23. package/src/RenderingEngine/VolumeViewport3D.ts +42 -0
  24. package/src/RenderingEngine/getRenderingEngine.ts +34 -0
  25. package/src/RenderingEngine/helpers/addVolumesToViewports.ts +52 -0
  26. package/src/RenderingEngine/helpers/cpuFallback/colors/colormap.ts +343 -0
  27. package/src/RenderingEngine/helpers/cpuFallback/colors/index.ts +4 -0
  28. package/src/RenderingEngine/helpers/cpuFallback/colors/lookupTable.ts +469 -0
  29. package/src/RenderingEngine/helpers/cpuFallback/drawImageSync.ts +58 -0
  30. package/src/RenderingEngine/helpers/cpuFallback/rendering/calculateTransform.ts +136 -0
  31. package/src/RenderingEngine/helpers/cpuFallback/rendering/canvasToPixel.ts +25 -0
  32. package/src/RenderingEngine/helpers/cpuFallback/rendering/computeAutoVoi.ts +47 -0
  33. package/src/RenderingEngine/helpers/cpuFallback/rendering/correctShift.ts +38 -0
  34. package/src/RenderingEngine/helpers/cpuFallback/rendering/createViewport.ts +64 -0
  35. package/src/RenderingEngine/helpers/cpuFallback/rendering/doesImageNeedToBeRendered.ts +36 -0
  36. package/src/RenderingEngine/helpers/cpuFallback/rendering/fitToWindow.ts +22 -0
  37. package/src/RenderingEngine/helpers/cpuFallback/rendering/generateColorLUT.ts +60 -0
  38. package/src/RenderingEngine/helpers/cpuFallback/rendering/generateLut.ts +83 -0
  39. package/src/RenderingEngine/helpers/cpuFallback/rendering/getDefaultViewport.ts +88 -0
  40. package/src/RenderingEngine/helpers/cpuFallback/rendering/getImageFitScale.ts +52 -0
  41. package/src/RenderingEngine/helpers/cpuFallback/rendering/getImageSize.ts +55 -0
  42. package/src/RenderingEngine/helpers/cpuFallback/rendering/getLut.ts +53 -0
  43. package/src/RenderingEngine/helpers/cpuFallback/rendering/getModalityLut.ts +55 -0
  44. package/src/RenderingEngine/helpers/cpuFallback/rendering/getTransform.ts +17 -0
  45. package/src/RenderingEngine/helpers/cpuFallback/rendering/getVOILut.ts +74 -0
  46. package/src/RenderingEngine/helpers/cpuFallback/rendering/initializeRenderCanvas.ts +37 -0
  47. package/src/RenderingEngine/helpers/cpuFallback/rendering/lutMatches.ts +21 -0
  48. package/src/RenderingEngine/helpers/cpuFallback/rendering/now.ts +13 -0
  49. package/src/RenderingEngine/helpers/cpuFallback/rendering/pixelToCanvas.ts +22 -0
  50. package/src/RenderingEngine/helpers/cpuFallback/rendering/renderColorImage.ts +193 -0
  51. package/src/RenderingEngine/helpers/cpuFallback/rendering/renderGrayscaleImage.ts +166 -0
  52. package/src/RenderingEngine/helpers/cpuFallback/rendering/renderPseudoColorImage.ts +203 -0
  53. package/src/RenderingEngine/helpers/cpuFallback/rendering/resetCamera.ts +32 -0
  54. package/src/RenderingEngine/helpers/cpuFallback/rendering/resize.ts +109 -0
  55. package/src/RenderingEngine/helpers/cpuFallback/rendering/saveLastRendered.ts +36 -0
  56. package/src/RenderingEngine/helpers/cpuFallback/rendering/setDefaultViewport.ts +17 -0
  57. package/src/RenderingEngine/helpers/cpuFallback/rendering/setToPixelCoordinateSystem.ts +32 -0
  58. package/src/RenderingEngine/helpers/cpuFallback/rendering/storedColorPixelDataToCanvasImageData.ts +58 -0
  59. package/src/RenderingEngine/helpers/cpuFallback/rendering/storedPixelDataToCanvasImageData.ts +76 -0
  60. package/src/RenderingEngine/helpers/cpuFallback/rendering/storedPixelDataToCanvasImageDataColorLUT.ts +60 -0
  61. package/src/RenderingEngine/helpers/cpuFallback/rendering/storedPixelDataToCanvasImageDataPET.ts +50 -0
  62. package/src/RenderingEngine/helpers/cpuFallback/rendering/storedPixelDataToCanvasImageDataPseudocolorLUT.ts +66 -0
  63. package/src/RenderingEngine/helpers/cpuFallback/rendering/storedPixelDataToCanvasImageDataPseudocolorLUTPET.ts +68 -0
  64. package/src/RenderingEngine/helpers/cpuFallback/rendering/storedPixelDataToCanvasImageDataRGBA.ts +81 -0
  65. package/src/RenderingEngine/helpers/cpuFallback/rendering/storedRGBAPixelDataToCanvasImageData.ts +56 -0
  66. package/src/RenderingEngine/helpers/cpuFallback/rendering/transform.ts +126 -0
  67. package/src/RenderingEngine/helpers/cpuFallback/rendering/validator.ts +31 -0
  68. package/src/RenderingEngine/helpers/createVolumeActor.ts +103 -0
  69. package/src/RenderingEngine/helpers/createVolumeMapper.ts +37 -0
  70. package/src/RenderingEngine/helpers/getOrCreateCanvas.ts +58 -0
  71. package/src/RenderingEngine/helpers/index.ts +15 -0
  72. package/src/RenderingEngine/helpers/isRgbaSourceRgbDest.ts +1 -0
  73. package/src/RenderingEngine/helpers/setDefaultVolumeVOI.ts +227 -0
  74. package/src/RenderingEngine/helpers/setVolumesForViewports.ts +52 -0
  75. package/src/RenderingEngine/helpers/viewportTypeToViewportClass.ts +14 -0
  76. package/src/RenderingEngine/helpers/viewportTypeUsesCustomRenderingPipeline.ts +7 -0
  77. package/src/RenderingEngine/helpers/volumeNewImageEventDispatcher.ts +75 -0
  78. package/src/RenderingEngine/index.ts +23 -0
  79. package/src/RenderingEngine/renderingEngineCache.ts +43 -0
  80. package/src/RenderingEngine/vtkClasses/index.js +11 -0
  81. package/src/RenderingEngine/vtkClasses/vtkOffscreenMultiRenderWindow.js +149 -0
  82. package/src/RenderingEngine/vtkClasses/vtkSharedVolumeMapper.js +52 -0
  83. package/src/RenderingEngine/vtkClasses/vtkSlabCamera.d.ts +781 -0
  84. package/src/RenderingEngine/vtkClasses/vtkSlabCamera.js +155 -0
  85. package/src/RenderingEngine/vtkClasses/vtkStreamingOpenGLRenderWindow.js +47 -0
  86. package/src/RenderingEngine/vtkClasses/vtkStreamingOpenGLTexture.js +272 -0
  87. package/src/RenderingEngine/vtkClasses/vtkStreamingOpenGLViewNodeFactory.js +159 -0
  88. package/src/RenderingEngine/vtkClasses/vtkStreamingOpenGLVolumeMapper.js +319 -0
  89. package/src/Settings.ts +294 -0
  90. package/src/cache/cache.ts +854 -0
  91. package/src/cache/classes/Contour.ts +70 -0
  92. package/src/cache/classes/ContourSet.ts +151 -0
  93. package/src/cache/classes/ImageVolume.ts +155 -0
  94. package/src/cache/index.ts +5 -0
  95. package/src/constants/cpuColormaps.ts +1537 -0
  96. package/src/constants/epsilon.ts +3 -0
  97. package/src/constants/index.ts +13 -0
  98. package/src/constants/mprCameraValues.ts +20 -0
  99. package/src/constants/rendering.ts +8 -0
  100. package/src/constants/viewportPresets.ts +357 -0
  101. package/src/enums/BlendModes.ts +23 -0
  102. package/src/enums/ContourType.ts +6 -0
  103. package/src/enums/Events.ts +196 -0
  104. package/src/enums/GeometryType.ts +5 -0
  105. package/src/enums/InterpolationType.ts +13 -0
  106. package/src/enums/OrientationAxis.ts +8 -0
  107. package/src/enums/RequestType.ts +13 -0
  108. package/src/enums/SharedArrayBufferModes.ts +11 -0
  109. package/src/enums/VOILUTFunctionType.ts +10 -0
  110. package/src/enums/ViewportType.ts +21 -0
  111. package/src/enums/index.ts +23 -0
  112. package/src/eventTarget.ts +67 -0
  113. package/src/getEnabledElement.ts +105 -0
  114. package/src/global.ts +8 -0
  115. package/src/index.ts +123 -0
  116. package/src/init.ts +247 -0
  117. package/src/loaders/geometryLoader.ts +108 -0
  118. package/src/loaders/imageLoader.ts +298 -0
  119. package/src/loaders/volumeLoader.ts +477 -0
  120. package/src/metaData.ts +84 -0
  121. package/src/requestPool/imageLoadPoolManager.ts +43 -0
  122. package/src/requestPool/imageRetrievalPoolManager.ts +25 -0
  123. package/src/requestPool/requestPoolManager.ts +329 -0
  124. package/src/types/ActorSliceRange.ts +17 -0
  125. package/src/types/CPUFallbackColormap.ts +23 -0
  126. package/src/types/CPUFallbackColormapData.ts +12 -0
  127. package/src/types/CPUFallbackColormapsData.ts +7 -0
  128. package/src/types/CPUFallbackEnabledElement.ts +71 -0
  129. package/src/types/CPUFallbackLUT.ts +5 -0
  130. package/src/types/CPUFallbackLookupTable.ts +17 -0
  131. package/src/types/CPUFallbackRenderingTools.ts +25 -0
  132. package/src/types/CPUFallbackTransform.ts +16 -0
  133. package/src/types/CPUFallbackViewport.ts +29 -0
  134. package/src/types/CPUFallbackViewportDisplayedArea.ts +15 -0
  135. package/src/types/CPUIImageData.ts +47 -0
  136. package/src/types/ContourData.ts +19 -0
  137. package/src/types/Cornerstone3DConfig.ts +31 -0
  138. package/src/types/CustomEventType.ts +14 -0
  139. package/src/types/EventTypes.ts +403 -0
  140. package/src/types/FlipDirection.ts +9 -0
  141. package/src/types/IActor.ts +23 -0
  142. package/src/types/ICache.ts +28 -0
  143. package/src/types/ICachedGeometry.ts +13 -0
  144. package/src/types/ICachedImage.ts +13 -0
  145. package/src/types/ICachedVolume.ts +12 -0
  146. package/src/types/ICamera.ts +36 -0
  147. package/src/types/IContour.ts +18 -0
  148. package/src/types/IContourSet.ts +56 -0
  149. package/src/types/IDynamicImageVolume.ts +18 -0
  150. package/src/types/IEnabledElement.ts +21 -0
  151. package/src/types/IGeometry.ts +12 -0
  152. package/src/types/IImage.ts +113 -0
  153. package/src/types/IImageData.ts +45 -0
  154. package/src/types/IImageVolume.ts +78 -0
  155. package/src/types/ILoadObject.ts +36 -0
  156. package/src/types/IRegisterImageLoader.ts +10 -0
  157. package/src/types/IRenderingEngine.ts +28 -0
  158. package/src/types/IStackViewport.ts +138 -0
  159. package/src/types/IStreamingImageVolume.ts +13 -0
  160. package/src/types/IStreamingVolumeProperties.ts +14 -0
  161. package/src/types/IViewport.ts +149 -0
  162. package/src/types/IViewportId.ts +9 -0
  163. package/src/types/IVolume.ts +45 -0
  164. package/src/types/IVolumeInput.ts +36 -0
  165. package/src/types/IVolumeViewport.ts +141 -0
  166. package/src/types/ImageLoaderFn.ts +16 -0
  167. package/src/types/ImageSliceData.ts +6 -0
  168. package/src/types/Mat3.ts +16 -0
  169. package/src/types/Metadata.ts +39 -0
  170. package/src/types/OrientationVectors.ts +36 -0
  171. package/src/types/Plane.ts +6 -0
  172. package/src/types/Point2.ts +6 -0
  173. package/src/types/Point3.ts +6 -0
  174. package/src/types/Point4.ts +6 -0
  175. package/src/types/ScalingParameters.ts +27 -0
  176. package/src/types/StackViewportProperties.ts +25 -0
  177. package/src/types/TransformMatrix2D.ts +4 -0
  178. package/src/types/ViewportInputOptions.ts +21 -0
  179. package/src/types/ViewportPreset.ts +14 -0
  180. package/src/types/VolumeLoaderFn.ts +18 -0
  181. package/src/types/VolumeViewportProperties.ts +14 -0
  182. package/src/types/index.ts +157 -0
  183. package/src/types/voi.ts +15 -0
  184. package/src/utilities/actorCheck.ts +24 -0
  185. package/src/utilities/applyPreset.ts +132 -0
  186. package/src/utilities/calculateViewportsSpatialRegistration.ts +74 -0
  187. package/src/utilities/calibratedPixelSpacingMetadataProvider.ts +38 -0
  188. package/src/utilities/createFloat32SharedArray.ts +45 -0
  189. package/src/utilities/createInt16SharedArray.ts +43 -0
  190. package/src/utilities/createLinearRGBTransferFunction.ts +22 -0
  191. package/src/utilities/createSigmoidRGBTransferFunction.ts +63 -0
  192. package/src/utilities/createUInt16SharedArray.ts +43 -0
  193. package/src/utilities/createUint8SharedArray.ts +45 -0
  194. package/src/utilities/deepFreeze.ts +19 -0
  195. package/src/utilities/deepMerge.ts +81 -0
  196. package/src/utilities/getClosestImageId.ts +80 -0
  197. package/src/utilities/getClosestStackImageIndexForPoint.ts +116 -0
  198. package/src/utilities/getImageSliceDataForVolumeViewport.ts +61 -0
  199. package/src/utilities/getMinMax.ts +31 -0
  200. package/src/utilities/getRuntimeId.ts +54 -0
  201. package/src/utilities/getScalarDataType.ts +31 -0
  202. package/src/utilities/getScalingParameters.ts +35 -0
  203. package/src/utilities/getSliceRange.ts +86 -0
  204. package/src/utilities/getSpacingInNormalDirection.ts +44 -0
  205. package/src/utilities/getTargetVolumeAndSpacingInNormalDir.ts +126 -0
  206. package/src/utilities/getViewportImageCornersInWorld.ts +102 -0
  207. package/src/utilities/getViewportsWithImageURI.ts +46 -0
  208. package/src/utilities/getViewportsWithVolumeId.ts +38 -0
  209. package/src/utilities/getVoiFromSigmoidRGBTransferFunction.ts +23 -0
  210. package/src/utilities/getVolumeActorCorners.ts +24 -0
  211. package/src/utilities/getVolumeSliceRangeInfo.ts +52 -0
  212. package/src/utilities/getVolumeViewportScrollInfo.ts +32 -0
  213. package/src/utilities/getVolumeViewportsContainingSameVolumes.ts +58 -0
  214. package/src/utilities/hasNaNValues.ts +12 -0
  215. package/src/utilities/imageIdToURI.ts +10 -0
  216. package/src/utilities/imageToWorldCoords.ts +54 -0
  217. package/src/utilities/index.ts +100 -0
  218. package/src/utilities/indexWithinDimensions.ts +27 -0
  219. package/src/utilities/invertRgbTransferFunction.ts +36 -0
  220. package/src/utilities/isEqual.ts +27 -0
  221. package/src/utilities/isOpposite.ts +23 -0
  222. package/src/utilities/isTypedArray.ts +20 -0
  223. package/src/utilities/loadImageToCanvas.ts +80 -0
  224. package/src/utilities/planar.ts +91 -0
  225. package/src/utilities/renderToCanvas.ts +32 -0
  226. package/src/utilities/scaleRgbTransferFunction.ts +37 -0
  227. package/src/utilities/snapFocalPointToSlice.ts +78 -0
  228. package/src/utilities/spatialRegistrationMetadataProvider.ts +50 -0
  229. package/src/utilities/transformWorldToIndex.ts +16 -0
  230. package/src/utilities/triggerEvent.ts +38 -0
  231. package/src/utilities/uuidv4.ts +13 -0
  232. package/src/utilities/windowLevel.ts +39 -0
  233. package/src/utilities/worldToImageCoords.ts +64 -0
@@ -0,0 +1,319 @@
1
+ import { mat3, mat4, vec3 } from 'gl-matrix';
2
+ import macro from '@kitware/vtk.js/macros';
3
+ import vtkOpenGLVolumeMapper from '@kitware/vtk.js/Rendering/OpenGL/VolumeMapper';
4
+ import { Filter } from '@kitware/vtk.js/Rendering/OpenGL/Texture/Constants';
5
+ import { VtkDataTypes } from '@kitware/vtk.js/Common/Core/DataArray/Constants';
6
+ import vtkDataArray from '@kitware/vtk.js/Common/Core/DataArray';
7
+ import { Representation } from '@kitware/vtk.js/Rendering/Core/Property/Constants';
8
+
9
+ const { vtkWarningMacro } = macro;
10
+ /**
11
+ * vtkStreamingOpenGLVolumeMapper - A dervied class of the core vtkOpenGLVolumeMapper class.
12
+ * This class replaces the buildBufferObjects function so that we progressively upload our textures
13
+ * into GPU memory using the new methods on vtkStreamingOpenGLTexture.
14
+ *
15
+ *
16
+ * @param {*} publicAPI The public API to extend
17
+ * @param {*} model The private model to extend.
18
+ */
19
+ function vtkStreamingOpenGLVolumeMapper(publicAPI, model) {
20
+ model.classHierarchy.push('vtkStreamingOpenGLVolumeMapper');
21
+
22
+ /**
23
+ * buildBufferObjects - A fork of vtkOpenGLVolumeMapper's buildBufferObjects method.
24
+ * This fork performs most of the same actions, but builds the textures progressively using
25
+ * vtkStreamingOpenGLTexture's methods, and also prevents recomputation of the texture for each
26
+ * vtkStreamingOpenGLVolumeMapper using the texture.
27
+ *
28
+ *
29
+ * @param {*} ren The renderer.
30
+ * @param {*} actor The actor to build the buffer objects for.
31
+ */
32
+ publicAPI.buildBufferObjects = (ren, actor) => {
33
+ const image = model.currentInput;
34
+ if (!image) {
35
+ return;
36
+ }
37
+
38
+ const scalars = image.getPointData() && image.getPointData().getScalars();
39
+ if (!scalars) {
40
+ return;
41
+ }
42
+
43
+ const vprop = actor.getProperty();
44
+
45
+ if (!model.jitterTexture.getHandle()) {
46
+ const oTable = new Uint8Array(32 * 32);
47
+ for (let i = 0; i < 32 * 32; ++i) {
48
+ oTable[i] = 255.0 * Math.random();
49
+ }
50
+ model.jitterTexture.setMinificationFilter(Filter.LINEAR);
51
+ model.jitterTexture.setMagnificationFilter(Filter.LINEAR);
52
+ model.jitterTexture.create2DFromRaw(
53
+ 32,
54
+ 32,
55
+ 1,
56
+ VtkDataTypes.UNSIGNED_CHAR,
57
+ oTable
58
+ );
59
+ }
60
+
61
+ const numComp = scalars.getNumberOfComponents();
62
+ const iComps = vprop.getIndependentComponents();
63
+ const numIComps = iComps ? numComp : 1;
64
+
65
+ // rebuild opacity tfun?
66
+ let toString = `${vprop.getMTime()}`;
67
+ if (model.opacityTextureString !== toString) {
68
+ const oWidth = 1024;
69
+ const oSize = oWidth * 2 * numIComps;
70
+ const ofTable = new Float32Array(oSize);
71
+ const tmpTable = new Float32Array(oWidth);
72
+
73
+ for (let c = 0; c < numIComps; ++c) {
74
+ const ofun = vprop.getScalarOpacity(c);
75
+ const opacityFactor =
76
+ model.renderable.getSampleDistance() /
77
+ vprop.getScalarOpacityUnitDistance(c);
78
+
79
+ const oRange = ofun.getRange();
80
+ ofun.getTable(oRange[0], oRange[1], oWidth, tmpTable, 1);
81
+ // adjust for sample distance etc
82
+ for (let i = 0; i < oWidth; ++i) {
83
+ ofTable[c * oWidth * 2 + i] =
84
+ 1.0 - (1.0 - tmpTable[i]) ** opacityFactor;
85
+ ofTable[c * oWidth * 2 + i + oWidth] = ofTable[c * oWidth * 2 + i];
86
+ }
87
+ }
88
+
89
+ model.opacityTexture.releaseGraphicsResources(model._openGLRenderWindow);
90
+ model.opacityTexture.setMinificationFilter(Filter.LINEAR);
91
+ model.opacityTexture.setMagnificationFilter(Filter.LINEAR);
92
+
93
+ // use float texture where possible because we really need the resolution
94
+ // for this table. Errors in low values of opacity accumulate to
95
+ // visible artifacts. High values of opacity quickly terminate without
96
+ // artifacts.
97
+ if (
98
+ model._openGLRenderWindow.getWebgl2() ||
99
+ (model.context.getExtension('OES_texture_float') &&
100
+ model.context.getExtension('OES_texture_float_linear'))
101
+ ) {
102
+ model.opacityTexture.create2DFromRaw(
103
+ oWidth,
104
+ 2 * numIComps,
105
+ 1,
106
+ VtkDataTypes.FLOAT,
107
+ ofTable
108
+ );
109
+ } else {
110
+ const oTable = new Uint8Array(oSize);
111
+ for (let i = 0; i < oSize; ++i) {
112
+ oTable[i] = 255.0 * ofTable[i];
113
+ }
114
+ model.opacityTexture.create2DFromRaw(
115
+ oWidth,
116
+ 2 * numIComps,
117
+ 1,
118
+ VtkDataTypes.UNSIGNED_CHAR,
119
+ oTable
120
+ );
121
+ }
122
+ model.opacityTextureString = toString;
123
+ }
124
+
125
+ // rebuild color tfun?
126
+ toString = `${vprop.getMTime()}`;
127
+
128
+ if (model.colorTextureString !== toString) {
129
+ const cWidth = 1024;
130
+ const cSize = cWidth * 2 * numIComps * 3;
131
+ const cTable = new Uint8Array(cSize);
132
+ const tmpTable = new Float32Array(cWidth * 3);
133
+
134
+ for (let c = 0; c < numIComps; ++c) {
135
+ const cfun = vprop.getRGBTransferFunction(c);
136
+ const cRange = cfun.getRange();
137
+ cfun.getTable(cRange[0], cRange[1], cWidth, tmpTable, 1);
138
+ for (let i = 0; i < cWidth * 3; ++i) {
139
+ cTable[c * cWidth * 6 + i] = 255.0 * tmpTable[i];
140
+ cTable[c * cWidth * 6 + i + cWidth * 3] = 255.0 * tmpTable[i];
141
+ }
142
+ }
143
+
144
+ model.colorTexture.releaseGraphicsResources(model._openGLRenderWindow);
145
+ model.colorTexture.setMinificationFilter(Filter.LINEAR);
146
+ model.colorTexture.setMagnificationFilter(Filter.LINEAR);
147
+
148
+ model.colorTexture.create2DFromRaw(
149
+ cWidth,
150
+ 2 * numIComps,
151
+ 3,
152
+ VtkDataTypes.UNSIGNED_CHAR,
153
+ cTable
154
+ );
155
+ model.colorTextureString = toString;
156
+ }
157
+
158
+ // rebuild the scalarTexture if the data has changed
159
+ toString = `${image.getMTime()}`;
160
+
161
+ if (model.scalarTextureString !== toString) {
162
+ // Build the textures
163
+ const dims = image.getDimensions();
164
+
165
+ const previousTextureParameters =
166
+ model.scalarTexture.getTextureParameters();
167
+
168
+ const dataType = image.getPointData().getScalars().getDataType();
169
+ const data = image.getPointData().getScalars().getData();
170
+
171
+ let shouldReset = true;
172
+
173
+ if (
174
+ previousTextureParameters.dataType &&
175
+ previousTextureParameters.dataType === dataType
176
+ ) {
177
+ const previousTextureSize =
178
+ previousTextureParameters.width *
179
+ previousTextureParameters.height *
180
+ previousTextureParameters.depth *
181
+ previousTextureParameters.numComps;
182
+ if (data.length === previousTextureSize) {
183
+ shouldReset = false;
184
+ }
185
+ }
186
+
187
+ if (shouldReset) {
188
+ model.scalarTexture.setOglNorm16Ext(
189
+ model.context.getExtension('EXT_texture_norm16')
190
+ );
191
+
192
+ model.scalarTexture.releaseGraphicsResources(model._openGLRenderWindow);
193
+ model.scalarTexture.resetFormatAndType();
194
+
195
+ model.scalarTexture.create3DFilterableFromRaw(
196
+ dims[0],
197
+ dims[1],
198
+ dims[2],
199
+ numComp,
200
+ scalars.getDataType(),
201
+ scalars.getData(),
202
+ model.renderable.getPreferSizeOverAccuracy()
203
+ );
204
+ } else {
205
+ model.scalarTexture.deactivate();
206
+ model.scalarTexture.update3DFromRaw(data);
207
+ }
208
+
209
+ model.scalarTextureString = toString;
210
+ }
211
+
212
+ if (!model.tris.getCABO().getElementCount()) {
213
+ // build the CABO
214
+ const ptsArray = new Float32Array(12);
215
+ for (let i = 0; i < 4; i++) {
216
+ ptsArray[i * 3] = (i % 2) * 2 - 1.0;
217
+ ptsArray[i * 3 + 1] = i > 1 ? 1.0 : -1.0;
218
+ ptsArray[i * 3 + 2] = -1.0;
219
+ }
220
+
221
+ const cellArray = new Uint16Array(8);
222
+ cellArray[0] = 3;
223
+ cellArray[1] = 0;
224
+ cellArray[2] = 1;
225
+ cellArray[3] = 3;
226
+ cellArray[4] = 3;
227
+ cellArray[5] = 0;
228
+ cellArray[6] = 3;
229
+ cellArray[7] = 2;
230
+
231
+ const points = vtkDataArray.newInstance({
232
+ numberOfComponents: 3,
233
+ values: ptsArray,
234
+ });
235
+ points.setName('points');
236
+ const cells = vtkDataArray.newInstance({
237
+ numberOfComponents: 1,
238
+ values: cellArray,
239
+ });
240
+ model.tris.getCABO().createVBO(cells, 'polys', Representation.SURFACE, {
241
+ points,
242
+ cellOffset: 0,
243
+ });
244
+ }
245
+
246
+ model.VBOBuildTime.modified();
247
+ };
248
+
249
+ // publicAPI.getRenderTargetSize = () => {
250
+ // // https://github.com/Kitware/vtk-js/blob/master/Sources/Rendering/OpenGL/VolumeMapper/index.js#L952
251
+ // if (model.lastXYF > 1.43) {
252
+ // const sz = model.framebuffer.getSize()
253
+ // return [model.fvp[0] * sz[0], model.fvp[1] * sz[1]]
254
+ // }
255
+
256
+ // // This seems wrong, it assumes the renderWindow only has one renderer
257
+ // // but I don't know if this stuff is correct...
258
+
259
+ // const { usize, vsize } = model.openGLRenderer.getTiledSizeAndOrigin()
260
+
261
+ // return [usize, vsize]
262
+ // }
263
+
264
+ // publicAPI.getRenderTargetSize = () => {
265
+ // if (model._useSmallViewport) {
266
+ // return [model._smallViewportWidth, model._smallViewportHeight]
267
+ // }
268
+
269
+ // return model._openGLRenderWindow.getFramebufferSize()
270
+ // }
271
+
272
+ publicAPI.getRenderTargetSize = () => {
273
+ if (model._useSmallViewport) {
274
+ return [model._smallViewportWidth, model._smallViewportHeight];
275
+ }
276
+
277
+ const { usize, vsize } = model._openGLRenderer.getTiledSizeAndOrigin();
278
+
279
+ return [usize, vsize];
280
+ };
281
+
282
+ publicAPI.getRenderTargetOffset = () => {
283
+ const { lowerLeftU, lowerLeftV } =
284
+ model._openGLRenderer.getTiledSizeAndOrigin();
285
+
286
+ return [lowerLeftU, lowerLeftV];
287
+ };
288
+ }
289
+
290
+ // ----------------------------------------------------------------------------
291
+ // Object factory
292
+ // ----------------------------------------------------------------------------
293
+
294
+ // ----------------------------------------------------------------------------
295
+
296
+ const DEFAULT_VALUES = {};
297
+
298
+ export function extend(publicAPI, model, initialValues = {}) {
299
+ Object.assign(model, DEFAULT_VALUES, initialValues);
300
+
301
+ vtkOpenGLVolumeMapper.extend(publicAPI, model, initialValues);
302
+
303
+ model.scalarTexture = initialValues.scalarTexture;
304
+ model.previousState = {};
305
+
306
+ // Object methods
307
+ vtkStreamingOpenGLVolumeMapper(publicAPI, model);
308
+ }
309
+
310
+ // ----------------------------------------------------------------------------
311
+
312
+ export const newInstance = macro.newInstance(
313
+ extend,
314
+ 'vtkStreamingOpenGLVolumeMapper'
315
+ );
316
+
317
+ // ----------------------------------------------------------------------------
318
+
319
+ export default { newInstance, extend };
@@ -0,0 +1,294 @@
1
+ /*
2
+ * Constants
3
+ */
4
+
5
+ const DEFAULT_SETTINGS = Symbol('DefaultSettings');
6
+ const RUNTIME_SETTINGS = Symbol('RuntimeSettings');
7
+ const OBJECT_SETTINGS_MAP = Symbol('ObjectSettingsMap');
8
+ const DICTIONARY = Symbol('Dictionary');
9
+
10
+ /**
11
+ * Settings
12
+ */
13
+ export default class Settings {
14
+ constructor(base?: Settings) {
15
+ const dictionary = Object.create(
16
+ base instanceof Settings && DICTIONARY in base ? base[DICTIONARY] : null
17
+ );
18
+ Object.seal(
19
+ Object.defineProperty(this, DICTIONARY, {
20
+ value: dictionary,
21
+ })
22
+ );
23
+ }
24
+
25
+ set(key: string, value: unknown): boolean {
26
+ return set(this[DICTIONARY], key, value, null);
27
+ }
28
+
29
+ get(key: string): unknown {
30
+ return get(this[DICTIONARY], key);
31
+ }
32
+
33
+ /**
34
+ * Unset a specific key or a set of keys within a namespace when the key ends with a dot (ASCII #46).
35
+ * If the key is ".", all keys will be removed and this command works as a reset.
36
+ * @param key - name The key to be unset or a namespace.
37
+ * @returns boolean
38
+ */
39
+ unset(key: string): boolean {
40
+ return unset(this[DICTIONARY], key + '');
41
+ }
42
+
43
+ forEach(callback: (key: string, value: unknown) => void): void {
44
+ iterate(this[DICTIONARY], callback);
45
+ }
46
+
47
+ extend(): Settings {
48
+ return new Settings(this);
49
+ }
50
+
51
+ /**
52
+ * Recursively import all properties from the given plain JavaScript object.
53
+ * This method has the opposite effect of the `dump` method.
54
+ * @param root - The root object whose properties will
55
+ * be imported.
56
+ */
57
+ import(root: Record<string, unknown>): void {
58
+ if (isPlainObject(root)) {
59
+ Object.keys(root).forEach((key) => {
60
+ set(this[DICTIONARY], key, root[key], null);
61
+ });
62
+ }
63
+ }
64
+
65
+ /**
66
+ * Build a JSON representation of the current internal state of this settings
67
+ * object. The returned object can be safely passed to `JSON.stringify`
68
+ * function.
69
+ * @returns The JSON representation of the current
70
+ * state of this settings instance
71
+ */
72
+ dump(): Record<string, unknown> {
73
+ const context = {};
74
+ iterate(this[DICTIONARY], (key, value) => {
75
+ if (typeof value !== 'undefined') {
76
+ deepSet(context, key, value);
77
+ }
78
+ });
79
+ return context;
80
+ }
81
+
82
+ static assert(subject: Settings): Settings {
83
+ return subject instanceof Settings
84
+ ? subject
85
+ : Settings.getRuntimeSettings();
86
+ }
87
+
88
+ static getDefaultSettings(subfield = null): Settings | any {
89
+ let defaultSettings = Settings[DEFAULT_SETTINGS];
90
+ if (!(defaultSettings instanceof Settings)) {
91
+ defaultSettings = new Settings();
92
+ Settings[DEFAULT_SETTINGS] = defaultSettings;
93
+ }
94
+
95
+ // Given subfield of 'segmentation' it will return all settings
96
+ // that starts with segmentation.*
97
+ if (subfield) {
98
+ const settingObj = {};
99
+ defaultSettings.forEach((name: string) => {
100
+ if (name.startsWith(subfield)) {
101
+ const setting = name.split(`${subfield}.`)[1];
102
+ settingObj[setting] = defaultSettings.get(name);
103
+ }
104
+ });
105
+ return settingObj;
106
+ }
107
+
108
+ return defaultSettings;
109
+ }
110
+
111
+ static getRuntimeSettings(): Settings {
112
+ let runtimeSettings = Settings[RUNTIME_SETTINGS];
113
+ if (!(runtimeSettings instanceof Settings)) {
114
+ runtimeSettings = new Settings(Settings.getDefaultSettings());
115
+ Settings[RUNTIME_SETTINGS] = runtimeSettings;
116
+ }
117
+ return runtimeSettings;
118
+ }
119
+
120
+ static getObjectSettings(subject: unknown, from?: unknown): Settings {
121
+ let settings = null;
122
+ if (subject instanceof Settings) {
123
+ settings = subject;
124
+ } else if (typeof subject === 'object' && subject !== null) {
125
+ let objectSettingsMap = Settings[OBJECT_SETTINGS_MAP];
126
+ if (!(objectSettingsMap instanceof WeakMap)) {
127
+ objectSettingsMap = new WeakMap();
128
+ Settings[OBJECT_SETTINGS_MAP] = objectSettingsMap;
129
+ }
130
+ settings = objectSettingsMap.get(subject);
131
+ if (!(settings instanceof Settings)) {
132
+ settings = new Settings(
133
+ Settings.assert(Settings.getObjectSettings(from))
134
+ );
135
+ objectSettingsMap.set(subject, settings);
136
+ }
137
+ }
138
+ return settings;
139
+ }
140
+
141
+ static extendRuntimeSettings(): Settings {
142
+ return Settings.getRuntimeSettings().extend();
143
+ }
144
+ }
145
+
146
+ /*
147
+ * Local Helpers
148
+ */
149
+
150
+ function unset(dictionary: Record<string, unknown>, name: string): boolean {
151
+ if (name.endsWith('.')) {
152
+ let deleteCount = 0;
153
+ const namespace = name;
154
+ const base = namespace.slice(0, -1);
155
+ const deleteAll = base.length === 0;
156
+ for (const key in dictionary) {
157
+ if (
158
+ Object.prototype.hasOwnProperty.call(dictionary, key) &&
159
+ (deleteAll || key.startsWith(namespace) || key === base)
160
+ ) {
161
+ delete dictionary[key];
162
+ ++deleteCount;
163
+ }
164
+ }
165
+ return deleteCount > 0;
166
+ }
167
+ return delete dictionary[name];
168
+ }
169
+
170
+ function iterate(
171
+ dictionary: Record<string, unknown>,
172
+ callback: (key: string, value: unknown) => void
173
+ ): void {
174
+ for (const key in dictionary) {
175
+ callback(key, dictionary[key]);
176
+ }
177
+ }
178
+
179
+ function setAll(
180
+ dictionary: Record<string, unknown>,
181
+ prefix: string,
182
+ record: Record<string, unknown>,
183
+ references: WeakSet<Record<string, unknown>>
184
+ ): boolean {
185
+ let failCount: number;
186
+ if (references.has(record)) {
187
+ return set(dictionary, prefix, null, references);
188
+ }
189
+ references.add(record);
190
+ failCount = 0;
191
+ for (const field in record) {
192
+ if (Object.prototype.hasOwnProperty.call(record, field)) {
193
+ const key = field.length === 0 ? prefix : `${prefix}.${field}`;
194
+ if (!set(dictionary, key, record[field], references)) {
195
+ ++failCount;
196
+ }
197
+ }
198
+ }
199
+ references.delete(record);
200
+ return failCount === 0;
201
+ }
202
+
203
+ /**
204
+ * Set the key-value pair on a given dictionary. If the given value is a
205
+ * plain javascript object, every property of that object will also be set.
206
+ * @param dictionary {Record<string, unknown>} The target dictionary
207
+ * @param key {string} The given key
208
+ * @param value {unknown} The given value
209
+ * @param references {WeakSet<Record<string, unknown>>} references is a WeakSet
210
+ * instance used to keep track of which objects have already been iterated
211
+ * through preventing thus possible stack overflows caused by cyclic references
212
+ * @returns {boolean} Returns true if every given key-value pair has been
213
+ * successfully set
214
+ */
215
+ function set(
216
+ dictionary: Record<string, unknown>,
217
+ key: string,
218
+ value: unknown,
219
+ references: WeakSet<Record<string, unknown>>
220
+ ): boolean {
221
+ if (isValidKey(key)) {
222
+ if (isPlainObject(value)) {
223
+ return setAll(
224
+ dictionary,
225
+ key,
226
+ value as Record<string, unknown>,
227
+ references instanceof WeakSet ? references : new WeakSet()
228
+ );
229
+ }
230
+ dictionary[key] = value;
231
+ return true;
232
+ }
233
+ return false;
234
+ }
235
+
236
+ function get(dictionary: Record<string, unknown>, key: string): unknown {
237
+ return dictionary[key];
238
+ }
239
+
240
+ /**
241
+ * Make sure the -provided key correctly formatted.
242
+ * e.g.:
243
+ * "my.cool.property" (valid)
244
+ * "my.cool.property." (invalid)
245
+ * ".my.cool.property" (invalid)
246
+ * "my.cool..property" (invalid)
247
+ * @param key {string} The property name to be used as key within the internal
248
+ * dictionary
249
+ * @returns {boolean} True on success, false otherwise
250
+ */
251
+ function isValidKey(key: string): boolean {
252
+ let last: number, current: number, previous: number;
253
+ if (typeof key !== 'string' || (last = key.length - 1) < 0) return false;
254
+ previous = -1;
255
+ while ((current = key.indexOf('.', previous + 1)) >= 0) {
256
+ if (current - previous < 2 || current === last) return false;
257
+ previous = current;
258
+ }
259
+ return true;
260
+ }
261
+
262
+ function isPlainObject(subject: unknown) {
263
+ if (typeof subject === 'object' && subject !== null) {
264
+ const prototype = Object.getPrototypeOf(subject);
265
+ if (prototype === Object.prototype || prototype === null) {
266
+ return true;
267
+ }
268
+ }
269
+ return false;
270
+ }
271
+
272
+ function deepSet(context, key, value) {
273
+ const separator = key.indexOf('.');
274
+ if (separator >= 0) {
275
+ const subKey = key.slice(0, separator);
276
+ let subContext = context[subKey];
277
+ if (typeof subContext !== 'object' || subContext === null) {
278
+ const subContextValue = subContext;
279
+ subContext = {};
280
+ if (typeof subContextValue !== 'undefined') {
281
+ subContext[''] = subContextValue;
282
+ }
283
+ context[subKey] = subContext;
284
+ }
285
+ deepSet(subContext, key.slice(separator + 1, key.length), value);
286
+ } else {
287
+ context[key] = value;
288
+ }
289
+ }
290
+
291
+ /**
292
+ * Initial Settings for the repository
293
+ */
294
+ Settings.getDefaultSettings().set('useCursors', true);