@cornerstonejs/core 0.36.3 → 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.
- package/dist/cjs/utilities/getSliceRange.js +2 -1
- package/dist/cjs/utilities/getSliceRange.js.map +1 -1
- package/dist/esm/utilities/getSliceRange.js +2 -1
- package/dist/esm/utilities/getSliceRange.js.map +1 -1
- package/dist/umd/index.js +1 -1
- package/dist/umd/index.js.map +1 -1
- package/package.json +4 -3
- package/src/RenderingEngine/BaseVolumeViewport.ts +847 -0
- package/src/RenderingEngine/RenderingEngine.ts +1364 -0
- package/src/RenderingEngine/StackViewport.ts +2690 -0
- package/src/RenderingEngine/Viewport.ts +1244 -0
- package/src/RenderingEngine/VolumeViewport.ts +420 -0
- package/src/RenderingEngine/VolumeViewport3D.ts +42 -0
- package/src/RenderingEngine/getRenderingEngine.ts +34 -0
- package/src/RenderingEngine/helpers/addVolumesToViewports.ts +52 -0
- package/src/RenderingEngine/helpers/cpuFallback/colors/colormap.ts +343 -0
- package/src/RenderingEngine/helpers/cpuFallback/colors/index.ts +4 -0
- package/src/RenderingEngine/helpers/cpuFallback/colors/lookupTable.ts +469 -0
- package/src/RenderingEngine/helpers/cpuFallback/drawImageSync.ts +58 -0
- package/src/RenderingEngine/helpers/cpuFallback/rendering/calculateTransform.ts +136 -0
- package/src/RenderingEngine/helpers/cpuFallback/rendering/canvasToPixel.ts +25 -0
- package/src/RenderingEngine/helpers/cpuFallback/rendering/computeAutoVoi.ts +47 -0
- package/src/RenderingEngine/helpers/cpuFallback/rendering/correctShift.ts +38 -0
- package/src/RenderingEngine/helpers/cpuFallback/rendering/createViewport.ts +64 -0
- package/src/RenderingEngine/helpers/cpuFallback/rendering/doesImageNeedToBeRendered.ts +36 -0
- package/src/RenderingEngine/helpers/cpuFallback/rendering/fitToWindow.ts +22 -0
- package/src/RenderingEngine/helpers/cpuFallback/rendering/generateColorLUT.ts +60 -0
- package/src/RenderingEngine/helpers/cpuFallback/rendering/generateLut.ts +83 -0
- package/src/RenderingEngine/helpers/cpuFallback/rendering/getDefaultViewport.ts +88 -0
- package/src/RenderingEngine/helpers/cpuFallback/rendering/getImageFitScale.ts +52 -0
- package/src/RenderingEngine/helpers/cpuFallback/rendering/getImageSize.ts +55 -0
- package/src/RenderingEngine/helpers/cpuFallback/rendering/getLut.ts +53 -0
- package/src/RenderingEngine/helpers/cpuFallback/rendering/getModalityLut.ts +55 -0
- package/src/RenderingEngine/helpers/cpuFallback/rendering/getTransform.ts +17 -0
- package/src/RenderingEngine/helpers/cpuFallback/rendering/getVOILut.ts +74 -0
- package/src/RenderingEngine/helpers/cpuFallback/rendering/initializeRenderCanvas.ts +37 -0
- package/src/RenderingEngine/helpers/cpuFallback/rendering/lutMatches.ts +21 -0
- package/src/RenderingEngine/helpers/cpuFallback/rendering/now.ts +13 -0
- package/src/RenderingEngine/helpers/cpuFallback/rendering/pixelToCanvas.ts +22 -0
- package/src/RenderingEngine/helpers/cpuFallback/rendering/renderColorImage.ts +193 -0
- package/src/RenderingEngine/helpers/cpuFallback/rendering/renderGrayscaleImage.ts +166 -0
- package/src/RenderingEngine/helpers/cpuFallback/rendering/renderPseudoColorImage.ts +203 -0
- package/src/RenderingEngine/helpers/cpuFallback/rendering/resetCamera.ts +32 -0
- package/src/RenderingEngine/helpers/cpuFallback/rendering/resize.ts +109 -0
- package/src/RenderingEngine/helpers/cpuFallback/rendering/saveLastRendered.ts +36 -0
- package/src/RenderingEngine/helpers/cpuFallback/rendering/setDefaultViewport.ts +17 -0
- package/src/RenderingEngine/helpers/cpuFallback/rendering/setToPixelCoordinateSystem.ts +32 -0
- package/src/RenderingEngine/helpers/cpuFallback/rendering/storedColorPixelDataToCanvasImageData.ts +58 -0
- package/src/RenderingEngine/helpers/cpuFallback/rendering/storedPixelDataToCanvasImageData.ts +76 -0
- package/src/RenderingEngine/helpers/cpuFallback/rendering/storedPixelDataToCanvasImageDataColorLUT.ts +60 -0
- package/src/RenderingEngine/helpers/cpuFallback/rendering/storedPixelDataToCanvasImageDataPET.ts +50 -0
- package/src/RenderingEngine/helpers/cpuFallback/rendering/storedPixelDataToCanvasImageDataPseudocolorLUT.ts +66 -0
- package/src/RenderingEngine/helpers/cpuFallback/rendering/storedPixelDataToCanvasImageDataPseudocolorLUTPET.ts +68 -0
- package/src/RenderingEngine/helpers/cpuFallback/rendering/storedPixelDataToCanvasImageDataRGBA.ts +81 -0
- package/src/RenderingEngine/helpers/cpuFallback/rendering/storedRGBAPixelDataToCanvasImageData.ts +56 -0
- package/src/RenderingEngine/helpers/cpuFallback/rendering/transform.ts +126 -0
- package/src/RenderingEngine/helpers/cpuFallback/rendering/validator.ts +31 -0
- package/src/RenderingEngine/helpers/createVolumeActor.ts +103 -0
- package/src/RenderingEngine/helpers/createVolumeMapper.ts +37 -0
- package/src/RenderingEngine/helpers/getOrCreateCanvas.ts +58 -0
- package/src/RenderingEngine/helpers/index.ts +15 -0
- package/src/RenderingEngine/helpers/isRgbaSourceRgbDest.ts +1 -0
- package/src/RenderingEngine/helpers/setDefaultVolumeVOI.ts +227 -0
- package/src/RenderingEngine/helpers/setVolumesForViewports.ts +52 -0
- package/src/RenderingEngine/helpers/viewportTypeToViewportClass.ts +14 -0
- package/src/RenderingEngine/helpers/viewportTypeUsesCustomRenderingPipeline.ts +7 -0
- package/src/RenderingEngine/helpers/volumeNewImageEventDispatcher.ts +75 -0
- package/src/RenderingEngine/index.ts +23 -0
- package/src/RenderingEngine/renderingEngineCache.ts +43 -0
- package/src/RenderingEngine/vtkClasses/index.js +11 -0
- package/src/RenderingEngine/vtkClasses/vtkOffscreenMultiRenderWindow.js +149 -0
- package/src/RenderingEngine/vtkClasses/vtkSharedVolumeMapper.js +52 -0
- package/src/RenderingEngine/vtkClasses/vtkSlabCamera.d.ts +781 -0
- package/src/RenderingEngine/vtkClasses/vtkSlabCamera.js +155 -0
- package/src/RenderingEngine/vtkClasses/vtkStreamingOpenGLRenderWindow.js +47 -0
- package/src/RenderingEngine/vtkClasses/vtkStreamingOpenGLTexture.js +272 -0
- package/src/RenderingEngine/vtkClasses/vtkStreamingOpenGLViewNodeFactory.js +159 -0
- package/src/RenderingEngine/vtkClasses/vtkStreamingOpenGLVolumeMapper.js +319 -0
- package/src/Settings.ts +294 -0
- package/src/cache/cache.ts +854 -0
- package/src/cache/classes/Contour.ts +70 -0
- package/src/cache/classes/ContourSet.ts +151 -0
- package/src/cache/classes/ImageVolume.ts +155 -0
- package/src/cache/index.ts +5 -0
- package/src/constants/cpuColormaps.ts +1537 -0
- package/src/constants/epsilon.ts +3 -0
- package/src/constants/index.ts +13 -0
- package/src/constants/mprCameraValues.ts +20 -0
- package/src/constants/rendering.ts +8 -0
- package/src/constants/viewportPresets.ts +357 -0
- package/src/enums/BlendModes.ts +23 -0
- package/src/enums/ContourType.ts +6 -0
- package/src/enums/Events.ts +196 -0
- package/src/enums/GeometryType.ts +5 -0
- package/src/enums/InterpolationType.ts +13 -0
- package/src/enums/OrientationAxis.ts +8 -0
- package/src/enums/RequestType.ts +13 -0
- package/src/enums/SharedArrayBufferModes.ts +11 -0
- package/src/enums/VOILUTFunctionType.ts +10 -0
- package/src/enums/ViewportType.ts +21 -0
- package/src/enums/index.ts +23 -0
- package/src/eventTarget.ts +67 -0
- package/src/getEnabledElement.ts +105 -0
- package/src/global.ts +8 -0
- package/src/index.ts +123 -0
- package/src/init.ts +247 -0
- package/src/loaders/geometryLoader.ts +108 -0
- package/src/loaders/imageLoader.ts +298 -0
- package/src/loaders/volumeLoader.ts +477 -0
- package/src/metaData.ts +84 -0
- package/src/requestPool/imageLoadPoolManager.ts +43 -0
- package/src/requestPool/imageRetrievalPoolManager.ts +25 -0
- package/src/requestPool/requestPoolManager.ts +329 -0
- package/src/types/ActorSliceRange.ts +17 -0
- package/src/types/CPUFallbackColormap.ts +23 -0
- package/src/types/CPUFallbackColormapData.ts +12 -0
- package/src/types/CPUFallbackColormapsData.ts +7 -0
- package/src/types/CPUFallbackEnabledElement.ts +71 -0
- package/src/types/CPUFallbackLUT.ts +5 -0
- package/src/types/CPUFallbackLookupTable.ts +17 -0
- package/src/types/CPUFallbackRenderingTools.ts +25 -0
- package/src/types/CPUFallbackTransform.ts +16 -0
- package/src/types/CPUFallbackViewport.ts +29 -0
- package/src/types/CPUFallbackViewportDisplayedArea.ts +15 -0
- package/src/types/CPUIImageData.ts +47 -0
- package/src/types/ContourData.ts +19 -0
- package/src/types/Cornerstone3DConfig.ts +31 -0
- package/src/types/CustomEventType.ts +14 -0
- package/src/types/EventTypes.ts +403 -0
- package/src/types/FlipDirection.ts +9 -0
- package/src/types/IActor.ts +23 -0
- package/src/types/ICache.ts +28 -0
- package/src/types/ICachedGeometry.ts +13 -0
- package/src/types/ICachedImage.ts +13 -0
- package/src/types/ICachedVolume.ts +12 -0
- package/src/types/ICamera.ts +36 -0
- package/src/types/IContour.ts +18 -0
- package/src/types/IContourSet.ts +56 -0
- package/src/types/IDynamicImageVolume.ts +18 -0
- package/src/types/IEnabledElement.ts +21 -0
- package/src/types/IGeometry.ts +12 -0
- package/src/types/IImage.ts +113 -0
- package/src/types/IImageData.ts +45 -0
- package/src/types/IImageVolume.ts +78 -0
- package/src/types/ILoadObject.ts +36 -0
- package/src/types/IRegisterImageLoader.ts +10 -0
- package/src/types/IRenderingEngine.ts +28 -0
- package/src/types/IStackViewport.ts +138 -0
- package/src/types/IStreamingImageVolume.ts +13 -0
- package/src/types/IStreamingVolumeProperties.ts +14 -0
- package/src/types/IViewport.ts +149 -0
- package/src/types/IViewportId.ts +9 -0
- package/src/types/IVolume.ts +45 -0
- package/src/types/IVolumeInput.ts +36 -0
- package/src/types/IVolumeViewport.ts +141 -0
- package/src/types/ImageLoaderFn.ts +16 -0
- package/src/types/ImageSliceData.ts +6 -0
- package/src/types/Mat3.ts +16 -0
- package/src/types/Metadata.ts +39 -0
- package/src/types/OrientationVectors.ts +36 -0
- package/src/types/Plane.ts +6 -0
- package/src/types/Point2.ts +6 -0
- package/src/types/Point3.ts +6 -0
- package/src/types/Point4.ts +6 -0
- package/src/types/ScalingParameters.ts +27 -0
- package/src/types/StackViewportProperties.ts +25 -0
- package/src/types/TransformMatrix2D.ts +4 -0
- package/src/types/ViewportInputOptions.ts +21 -0
- package/src/types/ViewportPreset.ts +14 -0
- package/src/types/VolumeLoaderFn.ts +18 -0
- package/src/types/VolumeViewportProperties.ts +14 -0
- package/src/types/index.ts +157 -0
- package/src/types/voi.ts +15 -0
- package/src/utilities/actorCheck.ts +24 -0
- package/src/utilities/applyPreset.ts +132 -0
- package/src/utilities/calculateViewportsSpatialRegistration.ts +74 -0
- package/src/utilities/calibratedPixelSpacingMetadataProvider.ts +38 -0
- package/src/utilities/createFloat32SharedArray.ts +45 -0
- package/src/utilities/createInt16SharedArray.ts +43 -0
- package/src/utilities/createLinearRGBTransferFunction.ts +22 -0
- package/src/utilities/createSigmoidRGBTransferFunction.ts +63 -0
- package/src/utilities/createUInt16SharedArray.ts +43 -0
- package/src/utilities/createUint8SharedArray.ts +45 -0
- package/src/utilities/deepFreeze.ts +19 -0
- package/src/utilities/deepMerge.ts +81 -0
- package/src/utilities/getClosestImageId.ts +80 -0
- package/src/utilities/getClosestStackImageIndexForPoint.ts +116 -0
- package/src/utilities/getImageSliceDataForVolumeViewport.ts +61 -0
- package/src/utilities/getMinMax.ts +31 -0
- package/src/utilities/getRuntimeId.ts +54 -0
- package/src/utilities/getScalarDataType.ts +31 -0
- package/src/utilities/getScalingParameters.ts +35 -0
- package/src/utilities/getSliceRange.ts +86 -0
- package/src/utilities/getSpacingInNormalDirection.ts +44 -0
- package/src/utilities/getTargetVolumeAndSpacingInNormalDir.ts +126 -0
- package/src/utilities/getViewportImageCornersInWorld.ts +102 -0
- package/src/utilities/getViewportsWithImageURI.ts +46 -0
- package/src/utilities/getViewportsWithVolumeId.ts +38 -0
- package/src/utilities/getVoiFromSigmoidRGBTransferFunction.ts +23 -0
- package/src/utilities/getVolumeActorCorners.ts +24 -0
- package/src/utilities/getVolumeSliceRangeInfo.ts +52 -0
- package/src/utilities/getVolumeViewportScrollInfo.ts +32 -0
- package/src/utilities/getVolumeViewportsContainingSameVolumes.ts +58 -0
- package/src/utilities/hasNaNValues.ts +12 -0
- package/src/utilities/imageIdToURI.ts +10 -0
- package/src/utilities/imageToWorldCoords.ts +54 -0
- package/src/utilities/index.ts +100 -0
- package/src/utilities/indexWithinDimensions.ts +27 -0
- package/src/utilities/invertRgbTransferFunction.ts +36 -0
- package/src/utilities/isEqual.ts +27 -0
- package/src/utilities/isOpposite.ts +23 -0
- package/src/utilities/isTypedArray.ts +20 -0
- package/src/utilities/loadImageToCanvas.ts +80 -0
- package/src/utilities/planar.ts +91 -0
- package/src/utilities/renderToCanvas.ts +32 -0
- package/src/utilities/scaleRgbTransferFunction.ts +37 -0
- package/src/utilities/snapFocalPointToSlice.ts +78 -0
- package/src/utilities/spatialRegistrationMetadataProvider.ts +50 -0
- package/src/utilities/transformWorldToIndex.ts +16 -0
- package/src/utilities/triggerEvent.ts +38 -0
- package/src/utilities/uuidv4.ts +13 -0
- package/src/utilities/windowLevel.ts +39 -0
- package/src/utilities/worldToImageCoords.ts +64 -0
|
@@ -0,0 +1,343 @@
|
|
|
1
|
+
import LookupTable from './lookupTable';
|
|
2
|
+
import CPU_COLORMAPS from '../../../../constants/cpuColormaps';
|
|
3
|
+
import {
|
|
4
|
+
CPUFallbackColormap,
|
|
5
|
+
CPUFallbackColormapData,
|
|
6
|
+
Point4,
|
|
7
|
+
} from '../../../../types';
|
|
8
|
+
|
|
9
|
+
const COLOR_TRANSPARENT: Point4 = [0, 0, 0, 0];
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Generate linearly spaced vectors
|
|
13
|
+
* http://cens.ioc.ee/local/man/matlab/techdoc/ref/linspace.html
|
|
14
|
+
* @param {Number} a A number representing the first vector
|
|
15
|
+
* @param {Number} b A number representing the second vector
|
|
16
|
+
* @param {Number} n The number of linear spaced vectors to generate
|
|
17
|
+
* @returns {Array} An array of points representing linear spaced vectors.
|
|
18
|
+
* @memberof Colors
|
|
19
|
+
*/
|
|
20
|
+
function linspace(a: number, b: number, n: number): number[] {
|
|
21
|
+
n = n === null ? 100 : n;
|
|
22
|
+
|
|
23
|
+
const increment = (b - a) / (n - 1);
|
|
24
|
+
const vector = [];
|
|
25
|
+
|
|
26
|
+
while (n-- > 0) {
|
|
27
|
+
vector.push(a);
|
|
28
|
+
a += increment;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// Make sure the last item will always be "b" because most of the
|
|
32
|
+
// Time we'll get numbers like 1.0000000000000002 instead of 1.
|
|
33
|
+
vector[vector.length - 1] = b;
|
|
34
|
+
|
|
35
|
+
return vector;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Returns the "rank/index" of the element in a sorted array if found or the highest index if not. Uses (binary search)
|
|
40
|
+
* @param {Array} array A sorted array to search in
|
|
41
|
+
* @param {any} elem the element in the array to search for
|
|
42
|
+
* @returns {number} The rank/index of the element in the given array
|
|
43
|
+
* @memberof Colors
|
|
44
|
+
*/
|
|
45
|
+
function getRank(array, elem) {
|
|
46
|
+
let left = 0;
|
|
47
|
+
let right = array.length - 1;
|
|
48
|
+
|
|
49
|
+
while (left <= right) {
|
|
50
|
+
const mid = left + Math.floor((right - left) / 2);
|
|
51
|
+
const midElem = array[mid];
|
|
52
|
+
|
|
53
|
+
if (midElem === elem) {
|
|
54
|
+
return mid;
|
|
55
|
+
} else if (elem < midElem) {
|
|
56
|
+
right = mid - 1;
|
|
57
|
+
} else {
|
|
58
|
+
left = mid + 1;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return left;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Find the indices into a sorted array a such that, if the corresponding elements
|
|
67
|
+
* In v were inserted before the indices, the order of a would be preserved.
|
|
68
|
+
* http://lagrange.univ-lyon1.fr/docs/numpy/1.11.0/reference/generated/numpy.searchsorted.html
|
|
69
|
+
* @param {Array} inputArray The array where the values will be inserted
|
|
70
|
+
* @param {Array} values An array of the values to be inserted into the inputArray
|
|
71
|
+
* @returns {Array} The indices where elements should be inserted to maintain order.
|
|
72
|
+
* @memberof Colors
|
|
73
|
+
*/
|
|
74
|
+
function searchSorted(inputArray, values) {
|
|
75
|
+
let i;
|
|
76
|
+
const indexes = [];
|
|
77
|
+
const len = values.length;
|
|
78
|
+
|
|
79
|
+
inputArray.sort(function (a, b) {
|
|
80
|
+
return a - b;
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
for (i = 0; i < len; i++) {
|
|
84
|
+
indexes[i] = getRank(inputArray, values[i]);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
return indexes;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Creates an *N* -element 1-d lookup table
|
|
92
|
+
* @param {Number} N The number of elements in the result lookup table
|
|
93
|
+
* @param {Array} data represented by a list of x,y0,y1 mapping correspondences. Each element in this
|
|
94
|
+
* List represents how a value between 0 and 1 (inclusive) represented by x is mapped to
|
|
95
|
+
* A corresponding value between 0 and 1 (inclusive). The two values of y are to allow for
|
|
96
|
+
* Discontinuous mapping functions (say as might be found in a sawtooth) where y0 represents
|
|
97
|
+
* The value of y for values of x <= to that given, and y1 is the value to be used for x >
|
|
98
|
+
* Than that given). The list must start with x=0, end with x=1, and all values of x must be
|
|
99
|
+
* In increasing order. Values between the given mapping points are determined by simple linear
|
|
100
|
+
* Interpolation.
|
|
101
|
+
* @param {any} gamma value denotes a "gamma curve" value which adjusts the brightness
|
|
102
|
+
* at the bottom and top of the map.
|
|
103
|
+
* @returns {any[]} an array "result" where result[x*(N-1)] gives the closest value for
|
|
104
|
+
* Values of x between 0 and 1.
|
|
105
|
+
* @memberof Colors
|
|
106
|
+
*/
|
|
107
|
+
function makeMappingArray(N, data, gamma) {
|
|
108
|
+
let i;
|
|
109
|
+
const x = [];
|
|
110
|
+
const y0 = [];
|
|
111
|
+
const y1 = [];
|
|
112
|
+
const lut = [];
|
|
113
|
+
|
|
114
|
+
gamma = gamma === null ? 1 : gamma;
|
|
115
|
+
|
|
116
|
+
for (i = 0; i < data.length; i++) {
|
|
117
|
+
const element = data[i];
|
|
118
|
+
|
|
119
|
+
x.push((N - 1) * element[0]);
|
|
120
|
+
y0.push(element[1]);
|
|
121
|
+
y1.push(element[1]);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
const xLinSpace = linspace(0, 1, N);
|
|
125
|
+
|
|
126
|
+
for (i = 0; i < N; i++) {
|
|
127
|
+
xLinSpace[i] = (N - 1) * Math.pow(xLinSpace[i], gamma);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
const xLinSpaceIndexes = searchSorted(x, xLinSpace);
|
|
131
|
+
|
|
132
|
+
for (i = 1; i < N - 1; i++) {
|
|
133
|
+
const index = xLinSpaceIndexes[i];
|
|
134
|
+
const colorPercent =
|
|
135
|
+
(xLinSpace[i] - x[index - 1]) / (x[index] - x[index - 1]);
|
|
136
|
+
const colorDelta = y0[index] - y1[index - 1];
|
|
137
|
+
|
|
138
|
+
lut[i] = colorPercent * colorDelta + y1[index - 1];
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
lut[0] = y1[0];
|
|
142
|
+
lut[N - 1] = y0[data.length - 1];
|
|
143
|
+
|
|
144
|
+
return lut;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Creates a Colormap based on lookup tables using linear segments.
|
|
149
|
+
* @param {{red:Array, green:Array, blue:Array}} segmentedData An object with a red, green and blue entries.
|
|
150
|
+
* Each entry should be a list of x, y0, y1 tuples, forming rows in a table.
|
|
151
|
+
* @param {Number} N The number of elements in the result Colormap
|
|
152
|
+
* @param {any} gamma value denotes a "gamma curve" value which adjusts the brightness
|
|
153
|
+
* at the bottom and top of the Colormap.
|
|
154
|
+
* @returns {Array} The created Colormap object
|
|
155
|
+
* @description The lookup table is generated using linear interpolation for each
|
|
156
|
+
* Primary color, with the 0-1 domain divided into any number of
|
|
157
|
+
* Segments.
|
|
158
|
+
* https://github.com/stefanv/matplotlib/blob/3f1a23755e86fef97d51e30e106195f34425c9e3/lib/matplotlib/colors.py#L663
|
|
159
|
+
* @memberof Colors
|
|
160
|
+
*/
|
|
161
|
+
function createLinearSegmentedColormap(segmentedData, N, gamma) {
|
|
162
|
+
let i;
|
|
163
|
+
const lut = [];
|
|
164
|
+
|
|
165
|
+
N = N === null ? 256 : N;
|
|
166
|
+
gamma = gamma === null ? 1 : gamma;
|
|
167
|
+
|
|
168
|
+
const redLut = makeMappingArray(N, segmentedData.red, gamma);
|
|
169
|
+
const greenLut = makeMappingArray(N, segmentedData.green, gamma);
|
|
170
|
+
const blueLut = makeMappingArray(N, segmentedData.blue, gamma);
|
|
171
|
+
|
|
172
|
+
for (i = 0; i < N; i++) {
|
|
173
|
+
const red = Math.round(redLut[i] * 255);
|
|
174
|
+
const green = Math.round(greenLut[i] * 255);
|
|
175
|
+
const blue = Math.round(blueLut[i] * 255);
|
|
176
|
+
const rgba = [red, green, blue, 255];
|
|
177
|
+
|
|
178
|
+
lut.push(rgba);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
return lut;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Return all available colormaps (id and name)
|
|
186
|
+
* @returns {Array<{id,key}>} An array of colormaps with an object containing the "id" and display "name"
|
|
187
|
+
* @memberof Colors
|
|
188
|
+
*/
|
|
189
|
+
export function getColormapsList() {
|
|
190
|
+
const colormaps = [];
|
|
191
|
+
const keys = Object.keys(CPU_COLORMAPS);
|
|
192
|
+
|
|
193
|
+
keys.forEach(function (key) {
|
|
194
|
+
if (CPU_COLORMAPS.hasOwnProperty(key)) {
|
|
195
|
+
const colormap = CPU_COLORMAPS[key];
|
|
196
|
+
|
|
197
|
+
colormaps.push({
|
|
198
|
+
id: key,
|
|
199
|
+
name: colormap.name,
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
colormaps.sort(function (a, b) {
|
|
205
|
+
const aName = a.name.toLowerCase();
|
|
206
|
+
const bName = b.name.toLowerCase();
|
|
207
|
+
|
|
208
|
+
if (aName === bName) {
|
|
209
|
+
return 0;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
return aName < bName ? -1 : 1;
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
return colormaps;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* Return a colorMap object with the provided id and colormapData
|
|
220
|
+
* if the Id matches existent colorMap objects (check colormapsData) the colormapData is ignored.
|
|
221
|
+
* if the colormapData is not empty, the colorMap will be added to the colormapsData list. Otherwise, an empty colorMap object is returned.
|
|
222
|
+
* @param {string} id The ID of the colormap
|
|
223
|
+
* @param {Object} colormapData - An object that can contain a name, numColors, gama, segmentedData and/or colors
|
|
224
|
+
* @returns {*} The Colormap Object
|
|
225
|
+
* @memberof Colors
|
|
226
|
+
*/
|
|
227
|
+
export function getColormap(
|
|
228
|
+
id: string,
|
|
229
|
+
colormapData?: CPUFallbackColormapData
|
|
230
|
+
): CPUFallbackColormap {
|
|
231
|
+
let colormap = CPU_COLORMAPS[id];
|
|
232
|
+
|
|
233
|
+
if (!colormap) {
|
|
234
|
+
colormap = CPU_COLORMAPS[id] = colormapData || {
|
|
235
|
+
name: '',
|
|
236
|
+
colors: [],
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
if (!colormap.colors && colormap.segmentedData) {
|
|
241
|
+
colormap.colors = createLinearSegmentedColormap(
|
|
242
|
+
colormap.segmentedData,
|
|
243
|
+
colormap.numColors,
|
|
244
|
+
colormap.gamma
|
|
245
|
+
);
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
const cpuFallbackColormap: CPUFallbackColormap = {
|
|
249
|
+
getId() {
|
|
250
|
+
return id;
|
|
251
|
+
},
|
|
252
|
+
|
|
253
|
+
getColorSchemeName() {
|
|
254
|
+
return colormap.name;
|
|
255
|
+
},
|
|
256
|
+
|
|
257
|
+
setColorSchemeName(name) {
|
|
258
|
+
colormap.name = name;
|
|
259
|
+
},
|
|
260
|
+
|
|
261
|
+
getNumberOfColors() {
|
|
262
|
+
return colormap.colors.length;
|
|
263
|
+
},
|
|
264
|
+
|
|
265
|
+
setNumberOfColors(numColors) {
|
|
266
|
+
while (colormap.colors.length < numColors) {
|
|
267
|
+
colormap.colors.push(COLOR_TRANSPARENT);
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
colormap.colors.length = numColors;
|
|
271
|
+
},
|
|
272
|
+
|
|
273
|
+
getColor(index) {
|
|
274
|
+
if (this.isValidIndex(index)) {
|
|
275
|
+
return colormap.colors[index];
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
return COLOR_TRANSPARENT;
|
|
279
|
+
},
|
|
280
|
+
|
|
281
|
+
getColorRepeating(index) {
|
|
282
|
+
const numColors = colormap.colors.length;
|
|
283
|
+
|
|
284
|
+
index = numColors ? index % numColors : 0;
|
|
285
|
+
|
|
286
|
+
return this.getColor(index);
|
|
287
|
+
},
|
|
288
|
+
|
|
289
|
+
setColor(index, rgba) {
|
|
290
|
+
if (this.isValidIndex(index)) {
|
|
291
|
+
colormap.colors[index] = rgba;
|
|
292
|
+
}
|
|
293
|
+
},
|
|
294
|
+
|
|
295
|
+
addColor(rgba) {
|
|
296
|
+
colormap.colors.push(rgba);
|
|
297
|
+
},
|
|
298
|
+
|
|
299
|
+
insertColor(index, rgba) {
|
|
300
|
+
if (this.isValidIndex(index)) {
|
|
301
|
+
colormap.colors.splice(index, 1, rgba);
|
|
302
|
+
}
|
|
303
|
+
},
|
|
304
|
+
|
|
305
|
+
removeColor(index) {
|
|
306
|
+
if (this.isValidIndex(index)) {
|
|
307
|
+
colormap.colors.splice(index, 1);
|
|
308
|
+
}
|
|
309
|
+
},
|
|
310
|
+
|
|
311
|
+
clearColors() {
|
|
312
|
+
colormap.colors = [];
|
|
313
|
+
},
|
|
314
|
+
|
|
315
|
+
buildLookupTable(lut) {
|
|
316
|
+
if (!lut) {
|
|
317
|
+
return;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
const numColors = colormap.colors.length;
|
|
321
|
+
|
|
322
|
+
lut.setNumberOfTableValues(numColors);
|
|
323
|
+
|
|
324
|
+
for (let i = 0; i < numColors; i++) {
|
|
325
|
+
lut.setTableValue(i, colormap.colors[i]);
|
|
326
|
+
}
|
|
327
|
+
},
|
|
328
|
+
|
|
329
|
+
createLookupTable() {
|
|
330
|
+
const lut = new LookupTable();
|
|
331
|
+
|
|
332
|
+
this.buildLookupTable(lut);
|
|
333
|
+
|
|
334
|
+
return lut;
|
|
335
|
+
},
|
|
336
|
+
|
|
337
|
+
isValidIndex(index) {
|
|
338
|
+
return index >= 0 && index < colormap.colors.length;
|
|
339
|
+
},
|
|
340
|
+
};
|
|
341
|
+
|
|
342
|
+
return cpuFallbackColormap;
|
|
343
|
+
}
|