@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,420 @@
|
|
|
1
|
+
import vtkPlane from '@kitware/vtk.js/Common/DataModel/Plane';
|
|
2
|
+
import { vec3 } from 'gl-matrix';
|
|
3
|
+
|
|
4
|
+
import cache from '../cache';
|
|
5
|
+
import { EPSILON, MPR_CAMERA_VALUES, RENDERING_DEFAULTS } from '../constants';
|
|
6
|
+
import { BlendModes, OrientationAxis } from '../enums';
|
|
7
|
+
import type {
|
|
8
|
+
ActorEntry,
|
|
9
|
+
IImageVolume,
|
|
10
|
+
IVolumeInput,
|
|
11
|
+
OrientationVectors,
|
|
12
|
+
Point3,
|
|
13
|
+
} from '../types';
|
|
14
|
+
import type { ViewportInput } from '../types/IViewport';
|
|
15
|
+
import { actorIsA } from '../utilities';
|
|
16
|
+
import transformWorldToIndex from '../utilities/transformWorldToIndex';
|
|
17
|
+
import BaseVolumeViewport from './BaseVolumeViewport';
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* An object representing a VolumeViewport. VolumeViewports are used to render
|
|
21
|
+
* 3D volumes from which various orientations can be viewed. Since VolumeViewports
|
|
22
|
+
* use SharedVolumeMappers behind the scene, memory footprint of visualizations
|
|
23
|
+
* of the same volume in different orientations is very small.
|
|
24
|
+
*
|
|
25
|
+
* For setting volumes on viewports you need to use {@link addVolumesToViewports}
|
|
26
|
+
* which will add volumes to the specified viewports.
|
|
27
|
+
*/
|
|
28
|
+
class VolumeViewport extends BaseVolumeViewport {
|
|
29
|
+
private _useAcquisitionPlaneForViewPlane = false;
|
|
30
|
+
constructor(props: ViewportInput) {
|
|
31
|
+
super(props);
|
|
32
|
+
|
|
33
|
+
const { orientation } = this.options;
|
|
34
|
+
|
|
35
|
+
// if the camera is set to be acquisition axis then we need to skip
|
|
36
|
+
// it for now until the volume is set
|
|
37
|
+
if (orientation && orientation !== OrientationAxis.ACQUISITION) {
|
|
38
|
+
this.applyViewOrientation(orientation);
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
this._useAcquisitionPlaneForViewPlane = true;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Creates volume actors for all volumes defined in the `volumeInputArray`.
|
|
47
|
+
* For each entry, if a `callback` is supplied, it will be called with the new volume actor as input.
|
|
48
|
+
* For each entry, if a `blendMode` and/or `slabThickness` is defined, this will be set on the actor's
|
|
49
|
+
* `VolumeMapper`.
|
|
50
|
+
*
|
|
51
|
+
* @param volumeInputArray - The array of `VolumeInput`s which define the volumes to add.
|
|
52
|
+
* @param immediate - Whether the `Viewport` should be rendered as soon as volumes are added.
|
|
53
|
+
*/
|
|
54
|
+
public async setVolumes(
|
|
55
|
+
volumeInputArray: Array<IVolumeInput>,
|
|
56
|
+
immediate = false,
|
|
57
|
+
suppressEvents = false
|
|
58
|
+
): Promise<void> {
|
|
59
|
+
const firstImageVolume = cache.getVolume(volumeInputArray[0].volumeId);
|
|
60
|
+
|
|
61
|
+
if (!firstImageVolume) {
|
|
62
|
+
throw new Error(
|
|
63
|
+
`imageVolume with id: ${firstImageVolume.volumeId} does not exist`
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (this._useAcquisitionPlaneForViewPlane) {
|
|
68
|
+
this._setViewPlaneToAcquisitionPlane(firstImageVolume);
|
|
69
|
+
this._useAcquisitionPlaneForViewPlane = false;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return super.setVolumes(volumeInputArray, immediate, suppressEvents);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Creates and adds volume actors for all volumes defined in the `volumeInputArray`.
|
|
77
|
+
* For each entry, if a `callback` is supplied, it will be called with the new volume actor as input.
|
|
78
|
+
*
|
|
79
|
+
* @param volumeInputArray - The array of `VolumeInput`s which define the volumes to add.
|
|
80
|
+
* @param immediate - Whether the `Viewport` should be rendered as soon as volumes are added.
|
|
81
|
+
*/
|
|
82
|
+
public async addVolumes(
|
|
83
|
+
volumeInputArray: Array<IVolumeInput>,
|
|
84
|
+
immediate = false,
|
|
85
|
+
suppressEvents = false
|
|
86
|
+
): Promise<void> {
|
|
87
|
+
const firstImageVolume = cache.getVolume(volumeInputArray[0].volumeId);
|
|
88
|
+
|
|
89
|
+
if (!firstImageVolume) {
|
|
90
|
+
throw new Error(
|
|
91
|
+
`imageVolume with id: ${firstImageVolume.volumeId} does not exist`
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
if (this._useAcquisitionPlaneForViewPlane) {
|
|
96
|
+
this._setViewPlaneToAcquisitionPlane(firstImageVolume);
|
|
97
|
+
this._useAcquisitionPlaneForViewPlane = false;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
return super.addVolumes(volumeInputArray, immediate, suppressEvents);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* It sets the orientation for the camera, the orientation can be one of the
|
|
105
|
+
* following: axial, sagittal, coronal, default. Use the Enums.OrientationAxis
|
|
106
|
+
* to set the orientation. The "default" orientation is the orientation that
|
|
107
|
+
* the volume was acquired in (scan axis)
|
|
108
|
+
*
|
|
109
|
+
* @param orientation - The orientation to set the camera to.
|
|
110
|
+
* @param immediate - Whether the `Viewport` should be rendered as soon as the camera is set.
|
|
111
|
+
*/
|
|
112
|
+
public setOrientation(orientation: OrientationAxis, immediate = true): void {
|
|
113
|
+
let viewPlaneNormal, viewUp;
|
|
114
|
+
|
|
115
|
+
if (MPR_CAMERA_VALUES[orientation]) {
|
|
116
|
+
({ viewPlaneNormal, viewUp } = MPR_CAMERA_VALUES[orientation]);
|
|
117
|
+
} else if (orientation === 'acquisition') {
|
|
118
|
+
({ viewPlaneNormal, viewUp } = this._getAcquisitionPlaneOrientation());
|
|
119
|
+
} else {
|
|
120
|
+
throw new Error(
|
|
121
|
+
`Invalid orientation: ${orientation}. Use Enums.OrientationAxis instead.`
|
|
122
|
+
);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
this.setCamera({
|
|
126
|
+
viewPlaneNormal,
|
|
127
|
+
viewUp,
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
this.resetCamera();
|
|
131
|
+
|
|
132
|
+
if (immediate) {
|
|
133
|
+
this.render();
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
private _getAcquisitionPlaneOrientation(): OrientationVectors {
|
|
138
|
+
const actorEntry = this.getDefaultActor();
|
|
139
|
+
|
|
140
|
+
if (!actorEntry) {
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// Todo: fix this after we add the volumeId reference to actorEntry later
|
|
145
|
+
// in the segmentation refactor
|
|
146
|
+
const volumeId = actorEntry.uid;
|
|
147
|
+
|
|
148
|
+
const imageVolume = cache.getVolume(volumeId);
|
|
149
|
+
|
|
150
|
+
if (!imageVolume) {
|
|
151
|
+
throw new Error(
|
|
152
|
+
`imageVolume with id: ${volumeId} does not exist in cache`
|
|
153
|
+
);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
const { direction } = imageVolume;
|
|
157
|
+
const viewPlaneNormal = direction.slice(6, 9).map((x) => -x) as Point3;
|
|
158
|
+
const viewUp = (direction.slice(3, 6) as Point3).map((x) => -x) as Point3;
|
|
159
|
+
|
|
160
|
+
return {
|
|
161
|
+
viewPlaneNormal,
|
|
162
|
+
viewUp,
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
private _setViewPlaneToAcquisitionPlane(imageVolume: IImageVolume): void {
|
|
167
|
+
let viewPlaneNormal, viewUp;
|
|
168
|
+
|
|
169
|
+
if (imageVolume) {
|
|
170
|
+
const { direction } = imageVolume;
|
|
171
|
+
viewPlaneNormal = direction.slice(6, 9).map((x) => -x) as Point3;
|
|
172
|
+
viewUp = (direction.slice(3, 6) as Point3).map((x) => -x) as Point3;
|
|
173
|
+
} else {
|
|
174
|
+
({ viewPlaneNormal, viewUp } = this._getAcquisitionPlaneOrientation());
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
this.setCamera({
|
|
178
|
+
viewPlaneNormal,
|
|
179
|
+
viewUp,
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
this.resetCamera();
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Given a point in world coordinates, return the intensity at that point
|
|
187
|
+
* @param point - The point in world coordinates to get the intensity
|
|
188
|
+
* from.
|
|
189
|
+
* @returns The intensity value of the voxel at the given point.
|
|
190
|
+
*/
|
|
191
|
+
public getIntensityFromWorld(point: Point3): number {
|
|
192
|
+
const actorEntry = this.getDefaultActor();
|
|
193
|
+
if (!actorIsA(actorEntry, 'vtkVolume')) {
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
const { actor, uid } = actorEntry;
|
|
198
|
+
const imageData = actor.getMapper().getInputData();
|
|
199
|
+
|
|
200
|
+
const volume = cache.getVolume(uid);
|
|
201
|
+
const { dimensions } = volume;
|
|
202
|
+
|
|
203
|
+
const index = transformWorldToIndex(imageData, point);
|
|
204
|
+
|
|
205
|
+
const voxelIndex =
|
|
206
|
+
index[2] * dimensions[0] * dimensions[1] +
|
|
207
|
+
index[1] * dimensions[0] +
|
|
208
|
+
index[0];
|
|
209
|
+
|
|
210
|
+
return volume.getScalarData()[voxelIndex];
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
public setBlendMode(
|
|
214
|
+
blendMode: BlendModes,
|
|
215
|
+
filterActorUIDs = [],
|
|
216
|
+
immediate = false
|
|
217
|
+
): void {
|
|
218
|
+
let actorEntries = this.getActors();
|
|
219
|
+
|
|
220
|
+
if (filterActorUIDs && filterActorUIDs.length > 0) {
|
|
221
|
+
actorEntries = actorEntries.filter((actorEntry: ActorEntry) => {
|
|
222
|
+
return filterActorUIDs.includes(actorEntry.uid);
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
actorEntries.forEach((actorEntry) => {
|
|
227
|
+
const { actor } = actorEntry;
|
|
228
|
+
|
|
229
|
+
const mapper = actor.getMapper();
|
|
230
|
+
// @ts-ignore vtk incorrect typing
|
|
231
|
+
mapper.setBlendMode(blendMode);
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
if (immediate) {
|
|
235
|
+
this.render();
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* Reset the camera for the volume viewport
|
|
241
|
+
*/
|
|
242
|
+
public resetCamera(
|
|
243
|
+
resetPan = true,
|
|
244
|
+
resetZoom = true,
|
|
245
|
+
resetToCenter = true
|
|
246
|
+
): boolean {
|
|
247
|
+
super.resetCamera(resetPan, resetZoom, resetToCenter);
|
|
248
|
+
|
|
249
|
+
this.resetVolumeViewportClippingRange();
|
|
250
|
+
|
|
251
|
+
const activeCamera = this.getVtkActiveCamera();
|
|
252
|
+
const viewPlaneNormal = <Point3>activeCamera.getViewPlaneNormal();
|
|
253
|
+
const focalPoint = <Point3>activeCamera.getFocalPoint();
|
|
254
|
+
|
|
255
|
+
// always add clipping planes for the volume viewport. If a use case
|
|
256
|
+
// arises where we don't want clipping planes, you should use the volume_3d
|
|
257
|
+
// viewport instead.
|
|
258
|
+
const actorEntries = this.getActors();
|
|
259
|
+
actorEntries.forEach((actorEntry) => {
|
|
260
|
+
if (!actorEntry.actor) {
|
|
261
|
+
return;
|
|
262
|
+
}
|
|
263
|
+
const mapper = actorEntry.actor.getMapper();
|
|
264
|
+
const vtkPlanes = mapper.getClippingPlanes();
|
|
265
|
+
|
|
266
|
+
if (vtkPlanes.length === 0) {
|
|
267
|
+
const clipPlane1 = vtkPlane.newInstance();
|
|
268
|
+
const clipPlane2 = vtkPlane.newInstance();
|
|
269
|
+
const newVtkPlanes = [clipPlane1, clipPlane2];
|
|
270
|
+
|
|
271
|
+
let slabThickness = RENDERING_DEFAULTS.MINIMUM_SLAB_THICKNESS;
|
|
272
|
+
if (actorEntry.slabThickness) {
|
|
273
|
+
slabThickness = actorEntry.slabThickness;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
this.setOrientationOfClippingPlanes(
|
|
277
|
+
newVtkPlanes,
|
|
278
|
+
slabThickness,
|
|
279
|
+
viewPlaneNormal,
|
|
280
|
+
focalPoint
|
|
281
|
+
);
|
|
282
|
+
|
|
283
|
+
mapper.addClippingPlane(clipPlane1);
|
|
284
|
+
mapper.addClippingPlane(clipPlane2);
|
|
285
|
+
}
|
|
286
|
+
});
|
|
287
|
+
|
|
288
|
+
return true;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
/**
|
|
292
|
+
* It sets the slabThickness of the actors of the viewport. If filterActorUIDs are
|
|
293
|
+
* provided, only the actors with the given UIDs will be affected. If no
|
|
294
|
+
* filterActorUIDs are provided, all actors will be affected.
|
|
295
|
+
*
|
|
296
|
+
* @param slabThickness - The slab thickness to set.
|
|
297
|
+
* @param blendMode - The blend mode to use when rendering the actors.
|
|
298
|
+
* @param filterActorUIDs - Optional argument to filter the actors to apply
|
|
299
|
+
* the slab thickness to (if not provided, all actors will be affected).
|
|
300
|
+
*/
|
|
301
|
+
public setSlabThickness(slabThickness: number, filterActorUIDs = []): void {
|
|
302
|
+
let actorEntries = this.getActors();
|
|
303
|
+
|
|
304
|
+
if (filterActorUIDs && filterActorUIDs.length > 0) {
|
|
305
|
+
actorEntries = actorEntries.filter((actorEntry) => {
|
|
306
|
+
return filterActorUIDs.includes(actorEntry.uid);
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
actorEntries.forEach((actorEntry) => {
|
|
311
|
+
if (actorIsA(actorEntry, 'vtkVolume')) {
|
|
312
|
+
actorEntry.slabThickness = slabThickness;
|
|
313
|
+
}
|
|
314
|
+
});
|
|
315
|
+
|
|
316
|
+
const currentCamera = this.getCamera();
|
|
317
|
+
this.updateClippingPlanesForActors(currentCamera);
|
|
318
|
+
this.triggerCameraModifiedEventIfNecessary(currentCamera, currentCamera);
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
/**
|
|
322
|
+
* Gets the largest slab thickness from all actors in the viewport.
|
|
323
|
+
*
|
|
324
|
+
* @returns slabThickness - The slab thickness.
|
|
325
|
+
*/
|
|
326
|
+
public getSlabThickness(): number {
|
|
327
|
+
const actors = this.getActors();
|
|
328
|
+
let slabThickness = RENDERING_DEFAULTS.MINIMUM_SLAB_THICKNESS;
|
|
329
|
+
actors.forEach((actor) => {
|
|
330
|
+
if (actor.slabThickness > slabThickness) {
|
|
331
|
+
slabThickness = actor.slabThickness;
|
|
332
|
+
}
|
|
333
|
+
});
|
|
334
|
+
|
|
335
|
+
return slabThickness;
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
/**
|
|
339
|
+
* Uses viewport camera and volume actor to decide if the viewport
|
|
340
|
+
* is looking at the volume in the direction of acquisition (imageIds).
|
|
341
|
+
* If so, it uses the origin and focalPoint to calculate the slice index.
|
|
342
|
+
* Todo: This only works if the imageIds are properly sorted
|
|
343
|
+
*
|
|
344
|
+
* @returns The slice index
|
|
345
|
+
*/
|
|
346
|
+
public getCurrentImageIdIndex = (): number | undefined => {
|
|
347
|
+
return this._getImageIdIndex();
|
|
348
|
+
};
|
|
349
|
+
|
|
350
|
+
/**
|
|
351
|
+
* Uses viewport camera and volume actor to decide if the viewport
|
|
352
|
+
* is looking at the volume in the direction of acquisition (imageIds).
|
|
353
|
+
* If so, it uses the origin and focalPoint to find which imageId is
|
|
354
|
+
* currently being viewed.
|
|
355
|
+
*
|
|
356
|
+
* @returns ImageId
|
|
357
|
+
*/
|
|
358
|
+
public getCurrentImageId = (): string | undefined => {
|
|
359
|
+
const index = this._getImageIdIndex();
|
|
360
|
+
|
|
361
|
+
if (isNaN(index)) {
|
|
362
|
+
return;
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
const actorEntry = this.getDefaultActor();
|
|
366
|
+
if (!actorIsA(actorEntry, 'vtkVolume')) {
|
|
367
|
+
return;
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
const { uid } = actorEntry;
|
|
371
|
+
const volume = cache.getVolume(uid);
|
|
372
|
+
|
|
373
|
+
if (!volume) {
|
|
374
|
+
return;
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
const imageIds = volume.imageIds;
|
|
378
|
+
|
|
379
|
+
return imageIds[index];
|
|
380
|
+
};
|
|
381
|
+
|
|
382
|
+
private _getImageIdIndex = () => {
|
|
383
|
+
const { viewPlaneNormal, focalPoint } = this.getCamera();
|
|
384
|
+
|
|
385
|
+
// Todo: handle scenario of fusion of multiple volumes
|
|
386
|
+
// we cannot only check number of actors, because we might have
|
|
387
|
+
// segmentations ...
|
|
388
|
+
const { direction, origin, spacing } = this.getImageData();
|
|
389
|
+
|
|
390
|
+
// get the last 3 components of the direction - axis normal
|
|
391
|
+
const dir = direction.slice(direction.length - 3);
|
|
392
|
+
|
|
393
|
+
const dot = Math.abs(
|
|
394
|
+
dir[0] * viewPlaneNormal[0] +
|
|
395
|
+
dir[1] * viewPlaneNormal[1] +
|
|
396
|
+
dir[2] * viewPlaneNormal[2]
|
|
397
|
+
);
|
|
398
|
+
|
|
399
|
+
// if dot is not 1 or -1 return null since it means
|
|
400
|
+
// viewport is not looking at the image acquisition plane
|
|
401
|
+
if (dot - 1 > EPSILON) {
|
|
402
|
+
return;
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
// how many steps are from the origin to the focal point in the
|
|
406
|
+
// normal direction
|
|
407
|
+
const spacingInNormal = spacing[2];
|
|
408
|
+
const sub = vec3.create();
|
|
409
|
+
vec3.sub(sub, focalPoint, origin);
|
|
410
|
+
const distance = vec3.dot(sub, viewPlaneNormal);
|
|
411
|
+
|
|
412
|
+
// divide by the spacing in the normal direction to get the
|
|
413
|
+
// number of steps, and subtract 1 to get the index
|
|
414
|
+
return Math.round(Math.abs(distance) / spacingInNormal);
|
|
415
|
+
};
|
|
416
|
+
|
|
417
|
+
getRotation = (): number => 0;
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
export default VolumeViewport;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { OrientationAxis } from '../enums';
|
|
2
|
+
import type { ViewportInput } from '../types/IViewport';
|
|
3
|
+
import BaseVolumeViewport from './BaseVolumeViewport';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* An object representing a 3-dimensional volume viewport. VolumeViewport3Ds are used to render
|
|
7
|
+
* 3D volumes in their entirety, and not just load a single slice at a time.
|
|
8
|
+
*
|
|
9
|
+
* For setting volumes on viewports you need to use {@link addVolumesToViewports}
|
|
10
|
+
* which will add volumes to the specified viewports.
|
|
11
|
+
*/
|
|
12
|
+
class VolumeViewport3D extends BaseVolumeViewport {
|
|
13
|
+
constructor(props: ViewportInput) {
|
|
14
|
+
super(props);
|
|
15
|
+
|
|
16
|
+
const { parallelProjection, orientation } = this.options;
|
|
17
|
+
|
|
18
|
+
const activeCamera = this.getVtkActiveCamera();
|
|
19
|
+
|
|
20
|
+
if (parallelProjection != null) {
|
|
21
|
+
activeCamera.setParallelProjection(parallelProjection);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (orientation && orientation !== OrientationAxis.ACQUISITION) {
|
|
25
|
+
this.applyViewOrientation(orientation);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
public resetCamera(
|
|
30
|
+
resetPan = true,
|
|
31
|
+
resetZoom = true,
|
|
32
|
+
resetToCenter = true
|
|
33
|
+
): boolean {
|
|
34
|
+
super.resetCamera(resetPan, resetZoom, resetToCenter);
|
|
35
|
+
this.resetVolumeViewportClippingRange();
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
getRotation = (): number => 0;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export default VolumeViewport3D;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import renderingEngineCache from './renderingEngineCache';
|
|
2
|
+
import type { IRenderingEngine } from '../types';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Method to retrieve a RenderingEngine by its unique identifier.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* How to get a RenderingEngine that was created earlier:
|
|
9
|
+
* ```javascript
|
|
10
|
+
* import { RenderingEngine, getRenderingEngine } from 'vtkjs-viewport';
|
|
11
|
+
*
|
|
12
|
+
* const renderingEngine = new RenderingEngine('my-engine');
|
|
13
|
+
*
|
|
14
|
+
* // getting reference to rendering engine later...
|
|
15
|
+
* const renderingEngine = getRenderingEngine('my-engine');
|
|
16
|
+
* ```
|
|
17
|
+
*
|
|
18
|
+
* @param id - The identifier that was used to create the RenderingEngine
|
|
19
|
+
* @returns the matching RenderingEngine, or `undefined` if there is no match
|
|
20
|
+
* @public
|
|
21
|
+
*/
|
|
22
|
+
export function getRenderingEngine(id: string): IRenderingEngine | undefined {
|
|
23
|
+
return renderingEngineCache.get(id);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Get all the rendering engines that are currently registered
|
|
28
|
+
* @returns An array of rendering engines.
|
|
29
|
+
*/
|
|
30
|
+
export function getRenderingEngines(): IRenderingEngine[] | undefined {
|
|
31
|
+
return renderingEngineCache.getAll();
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export default getRenderingEngine;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { VolumeViewport } from '../';
|
|
2
|
+
import BaseVolumeViewport from '../BaseVolumeViewport';
|
|
3
|
+
import type { IVolumeInput, IRenderingEngine } from '../../types';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* For each provided viewport it adds a volume to the viewport using the
|
|
7
|
+
* provided renderingEngine
|
|
8
|
+
*
|
|
9
|
+
*
|
|
10
|
+
* @param renderingEngine - The rendering engine to use to get viewports from
|
|
11
|
+
* @param volumeInputs - Array of volume inputs including volumeId. Other properties
|
|
12
|
+
* such as visibility, callback, blendMode, slabThickness are optional
|
|
13
|
+
* @param viewportIds - Array of viewport IDs to add the volume to
|
|
14
|
+
* @param immediateRender - If true, the volumes will be rendered immediately
|
|
15
|
+
* @returns A promise that resolves when all volumes have been added
|
|
16
|
+
*/
|
|
17
|
+
async function addVolumesToViewports(
|
|
18
|
+
renderingEngine: IRenderingEngine,
|
|
19
|
+
volumeInputs: Array<IVolumeInput>,
|
|
20
|
+
viewportIds: Array<string>,
|
|
21
|
+
immediateRender = false,
|
|
22
|
+
suppressEvents = false
|
|
23
|
+
): Promise<void> {
|
|
24
|
+
// Check if all viewports are volumeViewports
|
|
25
|
+
for (const viewportId of viewportIds) {
|
|
26
|
+
const viewport = renderingEngine.getViewport(viewportId);
|
|
27
|
+
|
|
28
|
+
if (!viewport) {
|
|
29
|
+
throw new Error(`Viewport with Id ${viewportId} does not exist`);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// if not instance of BaseVolumeViewport, throw
|
|
33
|
+
if (!(viewport instanceof BaseVolumeViewport)) {
|
|
34
|
+
console.warn(
|
|
35
|
+
`Viewport with Id ${viewportId} is not a BaseVolumeViewport. Cannot add volume to this viewport.`
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const addVolumePromises = viewportIds.map(async (viewportId) => {
|
|
43
|
+
const viewport = renderingEngine.getViewport(viewportId) as VolumeViewport;
|
|
44
|
+
|
|
45
|
+
await viewport.addVolumes(volumeInputs, immediateRender, suppressEvents);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
await Promise.all(addVolumePromises);
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export default addVolumesToViewports;
|