@cornerstonejs/tools 5.4.10 → 5.4.12
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/esm/stateManagement/segmentation/helpers/isSegmentationOverlayCompatible.d.ts +3 -0
- package/dist/esm/stateManagement/segmentation/helpers/isSegmentationOverlayCompatible.js +87 -0
- package/dist/esm/stateManagement/segmentation/internalAddSegmentationRepresentation.js +5 -0
- package/dist/esm/tools/displayTools/Labelmap/syncStackLabelmapActors.js +5 -0
- package/dist/esm/tools/segmentation/BrushTool.js +6 -3
- package/dist/esm/version.d.ts +1 -1
- package/dist/esm/version.js +1 -1
- package/package.json +5 -5
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { type Types } from '@cornerstonejs/core';
|
|
2
|
+
import { SegmentationRepresentations } from '../../../enums/index.js';
|
|
3
|
+
export declare function isSegmentationOverlayCompatible(viewport: Types.IViewport | undefined, segmentationId: string, representationType: SegmentationRepresentations | undefined): boolean;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { cache, metaData } from '@cornerstonejs/core';
|
|
2
|
+
import { SegmentationRepresentations } from '../../../enums/index.js';
|
|
3
|
+
import { getSegmentation } from '../getSegmentation.js';
|
|
4
|
+
import { getLabelmaps } from '../labelmapModel/index.js';
|
|
5
|
+
function getLayerReferencedImageIds(layer) {
|
|
6
|
+
if (layer.referencedImageIds?.length) {
|
|
7
|
+
return layer.referencedImageIds;
|
|
8
|
+
}
|
|
9
|
+
const labelmapImageIds = layer.imageIds ??
|
|
10
|
+
(layer.volumeId
|
|
11
|
+
? cache.getVolume(layer.volumeId)?.imageIds
|
|
12
|
+
: undefined) ??
|
|
13
|
+
[];
|
|
14
|
+
return labelmapImageIds
|
|
15
|
+
.map((labelmapImageId) => cache.getImage(labelmapImageId)?.referencedImageId)
|
|
16
|
+
.filter(Boolean);
|
|
17
|
+
}
|
|
18
|
+
function getLayerFrameOfReferenceUIDs(layer) {
|
|
19
|
+
const frameOfReferenceUIDs = new Set();
|
|
20
|
+
if (layer.volumeId) {
|
|
21
|
+
const volumeFrameOfReference = cache.getVolume(layer.volumeId)?.metadata?.FrameOfReferenceUID;
|
|
22
|
+
if (volumeFrameOfReference) {
|
|
23
|
+
frameOfReferenceUIDs.add(volumeFrameOfReference);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
for (const referencedImageId of getLayerReferencedImageIds(layer)) {
|
|
27
|
+
const imageFrameOfReference = metaData.get('imagePlaneModule', referencedImageId)?.frameOfReferenceUID;
|
|
28
|
+
if (imageFrameOfReference) {
|
|
29
|
+
frameOfReferenceUIDs.add(imageFrameOfReference);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return [...frameOfReferenceUIDs];
|
|
33
|
+
}
|
|
34
|
+
function volumeViewportSharesFrameOfReference(viewport, layers) {
|
|
35
|
+
let viewportFrameOfReference;
|
|
36
|
+
try {
|
|
37
|
+
viewportFrameOfReference = viewport.getFrameOfReferenceUID?.();
|
|
38
|
+
}
|
|
39
|
+
catch (error) {
|
|
40
|
+
return true;
|
|
41
|
+
}
|
|
42
|
+
if (!viewportFrameOfReference) {
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
45
|
+
const labelmapFrameOfReferenceUIDs = layers.flatMap((layer) => getLayerFrameOfReferenceUIDs(layer));
|
|
46
|
+
if (!labelmapFrameOfReferenceUIDs.length) {
|
|
47
|
+
return true;
|
|
48
|
+
}
|
|
49
|
+
return labelmapFrameOfReferenceUIDs.includes(viewportFrameOfReference);
|
|
50
|
+
}
|
|
51
|
+
function stackViewportReferencesImages(viewport, layers) {
|
|
52
|
+
const referencedImageIds = layers.flatMap((layer) => getLayerReferencedImageIds(layer));
|
|
53
|
+
if (!referencedImageIds.length) {
|
|
54
|
+
return true;
|
|
55
|
+
}
|
|
56
|
+
let viewportImageIds;
|
|
57
|
+
try {
|
|
58
|
+
viewportImageIds =
|
|
59
|
+
viewport.getImageIds?.() ?? [];
|
|
60
|
+
}
|
|
61
|
+
catch (error) {
|
|
62
|
+
return true;
|
|
63
|
+
}
|
|
64
|
+
if (!viewportImageIds.length) {
|
|
65
|
+
return true;
|
|
66
|
+
}
|
|
67
|
+
const referencedImageIdSet = new Set(referencedImageIds);
|
|
68
|
+
return viewportImageIds.some((imageId) => referencedImageIdSet.has(imageId));
|
|
69
|
+
}
|
|
70
|
+
export function isSegmentationOverlayCompatible(viewport, segmentationId, representationType) {
|
|
71
|
+
if (representationType !== SegmentationRepresentations.Labelmap) {
|
|
72
|
+
return true;
|
|
73
|
+
}
|
|
74
|
+
if (!viewport) {
|
|
75
|
+
return true;
|
|
76
|
+
}
|
|
77
|
+
const segmentation = getSegmentation(segmentationId);
|
|
78
|
+
if (!segmentation) {
|
|
79
|
+
return true;
|
|
80
|
+
}
|
|
81
|
+
const layers = getLabelmaps(segmentation);
|
|
82
|
+
const isVolumeViewport = typeof viewport
|
|
83
|
+
.getAllVolumeIds === 'function';
|
|
84
|
+
return isVolumeViewport
|
|
85
|
+
? volumeViewportSharesFrameOfReference(viewport, layers)
|
|
86
|
+
: stackViewportReferencesImages(viewport, layers);
|
|
87
|
+
}
|
|
@@ -5,10 +5,15 @@ import { SegmentationRepresentations } from '../../enums/index.js';
|
|
|
5
5
|
import { triggerSegmentationModified, triggerSegmentationDataModified, } from './triggerSegmentationEvents.js';
|
|
6
6
|
import { addColorLUT } from './addColorLUT.js';
|
|
7
7
|
import { defaultSegmentationStateManager } from './SegmentationStateManager.js';
|
|
8
|
+
import { isSegmentationOverlayCompatible } from './helpers/isSegmentationOverlayCompatible.js';
|
|
8
9
|
import { addDefaultSegmentationListener } from './segmentationEventManager.js';
|
|
9
10
|
import { getActiveSegmentIndex, setActiveSegmentIndex } from './segmentIndex.js';
|
|
10
11
|
function internalAddSegmentationRepresentation(viewportId, representationInput) {
|
|
11
12
|
const { segmentationId, config } = representationInput;
|
|
13
|
+
if (!isSegmentationOverlayCompatible(getEnabledElementByViewportId(viewportId)?.viewport, segmentationId, representationInput.type)) {
|
|
14
|
+
console.warn(`Skipping ${representationInput.type} representation of segmentation "${segmentationId}" on viewport "${viewportId}": the viewport is not a compatible destination for it.`);
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
12
17
|
const renderingConfig = {
|
|
13
18
|
colorLUTIndex: getColorLUTIndex(config),
|
|
14
19
|
...config,
|
|
@@ -3,6 +3,8 @@ import vtkImageData from '@kitware/vtk.js/Common/DataModel/ImageData.js';
|
|
|
3
3
|
import vtkPiecewiseFunction from '@kitware/vtk.js/Common/DataModel/PiecewiseFunction.js';
|
|
4
4
|
import { ActorRenderMode, cache, utilities, } from '@cornerstonejs/core';
|
|
5
5
|
import { triggerSegmentationRender } from '../../../stateManagement/segmentation/SegmentationRenderingEngine.js';
|
|
6
|
+
import { isSegmentationOverlayCompatible } from '../../../stateManagement/segmentation/helpers/isSegmentationOverlayCompatible.js';
|
|
7
|
+
import { SegmentationRepresentations } from '../../../enums/index.js';
|
|
6
8
|
import { updateLabelmapSegmentationImageReferences } from '../../../stateManagement/segmentation/updateLabelmapSegmentationImageReferences.js';
|
|
7
9
|
import { getCurrentLabelmapImageIdsForViewport } from '../../../stateManagement/segmentation/getCurrentLabelmapImageIdForViewport.js';
|
|
8
10
|
import { getLabelmapActorEntries } from '../../../stateManagement/segmentation/helpers/getSegmentationActor.js';
|
|
@@ -18,6 +20,9 @@ export function syncStackLabelmapActors(viewport, segmentationId) {
|
|
|
18
20
|
if (!currentImageId) {
|
|
19
21
|
return;
|
|
20
22
|
}
|
|
23
|
+
if (!isSegmentationOverlayCompatible(viewport, segmentationId, SegmentationRepresentations.Labelmap)) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
21
26
|
updateLabelmapSegmentationImageReferences(viewport.id, segmentationId);
|
|
22
27
|
const derivedImageIds = getCurrentLabelmapImageIdsForViewport(viewport.id, segmentationId) ?? [];
|
|
23
28
|
const derivedImageIdSet = new Set(derivedImageIds);
|
|
@@ -111,9 +111,6 @@ class BrushTool extends LabelmapBaseTool {
|
|
|
111
111
|
return false;
|
|
112
112
|
}
|
|
113
113
|
this._editData = this.createEditData(element);
|
|
114
|
-
this._activateDraw(element);
|
|
115
|
-
hideElementCursor(element);
|
|
116
|
-
evt.preventDefault();
|
|
117
114
|
this._previewData.isDrag = false;
|
|
118
115
|
this._previewData.timerStart = Date.now();
|
|
119
116
|
const canvasPoint = vec2.clone(currentPoints.canvas);
|
|
@@ -126,6 +123,9 @@ class BrushTool extends LabelmapBaseTool {
|
|
|
126
123
|
world: vec3.clone(worldPoint),
|
|
127
124
|
};
|
|
128
125
|
this._hoverData = this.createHoverData(element, canvasPoint);
|
|
126
|
+
if (!this._hoverData) {
|
|
127
|
+
return false;
|
|
128
|
+
}
|
|
129
129
|
this._calculateCursor(element, canvasPoint);
|
|
130
130
|
this._resetLazyEditState();
|
|
131
131
|
if (this._isLazyLabelmapEditingEnabled(this._hoverData.viewport)) {
|
|
@@ -137,6 +137,9 @@ class BrushTool extends LabelmapBaseTool {
|
|
|
137
137
|
if (!operationData) {
|
|
138
138
|
return false;
|
|
139
139
|
}
|
|
140
|
+
this._activateDraw(element);
|
|
141
|
+
hideElementCursor(element);
|
|
142
|
+
evt.preventDefault();
|
|
140
143
|
this.applyActiveStrategyCallback(enabledElement, operationData, StrategyCallbacks.OnInteractionStart);
|
|
141
144
|
return true;
|
|
142
145
|
};
|
package/dist/esm/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "5.4.
|
|
1
|
+
export declare const version = "5.4.12";
|
package/dist/esm/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = '5.4.
|
|
1
|
+
export const version = '5.4.12';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cornerstonejs/tools",
|
|
3
|
-
"version": "5.4.
|
|
3
|
+
"version": "5.4.12",
|
|
4
4
|
"description": "Cornerstone3D Tools",
|
|
5
5
|
"types": "./dist/esm/index.d.ts",
|
|
6
6
|
"module": "./dist/esm/index.js",
|
|
@@ -113,7 +113,7 @@
|
|
|
113
113
|
"build": "pnpm run build:esm",
|
|
114
114
|
"clean": "rm -rf node_modules/.cache/storybook && shx rm -rf dist",
|
|
115
115
|
"clean:deep": "pnpm run clean && shx rm -rf node_modules",
|
|
116
|
-
"dev": "tsc --project ./tsconfig.json --watch",
|
|
116
|
+
"dev": "tsc --project ./tsconfig.json --watch --sourceMap --inlineSources",
|
|
117
117
|
"lint": "oxlint .",
|
|
118
118
|
"api-check": "api-extractor --debug run ",
|
|
119
119
|
"prepublishOnly": "pnpm run build",
|
|
@@ -126,11 +126,11 @@
|
|
|
126
126
|
"lodash.get": "4.4.2"
|
|
127
127
|
},
|
|
128
128
|
"devDependencies": {
|
|
129
|
-
"@cornerstonejs/core": "5.4.
|
|
129
|
+
"@cornerstonejs/core": "5.4.12",
|
|
130
130
|
"canvas": "3.2.0"
|
|
131
131
|
},
|
|
132
132
|
"peerDependencies": {
|
|
133
|
-
"@cornerstonejs/core": "5.4.
|
|
133
|
+
"@cornerstonejs/core": "5.4.12",
|
|
134
134
|
"@kitware/vtk.js": "35.5.3",
|
|
135
135
|
"@types/d3-array": "3.2.1",
|
|
136
136
|
"@types/d3-interpolate": "3.0.4",
|
|
@@ -149,5 +149,5 @@
|
|
|
149
149
|
"type": "individual",
|
|
150
150
|
"url": "https://ohif.org/donate"
|
|
151
151
|
},
|
|
152
|
-
"gitHead": "
|
|
152
|
+
"gitHead": "0b67d01ebc033cc338c3612c1237b5d94025cac2"
|
|
153
153
|
}
|