@ohif/extension-cornerstone 3.14.0-beta.120 → 3.14.0-beta.122
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/ohif-extension-cornerstone.umd.js +1 -1
- package/package.json +4 -4
- package/src/commandsModule.ts +148 -0
- package/src/components/ViewportOrientationMenu/Viewport3DCompassMenu.tsx +261 -0
- package/src/components/ViewportOrientationMenu/ViewportOrientationMenuWrapper.tsx +11 -0
- package/src/components/VolumeCroppingMenu/VolumeCroppingMenu.tsx +169 -0
- package/src/customizations/toolbarButtonsCustomization.ts +31 -0
- package/src/getToolbarModule.tsx +41 -0
- package/src/index.tsx +2 -0
- package/src/initCornerstoneTools.js +9 -0
- package/src/utils/getVolumeCroppingToolGroup.test.ts +63 -0
- package/src/utils/getVolumeCroppingToolGroup.ts +53 -0
- package/src/utils/volume3dView.test.ts +48 -0
- package/src/utils/volume3dView.ts +113 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ohif/extension-cornerstone",
|
|
3
|
-
"version": "3.14.0-beta.
|
|
3
|
+
"version": "3.14.0-beta.122",
|
|
4
4
|
"description": "OHIF extension for Cornerstone",
|
|
5
5
|
"author": "OHIF",
|
|
6
6
|
"license": "MIT",
|
|
@@ -36,9 +36,9 @@
|
|
|
36
36
|
"@cornerstonejs/codec-openjpeg": "1.3.2",
|
|
37
37
|
"@cornerstonejs/codec-openjph": "2.4.9",
|
|
38
38
|
"@cornerstonejs/dicom-image-loader": "5.24.0",
|
|
39
|
-
"@ohif/core": "3.14.0-beta.
|
|
40
|
-
"@ohif/extension-default": "3.14.0-beta.
|
|
41
|
-
"@ohif/ui-next": "3.14.0-beta.
|
|
39
|
+
"@ohif/core": "3.14.0-beta.122",
|
|
40
|
+
"@ohif/extension-default": "3.14.0-beta.122",
|
|
41
|
+
"@ohif/ui-next": "3.14.0-beta.122",
|
|
42
42
|
"dcmjs": "0.52.0",
|
|
43
43
|
"dicom-parser": "1.8.21",
|
|
44
44
|
"hammerjs": "2.0.8",
|
package/src/commandsModule.ts
CHANGED
|
@@ -46,12 +46,22 @@ import {
|
|
|
46
46
|
} from './utils/getLegacyViewportType';
|
|
47
47
|
import { viewportOperations as ops } from './services/ViewportService/backends/viewportOperations';
|
|
48
48
|
import { getViewportAdapter } from './services/ViewportService/adapter';
|
|
49
|
+
import {
|
|
50
|
+
rotateVolume3D,
|
|
51
|
+
setVolume3DSpin,
|
|
52
|
+
setVolume3DViewDirection,
|
|
53
|
+
type ViewDirection,
|
|
54
|
+
} from './utils/volume3dView';
|
|
49
55
|
import {
|
|
50
56
|
usePositionPresentationStore,
|
|
51
57
|
useSegmentationPresentationStore,
|
|
52
58
|
useSelectedSegmentationsForViewportStore,
|
|
53
59
|
} from './stores';
|
|
54
60
|
import { toolNames } from './initCornerstoneTools';
|
|
61
|
+
import getVolumeCroppingToolGroup, {
|
|
62
|
+
getVolumeCroppingState,
|
|
63
|
+
setDisjointSegmentationMode,
|
|
64
|
+
} from './utils/getVolumeCroppingToolGroup';
|
|
55
65
|
import CornerstoneViewportDownloadForm from './utils/CornerstoneViewportDownloadForm';
|
|
56
66
|
import { updateSegmentBidirectionalStats } from './utils/updateSegmentationStats';
|
|
57
67
|
import { generateSegmentationCSVReport } from './utils/generateSegmentationCSVReport';
|
|
@@ -184,6 +194,10 @@ function commandsModule({
|
|
|
184
194
|
return toolGroup?.id;
|
|
185
195
|
}
|
|
186
196
|
|
|
197
|
+
function _getVolumeCroppingToolGroup(viewportId?: string) {
|
|
198
|
+
return getVolumeCroppingToolGroup(toolGroupService, viewportId);
|
|
199
|
+
}
|
|
200
|
+
|
|
187
201
|
function _usesPrimaryActivation(bindings) {
|
|
188
202
|
if (!bindings?.length) {
|
|
189
203
|
return true;
|
|
@@ -1223,6 +1237,119 @@ function commandsModule({
|
|
|
1223
1237
|
const renderingEngine = cornerstoneViewportService.getRenderingEngine();
|
|
1224
1238
|
renderingEngine.render();
|
|
1225
1239
|
},
|
|
1240
|
+
/**
|
|
1241
|
+
* Steps the crop tool through its three states: off -> Active -> Passive -> off, or sets
|
|
1242
|
+
* `mode` directly. Active: VolumeCropping owns the primary button (drag a handle to crop,
|
|
1243
|
+
* drag elsewhere to rotate). Passive: the crop box stays, and the previous primary tool
|
|
1244
|
+
* comes back. VolumeCroppingControl shows the same box in the MPR viewports.
|
|
1245
|
+
*/
|
|
1246
|
+
cycleVolumeCropping: ({ mode, viewportId }: { mode?: string; viewportId?: string } = {}) => {
|
|
1247
|
+
const toolGroup = _getVolumeCroppingToolGroup(
|
|
1248
|
+
viewportId ?? viewportGridService.getActiveViewportId()
|
|
1249
|
+
);
|
|
1250
|
+
if (!toolGroup) {
|
|
1251
|
+
return;
|
|
1252
|
+
}
|
|
1253
|
+
const { Active, Passive, Disabled } = Enums.ToolModes;
|
|
1254
|
+
const current = getVolumeCroppingState(toolGroup);
|
|
1255
|
+
const next = mode ?? (current === Active ? Passive : current === Passive ? Disabled : Active);
|
|
1256
|
+
if (next === current) {
|
|
1257
|
+
// A second activation would record VolumeCropping as its own previous primary tool.
|
|
1258
|
+
return;
|
|
1259
|
+
}
|
|
1260
|
+
const tool = toolGroup.getToolInstance(toolNames.VolumeCropping);
|
|
1261
|
+
|
|
1262
|
+
// The crop box is built in onSetToolActive, so Disabled -> Passive activates first.
|
|
1263
|
+
if (next === Active || current === Disabled) {
|
|
1264
|
+
actions.setToolActive({
|
|
1265
|
+
toolName: toolNames.VolumeCropping,
|
|
1266
|
+
toolGroupId: toolGroup.id,
|
|
1267
|
+
bindings: [
|
|
1268
|
+
{ mouseButton: Enums.MouseBindings.Primary },
|
|
1269
|
+
{
|
|
1270
|
+
mouseButton: Enums.MouseBindings.Primary,
|
|
1271
|
+
modifierKey: Enums.KeyboardBindings.Shift,
|
|
1272
|
+
},
|
|
1273
|
+
],
|
|
1274
|
+
});
|
|
1275
|
+
// onSetToolActive hides the box, so show it after activation.
|
|
1276
|
+
tool.setClippingPlanesVisible(true);
|
|
1277
|
+
}
|
|
1278
|
+
if (next !== Active && current !== Passive) {
|
|
1279
|
+
actions.setToolActive({
|
|
1280
|
+
toolName: toolGroup.getPrevActivePrimaryToolName(),
|
|
1281
|
+
toolGroupId: toolGroup.id,
|
|
1282
|
+
});
|
|
1283
|
+
// The SHIFT binding would otherwise keep VolumeCropping in Active mode.
|
|
1284
|
+
toolGroup.setToolPassive(toolNames.VolumeCropping, { removeAllBindings: true });
|
|
1285
|
+
}
|
|
1286
|
+
if (next === Disabled) {
|
|
1287
|
+
tool.setClippingPlanesVisible(false);
|
|
1288
|
+
toolGroup.setToolDisabled(toolNames.VolumeCropping);
|
|
1289
|
+
}
|
|
1290
|
+
|
|
1291
|
+
toolGroupService.getToolGroupIds().forEach(toolGroupId => {
|
|
1292
|
+
const controlGroup = toolGroupService.getToolGroup(toolGroupId);
|
|
1293
|
+
if (!controlGroup?.hasTool(toolNames.VolumeCroppingControl)) {
|
|
1294
|
+
return;
|
|
1295
|
+
}
|
|
1296
|
+
if (next === Disabled) {
|
|
1297
|
+
controlGroup.setToolDisabled(toolNames.VolumeCroppingControl);
|
|
1298
|
+
} else if (current === Disabled) {
|
|
1299
|
+
// Enabled adds the listener that follows the 3D handles; Active adds the box.
|
|
1300
|
+
// No binding: handles of an Active tool drag anyway, and a Primary binding would
|
|
1301
|
+
// overwrite the MPR group's previous primary tool.
|
|
1302
|
+
controlGroup.setToolEnabled(toolNames.VolumeCroppingControl);
|
|
1303
|
+
controlGroup.setToolActive(toolNames.VolumeCroppingControl);
|
|
1304
|
+
}
|
|
1305
|
+
});
|
|
1306
|
+
},
|
|
1307
|
+
/** Shows or hides the drag handles of the crop box. */
|
|
1308
|
+
toggle3Dhandles: ({ viewportId, visible }: { viewportId?: string; visible?: boolean } = {}) => {
|
|
1309
|
+
const tool = _getVolumeCroppingToolGroup(viewportId)?.getToolInstance(
|
|
1310
|
+
toolNames.VolumeCropping
|
|
1311
|
+
);
|
|
1312
|
+
tool?.setHandlesVisible(visible ?? !tool.getHandlesVisible());
|
|
1313
|
+
},
|
|
1314
|
+
/** Makes a plain drag rotate the crop planes, not the camera (SHIFT-drag always does). */
|
|
1315
|
+
togglePlaneRotation: ({
|
|
1316
|
+
viewportId,
|
|
1317
|
+
enabled,
|
|
1318
|
+
}: { viewportId?: string; enabled?: boolean } = {}) => {
|
|
1319
|
+
const tool = _getVolumeCroppingToolGroup(viewportId)?.getToolInstance(
|
|
1320
|
+
toolNames.VolumeCropping
|
|
1321
|
+
);
|
|
1322
|
+
tool?.setRotatePlanesOnDrag(enabled ?? !tool.getRotatePlanesOnDrag());
|
|
1323
|
+
},
|
|
1324
|
+
/** Shows the segmentation only outside the crop box (toggles when `enabled` is undefined). */
|
|
1325
|
+
setVolumeCroppingDisjointMode: ({
|
|
1326
|
+
viewportId,
|
|
1327
|
+
enabled,
|
|
1328
|
+
}: { viewportId?: string; enabled?: boolean } = {}) =>
|
|
1329
|
+
setDisjointSegmentationMode(_getVolumeCroppingToolGroup(viewportId), enabled),
|
|
1330
|
+
/** Looks at a volume3d viewport from an anatomical direction (S, I, R, L, A, P). */
|
|
1331
|
+
setViewport3DViewDirection: ({
|
|
1332
|
+
viewportId,
|
|
1333
|
+
direction,
|
|
1334
|
+
}: {
|
|
1335
|
+
viewportId: string;
|
|
1336
|
+
direction: ViewDirection;
|
|
1337
|
+
}) => {
|
|
1338
|
+
setVolume3DViewDirection(
|
|
1339
|
+
cornerstoneViewportService.getCornerstoneViewport(viewportId),
|
|
1340
|
+
direction
|
|
1341
|
+
);
|
|
1342
|
+
},
|
|
1343
|
+
/** Orbits a volume3d viewport camera by `angle` degrees about the patient superior axis. */
|
|
1344
|
+
rotateViewport3DBy: ({ viewportId, angle }: { viewportId: string; angle: number }) => {
|
|
1345
|
+
rotateVolume3D(cornerstoneViewportService.getCornerstoneViewport(viewportId), angle);
|
|
1346
|
+
},
|
|
1347
|
+
/** Spins a volume3d viewport continuously; `speed` 0 stops it, a negative value reverses it. */
|
|
1348
|
+
setViewport3DSpin: ({ viewportId, speed }: { viewportId: string; speed: number }) => {
|
|
1349
|
+
setVolume3DSpin(viewportId, speed, id =>
|
|
1350
|
+
cornerstoneViewportService.getCornerstoneViewport(id)
|
|
1351
|
+
);
|
|
1352
|
+
},
|
|
1226
1353
|
toggleEnabledDisabledToolbar({ value, itemId, toolGroupId }) {
|
|
1227
1354
|
const toolName = itemId || value;
|
|
1228
1355
|
toolGroupId = toolGroupId ?? _getActiveViewportToolGroupId();
|
|
@@ -2819,6 +2946,27 @@ function commandsModule({
|
|
|
2819
2946
|
updateVolumeData: {
|
|
2820
2947
|
commandFn: actions.updateVolumeData,
|
|
2821
2948
|
},
|
|
2949
|
+
cycleVolumeCropping: {
|
|
2950
|
+
commandFn: actions.cycleVolumeCropping,
|
|
2951
|
+
},
|
|
2952
|
+
toggle3Dhandles: {
|
|
2953
|
+
commandFn: actions.toggle3Dhandles,
|
|
2954
|
+
},
|
|
2955
|
+
togglePlaneRotation: {
|
|
2956
|
+
commandFn: actions.togglePlaneRotation,
|
|
2957
|
+
},
|
|
2958
|
+
setVolumeCroppingDisjointMode: {
|
|
2959
|
+
commandFn: actions.setVolumeCroppingDisjointMode,
|
|
2960
|
+
},
|
|
2961
|
+
setViewport3DViewDirection: {
|
|
2962
|
+
commandFn: actions.setViewport3DViewDirection,
|
|
2963
|
+
},
|
|
2964
|
+
rotateViewport3DBy: {
|
|
2965
|
+
commandFn: actions.rotateViewport3DBy,
|
|
2966
|
+
},
|
|
2967
|
+
setViewport3DSpin: {
|
|
2968
|
+
commandFn: actions.setViewport3DSpin,
|
|
2969
|
+
},
|
|
2822
2970
|
toggleEnabledDisabledToolbar: {
|
|
2823
2971
|
commandFn: actions.toggleEnabledDisabledToolbar,
|
|
2824
2972
|
},
|
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
import React, { useRef, useState } from 'react';
|
|
2
|
+
import { useSystem } from '@ohif/core';
|
|
3
|
+
import {
|
|
4
|
+
Button,
|
|
5
|
+
Icons,
|
|
6
|
+
Popover,
|
|
7
|
+
PopoverContent,
|
|
8
|
+
PopoverTrigger,
|
|
9
|
+
useIconPresentation,
|
|
10
|
+
} from '@ohif/ui-next';
|
|
11
|
+
import { getVolume3DSpin, type ViewDirection } from '../../utils/volume3dView';
|
|
12
|
+
|
|
13
|
+
const CENTER = 50;
|
|
14
|
+
const LINE_RADIUS = 30;
|
|
15
|
+
const LABEL_RADIUS = 42;
|
|
16
|
+
|
|
17
|
+
// Screen angle of each label; P-A is drawn as a diagonal to suggest depth.
|
|
18
|
+
const DIRECTIONS: { direction: ViewDirection; angle: number }[] = [
|
|
19
|
+
{ direction: 'S', angle: -90 },
|
|
20
|
+
{ direction: 'I', angle: 90 },
|
|
21
|
+
{ direction: 'R', angle: 180 },
|
|
22
|
+
{ direction: 'L', angle: 0 },
|
|
23
|
+
{ direction: 'P', angle: 225 },
|
|
24
|
+
{ direction: 'A', angle: 45 },
|
|
25
|
+
];
|
|
26
|
+
const AXIS_ANGLES = [180, -90, 225];
|
|
27
|
+
|
|
28
|
+
const toXY = (angleDegrees: number, radius: number) => {
|
|
29
|
+
const radians = (angleDegrees * Math.PI) / 180;
|
|
30
|
+
return { x: CENTER + radius * Math.cos(radians), y: CENTER + radius * Math.sin(radians) };
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Orientation menu of a volume3d viewport, in the style of the 3D Slicer view controller:
|
|
35
|
+
* click S, I, R, L, A or P to look from that side, and set a continuous spin speed.
|
|
36
|
+
*/
|
|
37
|
+
function Viewport3DCompassMenu({
|
|
38
|
+
location,
|
|
39
|
+
viewportId,
|
|
40
|
+
isOpen = false,
|
|
41
|
+
onOpen,
|
|
42
|
+
onClose,
|
|
43
|
+
disabled,
|
|
44
|
+
...props
|
|
45
|
+
}: withAppTypes<{
|
|
46
|
+
location?: string;
|
|
47
|
+
viewportId: string;
|
|
48
|
+
isOpen?: boolean;
|
|
49
|
+
onOpen?: () => void;
|
|
50
|
+
onClose?: () => void;
|
|
51
|
+
disabled?: boolean;
|
|
52
|
+
}>) {
|
|
53
|
+
const { servicesManager, commandsManager } = useSystem();
|
|
54
|
+
const { toolbarService } = servicesManager.services;
|
|
55
|
+
const { IconContainer, className: iconClassName, containerProps } = useIconPresentation();
|
|
56
|
+
const [spin, setSpin] = useState(0);
|
|
57
|
+
const triggerRef = useRef<HTMLDivElement>(null);
|
|
58
|
+
const interactedOutsideRef = useRef(false);
|
|
59
|
+
|
|
60
|
+
const changeSpin = (speed: number) => {
|
|
61
|
+
commandsManager.runCommand('setViewport3DSpin', { viewportId, speed });
|
|
62
|
+
setSpin(speed);
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
const lookFrom = (direction: ViewDirection) =>
|
|
66
|
+
commandsManager.runCommand('setViewport3DViewDirection', { viewportId, direction });
|
|
67
|
+
|
|
68
|
+
const handleOpenChange = (openState: boolean) => {
|
|
69
|
+
if (openState) {
|
|
70
|
+
// The spin can stop without this menu, for example when the viewport changes.
|
|
71
|
+
setSpin(getVolume3DSpin(viewportId));
|
|
72
|
+
onOpen?.();
|
|
73
|
+
} else {
|
|
74
|
+
onClose?.();
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
const { align, side } = toolbarService.getAlignAndSide(Number(location));
|
|
79
|
+
const Icon = <Icons.OrientationSwitch className={iconClassName} />;
|
|
80
|
+
const gradientId = `compass-sphere-${viewportId}`;
|
|
81
|
+
|
|
82
|
+
return (
|
|
83
|
+
<Popover
|
|
84
|
+
open={isOpen}
|
|
85
|
+
onOpenChange={handleOpenChange}
|
|
86
|
+
>
|
|
87
|
+
<PopoverTrigger
|
|
88
|
+
asChild
|
|
89
|
+
className="flex items-center justify-center"
|
|
90
|
+
>
|
|
91
|
+
<div ref={triggerRef}>
|
|
92
|
+
{IconContainer ? (
|
|
93
|
+
<IconContainer
|
|
94
|
+
disabled={disabled}
|
|
95
|
+
icon="OrientationSwitch"
|
|
96
|
+
label="3D orientation"
|
|
97
|
+
{...props}
|
|
98
|
+
{...containerProps}
|
|
99
|
+
>
|
|
100
|
+
{Icon}
|
|
101
|
+
</IconContainer>
|
|
102
|
+
) : (
|
|
103
|
+
<Button
|
|
104
|
+
variant="ghost"
|
|
105
|
+
size="icon"
|
|
106
|
+
disabled={disabled}
|
|
107
|
+
aria-label="3D orientation"
|
|
108
|
+
>
|
|
109
|
+
{Icon}
|
|
110
|
+
</Button>
|
|
111
|
+
)}
|
|
112
|
+
</div>
|
|
113
|
+
</PopoverTrigger>
|
|
114
|
+
<PopoverContent
|
|
115
|
+
onInteractOutside={() => {
|
|
116
|
+
interactedOutsideRef.current = true;
|
|
117
|
+
}}
|
|
118
|
+
// The trigger is a wrapper div that cannot take focus; return focus to its button,
|
|
119
|
+
// except after a click outside, where the focus stays where the user put it.
|
|
120
|
+
onCloseAutoFocus={event => {
|
|
121
|
+
event.preventDefault();
|
|
122
|
+
if (!interactedOutsideRef.current) {
|
|
123
|
+
triggerRef.current?.querySelector('button')?.focus();
|
|
124
|
+
}
|
|
125
|
+
interactedOutsideRef.current = false;
|
|
126
|
+
}}
|
|
127
|
+
className="w-auto flex-shrink-0 rounded-lg border-0 bg-neutral-800 p-1 shadow-none"
|
|
128
|
+
align={align}
|
|
129
|
+
side={side}
|
|
130
|
+
style={{ left: 0 }}
|
|
131
|
+
>
|
|
132
|
+
<svg
|
|
133
|
+
viewBox="0 0 100 100"
|
|
134
|
+
className="h-36 w-36"
|
|
135
|
+
role="group"
|
|
136
|
+
aria-label="View direction"
|
|
137
|
+
>
|
|
138
|
+
<defs>
|
|
139
|
+
<radialGradient
|
|
140
|
+
id={gradientId}
|
|
141
|
+
cx="35%"
|
|
142
|
+
cy="35%"
|
|
143
|
+
r="65%"
|
|
144
|
+
fx="35%"
|
|
145
|
+
fy="35%"
|
|
146
|
+
>
|
|
147
|
+
<stop
|
|
148
|
+
offset="0%"
|
|
149
|
+
stopColor="hsl(var(--secondary-foreground))"
|
|
150
|
+
stopOpacity="0.9"
|
|
151
|
+
/>
|
|
152
|
+
<stop
|
|
153
|
+
offset="45%"
|
|
154
|
+
stopColor="hsl(var(--secondary))"
|
|
155
|
+
stopOpacity="1"
|
|
156
|
+
/>
|
|
157
|
+
<stop
|
|
158
|
+
offset="100%"
|
|
159
|
+
stopColor="hsl(var(--secondary))"
|
|
160
|
+
stopOpacity="0.55"
|
|
161
|
+
/>
|
|
162
|
+
</radialGradient>
|
|
163
|
+
</defs>
|
|
164
|
+
{AXIS_ANGLES.map(angle => {
|
|
165
|
+
const start = toXY(angle, LINE_RADIUS);
|
|
166
|
+
const end = toXY(angle + 180, LINE_RADIUS);
|
|
167
|
+
return (
|
|
168
|
+
<line
|
|
169
|
+
key={angle}
|
|
170
|
+
x1={start.x}
|
|
171
|
+
y1={start.y}
|
|
172
|
+
x2={end.x}
|
|
173
|
+
y2={end.y}
|
|
174
|
+
stroke="white"
|
|
175
|
+
strokeWidth="1.2"
|
|
176
|
+
/>
|
|
177
|
+
);
|
|
178
|
+
})}
|
|
179
|
+
<circle
|
|
180
|
+
cx={CENTER}
|
|
181
|
+
cy={CENTER}
|
|
182
|
+
r={5}
|
|
183
|
+
fill={`url(#${gradientId})`}
|
|
184
|
+
className="drop-shadow-[0_0_6px_hsl(var(--secondary)/0.7)]"
|
|
185
|
+
/>
|
|
186
|
+
{DIRECTIONS.map(({ direction, angle }) => {
|
|
187
|
+
const { x, y } = toXY(angle, LABEL_RADIUS);
|
|
188
|
+
return (
|
|
189
|
+
<g
|
|
190
|
+
key={direction}
|
|
191
|
+
className="group cursor-pointer select-none outline-none"
|
|
192
|
+
onClick={() => lookFrom(direction)}
|
|
193
|
+
onKeyDown={event => {
|
|
194
|
+
if (event.key === 'Enter' || event.key === ' ') {
|
|
195
|
+
event.preventDefault();
|
|
196
|
+
lookFrom(direction);
|
|
197
|
+
}
|
|
198
|
+
}}
|
|
199
|
+
role="button"
|
|
200
|
+
tabIndex={0}
|
|
201
|
+
aria-label={`View from ${direction}`}
|
|
202
|
+
>
|
|
203
|
+
<circle
|
|
204
|
+
cx={x}
|
|
205
|
+
cy={y}
|
|
206
|
+
r={10}
|
|
207
|
+
fill="transparent"
|
|
208
|
+
className="group-focus-visible:stroke-white"
|
|
209
|
+
/>
|
|
210
|
+
<text
|
|
211
|
+
x={x}
|
|
212
|
+
y={y}
|
|
213
|
+
textAnchor="middle"
|
|
214
|
+
dominantBaseline="central"
|
|
215
|
+
fill="white"
|
|
216
|
+
fontSize="11"
|
|
217
|
+
fontWeight="600"
|
|
218
|
+
fontFamily="sans-serif"
|
|
219
|
+
className="pointer-events-none"
|
|
220
|
+
>
|
|
221
|
+
{direction}
|
|
222
|
+
</text>
|
|
223
|
+
</g>
|
|
224
|
+
);
|
|
225
|
+
})}
|
|
226
|
+
</svg>
|
|
227
|
+
<div className="mt-2 flex items-center justify-center">
|
|
228
|
+
<button
|
|
229
|
+
type="button"
|
|
230
|
+
className="mr-2 cursor-pointer text-lg text-neutral-400 outline-none hover:text-neutral-200 focus:text-neutral-200"
|
|
231
|
+
onClick={() => changeSpin(spin === 0 ? 1 : 0)}
|
|
232
|
+
aria-label={spin === 0 ? 'Start spin' : 'Stop spin'}
|
|
233
|
+
>
|
|
234
|
+
Spin
|
|
235
|
+
</button>
|
|
236
|
+
<Button
|
|
237
|
+
variant="ghost"
|
|
238
|
+
size="icon"
|
|
239
|
+
className="h-7 w-7"
|
|
240
|
+
onClick={() => changeSpin(spin - 1)}
|
|
241
|
+
aria-label="Decrease spin"
|
|
242
|
+
>
|
|
243
|
+
<Icons.ChevronLeft className="h-4 w-4" />
|
|
244
|
+
</Button>
|
|
245
|
+
<span className="min-w-[1.75rem] text-center font-mono text-sm font-medium">{spin}</span>
|
|
246
|
+
<Button
|
|
247
|
+
variant="ghost"
|
|
248
|
+
size="icon"
|
|
249
|
+
className="h-7 w-7"
|
|
250
|
+
onClick={() => changeSpin(spin + 1)}
|
|
251
|
+
aria-label="Increase spin"
|
|
252
|
+
>
|
|
253
|
+
<Icons.ChevronRight className="h-4 w-4" />
|
|
254
|
+
</Button>
|
|
255
|
+
</div>
|
|
256
|
+
</PopoverContent>
|
|
257
|
+
</Popover>
|
|
258
|
+
);
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
export default Viewport3DCompassMenu;
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import React, { ReactNode } from 'react';
|
|
2
|
+
import { useSystem } from '@ohif/core';
|
|
2
3
|
import ViewportOrientationMenu from './ViewportOrientationMenu';
|
|
4
|
+
import Viewport3DCompassMenu from './Viewport3DCompassMenu';
|
|
3
5
|
import { useViewportDisplaySets } from '../../hooks/useViewportDisplaySets';
|
|
6
|
+
import { getViewportAdapter } from '../../services/ViewportService/adapter';
|
|
4
7
|
|
|
5
8
|
export function ViewportOrientationMenuWrapper(
|
|
6
9
|
props: withAppTypes<{
|
|
@@ -15,11 +18,19 @@ export function ViewportOrientationMenuWrapper(
|
|
|
15
18
|
): ReactNode {
|
|
16
19
|
const { viewportId } = props;
|
|
17
20
|
const { viewportDisplaySets } = useViewportDisplaySets(viewportId);
|
|
21
|
+
const { servicesManager } = useSystem();
|
|
18
22
|
|
|
19
23
|
if (!viewportDisplaySets.length) {
|
|
20
24
|
return null;
|
|
21
25
|
}
|
|
22
26
|
|
|
27
|
+
const viewport = servicesManager.services.cornerstoneViewportService.getCornerstoneViewport(
|
|
28
|
+
viewportId
|
|
29
|
+
);
|
|
30
|
+
if (viewport && getViewportAdapter(viewport).getShape() === 'volume3d') {
|
|
31
|
+
return <Viewport3DCompassMenu {...props} />;
|
|
32
|
+
}
|
|
33
|
+
|
|
23
34
|
return (
|
|
24
35
|
<ViewportOrientationMenu
|
|
25
36
|
{...props}
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import React, { useState } from 'react';
|
|
2
|
+
import { useSystem } from '@ohif/core';
|
|
3
|
+
import {
|
|
4
|
+
Button,
|
|
5
|
+
Icons,
|
|
6
|
+
Popover,
|
|
7
|
+
PopoverContent,
|
|
8
|
+
PopoverTrigger,
|
|
9
|
+
Switch,
|
|
10
|
+
useIconPresentation,
|
|
11
|
+
} from '@ohif/ui-next';
|
|
12
|
+
import i18n from 'i18next';
|
|
13
|
+
import { Enums } from '@cornerstonejs/tools';
|
|
14
|
+
import { toolNames } from '../../initCornerstoneTools';
|
|
15
|
+
import { getVolumeCroppingState } from '../../utils/getVolumeCroppingToolGroup';
|
|
16
|
+
|
|
17
|
+
type CroppingState = { handles: boolean; rotatePlanes: boolean; disjoint: boolean };
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Viewport corner menu for the VolumeCropping tool of a volume3d viewport, shown while
|
|
21
|
+
* the crop box is on: the drag handles, whether a plain drag rotates the crop planes, and
|
|
22
|
+
* whether the segmentation shows only outside the crop box.
|
|
23
|
+
* The VolumeCropping toolbar button turns the crop box on and off.
|
|
24
|
+
*/
|
|
25
|
+
function VolumeCroppingMenu({
|
|
26
|
+
viewportId,
|
|
27
|
+
location,
|
|
28
|
+
isOpen = false,
|
|
29
|
+
onOpen,
|
|
30
|
+
onClose,
|
|
31
|
+
disabled,
|
|
32
|
+
...props
|
|
33
|
+
}: withAppTypes<{
|
|
34
|
+
viewportId: string;
|
|
35
|
+
location?: string;
|
|
36
|
+
isOpen?: boolean;
|
|
37
|
+
onOpen?: () => void;
|
|
38
|
+
onClose?: () => void;
|
|
39
|
+
disabled?: boolean;
|
|
40
|
+
}>) {
|
|
41
|
+
const { servicesManager, commandsManager } = useSystem();
|
|
42
|
+
const { toolGroupService, toolbarService } = servicesManager.services;
|
|
43
|
+
const { IconContainer, className: iconClassName, containerProps } = useIconPresentation();
|
|
44
|
+
const [state, setState] = useState<CroppingState>({
|
|
45
|
+
handles: false,
|
|
46
|
+
rotatePlanes: false,
|
|
47
|
+
disjoint: false,
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
// The tool owns this state, and hotkeys or other code can change it, so read it on open.
|
|
51
|
+
const readState = () => {
|
|
52
|
+
const tool = toolGroupService
|
|
53
|
+
.getToolGroupForViewport(viewportId)
|
|
54
|
+
?.getToolInstance(toolNames.VolumeCropping);
|
|
55
|
+
setState({
|
|
56
|
+
handles: !!tool?.getHandlesVisible(),
|
|
57
|
+
rotatePlanes: !!tool?.getRotatePlanesOnDrag(),
|
|
58
|
+
disjoint: !!tool?.getDisjointSegmentation?.(),
|
|
59
|
+
});
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
const run = (commandName: string, options: Record<string, unknown>) => {
|
|
63
|
+
commandsManager.runCommand(commandName, { viewportId, ...options });
|
|
64
|
+
readState();
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
const handleOpenChange = (openState: boolean) => {
|
|
68
|
+
if (openState) {
|
|
69
|
+
readState();
|
|
70
|
+
onOpen?.();
|
|
71
|
+
} else {
|
|
72
|
+
onClose?.();
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
// Toolbar state is evaluated for the active viewport only, so check this viewport too.
|
|
77
|
+
const toolGroup = toolGroupService.getToolGroupForViewport(viewportId);
|
|
78
|
+
if (
|
|
79
|
+
!toolGroup?.hasTool(toolNames.VolumeCropping) ||
|
|
80
|
+
getVolumeCroppingState(toolGroup) === Enums.ToolModes.Disabled
|
|
81
|
+
) {
|
|
82
|
+
return null;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const { align, side } = toolbarService.getAlignAndSide(Number(location));
|
|
86
|
+
const Icon = <Icons.Crop className={iconClassName} />;
|
|
87
|
+
const ariaLabel = i18n.t('Buttons:Volume Cropping');
|
|
88
|
+
|
|
89
|
+
const rows = [
|
|
90
|
+
{
|
|
91
|
+
label: i18n.t('Buttons:Show handles'),
|
|
92
|
+
tooltip: i18n.t('Buttons:Show the drag handles of the crop box'),
|
|
93
|
+
checked: state.handles,
|
|
94
|
+
onChange: (visible: boolean) => run('toggle3Dhandles', { visible }),
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
label: i18n.t('Buttons:Rotate planes on drag'),
|
|
98
|
+
tooltip: i18n.t(
|
|
99
|
+
'Buttons:While the crop tool is active, a drag rotates the crop planes, not the camera'
|
|
100
|
+
),
|
|
101
|
+
checked: state.rotatePlanes,
|
|
102
|
+
onChange: (enabled: boolean) => run('togglePlaneRotation', { enabled }),
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
label: i18n.t('Buttons:Segmentation outside the crop box'),
|
|
106
|
+
tooltip: i18n.t(
|
|
107
|
+
'Buttons:Show the segmentation only outside the crop box. When off, the crop box also crops the segmentation'
|
|
108
|
+
),
|
|
109
|
+
checked: state.disjoint,
|
|
110
|
+
onChange: (enabled: boolean) => run('setVolumeCroppingDisjointMode', { enabled }),
|
|
111
|
+
},
|
|
112
|
+
];
|
|
113
|
+
|
|
114
|
+
return (
|
|
115
|
+
<Popover
|
|
116
|
+
open={isOpen}
|
|
117
|
+
onOpenChange={handleOpenChange}
|
|
118
|
+
>
|
|
119
|
+
<PopoverTrigger
|
|
120
|
+
asChild
|
|
121
|
+
className="flex items-center justify-center"
|
|
122
|
+
>
|
|
123
|
+
<div>
|
|
124
|
+
{IconContainer ? (
|
|
125
|
+
<IconContainer
|
|
126
|
+
disabled={disabled}
|
|
127
|
+
icon="Crop"
|
|
128
|
+
aria-label={ariaLabel}
|
|
129
|
+
{...props}
|
|
130
|
+
{...containerProps}
|
|
131
|
+
>
|
|
132
|
+
{Icon}
|
|
133
|
+
</IconContainer>
|
|
134
|
+
) : (
|
|
135
|
+
<Button
|
|
136
|
+
variant="ghost"
|
|
137
|
+
size="icon"
|
|
138
|
+
disabled={disabled}
|
|
139
|
+
aria-label={ariaLabel}
|
|
140
|
+
>
|
|
141
|
+
{Icon}
|
|
142
|
+
</Button>
|
|
143
|
+
)}
|
|
144
|
+
</div>
|
|
145
|
+
</PopoverTrigger>
|
|
146
|
+
<PopoverContent
|
|
147
|
+
className="flex w-[240px] flex-col gap-2 rounded p-2"
|
|
148
|
+
align={align}
|
|
149
|
+
side={side}
|
|
150
|
+
>
|
|
151
|
+
{rows.map(row => (
|
|
152
|
+
<label
|
|
153
|
+
key={row.label}
|
|
154
|
+
title={row.tooltip}
|
|
155
|
+
className="flex items-center justify-between text-sm"
|
|
156
|
+
>
|
|
157
|
+
{row.label}
|
|
158
|
+
<Switch
|
|
159
|
+
checked={row.checked}
|
|
160
|
+
onCheckedChange={row.onChange}
|
|
161
|
+
/>
|
|
162
|
+
</label>
|
|
163
|
+
))}
|
|
164
|
+
</PopoverContent>
|
|
165
|
+
</Popover>
|
|
166
|
+
);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
export default VolumeCroppingMenu;
|