feature(segmentation): Add contour tools and utilities in a side panel (#5517)
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Dan Rukas <dan.rukas@gmail.com>
This commit is contained in:
73 files changed
+2770
-435
No files matched your search
@@ -1,5 +1,7 @@
|
||||
import * as cornerstoneTools from '@cornerstonejs/tools';
|
||||
import { updateSegmentationStats } from './updateSegmentationStats';
|
||||
import { useSelectedSegmentationsForViewportStore } from '../stores';
|
||||
import { SegmentationRepresentations } from '@cornerstonejs/tools/enums';
|
||||
|
||||
/**
|
||||
* Sets up the handler for segmentation data modification events
|
||||
@@ -110,3 +112,49 @@ export function setupSegmentationModifiedHandler({ segmentationService }) {
|
||||
|
||||
return { unsubscribe };
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets up auto tab switching for when the first segmentation is added into the viewer.
|
||||
*/
|
||||
export function setUpSelectedSegmentationsForViewportHandler({ segmentationService }) {
|
||||
const selectedSegmentationsForViewportEvents = [
|
||||
segmentationService.EVENTS.SEGMENTATION_MODIFIED,
|
||||
segmentationService.EVENTS.SEGMENTATION_REPRESENTATION_MODIFIED,
|
||||
];
|
||||
|
||||
const unsubscribeSelectedSegmentationsForViewportEvents = selectedSegmentationsForViewportEvents
|
||||
.map(eventName =>
|
||||
segmentationService.subscribe(eventName, event => {
|
||||
const { viewportId } = event;
|
||||
|
||||
if (!viewportId) {
|
||||
return;
|
||||
}
|
||||
|
||||
const { selectedSegmentationsForViewport, setSelectedSegmentationsForViewport } =
|
||||
useSelectedSegmentationsForViewportStore.getState();
|
||||
|
||||
const representations = segmentationService.getSegmentationRepresentations(viewportId);
|
||||
|
||||
const activeRepresentation = representations.find(representation => representation.active);
|
||||
|
||||
const typeToSegmentationIdMap =
|
||||
selectedSegmentationsForViewport[viewportId] ??
|
||||
new Map<SegmentationRepresentations, string>();
|
||||
|
||||
if (activeRepresentation) {
|
||||
typeToSegmentationIdMap.set(
|
||||
activeRepresentation.type,
|
||||
activeRepresentation.segmentationId
|
||||
);
|
||||
} else {
|
||||
typeToSegmentationIdMap.clear();
|
||||
}
|
||||
|
||||
setSelectedSegmentationsForViewport(viewportId, typeToSegmentationIdMap);
|
||||
})
|
||||
)
|
||||
.map(subscription => subscription.unsubscribe);
|
||||
|
||||
return { unsubscribeSelectedSegmentationsForViewportEvents };
|
||||
}
|
||||
Reference in new issue
Block a user