@ohif/extension-cornerstone 3.14.0-beta.106 → 3.14.0-beta.107
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 +13 -13
- package/src/components/FidelityIndicator/FidelityIndicator.tsx +152 -0
- package/src/components/FidelityIndicator/index.ts +1 -0
- package/src/components/OHIFViewportActionCorners.tsx +59 -44
- package/src/components/index.ts +1 -0
- package/src/hooks/index.ts +1 -0
- package/src/hooks/useViewportFidelity.ts +243 -0
- package/src/init.tsx +3 -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.107",
|
|
4
4
|
"description": "OHIF extension for Cornerstone",
|
|
5
5
|
"author": "OHIF",
|
|
6
6
|
"license": "MIT",
|
|
@@ -35,10 +35,10 @@
|
|
|
35
35
|
"@cornerstonejs/codec-libjpeg-turbo-8bit": "1.2.4",
|
|
36
36
|
"@cornerstonejs/codec-openjpeg": "1.3.2",
|
|
37
37
|
"@cornerstonejs/codec-openjph": "2.4.9",
|
|
38
|
-
"@cornerstonejs/dicom-image-loader": "5.
|
|
39
|
-
"@ohif/core": "3.14.0-beta.
|
|
40
|
-
"@ohif/extension-default": "3.14.0-beta.
|
|
41
|
-
"@ohif/ui-next": "3.14.0-beta.
|
|
38
|
+
"@cornerstonejs/dicom-image-loader": "5.19.7",
|
|
39
|
+
"@ohif/core": "3.14.0-beta.107",
|
|
40
|
+
"@ohif/extension-default": "3.14.0-beta.107",
|
|
41
|
+
"@ohif/ui-next": "3.14.0-beta.107",
|
|
42
42
|
"dcmjs": "0.52.0",
|
|
43
43
|
"dicom-parser": "1.8.21",
|
|
44
44
|
"hammerjs": "2.0.8",
|
|
@@ -47,14 +47,14 @@
|
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
49
|
"@babel/runtime": "7.29.7",
|
|
50
|
-
"@cornerstonejs/adapters": "5.
|
|
51
|
-
"@cornerstonejs/ai": "5.
|
|
52
|
-
"@cornerstonejs/core": "5.
|
|
53
|
-
"@cornerstonejs/labelmap-interpolation": "5.
|
|
54
|
-
"@cornerstonejs/metadata": "5.
|
|
55
|
-
"@cornerstonejs/polymorphic-segmentation": "5.
|
|
56
|
-
"@cornerstonejs/tools": "5.
|
|
57
|
-
"@cornerstonejs/utils": "5.
|
|
50
|
+
"@cornerstonejs/adapters": "5.19.7",
|
|
51
|
+
"@cornerstonejs/ai": "5.19.7",
|
|
52
|
+
"@cornerstonejs/core": "5.19.7",
|
|
53
|
+
"@cornerstonejs/labelmap-interpolation": "5.19.7",
|
|
54
|
+
"@cornerstonejs/metadata": "5.19.7",
|
|
55
|
+
"@cornerstonejs/polymorphic-segmentation": "5.19.7",
|
|
56
|
+
"@cornerstonejs/tools": "5.19.7",
|
|
57
|
+
"@cornerstonejs/utils": "5.19.7",
|
|
58
58
|
"@icr/polyseg-wasm": "0.4.0",
|
|
59
59
|
"@itk-wasm/morphological-contour-interpolation": "1.1.0",
|
|
60
60
|
"@kitware/vtk.js": "36.4.1",
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import classNames from 'classnames';
|
|
3
|
+
import { useTranslation } from 'react-i18next';
|
|
4
|
+
import { Icons, Tooltip, TooltipTrigger, TooltipContent } from '@ohif/ui-next';
|
|
5
|
+
import { useViewportFidelity, type FidelityPresentation } from '../../hooks/useViewportFidelity';
|
|
6
|
+
import type { Types } from '@cornerstonejs/core';
|
|
7
|
+
|
|
8
|
+
function labelKeyOf(presentation: FidelityPresentation): string | null {
|
|
9
|
+
if (presentation === 'transient') {
|
|
10
|
+
return 'TransientLowFidelity';
|
|
11
|
+
}
|
|
12
|
+
if (presentation === 'standing') {
|
|
13
|
+
return 'LowFidelity';
|
|
14
|
+
}
|
|
15
|
+
if (presentation === 'recovered') {
|
|
16
|
+
return 'FullFidelity';
|
|
17
|
+
}
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function ariaKeyOf(presentation: FidelityPresentation): string {
|
|
22
|
+
if (presentation === 'transient') {
|
|
23
|
+
return 'AriaTransient';
|
|
24
|
+
}
|
|
25
|
+
if (presentation === 'standing') {
|
|
26
|
+
return 'AriaStanding';
|
|
27
|
+
}
|
|
28
|
+
if (presentation === 'recovered') {
|
|
29
|
+
return 'AriaRecovered';
|
|
30
|
+
}
|
|
31
|
+
return 'AriaIdle';
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function causeSummary(
|
|
35
|
+
state: Types.ViewportFidelityState | null,
|
|
36
|
+
t: (key: string) => string
|
|
37
|
+
): string | null {
|
|
38
|
+
if (!state?.cause) {
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
const known: Record<string, string> = {
|
|
42
|
+
deviceTextureLimit: t('CauseDeviceLimit'),
|
|
43
|
+
memoryBudget: t('CauseMemoryBudget'),
|
|
44
|
+
performanceTarget: t('CausePerformance'),
|
|
45
|
+
incompleteLoad: t('CauseIncompleteLoad'),
|
|
46
|
+
missingFrames: t('CauseMissingFrames'),
|
|
47
|
+
lossyDecode: t('CauseLossyDecode'),
|
|
48
|
+
displayIssue: t('CauseDisplayIssue'),
|
|
49
|
+
};
|
|
50
|
+
return known[state.cause] ?? t('CauseUnknown');
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** `icon`: glyph only (default). `text`: label only. `both`: glyph and label. */
|
|
54
|
+
export type FidelityIndicatorDisplay = 'icon' | 'text' | 'both';
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Per-viewport fidelity indicator for OHIF (#6256 / VF-VIS), rendered last in the
|
|
58
|
+
* top-right viewport action corner.
|
|
59
|
+
* Consumes Cornerstone3D `VIEWPORT_FIDELITY_CHANGED` / `getFidelityState()`.
|
|
60
|
+
* Glyph is a fixed yellow warning triangle; transient vs standing is carried by
|
|
61
|
+
* label / aria / tooltip. No customization sets `display` yet; that comes with
|
|
62
|
+
* `Replaceable` (OHIF/Viewers#6452).
|
|
63
|
+
*/
|
|
64
|
+
function FidelityIndicator({
|
|
65
|
+
viewportId,
|
|
66
|
+
display = 'icon',
|
|
67
|
+
}: {
|
|
68
|
+
viewportId: string;
|
|
69
|
+
display?: FidelityIndicatorDisplay;
|
|
70
|
+
}) {
|
|
71
|
+
const { t } = useTranslation('FidelityIndicator');
|
|
72
|
+
const { presentation, wasLossy, state, revealRecovered, hideRecoveredReveal } =
|
|
73
|
+
useViewportFidelity({ viewportId });
|
|
74
|
+
|
|
75
|
+
const idleRevealer = presentation === 'none' && wasLossy;
|
|
76
|
+
const showIcon = display === 'icon' || display === 'both';
|
|
77
|
+
const showText = display === 'text' || display === 'both';
|
|
78
|
+
// Yellow triangle while lossy; green check for the recovered hold and its hover reveal.
|
|
79
|
+
const showWarningGlyph =
|
|
80
|
+
showIcon && (presentation === 'transient' || presentation === 'standing');
|
|
81
|
+
const showRecoveredGlyph = showIcon && presentation === 'recovered';
|
|
82
|
+
|
|
83
|
+
if (presentation === 'none' && !idleRevealer) {
|
|
84
|
+
return null;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// text-only mode: nothing to show while idle (no invisible icon hit target needed for text)
|
|
88
|
+
if (presentation === 'none' && idleRevealer && display === 'text') {
|
|
89
|
+
return null;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const labelKey = labelKeyOf(presentation);
|
|
93
|
+
const cause = causeSummary(state, t);
|
|
94
|
+
const ariaPresentation = presentation === 'none' ? 'recovered' : presentation;
|
|
95
|
+
const isIdle = presentation === 'none' && idleRevealer;
|
|
96
|
+
|
|
97
|
+
return (
|
|
98
|
+
<Tooltip>
|
|
99
|
+
<TooltipTrigger asChild>
|
|
100
|
+
<button
|
|
101
|
+
type="button"
|
|
102
|
+
data-cy="fidelity-indicator"
|
|
103
|
+
className={classNames('inline-flex cursor-default items-center gap-1.5 leading-none', {
|
|
104
|
+
// Invisible hover target after the recovered hold (VF-VIS-1d).
|
|
105
|
+
'h-3 w-3 opacity-0': isIdle,
|
|
106
|
+
})}
|
|
107
|
+
aria-label={t(ariaKeyOf(ariaPresentation))}
|
|
108
|
+
onMouseEnter={revealRecovered}
|
|
109
|
+
onMouseLeave={hideRecoveredReveal}
|
|
110
|
+
onFocus={revealRecovered}
|
|
111
|
+
onBlur={hideRecoveredReveal}
|
|
112
|
+
>
|
|
113
|
+
{showWarningGlyph ? (
|
|
114
|
+
<Icons.StatusWarning
|
|
115
|
+
className="h-6 w-6 shrink-0"
|
|
116
|
+
aria-hidden="true"
|
|
117
|
+
/>
|
|
118
|
+
) : null}
|
|
119
|
+
{showRecoveredGlyph ? (
|
|
120
|
+
<Icons.StatusSuccess
|
|
121
|
+
className="h-6 w-6 shrink-0 text-green-500"
|
|
122
|
+
aria-hidden="true"
|
|
123
|
+
/>
|
|
124
|
+
) : null}
|
|
125
|
+
{showText && labelKey ? (
|
|
126
|
+
<span className="whitespace-nowrap text-xs font-semibold leading-tight [text-shadow:0_0_2px_rgb(0_0_0/70%)]">
|
|
127
|
+
{t(labelKey)}
|
|
128
|
+
</span>
|
|
129
|
+
) : null}
|
|
130
|
+
</button>
|
|
131
|
+
</TooltipTrigger>
|
|
132
|
+
<TooltipContent
|
|
133
|
+
side="bottom"
|
|
134
|
+
className="max-w-[16rem]"
|
|
135
|
+
>
|
|
136
|
+
<div>{t(ariaKeyOf(ariaPresentation))}</div>
|
|
137
|
+
{cause ? <div className="mt-1 opacity-[.85]">{cause}</div> : null}
|
|
138
|
+
{/* VF-INFO-11: Cornerstone3D gives the issue messages in English only. */}
|
|
139
|
+
{state?.issues?.map(issue => (
|
|
140
|
+
<div
|
|
141
|
+
key={issue.code}
|
|
142
|
+
className="mt-1 opacity-[.85]"
|
|
143
|
+
>
|
|
144
|
+
{issue.message}
|
|
145
|
+
</div>
|
|
146
|
+
))}
|
|
147
|
+
</TooltipContent>
|
|
148
|
+
</Tooltip>
|
|
149
|
+
);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
export default FidelityIndicator;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from './FidelityIndicator';
|
|
@@ -3,6 +3,7 @@ import { ViewportActionCorners, IconPresentationProvider, ToolButton } from '@oh
|
|
|
3
3
|
import { Toolbar } from '@ohif/extension-default/src/Toolbar/Toolbar';
|
|
4
4
|
import { ButtonLocation } from '@ohif/core/src/services/ToolBarService/ToolbarService';
|
|
5
5
|
import { useViewportHover } from '../hooks';
|
|
6
|
+
import FidelityIndicator from './FidelityIndicator';
|
|
6
7
|
|
|
7
8
|
export type OHIFViewportActionCornersProps = {
|
|
8
9
|
viewportId: string;
|
|
@@ -14,10 +15,6 @@ function OHIFViewportActionCornersComponent({ viewportId }: OHIFViewportActionCo
|
|
|
14
15
|
|
|
15
16
|
const shouldShowCorners = isHovered || isActive;
|
|
16
17
|
|
|
17
|
-
if (!shouldShowCorners) {
|
|
18
|
-
return null;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
18
|
return (
|
|
22
19
|
<IconPresentationProvider
|
|
23
20
|
size="medium"
|
|
@@ -29,60 +26,78 @@ function OHIFViewportActionCornersComponent({ viewportId }: OHIFViewportActionCo
|
|
|
29
26
|
>
|
|
30
27
|
<ViewportActionCorners.Container>
|
|
31
28
|
<ViewportActionCorners.TopLeft>
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
29
|
+
{shouldShowCorners && (
|
|
30
|
+
<Toolbar
|
|
31
|
+
buttonSection="viewportActionMenu.topLeft"
|
|
32
|
+
viewportId={viewportId}
|
|
33
|
+
location={ButtonLocation.TopLeft}
|
|
34
|
+
/>
|
|
35
|
+
)}
|
|
37
36
|
</ViewportActionCorners.TopLeft>
|
|
38
37
|
<ViewportActionCorners.TopMiddle>
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
38
|
+
{shouldShowCorners && (
|
|
39
|
+
<Toolbar
|
|
40
|
+
buttonSection="viewportActionMenu.topMiddle"
|
|
41
|
+
viewportId={viewportId}
|
|
42
|
+
location={ButtonLocation.TopMiddle}
|
|
43
|
+
/>
|
|
44
|
+
)}
|
|
44
45
|
</ViewportActionCorners.TopMiddle>
|
|
45
46
|
<ViewportActionCorners.TopRight>
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
47
|
+
{shouldShowCorners && (
|
|
48
|
+
<Toolbar
|
|
49
|
+
buttonSection="viewportActionMenu.topRight"
|
|
50
|
+
viewportId={viewportId}
|
|
51
|
+
location={ButtonLocation.TopRight}
|
|
52
|
+
/>
|
|
53
|
+
)}
|
|
54
|
+
{/* A status, not a control: shows without hover or focus (VF-VIS-2, VF-VIS-3). */}
|
|
55
|
+
<FidelityIndicator viewportId={viewportId} />
|
|
51
56
|
</ViewportActionCorners.TopRight>
|
|
52
57
|
<ViewportActionCorners.LeftMiddle>
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
+
{shouldShowCorners && (
|
|
59
|
+
<Toolbar
|
|
60
|
+
buttonSection="viewportActionMenu.leftMiddle"
|
|
61
|
+
viewportId={viewportId}
|
|
62
|
+
location={ButtonLocation.LeftMiddle}
|
|
63
|
+
/>
|
|
64
|
+
)}
|
|
58
65
|
</ViewportActionCorners.LeftMiddle>
|
|
59
66
|
<ViewportActionCorners.RightMiddle>
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
67
|
+
{shouldShowCorners && (
|
|
68
|
+
<Toolbar
|
|
69
|
+
buttonSection="viewportActionMenu.rightMiddle"
|
|
70
|
+
viewportId={viewportId}
|
|
71
|
+
location={ButtonLocation.RightMiddle}
|
|
72
|
+
/>
|
|
73
|
+
)}
|
|
65
74
|
</ViewportActionCorners.RightMiddle>
|
|
66
75
|
<ViewportActionCorners.BottomLeft>
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
76
|
+
{shouldShowCorners && (
|
|
77
|
+
<Toolbar
|
|
78
|
+
buttonSection="viewportActionMenu.bottomLeft"
|
|
79
|
+
viewportId={viewportId}
|
|
80
|
+
location={ButtonLocation.BottomLeft}
|
|
81
|
+
/>
|
|
82
|
+
)}
|
|
72
83
|
</ViewportActionCorners.BottomLeft>
|
|
73
84
|
<ViewportActionCorners.BottomMiddle>
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
85
|
+
{shouldShowCorners && (
|
|
86
|
+
<Toolbar
|
|
87
|
+
buttonSection="viewportActionMenu.bottomMiddle"
|
|
88
|
+
viewportId={viewportId}
|
|
89
|
+
location={ButtonLocation.BottomMiddle}
|
|
90
|
+
/>
|
|
91
|
+
)}
|
|
79
92
|
</ViewportActionCorners.BottomMiddle>
|
|
80
93
|
<ViewportActionCorners.BottomRight>
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
94
|
+
{shouldShowCorners && (
|
|
95
|
+
<Toolbar
|
|
96
|
+
buttonSection="viewportActionMenu.bottomRight"
|
|
97
|
+
viewportId={viewportId}
|
|
98
|
+
location={ButtonLocation.BottomRight}
|
|
99
|
+
/>
|
|
100
|
+
)}
|
|
86
101
|
</ViewportActionCorners.BottomRight>
|
|
87
102
|
</ViewportActionCorners.Container>
|
|
88
103
|
</IconPresentationProvider>
|
package/src/components/index.ts
CHANGED
package/src/hooks/index.ts
CHANGED
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
2
|
+
import { Enums, getEnabledElement } from '@cornerstonejs/core';
|
|
3
|
+
import type { Types } from '@cornerstonejs/core';
|
|
4
|
+
import { useSystem } from '@ohif/core';
|
|
5
|
+
import { useViewportDisplaySets } from './useViewportDisplaySets';
|
|
6
|
+
|
|
7
|
+
const { VIEWPORT_FIDELITY_CHANGED } = Enums.Events;
|
|
8
|
+
|
|
9
|
+
/** Brief recovered (green) hold, then withdrawn (VF-VIS-1c). Spec: ~1s. */
|
|
10
|
+
export const FIDELITY_RECOVERED_HOLD_MS = 1000;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* OHIF presentation of Cornerstone3D fidelity (VF-VIS / #6256).
|
|
14
|
+
* - none: never lossy, no data, or recovered hold finished
|
|
15
|
+
* - transient: lossy now, expected to improve (yellow)
|
|
16
|
+
* - standing: lossy now, as good as it gets (red)
|
|
17
|
+
* - recovered: was lossy, now not (green, brief)
|
|
18
|
+
*/
|
|
19
|
+
export type FidelityPresentation = 'none' | 'transient' | 'standing' | 'recovered';
|
|
20
|
+
|
|
21
|
+
export type ViewportFidelityView = {
|
|
22
|
+
presentation: FidelityPresentation;
|
|
23
|
+
/** True after any lossy state on the current display set (VF-VIS-1d). */
|
|
24
|
+
wasLossy: boolean;
|
|
25
|
+
state: Types.ViewportFidelityState | null;
|
|
26
|
+
/** Re-show recovered while hovering after the hold withdrew. */
|
|
27
|
+
revealRecovered: () => void;
|
|
28
|
+
hideRecoveredReveal: () => void;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
function presentationOf(
|
|
32
|
+
state: Types.ViewportFidelityState | null | undefined,
|
|
33
|
+
wasLossy: boolean
|
|
34
|
+
): FidelityPresentation {
|
|
35
|
+
if (!state || state.shownState === 'hidden') {
|
|
36
|
+
return 'none';
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (state.lossy) {
|
|
40
|
+
return state.transient === false ? 'standing' : 'transient';
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// Lossless (`done` or equivalent): only announce if this display set was lossy.
|
|
44
|
+
return wasLossy ? 'recovered' : 'none';
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function fidelityViewportOf(
|
|
48
|
+
element: HTMLElement | null | undefined,
|
|
49
|
+
cornerstoneViewportService: AppTypes.ServicesManager['services']['cornerstoneViewportService'],
|
|
50
|
+
viewportId: string
|
|
51
|
+
): (Types.IViewport & { getFidelityState?: () => Types.ViewportFidelityState }) | null {
|
|
52
|
+
if (element) {
|
|
53
|
+
const enabled = getEnabledElement(element);
|
|
54
|
+
const fromElement = enabled?.viewport as
|
|
55
|
+
| (Types.IViewport & { getFidelityState?: () => Types.ViewportFidelityState })
|
|
56
|
+
| undefined;
|
|
57
|
+
if (fromElement && typeof fromElement.getFidelityState === 'function') {
|
|
58
|
+
return fromElement;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const fromService = cornerstoneViewportService?.getCornerstoneViewport(viewportId) as
|
|
63
|
+
| (Types.IViewport & { getFidelityState?: () => Types.ViewportFidelityState })
|
|
64
|
+
| null
|
|
65
|
+
| undefined;
|
|
66
|
+
|
|
67
|
+
if (fromService && typeof fromService.getFidelityState === 'function') {
|
|
68
|
+
return fromService;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Subscribes to `VIEWPORT_FIDELITY_CHANGED` for a viewport and derives the
|
|
76
|
+
* OHIF presentation states (never-lossy history + brief recovered hold).
|
|
77
|
+
*/
|
|
78
|
+
export function useViewportFidelity({
|
|
79
|
+
viewportId,
|
|
80
|
+
element,
|
|
81
|
+
}: {
|
|
82
|
+
viewportId: string;
|
|
83
|
+
/** Viewport host element from the overlay (preferred for subscribe + read). */
|
|
84
|
+
element?: HTMLElement | null;
|
|
85
|
+
}): ViewportFidelityView {
|
|
86
|
+
const { servicesManager } = useSystem();
|
|
87
|
+
const { cornerstoneViewportService } = servicesManager.services;
|
|
88
|
+
const { backgroundDisplaySet } = useViewportDisplaySets(viewportId);
|
|
89
|
+
|
|
90
|
+
const [state, setState] = useState<Types.ViewportFidelityState | null>(null);
|
|
91
|
+
const [wasLossy, setWasLossy] = useState(false);
|
|
92
|
+
const [presentation, setPresentation] = useState<FidelityPresentation>('none');
|
|
93
|
+
const [forceRecovered, setForceRecovered] = useState(false);
|
|
94
|
+
// Bumps when the CS viewport becomes available after a null first look.
|
|
95
|
+
const [viewportEpoch, setViewportEpoch] = useState(0);
|
|
96
|
+
|
|
97
|
+
const holdTimerRef = useRef<number>(0);
|
|
98
|
+
const displaySetKeyRef = useRef<string | undefined>(undefined);
|
|
99
|
+
const wasLossyRef = useRef(false);
|
|
100
|
+
|
|
101
|
+
const clearHold = useCallback(() => {
|
|
102
|
+
if (holdTimerRef.current) {
|
|
103
|
+
window.clearTimeout(holdTimerRef.current);
|
|
104
|
+
holdTimerRef.current = 0;
|
|
105
|
+
}
|
|
106
|
+
}, []);
|
|
107
|
+
|
|
108
|
+
const applyState = useCallback(
|
|
109
|
+
(next: Types.ViewportFidelityState | null) => {
|
|
110
|
+
const nextWasLossy = wasLossyRef.current || Boolean(next?.lossy);
|
|
111
|
+
wasLossyRef.current = nextWasLossy;
|
|
112
|
+
const nextPresentation = presentationOf(next, nextWasLossy);
|
|
113
|
+
|
|
114
|
+
setState(next);
|
|
115
|
+
setWasLossy(nextWasLossy);
|
|
116
|
+
|
|
117
|
+
if (nextPresentation === 'recovered') {
|
|
118
|
+
setForceRecovered(false);
|
|
119
|
+
setPresentation('recovered');
|
|
120
|
+
clearHold();
|
|
121
|
+
holdTimerRef.current = window.setTimeout(() => {
|
|
122
|
+
holdTimerRef.current = 0;
|
|
123
|
+
setPresentation(prev => (prev === 'recovered' ? 'none' : prev));
|
|
124
|
+
}, FIDELITY_RECOVERED_HOLD_MS);
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
clearHold();
|
|
129
|
+
setPresentation(nextPresentation);
|
|
130
|
+
},
|
|
131
|
+
[clearHold]
|
|
132
|
+
);
|
|
133
|
+
|
|
134
|
+
const readSnapshot = useCallback(() => {
|
|
135
|
+
const viewport = fidelityViewportOf(element, cornerstoneViewportService, viewportId);
|
|
136
|
+
return viewport?.getFidelityState?.() ?? null;
|
|
137
|
+
}, [cornerstoneViewportService, element, viewportId]);
|
|
138
|
+
|
|
139
|
+
// Retry when the Cornerstone viewport is enabled after the overlay mounts.
|
|
140
|
+
useEffect(() => {
|
|
141
|
+
if (!viewportId || !cornerstoneViewportService) {
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
if (fidelityViewportOf(element, cornerstoneViewportService, viewportId)) {
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
const { unsubscribe } = cornerstoneViewportService.subscribe(
|
|
150
|
+
cornerstoneViewportService.EVENTS.VIEWPORT_DATA_CHANGED,
|
|
151
|
+
({ viewportId: eventViewportId }) => {
|
|
152
|
+
if (eventViewportId !== viewportId) {
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
if (fidelityViewportOf(element, cornerstoneViewportService, viewportId)) {
|
|
156
|
+
setViewportEpoch(n => n + 1);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
);
|
|
160
|
+
|
|
161
|
+
return () => {
|
|
162
|
+
unsubscribe();
|
|
163
|
+
};
|
|
164
|
+
}, [viewportId, cornerstoneViewportService, element]);
|
|
165
|
+
|
|
166
|
+
// Reset lossiness history when the viewport shows a different display set (VF-VIS-7).
|
|
167
|
+
useEffect(() => {
|
|
168
|
+
const key = backgroundDisplaySet?.displaySetInstanceUID ?? '';
|
|
169
|
+
if (displaySetKeyRef.current === undefined) {
|
|
170
|
+
displaySetKeyRef.current = key;
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
if (displaySetKeyRef.current === key) {
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
displaySetKeyRef.current = key;
|
|
177
|
+
wasLossyRef.current = false;
|
|
178
|
+
// Apply in the next frame, not in the effect body (react-hooks/set-state-in-effect).
|
|
179
|
+
const frame = window.requestAnimationFrame(() => {
|
|
180
|
+
clearHold();
|
|
181
|
+
setWasLossy(false);
|
|
182
|
+
setForceRecovered(false);
|
|
183
|
+
applyState(readSnapshot());
|
|
184
|
+
});
|
|
185
|
+
return () => window.cancelAnimationFrame(frame);
|
|
186
|
+
}, [backgroundDisplaySet?.displaySetInstanceUID, applyState, clearHold, readSnapshot]);
|
|
187
|
+
|
|
188
|
+
useEffect(() => {
|
|
189
|
+
const viewport = fidelityViewportOf(element, cornerstoneViewportService, viewportId);
|
|
190
|
+
const listenEl = (element ?? viewport?.element) as HTMLElement | undefined;
|
|
191
|
+
|
|
192
|
+
if (!listenEl || !viewport) {
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
const onFidelityChanged = (evt: Event) => {
|
|
197
|
+
const detail = (evt as Types.EventTypes.ViewportFidelityChangedEvent).detail;
|
|
198
|
+
if (detail?.viewportId && detail.viewportId !== viewportId) {
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
applyState(detail?.state ?? readSnapshot());
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
listenEl.addEventListener(VIEWPORT_FIDELITY_CHANGED, onFidelityChanged);
|
|
205
|
+
// Read the current state in the next frame, not in the effect body.
|
|
206
|
+
const frame = window.requestAnimationFrame(() => applyState(readSnapshot()));
|
|
207
|
+
|
|
208
|
+
return () => {
|
|
209
|
+
window.cancelAnimationFrame(frame);
|
|
210
|
+
listenEl.removeEventListener(VIEWPORT_FIDELITY_CHANGED, onFidelityChanged);
|
|
211
|
+
clearHold();
|
|
212
|
+
};
|
|
213
|
+
}, [
|
|
214
|
+
viewportId,
|
|
215
|
+
element,
|
|
216
|
+
viewportEpoch,
|
|
217
|
+
cornerstoneViewportService,
|
|
218
|
+
applyState,
|
|
219
|
+
readSnapshot,
|
|
220
|
+
clearHold,
|
|
221
|
+
]);
|
|
222
|
+
|
|
223
|
+
const revealRecovered = useCallback(() => {
|
|
224
|
+
if (wasLossyRef.current && presentation === 'none' && state && !state.lossy) {
|
|
225
|
+
setForceRecovered(true);
|
|
226
|
+
}
|
|
227
|
+
}, [presentation, state]);
|
|
228
|
+
|
|
229
|
+
const hideRecoveredReveal = useCallback(() => {
|
|
230
|
+
setForceRecovered(false);
|
|
231
|
+
}, []);
|
|
232
|
+
|
|
233
|
+
const shownPresentation: FidelityPresentation =
|
|
234
|
+
forceRecovered && presentation === 'none' && wasLossy ? 'recovered' : presentation;
|
|
235
|
+
|
|
236
|
+
return {
|
|
237
|
+
presentation: shownPresentation,
|
|
238
|
+
wasLossy,
|
|
239
|
+
state,
|
|
240
|
+
revealRecovered,
|
|
241
|
+
hideRecoveredReveal,
|
|
242
|
+
};
|
|
243
|
+
}
|
package/src/init.tsx
CHANGED
|
@@ -75,9 +75,12 @@ export default async function init({
|
|
|
75
75
|
const statsOverlay =
|
|
76
76
|
new URLSearchParams(window.location.search).get('debug') === 'true';
|
|
77
77
|
|
|
78
|
+
// OHIF owns the fidelity indicator (top-right action corner); turn off CS3D's .fi-root
|
|
79
|
+
// so it cannot cover menus (z-index 1000).
|
|
78
80
|
await cs3DInit({
|
|
79
81
|
peerImport: appConfig.peerImport,
|
|
80
82
|
debug: { statsOverlay },
|
|
83
|
+
dangerouslyDisableFidelityIndicator: true,
|
|
81
84
|
...(appConfig.lossyDownsampling && {
|
|
82
85
|
rendering: { lossyDownsampling: appConfig.lossyDownsampling },
|
|
83
86
|
}),
|