Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 | 62x 62x 62x 187x 187x 62x 62x 69x 69x 69x 62x 189x 69x 120x 120x 39x 39x 81x 79x 62x 62x 62x 63x 63x 63x 63x 81x 81x 81x 81x 81x 81x 63x 63x 63x 63x 63x 63x 63x 1x 1x 62x 62x 204x 63x 63x 63x 63x | import type { Types } from '@ohif/core';
import { isDisplaySetOverlayable } from './isDisplaySetOverlayable';
import { isAutoHydrateViewportType } from './autoHydrateViewportTypes';
/**
* After SEG hydration we must refresh every viewport that shows the referenced volume so
* presentations (including segmentation) apply to all MPR/3D tiles. Hanging-protocol matching
* can return only the active viewport when protocol definitions omit viewportId (e.g. 3D four-up)
* or when layout state diverges from the protocol; this merges in all grid panes that already
* list that volume in `displaySetInstanceUIDs`, plus every pane whose background the derived
* display set may be drawn over (`isDisplaySetOverlayable`, i.e. same frame of reference).
*
* The frame-of-reference merge is what makes hydration mean "show it wherever it logically
* belongs" rather than "show it where the exact referenced UID happens to be hung": a pane built
* from a different display set of the same data (a multi-frame split, a reconstruction) is a
* legitimate place to show the segmentation, and the segmentation presentation store is keyed by
* frame of reference so the lookup in those panes resolves.
*/
function mergeMatchingViewports(
hangingProtocolUpdates: Types.HangingProtocol.ViewportUpdate[] | null | undefined,
volumeUid: string | undefined,
viewports: AppTypes.ViewportGrid.Viewports,
isEligiblePane?: (viewport: AppTypes.ViewportGrid.Viewport) => boolean
): Types.HangingProtocol.ViewportUpdate[] {
Iif (!volumeUid && !isEligiblePane) {
return (hangingProtocolUpdates ?? []) as Types.HangingProtocol.ViewportUpdate[];
}
const byId = new Map<string, Types.HangingProtocol.ViewportUpdate>();
const add = (viewportId: string, uids: string[]) => {
Iif (!viewportId || !uids?.length) {
return;
}
byId.set(viewportId, { viewportId, displaySetInstanceUIDs: uids });
};
if (Array.isArray(hangingProtocolUpdates)) {
for (const entry of hangingProtocolUpdates) {
const vid = entry.viewportId ?? entry.viewportOptions?.viewportId;
if (vid) {
add(vid, entry.displaySetInstanceUIDs?.length ? entry.displaySetInstanceUIDs : [volumeUid]);
}
}
}
viewports.forEach(vp => {
// The hanging-protocol pass ran first and is authoritative for the panes it names - it is the
// one that knows the referenced display set has to be *loaded* into the hydration target,
// whose current display sets are exactly what hydration is replacing. Overwriting its entry
// with the pane's existing UIDs would discard that instruction.
if (byId.has(vp.viewportId)) {
return;
}
const uids = vp.displaySetInstanceUIDs || [];
// Only exact displaySetInstanceUID matches force the referenced volume onto the pane; a pane
// that merely shares the frame of reference keeps the display sets it already has (forcing a
// different UID onto a volume viewport can leave it blank).
if (volumeUid && uids.includes(volumeUid)) {
add(vp.viewportId, [volumeUid]);
return;
}
if (isEligiblePane?.(vp)) {
add(vp.viewportId, uids);
}
});
const merged = Array.from(byId.values());
Iif (
merged.length === 0 &&
Array.isArray(hangingProtocolUpdates) &&
hangingProtocolUpdates.length > 0
) {
return hangingProtocolUpdates;
}
return merged;
}
/**
* Builds a predicate saying whether a grid pane is a standard place to show the given derived
* display set: its background must be something the segmentation can be drawn over, and its
* viewport type must be one automatic hydration is allowed into.
*
* Returns undefined when there is no derived display set to reason about, so callers fall back to
* exact-UID matching alone.
*/
function makeEligiblePanePredicate({
derivedDisplaySetInstanceUID,
servicesManager,
}: {
derivedDisplaySetInstanceUID?: string;
servicesManager: AppTypes.ServicesManager;
}) {
const { displaySetService, customizationService } = servicesManager.services;
const derivedDisplaySet = derivedDisplaySetInstanceUID
? displaySetService.getDisplaySetByUID(derivedDisplaySetInstanceUID)
: undefined;
Iif (!derivedDisplaySet) {
return undefined;
}
return (viewport: AppTypes.ViewportGrid.Viewport) => {
Iif (
!isAutoHydrateViewportType({
viewportType: viewport?.viewportOptions?.viewportType,
customizationService,
})
) {
return false;
}
const backgroundUid = (viewport?.displaySetInstanceUIDs || []).find(uid => {
const ds = displaySetService.getDisplaySetByUID(uid);
return ds && !ds.isOverlayDisplaySet;
});
Iif (!backgroundUid) {
return false;
}
return isDisplaySetOverlayable({
displaySet: derivedDisplaySet,
backgroundDisplaySet: displaySetService.getDisplaySetByUID(backgroundUid),
});
};
}
function getUpdatedViewportsForSegmentation({
viewportId,
servicesManager,
displaySetInstanceUIDs,
derivedDisplaySetInstanceUID,
}: withAppTypes) {
const { hangingProtocolService, viewportGridService } = servicesManager.services;
const { isHangingProtocolLayout, viewports } = viewportGridService.getState();
const isEligiblePane = makeEligiblePanePredicate({
derivedDisplaySetInstanceUID: derivedDisplaySetInstanceUID as string | undefined,
servicesManager,
});
// The target viewport may be gone (the layout changed while the hydration prompt was open, and
// promptHydrationDialog resolves after a user click and a setTimeout) or may never have existed
// (hydration driven from the study panel with nothing showing the referenced series). Hydration
// is a statement about the display set, not about a viewport, so a missing one is not fatal -
// fall through to eligibility matching instead of dereferencing it.
const viewport = getTargetViewport({ viewportId, viewportGridService });
const targetViewportId = viewport?.viewportOptions?.viewportId;
const updatedViewports = targetViewportId
? hangingProtocolService.getViewportsRequireUpdate(
targetViewportId,
displaySetInstanceUIDs[0],
isHangingProtocolLayout
)
: null;
if (!isHangingProtocolLayout) {
// Outside a hanging protocol layout the protocol match is authoritative when there is one;
// eligibility matching only fills in when there was nothing to match against.
if (updatedViewports?.length) {
return updatedViewports;
}
return mergeMatchingViewports(null, undefined, viewports, isEligiblePane);
}
Iif (updatedViewports == null && !isEligiblePane) {
return updatedViewports;
}
return mergeMatchingViewports(
updatedViewports,
displaySetInstanceUIDs[0],
viewports,
isEligiblePane
);
}
const getTargetViewport = ({ viewportId, viewportGridService }) => {
const { viewports, activeViewportId } = viewportGridService.getState();
const targetViewportId = viewportId || activeViewportId;
const viewport = viewports.get(targetViewportId);
return viewport;
};
export { getUpdatedViewportsForSegmentation };
|