@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.
- package/dist/cjs/loaders/volumeLoader.d.ts +1 -0
- package/dist/cjs/loaders/volumeLoader.js +5 -1
- package/dist/cjs/loaders/volumeLoader.js.map +1 -1
- package/dist/cjs/utilities/getSliceRange.js +3 -1
- package/dist/cjs/utilities/getSliceRange.js.map +1 -1
- package/dist/cjs/utilities/getTargetVolumeAndSpacingInNormalDir.js +7 -0
- package/dist/cjs/utilities/getTargetVolumeAndSpacingInNormalDir.js.map +1 -1
- package/dist/esm/loaders/volumeLoader.d.ts +1 -0
- package/dist/esm/loaders/volumeLoader.js +3 -0
- package/dist/esm/loaders/volumeLoader.js.map +1 -1
- package/dist/esm/utilities/getSliceRange.js +3 -1
- package/dist/esm/utilities/getSliceRange.js.map +1 -1
- package/dist/esm/utilities/getTargetVolumeAndSpacingInNormalDir.js +7 -0
- package/dist/esm/utilities/getTargetVolumeAndSpacingInNormalDir.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,102 @@
|
|
|
1
|
+
import {
|
|
2
|
+
IImageData,
|
|
3
|
+
IStackViewport,
|
|
4
|
+
IVolumeViewport,
|
|
5
|
+
Point2,
|
|
6
|
+
Point3,
|
|
7
|
+
} from '../types';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Given a viewport, return the corners of the image in the viewport in world coordinates.
|
|
11
|
+
* Note that this is different than the corners of the canvas in world coordinates since
|
|
12
|
+
* an image can be zoomed out and the canvas can be larger than the image; hence, the
|
|
13
|
+
* corners of the canvas in world coordinates will be outside the image.
|
|
14
|
+
*
|
|
15
|
+
* @param viewport - The viewport to get the corners of.
|
|
16
|
+
* @returns The corners of the image in the viewport in world coordinates.
|
|
17
|
+
*/
|
|
18
|
+
export default function getViewportImageCornersInWorld(
|
|
19
|
+
viewport: IStackViewport | IVolumeViewport
|
|
20
|
+
): Point3[] {
|
|
21
|
+
const { imageData, dimensions } = viewport.getImageData() as IImageData;
|
|
22
|
+
const { canvas } = viewport;
|
|
23
|
+
|
|
24
|
+
const topLeftCanvas: Point2 = [0, 0];
|
|
25
|
+
const topRightCanvas: Point2 = [canvas.width, 0];
|
|
26
|
+
const bottomRightCanvas: Point2 = [canvas.width, canvas.height];
|
|
27
|
+
const bottomLeftCanvas: Point2 = [0, canvas.height];
|
|
28
|
+
|
|
29
|
+
const topLeftWorld = viewport.canvasToWorld(topLeftCanvas);
|
|
30
|
+
const topRightWorld = viewport.canvasToWorld(topRightCanvas);
|
|
31
|
+
const bottomRightWorld = viewport.canvasToWorld(bottomRightCanvas);
|
|
32
|
+
const bottomLeftWorld = viewport.canvasToWorld(bottomLeftCanvas);
|
|
33
|
+
|
|
34
|
+
const topLeftImage = imageData.worldToIndex(topLeftWorld);
|
|
35
|
+
const topRightImage = imageData.worldToIndex(topRightWorld);
|
|
36
|
+
const bottomRightImage = imageData.worldToIndex(bottomRightWorld);
|
|
37
|
+
const bottomLeftImage = imageData.worldToIndex(bottomLeftWorld);
|
|
38
|
+
|
|
39
|
+
return _getStackViewportImageCorners({
|
|
40
|
+
dimensions,
|
|
41
|
+
imageData,
|
|
42
|
+
topLeftImage,
|
|
43
|
+
topRightImage,
|
|
44
|
+
bottomRightImage,
|
|
45
|
+
bottomLeftImage,
|
|
46
|
+
topLeftWorld,
|
|
47
|
+
topRightWorld,
|
|
48
|
+
bottomRightWorld,
|
|
49
|
+
bottomLeftWorld,
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function _getStackViewportImageCorners({
|
|
54
|
+
dimensions,
|
|
55
|
+
imageData,
|
|
56
|
+
topLeftImage,
|
|
57
|
+
topRightImage,
|
|
58
|
+
bottomRightImage,
|
|
59
|
+
bottomLeftImage,
|
|
60
|
+
topLeftWorld,
|
|
61
|
+
topRightWorld,
|
|
62
|
+
bottomRightWorld,
|
|
63
|
+
bottomLeftWorld,
|
|
64
|
+
}) {
|
|
65
|
+
const topLeftImageWorld = _isInBounds(topLeftImage, dimensions)
|
|
66
|
+
? topLeftWorld
|
|
67
|
+
: (imageData.indexToWorld([0, 0, 0]) as Point3);
|
|
68
|
+
|
|
69
|
+
const topRightImageWorld = _isInBounds(topRightImage, dimensions)
|
|
70
|
+
? topRightWorld
|
|
71
|
+
: (imageData.indexToWorld([dimensions[0] - 1, 0, 0]) as Point3);
|
|
72
|
+
|
|
73
|
+
const bottomRightImageWorld = _isInBounds(bottomRightImage, dimensions)
|
|
74
|
+
? bottomRightWorld
|
|
75
|
+
: (imageData.indexToWorld([
|
|
76
|
+
dimensions[0] - 1,
|
|
77
|
+
dimensions[1] - 1,
|
|
78
|
+
0,
|
|
79
|
+
]) as Point3);
|
|
80
|
+
|
|
81
|
+
const bottomLeftImageWorld = _isInBounds(bottomLeftImage, dimensions)
|
|
82
|
+
? bottomLeftWorld
|
|
83
|
+
: (imageData.indexToWorld([0, dimensions[1] - 1, 0]) as Point3);
|
|
84
|
+
|
|
85
|
+
return [
|
|
86
|
+
topLeftImageWorld,
|
|
87
|
+
topRightImageWorld,
|
|
88
|
+
bottomLeftImageWorld,
|
|
89
|
+
bottomRightImageWorld,
|
|
90
|
+
];
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function _isInBounds(imageCoord, dimensions) {
|
|
94
|
+
return (
|
|
95
|
+
imageCoord[0] > 0 ||
|
|
96
|
+
imageCoord[0] < dimensions[0] - 1 ||
|
|
97
|
+
imageCoord[1] > 0 ||
|
|
98
|
+
imageCoord[1] < dimensions[1] - 1 ||
|
|
99
|
+
imageCoord[2] > 0 ||
|
|
100
|
+
imageCoord[2] < dimensions[2] - 1
|
|
101
|
+
);
|
|
102
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { getRenderingEngine } from '../RenderingEngine';
|
|
2
|
+
import { getRenderingEngines } from '../RenderingEngine/getRenderingEngine';
|
|
3
|
+
import { IStackViewport, IVolumeViewport } from '../types';
|
|
4
|
+
|
|
5
|
+
type Viewport = IStackViewport | IVolumeViewport;
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Get the viewport that is rendering the image with the given imageURI (imageId without
|
|
9
|
+
* the loader schema), this can be a stackViewport or a volumeViewport.
|
|
10
|
+
*
|
|
11
|
+
* @param renderingEngine - The rendering engine that is rendering the viewports
|
|
12
|
+
* @param imageURI - The imageURI of the image that is requested
|
|
13
|
+
* @returns A Viewport
|
|
14
|
+
*/
|
|
15
|
+
export default function getViewportsWithImageURI(
|
|
16
|
+
imageURI: string,
|
|
17
|
+
renderingEngineId?: string
|
|
18
|
+
): Array<Viewport> {
|
|
19
|
+
// If rendering engine is not provided, use all rendering engines
|
|
20
|
+
let renderingEngines;
|
|
21
|
+
if (renderingEngineId) {
|
|
22
|
+
renderingEngines = [getRenderingEngine(renderingEngineId)];
|
|
23
|
+
} else {
|
|
24
|
+
renderingEngines = getRenderingEngines();
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const viewports = [];
|
|
28
|
+
renderingEngines.forEach((renderingEngine) => {
|
|
29
|
+
const stackViewports = renderingEngine.getStackViewports();
|
|
30
|
+
|
|
31
|
+
const filteredStackViewports = stackViewports.filter((viewport) =>
|
|
32
|
+
viewport.hasImageURI(imageURI)
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
// If no stack viewport found but a volumeViewport is rendering the same data
|
|
36
|
+
const volumeViewports = renderingEngine.getVolumeViewports();
|
|
37
|
+
|
|
38
|
+
const filteredVolumeViewports = volumeViewports.filter((viewport) =>
|
|
39
|
+
viewport.hasImageURI(imageURI)
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
viewports.push(...filteredStackViewports, ...filteredVolumeViewports);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
return viewports;
|
|
46
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { IVolumeViewport } from '../types';
|
|
2
|
+
import {
|
|
3
|
+
getRenderingEngines,
|
|
4
|
+
getRenderingEngine,
|
|
5
|
+
} from '../RenderingEngine/getRenderingEngine';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Similar to {@link getVolumeViewportsContainingSameVolumes}, but uses the volumeId
|
|
9
|
+
* to filter viewports that contain the same volume.
|
|
10
|
+
*
|
|
11
|
+
* @returns VolumeViewport viewports array
|
|
12
|
+
*/
|
|
13
|
+
function getViewportsWithVolumeId(
|
|
14
|
+
volumeId: string,
|
|
15
|
+
renderingEngineId?: string
|
|
16
|
+
): Array<IVolumeViewport> {
|
|
17
|
+
// If rendering engine is not provided, use all rendering engines
|
|
18
|
+
let renderingEngines;
|
|
19
|
+
if (renderingEngineId) {
|
|
20
|
+
renderingEngines = [getRenderingEngine(renderingEngineId)];
|
|
21
|
+
} else {
|
|
22
|
+
renderingEngines = getRenderingEngines();
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const targetViewports = [];
|
|
26
|
+
|
|
27
|
+
renderingEngines.forEach((renderingEngine) => {
|
|
28
|
+
const viewports = renderingEngine.getVolumeViewports();
|
|
29
|
+
const filteredViewports = viewports.filter((vp) =>
|
|
30
|
+
vp.hasVolumeId(volumeId)
|
|
31
|
+
);
|
|
32
|
+
targetViewports.push(...filteredViewports);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
return targetViewports;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export default getViewportsWithVolumeId;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import vtkColorTransferFunction from '@kitware/vtk.js/Rendering/Core/ColorTransferFunction';
|
|
2
|
+
|
|
3
|
+
export default function getVoiFromSigmoidRGBTransferFunction(
|
|
4
|
+
cfun: vtkColorTransferFunction
|
|
5
|
+
): [number, number] {
|
|
6
|
+
let cfunRange = [];
|
|
7
|
+
// @ts-ignore: vtk d ts problem
|
|
8
|
+
const [lower, upper] = cfun.getRange();
|
|
9
|
+
cfun.getTable(lower, upper, 1024, cfunRange);
|
|
10
|
+
cfunRange = cfunRange.filter((v, k) => k % 3 === 0);
|
|
11
|
+
const cfunDomain = [...Array(1024).keys()].map((v, k) => {
|
|
12
|
+
return lower + ((upper - lower) / (1024 - 1)) * k;
|
|
13
|
+
});
|
|
14
|
+
const y1 = cfunRange[256];
|
|
15
|
+
const logy1 = Math.log((1 - y1) / y1);
|
|
16
|
+
const x1 = cfunDomain[256];
|
|
17
|
+
const y2 = cfunRange[256 * 3];
|
|
18
|
+
const logy2 = Math.log((1 - y2) / y2);
|
|
19
|
+
const x2 = cfunDomain[256 * 3];
|
|
20
|
+
const ww = Math.round((4 * (x2 - x1)) / (logy1 - logy2));
|
|
21
|
+
const wc = Math.round(x1 + (ww * logy1) / 4);
|
|
22
|
+
return [Math.round(wc - ww / 2), Math.round(wc + ww / 2)];
|
|
23
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Point3 } from '../types';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Converts `vtkVolumeActor` bounds to corners in world space.
|
|
5
|
+
*
|
|
6
|
+
* @param volumeActor - The `vtkVolumeActor`.
|
|
7
|
+
*
|
|
8
|
+
* @returns An array of the corners of the `volumeActor` in world space.
|
|
9
|
+
*/
|
|
10
|
+
export default function getVolumeActorCorners(volumeActor): Array<Point3> {
|
|
11
|
+
const imageData = volumeActor.getMapper().getInputData();
|
|
12
|
+
const bounds = imageData.extentToBounds(imageData.getExtent());
|
|
13
|
+
|
|
14
|
+
return [
|
|
15
|
+
[bounds[0], bounds[2], bounds[4]],
|
|
16
|
+
[bounds[0], bounds[2], bounds[5]],
|
|
17
|
+
[bounds[0], bounds[3], bounds[4]],
|
|
18
|
+
[bounds[0], bounds[3], bounds[5]],
|
|
19
|
+
[bounds[1], bounds[2], bounds[4]],
|
|
20
|
+
[bounds[1], bounds[2], bounds[5]],
|
|
21
|
+
[bounds[1], bounds[3], bounds[4]],
|
|
22
|
+
[bounds[1], bounds[3], bounds[5]],
|
|
23
|
+
];
|
|
24
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import getSliceRange from './getSliceRange';
|
|
2
|
+
import getTargetVolumeAndSpacingInNormalDir from './getTargetVolumeAndSpacingInNormalDir';
|
|
3
|
+
import {
|
|
4
|
+
ActorSliceRange,
|
|
5
|
+
IVolumeViewport,
|
|
6
|
+
ICamera,
|
|
7
|
+
VolumeActor,
|
|
8
|
+
} from '../types';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Calculates the slice range for the given volume based on its orientation
|
|
12
|
+
* @param viewport - Volume viewport
|
|
13
|
+
* @param volumeId - Id of one of the volumes loaded on the given viewport
|
|
14
|
+
* @returns slice range information
|
|
15
|
+
*/
|
|
16
|
+
function getVolumeSliceRangeInfo(
|
|
17
|
+
viewport: IVolumeViewport,
|
|
18
|
+
volumeId: string
|
|
19
|
+
): {
|
|
20
|
+
sliceRange: ActorSliceRange;
|
|
21
|
+
spacingInNormalDirection: number;
|
|
22
|
+
camera: ICamera;
|
|
23
|
+
} {
|
|
24
|
+
const camera = viewport.getCamera();
|
|
25
|
+
const { focalPoint, viewPlaneNormal } = camera;
|
|
26
|
+
const { spacingInNormalDirection, actorUID } =
|
|
27
|
+
getTargetVolumeAndSpacingInNormalDir(viewport, camera, volumeId);
|
|
28
|
+
|
|
29
|
+
if (!actorUID) {
|
|
30
|
+
throw new Error(
|
|
31
|
+
`Could not find image volume with id ${volumeId} in the viewport`
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const actorEntry = viewport.getActor(actorUID);
|
|
36
|
+
|
|
37
|
+
if (!actorEntry) {
|
|
38
|
+
console.warn('No actor found for with actorUID of', actorUID);
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const volumeActor = actorEntry.actor as VolumeActor;
|
|
43
|
+
const sliceRange = getSliceRange(volumeActor, viewPlaneNormal, focalPoint);
|
|
44
|
+
|
|
45
|
+
return {
|
|
46
|
+
sliceRange,
|
|
47
|
+
spacingInNormalDirection,
|
|
48
|
+
camera,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export default getVolumeSliceRangeInfo;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { IVolumeViewport } from '../types';
|
|
2
|
+
import getVolumeSliceRangeInfo from './getVolumeSliceRangeInfo';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Calculates the number os steps the volume can scroll based on its orientation
|
|
6
|
+
* @param viewport - Volume viewport
|
|
7
|
+
* @param volumeId - Id of one of the volumes loaded on the given viewport
|
|
8
|
+
* @returns number of steps the volume can scroll and its current position
|
|
9
|
+
*/
|
|
10
|
+
function getVolumeViewportScrollInfo(
|
|
11
|
+
viewport: IVolumeViewport,
|
|
12
|
+
volumeId: string
|
|
13
|
+
) {
|
|
14
|
+
const { sliceRange, spacingInNormalDirection } = getVolumeSliceRangeInfo(
|
|
15
|
+
viewport,
|
|
16
|
+
volumeId
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
const { min, max, current } = sliceRange;
|
|
20
|
+
|
|
21
|
+
// Now we can see how many steps there are in this direction
|
|
22
|
+
const numScrollSteps = Math.round((max - min) / spacingInNormalDirection);
|
|
23
|
+
|
|
24
|
+
// Find out current frameIndex
|
|
25
|
+
const fraction = (current - min) / (max - min);
|
|
26
|
+
const floatingStepNumber = fraction * numScrollSteps;
|
|
27
|
+
const currentStepIndex = Math.round(floatingStepNumber);
|
|
28
|
+
|
|
29
|
+
return { numScrollSteps, currentStepIndex };
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export default getVolumeViewportScrollInfo;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { IVolumeViewport } from '../types';
|
|
2
|
+
import {
|
|
3
|
+
getRenderingEngines,
|
|
4
|
+
getRenderingEngine,
|
|
5
|
+
} from '../RenderingEngine/getRenderingEngine';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Returns the viewports containing the same volume actors (all actors) the same
|
|
9
|
+
* as the target viewport. If renderingEngineId is provided, it will only return
|
|
10
|
+
* viewports that are associated with the renderingEngineId; otherwise, it will
|
|
11
|
+
* return search in all rendering engines.
|
|
12
|
+
*
|
|
13
|
+
* This method is useful for finding viewports that are associated with the same
|
|
14
|
+
* volume (e.g., for tools that share state between viewports).
|
|
15
|
+
*
|
|
16
|
+
* @param viewport - target viewport
|
|
17
|
+
* @returns array of viewports that have the same volume actor as the target viewport
|
|
18
|
+
*/
|
|
19
|
+
function getVolumeViewportsContainingSameVolumes(
|
|
20
|
+
targetViewport: IVolumeViewport,
|
|
21
|
+
renderingEngineId?: string
|
|
22
|
+
): Array<IVolumeViewport> {
|
|
23
|
+
// If rendering engine is not provided, use all rendering engines
|
|
24
|
+
let renderingEngines;
|
|
25
|
+
if (renderingEngineId) {
|
|
26
|
+
renderingEngines = [getRenderingEngine(renderingEngineId)];
|
|
27
|
+
} else {
|
|
28
|
+
renderingEngines = getRenderingEngines();
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const sameVolumesViewports = [];
|
|
32
|
+
|
|
33
|
+
renderingEngines.forEach((renderingEngine) => {
|
|
34
|
+
const targetActors = targetViewport.getActors();
|
|
35
|
+
const viewports = renderingEngine.getVolumeViewports();
|
|
36
|
+
|
|
37
|
+
for (const vp of viewports) {
|
|
38
|
+
const vpActors = vp.getActors();
|
|
39
|
+
|
|
40
|
+
if (vpActors.length !== targetActors.length) {
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// every targetActors should be in the vpActors
|
|
45
|
+
const sameVolumes = targetActors.every(({ uid }) =>
|
|
46
|
+
vpActors.find((vpActor) => uid === vpActor.uid)
|
|
47
|
+
);
|
|
48
|
+
|
|
49
|
+
if (sameVolumes) {
|
|
50
|
+
sameVolumesViewports.push(vp);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
return sameVolumesViewports;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export default getVolumeViewportsContainingSameVolumes;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A function that checks if there is a value in the array that is NaN.
|
|
3
|
+
* or if the input is a number it just checks if it is NaN.
|
|
4
|
+
* @param input - The input to check if it is NaN.
|
|
5
|
+
* @returns - True if the input is NaN, false otherwise.
|
|
6
|
+
*/
|
|
7
|
+
export default function hasNaNValues(input: number[] | number): boolean {
|
|
8
|
+
if (Array.isArray(input)) {
|
|
9
|
+
return input.some((value) => Number.isNaN(value));
|
|
10
|
+
}
|
|
11
|
+
return Number.isNaN(input);
|
|
12
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Removes the data loader scheme from the imageId
|
|
3
|
+
*
|
|
4
|
+
* @param imageId - Image ID
|
|
5
|
+
* @returns imageId without the data loader scheme
|
|
6
|
+
*/
|
|
7
|
+
export default function imageIdToURI(imageId: string): string {
|
|
8
|
+
const colonIndex = imageId.indexOf(':');
|
|
9
|
+
return imageId.substring(colonIndex + 1);
|
|
10
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { vec3 } from 'gl-matrix';
|
|
2
|
+
import { metaData } from '..';
|
|
3
|
+
import { Point2, Point3 } from '../types';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Given the imageId and a 2d coordinates on the image space with [0,0] being the top left corner
|
|
7
|
+
* of the top left pixel, and options which includes the imageId, it returns the
|
|
8
|
+
* 3d coordinates on the world space.
|
|
9
|
+
* @param imageId - The image id
|
|
10
|
+
* @param imageCoords - The 2d coordinates on the image
|
|
11
|
+
* @returns The 3d coordinates on the world.
|
|
12
|
+
*
|
|
13
|
+
*/
|
|
14
|
+
export default function imageToWorldCoords(
|
|
15
|
+
imageId: string,
|
|
16
|
+
imageCoords: Point2
|
|
17
|
+
): Point3 | undefined {
|
|
18
|
+
const imagePlaneModule = metaData.get('imagePlaneModule', imageId);
|
|
19
|
+
|
|
20
|
+
if (!imagePlaneModule) {
|
|
21
|
+
throw new Error(`No imagePlaneModule found for imageId: ${imageId}`);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const {
|
|
25
|
+
columnCosines,
|
|
26
|
+
columnPixelSpacing,
|
|
27
|
+
rowCosines,
|
|
28
|
+
rowPixelSpacing,
|
|
29
|
+
imagePositionPatient: origin,
|
|
30
|
+
} = imagePlaneModule;
|
|
31
|
+
|
|
32
|
+
// calculate the image coordinates in the world space
|
|
33
|
+
const imageCoordsInWorld = vec3.create();
|
|
34
|
+
|
|
35
|
+
// move from origin in the direction of the row cosines with the amount of
|
|
36
|
+
// row pixel spacing times the first element of the image coordinates vector
|
|
37
|
+
vec3.scaleAndAdd(
|
|
38
|
+
imageCoordsInWorld,
|
|
39
|
+
origin,
|
|
40
|
+
rowCosines,
|
|
41
|
+
// to accommodate the [0,0] being on the top left corner of the top left pixel
|
|
42
|
+
// but the origin is at the center of the top left pixel
|
|
43
|
+
rowPixelSpacing * (imageCoords[0] - 0.5)
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
vec3.scaleAndAdd(
|
|
47
|
+
imageCoordsInWorld,
|
|
48
|
+
imageCoordsInWorld,
|
|
49
|
+
columnCosines,
|
|
50
|
+
columnPixelSpacing * (imageCoords[1] - 0.5)
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
return Array.from(imageCoordsInWorld) as Point3;
|
|
54
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import csUtils from './invertRgbTransferFunction';
|
|
2
|
+
import createSigmoidRGBTransferFunction from './createSigmoidRGBTransferFunction';
|
|
3
|
+
import getVoiFromSigmoidRGBTransferFunction from './getVoiFromSigmoidRGBTransferFunction';
|
|
4
|
+
import createLinearRGBTransferFunction from './createLinearRGBTransferFunction';
|
|
5
|
+
import scaleRgbTransferFunction from './scaleRgbTransferFunction';
|
|
6
|
+
import triggerEvent from './triggerEvent';
|
|
7
|
+
import uuidv4 from './uuidv4';
|
|
8
|
+
import getMinMax from './getMinMax';
|
|
9
|
+
import getRuntimeId from './getRuntimeId';
|
|
10
|
+
import imageIdToURI from './imageIdToURI';
|
|
11
|
+
import calibratedPixelSpacingMetadataProvider from './calibratedPixelSpacingMetadataProvider';
|
|
12
|
+
import isEqual from './isEqual';
|
|
13
|
+
import isOpposite from './isOpposite';
|
|
14
|
+
import createUint8SharedArray from './createUint8SharedArray';
|
|
15
|
+
import createFloat32SharedArray from './createFloat32SharedArray';
|
|
16
|
+
import createUint16SharedArray from './createUInt16SharedArray';
|
|
17
|
+
import createInt16SharedArray from './createInt16SharedArray';
|
|
18
|
+
import getClosestImageId from './getClosestImageId';
|
|
19
|
+
import getSpacingInNormalDirection from './getSpacingInNormalDirection';
|
|
20
|
+
import getTargetVolumeAndSpacingInNormalDir from './getTargetVolumeAndSpacingInNormalDir';
|
|
21
|
+
import getVolumeActorCorners from './getVolumeActorCorners';
|
|
22
|
+
import indexWithinDimensions from './indexWithinDimensions';
|
|
23
|
+
import getVolumeViewportsContainingSameVolumes from './getVolumeViewportsContainingSameVolumes';
|
|
24
|
+
import getViewportsWithVolumeId from './getViewportsWithVolumeId';
|
|
25
|
+
import transformWorldToIndex from './transformWorldToIndex';
|
|
26
|
+
import loadImageToCanvas from './loadImageToCanvas';
|
|
27
|
+
import renderToCanvas from './renderToCanvas';
|
|
28
|
+
import worldToImageCoords from './worldToImageCoords';
|
|
29
|
+
import imageToWorldCoords from './imageToWorldCoords';
|
|
30
|
+
import getVolumeSliceRangeInfo from './getVolumeSliceRangeInfo';
|
|
31
|
+
import getVolumeViewportScrollInfo from './getVolumeViewportScrollInfo';
|
|
32
|
+
import getSliceRange from './getSliceRange';
|
|
33
|
+
import snapFocalPointToSlice from './snapFocalPointToSlice';
|
|
34
|
+
import getImageSliceDataForVolumeViewport from './getImageSliceDataForVolumeViewport';
|
|
35
|
+
import { isImageActor, actorIsA } from './actorCheck';
|
|
36
|
+
import getViewportsWithImageURI from './getViewportsWithImageURI';
|
|
37
|
+
import getClosestStackImageIndexForPoint from './getClosestStackImageIndexForPoint';
|
|
38
|
+
import calculateViewportsSpatialRegistration from './calculateViewportsSpatialRegistration';
|
|
39
|
+
import spatialRegistrationMetadataProvider from './spatialRegistrationMetadataProvider';
|
|
40
|
+
import getViewportImageCornersInWorld from './getViewportImageCornersInWorld';
|
|
41
|
+
import hasNaNValues from './hasNaNValues';
|
|
42
|
+
import applyPreset from './applyPreset';
|
|
43
|
+
import deepMerge from './deepMerge';
|
|
44
|
+
import getScalingParameters from './getScalingParameters';
|
|
45
|
+
import getScalarDataType from './getScalarDataType';
|
|
46
|
+
|
|
47
|
+
// name spaces
|
|
48
|
+
import * as planar from './planar';
|
|
49
|
+
import * as windowLevel from './windowLevel';
|
|
50
|
+
|
|
51
|
+
export {
|
|
52
|
+
csUtils as invertRgbTransferFunction,
|
|
53
|
+
createSigmoidRGBTransferFunction,
|
|
54
|
+
getVoiFromSigmoidRGBTransferFunction,
|
|
55
|
+
createLinearRGBTransferFunction,
|
|
56
|
+
scaleRgbTransferFunction,
|
|
57
|
+
triggerEvent,
|
|
58
|
+
imageIdToURI,
|
|
59
|
+
calibratedPixelSpacingMetadataProvider,
|
|
60
|
+
uuidv4,
|
|
61
|
+
planar,
|
|
62
|
+
getMinMax,
|
|
63
|
+
getRuntimeId,
|
|
64
|
+
isEqual,
|
|
65
|
+
isOpposite,
|
|
66
|
+
createFloat32SharedArray,
|
|
67
|
+
createUint8SharedArray,
|
|
68
|
+
createUint16SharedArray,
|
|
69
|
+
createInt16SharedArray,
|
|
70
|
+
windowLevel,
|
|
71
|
+
getClosestImageId,
|
|
72
|
+
getSpacingInNormalDirection,
|
|
73
|
+
getTargetVolumeAndSpacingInNormalDir,
|
|
74
|
+
getVolumeActorCorners,
|
|
75
|
+
indexWithinDimensions,
|
|
76
|
+
getVolumeViewportsContainingSameVolumes,
|
|
77
|
+
getViewportsWithVolumeId,
|
|
78
|
+
transformWorldToIndex,
|
|
79
|
+
loadImageToCanvas,
|
|
80
|
+
renderToCanvas,
|
|
81
|
+
worldToImageCoords,
|
|
82
|
+
imageToWorldCoords,
|
|
83
|
+
getVolumeSliceRangeInfo,
|
|
84
|
+
getVolumeViewportScrollInfo,
|
|
85
|
+
getSliceRange,
|
|
86
|
+
snapFocalPointToSlice,
|
|
87
|
+
getImageSliceDataForVolumeViewport,
|
|
88
|
+
isImageActor,
|
|
89
|
+
actorIsA,
|
|
90
|
+
getViewportsWithImageURI,
|
|
91
|
+
getClosestStackImageIndexForPoint,
|
|
92
|
+
calculateViewportsSpatialRegistration,
|
|
93
|
+
spatialRegistrationMetadataProvider,
|
|
94
|
+
getViewportImageCornersInWorld,
|
|
95
|
+
hasNaNValues,
|
|
96
|
+
applyPreset,
|
|
97
|
+
deepMerge,
|
|
98
|
+
getScalingParameters,
|
|
99
|
+
getScalarDataType,
|
|
100
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Point3 } from '../types';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Returns true if the specified index is within the given dimensions.
|
|
5
|
+
*
|
|
6
|
+
* @param index - The index to check.
|
|
7
|
+
* @param dimensions - The dimensions to check against.
|
|
8
|
+
*
|
|
9
|
+
* @returns True if the index is in-bounds.
|
|
10
|
+
*/
|
|
11
|
+
export default function indexWithinDimensions(
|
|
12
|
+
index: Point3,
|
|
13
|
+
dimensions: Point3
|
|
14
|
+
): boolean {
|
|
15
|
+
if (
|
|
16
|
+
index[0] < 0 ||
|
|
17
|
+
index[0] >= dimensions[0] ||
|
|
18
|
+
index[1] < 0 ||
|
|
19
|
+
index[1] >= dimensions[1] ||
|
|
20
|
+
index[2] < 0 ||
|
|
21
|
+
index[2] >= dimensions[2]
|
|
22
|
+
) {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return true;
|
|
27
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A utility that can be used to invert (in place) an RgbTransferFunction.
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* Grabbing a reference to the RGB Transfer function from the viewport:
|
|
6
|
+
* ```
|
|
7
|
+
* const rgbTransferFunction = viewport
|
|
8
|
+
* .getActor()
|
|
9
|
+
* .getProperty()
|
|
10
|
+
* .getRGBTransferFunction(0);
|
|
11
|
+
*
|
|
12
|
+
* rgbTransferFunction.setRange(0, 5);
|
|
13
|
+
*
|
|
14
|
+
* invertRgbTransferFunction(rgbTransferFunction);
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* @see {@link https://kitware.github.io/vtk-js/api/Rendering_Core_ColorTransferFunction.html|VTK.js: ColorTransferFunction}
|
|
18
|
+
* @param rgbTransferFunction
|
|
19
|
+
*/
|
|
20
|
+
export default function invertRgbTransferFunction(
|
|
21
|
+
rgbTransferFunction: any
|
|
22
|
+
): void {
|
|
23
|
+
const size = rgbTransferFunction.getSize();
|
|
24
|
+
|
|
25
|
+
for (let index = 0; index < size; index++) {
|
|
26
|
+
const nodeValue1 = [];
|
|
27
|
+
|
|
28
|
+
rgbTransferFunction.getNodeValue(index, nodeValue1);
|
|
29
|
+
|
|
30
|
+
nodeValue1[1] = 1 - nodeValue1[1];
|
|
31
|
+
nodeValue1[2] = 1 - nodeValue1[2];
|
|
32
|
+
nodeValue1[3] = 1 - nodeValue1[3];
|
|
33
|
+
|
|
34
|
+
rgbTransferFunction.setNodeValue(index, nodeValue1);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* returns equal if the two arrays are identical within the
|
|
3
|
+
* given tolerance.
|
|
4
|
+
*
|
|
5
|
+
* @param v1 - The first array of values
|
|
6
|
+
* @param v2 - The second array of values.
|
|
7
|
+
* @param tolerance - The acceptable tolerance, the default is 0.00001
|
|
8
|
+
*
|
|
9
|
+
* @returns True if the two values are within the tolerance levels.
|
|
10
|
+
*/
|
|
11
|
+
export default function isEqual(
|
|
12
|
+
v1: number[] | Float32Array,
|
|
13
|
+
v2: number[] | Float32Array,
|
|
14
|
+
tolerance = 1e-5
|
|
15
|
+
): boolean {
|
|
16
|
+
if (v1.length !== v2.length) {
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
for (let i = 0; i < v1.length; i++) {
|
|
21
|
+
if (Math.abs(v1[i] - v2[i]) > tolerance) {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return true;
|
|
27
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type Point3 from '../types/Point3';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* returns equal if the two vec3s are opposite within the
|
|
5
|
+
* given tolerance in each dimension.
|
|
6
|
+
*
|
|
7
|
+
* @param v1 - The first 3 vector
|
|
8
|
+
* @param v2 - The second 3 vector.
|
|
9
|
+
* @param tolerance - The acceptable tolerance.
|
|
10
|
+
*
|
|
11
|
+
* @returns True if the two values are within the tolerance levels.
|
|
12
|
+
*/
|
|
13
|
+
export default function isOpposite(
|
|
14
|
+
v1: Point3,
|
|
15
|
+
v2: Point3,
|
|
16
|
+
tolerance = 1e-5
|
|
17
|
+
): boolean {
|
|
18
|
+
return (
|
|
19
|
+
Math.abs(v1[0] + v2[0]) < tolerance &&
|
|
20
|
+
Math.abs(v1[1] + v2[1]) < tolerance &&
|
|
21
|
+
Math.abs(v1[2] + v2[2]) < tolerance
|
|
22
|
+
);
|
|
23
|
+
}
|