@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,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* checks if an object is an instance of a TypedArray
|
|
3
|
+
*
|
|
4
|
+
* @param obj - Object to check
|
|
5
|
+
*
|
|
6
|
+
* @returns True if the object is a TypedArray.
|
|
7
|
+
*/
|
|
8
|
+
export default function isTypedArray(obj: any): boolean {
|
|
9
|
+
return (
|
|
10
|
+
obj instanceof Int8Array ||
|
|
11
|
+
obj instanceof Uint8Array ||
|
|
12
|
+
obj instanceof Uint8ClampedArray ||
|
|
13
|
+
obj instanceof Int16Array ||
|
|
14
|
+
obj instanceof Uint16Array ||
|
|
15
|
+
obj instanceof Int32Array ||
|
|
16
|
+
obj instanceof Uint32Array ||
|
|
17
|
+
obj instanceof Float32Array ||
|
|
18
|
+
obj instanceof Float64Array
|
|
19
|
+
);
|
|
20
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { IImage } from '../types';
|
|
2
|
+
|
|
3
|
+
import { loadAndCacheImage } from '../loaders/imageLoader';
|
|
4
|
+
import * as metaData from '../metaData';
|
|
5
|
+
import { RequestType } from '../enums';
|
|
6
|
+
import imageLoadPoolManager from '../requestPool/imageLoadPoolManager';
|
|
7
|
+
import renderToCanvas from './renderToCanvas';
|
|
8
|
+
import { getConfiguration } from '../init';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Loads and renders an imageId to a Canvas. It will use the CPU rendering pipeline
|
|
12
|
+
* for image.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```
|
|
16
|
+
* const canvas = document.getElementById('myCanvas')
|
|
17
|
+
* const imageId = 'myImageId'
|
|
18
|
+
*
|
|
19
|
+
* loadImageToCanvas(canvas, imageId)
|
|
20
|
+
* ```
|
|
21
|
+
* @param imageId - The imageId to render
|
|
22
|
+
* @param canvas - Canvas element to render to
|
|
23
|
+
* @param requestType - The type of request (default to interaction), can be 'interaction' or 'prefetch' or 'thumbnail'
|
|
24
|
+
* the order of loading for the pool manager is interaction, thumbnail, prefetch
|
|
25
|
+
* @param priority - The priority of the request within the request type (lower is higher priority)
|
|
26
|
+
* @returns - A promise that resolves when the image has been rendered with the imageId
|
|
27
|
+
*/
|
|
28
|
+
export default function loadImageToCanvas(
|
|
29
|
+
canvas: HTMLCanvasElement,
|
|
30
|
+
imageId: string,
|
|
31
|
+
requestType = RequestType.Thumbnail,
|
|
32
|
+
priority = -5
|
|
33
|
+
): Promise<string> {
|
|
34
|
+
return new Promise((resolve, reject) => {
|
|
35
|
+
function successCallback(image: IImage, imageId: string) {
|
|
36
|
+
const { modality } = metaData.get('generalSeriesModule', imageId) || {};
|
|
37
|
+
|
|
38
|
+
image.isPreScaled = image.isPreScaled || image.preScale?.scaled;
|
|
39
|
+
renderToCanvas(canvas, image, modality);
|
|
40
|
+
resolve(imageId);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function errorCallback(error: Error, imageId: string) {
|
|
44
|
+
console.error(error, imageId);
|
|
45
|
+
reject(error);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function sendRequest(imageId, imageIdIndex, options) {
|
|
49
|
+
return loadAndCacheImage(imageId, options).then(
|
|
50
|
+
(image) => {
|
|
51
|
+
successCallback.call(this, image, imageId);
|
|
52
|
+
},
|
|
53
|
+
(error) => {
|
|
54
|
+
errorCallback.call(this, error, imageId);
|
|
55
|
+
}
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const { useNorm16Texture } = getConfiguration().rendering;
|
|
60
|
+
|
|
61
|
+
// IMPORTANT: Request type should be passed if not the 'interaction'
|
|
62
|
+
// highest priority will be used for the request type in the imageRetrievalPool
|
|
63
|
+
const options = {
|
|
64
|
+
targetBuffer: {
|
|
65
|
+
type: useNorm16Texture ? undefined : 'Float32Array',
|
|
66
|
+
},
|
|
67
|
+
preScale: {
|
|
68
|
+
enabled: true,
|
|
69
|
+
},
|
|
70
|
+
requestType,
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
imageLoadPoolManager.addRequest(
|
|
74
|
+
sendRequest.bind(null, imageId, null, options),
|
|
75
|
+
requestType,
|
|
76
|
+
{ imageId },
|
|
77
|
+
priority
|
|
78
|
+
);
|
|
79
|
+
});
|
|
80
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { Point3, Plane } from '../types';
|
|
2
|
+
import { vec3, mat3 } from 'gl-matrix';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* It calculates the intersection of a line and a plane.
|
|
6
|
+
* Plane equation is Ax+By+Cz=D
|
|
7
|
+
* @param p0 - [x,y,z] of the first point of the line
|
|
8
|
+
* @param p1 - [x,y,z] of the second point of the line
|
|
9
|
+
* @param plane - [A, B, C, D] Plane parameter: Ax+By+Cz=D
|
|
10
|
+
* @returns - [X,Y,Z] coordinates of the intersection
|
|
11
|
+
*/
|
|
12
|
+
function linePlaneIntersection(p0: Point3, p1: Point3, plane: Plane): Point3 {
|
|
13
|
+
const [x0, y0, z0] = p0;
|
|
14
|
+
const [x1, y1, z1] = p1;
|
|
15
|
+
const [A, B, C, D] = plane;
|
|
16
|
+
const a = x1 - x0;
|
|
17
|
+
const b = y1 - y0;
|
|
18
|
+
const c = z1 - z0;
|
|
19
|
+
const t = (-1 * (A * x0 + B * y0 + C * z0 - D)) / (A * a + B * b + C * c);
|
|
20
|
+
const X = a * t + x0;
|
|
21
|
+
const Y = b * t + y0;
|
|
22
|
+
const Z = c * t + z0;
|
|
23
|
+
|
|
24
|
+
return [X, Y, Z];
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* It returns the plane equation defined by a point and a normal vector.
|
|
29
|
+
* @param normal - normal vector
|
|
30
|
+
* @param point - a point on the plane
|
|
31
|
+
* @returns - [A, B,C, D] of plane equation A*X + B*Y + C*Z = D
|
|
32
|
+
*/
|
|
33
|
+
function planeEquation(normal: Point3, point: Point3 | vec3): Plane {
|
|
34
|
+
const [A, B, C] = normal;
|
|
35
|
+
const D = A * point[0] + B * point[1] + C * point[2];
|
|
36
|
+
return [A, B, C, D];
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Computes the intersection of three planes in 3D space with equations:
|
|
41
|
+
* A1*X + B1*Y + C1*Z = D1
|
|
42
|
+
* A2*X + B2*Y + C2*Z = D2
|
|
43
|
+
* A3*X + B3*Y + C3*Z = D3
|
|
44
|
+
* @returns - [x, y, z] the intersection in the world coordinate
|
|
45
|
+
*/
|
|
46
|
+
function threePlaneIntersection(
|
|
47
|
+
firstPlane: Plane,
|
|
48
|
+
secondPlane: Plane,
|
|
49
|
+
thirdPlane: Plane
|
|
50
|
+
): Point3 {
|
|
51
|
+
const [A1, B1, C1, D1] = firstPlane;
|
|
52
|
+
const [A2, B2, C2, D2] = secondPlane;
|
|
53
|
+
const [A3, B3, C3, D3] = thirdPlane;
|
|
54
|
+
const m0 = mat3.fromValues(A1, A2, A3, B1, B2, B3, C1, C2, C3);
|
|
55
|
+
const m1 = mat3.fromValues(D1, D2, D3, B1, B2, B3, C1, C2, C3);
|
|
56
|
+
const m2 = mat3.fromValues(A1, A2, A3, D1, D2, D3, C1, C2, C3);
|
|
57
|
+
const m3 = mat3.fromValues(A1, A2, A3, B1, B2, B3, D1, D2, D3);
|
|
58
|
+
|
|
59
|
+
// TODO: handle no intersection scenario
|
|
60
|
+
const x = mat3.determinant(m1) / mat3.determinant(m0);
|
|
61
|
+
const y = mat3.determinant(m2) / mat3.determinant(m0);
|
|
62
|
+
const z = mat3.determinant(m3) / mat3.determinant(m0);
|
|
63
|
+
return [x, y, z];
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Computes the distance of a point in 3D space to a plane
|
|
68
|
+
* @param plane - [A, B, C, D] of plane equation A*X + B*Y + C*Z = D
|
|
69
|
+
* @param point - [A, B, C] the plane in World coordinate
|
|
70
|
+
* @param signed - if true, the distance is signed
|
|
71
|
+
* @returns - the distance of the point to the plane
|
|
72
|
+
* */
|
|
73
|
+
function planeDistanceToPoint(
|
|
74
|
+
plane: Plane,
|
|
75
|
+
point: Point3,
|
|
76
|
+
signed = false
|
|
77
|
+
): number {
|
|
78
|
+
const [A, B, C, D] = plane;
|
|
79
|
+
const [x, y, z] = point;
|
|
80
|
+
const numerator = A * x + B * y + C * z - D;
|
|
81
|
+
const distance = Math.abs(numerator) / Math.sqrt(A * A + B * B + C * C);
|
|
82
|
+
const sign = signed ? Math.sign(numerator) : 1;
|
|
83
|
+
return sign * distance;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export {
|
|
87
|
+
linePlaneIntersection,
|
|
88
|
+
planeEquation,
|
|
89
|
+
threePlaneIntersection,
|
|
90
|
+
planeDistanceToPoint,
|
|
91
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { IImage, CPUFallbackEnabledElement } from '../types';
|
|
2
|
+
|
|
3
|
+
import getDefaultViewport from '../RenderingEngine/helpers/cpuFallback/rendering/getDefaultViewport';
|
|
4
|
+
import calculateTransform from '../RenderingEngine/helpers/cpuFallback/rendering/calculateTransform';
|
|
5
|
+
import drawImageSync from '../RenderingEngine/helpers/cpuFallback/drawImageSync';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Renders a cornerstone image object to a canvas.
|
|
9
|
+
* Note: this does not load the image but only takes care of the rendering pipeline
|
|
10
|
+
*
|
|
11
|
+
* @param image - Cornerstone image object
|
|
12
|
+
* @param canvas - Canvas element to render to
|
|
13
|
+
*/
|
|
14
|
+
export default function renderToCanvas(
|
|
15
|
+
canvas: HTMLCanvasElement,
|
|
16
|
+
image: IImage,
|
|
17
|
+
modality?: string
|
|
18
|
+
): void {
|
|
19
|
+
const viewport = getDefaultViewport(canvas, image, modality);
|
|
20
|
+
|
|
21
|
+
const enabledElement: CPUFallbackEnabledElement = {
|
|
22
|
+
canvas,
|
|
23
|
+
viewport,
|
|
24
|
+
image,
|
|
25
|
+
renderingTools: {},
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
enabledElement.transform = calculateTransform(enabledElement);
|
|
29
|
+
|
|
30
|
+
const invalidated = true;
|
|
31
|
+
drawImageSync(enabledElement, invalidated);
|
|
32
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A utility that can be used to scale (in place) an RgbTransferFunction. We
|
|
3
|
+
* often use this to scale the transfer function based on a PET calculation.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* Grabbing a reference to the RGB Transfer function from the viewport:
|
|
7
|
+
* ```
|
|
8
|
+
* const rgbTransferFunction = viewport
|
|
9
|
+
* .getActor()
|
|
10
|
+
* .getProperty()
|
|
11
|
+
* .getRGBTransferFunction(0);
|
|
12
|
+
*
|
|
13
|
+
* scaleRgbTransferFunction(rgbTransferFunction, 2);
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
16
|
+
* @see {@link https://kitware.github.io/vtk-js/api/Rendering_Core_ColorTransferFunction.html|VTK.js: ColorTransferFunction}
|
|
17
|
+
* @param rgbTransferFunction
|
|
18
|
+
* @param scalingFactor
|
|
19
|
+
*/
|
|
20
|
+
export default function scaleRGBTransferFunction(
|
|
21
|
+
rgbTransferFunction: any,
|
|
22
|
+
scalingFactor: number
|
|
23
|
+
): void {
|
|
24
|
+
const size = rgbTransferFunction.getSize();
|
|
25
|
+
|
|
26
|
+
for (let index = 0; index < size; index++) {
|
|
27
|
+
const nodeValue1 = [];
|
|
28
|
+
|
|
29
|
+
rgbTransferFunction.getNodeValue(index, nodeValue1);
|
|
30
|
+
|
|
31
|
+
nodeValue1[1] = nodeValue1[1] * scalingFactor;
|
|
32
|
+
nodeValue1[2] = nodeValue1[2] * scalingFactor;
|
|
33
|
+
nodeValue1[3] = nodeValue1[3] * scalingFactor;
|
|
34
|
+
|
|
35
|
+
rgbTransferFunction.setNodeValue(index, nodeValue1);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { vec3 } from 'gl-matrix';
|
|
2
|
+
import { ActorSliceRange, Point3 } from '../types';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Given a number of frames, `deltaFrames`,
|
|
6
|
+
* move the `focalPoint` and camera `position` so that it moves forward/backwards
|
|
7
|
+
* `deltaFrames` in the camera's normal direction, and snaps to the nearest frame.
|
|
8
|
+
*
|
|
9
|
+
* @param focalPoint - The focal point to move.
|
|
10
|
+
* @param position - The camera position to move.
|
|
11
|
+
* @param sliceRange - The scroll range used to find the current
|
|
12
|
+
* position in the stack, as well as prevent scrolling past the extent of the volume.
|
|
13
|
+
* @param viewPlaneNormal - The normal direction of the camera.
|
|
14
|
+
* @param spacingInNormalDirection - The spacing of frames the normal direction of the camera.
|
|
15
|
+
* @param deltaFrames - The number of frames to jump.
|
|
16
|
+
*
|
|
17
|
+
* @returns The `newFocalPoint` and `newPosition` of the camera.
|
|
18
|
+
*/
|
|
19
|
+
export default function snapFocalPointToSlice(
|
|
20
|
+
focalPoint: Point3,
|
|
21
|
+
position: Point3,
|
|
22
|
+
sliceRange: ActorSliceRange,
|
|
23
|
+
viewPlaneNormal: Point3,
|
|
24
|
+
spacingInNormalDirection: number,
|
|
25
|
+
deltaFrames: number
|
|
26
|
+
): { newFocalPoint: Point3; newPosition: Point3 } {
|
|
27
|
+
const { min, max, current } = sliceRange;
|
|
28
|
+
|
|
29
|
+
// Get the current offset off the camera position so we can add it on at the end.
|
|
30
|
+
const posDiffFromFocalPoint = vec3.create();
|
|
31
|
+
|
|
32
|
+
vec3.sub(posDiffFromFocalPoint, <vec3>position, <vec3>focalPoint);
|
|
33
|
+
|
|
34
|
+
// Now we can see how many steps there are in this direction
|
|
35
|
+
const steps = Math.round((max - min) / spacingInNormalDirection);
|
|
36
|
+
|
|
37
|
+
// Find out current frameIndex
|
|
38
|
+
const fraction = (current - min) / (max - min);
|
|
39
|
+
const floatingStepNumber = fraction * steps;
|
|
40
|
+
let frameIndex = Math.round(floatingStepNumber);
|
|
41
|
+
|
|
42
|
+
// Dolly the focal point back to min slice focal point.
|
|
43
|
+
let newFocalPoint = <Point3>[
|
|
44
|
+
focalPoint[0] -
|
|
45
|
+
viewPlaneNormal[0] * floatingStepNumber * spacingInNormalDirection,
|
|
46
|
+
focalPoint[1] -
|
|
47
|
+
viewPlaneNormal[1] * floatingStepNumber * spacingInNormalDirection,
|
|
48
|
+
focalPoint[2] -
|
|
49
|
+
viewPlaneNormal[2] * floatingStepNumber * spacingInNormalDirection,
|
|
50
|
+
];
|
|
51
|
+
|
|
52
|
+
// Increment the slice number by deltaFrames.
|
|
53
|
+
frameIndex += deltaFrames;
|
|
54
|
+
|
|
55
|
+
// Clamp sliceNumber to volume.
|
|
56
|
+
if (frameIndex > steps) {
|
|
57
|
+
frameIndex = steps;
|
|
58
|
+
} else if (frameIndex < 0) {
|
|
59
|
+
frameIndex = 0;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// Dolly the focal towards to the correct frame focal point.
|
|
63
|
+
const newSlicePosFromMin = frameIndex * spacingInNormalDirection;
|
|
64
|
+
|
|
65
|
+
newFocalPoint = <Point3>[
|
|
66
|
+
newFocalPoint[0] + viewPlaneNormal[0] * newSlicePosFromMin,
|
|
67
|
+
newFocalPoint[1] + viewPlaneNormal[1] * newSlicePosFromMin,
|
|
68
|
+
newFocalPoint[2] + viewPlaneNormal[2] * newSlicePosFromMin,
|
|
69
|
+
];
|
|
70
|
+
|
|
71
|
+
const newPosition = <Point3>[
|
|
72
|
+
newFocalPoint[0] + posDiffFromFocalPoint[0],
|
|
73
|
+
newFocalPoint[1] + posDiffFromFocalPoint[1],
|
|
74
|
+
newFocalPoint[2] + posDiffFromFocalPoint[2],
|
|
75
|
+
];
|
|
76
|
+
|
|
77
|
+
return { newFocalPoint, newPosition };
|
|
78
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { mat4 } from 'gl-matrix';
|
|
2
|
+
import { addProvider } from '../metaData';
|
|
3
|
+
|
|
4
|
+
const state = {};
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Simple metadataProvider object to store metadata for spatial registration module.
|
|
8
|
+
*/
|
|
9
|
+
const spatialRegistrationMetadataProvider = {
|
|
10
|
+
/* Adding a new entry to the state object. */
|
|
11
|
+
add: (query: string[], payload: mat4): void => {
|
|
12
|
+
const [viewportId1, viewportId2] = query;
|
|
13
|
+
const entryId = `${viewportId1}_${viewportId2}`;
|
|
14
|
+
|
|
15
|
+
if (!state[entryId]) {
|
|
16
|
+
state[entryId] = {};
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
state[entryId] = payload;
|
|
20
|
+
},
|
|
21
|
+
|
|
22
|
+
get: (type: string, query: string[]): mat4 => {
|
|
23
|
+
if (type !== 'spatialRegistrationModule') {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const [viewportId1, viewportId2] = query;
|
|
28
|
+
|
|
29
|
+
// check both ways
|
|
30
|
+
const entryId = `${viewportId1}_${viewportId2}`;
|
|
31
|
+
|
|
32
|
+
if (state[entryId]) {
|
|
33
|
+
return state[entryId];
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const entryIdReverse = `${viewportId2}_${viewportId1}`;
|
|
37
|
+
|
|
38
|
+
if (state[entryIdReverse]) {
|
|
39
|
+
return mat4.invert(mat4.create(), state[entryIdReverse]);
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
addProvider(
|
|
45
|
+
spatialRegistrationMetadataProvider.get.bind(
|
|
46
|
+
spatialRegistrationMetadataProvider
|
|
47
|
+
)
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
export default spatialRegistrationMetadataProvider;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type Point3 from '../types/Point3';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Given an imageData object and a point in physical space, return the index of the
|
|
5
|
+
* voxel that contains the point. TODO: this should be pushed to vtk upstream.
|
|
6
|
+
* @param imageData - The image data object.
|
|
7
|
+
* @param physicalPoint - The point in physical space that you want to transform to
|
|
8
|
+
* index space.
|
|
9
|
+
* @returns An array of integers.
|
|
10
|
+
*/
|
|
11
|
+
export default function transformWorldToIndex(imageData, worldPos: Point3) {
|
|
12
|
+
const continuousIndex = imageData.worldToIndex(worldPos);
|
|
13
|
+
const index = continuousIndex.map(Math.round);
|
|
14
|
+
|
|
15
|
+
return index;
|
|
16
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import eventTarget from '../eventTarget';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Small utility to trigger a custom event for a given EventTarget.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
*
|
|
8
|
+
* ```javascript
|
|
9
|
+
* triggerEvent(element, Events.IMAGE_RENDERED, { element })
|
|
10
|
+
* ```
|
|
11
|
+
* or it can trigger event on the eventTarget itself
|
|
12
|
+
*
|
|
13
|
+
* ```javascript
|
|
14
|
+
* triggerEvent(eventTarget, CSTOOLS_EVENTS.ANNOTATION_MODIFIED, { viewportId, annotationUID })
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* @param el - The element or EventTarget to trigger the event upon
|
|
18
|
+
* @param type - The event type name
|
|
19
|
+
* @param detail - The event detail to be sent
|
|
20
|
+
* @returns false if event is cancelable and at least one of the event handlers
|
|
21
|
+
* which received event called Event.preventDefault(). Otherwise it returns true.
|
|
22
|
+
*/
|
|
23
|
+
export default function triggerEvent(
|
|
24
|
+
el: EventTarget = eventTarget,
|
|
25
|
+
type: string,
|
|
26
|
+
detail: unknown = null
|
|
27
|
+
): boolean {
|
|
28
|
+
if (!type) {
|
|
29
|
+
throw new Error('Event type was not defined');
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const event = new CustomEvent(type, {
|
|
33
|
+
detail,
|
|
34
|
+
cancelable: true,
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
return el.dispatchEvent(event);
|
|
38
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// prettier-ignore
|
|
2
|
+
// @ts-nocheck
|
|
3
|
+
/**
|
|
4
|
+
* Generates a unique id that has limited chance of collision
|
|
5
|
+
*
|
|
6
|
+
* @see {@link https://stackoverflow.com/a/2117523/1867984|StackOverflow: Source}
|
|
7
|
+
* @returns a v4 compliant GUID
|
|
8
|
+
*/
|
|
9
|
+
export default function uuidv4(): string {
|
|
10
|
+
return ([1e7]+-1e3+-4e3+-8e3+-1e11).replace(/[018]/g, c =>
|
|
11
|
+
(c ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> c / 4).toString(16)
|
|
12
|
+
);
|
|
13
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Given a low and high window level, return the window width and window center
|
|
3
|
+
* @param low - The low window level.
|
|
4
|
+
* @param high - The high window level.
|
|
5
|
+
* @returns a JavaScript object with two properties: windowWidth and windowCenter.
|
|
6
|
+
*/
|
|
7
|
+
function toWindowLevel(
|
|
8
|
+
low: number,
|
|
9
|
+
high: number
|
|
10
|
+
): {
|
|
11
|
+
windowWidth: number;
|
|
12
|
+
windowCenter: number;
|
|
13
|
+
} {
|
|
14
|
+
const windowWidth = Math.abs(low - high);
|
|
15
|
+
const windowCenter = low + windowWidth / 2;
|
|
16
|
+
|
|
17
|
+
return { windowWidth, windowCenter };
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Given a window width and center, return the lower and upper bounds of the window
|
|
22
|
+
* @param windowWidth - the width of the window in HU
|
|
23
|
+
* @param windowCenter - The center of the window.
|
|
24
|
+
* @returns a JavaScript object with two properties: lower and upper.
|
|
25
|
+
*/
|
|
26
|
+
function toLowHighRange(
|
|
27
|
+
windowWidth: number,
|
|
28
|
+
windowCenter: number
|
|
29
|
+
): {
|
|
30
|
+
lower: number;
|
|
31
|
+
upper: number;
|
|
32
|
+
} {
|
|
33
|
+
const lower = windowCenter - windowWidth / 2.0;
|
|
34
|
+
const upper = windowCenter + windowWidth / 2.0;
|
|
35
|
+
|
|
36
|
+
return { lower, upper };
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export { toWindowLevel, toLowHighRange };
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { vec3 } from 'gl-matrix';
|
|
2
|
+
import { metaData } from '..';
|
|
3
|
+
import { Point2, Point3 } from '../types';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Given the imageId, and 3d coordinates on the world space, it returns the continuos
|
|
7
|
+
* image coordinates (IJ) on the image space. The image space is
|
|
8
|
+
* defined with [0,0] being on the top left corner of the top left pixel,
|
|
9
|
+
* the [1,1] being on the bottom right corner of the top left pixel.
|
|
10
|
+
* @param imageId - The image id
|
|
11
|
+
* @param worldCoords - The 3d coordinates on the world.
|
|
12
|
+
* @returns The 2d coordinates on the image.
|
|
13
|
+
*
|
|
14
|
+
*/
|
|
15
|
+
function worldToImageCoords(
|
|
16
|
+
imageId: string,
|
|
17
|
+
worldCoords: Point3
|
|
18
|
+
): Point2 | undefined {
|
|
19
|
+
const imagePlaneModule = metaData.get('imagePlaneModule', imageId);
|
|
20
|
+
|
|
21
|
+
if (!imagePlaneModule) {
|
|
22
|
+
throw new Error(`No imagePlaneModule found for imageId: ${imageId}`);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// For the image coordinates we need to calculate the transformation matrix
|
|
26
|
+
// from the world coordinates to the image coordinates.
|
|
27
|
+
|
|
28
|
+
const {
|
|
29
|
+
columnCosines,
|
|
30
|
+
columnPixelSpacing,
|
|
31
|
+
rowCosines,
|
|
32
|
+
rowPixelSpacing,
|
|
33
|
+
imagePositionPatient: origin,
|
|
34
|
+
rows,
|
|
35
|
+
columns,
|
|
36
|
+
} = imagePlaneModule;
|
|
37
|
+
|
|
38
|
+
// The origin is the image position patient, but since image coordinates start
|
|
39
|
+
// from [0,0] for the top left hand of the first pixel, and the origin is at the
|
|
40
|
+
// center of the first pixel, we need to account for this.
|
|
41
|
+
const newOrigin = vec3.create();
|
|
42
|
+
|
|
43
|
+
vec3.scaleAndAdd(newOrigin, origin, columnCosines, -columnPixelSpacing / 2);
|
|
44
|
+
vec3.scaleAndAdd(newOrigin, newOrigin, rowCosines, -rowPixelSpacing / 2);
|
|
45
|
+
|
|
46
|
+
// Get the subtraction vector from the origin to the world coordinates
|
|
47
|
+
const sub = vec3.create();
|
|
48
|
+
vec3.sub(sub, worldCoords, newOrigin);
|
|
49
|
+
|
|
50
|
+
// Projected distance of the sub vector onto the rowCosines
|
|
51
|
+
const rowDistance = vec3.dot(sub, rowCosines);
|
|
52
|
+
|
|
53
|
+
// Projected distance of the sub vector onto the columnCosines
|
|
54
|
+
const columnDistance = vec3.dot(sub, columnCosines);
|
|
55
|
+
|
|
56
|
+
const imageCoords = [
|
|
57
|
+
rowDistance / rowPixelSpacing,
|
|
58
|
+
columnDistance / columnPixelSpacing,
|
|
59
|
+
];
|
|
60
|
+
|
|
61
|
+
return imageCoords as Point2;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export default worldToImageCoords;
|