fix: seg sync for data without FOR (#5565)
* fix: seg sync for data without FOR * test commit to trigger deploy re-run * test commit to trigger deploy re-run * Revert "test commit to trigger deploy re-run" This reverts commit 42c532c6f404798e39e3d137fff7c1e7569956ad. * chore: comments updated * review commnets --------- Co-authored-by: Bill Wallace <wayfarer3130@gmail.com>
This commit is contained in:
parent
31ac27d5a0
commit
6c628e0937
@ -6,6 +6,8 @@ import {
|
|||||||
Types as ToolsTypes,
|
Types as ToolsTypes,
|
||||||
} from '@cornerstonejs/tools';
|
} from '@cornerstonejs/tools';
|
||||||
|
|
||||||
|
import { isAnyDisplaySetCommon } from '../../utils/isAnyDisplaySetCommon';
|
||||||
|
|
||||||
const { createSynchronizer } = SynchronizerManager;
|
const { createSynchronizer } = SynchronizerManager;
|
||||||
const { SEGMENTATION_REPRESENTATION_MODIFIED } = Enums.Events;
|
const { SEGMENTATION_REPRESENTATION_MODIFIED } = Enums.Events;
|
||||||
const { BlendModes } = CoreEnums;
|
const { BlendModes } = CoreEnums;
|
||||||
@ -34,6 +36,12 @@ export default function createHydrateSegmentationSynchronizer(
|
|||||||
return stackImageSynchronizer;
|
return stackImageSynchronizer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method will add the segmentation representation to any target viewports having:
|
||||||
|
*
|
||||||
|
* 1. the same FrameOfReferenceUID (FOR) as the segmentation representation, or
|
||||||
|
* 2. a shared DisplaySet with the source viewport when no FOR is present.
|
||||||
|
*/
|
||||||
const segmentationRepresentationModifiedCallback = async (
|
const segmentationRepresentationModifiedCallback = async (
|
||||||
synchronizerInstance: Synchronizer,
|
synchronizerInstance: Synchronizer,
|
||||||
sourceViewport: Types.IViewportId,
|
sourceViewport: Types.IViewportId,
|
||||||
@ -44,15 +52,21 @@ const segmentationRepresentationModifiedCallback = async (
|
|||||||
const event = sourceEvent as ToolsTypes.EventTypes.SegmentationRepresentationModifiedEventType;
|
const event = sourceEvent as ToolsTypes.EventTypes.SegmentationRepresentationModifiedEventType;
|
||||||
|
|
||||||
const { segmentationId, type: segmentationRepresentationType } = event.detail;
|
const { segmentationId, type: segmentationRepresentationType } = event.detail;
|
||||||
const { segmentationService } = servicesManager.services;
|
const { segmentationService, cornerstoneViewportService } = servicesManager.services;
|
||||||
|
|
||||||
const targetViewportId = targetViewport.viewportId;
|
const targetViewportId = targetViewport.viewportId;
|
||||||
|
const sourceViewportId = sourceViewport.viewportId;
|
||||||
|
|
||||||
const { viewport } = getEnabledElementByViewportId(targetViewportId);
|
const { viewport } = getEnabledElementByViewportId(targetViewportId);
|
||||||
|
const sourceViewportInfo = cornerstoneViewportService.getViewportInfo(sourceViewportId);
|
||||||
|
const targetViewportInfo = cornerstoneViewportService.getViewportInfo(targetViewportId);
|
||||||
|
|
||||||
const targetFrameOfReferenceUID = viewport.getFrameOfReferenceUID();
|
const sourceDisplaySetUIDs = extractDisplaySetUIDs(sourceViewportInfo);
|
||||||
|
const targetDisplaySetUIDs = extractDisplaySetUIDs(targetViewportInfo);
|
||||||
|
|
||||||
if (!targetFrameOfReferenceUID) {
|
const sharedDisplaySetExists = isAnyDisplaySetCommon(sourceDisplaySetUIDs, targetDisplaySetUIDs);
|
||||||
|
|
||||||
|
if (!sharedDisplaySetExists && !viewport.getFrameOfReferenceUID()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -81,3 +95,10 @@ const segmentationRepresentationModifiedCallback = async (
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extracts the displaySetInstanceUIDs from a viewportInfo.
|
||||||
|
*/
|
||||||
|
function extractDisplaySetUIDs(viewportInfo) {
|
||||||
|
return viewportInfo.getViewportData().data.map(ds => ds.displaySetInstanceUID);
|
||||||
|
}
|
||||||
|
|||||||
18
extensions/cornerstone/src/utils/isAnyDisplaySetCommon.ts
Normal file
18
extensions/cornerstone/src/utils/isAnyDisplaySetCommon.ts
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
/**
|
||||||
|
* Checks whether two viewports share at least one common display set.
|
||||||
|
*
|
||||||
|
* This method checks to see if the source and target share a display set.
|
||||||
|
* It performs an O(n * m) comparison between the display sets of each viewport.
|
||||||
|
* Since each viewport typically contains only a small number of display sets (≤ 5),
|
||||||
|
* the computational cost is negligible.
|
||||||
|
*
|
||||||
|
* @param sourceDisplaySetUIDs - Array of displaySetInstanceUID from the source viewport.
|
||||||
|
* @param targetDisplaySetUIDs - Array of displaySetInstanceUID from the target viewport.
|
||||||
|
* @returns true if at least one display set is common; false otherwise.
|
||||||
|
*/
|
||||||
|
export function isAnyDisplaySetCommon(
|
||||||
|
sourceDisplaySetUIDs: string[],
|
||||||
|
targetDisplaySetUIDs: string[]
|
||||||
|
): boolean {
|
||||||
|
return sourceDisplaySetUIDs.some(uid => targetDisplaySetUIDs.includes(uid));
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user