feat(Segments Looping) : Fixed looping through Segments of SEG (#4793)

This commit is contained in:
Yiannis Theocharakis authored and GitHub committed 2025-02-25 16:25:52 -05:00
1 parent 4ecffe89cb
commit 4b63d48518
6 files changed
+87 -55

No files matched your search

@@ -0,0 +1,7 @@
import { handleSegmentChange } from './segmentUtils';
const utils = {
handleSegmentChange,
};
export default utils;
@@ -0,0 +1,47 @@
import SegmentationServiceType from '../services/SegmentationService';
export const handleSegmentChange = ({
direction,
segDisplaySet,
viewportId,
selectedSegmentObjectIndex,
segmentationService,
}: {
direction: number;
segDisplaySet: AppTypes.DisplaySet;
viewportId: string;
selectedSegmentObjectIndex: number;
segmentationService: SegmentationServiceType;
}) => {
const segmentationId = segDisplaySet.displaySetInstanceUID;
const segmentation = segmentationService.getSegmentation(segmentationId);
const { segments } = segmentation;
const numberOfSegments = Object.keys(segments).length;
// Get activeSegment each time because the user can select any segment from the list and thus the index should be updated
const activeSegment = segmentationService.getActiveSegment(viewportId);
if (activeSegment) {
// from the activeSegment get the actual object array index to be used
selectedSegmentObjectIndex = Object.values(segments).findIndex(
segment => segment.segmentIndex === activeSegment.segmentIndex
);
}
let newSelectedSegmentIndex = selectedSegmentObjectIndex + direction;
// Handle looping through list of segments
if (newSelectedSegmentIndex > numberOfSegments - 1) {
newSelectedSegmentIndex = 0;
} else if (newSelectedSegmentIndex < 0) {
newSelectedSegmentIndex = numberOfSegments - 1;
}
// Convert segmentationId from object array index to property value of type Segment
// Functions below use the segmentIndex object attribute so we have to do the conversion
const segmentIndex = Object.values(segments)[newSelectedSegmentIndex]?.segmentIndex;
segmentationService.setActiveSegment(segmentationId, segmentIndex);
segmentationService.jumpToSegmentCenter(segmentationId, segmentIndex, viewportId);
selectedSegmentObjectIndex = newSelectedSegmentIndex;
};