fix(Segments Looping) : Fixed looping through Segments of RTSTRUCT using Left/Right viewport buttons (#4783)

This commit is contained in:
Yiannis Theocharakis 2025-02-19 01:20:26 +02:00 committed by GitHub
parent 2410c6a509
commit c61dbba8d0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -48,7 +48,7 @@ function OHIFCornerstoneRTViewport(props: withAppTypes) {
const [viewportGrid, viewportGridService] = useViewportGrid(); const [viewportGrid, viewportGridService] = useViewportGrid();
// States // States
const [selectedSegment, setSelectedSegment] = useState(1); let selectedSegmentObjectIndex: number = 0;
const { setPositionPresentation } = usePositionPresentationStore(); const { setPositionPresentation } = usePositionPresentationStore();
// Hydration means that the RT is opened and segments are loaded into the // Hydration means that the RT is opened and segments are loaded into the
@ -147,20 +147,32 @@ function OHIFCornerstoneRTViewport(props: withAppTypes) {
const { segments } = segmentation; const { segments } = segmentation;
const numberOfSegments = Object.keys(segments).length; 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;
let newSelectedSegmentIndex = selectedSegment + direction; //Handle looping through list of segments
if (newSelectedSegmentIndex > numberOfSegments - 1) {
// Segment 0 is always background newSelectedSegmentIndex = 0;
if (newSelectedSegmentIndex >= numberOfSegments - 1) { } else if (newSelectedSegmentIndex < 0) {
newSelectedSegmentIndex = 1;
} else if (newSelectedSegmentIndex === 0) {
newSelectedSegmentIndex = numberOfSegments - 1; newSelectedSegmentIndex = numberOfSegments - 1;
} }
segmentationService.jumpToSegmentCenter(segmentationId, newSelectedSegmentIndex, viewportId); //convert segmentationId from object array index to property value of type Segment
setSelectedSegment(newSelectedSegmentIndex); //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;
}, },
[selectedSegment, segmentationService] [selectedSegmentObjectIndex, segmentationService]
); );
useEffect(() => { useEffect(() => {