fix(seg): prevent segmentations from spreading to all viewports before hydration confirmation in 3D four-up (#5967)
This commit is contained in:
1 parent
c9c4f11b82
commit
f8ccf9ff2e
23 files changed
+558
-39
No files matched your search
@@ -262,6 +262,57 @@ describe('getUpdatedViewportsForSegmentation', () => {
|
||||
expect(result).toEqual(mockUpdatedViewports);
|
||||
});
|
||||
|
||||
it('should merge all grid viewports that reference the volume after hydration (e.g. 3D four-up)', () => {
|
||||
const volumeUid = 'volume-1';
|
||||
const viewports = new Map([
|
||||
[
|
||||
'vp-axial',
|
||||
{
|
||||
viewportId: 'vp-axial',
|
||||
viewportOptions: { viewportId: 'vp-axial' },
|
||||
displaySetInstanceUIDs: [volumeUid],
|
||||
},
|
||||
],
|
||||
[
|
||||
'vp-sagittal',
|
||||
{
|
||||
viewportId: 'vp-sagittal',
|
||||
viewportOptions: { viewportId: 'vp-sagittal' },
|
||||
displaySetInstanceUIDs: [volumeUid],
|
||||
},
|
||||
],
|
||||
[
|
||||
'vp-other-study',
|
||||
{
|
||||
viewportId: 'vp-other-study',
|
||||
viewportOptions: { viewportId: 'vp-other-study' },
|
||||
displaySetInstanceUIDs: ['other-volume'],
|
||||
},
|
||||
],
|
||||
]);
|
||||
|
||||
mockViewportGridService.getState.mockReturnValue({
|
||||
isHangingProtocolLayout: true,
|
||||
viewports,
|
||||
activeViewportId: 'vp-axial',
|
||||
});
|
||||
|
||||
mockHangingProtocolService.getViewportsRequireUpdate.mockReturnValue([
|
||||
{ viewportId: 'vp-axial', displaySetInstanceUIDs: [volumeUid] },
|
||||
]);
|
||||
|
||||
const result = getUpdatedViewportsForSegmentation({
|
||||
viewportId: 'vp-axial',
|
||||
servicesManager: mockServicesManager as unknown as AppTypes.ServicesManager,
|
||||
displaySetInstanceUIDs: [volumeUid],
|
||||
});
|
||||
|
||||
expect(result).toEqual([
|
||||
{ viewportId: 'vp-axial', displaySetInstanceUIDs: [volumeUid] },
|
||||
{ viewportId: 'vp-sagittal', displaySetInstanceUIDs: [volumeUid] },
|
||||
]);
|
||||
});
|
||||
|
||||
it('should handle complex viewport structure', () => {
|
||||
const complexViewport = {
|
||||
viewportOptions: {
|
||||
|
||||
@@ -1,3 +1,63 @@
|
||||
import type { Types } from '@ohif/core';
|
||||
|
||||
/**
|
||||
* 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`.
|
||||
*
|
||||
* Only exact displaySetInstanceUID matches are used (no Frame-of-Reference inference): sibling
|
||||
* MPR planes must already share the same referenced volume UID in grid state, or HP matching
|
||||
* must list them; otherwise forcing a different UID onto a volume viewport can leave it blank.
|
||||
*/
|
||||
function mergeVolumeSharingViewports(
|
||||
hangingProtocolUpdates: Types.HangingProtocol.ViewportUpdate[] | null | undefined,
|
||||
volumeUid: string | undefined,
|
||||
viewports: AppTypes.ViewportGrid.GridViewports
|
||||
): Types.HangingProtocol.ViewportUpdate[] {
|
||||
if (!volumeUid) {
|
||||
return (hangingProtocolUpdates ?? []) as Types.HangingProtocol.ViewportUpdate[];
|
||||
}
|
||||
|
||||
const byId = new Map<string, Types.HangingProtocol.ViewportUpdate>();
|
||||
|
||||
const add = (viewportId: string, uids: string[]) => {
|
||||
if (!viewportId) {
|
||||
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 => {
|
||||
const uids = vp.displaySetInstanceUIDs || [];
|
||||
if (uids.includes(volumeUid)) {
|
||||
add(vp.viewportId, [volumeUid]);
|
||||
}
|
||||
});
|
||||
|
||||
const merged = Array.from(byId.values());
|
||||
|
||||
if (
|
||||
merged.length === 0 &&
|
||||
Array.isArray(hangingProtocolUpdates) &&
|
||||
hangingProtocolUpdates.length > 0
|
||||
) {
|
||||
return hangingProtocolUpdates;
|
||||
}
|
||||
|
||||
return merged;
|
||||
}
|
||||
|
||||
function getUpdatedViewportsForSegmentation({
|
||||
viewportId,
|
||||
servicesManager,
|
||||
@@ -5,7 +65,7 @@ function getUpdatedViewportsForSegmentation({
|
||||
}: withAppTypes) {
|
||||
const { hangingProtocolService, viewportGridService } = servicesManager.services;
|
||||
|
||||
const { isHangingProtocolLayout } = viewportGridService.getState();
|
||||
const { isHangingProtocolLayout, viewports } = viewportGridService.getState();
|
||||
|
||||
const viewport = getTargetViewport({ viewportId, viewportGridService });
|
||||
const targetViewportId = viewport.viewportOptions.viewportId;
|
||||
@@ -16,7 +76,11 @@ function getUpdatedViewportsForSegmentation({
|
||||
isHangingProtocolLayout
|
||||
);
|
||||
|
||||
return updatedViewports;
|
||||
if (updatedViewports == null) {
|
||||
return updatedViewports;
|
||||
}
|
||||
|
||||
return mergeVolumeSharingViewports(updatedViewports, displaySetInstanceUIDs[0], viewports);
|
||||
}
|
||||
|
||||
const getTargetViewport = ({ viewportId, viewportGridService }) => {
|
||||
|
||||
Reference in new issue
Block a user