@cornerstonejs/core 1.21.2 → 1.22.0
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/RenderingEngine/BaseVolumeViewport.d.ts +10 -4
- package/dist/cjs/RenderingEngine/BaseVolumeViewport.js +112 -16
- package/dist/cjs/RenderingEngine/BaseVolumeViewport.js.map +1 -1
- package/dist/cjs/RenderingEngine/StackViewport.d.ts +12 -3
- package/dist/cjs/RenderingEngine/StackViewport.js +113 -7
- package/dist/cjs/RenderingEngine/StackViewport.js.map +1 -1
- package/dist/cjs/RenderingEngine/VolumeViewport.js +9 -0
- package/dist/cjs/RenderingEngine/VolumeViewport.js.map +1 -1
- package/dist/cjs/types/IStackViewport.d.ts +5 -4
- package/dist/cjs/types/IVolumeViewport.d.ts +5 -2
- package/dist/cjs/types/ViewportProperties.d.ts +2 -0
- package/dist/cjs/types/VolumeViewportProperties.d.ts +1 -2
- package/dist/cjs/utilities/index.d.ts +2 -1
- package/dist/cjs/utilities/index.js +3 -1
- package/dist/cjs/utilities/index.js.map +1 -1
- package/dist/cjs/utilities/transferFunctionUtils.d.ts +3 -0
- package/dist/cjs/utilities/transferFunctionUtils.js +22 -0
- package/dist/cjs/utilities/transferFunctionUtils.js.map +1 -0
- package/dist/esm/RenderingEngine/BaseVolumeViewport.d.ts +10 -4
- package/dist/esm/RenderingEngine/BaseVolumeViewport.js +112 -16
- package/dist/esm/RenderingEngine/BaseVolumeViewport.js.map +1 -1
- package/dist/esm/RenderingEngine/StackViewport.d.ts +12 -3
- package/dist/esm/RenderingEngine/StackViewport.js +116 -8
- package/dist/esm/RenderingEngine/StackViewport.js.map +1 -1
- package/dist/esm/RenderingEngine/VolumeViewport.js +10 -1
- package/dist/esm/RenderingEngine/VolumeViewport.js.map +1 -1
- package/dist/esm/types/IStackViewport.d.ts +5 -4
- package/dist/esm/types/IVolumeViewport.d.ts +5 -2
- package/dist/esm/types/ViewportProperties.d.ts +2 -0
- package/dist/esm/types/VolumeViewportProperties.d.ts +1 -2
- package/dist/esm/utilities/index.d.ts +2 -1
- package/dist/esm/utilities/index.js +2 -1
- package/dist/esm/utilities/index.js.map +1 -1
- package/dist/esm/utilities/transferFunctionUtils.d.ts +3 -0
- package/dist/esm/utilities/transferFunctionUtils.js +18 -0
- package/dist/esm/utilities/transferFunctionUtils.js.map +1 -0
- package/dist/umd/index.js +1 -1
- package/dist/umd/index.js.map +1 -1
- package/package.json +2 -2
- package/src/RenderingEngine/BaseVolumeViewport.ts +182 -19
- package/src/RenderingEngine/StackViewport.ts +204 -22
- package/src/RenderingEngine/VolumeViewport.ts +22 -1
- package/src/types/IStackViewport.ts +31 -8
- package/src/types/IVolumeViewport.ts +27 -5
- package/src/types/ViewportProperties.ts +3 -0
- package/src/types/VolumeViewportProperties.ts +2 -3
- package/src/utilities/index.ts +2 -0
- package/src/utilities/transferFunctionUtils.ts +23 -0
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import vtkDataArray from '@kitware/vtk.js/Common/Core/DataArray';
|
|
2
2
|
import vtkImageData from '@kitware/vtk.js/Common/DataModel/ImageData';
|
|
3
3
|
import type { vtkImageData as vtkImageDataType } from '@kitware/vtk.js/Common/DataModel/ImageData';
|
|
4
|
+
import vtkColorMaps from '@kitware/vtk.js/Rendering/Core/ColorTransferFunction/ColorMaps';
|
|
4
5
|
import _cloneDeep from 'lodash.clonedeep';
|
|
5
6
|
import vtkCamera from '@kitware/vtk.js/Rendering/Core/Camera';
|
|
6
7
|
import { vec2, vec3, mat4 } from 'gl-matrix';
|
|
@@ -19,6 +20,7 @@ import {
|
|
|
19
20
|
imageIdToURI,
|
|
20
21
|
isImageActor,
|
|
21
22
|
actorIsA,
|
|
23
|
+
colormap as colormapUtils,
|
|
22
24
|
} from '../utilities';
|
|
23
25
|
import {
|
|
24
26
|
Point2,
|
|
@@ -39,7 +41,7 @@ import {
|
|
|
39
41
|
IStackViewport,
|
|
40
42
|
VolumeActor,
|
|
41
43
|
Mat3,
|
|
42
|
-
|
|
44
|
+
ColormapPublic,
|
|
43
45
|
IImageCalibration,
|
|
44
46
|
} from '../types';
|
|
45
47
|
import { ViewportInput } from '../types/IViewport';
|
|
@@ -52,7 +54,6 @@ import {
|
|
|
52
54
|
InterpolationType,
|
|
53
55
|
RequestType,
|
|
54
56
|
Events,
|
|
55
|
-
CalibrationTypes,
|
|
56
57
|
VOILUTFunctionType,
|
|
57
58
|
} from '../enums';
|
|
58
59
|
import canvasToPixel from './helpers/cpuFallback/rendering/canvasToPixel';
|
|
@@ -79,6 +80,10 @@ import {
|
|
|
79
80
|
ImagePlaneModule,
|
|
80
81
|
} from '../types';
|
|
81
82
|
import ViewportStatus from '../enums/ViewportStatus';
|
|
83
|
+
import {
|
|
84
|
+
getTransferFunctionNodes,
|
|
85
|
+
setTransferFunctionNodes,
|
|
86
|
+
} from '../utilities/transferFunctionUtils';
|
|
82
87
|
|
|
83
88
|
const EPSILON = 1; // Slice Thickness
|
|
84
89
|
|
|
@@ -125,6 +130,13 @@ class StackViewport extends Viewport implements IStackViewport {
|
|
|
125
130
|
private debouncedTimeout: number;
|
|
126
131
|
|
|
127
132
|
// Viewport Properties
|
|
133
|
+
private globalDefaultProperties: StackViewportProperties;
|
|
134
|
+
private perImageIdDefaultProperties = new Map<
|
|
135
|
+
string,
|
|
136
|
+
StackViewportProperties
|
|
137
|
+
>();
|
|
138
|
+
|
|
139
|
+
private colormap: ColormapPublic | CPUFallbackColormapData;
|
|
128
140
|
private voiRange: VOIRange;
|
|
129
141
|
private voiUpdatedWithSetProperties = false;
|
|
130
142
|
private VOILUTFunction: VOILUTFunctionType;
|
|
@@ -132,6 +144,7 @@ class StackViewport extends Viewport implements IStackViewport {
|
|
|
132
144
|
private invert = false;
|
|
133
145
|
// The initial invert of the image loaded as opposed to the invert status of the viewport itself (see above).
|
|
134
146
|
private initialInvert = false;
|
|
147
|
+
private initialTransferFunctionNodes = null;
|
|
135
148
|
private interpolationType: InterpolationType;
|
|
136
149
|
|
|
137
150
|
// Helpers
|
|
@@ -250,14 +263,6 @@ class StackViewport extends Viewport implements IStackViewport {
|
|
|
250
263
|
*/
|
|
251
264
|
public getImageData: () => IImageData | CPUIImageData;
|
|
252
265
|
|
|
253
|
-
/**
|
|
254
|
-
* Sets the colormap for the current viewport.
|
|
255
|
-
* @param colormap - The colormap data to use.
|
|
256
|
-
*/
|
|
257
|
-
public setColormap: (
|
|
258
|
-
colormap: CPUFallbackColormapData | ColormapRegistration
|
|
259
|
-
) => void;
|
|
260
|
-
|
|
261
266
|
/**
|
|
262
267
|
* If the user has selected CPU rendering, return the CPU camera, otherwise
|
|
263
268
|
* return the default camera
|
|
@@ -365,6 +370,14 @@ class StackViewport extends Viewport implements IStackViewport {
|
|
|
365
370
|
|
|
366
371
|
private setInvertColor: (invert: boolean) => void;
|
|
367
372
|
|
|
373
|
+
/**
|
|
374
|
+
* Sets the colormap for the current viewport.
|
|
375
|
+
* @param colormap - The colormap data to use.
|
|
376
|
+
*/
|
|
377
|
+
private setColormap: (
|
|
378
|
+
colormap: CPUFallbackColormapData | ColormapPublic
|
|
379
|
+
) => void;
|
|
380
|
+
|
|
368
381
|
private initializeElementDisabledHandler() {
|
|
369
382
|
eventTarget.addEventListener(
|
|
370
383
|
Events.ELEMENT_DISABLED,
|
|
@@ -623,15 +636,60 @@ class StackViewport extends Viewport implements IStackViewport {
|
|
|
623
636
|
}
|
|
624
637
|
|
|
625
638
|
/**
|
|
626
|
-
*
|
|
627
|
-
*
|
|
628
|
-
* @param
|
|
629
|
-
*
|
|
630
|
-
|
|
631
|
-
|
|
639
|
+
* Update the default properties of the viewport and add properties by imageId if specified
|
|
640
|
+
* @param ViewportProperties - The properties to set
|
|
641
|
+
* @param imageId If given, we set the default properties only for this image index, if not
|
|
642
|
+
* the default properties will be set for all imageIds
|
|
643
|
+
*/
|
|
644
|
+
public setDefaultProperties(
|
|
645
|
+
ViewportProperties: StackViewportProperties,
|
|
646
|
+
imageId?: string
|
|
647
|
+
): void {
|
|
648
|
+
if (imageId == null) {
|
|
649
|
+
this.globalDefaultProperties = ViewportProperties;
|
|
650
|
+
} else {
|
|
651
|
+
this.perImageIdDefaultProperties.set(imageId, ViewportProperties);
|
|
652
|
+
|
|
653
|
+
//If the viewport is the same imageIdI, we need to update the viewport
|
|
654
|
+
if (this.getCurrentImageId() === imageId) {
|
|
655
|
+
this.setProperties(ViewportProperties);
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
/**
|
|
661
|
+
* Remove the global default properties of the viewport or remove default properties for an imageId if specified
|
|
662
|
+
* @param imageId If given, we remove the default properties only for this imageID, if not
|
|
663
|
+
* the global default properties will be removed
|
|
664
|
+
*/
|
|
665
|
+
public clearDefaultProperties(imageId?: string): void {
|
|
666
|
+
if (imageId == null) {
|
|
667
|
+
this.globalDefaultProperties = {};
|
|
668
|
+
this.resetProperties();
|
|
669
|
+
} else {
|
|
670
|
+
this.perImageIdDefaultProperties.delete(imageId);
|
|
671
|
+
this.resetToDefaultProperties();
|
|
672
|
+
}
|
|
673
|
+
}
|
|
674
|
+
|
|
675
|
+
/**
|
|
676
|
+
Configures the properties of the viewport.
|
|
677
|
+
This method allows customization of the viewport by setting attributes like
|
|
678
|
+
VOI (Value of Interest), color inversion, interpolation type, and image rotation.
|
|
679
|
+
If setProperties is called for the first time, the provided properties will
|
|
680
|
+
become the default settings for all images in the stack in case the resetPropertiese need to be called
|
|
681
|
+
@param properties - An object containing the properties to be set.
|
|
682
|
+
@param properties.colormap - Specifies the colormap for the viewport.
|
|
683
|
+
@param properties.voiRange - Defines the lower and upper Value of Interest (VOI) to be applied.
|
|
684
|
+
@param properties.VOILUTFunction - Function to handle the application of a lookup table (LUT) to the VOI.
|
|
685
|
+
@param properties.invert - A boolean value to toggle color inversion (true: inverted, false: not inverted).
|
|
686
|
+
@param properties.interpolationType - Determines the interpolation method to be used (1: linear, 0: nearest-neighbor).
|
|
687
|
+
@param properties.rotation - Specifies the image rotation angle in degrees.
|
|
688
|
+
@param suppressEvents - A boolean value to control event suppression. If true, the related events will not be triggered. Default is false.
|
|
632
689
|
*/
|
|
633
690
|
public setProperties(
|
|
634
691
|
{
|
|
692
|
+
colormap,
|
|
635
693
|
voiRange,
|
|
636
694
|
VOILUTFunction,
|
|
637
695
|
invert,
|
|
@@ -643,6 +701,21 @@ class StackViewport extends Viewport implements IStackViewport {
|
|
|
643
701
|
this.viewportStatus = this.csImage
|
|
644
702
|
? ViewportStatus.PRE_RENDER
|
|
645
703
|
: ViewportStatus.LOADING;
|
|
704
|
+
|
|
705
|
+
if (this.globalDefaultProperties == null) {
|
|
706
|
+
this.setDefaultProperties({
|
|
707
|
+
colormap,
|
|
708
|
+
voiRange,
|
|
709
|
+
VOILUTFunction,
|
|
710
|
+
invert,
|
|
711
|
+
interpolationType,
|
|
712
|
+
rotation,
|
|
713
|
+
});
|
|
714
|
+
}
|
|
715
|
+
|
|
716
|
+
if (typeof colormap !== 'undefined') {
|
|
717
|
+
this.setColormap(colormap);
|
|
718
|
+
}
|
|
646
719
|
// if voi is not applied for the first time, run the setVOI function
|
|
647
720
|
// which will apply the default voi based on the range
|
|
648
721
|
if (typeof voiRange !== 'undefined') {
|
|
@@ -670,12 +743,35 @@ class StackViewport extends Viewport implements IStackViewport {
|
|
|
670
743
|
}
|
|
671
744
|
}
|
|
672
745
|
|
|
746
|
+
/**
|
|
747
|
+
* Retrieve the viewport default properties
|
|
748
|
+
* @param imageId If given, we retrieve the default properties of an image index if it exists
|
|
749
|
+
* If not given,we return the global properties of the viewport
|
|
750
|
+
* @returns viewport properties including voi, invert, interpolation type, rotation, flip
|
|
751
|
+
*/
|
|
752
|
+
public getDefaultProperties = (imageId?: string): StackViewportProperties => {
|
|
753
|
+
let imageProperties;
|
|
754
|
+
if (imageId !== undefined) {
|
|
755
|
+
imageProperties = this.perImageIdDefaultProperties.get(imageId);
|
|
756
|
+
}
|
|
757
|
+
|
|
758
|
+
if (imageProperties !== undefined) {
|
|
759
|
+
return imageProperties;
|
|
760
|
+
}
|
|
761
|
+
|
|
762
|
+
return {
|
|
763
|
+
...this.globalDefaultProperties,
|
|
764
|
+
rotation: this.getRotation(),
|
|
765
|
+
};
|
|
766
|
+
};
|
|
767
|
+
|
|
673
768
|
/**
|
|
674
769
|
* Retrieve the viewport properties
|
|
675
770
|
* @returns viewport properties including voi, invert, interpolation type, rotation, flip
|
|
676
771
|
*/
|
|
677
772
|
public getProperties = (): StackViewportProperties => {
|
|
678
773
|
const {
|
|
774
|
+
colormap,
|
|
679
775
|
voiRange,
|
|
680
776
|
VOILUTFunction,
|
|
681
777
|
interpolationType,
|
|
@@ -685,6 +781,7 @@ class StackViewport extends Viewport implements IStackViewport {
|
|
|
685
781
|
const rotation = this.getRotation();
|
|
686
782
|
|
|
687
783
|
return {
|
|
784
|
+
colormap,
|
|
688
785
|
voiRange,
|
|
689
786
|
VOILUTFunction,
|
|
690
787
|
interpolationType,
|
|
@@ -733,6 +830,52 @@ class StackViewport extends Viewport implements IStackViewport {
|
|
|
733
830
|
}
|
|
734
831
|
this.setInterpolationType(InterpolationType.LINEAR);
|
|
735
832
|
this.setInvertColor(this.initialInvert);
|
|
833
|
+
|
|
834
|
+
const transferFunction = this.getTransferFunction();
|
|
835
|
+
setTransferFunctionNodes(
|
|
836
|
+
transferFunction,
|
|
837
|
+
this.initialTransferFunctionNodes
|
|
838
|
+
);
|
|
839
|
+
}
|
|
840
|
+
|
|
841
|
+
public resetToDefaultProperties(): void {
|
|
842
|
+
this.cpuRenderingInvalidated = true;
|
|
843
|
+
this.viewportStatus = ViewportStatus.PRE_RENDER;
|
|
844
|
+
|
|
845
|
+
this.fillWithBackgroundColor();
|
|
846
|
+
|
|
847
|
+
if (this.useCPURendering) {
|
|
848
|
+
this._cpuFallbackEnabledElement.renderingTools = {};
|
|
849
|
+
}
|
|
850
|
+
|
|
851
|
+
const currentImageId = this.getCurrentImageId();
|
|
852
|
+
const properties =
|
|
853
|
+
this.perImageIdDefaultProperties.get(currentImageId) ||
|
|
854
|
+
this.globalDefaultProperties;
|
|
855
|
+
|
|
856
|
+
if (properties.colormap?.name) {
|
|
857
|
+
this.setColormap(properties.colormap);
|
|
858
|
+
}
|
|
859
|
+
|
|
860
|
+
let voiRange;
|
|
861
|
+
if (properties.voiRange == undefined) {
|
|
862
|
+
// if not set via setProperties; if it is not a PT image or is not prescaled,
|
|
863
|
+
// use the voiRange for the current image from its metadata if found
|
|
864
|
+
// otherwise, use the cached voiRange
|
|
865
|
+
voiRange = this._getVOIRangeForCurrentImage();
|
|
866
|
+
} else {
|
|
867
|
+
voiRange = properties.voiRange;
|
|
868
|
+
}
|
|
869
|
+
|
|
870
|
+
this.setVOI(voiRange);
|
|
871
|
+
|
|
872
|
+
if (this.getRotation() !== 0) {
|
|
873
|
+
this.setRotation(0);
|
|
874
|
+
}
|
|
875
|
+
this.setInterpolationType(InterpolationType.LINEAR);
|
|
876
|
+
this.setInvertColor(false);
|
|
877
|
+
|
|
878
|
+
this.render();
|
|
736
879
|
}
|
|
737
880
|
|
|
738
881
|
private _setPropertiesFromCache(): void {
|
|
@@ -1040,6 +1183,7 @@ class StackViewport extends Viewport implements IStackViewport {
|
|
|
1040
1183
|
|
|
1041
1184
|
// @ts-ignore
|
|
1042
1185
|
volumeProperty.setInterpolationType(interpolationType);
|
|
1186
|
+
|
|
1043
1187
|
this.interpolationType = interpolationType;
|
|
1044
1188
|
}
|
|
1045
1189
|
|
|
@@ -1091,6 +1235,7 @@ class StackViewport extends Viewport implements IStackViewport {
|
|
|
1091
1235
|
if ((!this.invert && invert) || (this.invert && !invert)) {
|
|
1092
1236
|
invertRgbTransferFunction(tfunc);
|
|
1093
1237
|
}
|
|
1238
|
+
|
|
1094
1239
|
this.invert = invert;
|
|
1095
1240
|
}
|
|
1096
1241
|
}
|
|
@@ -1145,6 +1290,21 @@ class StackViewport extends Viewport implements IStackViewport {
|
|
|
1145
1290
|
}
|
|
1146
1291
|
}
|
|
1147
1292
|
|
|
1293
|
+
private getTransferFunction() {
|
|
1294
|
+
const defaultActor = this.getDefaultActor();
|
|
1295
|
+
|
|
1296
|
+
if (!defaultActor) {
|
|
1297
|
+
return;
|
|
1298
|
+
}
|
|
1299
|
+
|
|
1300
|
+
if (!isImageActor(defaultActor)) {
|
|
1301
|
+
return;
|
|
1302
|
+
}
|
|
1303
|
+
const imageActor = defaultActor.actor as ImageActor;
|
|
1304
|
+
|
|
1305
|
+
return imageActor.getProperty().getRGBTransferFunction(0);
|
|
1306
|
+
}
|
|
1307
|
+
|
|
1148
1308
|
private setVOIGPU(voiRange: VOIRange, options: SetVOIOptions = {}): void {
|
|
1149
1309
|
const {
|
|
1150
1310
|
suppressEvents = false,
|
|
@@ -1204,6 +1364,8 @@ class StackViewport extends Viewport implements IStackViewport {
|
|
|
1204
1364
|
}
|
|
1205
1365
|
|
|
1206
1366
|
imageActor.getProperty().setRGBTransferFunction(0, transferFunction);
|
|
1367
|
+
this.initialTransferFunctionNodes =
|
|
1368
|
+
getTransferFunctionNodes(transferFunction);
|
|
1207
1369
|
}
|
|
1208
1370
|
|
|
1209
1371
|
if (!isSigmoidTFun) {
|
|
@@ -2084,7 +2246,7 @@ class StackViewport extends Viewport implements IStackViewport {
|
|
|
2084
2246
|
|
|
2085
2247
|
private _getInitialVOIRange(image: IImage) {
|
|
2086
2248
|
if (this.voiRange && this.voiUpdatedWithSetProperties) {
|
|
2087
|
-
return this.voiRange;
|
|
2249
|
+
return this.globalDefaultProperties.voiRange;
|
|
2088
2250
|
}
|
|
2089
2251
|
const { windowCenter, windowWidth } = image;
|
|
2090
2252
|
|
|
@@ -2164,6 +2326,17 @@ class StackViewport extends Viewport implements IStackViewport {
|
|
|
2164
2326
|
imageIdIndex
|
|
2165
2327
|
);
|
|
2166
2328
|
|
|
2329
|
+
//Check if there is any existing specific options for images if not we don't
|
|
2330
|
+
//want to re-render the viewport to its default properties
|
|
2331
|
+
if (this.perImageIdDefaultProperties.size >= 1) {
|
|
2332
|
+
const defaultProperties = this.perImageIdDefaultProperties.get(imageId);
|
|
2333
|
+
if (defaultProperties !== undefined) {
|
|
2334
|
+
this.setProperties(defaultProperties);
|
|
2335
|
+
} else if (this.globalDefaultProperties !== undefined) {
|
|
2336
|
+
this.setProperties(this.globalDefaultProperties);
|
|
2337
|
+
}
|
|
2338
|
+
}
|
|
2339
|
+
|
|
2167
2340
|
return imageId;
|
|
2168
2341
|
}
|
|
2169
2342
|
|
|
@@ -2642,6 +2815,7 @@ class StackViewport extends Viewport implements IStackViewport {
|
|
|
2642
2815
|
}
|
|
2643
2816
|
|
|
2644
2817
|
private setColormapCPU(colormapData: CPUFallbackColormapData) {
|
|
2818
|
+
this.colormap = colormapData;
|
|
2645
2819
|
const colormap = getColormap(colormapData.name, colormapData);
|
|
2646
2820
|
|
|
2647
2821
|
this._cpuFallbackEnabledElement.viewport.colormap = colormap;
|
|
@@ -2653,23 +2827,31 @@ class StackViewport extends Viewport implements IStackViewport {
|
|
|
2653
2827
|
this.render();
|
|
2654
2828
|
}
|
|
2655
2829
|
|
|
2656
|
-
private setColormapGPU(colormap:
|
|
2830
|
+
private setColormapGPU(colormap: ColormapPublic) {
|
|
2657
2831
|
const ActorEntry = this.getDefaultActor();
|
|
2658
2832
|
const actor = ActorEntry.actor as ImageActor;
|
|
2659
2833
|
const actorProp = actor.getProperty();
|
|
2660
2834
|
const rgbTransferFunction = actorProp.getRGBTransferFunction();
|
|
2661
2835
|
|
|
2836
|
+
const colormapObj =
|
|
2837
|
+
colormapUtils.getColormap(colormap.name) ||
|
|
2838
|
+
vtkColorMaps.getPresetByName(colormap.name);
|
|
2839
|
+
|
|
2662
2840
|
if (!rgbTransferFunction) {
|
|
2663
2841
|
const cfun = vtkColorTransferFunction.newInstance();
|
|
2664
|
-
|
|
2665
|
-
cfun.
|
|
2666
|
-
cfun.setMappingRange(voiRange.lower, voiRange.upper);
|
|
2842
|
+
cfun.applyColorMap(colormapObj);
|
|
2843
|
+
cfun.setMappingRange(this.voiRange.lower, this.voiRange.upper);
|
|
2667
2844
|
actorProp.setRGBTransferFunction(0, cfun);
|
|
2668
2845
|
} else {
|
|
2669
|
-
rgbTransferFunction.applyColorMap(
|
|
2846
|
+
rgbTransferFunction.applyColorMap(colormapObj);
|
|
2847
|
+
rgbTransferFunction.setMappingRange(
|
|
2848
|
+
this.voiRange.lower,
|
|
2849
|
+
this.voiRange.upper
|
|
2850
|
+
);
|
|
2670
2851
|
actorProp.setRGBTransferFunction(0, rgbTransferFunction);
|
|
2671
2852
|
}
|
|
2672
2853
|
|
|
2854
|
+
this.colormap = colormap;
|
|
2673
2855
|
this.render();
|
|
2674
2856
|
}
|
|
2675
2857
|
|
|
@@ -14,9 +14,16 @@ import type {
|
|
|
14
14
|
Point3,
|
|
15
15
|
} from '../types';
|
|
16
16
|
import type { ViewportInput } from '../types/IViewport';
|
|
17
|
-
import {
|
|
17
|
+
import {
|
|
18
|
+
actorIsA,
|
|
19
|
+
getClosestImageId,
|
|
20
|
+
isImageActor,
|
|
21
|
+
triggerEvent,
|
|
22
|
+
} from '../utilities';
|
|
18
23
|
import BaseVolumeViewport from './BaseVolumeViewport';
|
|
19
24
|
import setDefaultVolumeVOI from './helpers/setDefaultVolumeVOI';
|
|
25
|
+
import { setTransferFunctionNodes } from '../utilities/transferFunctionUtils';
|
|
26
|
+
import { ImageActor } from '../types/IActor';
|
|
20
27
|
|
|
21
28
|
/**
|
|
22
29
|
* An object representing a VolumeViewport. VolumeViewports are used to render
|
|
@@ -272,6 +279,11 @@ class VolumeViewport extends BaseVolumeViewport {
|
|
|
272
279
|
* the slab thickness to (if not provided, all actors will be affected).
|
|
273
280
|
*/
|
|
274
281
|
public setSlabThickness(slabThickness: number, filterActorUIDs = []): void {
|
|
282
|
+
if (slabThickness < 0.1) {
|
|
283
|
+
// Cannot render zero thickness
|
|
284
|
+
slabThickness = 0.1;
|
|
285
|
+
}
|
|
286
|
+
|
|
275
287
|
let actorEntries = this.getActors();
|
|
276
288
|
|
|
277
289
|
if (filterActorUIDs && filterActorUIDs.length > 0) {
|
|
@@ -385,6 +397,15 @@ class VolumeViewport extends BaseVolumeViewport {
|
|
|
385
397
|
}
|
|
386
398
|
setDefaultVolumeVOI(volumeActor.actor as vtkVolume, imageVolume, false);
|
|
387
399
|
|
|
400
|
+
if (isImageActor(volumeActor)) {
|
|
401
|
+
setTransferFunctionNodes(
|
|
402
|
+
(volumeActor.actor as ImageActor)
|
|
403
|
+
.getProperty()
|
|
404
|
+
.getRGBTransferFunction(0),
|
|
405
|
+
this.initialTransferFunctionNodes
|
|
406
|
+
);
|
|
407
|
+
}
|
|
408
|
+
|
|
388
409
|
const range = (volumeActor.actor as vtkVolume)
|
|
389
410
|
.getProperty()
|
|
390
411
|
.getRGBTransferFunction(0)
|
|
@@ -7,7 +7,7 @@ import Point2 from './Point2';
|
|
|
7
7
|
import Point3 from './Point3';
|
|
8
8
|
import { Scaling } from './ScalingParameters';
|
|
9
9
|
import StackViewportProperties from './StackViewportProperties';
|
|
10
|
-
import {
|
|
10
|
+
import { ColormapPublic } from './Colormap';
|
|
11
11
|
import IImage from './IImage';
|
|
12
12
|
|
|
13
13
|
/**
|
|
@@ -27,14 +27,38 @@ export default interface IStackViewport extends IViewport {
|
|
|
27
27
|
* metadata, it returns undefined, otherwise, frameOfReferenceUID is returned.
|
|
28
28
|
*/
|
|
29
29
|
getFrameOfReferenceUID: () => string;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Update the default properties of the viewport and add properties by imageId if specified
|
|
33
|
+
* setting the VOI, inverting the colors and setting the interpolation type, rotation
|
|
34
|
+
*/
|
|
35
|
+
setDefaultProperties(
|
|
36
|
+
ViewportProperties: StackViewportProperties,
|
|
37
|
+
imageId?: string
|
|
38
|
+
): void;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Remove the global default properties of the viewport or remove default properties for an imageId if specified
|
|
42
|
+
*/
|
|
43
|
+
clearDefaultProperties(imageId?: string): void;
|
|
30
44
|
/**
|
|
31
45
|
* Sets the properties for the viewport on the default actor. Properties include
|
|
32
46
|
* setting the VOI, inverting the colors and setting the interpolation type, rotation
|
|
33
47
|
*/
|
|
34
48
|
setProperties(
|
|
35
|
-
{
|
|
49
|
+
{
|
|
50
|
+
voiRange,
|
|
51
|
+
invert,
|
|
52
|
+
interpolationType,
|
|
53
|
+
rotation,
|
|
54
|
+
colormap,
|
|
55
|
+
}: StackViewportProperties,
|
|
36
56
|
suppressEvents?: boolean
|
|
37
57
|
): void;
|
|
58
|
+
/**
|
|
59
|
+
* Retrieve the viewport default properties
|
|
60
|
+
*/
|
|
61
|
+
getDefaultProperties: (imageId?: string) => StackViewportProperties;
|
|
38
62
|
/**
|
|
39
63
|
* Retrieve the viewport properties
|
|
40
64
|
*/
|
|
@@ -90,7 +114,11 @@ export default interface IStackViewport extends IViewport {
|
|
|
90
114
|
*/
|
|
91
115
|
getCornerstoneImage: () => IImage;
|
|
92
116
|
/**
|
|
93
|
-
* Reset the viewport properties to the default values
|
|
117
|
+
* Reset the viewport properties to the his default values if possible
|
|
118
|
+
*/
|
|
119
|
+
resetToDefaultProperties(): void;
|
|
120
|
+
/**
|
|
121
|
+
* Reset the viewport properties to the default metadata values
|
|
94
122
|
*/
|
|
95
123
|
resetProperties(): void;
|
|
96
124
|
/**
|
|
@@ -132,11 +160,6 @@ export default interface IStackViewport extends IViewport {
|
|
|
132
160
|
* If the renderer is CPU based, throw an error. Otherwise, returns the `vtkRenderer` responsible for rendering the `Viewport`.
|
|
133
161
|
*/
|
|
134
162
|
getRenderer(): any;
|
|
135
|
-
/**
|
|
136
|
-
* Sets the colormap for the current viewport.
|
|
137
|
-
* @param colormap - The colormap data to use.
|
|
138
|
-
*/
|
|
139
|
-
setColormap(colormap: CPUFallbackColormapData | ColormapRegistration): void;
|
|
140
163
|
/**
|
|
141
164
|
* It sets the colormap to the default colormap.
|
|
142
165
|
*/
|
|
@@ -13,10 +13,18 @@ import { VolumeViewportProperties } from '.';
|
|
|
13
13
|
export default interface IVolumeViewport extends IViewport {
|
|
14
14
|
useCPURendering: boolean;
|
|
15
15
|
getFrameOfReferenceUID: () => string;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Retrieve the viewport default properties
|
|
19
|
+
* If volumeId is given, we retrieve the default properties of a volumeId if it exists
|
|
20
|
+
* If not given,we return the global properties of the viewport
|
|
21
|
+
* default viewport properties including voi, invert, interpolation type, colormap
|
|
22
|
+
*/
|
|
23
|
+
getDefaultProperties: (volumeId?: string) => VolumeViewportProperties;
|
|
16
24
|
/**
|
|
17
25
|
* Retrieve the viewport properties
|
|
18
26
|
*/
|
|
19
|
-
getProperties: () => VolumeViewportProperties;
|
|
27
|
+
getProperties: (volumeId?: string) => VolumeViewportProperties;
|
|
20
28
|
/**
|
|
21
29
|
* canvasToWorld Returns the world coordinates of the given `canvasPos`
|
|
22
30
|
* projected onto the plane defined by the `Viewport`'s `vtkCamera`'s focal point
|
|
@@ -57,6 +65,20 @@ export default interface IVolumeViewport extends IViewport {
|
|
|
57
65
|
* currently being viewed.
|
|
58
66
|
*/
|
|
59
67
|
getCurrentImageId: () => string;
|
|
68
|
+
/**
|
|
69
|
+
* Sets the default properties for the viewport. If no volumeId is provided
|
|
70
|
+
* it applies the properties to the default volume actor (first volume)
|
|
71
|
+
*/
|
|
72
|
+
setDefaultProperties(
|
|
73
|
+
ViewportProperties: VolumeViewportProperties,
|
|
74
|
+
volumeId?: string
|
|
75
|
+
): void;
|
|
76
|
+
/**
|
|
77
|
+
* Remove the global default properties of the viewport or remove default properties for a volumeId if specified
|
|
78
|
+
* If volumeId is given, we remove the default properties only for this volumeId, if not
|
|
79
|
+
* the global default properties will be removed
|
|
80
|
+
*/
|
|
81
|
+
clearDefaultProperties(volumeId?: string): void;
|
|
60
82
|
/**
|
|
61
83
|
* Sets the properties for the viewport. If no volumeId is provided
|
|
62
84
|
* it applies the properties to the default volume actor (first volume)
|
|
@@ -66,6 +88,10 @@ export default interface IVolumeViewport extends IViewport {
|
|
|
66
88
|
volumeId?: string,
|
|
67
89
|
suppressEvents?: boolean
|
|
68
90
|
): void;
|
|
91
|
+
/**
|
|
92
|
+
* Reset the viewport properties to the default values
|
|
93
|
+
*/
|
|
94
|
+
resetProperties(volumeId: string): void;
|
|
69
95
|
/**
|
|
70
96
|
* Creates volume actors for all volumes defined in the `volumeInputArray`.
|
|
71
97
|
* For each entry, if a `callback` is supplied, it will be called with the new volume actor as input.
|
|
@@ -142,8 +168,4 @@ export default interface IVolumeViewport extends IViewport {
|
|
|
142
168
|
getImageData(volumeId?: string): IImageData | undefined;
|
|
143
169
|
|
|
144
170
|
setOrientation(orientation: OrientationAxis): void;
|
|
145
|
-
/**
|
|
146
|
-
* Reset the viewport properties to the default values
|
|
147
|
-
*/
|
|
148
|
-
resetProperties(volumeId?: string): void;
|
|
149
171
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { InterpolationType, VOILUTFunctionType } from '../enums';
|
|
2
2
|
import { VOIRange } from './voi';
|
|
3
|
+
import { ColormapPublic } from './Colormap';
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* Shared Viewport Properties between Stack and Volume Viewports
|
|
@@ -11,6 +12,8 @@ type ViewportProperties = {
|
|
|
11
12
|
VOILUTFunction?: VOILUTFunctionType;
|
|
12
13
|
/** invert flag - whether the image is inverted */
|
|
13
14
|
invert?: boolean;
|
|
15
|
+
/** Colormap applied to the viewport*/
|
|
16
|
+
colormap?: ColormapPublic;
|
|
14
17
|
/** interpolation type */
|
|
15
18
|
interpolationType?: InterpolationType;
|
|
16
19
|
};
|
|
@@ -1,14 +1,13 @@
|
|
|
1
|
-
import { ColormapPublic } from './Colormap';
|
|
2
1
|
import { ViewportProperties } from './ViewportProperties';
|
|
3
2
|
|
|
4
3
|
/**
|
|
5
4
|
* Stack Viewport Properties
|
|
6
5
|
*/
|
|
7
6
|
type VolumeViewportProperties = ViewportProperties & {
|
|
8
|
-
/** color maps */
|
|
9
|
-
colormap?: ColormapPublic;
|
|
10
7
|
/** 3d preset */
|
|
11
8
|
preset?: string;
|
|
9
|
+
|
|
10
|
+
slabThickness?: number;
|
|
12
11
|
};
|
|
13
12
|
|
|
14
13
|
export default VolumeViewportProperties;
|
package/src/utilities/index.ts
CHANGED
|
@@ -51,6 +51,7 @@ import getImageLegacy from './getImageLegacy';
|
|
|
51
51
|
import * as planar from './planar';
|
|
52
52
|
import * as windowLevel from './windowLevel';
|
|
53
53
|
import * as colormap from './colormap';
|
|
54
|
+
import * as transferFunctionUtils from './transferFunctionUtils';
|
|
54
55
|
|
|
55
56
|
export {
|
|
56
57
|
csUtils as invertRgbTransferFunction,
|
|
@@ -105,4 +106,5 @@ export {
|
|
|
105
106
|
getScalarDataType,
|
|
106
107
|
colormap,
|
|
107
108
|
getImageLegacy,
|
|
109
|
+
transferFunctionUtils,
|
|
108
110
|
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
function getTransferFunctionNodes(transferFunction) {
|
|
2
|
+
const size = transferFunction.getSize();
|
|
3
|
+
const values = [];
|
|
4
|
+
for (let index = 0; index < size; index++) {
|
|
5
|
+
const nodeValue1 = [];
|
|
6
|
+
|
|
7
|
+
transferFunction.getNodeValue(index, nodeValue1);
|
|
8
|
+
|
|
9
|
+
values.push(nodeValue1);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
return values;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function setTransferFunctionNodes(transferFunction, nodes) {
|
|
16
|
+
transferFunction.removeAllPoints();
|
|
17
|
+
|
|
18
|
+
nodes.forEach((node) => {
|
|
19
|
+
transferFunction.addRGBPoint(...node);
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export { getTransferFunctionNodes, setTransferFunctionNodes };
|