diff --git a/extensions/cornerstone/src/customizations/CustomDropdownMenuContent.tsx b/extensions/cornerstone/src/customizations/CustomDropdownMenuContent.tsx index d83e1d59f..aed2eb8cc 100644 --- a/extensions/cornerstone/src/customizations/CustomDropdownMenuContent.tsx +++ b/extensions/cornerstone/src/customizations/CustomDropdownMenuContent.tsx @@ -108,6 +108,7 @@ export const CustomDropdownMenuContent = () => { e.preventDefault(); actions.downloadCSVSegmentationReport(segmentationId); }} + disabled={!allowExport} > {t('CSV Report')} diff --git a/extensions/cornerstone/src/panels/PanelSegmentation.tsx b/extensions/cornerstone/src/panels/PanelSegmentation.tsx index bd531e7c1..2baf9d145 100644 --- a/extensions/cornerstone/src/panels/PanelSegmentation.tsx +++ b/extensions/cornerstone/src/panels/PanelSegmentation.tsx @@ -1,7 +1,7 @@ import React from 'react'; import { SegmentationTable } from '@ohif/ui-next'; import { useActiveViewportSegmentationRepresentations } from '../hooks/useActiveViewportSegmentationRepresentations'; -import { metaData } from '@cornerstonejs/core'; +import { metaData, cache } from '@cornerstonejs/core'; import { useSystem } from '@ohif/core/src'; export default function PanelSegmentation({ children }: withAppTypes) { @@ -104,6 +104,26 @@ export default function PanelSegmentation({ children }: withAppTypes) { return { segmentationId, isExportable: true }; } + // Check if any segments have anything drawn in any of the viewports + const hasAnySegmentData = (() => { + const imageIds = Labelmap.imageIds; + if (!imageIds?.length) return false; + + for (const imageId of imageIds) { + const pixelData = cache.getImage(imageId)?.getPixelData(); + if (!pixelData) continue; + + for (let i = 0; i < pixelData.length; i++) { + if (pixelData[i] !== 0) return true; + } + } + return false; + })(); + + if (!hasAnySegmentData) { + return { segmentationId, isExportable: false }; + } + const referencedImageIds = Labelmap.referencedImageIds; const firstImageId = referencedImageIds[0]; const instance = metaData.get('instance', firstImageId);