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

@@ -2,6 +2,7 @@ import React, { useCallback, useEffect, useRef, useState } from 'react';
import PropTypes from 'prop-types';
import { ViewportActionArrows } from '@ohif/ui';
import { useViewportGrid } from '@ohif/ui-next';
import { utils } from '@ohif/extension-cornerstone';
import promptHydrateRT from '../utils/promptHydrateRT';
import _getStatusComponent from './_getStatusComponent';
@@ -48,7 +49,7 @@ function OHIFCornerstoneRTViewport(props: withAppTypes) {
const [viewportGrid, viewportGridService] = useViewportGrid();
// States
let selectedSegmentObjectIndex: number = 0;
const selectedSegmentObjectIndex: number = 0;
const { setPositionPresentation } = usePositionPresentationStore();
// Hydration means that the RT is opened and segments are loaded into the
@@ -141,38 +142,15 @@ function OHIFCornerstoneRTViewport(props: withAppTypes) {
const onSegmentChange = useCallback(
direction => {
const segmentationId = rtDisplaySet.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) {
const activeSegmentIndex = Object.values(segments).findIndex(
segment => segment.segmentIndex === activeSegment.segmentIndex
);
//from the activeSegment get the actual obeject array index to be used
selectedSegmentObjectIndex = activeSegmentIndex;
}
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 uses the segmentIndex object attribute so we have to do the conversion
const keyIndex = Object.values(segments)[newSelectedSegmentIndex]?.segmentIndex;
segmentationService.setActiveSegment(segmentationId, keyIndex);
segmentationService.jumpToSegmentCenter(segmentationId, keyIndex, viewportId);
selectedSegmentObjectIndex = newSelectedSegmentIndex;
utils.handleSegmentChange({
direction,
segDisplaySet: rtDisplaySet,
viewportId,
selectedSegmentObjectIndex,
segmentationService,
});
},
[selectedSegmentObjectIndex, segmentationService]
[selectedSegmentObjectIndex]
);
useEffect(() => {