@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,66 @@
1
+ import * as colors from '../colors/index';
2
+ import now from './now';
3
+ import type { IImage, CPUFallbackLookupTable } from '../../../../types';
4
+
5
+ /**
6
+ *
7
+ * @param {Image} image A Cornerstone Image Object
8
+ * @param {Array} grayscaleLut Lookup table array
9
+ * @param {LookupTable|Array} colorLUT Lookup table array
10
+ * @param {Uint8ClampedArray} canvasImageDataData canvasImageData.data buffer filled with white pixels
11
+ *
12
+ * @returns {void}
13
+ * @memberof Internal
14
+ */
15
+ function storedPixelDataToCanvasImageDataPseudocolorLUT(
16
+ image: IImage,
17
+ grayscaleLut: Uint8ClampedArray,
18
+ colorLUT: CPUFallbackLookupTable,
19
+ canvasImageDataData: Uint8ClampedArray
20
+ ): void {
21
+ let start = now();
22
+ const pixelData = image.getPixelData();
23
+
24
+ image.stats.lastGetPixelDataTime = now() - start;
25
+
26
+ const numPixels = pixelData.length;
27
+ const minPixelValue = image.minPixelValue;
28
+ let canvasImageDataIndex = 0;
29
+ let storedPixelDataIndex = 0;
30
+ let grayscale;
31
+ let rgba;
32
+ let clut;
33
+
34
+ start = now();
35
+
36
+ if (colorLUT instanceof colors.LookupTable) {
37
+ clut = colorLUT.Table;
38
+ } else {
39
+ clut = colorLUT;
40
+ }
41
+
42
+ if (minPixelValue < 0) {
43
+ while (storedPixelDataIndex < numPixels) {
44
+ grayscale =
45
+ grayscaleLut[pixelData[storedPixelDataIndex++] + -minPixelValue];
46
+ rgba = clut[grayscale];
47
+ canvasImageDataData[canvasImageDataIndex++] = rgba[0];
48
+ canvasImageDataData[canvasImageDataIndex++] = rgba[1];
49
+ canvasImageDataData[canvasImageDataIndex++] = rgba[2];
50
+ canvasImageDataData[canvasImageDataIndex++] = rgba[3];
51
+ }
52
+ } else {
53
+ while (storedPixelDataIndex < numPixels) {
54
+ grayscale = grayscaleLut[pixelData[storedPixelDataIndex++]];
55
+ rgba = clut[grayscale];
56
+ canvasImageDataData[canvasImageDataIndex++] = rgba[0];
57
+ canvasImageDataData[canvasImageDataIndex++] = rgba[1];
58
+ canvasImageDataData[canvasImageDataIndex++] = rgba[2];
59
+ canvasImageDataData[canvasImageDataIndex++] = rgba[3];
60
+ }
61
+ }
62
+
63
+ image.stats.lastStoredPixelDataToCanvasImageDataTime = now() - start;
64
+ }
65
+
66
+ export default storedPixelDataToCanvasImageDataPseudocolorLUT;
@@ -0,0 +1,68 @@
1
+ import * as colors from '../colors/index';
2
+ import now from './now';
3
+ import type { IImage, CPUFallbackLookupTable } from '../../../../types';
4
+
5
+ /**
6
+ *
7
+ * @param {Image} image A Cornerstone Image Object
8
+ * @param {Array} grayscaleLut Lookup table array
9
+ * @param {LookupTable|Array} colorLUT Lookup table array
10
+ * @param {Uint8ClampedArray} canvasImageDataData canvasImageData.data buffer filled with white pixels
11
+ *
12
+ * @returns {void}
13
+ * @memberof Internal
14
+ */
15
+ function storedPixelDataToCanvasImageDataPseudocolorLUTPET(
16
+ image: IImage,
17
+ lutFunction: (value: number) => number,
18
+ colorLUT: CPUFallbackLookupTable,
19
+ canvasImageDataData: Uint8ClampedArray
20
+ ): void {
21
+ let start = now();
22
+ const pixelData = image.getPixelData();
23
+
24
+ image.stats.lastGetPixelDataTime = now() - start;
25
+
26
+ const numPixels = pixelData.length;
27
+ const minPixelValue = image.minPixelValue;
28
+ let canvasImageDataIndex = 0;
29
+ let storedPixelDataIndex = 0;
30
+ let grayscale;
31
+ let rgba;
32
+ let clut;
33
+
34
+ start = now();
35
+
36
+ if (colorLUT instanceof colors.LookupTable) {
37
+ clut = colorLUT.Table;
38
+ } else {
39
+ clut = colorLUT;
40
+ }
41
+
42
+ if (minPixelValue < 0) {
43
+ while (storedPixelDataIndex < numPixels) {
44
+ grayscale = lutFunction(
45
+ pixelData[storedPixelDataIndex++] + -minPixelValue
46
+ );
47
+
48
+ rgba = clut[grayscale];
49
+ canvasImageDataData[canvasImageDataIndex++] = rgba[0];
50
+ canvasImageDataData[canvasImageDataIndex++] = rgba[1];
51
+ canvasImageDataData[canvasImageDataIndex++] = rgba[2];
52
+ canvasImageDataData[canvasImageDataIndex++] = rgba[3];
53
+ }
54
+ } else {
55
+ while (storedPixelDataIndex < numPixels) {
56
+ grayscale = lutFunction(pixelData[storedPixelDataIndex++]);
57
+ rgba = clut[grayscale];
58
+ canvasImageDataData[canvasImageDataIndex++] = rgba[0];
59
+ canvasImageDataData[canvasImageDataIndex++] = rgba[1];
60
+ canvasImageDataData[canvasImageDataIndex++] = rgba[2];
61
+ canvasImageDataData[canvasImageDataIndex++] = rgba[3];
62
+ }
63
+ }
64
+
65
+ image.stats.lastStoredPixelDataToCanvasImageDataTime = now() - start;
66
+ }
67
+
68
+ export default storedPixelDataToCanvasImageDataPseudocolorLUTPET;
@@ -0,0 +1,81 @@
1
+ import now from './now';
2
+ import { IImage } from '../../../../types';
3
+
4
+ /**
5
+ * This function transforms stored pixel values into a canvas image data buffer
6
+ * by using a LUT.
7
+ *
8
+ * @param {Image} image A Cornerstone Image Object
9
+ * @param {Array} lut Lookup table array
10
+ * @param {Uint8ClampedArray} canvasImageDataData canvasImageData.data buffer filled with white pixels
11
+ *
12
+ * @returns {void}
13
+ * @memberof Internal
14
+ */
15
+ export default function (
16
+ image: IImage,
17
+ lut: Uint8ClampedArray,
18
+ canvasImageDataData: Uint8ClampedArray
19
+ ): void {
20
+ let start = now();
21
+ const pixelData = image.getPixelData();
22
+
23
+ image.stats.lastGetPixelDataTime = now() - start;
24
+
25
+ const numPixels = pixelData.length;
26
+ const minPixelValue = image.minPixelValue;
27
+ let canvasImageDataIndex = 0;
28
+ let storedPixelDataIndex = 0;
29
+ let pixelValue;
30
+
31
+ // NOTE: As of Nov 2014, most javascript engines have lower performance when indexing negative indexes.
32
+ // We have a special code path for this case that improves performance. Thanks to @jpambrun for this enhancement
33
+
34
+ // Added two paths (Int16Array, Uint16Array) to avoid polymorphic deoptimization in chrome.
35
+ start = now();
36
+ if (pixelData instanceof Int16Array) {
37
+ if (minPixelValue < 0) {
38
+ while (storedPixelDataIndex < numPixels) {
39
+ pixelValue = lut[pixelData[storedPixelDataIndex++] + -minPixelValue];
40
+ canvasImageDataData[canvasImageDataIndex++] = pixelValue;
41
+ canvasImageDataData[canvasImageDataIndex++] = pixelValue;
42
+ canvasImageDataData[canvasImageDataIndex++] = pixelValue;
43
+ canvasImageDataData[canvasImageDataIndex++] = 255; // Alpha
44
+ }
45
+ } else {
46
+ while (storedPixelDataIndex < numPixels) {
47
+ pixelValue = lut[pixelData[storedPixelDataIndex++]];
48
+ canvasImageDataData[canvasImageDataIndex++] = pixelValue;
49
+ canvasImageDataData[canvasImageDataIndex++] = pixelValue;
50
+ canvasImageDataData[canvasImageDataIndex++] = pixelValue;
51
+ canvasImageDataData[canvasImageDataIndex++] = 255; // Alpha
52
+ }
53
+ }
54
+ } else if (pixelData instanceof Uint16Array) {
55
+ while (storedPixelDataIndex < numPixels) {
56
+ pixelValue = lut[pixelData[storedPixelDataIndex++]];
57
+ canvasImageDataData[canvasImageDataIndex++] = pixelValue;
58
+ canvasImageDataData[canvasImageDataIndex++] = pixelValue;
59
+ canvasImageDataData[canvasImageDataIndex++] = pixelValue;
60
+ canvasImageDataData[canvasImageDataIndex++] = 255; // Alpha
61
+ }
62
+ } else if (minPixelValue < 0) {
63
+ while (storedPixelDataIndex < numPixels) {
64
+ pixelValue = lut[pixelData[storedPixelDataIndex++] + -minPixelValue];
65
+ canvasImageDataData[canvasImageDataIndex++] = pixelValue;
66
+ canvasImageDataData[canvasImageDataIndex++] = pixelValue;
67
+ canvasImageDataData[canvasImageDataIndex++] = pixelValue;
68
+ canvasImageDataData[canvasImageDataIndex++] = 255; // Alpha
69
+ }
70
+ } else {
71
+ while (storedPixelDataIndex < numPixels) {
72
+ pixelValue = lut[pixelData[storedPixelDataIndex++]];
73
+ canvasImageDataData[canvasImageDataIndex++] = pixelValue;
74
+ canvasImageDataData[canvasImageDataIndex++] = pixelValue;
75
+ canvasImageDataData[canvasImageDataIndex++] = pixelValue;
76
+ canvasImageDataData[canvasImageDataIndex++] = 255; // Alpha
77
+ }
78
+ }
79
+
80
+ image.stats.lastStoredPixelDataToCanvasImageDataTime = now() - start;
81
+ }
@@ -0,0 +1,56 @@
1
+ import now from './now';
2
+ import { IImage } from '../../../../types';
3
+
4
+ /**
5
+ * Converts stored RGBA color pixel values to display pixel values using a LUT.
6
+ *
7
+ * @param {Image} image A Cornerstone Image Object
8
+ * @param {Array} lut Lookup table array
9
+ * @param {Uint8ClampedArray} canvasImageDataData canvasImageData.data buffer filled with white pixels
10
+ *
11
+ * @returns {void}
12
+ * @memberof Internal
13
+ */
14
+ export default function (
15
+ image: IImage,
16
+ lut: Uint8ClampedArray,
17
+ canvasImageDataData: Uint8ClampedArray
18
+ ): void {
19
+ let start = now();
20
+ const pixelData = image.getPixelData();
21
+
22
+ image.stats.lastGetPixelDataTime = now() - start;
23
+
24
+ const minPixelValue = image.minPixelValue;
25
+ let canvasImageDataIndex = 0;
26
+ let storedPixelDataIndex = 0;
27
+ const numPixels = pixelData.length;
28
+
29
+ // NOTE: As of Nov 2014, most javascript engines have lower performance when indexing negative indexes.
30
+ // We have a special code path for this case that improves performance. Thanks to @jpambrun for this enhancement
31
+ start = now();
32
+ if (minPixelValue < 0) {
33
+ while (storedPixelDataIndex < numPixels) {
34
+ canvasImageDataData[canvasImageDataIndex++] =
35
+ lut[pixelData[storedPixelDataIndex++] + -minPixelValue]; // Red
36
+ canvasImageDataData[canvasImageDataIndex++] =
37
+ lut[pixelData[storedPixelDataIndex++] + -minPixelValue]; // Green
38
+ canvasImageDataData[canvasImageDataIndex++] =
39
+ lut[pixelData[storedPixelDataIndex++] + -minPixelValue]; // Blue
40
+ canvasImageDataData[canvasImageDataIndex++] =
41
+ pixelData[storedPixelDataIndex++];
42
+ }
43
+ } else {
44
+ while (storedPixelDataIndex < numPixels) {
45
+ canvasImageDataData[canvasImageDataIndex++] =
46
+ lut[pixelData[storedPixelDataIndex++]]; // Red
47
+ canvasImageDataData[canvasImageDataIndex++] =
48
+ lut[pixelData[storedPixelDataIndex++]]; // Green
49
+ canvasImageDataData[canvasImageDataIndex++] =
50
+ lut[pixelData[storedPixelDataIndex++]]; // Blue
51
+ canvasImageDataData[canvasImageDataIndex++] =
52
+ pixelData[storedPixelDataIndex++];
53
+ }
54
+ }
55
+ image.stats.lastStoredPixelDataToCanvasImageDataTime = now() - start;
56
+ }
@@ -0,0 +1,126 @@
1
+ import {
2
+ CPUFallbackTransform,
3
+ Point2,
4
+ TransformMatrix2D,
5
+ } from '../../../../types';
6
+
7
+ // By Simon Sarris
8
+ // Www.simonsarris.com
9
+ // Sarris@acm.org
10
+ //
11
+ // Free to use and distribute at will
12
+ // So long as you are nice to people, etc
13
+
14
+ // Simple class for keeping track of the current transformation matrix
15
+
16
+ // For instance:
17
+ // Var t = new Transform();
18
+ // T.rotate(5);
19
+ // Var m = t.m;
20
+ // Ctx.setTransform(m[0], m[1], m[2], m[3], m[4], m[5]);
21
+
22
+ // Is equivalent to:
23
+ // Ctx.rotate(5);
24
+
25
+ // But now you can retrieve it :)
26
+
27
+ // Remember that this does not account for any CSS transforms applied to the canvas
28
+ export class Transform implements CPUFallbackTransform {
29
+ private m: TransformMatrix2D;
30
+
31
+ constructor() {
32
+ this.reset();
33
+ }
34
+
35
+ getMatrix(): TransformMatrix2D {
36
+ return this.m;
37
+ }
38
+
39
+ reset(): void {
40
+ this.m = [1, 0, 0, 1, 0, 0];
41
+ }
42
+
43
+ clone(): CPUFallbackTransform {
44
+ const transform = new Transform();
45
+
46
+ transform.m[0] = this.m[0];
47
+ transform.m[1] = this.m[1];
48
+ transform.m[2] = this.m[2];
49
+ transform.m[3] = this.m[3];
50
+ transform.m[4] = this.m[4];
51
+ transform.m[5] = this.m[5];
52
+
53
+ return transform;
54
+ }
55
+
56
+ multiply(matrix: TransformMatrix2D): void {
57
+ const m11 = this.m[0] * matrix[0] + this.m[2] * matrix[1];
58
+ const m12 = this.m[1] * matrix[0] + this.m[3] * matrix[1];
59
+
60
+ const m21 = this.m[0] * matrix[2] + this.m[2] * matrix[3];
61
+ const m22 = this.m[1] * matrix[2] + this.m[3] * matrix[3];
62
+
63
+ const dx = this.m[0] * matrix[4] + this.m[2] * matrix[5] + this.m[4];
64
+ const dy = this.m[1] * matrix[4] + this.m[3] * matrix[5] + this.m[5];
65
+
66
+ this.m[0] = m11;
67
+ this.m[1] = m12;
68
+ this.m[2] = m21;
69
+ this.m[3] = m22;
70
+ this.m[4] = dx;
71
+ this.m[5] = dy;
72
+ }
73
+
74
+ invert(): void {
75
+ const d = 1 / (this.m[0] * this.m[3] - this.m[1] * this.m[2]);
76
+ const m0 = this.m[3] * d;
77
+ const m1 = -this.m[1] * d;
78
+ const m2 = -this.m[2] * d;
79
+ const m3 = this.m[0] * d;
80
+ const m4 = d * (this.m[2] * this.m[5] - this.m[3] * this.m[4]);
81
+ const m5 = d * (this.m[1] * this.m[4] - this.m[0] * this.m[5]);
82
+
83
+ this.m[0] = m0;
84
+ this.m[1] = m1;
85
+ this.m[2] = m2;
86
+ this.m[3] = m3;
87
+ this.m[4] = m4;
88
+ this.m[5] = m5;
89
+ }
90
+
91
+ rotate(rad: number): void {
92
+ const c = Math.cos(rad);
93
+ const s = Math.sin(rad);
94
+ const m11 = this.m[0] * c + this.m[2] * s;
95
+ const m12 = this.m[1] * c + this.m[3] * s;
96
+ const m21 = this.m[0] * -s + this.m[2] * c;
97
+ const m22 = this.m[1] * -s + this.m[3] * c;
98
+
99
+ this.m[0] = m11;
100
+ this.m[1] = m12;
101
+ this.m[2] = m21;
102
+ this.m[3] = m22;
103
+ }
104
+
105
+ translate(x: number, y: number): void {
106
+ this.m[4] += this.m[0] * x + this.m[2] * y;
107
+ this.m[5] += this.m[1] * x + this.m[3] * y;
108
+ }
109
+
110
+ scale(sx: number, sy: number) {
111
+ this.m[0] *= sx;
112
+ this.m[1] *= sx;
113
+ this.m[2] *= sy;
114
+ this.m[3] *= sy;
115
+ }
116
+
117
+ transformPoint(point: Point2): Point2 {
118
+ const x = point[0];
119
+ const y = point[1];
120
+
121
+ return [
122
+ x * this.m[0] + y * this.m[2] + this.m[4],
123
+ x * this.m[1] + y * this.m[3] + this.m[5],
124
+ ];
125
+ }
126
+ }
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Check if the supplied parameter is undefined and throws and error
3
+ * @param {any} checkParam the parameter to validate for undefined
4
+ * @param {any} errorMsg the error message to be thrown
5
+ * @returns {void}
6
+ * @memberof internal
7
+ */
8
+ export function validateParameterUndefined(
9
+ checkParam: any | undefined,
10
+ errorMsg: string
11
+ ): void {
12
+ if (checkParam === undefined) {
13
+ throw new Error(errorMsg);
14
+ }
15
+ }
16
+
17
+ /**
18
+ * Check if the supplied parameter is undefined or null and throws and error
19
+ * @param {any} checkParam the parameter to validate for undefined
20
+ * @param {any} errorMsg the error message to be thrown
21
+ * @returns {void}
22
+ * @memberof internal
23
+ */
24
+ export function validateParameterUndefinedOrNull(
25
+ checkParam: any | null | undefined,
26
+ errorMsg: string
27
+ ): void {
28
+ if (checkParam === undefined || checkParam === null) {
29
+ throw new Error(errorMsg);
30
+ }
31
+ }
@@ -0,0 +1,103 @@
1
+ import vtkVolume from '@kitware/vtk.js/Rendering/Core/Volume';
2
+
3
+ import { VolumeActor } from './../../types/IActor';
4
+ import { VoiModifiedEventDetail } from './../../types/EventTypes';
5
+ import { loadVolume } from '../../loaders/volumeLoader';
6
+ import createVolumeMapper from './createVolumeMapper';
7
+ import BlendModes from '../../enums/BlendModes';
8
+ import { triggerEvent } from '../../utilities';
9
+ import { Events } from '../../enums';
10
+ import setDefaultVolumeVOI from './setDefaultVolumeVOI';
11
+
12
+ interface createVolumeActorInterface {
13
+ volumeId: string;
14
+ callback?: ({
15
+ volumeActor,
16
+ volumeId,
17
+ }: {
18
+ volumeActor: VolumeActor;
19
+ volumeId: string;
20
+ }) => void;
21
+ blendMode?: BlendModes;
22
+ }
23
+
24
+ /**
25
+ * Given a volumeId, it creates a vtk volume actor and returns it. If
26
+ * callback is provided, it will be called with the volume actor and the
27
+ * volumeId. If blendMode is provided, it will be set on the volume actor.
28
+ *
29
+ * @param props - createVolumeActorInterface
30
+ * @returns A promise that resolves to a VolumeActor.
31
+ */
32
+ async function createVolumeActor(
33
+ props: createVolumeActorInterface,
34
+ element: HTMLDivElement,
35
+ viewportId: string,
36
+ suppressEvents = false,
37
+ use16BitTexture = false
38
+ ): Promise<VolumeActor> {
39
+ const { volumeId, callback, blendMode } = props;
40
+
41
+ const imageVolume = await loadVolume(volumeId);
42
+
43
+ if (!imageVolume) {
44
+ throw new Error(
45
+ `imageVolume with id: ${imageVolume.volumeId} does not exist`
46
+ );
47
+ }
48
+
49
+ const { imageData, vtkOpenGLTexture } = imageVolume;
50
+
51
+ const volumeMapper = createVolumeMapper(imageData, vtkOpenGLTexture);
52
+
53
+ if (blendMode) {
54
+ volumeMapper.setBlendMode(blendMode);
55
+ }
56
+
57
+ const volumeActor = vtkVolume.newInstance();
58
+ volumeActor.setMapper(volumeMapper);
59
+
60
+ // If the volume is composed of imageIds, we can apply a default VOI based
61
+ // on either the metadata or the min/max of the middle slice. Example of other
62
+ // types of volumes which might not be composed of imageIds would be e.g., nrrd, nifti
63
+ // format volumes
64
+ if (imageVolume.imageIds) {
65
+ await setDefaultVolumeVOI(volumeActor, imageVolume, use16BitTexture);
66
+ }
67
+
68
+ if (callback) {
69
+ callback({ volumeActor, volumeId });
70
+ }
71
+
72
+ if (!suppressEvents) {
73
+ triggerVOIModified(element, viewportId, volumeActor, volumeId);
74
+ }
75
+
76
+ return volumeActor;
77
+ }
78
+
79
+ function triggerVOIModified(
80
+ element: HTMLDivElement,
81
+ viewportId: string,
82
+ volumeActor: VolumeActor,
83
+ volumeId: string
84
+ ) {
85
+ const voiRange = volumeActor
86
+ .getProperty()
87
+ .getRGBTransferFunction(0)
88
+ // @ts-ignore: vtk d ts problem
89
+ .getRange();
90
+
91
+ const voiModifiedEventDetail: VoiModifiedEventDetail = {
92
+ viewportId,
93
+ range: {
94
+ lower: voiRange[0],
95
+ upper: voiRange[1],
96
+ },
97
+ volumeId,
98
+ };
99
+
100
+ triggerEvent(element, Events.VOI_MODIFIED, voiModifiedEventDetail);
101
+ }
102
+
103
+ export default createVolumeActor;
@@ -0,0 +1,37 @@
1
+ import { vtkSharedVolumeMapper } from '../vtkClasses';
2
+ import { getConfiguration } from '../../init';
3
+ /**
4
+ * Given an imageData and a vtkOpenGLTexture, it creates a "shared" vtk volume mapper
5
+ * from which various volume actors can be created.
6
+ *
7
+ * @param imageData - the vtkImageData object that contains the data to
8
+ * render.
9
+ * @param vtkOpenGLTexture - The vtkOpenGLTexture that will be used to render
10
+ * the volume.
11
+ * @returns The volume mapper.
12
+ */
13
+ export default function createVolumeMapper(
14
+ imageData: any,
15
+ vtkOpenGLTexture: any
16
+ ): any {
17
+ const volumeMapper = vtkSharedVolumeMapper.newInstance();
18
+
19
+ if (getConfiguration().rendering.preferSizeOverAccuracy) {
20
+ volumeMapper.setPreferSizeOverAccuracy(true);
21
+ }
22
+
23
+ volumeMapper.setInputData(imageData);
24
+
25
+ const spacing = imageData.getSpacing();
26
+ // Set the sample distance to half the mean length of one side. This is where the divide by 6 comes from.
27
+ // https://github.com/Kitware/VTK/blob/6b559c65bb90614fb02eb6d1b9e3f0fca3fe4b0b/Rendering/VolumeOpenGL2/vtkSmartVolumeMapper.cxx#L344
28
+ const sampleDistance = (spacing[0] + spacing[1] + spacing[2]) / 6;
29
+
30
+ // This is to allow for good pixel level image quality.
31
+ // Todo: why we are setting this to 4000? Is this a good number? it should be configurable
32
+ volumeMapper.setMaximumSamplesPerRay(4000);
33
+ volumeMapper.setSampleDistance(sampleDistance);
34
+ volumeMapper.setScalarTexture(vtkOpenGLTexture);
35
+
36
+ return volumeMapper;
37
+ }
@@ -0,0 +1,58 @@
1
+ const VIEWPORT_ELEMENT = 'viewport-element';
2
+ const CANVAS_CSS_CLASS = 'cornerstone-canvas';
3
+
4
+ /**
5
+ * Create a canvas and append it to the element
6
+ *
7
+ * @param element - An HTML Element
8
+ * @returns canvas - A Canvas DOM element
9
+ */
10
+ function createCanvas(element: Element | HTMLDivElement): HTMLCanvasElement {
11
+ const canvas = document.createElement('canvas');
12
+
13
+ canvas.style.position = 'absolute';
14
+ canvas.style.width = '100%';
15
+ canvas.style.height = '100%';
16
+ canvas.classList.add(CANVAS_CSS_CLASS);
17
+ element.appendChild(canvas);
18
+
19
+ return canvas;
20
+ }
21
+
22
+ /**
23
+ * Creates an internal div that will contain canvas and SVG layer as children
24
+ * @param element - An HTML Element
25
+ * @returns div Cornerstone internal div that will include the canvas and SVG
26
+ * as its children
27
+ */
28
+ export function createViewportElement(element: HTMLDivElement): HTMLDivElement {
29
+ const div = document.createElement('div');
30
+ div.style.position = 'relative';
31
+ div.style.width = '100%';
32
+ div.style.height = '100%';
33
+ div.classList.add(VIEWPORT_ELEMENT);
34
+ element.appendChild(div);
35
+
36
+ return div;
37
+ }
38
+
39
+ /**
40
+ * Create a canvas or returns the one that already exists for a given element.
41
+ * It first checks if the element has a canvas, if not it creates one and returns it.
42
+ *
43
+ * @param element - An HTML Element
44
+ * @returns canvas a Canvas DOM element
45
+ */
46
+ export default function getOrCreateCanvas(
47
+ element: HTMLDivElement
48
+ ): HTMLCanvasElement {
49
+ const canvasSelector = `canvas.${CANVAS_CSS_CLASS}`;
50
+ const viewportElement = `div.${VIEWPORT_ELEMENT}`;
51
+
52
+ // Internal div with `relative` positioning to enable absolute positioning
53
+ // of the canvas and svg layer.
54
+ const internalDiv =
55
+ element.querySelector(viewportElement) || createViewportElement(element);
56
+
57
+ return internalDiv.querySelector(canvasSelector) || createCanvas(internalDiv);
58
+ }
@@ -0,0 +1,15 @@
1
+ import createVolumeActor from './createVolumeActor';
2
+ import createVolumeMapper from './createVolumeMapper';
3
+ import getOrCreateCanvas from './getOrCreateCanvas';
4
+ import setVolumesForViewports from './setVolumesForViewports';
5
+ import addVolumesToViewports from './addVolumesToViewports';
6
+ import volumeNewImageEventDispatcher from './volumeNewImageEventDispatcher';
7
+
8
+ export {
9
+ createVolumeActor,
10
+ createVolumeMapper,
11
+ getOrCreateCanvas,
12
+ setVolumesForViewports,
13
+ addVolumesToViewports,
14
+ volumeNewImageEventDispatcher,
15
+ };
@@ -0,0 +1 @@
1
+ export default (src, dest) => src.length * 3 === dest.byteLength * 4;