@cornerstonejs/core 1.70.12 → 1.70.14
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 +3 -0
- package/dist/cjs/RenderingEngine/BaseVolumeViewport.js +44 -56
- package/dist/cjs/RenderingEngine/BaseVolumeViewport.js.map +1 -1
- package/dist/cjs/RenderingEngine/StackViewport.js +9 -0
- package/dist/cjs/RenderingEngine/StackViewport.js.map +1 -1
- package/dist/cjs/RenderingEngine/VolumeViewport.js +6 -15
- package/dist/cjs/RenderingEngine/VolumeViewport.js.map +1 -1
- package/dist/cjs/RenderingEngine/vtkClasses/vtkStreamingOpenGLRenderWindow.js +25 -2
- package/dist/cjs/RenderingEngine/vtkClasses/vtkStreamingOpenGLRenderWindow.js.map +1 -1
- package/dist/cjs/RenderingEngine/vtkClasses/vtkStreamingOpenGLViewNodeFactory.d.ts +1 -0
- package/dist/cjs/RenderingEngine/vtkClasses/vtkStreamingOpenGLViewNodeFactory.js +23 -17
- package/dist/cjs/RenderingEngine/vtkClasses/vtkStreamingOpenGLViewNodeFactory.js.map +1 -1
- package/dist/cjs/types/Colormap.d.ts +1 -1
- package/dist/cjs/types/EventTypes.d.ts +1 -0
- package/dist/cjs/utilities/actorCheck.d.ts +1 -1
- package/dist/cjs/utilities/actorCheck.js +2 -2
- package/dist/cjs/utilities/actorCheck.js.map +1 -1
- package/dist/cjs/utilities/colormap.d.ts +3 -2
- package/dist/cjs/utilities/colormap.js +49 -1
- package/dist/cjs/utilities/colormap.js.map +1 -1
- package/dist/esm/RenderingEngine/BaseVolumeViewport.js +45 -52
- package/dist/esm/RenderingEngine/BaseVolumeViewport.js.map +1 -1
- package/dist/esm/RenderingEngine/StackViewport.js +9 -0
- package/dist/esm/RenderingEngine/StackViewport.js.map +1 -1
- package/dist/esm/RenderingEngine/VolumeViewport.js +5 -13
- package/dist/esm/RenderingEngine/VolumeViewport.js.map +1 -1
- package/dist/esm/RenderingEngine/vtkClasses/vtkStreamingOpenGLRenderWindow.js +2 -2
- package/dist/esm/RenderingEngine/vtkClasses/vtkStreamingOpenGLRenderWindow.js.map +1 -1
- package/dist/esm/RenderingEngine/vtkClasses/vtkStreamingOpenGLViewNodeFactory.js +21 -16
- package/dist/esm/RenderingEngine/vtkClasses/vtkStreamingOpenGLViewNodeFactory.js.map +1 -1
- package/dist/esm/utilities/actorCheck.js +2 -2
- package/dist/esm/utilities/actorCheck.js.map +1 -1
- package/dist/esm/utilities/colormap.js +45 -1
- package/dist/esm/utilities/colormap.js.map +1 -1
- package/dist/types/RenderingEngine/BaseVolumeViewport.d.ts +3 -0
- package/dist/types/RenderingEngine/BaseVolumeViewport.d.ts.map +1 -1
- package/dist/types/RenderingEngine/StackViewport.d.ts.map +1 -1
- package/dist/types/RenderingEngine/VolumeViewport.d.ts.map +1 -1
- package/dist/types/RenderingEngine/vtkClasses/vtkStreamingOpenGLRenderWindow.d.ts.map +1 -1
- package/dist/types/RenderingEngine/vtkClasses/vtkStreamingOpenGLViewNodeFactory.d.ts +1 -0
- package/dist/types/RenderingEngine/vtkClasses/vtkStreamingOpenGLViewNodeFactory.d.ts.map +1 -1
- package/dist/types/types/Colormap.d.ts +1 -1
- package/dist/types/types/Colormap.d.ts.map +1 -1
- package/dist/types/types/EventTypes.d.ts +1 -0
- package/dist/types/types/EventTypes.d.ts.map +1 -1
- package/dist/types/utilities/actorCheck.d.ts +1 -1
- package/dist/types/utilities/actorCheck.d.ts.map +1 -1
- package/dist/types/utilities/colormap.d.ts +3 -2
- package/dist/types/utilities/colormap.d.ts.map +1 -1
- package/dist/umd/index.js +1 -1
- package/dist/umd/index.js.map +1 -1
- package/package.json +3 -3
- package/src/RenderingEngine/BaseVolumeViewport.ts +69 -68
- package/src/RenderingEngine/StackViewport.ts +13 -0
- package/src/RenderingEngine/VolumeViewport.ts +7 -15
- package/src/RenderingEngine/vtkClasses/vtkStreamingOpenGLRenderWindow.js +6 -5
- package/src/RenderingEngine/vtkClasses/vtkStreamingOpenGLViewNodeFactory.js +25 -32
- package/src/types/Colormap.ts +1 -1
- package/src/types/EventTypes.ts +2 -0
- package/src/utilities/actorCheck.ts +3 -3
- package/src/utilities/colormap.ts +80 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cornerstonejs/core",
|
|
3
|
-
"version": "1.70.
|
|
3
|
+
"version": "1.70.14",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "src/index.ts",
|
|
6
6
|
"types": "dist/types/index.d.ts",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"webpack:watch": "webpack --mode development --progress --watch --config ./.webpack/webpack.dev.js"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@kitware/vtk.js": "30.
|
|
33
|
+
"@kitware/vtk.js": "30.4.1",
|
|
34
34
|
"comlink": "^4.4.1",
|
|
35
35
|
"detect-gpu": "^5.0.22",
|
|
36
36
|
"gl-matrix": "^3.4.3",
|
|
@@ -47,5 +47,5 @@
|
|
|
47
47
|
"type": "individual",
|
|
48
48
|
"url": "https://ohif.org/donate"
|
|
49
49
|
},
|
|
50
|
-
"gitHead": "
|
|
50
|
+
"gitHead": "e511c3f4b11596cfedb30b071b42c9c68d71d018"
|
|
51
51
|
}
|
|
@@ -51,7 +51,6 @@ import {
|
|
|
51
51
|
invertRgbTransferFunction,
|
|
52
52
|
triggerEvent,
|
|
53
53
|
colormap as colormapUtils,
|
|
54
|
-
isEqual,
|
|
55
54
|
} from '../utilities';
|
|
56
55
|
import { createVolumeActor } from './helpers';
|
|
57
56
|
import volumeNewImageEventDispatcher, {
|
|
@@ -61,8 +60,8 @@ import Viewport from './Viewport';
|
|
|
61
60
|
import type { vtkSlabCamera as vtkSlabCameraType } from './vtkClasses/vtkSlabCamera';
|
|
62
61
|
import vtkSlabCamera from './vtkClasses/vtkSlabCamera';
|
|
63
62
|
import transformWorldToIndex from '../utilities/transformWorldToIndex';
|
|
63
|
+
import { findMatchingColormap } from '../utilities/colormap';
|
|
64
64
|
import { getTransferFunctionNodes } from '../utilities/transferFunctionUtils';
|
|
65
|
-
import { getColormap, getColormapNames } from '../utilities/colormap';
|
|
66
65
|
/**
|
|
67
66
|
* Abstract base class for volume viewports. VolumeViewports are used to render
|
|
68
67
|
* 3D volumes from which various orientations can be viewed. Since VolumeViewports
|
|
@@ -357,17 +356,11 @@ abstract class BaseVolumeViewport extends Viewport implements IVolumeViewport {
|
|
|
357
356
|
const cfun = this._getOrCreateColorTransferFunction(volumeIdToUse);
|
|
358
357
|
invertRgbTransferFunction(cfun);
|
|
359
358
|
|
|
360
|
-
const { voiRange, VOILUTFunction } = this.getProperties(volumeIdToUse);
|
|
361
|
-
|
|
362
359
|
this.viewportProperties.invert = inverted;
|
|
363
360
|
|
|
364
361
|
if (!suppressEvents) {
|
|
365
362
|
const eventDetail: VoiModifiedEventDetail = {
|
|
366
|
-
|
|
367
|
-
range: voiRange,
|
|
368
|
-
volumeId: volumeIdToUse,
|
|
369
|
-
VOILUTFunction: VOILUTFunction,
|
|
370
|
-
invert: inverted,
|
|
363
|
+
...this.getVOIModifiedEventDetail(volumeIdToUse),
|
|
371
364
|
invertStateChanged: true,
|
|
372
365
|
};
|
|
373
366
|
|
|
@@ -375,6 +368,39 @@ abstract class BaseVolumeViewport extends Viewport implements IVolumeViewport {
|
|
|
375
368
|
}
|
|
376
369
|
}
|
|
377
370
|
|
|
371
|
+
protected getVOIModifiedEventDetail(
|
|
372
|
+
volumeId: string
|
|
373
|
+
): VoiModifiedEventDetail {
|
|
374
|
+
const applicableVolumeActorInfo = this._getApplicableVolumeActor(volumeId);
|
|
375
|
+
|
|
376
|
+
if (!applicableVolumeActorInfo) {
|
|
377
|
+
throw new Error(`No actor found for the given volumeId: ${volumeId}`);
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
const volumeActor = applicableVolumeActorInfo.volumeActor;
|
|
381
|
+
|
|
382
|
+
const transferFunction = volumeActor
|
|
383
|
+
.getProperty()
|
|
384
|
+
.getRGBTransferFunction(0);
|
|
385
|
+
|
|
386
|
+
const range = transferFunction.getMappingRange();
|
|
387
|
+
|
|
388
|
+
const matchedColormap = this.getColormap(volumeId);
|
|
389
|
+
const { VOILUTFunction, invert } = this.getProperties(volumeId);
|
|
390
|
+
|
|
391
|
+
return {
|
|
392
|
+
viewportId: this.id,
|
|
393
|
+
range: {
|
|
394
|
+
lower: range[0],
|
|
395
|
+
upper: range[1],
|
|
396
|
+
},
|
|
397
|
+
volumeId: applicableVolumeActorInfo.volumeId,
|
|
398
|
+
VOILUTFunction: VOILUTFunction,
|
|
399
|
+
colormap: matchedColormap,
|
|
400
|
+
invert,
|
|
401
|
+
};
|
|
402
|
+
}
|
|
403
|
+
|
|
378
404
|
private _getOrCreateColorTransferFunction(
|
|
379
405
|
volumeId: string
|
|
380
406
|
): vtkColorTransferFunction {
|
|
@@ -468,22 +494,11 @@ abstract class BaseVolumeViewport extends Viewport implements IVolumeViewport {
|
|
|
468
494
|
.getProperty()
|
|
469
495
|
.getRGBTransferFunction(0)
|
|
470
496
|
.setRange(lower, upper);
|
|
471
|
-
|
|
472
|
-
if (!this.initialTransferFunctionNodes) {
|
|
473
|
-
const transferFunction = volumeActor
|
|
474
|
-
.getProperty()
|
|
475
|
-
.getRGBTransferFunction(0);
|
|
476
|
-
this.initialTransferFunctionNodes =
|
|
477
|
-
getTransferFunctionNodes(transferFunction);
|
|
478
|
-
}
|
|
479
497
|
}
|
|
480
498
|
|
|
481
499
|
if (!suppressEvents) {
|
|
482
500
|
const eventDetail: VoiModifiedEventDetail = {
|
|
483
|
-
|
|
484
|
-
range: voiRange,
|
|
485
|
-
volumeId: volumeIdToUse,
|
|
486
|
-
VOILUTFunction: VOILUTFunction,
|
|
501
|
+
...this.getVOIModifiedEventDetail(volumeIdToUse),
|
|
487
502
|
};
|
|
488
503
|
|
|
489
504
|
triggerEvent(this.element, Events.VOI_MODIFIED, eventDetail);
|
|
@@ -850,7 +865,7 @@ abstract class BaseVolumeViewport extends Viewport implements IVolumeViewport {
|
|
|
850
865
|
? voiRanges.find((range) => range.volumeId === volumeId)?.voiRange
|
|
851
866
|
: voiRanges[0]?.voiRange;
|
|
852
867
|
|
|
853
|
-
const volumeColormap = this.getColormap(
|
|
868
|
+
const volumeColormap = this.getColormap(volumeId);
|
|
854
869
|
|
|
855
870
|
const colormap =
|
|
856
871
|
volumeId && volumeColormap ? volumeColormap : latestColormap;
|
|
@@ -880,7 +895,13 @@ abstract class BaseVolumeViewport extends Viewport implements IVolumeViewport {
|
|
|
880
895
|
* @param applicableVolumeActorInfo - The volume actor information for the volume
|
|
881
896
|
* @returns colormap information for the volume if identified
|
|
882
897
|
*/
|
|
883
|
-
private getColormap = (
|
|
898
|
+
private getColormap = (volumeId) => {
|
|
899
|
+
const applicableVolumeActorInfo = this._getApplicableVolumeActor(volumeId);
|
|
900
|
+
|
|
901
|
+
if (!applicableVolumeActorInfo) {
|
|
902
|
+
return;
|
|
903
|
+
}
|
|
904
|
+
|
|
884
905
|
const { volumeActor } = applicableVolumeActorInfo;
|
|
885
906
|
const cfun = volumeActor.getProperty().getRGBTransferFunction(0);
|
|
886
907
|
const { nodes } = cfun.getState();
|
|
@@ -888,53 +909,10 @@ abstract class BaseVolumeViewport extends Viewport implements IVolumeViewport {
|
|
|
888
909
|
acc.push(node.x, node.r, node.g, node.b);
|
|
889
910
|
return acc;
|
|
890
911
|
}, []);
|
|
891
|
-
const colormapsVTK = vtkColorMaps.rgbPresetNames.map((presetName) =>
|
|
892
|
-
vtkColorMaps.getPresetByName(presetName)
|
|
893
|
-
);
|
|
894
|
-
const colormapsCS3D = getColormapNames().map((colormapName) =>
|
|
895
|
-
getColormap(colormapName)
|
|
896
|
-
);
|
|
897
|
-
const colormaps = colormapsVTK.concat(colormapsCS3D);
|
|
898
|
-
const matchedColormap = colormaps.find((colormap) => {
|
|
899
|
-
const { RGBPoints: presetRGBPoints } = colormap;
|
|
900
|
-
if (presetRGBPoints.length !== RGBPoints.length) {
|
|
901
|
-
return false;
|
|
902
|
-
}
|
|
903
|
-
|
|
904
|
-
for (let i = 0; i < presetRGBPoints.length; i += 4) {
|
|
905
|
-
if (
|
|
906
|
-
!isEqual(
|
|
907
|
-
presetRGBPoints.slice(i + 1, i + 4),
|
|
908
|
-
RGBPoints.slice(i + 1, i + 4)
|
|
909
|
-
)
|
|
910
|
-
) {
|
|
911
|
-
return false;
|
|
912
|
-
}
|
|
913
|
-
}
|
|
914
|
-
|
|
915
|
-
return true;
|
|
916
|
-
});
|
|
917
|
-
|
|
918
|
-
if (!matchedColormap) {
|
|
919
|
-
return null;
|
|
920
|
-
}
|
|
921
912
|
|
|
922
|
-
const
|
|
923
|
-
.getProperty()
|
|
924
|
-
.getScalarOpacity(0)
|
|
925
|
-
.getDataPointer();
|
|
926
|
-
|
|
927
|
-
const opacity = [];
|
|
928
|
-
for (let i = 0; i < opacityPoints.length; i += 2) {
|
|
929
|
-
opacity.push({ value: opacityPoints[i], opacity: opacityPoints[i + 1] });
|
|
930
|
-
}
|
|
931
|
-
|
|
932
|
-
const colormap = {
|
|
933
|
-
name: matchedColormap.Name,
|
|
934
|
-
opacity: opacity,
|
|
935
|
-
};
|
|
913
|
+
const matchedColormap = findMatchingColormap(RGBPoints, volumeActor);
|
|
936
914
|
|
|
937
|
-
return
|
|
915
|
+
return matchedColormap;
|
|
938
916
|
};
|
|
939
917
|
|
|
940
918
|
/**
|
|
@@ -996,6 +974,8 @@ abstract class BaseVolumeViewport extends Viewport implements IVolumeViewport {
|
|
|
996
974
|
this._setVolumeActors(volumeActors);
|
|
997
975
|
this.viewportStatus = ViewportStatus.PRE_RENDER;
|
|
998
976
|
|
|
977
|
+
this.initializeColorTransferFunction(volumeInputArray);
|
|
978
|
+
|
|
999
979
|
triggerEvent(this.element, Events.VOLUME_VIEWPORT_NEW_VOLUME, {
|
|
1000
980
|
viewportId: this.id,
|
|
1001
981
|
volumeActors,
|
|
@@ -1070,6 +1050,8 @@ abstract class BaseVolumeViewport extends Viewport implements IVolumeViewport {
|
|
|
1070
1050
|
|
|
1071
1051
|
this.addActors(volumeActors);
|
|
1072
1052
|
|
|
1053
|
+
this.initializeColorTransferFunction(volumeInputArray);
|
|
1054
|
+
|
|
1073
1055
|
if (immediate) {
|
|
1074
1056
|
// render
|
|
1075
1057
|
this.render();
|
|
@@ -1106,6 +1088,25 @@ abstract class BaseVolumeViewport extends Viewport implements IVolumeViewport {
|
|
|
1106
1088
|
console.warn('Method "setOrientation" needs implementation');
|
|
1107
1089
|
}
|
|
1108
1090
|
|
|
1091
|
+
/**
|
|
1092
|
+
* Initializes the color transfer function nodes for a given volume.
|
|
1093
|
+
*
|
|
1094
|
+
* @param volumeInputArray - Array of volume inputs.
|
|
1095
|
+
* @param getTransferFunctionNodes - Function to get the transfer function nodes.
|
|
1096
|
+
* @returns void
|
|
1097
|
+
*/
|
|
1098
|
+
private initializeColorTransferFunction(volumeInputArray) {
|
|
1099
|
+
const selectedVolumeId = volumeInputArray[0].volumeId;
|
|
1100
|
+
const colorTransferFunction =
|
|
1101
|
+
this._getOrCreateColorTransferFunction(selectedVolumeId);
|
|
1102
|
+
|
|
1103
|
+
if (!this.initialTransferFunctionNodes) {
|
|
1104
|
+
this.initialTransferFunctionNodes = getTransferFunctionNodes(
|
|
1105
|
+
colorTransferFunction
|
|
1106
|
+
);
|
|
1107
|
+
}
|
|
1108
|
+
}
|
|
1109
|
+
|
|
1109
1110
|
private _getApplicableVolumeActor(volumeId?: string) {
|
|
1110
1111
|
if (volumeId !== undefined && !this.getActor(volumeId)) {
|
|
1111
1112
|
return;
|
|
@@ -97,6 +97,7 @@ import {
|
|
|
97
97
|
import correctShift from './helpers/cpuFallback/rendering/correctShift';
|
|
98
98
|
import resetCamera from './helpers/cpuFallback/rendering/resetCamera';
|
|
99
99
|
import { Transform } from './helpers/cpuFallback/rendering/transform';
|
|
100
|
+
import { findMatchingColormap } from '../utilities/colormap';
|
|
100
101
|
|
|
101
102
|
const EPSILON = 1; // Slice Thickness
|
|
102
103
|
|
|
@@ -867,6 +868,18 @@ class StackViewport extends Viewport implements IStackViewport, IImagesLoader {
|
|
|
867
868
|
transferFunction,
|
|
868
869
|
this.initialTransferFunctionNodes
|
|
869
870
|
);
|
|
871
|
+
|
|
872
|
+
const nodes = getTransferFunctionNodes(transferFunction);
|
|
873
|
+
|
|
874
|
+
const RGBPoints = nodes.reduce((acc, node) => {
|
|
875
|
+
acc.push(node[0], node[1], node[2], node[3]);
|
|
876
|
+
return acc;
|
|
877
|
+
}, []);
|
|
878
|
+
|
|
879
|
+
const defaultActor = this.getDefaultActor();
|
|
880
|
+
const matchedColormap = findMatchingColormap(RGBPoints, defaultActor.actor);
|
|
881
|
+
|
|
882
|
+
this.setColormap(matchedColormap);
|
|
870
883
|
}
|
|
871
884
|
|
|
872
885
|
public resetToDefaultProperties(): void {
|
|
@@ -238,7 +238,7 @@ class VolumeViewport extends BaseVolumeViewport {
|
|
|
238
238
|
|
|
239
239
|
const mapper = actor.getMapper();
|
|
240
240
|
// @ts-ignore vtk incorrect typing
|
|
241
|
-
mapper.setBlendMode(blendMode);
|
|
241
|
+
mapper.setBlendMode?.(blendMode);
|
|
242
242
|
});
|
|
243
243
|
|
|
244
244
|
if (immediate) {
|
|
@@ -443,26 +443,18 @@ class VolumeViewport extends BaseVolumeViewport {
|
|
|
443
443
|
setDefaultVolumeVOI(volumeActor.actor as vtkVolume, imageVolume, false);
|
|
444
444
|
|
|
445
445
|
if (isImageActor(volumeActor)) {
|
|
446
|
+
const transferFunction = (volumeActor.actor as ImageActor)
|
|
447
|
+
.getProperty()
|
|
448
|
+
.getRGBTransferFunction(0);
|
|
449
|
+
|
|
446
450
|
setTransferFunctionNodes(
|
|
447
|
-
|
|
448
|
-
.getProperty()
|
|
449
|
-
.getRGBTransferFunction(0),
|
|
451
|
+
transferFunction,
|
|
450
452
|
this.initialTransferFunctionNodes
|
|
451
453
|
);
|
|
452
454
|
}
|
|
453
455
|
|
|
454
|
-
const range = (volumeActor.actor as vtkVolume)
|
|
455
|
-
.getProperty()
|
|
456
|
-
.getRGBTransferFunction(0)
|
|
457
|
-
.getMappingRange();
|
|
458
|
-
|
|
459
456
|
const eventDetails = {
|
|
460
|
-
|
|
461
|
-
range: {
|
|
462
|
-
lower: range[0],
|
|
463
|
-
upper: range[1],
|
|
464
|
-
},
|
|
465
|
-
volumeId: volumeActor.uid,
|
|
457
|
+
...super.getVOIModifiedEventDetail(volumeId),
|
|
466
458
|
};
|
|
467
459
|
|
|
468
460
|
const resetPan = true;
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import macro from '@kitware/vtk.js/macros';
|
|
2
2
|
import vtkOpenGLRenderWindow from '@kitware/vtk.js/Rendering/OpenGL/RenderWindow';
|
|
3
|
-
import vtkStreamingOpenGLViewNodeFactory
|
|
3
|
+
import vtkStreamingOpenGLViewNodeFactory, {
|
|
4
|
+
registerOverride,
|
|
5
|
+
} from './vtkStreamingOpenGLViewNodeFactory';
|
|
4
6
|
|
|
5
7
|
/**
|
|
6
|
-
* vtkStreamingOpenGLRenderWindow - A
|
|
8
|
+
* vtkStreamingOpenGLRenderWindow - A derived class of the core vtkOpenGLRenderWindow class.
|
|
7
9
|
* The main purpose for this class extension is to add in our own node factory, so we can use
|
|
8
10
|
* our extended "streaming" classes for progressive texture loading.
|
|
9
11
|
*
|
|
@@ -27,9 +29,8 @@ export function extend(publicAPI, model, initialValues = {}) {
|
|
|
27
29
|
vtkOpenGLRenderWindow.extend(publicAPI, model, initialValues);
|
|
28
30
|
|
|
29
31
|
model.myFactory = vtkStreamingOpenGLViewNodeFactory.newInstance();
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
/* eslint-enable no-use-before-define */
|
|
32
|
+
|
|
33
|
+
registerOverride('vtkRenderWindow', newInstance);
|
|
33
34
|
|
|
34
35
|
// Object methods
|
|
35
36
|
vtkStreamingOpenGLRenderWindow(publicAPI, model);
|
|
@@ -18,6 +18,12 @@ import vtkOpenGLVolumeMapper from '@kitware/vtk.js/Rendering/OpenGL/VolumeMapper
|
|
|
18
18
|
import vtkViewNodeFactory from '@kitware/vtk.js/Rendering/SceneGraph/ViewNodeFactory';
|
|
19
19
|
import vtkStreamingOpenGLVolumeMapper from './vtkStreamingOpenGLVolumeMapper';
|
|
20
20
|
|
|
21
|
+
const CLASS_MAPPING = Object.create(null);
|
|
22
|
+
|
|
23
|
+
export function registerOverride(className, fn) {
|
|
24
|
+
CLASS_MAPPING[className] = fn;
|
|
25
|
+
}
|
|
26
|
+
|
|
21
27
|
/**
|
|
22
28
|
* vtkStreamingOpenGLViewNodeFactory - A fork of the vtkOpenGLViewNodeFactory,
|
|
23
29
|
* so that we can inject our custom derived "Streaming" classes.
|
|
@@ -63,6 +69,8 @@ function vtkStreamingOpenGLViewNodeFactory(publicAPI, model) {
|
|
|
63
69
|
return vn;
|
|
64
70
|
};
|
|
65
71
|
|
|
72
|
+
model.overrides = CLASS_MAPPING;
|
|
73
|
+
|
|
66
74
|
/**
|
|
67
75
|
* getModelInitialValues - This function allows us to pass textures down from our
|
|
68
76
|
* vtkSharedVolumeMapper to new instances of vtkStreamingOpenGLVolumeMapper.
|
|
@@ -104,44 +112,29 @@ export function extend(publicAPI, model, initialValues = {}) {
|
|
|
104
112
|
vtkStreamingOpenGLViewNodeFactory(publicAPI, model);
|
|
105
113
|
|
|
106
114
|
// Initialization
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
);
|
|
114
|
-
|
|
115
|
-
'vtkImageMapper',
|
|
116
|
-
vtkOpenGLImageMapper.newInstance
|
|
117
|
-
);
|
|
118
|
-
publicAPI.registerOverride('vtkImageSlice', vtkOpenGLImageSlice.newInstance);
|
|
119
|
-
publicAPI.registerOverride('vtkMapper', vtkOpenGLPolyDataMapper.newInstance);
|
|
120
|
-
publicAPI.registerOverride(
|
|
115
|
+
registerOverride('vtkActor', vtkOpenGLActor.newInstance);
|
|
116
|
+
registerOverride('vtkActor2D', vtkOpenGLActor2D.newInstance);
|
|
117
|
+
registerOverride('vtkCamera', vtkOpenGLCamera.newInstance);
|
|
118
|
+
registerOverride('vtkGlyph3DMapper', vtkOpenGLGlyph3DMapper.newInstance);
|
|
119
|
+
registerOverride('vtkImageMapper', vtkOpenGLImageMapper.newInstance);
|
|
120
|
+
registerOverride('vtkImageSlice', vtkOpenGLImageSlice.newInstance);
|
|
121
|
+
registerOverride('vtkMapper', vtkOpenGLPolyDataMapper.newInstance);
|
|
122
|
+
registerOverride(
|
|
121
123
|
'vtkPixelSpaceCallbackMapper',
|
|
122
124
|
vtkOpenGLPixelSpaceCallbackMapper.newInstance
|
|
123
125
|
);
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
);
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
vtkOpenGLStickMapper.newInstance
|
|
133
|
-
);
|
|
134
|
-
publicAPI.registerOverride('vtkTexture', vtkOpenGLTexture.newInstance);
|
|
135
|
-
publicAPI.registerOverride('vtkVolume', vtkOpenGLVolume.newInstance);
|
|
136
|
-
publicAPI.registerOverride(
|
|
137
|
-
'vtkVolumeMapper',
|
|
138
|
-
vtkOpenGLVolumeMapper.newInstance
|
|
139
|
-
);
|
|
140
|
-
publicAPI.registerOverride(
|
|
126
|
+
registerOverride('vtkRenderer', vtkOpenGLRenderer.newInstance);
|
|
127
|
+
registerOverride('vtkSkybox', vtkOpenGLSkybox.newInstance);
|
|
128
|
+
registerOverride('vtkSphereMapper', vtkOpenGLSphereMapper.newInstance);
|
|
129
|
+
registerOverride('vtkStickMapper', vtkOpenGLStickMapper.newInstance);
|
|
130
|
+
registerOverride('vtkTexture', vtkOpenGLTexture.newInstance);
|
|
131
|
+
registerOverride('vtkVolume', vtkOpenGLVolume.newInstance);
|
|
132
|
+
registerOverride('vtkVolumeMapper', vtkOpenGLVolumeMapper.newInstance);
|
|
133
|
+
registerOverride(
|
|
141
134
|
'vtkSharedVolumeMapper',
|
|
142
135
|
vtkStreamingOpenGLVolumeMapper.newInstance
|
|
143
136
|
);
|
|
144
|
-
//
|
|
137
|
+
// registerOverride(
|
|
145
138
|
// 'vtkWidgetRepresentation',
|
|
146
139
|
// vtkGenericWidgetRepresentation.newInstance
|
|
147
140
|
// )
|
package/src/types/Colormap.ts
CHANGED
package/src/types/EventTypes.ts
CHANGED
|
@@ -47,6 +47,8 @@ type VoiModifiedEventDetail = {
|
|
|
47
47
|
invert?: boolean;
|
|
48
48
|
/** Indicates if the 'invert' state has changed from the previous state */
|
|
49
49
|
invertStateChanged?: boolean;
|
|
50
|
+
/** color map */
|
|
51
|
+
colormap?: ColormapPublic;
|
|
50
52
|
};
|
|
51
53
|
|
|
52
54
|
type ColormapModifiedEventDetail = {
|
|
@@ -15,10 +15,10 @@ export function isImageActor(actorEntry: Types.ActorEntry): boolean {
|
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
export function actorIsA(
|
|
18
|
-
actorEntry: Types.ActorEntry,
|
|
18
|
+
actorEntry: Types.ActorEntry | Types.Actor,
|
|
19
19
|
actorType: actorTypes
|
|
20
20
|
): boolean {
|
|
21
|
-
const
|
|
21
|
+
const actorToCheck = 'isA' in actorEntry ? actorEntry : actorEntry.actor;
|
|
22
22
|
|
|
23
|
-
return !!
|
|
23
|
+
return !!actorToCheck.isA(actorType);
|
|
24
24
|
}
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
import
|
|
1
|
+
import vtkColorMaps from '@kitware/vtk.js/Rendering/Core/ColorTransferFunction/ColorMaps';
|
|
2
|
+
|
|
3
|
+
import { ColormapPublic, ColormapRegistration } from '../types';
|
|
4
|
+
import isEqual from './isEqual';
|
|
5
|
+
import { actorIsA } from './actorCheck';
|
|
2
6
|
|
|
3
7
|
const _colormaps = new Map();
|
|
4
8
|
|
|
@@ -29,4 +33,78 @@ function getColormapNames() {
|
|
|
29
33
|
return Array.from(_colormaps.keys());
|
|
30
34
|
}
|
|
31
35
|
|
|
32
|
-
|
|
36
|
+
/**
|
|
37
|
+
* Finds a colormap that matches the given RGB points.
|
|
38
|
+
*
|
|
39
|
+
* @param rgbPoints - The RGB points to match against the colormaps.
|
|
40
|
+
* @returns The matched colormap object or null if no match is found.
|
|
41
|
+
*/
|
|
42
|
+
function findMatchingColormap(rgbPoints, actor): ColormapPublic | null {
|
|
43
|
+
const colormapsVTK = vtkColorMaps.rgbPresetNames.map((presetName) =>
|
|
44
|
+
vtkColorMaps.getPresetByName(presetName)
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
const colormapsCS3D = getColormapNames().map((colormapName) =>
|
|
48
|
+
getColormap(colormapName)
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
const colormaps = colormapsVTK.concat(colormapsCS3D);
|
|
52
|
+
|
|
53
|
+
// Find the colormap that matches the given RGB points
|
|
54
|
+
const matchedColormap = colormaps.find((colormap) => {
|
|
55
|
+
const { RGBPoints: presetRGBPoints } = colormap;
|
|
56
|
+
|
|
57
|
+
if (presetRGBPoints.length !== rgbPoints.length) {
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
for (let i = 0; i < presetRGBPoints.length; i += 4) {
|
|
62
|
+
if (
|
|
63
|
+
!isEqual(
|
|
64
|
+
presetRGBPoints.slice(i + 1, i + 4),
|
|
65
|
+
rgbPoints.slice(i + 1, i + 4)
|
|
66
|
+
)
|
|
67
|
+
) {
|
|
68
|
+
return false;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return true;
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
if (!matchedColormap) {
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const opacity = [];
|
|
80
|
+
if (actorIsA(actor, 'vtkVolume')) {
|
|
81
|
+
const opacityPoints = actor
|
|
82
|
+
.getProperty()
|
|
83
|
+
.getScalarOpacity(0)
|
|
84
|
+
.getDataPointer();
|
|
85
|
+
|
|
86
|
+
if (!opacityPoints) {
|
|
87
|
+
return {
|
|
88
|
+
name: matchedColormap.Name,
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
for (let i = 0; i < opacityPoints.length; i += 2) {
|
|
93
|
+
opacity.push({
|
|
94
|
+
value: opacityPoints[i],
|
|
95
|
+
opacity: opacityPoints[i + 1],
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
return {
|
|
101
|
+
name: matchedColormap.Name,
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export {
|
|
106
|
+
getColormap,
|
|
107
|
+
getColormapNames,
|
|
108
|
+
registerColormap,
|
|
109
|
+
findMatchingColormap,
|
|
110
|
+
};
|