2025-03-17 22:34:34 -04:00
|
|
|
import { CustomDropdownMenuContent } from './CustomDropdownMenuContent';
|
|
|
|
|
import { CustomSegmentStatisticsHeader } from './CustomSegmentStatisticsHeader';
|
2025-10-29 14:15:52 -04:00
|
|
|
import SegmentationToolConfig from '../components/SegmentationToolConfig';
|
|
|
|
|
import React from 'react';
|
|
|
|
|
import { SegmentationRepresentations } from '@cornerstonejs/tools/enums';
|
2025-01-23 14:24:13 -05:00
|
|
|
|
|
|
|
|
export default function getSegmentationPanelCustomization({ commandsManager, servicesManager }) {
|
2025-11-19 17:55:53 -05:00
|
|
|
const { segmentationService } = servicesManager.services;
|
|
|
|
|
|
|
|
|
|
let contourRenderFillChangedGlobally = false;
|
|
|
|
|
|
|
|
|
|
// Listen to when the global CONTOUR type renderFill style property is changed.
|
|
|
|
|
const { unsubscribe } = segmentationService.subscribe(
|
|
|
|
|
segmentationService.EVENTS.SEGMENTATION_STYLE_MODIFIED,
|
|
|
|
|
({ specifier, style }) => {
|
|
|
|
|
if (
|
|
|
|
|
specifier.type === SegmentationRepresentations.Contour &&
|
|
|
|
|
specifier.segmentationId == null &&
|
|
|
|
|
specifier.viewportId == null &&
|
|
|
|
|
style.renderFill != null
|
|
|
|
|
) {
|
|
|
|
|
unsubscribe();
|
|
|
|
|
contourRenderFillChangedGlobally = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
|
2025-01-23 14:24:13 -05:00
|
|
|
return {
|
2025-03-17 22:34:34 -04:00
|
|
|
'panelSegmentation.customDropdownMenuContent': CustomDropdownMenuContent,
|
|
|
|
|
'panelSegmentation.customSegmentStatisticsHeader': CustomSegmentStatisticsHeader,
|
2025-01-23 14:24:13 -05:00
|
|
|
'panelSegmentation.disableEditing': false,
|
|
|
|
|
'panelSegmentation.showAddSegment': true,
|
2025-10-29 14:15:52 -04:00
|
|
|
'panelSegmentation.onSegmentationAdd': async ({
|
|
|
|
|
segmentationRepresentationType = SegmentationRepresentations.Labelmap,
|
|
|
|
|
}) => {
|
2025-01-23 14:24:13 -05:00
|
|
|
const { viewportGridService } = servicesManager.services;
|
|
|
|
|
const viewportId = viewportGridService.getState().activeViewportId;
|
2025-10-29 14:15:52 -04:00
|
|
|
if (segmentationRepresentationType === SegmentationRepresentations.Labelmap) {
|
|
|
|
|
commandsManager.run('createLabelmapForViewport', { viewportId });
|
|
|
|
|
} else if (segmentationRepresentationType === SegmentationRepresentations.Contour) {
|
|
|
|
|
const segmentationId = await commandsManager.run('createContourForViewport', {
|
|
|
|
|
viewportId,
|
|
|
|
|
});
|
2025-11-19 17:55:53 -05:00
|
|
|
// Override the default (i.e. hydrated RTSTRUCT) style for contours if the global CONTOUR type
|
|
|
|
|
// renderFill style property has not been changed.
|
|
|
|
|
if (!contourRenderFillChangedGlobally) {
|
|
|
|
|
segmentationService.setStyle(
|
|
|
|
|
{ segmentationId, type: SegmentationRepresentations.Contour },
|
|
|
|
|
{
|
|
|
|
|
renderFill: true,
|
|
|
|
|
renderFillInactive: true,
|
|
|
|
|
},
|
|
|
|
|
// Do not merge so that these created contours inherit other type-specific style properties like the fill alpha.
|
|
|
|
|
// Merging would otherwise permanently inherit the fill alpha and any inheritance from the type level would be lost.
|
|
|
|
|
false
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// If the global CONTOUR type renderFill style property is already set, do not subscribe to the SEGMENTATION_STYLE_MODIFIED event.
|
|
|
|
|
if (contourRenderFillChangedGlobally) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Subscribe to the SEGMENTATION_STYLE_MODIFIED event to listen for changes to the CONTOUR type renderFill style property.
|
|
|
|
|
const { unsubscribe } = segmentationService.subscribe(
|
|
|
|
|
segmentationService.EVENTS.SEGMENTATION_STYLE_MODIFIED,
|
|
|
|
|
({ specifier, style }) => {
|
|
|
|
|
if (
|
|
|
|
|
specifier.type === SegmentationRepresentations.Contour &&
|
|
|
|
|
specifier.segmentationId == null &&
|
|
|
|
|
specifier.viewportId == null &&
|
|
|
|
|
style.renderFill != null
|
|
|
|
|
) {
|
|
|
|
|
// We are here because the renderFill style property is globally being changed for ALL contours.
|
|
|
|
|
// When this occurs, the desire is for ALL contours to inherit the property. To make this happen,
|
|
|
|
|
// we have to clear the style property that was set for this specific segmentation
|
|
|
|
|
// when it was created above.
|
|
|
|
|
// We can now also unsubscribe because this change only needs to be made when the global CONTOUR type
|
|
|
|
|
// renderFill style property is first changed.
|
|
|
|
|
|
|
|
|
|
contourRenderFillChangedGlobally = true;
|
|
|
|
|
unsubscribe();
|
|
|
|
|
segmentationService.setStyle(
|
|
|
|
|
{ segmentationId, type: SegmentationRepresentations.Contour },
|
|
|
|
|
{},
|
|
|
|
|
false
|
|
|
|
|
);
|
|
|
|
|
}
|
2025-10-29 14:15:52 -04:00
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
}
|
2025-01-23 14:24:13 -05:00
|
|
|
},
|
|
|
|
|
'panelSegmentation.tableMode': 'collapsed',
|
|
|
|
|
'panelSegmentation.readableText': {
|
2025-03-17 22:34:34 -04:00
|
|
|
// the values will appear in this order
|
|
|
|
|
min: 'Min Value',
|
|
|
|
|
minLPS: 'Min Coord',
|
|
|
|
|
max: 'Max Value',
|
|
|
|
|
maxLPS: 'Max Coord',
|
|
|
|
|
mean: 'Mean Value',
|
|
|
|
|
stdDev: 'Standard Deviation',
|
|
|
|
|
count: 'Voxel Count',
|
|
|
|
|
median: 'Median',
|
|
|
|
|
skewness: 'Skewness',
|
|
|
|
|
kurtosis: 'Kurtosis',
|
|
|
|
|
peakValue: 'Peak Value',
|
|
|
|
|
peakLPS: 'Peak Coord',
|
|
|
|
|
volume: 'Volume',
|
|
|
|
|
lesionGlycolysis: 'Lesion Glycolysis',
|
2025-04-07 16:45:29 -04:00
|
|
|
center: 'Center',
|
2025-01-23 14:24:13 -05:00
|
|
|
},
|
2025-10-29 14:15:52 -04:00
|
|
|
'labelMapSegmentationToolbox.config': () => {
|
|
|
|
|
return <SegmentationToolConfig />;
|
|
|
|
|
},
|
|
|
|
|
'contourSegmentationToolbox.config': () => {
|
|
|
|
|
return <SegmentationToolConfig />;
|
2025-03-19 18:24:33 -04:00
|
|
|
},
|
2025-01-23 14:24:13 -05:00
|
|
|
};
|
|
|
|
|
}
|