202 lines
7.3 KiB
TypeScript
202 lines
7.3 KiB
TypeScript
import React from 'react';
|
|
import { SegmentationTable } from '@ohif/ui-next';
|
|
import { useActiveViewportSegmentationRepresentations } from '../hooks/useActiveViewportSegmentationRepresentations';
|
|
import { metaData } from '@cornerstonejs/core';
|
|
import { useSystem } from '@ohif/core/src';
|
|
|
|
export default function PanelSegmentation({ children }: withAppTypes) {
|
|
const { commandsManager, servicesManager } = useSystem();
|
|
const { customizationService, displaySetService } = servicesManager.services;
|
|
|
|
const { segmentationsWithRepresentations, disabled } =
|
|
useActiveViewportSegmentationRepresentations();
|
|
|
|
// Extract customization options
|
|
const segmentationTableMode = customizationService.getCustomization(
|
|
'panelSegmentation.tableMode'
|
|
) as unknown as string;
|
|
const onSegmentationAdd = customizationService.getCustomization(
|
|
'panelSegmentation.onSegmentationAdd'
|
|
);
|
|
const disableEditing = customizationService.getCustomization('panelSegmentation.disableEditing');
|
|
const showAddSegment = customizationService.getCustomization('panelSegmentation.showAddSegment');
|
|
const CustomDropdownMenuContent = customizationService.getCustomization(
|
|
'panelSegmentation.customDropdownMenuContent'
|
|
);
|
|
|
|
const CustomSegmentStatisticsHeader = customizationService.getCustomization(
|
|
'panelSegmentation.customSegmentStatisticsHeader'
|
|
);
|
|
|
|
// Create handlers object for all command runs
|
|
const handlers = {
|
|
onSegmentationClick: (segmentationId: string) => {
|
|
commandsManager.run('setActiveSegmentation', { segmentationId });
|
|
},
|
|
onSegmentAdd: segmentationId => {
|
|
commandsManager.run('addSegment', { segmentationId });
|
|
},
|
|
onSegmentClick: (segmentationId, segmentIndex) => {
|
|
commandsManager.run('setActiveSegmentAndCenter', { segmentationId, segmentIndex });
|
|
},
|
|
onSegmentEdit: (segmentationId, segmentIndex) => {
|
|
commandsManager.run('editSegmentLabel', { segmentationId, segmentIndex });
|
|
},
|
|
onSegmentationEdit: segmentationId => {
|
|
commandsManager.run('editSegmentationLabel', { segmentationId });
|
|
},
|
|
onSegmentColorClick: (segmentationId, segmentIndex) => {
|
|
commandsManager.run('editSegmentColor', { segmentationId, segmentIndex });
|
|
},
|
|
onSegmentDelete: (segmentationId, segmentIndex) => {
|
|
commandsManager.run('deleteSegment', { segmentationId, segmentIndex });
|
|
},
|
|
onToggleSegmentVisibility: (segmentationId, segmentIndex, type) => {
|
|
commandsManager.run('toggleSegmentVisibility', { segmentationId, segmentIndex, type });
|
|
},
|
|
onToggleSegmentLock: (segmentationId, segmentIndex) => {
|
|
commandsManager.run('toggleSegmentLock', { segmentationId, segmentIndex });
|
|
},
|
|
onToggleSegmentationRepresentationVisibility: (segmentationId, type) => {
|
|
commandsManager.run('toggleSegmentationVisibility', { segmentationId, type });
|
|
},
|
|
onSegmentationDownload: segmentationId => {
|
|
commandsManager.run('downloadSegmentation', { segmentationId });
|
|
},
|
|
setStyle: (segmentationId, type, key, value) => {
|
|
commandsManager.run('setSegmentationStyle', { segmentationId, type, key, value });
|
|
},
|
|
toggleRenderInactiveSegmentations: () => {
|
|
commandsManager.run('toggleRenderInactiveSegmentations');
|
|
},
|
|
onSegmentationRemoveFromViewport: segmentationId => {
|
|
commandsManager.run('removeSegmentationFromViewport', { segmentationId });
|
|
},
|
|
onSegmentationDelete: segmentationId => {
|
|
commandsManager.run('deleteSegmentation', { segmentationId });
|
|
},
|
|
setFillAlpha: ({ type }, value) => {
|
|
commandsManager.run('setFillAlpha', { type, value });
|
|
},
|
|
setOutlineWidth: ({ type }, value) => {
|
|
commandsManager.run('setOutlineWidth', { type, value });
|
|
},
|
|
setRenderFill: ({ type }, value) => {
|
|
commandsManager.run('setRenderFill', { type, value });
|
|
},
|
|
setRenderOutline: ({ type }, value) => {
|
|
commandsManager.run('setRenderOutline', { type, value });
|
|
},
|
|
setFillAlphaInactive: ({ type }, value) => {
|
|
commandsManager.run('setFillAlphaInactive', { type, value });
|
|
},
|
|
getRenderInactiveSegmentations: () => {
|
|
return commandsManager.run('getRenderInactiveSegmentations');
|
|
},
|
|
};
|
|
|
|
// Generate export options
|
|
const exportOptions = segmentationsWithRepresentations.map(({ segmentation }) => {
|
|
const { representationData, segmentationId } = segmentation;
|
|
const { Labelmap } = representationData;
|
|
|
|
if (!Labelmap) {
|
|
return { segmentationId, isExportable: true };
|
|
}
|
|
|
|
const referencedImageIds = Labelmap.referencedImageIds;
|
|
const firstImageId = referencedImageIds[0];
|
|
const instance = metaData.get('instance', firstImageId);
|
|
|
|
if (!instance) {
|
|
return { segmentationId, isExportable: false };
|
|
}
|
|
|
|
const SOPInstanceUID = instance.SOPInstanceUID || instance.SopInstanceUID;
|
|
const SeriesInstanceUID = instance.SeriesInstanceUID;
|
|
const displaySet = displaySetService.getDisplaySetForSOPInstanceUID(
|
|
SOPInstanceUID,
|
|
SeriesInstanceUID
|
|
);
|
|
|
|
return {
|
|
segmentationId,
|
|
isExportable: displaySet?.isReconstructable,
|
|
};
|
|
});
|
|
|
|
// Common props for SegmentationTable
|
|
const tableProps = {
|
|
disabled,
|
|
data: segmentationsWithRepresentations,
|
|
mode: segmentationTableMode,
|
|
title: 'Segmentations',
|
|
exportOptions,
|
|
disableEditing,
|
|
onSegmentationAdd,
|
|
showAddSegment,
|
|
renderInactiveSegmentations: handlers.getRenderInactiveSegmentations(),
|
|
...handlers,
|
|
};
|
|
|
|
const renderSegments = () => {
|
|
return (
|
|
<SegmentationTable.Segments>
|
|
<SegmentationTable.SegmentStatistics.Header>
|
|
<CustomSegmentStatisticsHeader />
|
|
</SegmentationTable.SegmentStatistics.Header>
|
|
<SegmentationTable.SegmentStatistics.Body />
|
|
</SegmentationTable.Segments>
|
|
);
|
|
};
|
|
|
|
// Render content based on mode
|
|
const renderModeContent = () => {
|
|
if (tableProps.mode === 'collapsed') {
|
|
return (
|
|
<SegmentationTable.Collapsed>
|
|
<SegmentationTable.Collapsed.Header>
|
|
<SegmentationTable.Collapsed.DropdownMenu>
|
|
<CustomDropdownMenuContent />
|
|
</SegmentationTable.Collapsed.DropdownMenu>
|
|
<SegmentationTable.Collapsed.Selector />
|
|
<SegmentationTable.Collapsed.Info />
|
|
</SegmentationTable.Collapsed.Header>
|
|
<SegmentationTable.Collapsed.Content>
|
|
<SegmentationTable.AddSegmentRow />
|
|
{renderSegments()}
|
|
</SegmentationTable.Collapsed.Content>
|
|
</SegmentationTable.Collapsed>
|
|
);
|
|
}
|
|
|
|
return (
|
|
<>
|
|
<SegmentationTable.Expanded>
|
|
<SegmentationTable.Expanded.Header>
|
|
<SegmentationTable.Expanded.DropdownMenu>
|
|
<CustomDropdownMenuContent />
|
|
</SegmentationTable.Expanded.DropdownMenu>
|
|
<SegmentationTable.Expanded.Label />
|
|
<SegmentationTable.Expanded.Info />
|
|
</SegmentationTable.Expanded.Header>
|
|
|
|
<SegmentationTable.Expanded.Content>
|
|
<SegmentationTable.AddSegmentRow />
|
|
{renderSegments()}
|
|
</SegmentationTable.Expanded.Content>
|
|
</SegmentationTable.Expanded>
|
|
</>
|
|
);
|
|
};
|
|
|
|
return (
|
|
<SegmentationTable {...tableProps}>
|
|
{children}
|
|
<SegmentationTable.Config />
|
|
<SegmentationTable.AddSegmentationRow />
|
|
{renderModeContent()}
|
|
</SegmentationTable>
|
|
);
|
|
}
|