@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,469 @@
1
+ import { Point2, Point4, CPUFallbackLookupTable } from '../../../../types';
2
+
3
+ // This code was created based on vtkLookupTable
4
+ // http://www.vtk.org/doc/release/5.0/html/a01697.html
5
+ // https://github.com/Kitware/VTK/blob/master/Common/Core/vtkLookupTable.cxx
6
+ const BELOW_RANGE_COLOR_INDEX = 0;
7
+ const ABOVE_RANGE_COLOR_INDEX = 1;
8
+ const NAN_COLOR_INDEX = 2;
9
+
10
+ /**
11
+ * Converts an HSV (Hue, Saturation, Value) color to RGB (Red, Green, Blue) color value
12
+ * @param {Number} hue A number representing the hue color value
13
+ * @param {any} sat A number representing the saturation color value
14
+ * @param {any} val A number representing the value color value
15
+ * @returns {Numberp[]} An RGB color array
16
+ */
17
+ function HSVToRGB(hue, sat, val) {
18
+ if (hue > 1) {
19
+ throw new Error('HSVToRGB expects hue < 1');
20
+ }
21
+
22
+ const rgb = [];
23
+
24
+ if (sat === 0) {
25
+ rgb[0] = val;
26
+ rgb[1] = val;
27
+ rgb[2] = val;
28
+
29
+ return rgb;
30
+ }
31
+
32
+ const hueCase = Math.floor(hue * 6);
33
+ const frac = 6 * hue - hueCase;
34
+ const lx = val * (1 - sat);
35
+ const ly = val * (1 - sat * frac);
36
+ const lz = val * (1 - sat * (1 - frac));
37
+
38
+ switch (hueCase) {
39
+ /* 0<hue<1/6 */
40
+ case 0:
41
+ case 6:
42
+ rgb[0] = val;
43
+ rgb[1] = lz;
44
+ rgb[2] = lx;
45
+ break;
46
+
47
+ /* 1/6<hue<2/6 */
48
+ case 1:
49
+ rgb[0] = ly;
50
+ rgb[1] = val;
51
+ rgb[2] = lx;
52
+ break;
53
+
54
+ /* 2/6<hue<3/6 */
55
+ case 2:
56
+ rgb[0] = lx;
57
+ rgb[1] = val;
58
+ rgb[2] = lz;
59
+ break;
60
+
61
+ /* 3/6<hue/4/6 */
62
+ case 3:
63
+ rgb[0] = lx;
64
+ rgb[1] = ly;
65
+ rgb[2] = val;
66
+ break;
67
+
68
+ /* 4/6<hue<5/6 */
69
+ case 4:
70
+ rgb[0] = lz;
71
+ rgb[1] = lx;
72
+ rgb[2] = val;
73
+ break;
74
+
75
+ /* 5/6<hue<1 */
76
+ case 5:
77
+ rgb[0] = val;
78
+ rgb[1] = lx;
79
+ rgb[2] = ly;
80
+ break;
81
+ }
82
+
83
+ return rgb;
84
+ }
85
+
86
+ /**
87
+ * Maps a value to an index in the table
88
+ * @param {Number} v A double value which table index will be returned.
89
+ * @param {any} p An object that contains the Table "Range", the table "MaxIndex",
90
+ * A "Shift" from first value in the table and the table "Scale" value
91
+ * @returns {Number} The mapped index in the table
92
+ * @memberof Colors
93
+ */
94
+ function linearIndexLookupMain(v, p) {
95
+ let dIndex;
96
+
97
+ // NOTE: Added Math.floor since values were not integers? Check VTK source
98
+ if (v < p.Range[0]) {
99
+ dIndex = p.MaxIndex + BELOW_RANGE_COLOR_INDEX + 1.5;
100
+ } else if (v > p.Range[1]) {
101
+ dIndex = p.MaxIndex + ABOVE_RANGE_COLOR_INDEX + 1.5;
102
+ } else {
103
+ dIndex = (v + p.Shift) * p.Scale;
104
+ }
105
+
106
+ return Math.floor(dIndex);
107
+ }
108
+
109
+ /**
110
+ * Maps scalar values into colors via a lookup table
111
+ * LookupTable is an object that is used by mapper objects to map scalar values into rgba (red-green-blue-alpha transparency) color specification,
112
+ * or rgba into scalar values. The color table can be created by direct insertion of color values, or by specifying hue, saturation, value, and alpha range and generating a table
113
+ */
114
+ class LookupTable implements CPUFallbackLookupTable {
115
+ NumberOfColors: number;
116
+ Ramp: string;
117
+ TableRange: Point2;
118
+ HueRange: Point2;
119
+ SaturationRange: Point2;
120
+ ValueRange: Point2;
121
+ AlphaRange: Point2;
122
+ NaNColor: Point4;
123
+ BelowRangeColor: Point4;
124
+ UseBelowRangeColor: boolean;
125
+ AboveRangeColor: Point4;
126
+ UseAboveRangeColor: boolean;
127
+ InputRange: Point2;
128
+ Table: Point4[];
129
+
130
+ /**
131
+ * Creates a default linear LookupTable object with 256 colors.
132
+ */
133
+ constructor() {
134
+ this.NumberOfColors = 256;
135
+ this.Ramp = 'linear';
136
+ this.TableRange = [0, 255];
137
+ this.HueRange = [0, 0.66667];
138
+ this.SaturationRange = [1, 1];
139
+ this.ValueRange = [1, 1];
140
+ this.AlphaRange = [1, 1];
141
+ this.NaNColor = [128, 0, 0, 255];
142
+ this.BelowRangeColor = [0, 0, 0, 255];
143
+ this.UseBelowRangeColor = true;
144
+ this.AboveRangeColor = [255, 255, 255, 255];
145
+ this.UseAboveRangeColor = true;
146
+ this.InputRange = [0, 255];
147
+ this.Table = [];
148
+ }
149
+
150
+ /**
151
+ * Specify the number of values (i.e., colors) in the lookup table.
152
+ * @param {Number} number The number of colors in he LookupTable
153
+ * @returns {void}
154
+ * @memberof Colors
155
+ */
156
+ public setNumberOfTableValues(number) {
157
+ this.NumberOfColors = number;
158
+ }
159
+
160
+ /**
161
+ * Set the shape of the table ramp to either 'linear', 'scurve' or 'sqrt'
162
+ * @param {String} ramp A string value representing the shape of the table. Allowed values are 'linear', 'scurve' or 'sqrt'
163
+ * @returns {void}
164
+ * @memberof Colors
165
+ */
166
+ public setRamp(ramp) {
167
+ this.Ramp = ramp;
168
+ }
169
+
170
+ /**
171
+ * Sets the minimum/maximum scalar values for scalar mapping.
172
+ * Scalar values less than minimum range value are clamped to minimum range value.
173
+ * Scalar values greater than maximum range value are clamped to maximum range value.
174
+ * @param {Number} start A double representing the minimum scaler value of the LookupTable
175
+ * @param {any} end A double representing the maximum scaler value of the LookupTable
176
+ * @returns {void}
177
+ * @memberof Colors
178
+ */
179
+ public setTableRange(start, end) {
180
+ this.TableRange[0] = start;
181
+ this.TableRange[1] = end;
182
+ }
183
+
184
+ /**
185
+ * Set the range in hue (using automatic generation). Hue ranges between [0,1].
186
+ * @param {Number} start A double representing the minimum hue value in a range. Min. is 0
187
+ * @param {Number} end A double representing the maximum hue value in a range. Max. is 1
188
+ * @returns {void}
189
+ * @memberof Colors
190
+ */
191
+ public setHueRange(start, end) {
192
+ this.HueRange[0] = start;
193
+ this.HueRange[1] = end;
194
+ }
195
+
196
+ /**
197
+ * Set the range in saturation (using automatic generation). Saturation ranges between [0,1].
198
+ * @param {Number} start A double representing the minimum Saturation value in a range. Min. is 0
199
+ * @param {Number} end A double representing the maximum Saturation value in a range. Max. is 1
200
+ * @returns {void}
201
+ * @memberof Colors
202
+ */
203
+ public setSaturationRange(start, end) {
204
+ this.SaturationRange[0] = start;
205
+ this.SaturationRange[1] = end;
206
+ }
207
+
208
+ /**
209
+ * Set the range in value (using automatic generation). Value ranges between [0,1].
210
+ * @param {Numeber } start A double representing the minimum value in a range. Min. is 0
211
+ * @param {Numeber} end A double representing the maximum value in a range. Max. is 1
212
+ * @returns {void}
213
+ * @memberof Colors
214
+ */
215
+ public setValueRange(start, end) {
216
+ // Set the range in value (using automatic generation). Value ranges between [0,1].
217
+ this.ValueRange[0] = start;
218
+ this.ValueRange[1] = end;
219
+ }
220
+
221
+ /**
222
+ * (Not Used) Sets the range of scalars which will be mapped.
223
+ * @param {Number} start the minimum scalar value in the range
224
+ * @param {Number} end the maximum scalar value in the range
225
+ * @returns {void}
226
+ * @memberof Colors
227
+ */
228
+ public setRange(start, end) {
229
+ this.InputRange[0] = start;
230
+ this.InputRange[1] = end;
231
+ }
232
+
233
+ /**
234
+ * Set the range in alpha (using automatic generation). Alpha ranges from [0,1].
235
+ * @param {Number} start A double representing the minimum alpha value
236
+ * @param {Number} end A double representing the maximum alpha value
237
+ * @returns {void}
238
+ * @memberof Colors
239
+ */
240
+ public setAlphaRange(start, end) {
241
+ // Set the range in alpha (using automatic generation). Alpha ranges from [0,1].
242
+ this.AlphaRange[0] = start;
243
+ this.AlphaRange[1] = end;
244
+ }
245
+
246
+ /**
247
+ * Map one value through the lookup table and return the color as an
248
+ * RGBA array of doubles between 0 and 1.
249
+ * @param {Number} scalar A double scalar value which will be mapped to a color in the LookupTable
250
+ * @returns {Number[]} An RGBA array of doubles between 0 and 1
251
+ * @memberof Colors
252
+ */
253
+ public getColor(scalar) {
254
+ return this.mapValue(scalar);
255
+ }
256
+
257
+ /**
258
+ * Generate lookup table from hue, saturation, value, alpha min/max values. Table is built from linear ramp of each value.
259
+ * @param {Boolean} force true to force the build of the LookupTable. Otherwie, false. This is useful if a lookup table has been defined manually
260
+ * (using SetTableValue) and then an application decides to rebuild the lookup table using the implicit process.
261
+ * @returns {void}
262
+ * @memberof Colors
263
+ */
264
+ public build(force) {
265
+ if (this.Table.length > 1 && !force) {
266
+ return;
267
+ }
268
+
269
+ // Clear the table
270
+ this.Table = [];
271
+
272
+ const maxIndex = this.NumberOfColors - 1;
273
+
274
+ let hinc, sinc, vinc, ainc;
275
+
276
+ if (maxIndex) {
277
+ hinc = (this.HueRange[1] - this.HueRange[0]) / maxIndex;
278
+ sinc = (this.SaturationRange[1] - this.SaturationRange[0]) / maxIndex;
279
+ vinc = (this.ValueRange[1] - this.ValueRange[0]) / maxIndex;
280
+ ainc = (this.AlphaRange[1] - this.AlphaRange[0]) / maxIndex;
281
+ } else {
282
+ hinc = sinc = vinc = ainc = 0.0;
283
+ }
284
+
285
+ for (let i = 0; i <= maxIndex; i++) {
286
+ const hue = this.HueRange[0] + i * hinc;
287
+ const sat = this.SaturationRange[0] + i * sinc;
288
+ const val = this.ValueRange[0] + i * vinc;
289
+ const alpha = this.AlphaRange[0] + i * ainc;
290
+
291
+ const rgb = HSVToRGB(hue, sat, val);
292
+ const c_rgba: Point4 = [0, 0, 0, 0];
293
+
294
+ switch (this.Ramp) {
295
+ case 'scurve':
296
+ c_rgba[0] = Math.floor(
297
+ 127.5 * (1.0 + Math.cos((1.0 - rgb[0]) * Math.PI))
298
+ );
299
+ c_rgba[1] = Math.floor(
300
+ 127.5 * (1.0 + Math.cos((1.0 - rgb[1]) * Math.PI))
301
+ );
302
+ c_rgba[2] = Math.floor(
303
+ 127.5 * (1.0 + Math.cos((1.0 - rgb[2]) * Math.PI))
304
+ );
305
+ c_rgba[3] = Math.floor(alpha * 255);
306
+ break;
307
+ case 'linear':
308
+ c_rgba[0] = Math.floor(rgb[0] * 255 + 0.5);
309
+ c_rgba[1] = Math.floor(rgb[1] * 255 + 0.5);
310
+ c_rgba[2] = Math.floor(rgb[2] * 255 + 0.5);
311
+ c_rgba[3] = Math.floor(alpha * 255 + 0.5);
312
+ break;
313
+ case 'sqrt':
314
+ c_rgba[0] = Math.floor(Math.sqrt(rgb[0]) * 255 + 0.5);
315
+ c_rgba[1] = Math.floor(Math.sqrt(rgb[1]) * 255 + 0.5);
316
+ c_rgba[2] = Math.floor(Math.sqrt(rgb[2]) * 255 + 0.5);
317
+ c_rgba[3] = Math.floor(Math.sqrt(alpha) * 255 + 0.5);
318
+ break;
319
+ default:
320
+ throw new Error(`Invalid Ramp value (${this.Ramp})`);
321
+ }
322
+
323
+ this.Table.push(c_rgba);
324
+ }
325
+
326
+ this.buildSpecialColors();
327
+ }
328
+
329
+ /**
330
+ * Ensures the out-of-range colors (Below range and Above range) are set correctly.
331
+ * @returns {void}
332
+ * @memberof Colors
333
+ */
334
+ private buildSpecialColors() {
335
+ const numberOfColors = this.NumberOfColors;
336
+ const belowRangeColorIndex = numberOfColors + BELOW_RANGE_COLOR_INDEX;
337
+ const aboveRangeColorIndex = numberOfColors + ABOVE_RANGE_COLOR_INDEX;
338
+ const nanColorIndex = numberOfColors + NAN_COLOR_INDEX;
339
+
340
+ // Below range color
341
+ if (this.UseBelowRangeColor || numberOfColors === 0) {
342
+ this.Table[belowRangeColorIndex] = this.BelowRangeColor;
343
+ } else {
344
+ // Duplicate the first color in the table.
345
+ this.Table[belowRangeColorIndex] = this.Table[0];
346
+ }
347
+
348
+ // Above range color
349
+ if (this.UseAboveRangeColor || numberOfColors === 0) {
350
+ this.Table[aboveRangeColorIndex] = this.AboveRangeColor;
351
+ } else {
352
+ // Duplicate the last color in the table.
353
+ this.Table[aboveRangeColorIndex] = this.Table[numberOfColors - 1];
354
+ }
355
+
356
+ // Always use NanColor
357
+ this.Table[nanColorIndex] = this.NaNColor;
358
+ }
359
+
360
+ /**
361
+ * Similar to GetColor - Map one value through the lookup table and return the color as an
362
+ * RGBA array of doubles between 0 and 1.
363
+ * @param {Numeber} v A double scalar value which will be mapped to a color in the LookupTable
364
+ * @returns {Number[]} An RGBA array of doubles between 0 and 1
365
+ * @memberof Colors
366
+ */
367
+ private mapValue(v) {
368
+ const index = this.getIndex(v);
369
+
370
+ if (index < 0) {
371
+ return this.NaNColor;
372
+ } else if (index === 0) {
373
+ if (this.UseBelowRangeColor && v < this.TableRange[0]) {
374
+ return this.BelowRangeColor;
375
+ }
376
+ } else if (index === this.NumberOfColors - 1) {
377
+ if (this.UseAboveRangeColor && v > this.TableRange[1]) {
378
+ return this.AboveRangeColor;
379
+ }
380
+ }
381
+
382
+ return this.Table[index];
383
+ }
384
+
385
+ /**
386
+ * Return the table index associated with a particular value.
387
+ * @param {Number} v A double value which table index will be returned.
388
+ * @returns {Number} The index in the LookupTable
389
+ * @memberof Colors
390
+ */
391
+ private getIndex(v) {
392
+ const p = {
393
+ Range: [],
394
+ MaxIndex: this.NumberOfColors - 1,
395
+ Shift: -this.TableRange[0],
396
+ Scale: 1,
397
+ };
398
+
399
+ if (this.TableRange[1] <= this.TableRange[0]) {
400
+ p.Scale = Number.MAX_VALUE;
401
+ } else {
402
+ p.Scale = p.MaxIndex / (this.TableRange[1] - this.TableRange[0]);
403
+ }
404
+
405
+ p.Range[0] = this.TableRange[0];
406
+ p.Range[1] = this.TableRange[1];
407
+
408
+ // First, check whether we have a number...
409
+ if (isNaN(v)) {
410
+ // For backwards compatibility
411
+ return -1;
412
+ }
413
+
414
+ // Map to an index:
415
+ let index = linearIndexLookupMain(v, p);
416
+
417
+ // For backwards compatibility, if the index indicates an
418
+ // Out-of-range value, truncate to index range for in-range colors.
419
+ if (index === this.NumberOfColors + BELOW_RANGE_COLOR_INDEX) {
420
+ index = 0;
421
+ } else if (index === this.NumberOfColors + ABOVE_RANGE_COLOR_INDEX) {
422
+ index = this.NumberOfColors - 1;
423
+ }
424
+
425
+ return index;
426
+ }
427
+
428
+ /**
429
+ * Directly load color into lookup table. Use [0,1] double values for color component specification.
430
+ * Make sure that you've either used the Build() method or used SetNumberOfTableValues() prior to using this method.
431
+ * @param {Number} index The index in the LookupTable of where to insert the color value
432
+ * @param {Number[]} rgba An array of [0,1] double values for an RGBA color component
433
+ * @returns {void}
434
+ * @memberof Colors
435
+ */
436
+ public setTableValue(index, rgba) {
437
+ // Check if it index, red, green, blue and alpha were passed as parameter
438
+ if (arguments.length === 5) {
439
+ rgba = Array.prototype.slice.call(arguments, 1);
440
+ }
441
+
442
+ // Check the index to make sure it is valid
443
+ if (index < 0) {
444
+ throw new Error(
445
+ `Can't set the table value for negative index (${index})`
446
+ );
447
+ }
448
+
449
+ if (index >= this.NumberOfColors) {
450
+ new Error(
451
+ `Index ${index} is greater than the number of colors ${this.NumberOfColors}`
452
+ );
453
+ }
454
+
455
+ this.Table[index] = rgba;
456
+
457
+ if (index === 0 || index === this.NumberOfColors - 1) {
458
+ // This is needed due to the way the special colors are stored in
459
+ // The internal table. If Above/BelowRangeColors are not used and
460
+ // The min/max colors are changed in the table with this member
461
+ // Function, then the colors used for values outside the range may
462
+ // Be incorrect. Calling this here ensures the out-of-range colors
463
+ // Are set correctly.
464
+ this.buildSpecialColors();
465
+ }
466
+ }
467
+ }
468
+
469
+ export default LookupTable;
@@ -0,0 +1,58 @@
1
+ import now from './rendering/now';
2
+ import { renderColorImage } from './rendering/renderColorImage';
3
+ import { renderGrayscaleImage } from './rendering/renderGrayscaleImage';
4
+ import { renderPseudoColorImage } from './rendering/renderPseudoColorImage';
5
+ import { CPUFallbackEnabledElement } from '../../../types';
6
+
7
+ /**
8
+ * Draw an image to a given enabled element synchronously
9
+ *
10
+ * @param enabledElement - An enabled element to draw into
11
+ * @param invalidated - true if pixel data has been invalidated and cached rendering should not be used
12
+ */
13
+ export default function (
14
+ enabledElement: CPUFallbackEnabledElement,
15
+ invalidated: boolean
16
+ ): void {
17
+ const image = enabledElement.image;
18
+
19
+ // Check if enabledElement can be redrawn
20
+ if (!enabledElement.canvas || !enabledElement.image) {
21
+ return;
22
+ }
23
+
24
+ // Start measuring the time needed to draw the image.
25
+ const start = now();
26
+
27
+ image.stats = {
28
+ lastGetPixelDataTime: -1.0,
29
+ lastStoredPixelDataToCanvasImageDataTime: -1.0,
30
+ lastPutImageDataTime: -1.0,
31
+ lastRenderTime: -1.0,
32
+ lastLutGenerateTime: -1.0,
33
+ };
34
+
35
+ if (image) {
36
+ let render = image.render;
37
+
38
+ if (!render) {
39
+ if (enabledElement.viewport.colormap) {
40
+ render = renderPseudoColorImage;
41
+ } else if (image.color) {
42
+ render = renderColorImage;
43
+ } else {
44
+ render = renderGrayscaleImage;
45
+ }
46
+ }
47
+
48
+ render(enabledElement, invalidated);
49
+ }
50
+
51
+ // Calculate how long it took to draw the image/layers
52
+ const renderTimeInMs = now() - start;
53
+
54
+ image.stats.lastRenderTime = renderTimeInMs;
55
+
56
+ enabledElement.invalid = false;
57
+ enabledElement.needsRedraw = false;
58
+ }
@@ -0,0 +1,136 @@
1
+ import { Transform } from './transform';
2
+ import {
3
+ CPUFallbackEnabledElement,
4
+ CPUFallbackTransform,
5
+ } from '../../../../types';
6
+
7
+ /**
8
+ * Calculate the transform for a Cornerstone enabled element
9
+ *
10
+ * @param enabledElement - The Cornerstone Enabled Element
11
+ * @param scale - The viewport scale
12
+ * @returns The current transform
13
+ */
14
+ export default function (
15
+ enabledElement: CPUFallbackEnabledElement,
16
+ scale?: number
17
+ ): CPUFallbackTransform {
18
+ const transform = new Transform();
19
+
20
+ if (!enabledElement.viewport.displayedArea) {
21
+ return transform;
22
+ }
23
+
24
+ // Move to center of canvas
25
+ transform.translate(
26
+ enabledElement.canvas.width / 2,
27
+ enabledElement.canvas.height / 2
28
+ );
29
+
30
+ // Apply the rotation before scaling for non square pixels
31
+ const angle = enabledElement.viewport.rotation;
32
+
33
+ if (angle !== 0) {
34
+ transform.rotate((angle * Math.PI) / 180);
35
+ }
36
+
37
+ // Apply the scale
38
+ let widthScale = enabledElement.viewport.scale;
39
+ let heightScale = enabledElement.viewport.scale;
40
+
41
+ const width =
42
+ enabledElement.viewport.displayedArea.brhc.x -
43
+ (enabledElement.viewport.displayedArea.tlhc.x - 1);
44
+ const height =
45
+ enabledElement.viewport.displayedArea.brhc.y -
46
+ (enabledElement.viewport.displayedArea.tlhc.y - 1);
47
+
48
+ if (enabledElement.viewport.displayedArea.presentationSizeMode === 'NONE') {
49
+ if (
50
+ enabledElement.image.rowPixelSpacing <
51
+ enabledElement.image.columnPixelSpacing
52
+ ) {
53
+ widthScale *=
54
+ enabledElement.image.columnPixelSpacing /
55
+ enabledElement.image.rowPixelSpacing;
56
+ } else if (
57
+ enabledElement.image.columnPixelSpacing <
58
+ enabledElement.image.rowPixelSpacing
59
+ ) {
60
+ heightScale *=
61
+ enabledElement.image.rowPixelSpacing /
62
+ enabledElement.image.columnPixelSpacing;
63
+ }
64
+ } else {
65
+ // These should be good for "TRUE SIZE" and "MAGNIFY"
66
+ widthScale = enabledElement.viewport.displayedArea.columnPixelSpacing;
67
+ heightScale = enabledElement.viewport.displayedArea.rowPixelSpacing;
68
+
69
+ if (
70
+ enabledElement.viewport.displayedArea.presentationSizeMode ===
71
+ 'SCALE TO FIT'
72
+ ) {
73
+ // Fit TRUE IMAGE image (width/height) to window
74
+ const verticalScale =
75
+ enabledElement.canvas.height / (height * heightScale);
76
+ const horizontalScale =
77
+ enabledElement.canvas.width / (width * widthScale);
78
+
79
+ // Apply new scale
80
+ widthScale = heightScale = Math.min(horizontalScale, verticalScale);
81
+
82
+ if (
83
+ enabledElement.viewport.displayedArea.rowPixelSpacing <
84
+ enabledElement.viewport.displayedArea.columnPixelSpacing
85
+ ) {
86
+ widthScale *=
87
+ enabledElement.viewport.displayedArea.columnPixelSpacing /
88
+ enabledElement.viewport.displayedArea.rowPixelSpacing;
89
+ } else if (
90
+ enabledElement.viewport.displayedArea.columnPixelSpacing <
91
+ enabledElement.viewport.displayedArea.rowPixelSpacing
92
+ ) {
93
+ heightScale *=
94
+ enabledElement.viewport.displayedArea.rowPixelSpacing /
95
+ enabledElement.viewport.displayedArea.columnPixelSpacing;
96
+ }
97
+ }
98
+ }
99
+
100
+ transform.scale(widthScale, heightScale);
101
+
102
+ // Unrotate to so we can translate unrotated
103
+ if (angle !== 0) {
104
+ transform.rotate((-angle * Math.PI) / 180);
105
+ }
106
+
107
+ // Apply the pan offset
108
+ transform.translate(
109
+ enabledElement.viewport.translation.x,
110
+ enabledElement.viewport.translation.y
111
+ );
112
+
113
+ // Rotate again so we can apply general scale
114
+ if (angle !== 0) {
115
+ transform.rotate((angle * Math.PI) / 180);
116
+ }
117
+
118
+ if (scale !== undefined) {
119
+ // Apply the font scale
120
+ transform.scale(scale, scale);
121
+ }
122
+
123
+ // Apply Flip if required
124
+ if (enabledElement.viewport.hflip) {
125
+ transform.scale(-1, 1);
126
+ }
127
+
128
+ if (enabledElement.viewport.vflip) {
129
+ transform.scale(1, -1);
130
+ }
131
+
132
+ // Move back from center of image
133
+ transform.translate(-width / 2, -height / 2);
134
+
135
+ return transform;
136
+ }
@@ -0,0 +1,25 @@
1
+ import getTransform from './getTransform';
2
+
3
+ import { Point2, CPUFallbackEnabledElement } from '../../../../types';
4
+
5
+ /**
6
+ * Converts a point in the canvas coordinate system to the pixel coordinate system
7
+ * system. This can be used to reset tools' image coordinates after modifications
8
+ * have been made in canvas space (e.g. moving a tool by a few cm, independent of
9
+ * image resolution).
10
+ *
11
+ * @param element - The Cornerstone element within which the input point lies
12
+ * @param pt - The input point in the canvas coordinate system
13
+ *
14
+ * @returns The transformed point in the pixel coordinate system
15
+ */
16
+ export default function (
17
+ enabledElement: CPUFallbackEnabledElement,
18
+ pt: Point2
19
+ ): Point2 {
20
+ const transform = getTransform(enabledElement);
21
+
22
+ transform.invert();
23
+
24
+ return transform.transformPoint(pt);
25
+ }