feat(Segments Looping) : Fixed looping through Segments of SEG (#4793)
This commit is contained in:
1 parent
4ecffe89cb
commit
4b63d48518
6 files changed
+87
-55
No files matched your search
@@ -54,6 +54,7 @@ import PanelMeasurement from './panels/PanelMeasurement';
|
||||
import DicomUpload from './components/DicomUpload/DicomUpload';
|
||||
import { useSegmentations } from './hooks/useSegmentations';
|
||||
import { StudySummaryFromMetadata } from './components/StudySummaryFromMetadata';
|
||||
import utils from './utils';
|
||||
|
||||
const { imageRetrieveMetadataProvider } = cornerstone.utilities;
|
||||
|
||||
@@ -254,5 +255,6 @@ export {
|
||||
PanelMeasurement,
|
||||
DicomUpload,
|
||||
StudySummaryFromMetadata,
|
||||
utils,
|
||||
};
|
||||
export default cornerstoneExtension;
|
||||
@@ -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;
|
||||
};
|
||||
Reference in new issue
Block a user