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:
Devu-trenser 2025-12-15 19:19:43 +05:30 committed by GitHub
parent 31ac27d5a0
commit 6c628e0937
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 42 additions and 3 deletions

View File

@ -6,6 +6,8 @@ import {
Types as ToolsTypes,
} from '@cornerstonejs/tools';
import { isAnyDisplaySetCommon } from '../../utils/isAnyDisplaySetCommon';
const { createSynchronizer } = SynchronizerManager;
const { SEGMENTATION_REPRESENTATION_MODIFIED } = Enums.Events;
const { BlendModes } = CoreEnums;
@ -34,6 +36,12 @@ export default function createHydrateSegmentationSynchronizer(
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 (
synchronizerInstance: Synchronizer,
sourceViewport: Types.IViewportId,
@ -44,15 +52,21 @@ const segmentationRepresentationModifiedCallback = async (
const event = sourceEvent as ToolsTypes.EventTypes.SegmentationRepresentationModifiedEventType;
const { segmentationId, type: segmentationRepresentationType } = event.detail;
const { segmentationService } = servicesManager.services;
const { segmentationService, cornerstoneViewportService } = servicesManager.services;
const targetViewportId = targetViewport.viewportId;
const sourceViewportId = sourceViewport.viewportId;
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;
}
@ -81,3 +95,10 @@ const segmentationRepresentationModifiedCallback = async (
},
});
};
/**
* Extracts the displaySetInstanceUIDs from a viewportInfo.
*/
function extractDisplaySetUIDs(viewportInfo) {
return viewportInfo.getViewportData().data.map(ds => ds.displaySetInstanceUID);
}

View 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));
}