Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Segmentation): download RTSS from Labelmap #3692

Merged
merged 10 commits into from
Oct 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion extensions/cornerstone-dicom-seg/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@
},
"dependencies": {
"@babel/runtime": "^7.20.13",
"@cornerstonejs/tools": "^1.19.4",
"@cornerstonejs/tools": "^1.20.1",
"@cornerstonejs/adapters": "^1.20.1",
"@kitware/vtk.js": "27.3.1",
"react-color": "^2.19.3"
}
}
58 changes: 55 additions & 3 deletions extensions/cornerstone-dicom-seg/src/commandsModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,37 @@ import dcmjs from 'dcmjs';
import { createReportDialogPrompt } from '@ohif/extension-default';
import { ServicesManager, Types } from '@ohif/core';
import { cache, metaData } from '@cornerstonejs/core';
import { segmentation as cornerstoneToolsSegmentation } from '@cornerstonejs/tools';
import { adaptersSEG, helpers } from '@cornerstonejs/adapters';
import { DicomMetadataStore } from '@ohif/core';
import {
segmentation as cornerstoneToolsSegmentation,
Enums as cornerstoneToolsEnums,
} from '@cornerstonejs/tools';
import { adaptersRT, helpers, adaptersSEG } from '@cornerstonejs/adapters';
import { classes, DicomMetadataStore } from '@ohif/core';

import vtkImageMarchingSquares from '@kitware/vtk.js/Filters/General/ImageMarchingSquares';
import vtkDataArray from '@kitware/vtk.js/Common/Core/DataArray';
import vtkImageData from '@kitware/vtk.js/Common/DataModel/ImageData';

import {
updateViewportsForSegmentationRendering,
getUpdatedViewportsForSegmentation,
getTargetViewport,
} from './utils/hydrationUtils';

const { datasetToBlob } = dcmjs.data;

const {
Cornerstone3D: {
Segmentation: { generateLabelMaps2DFrom3D, generateSegmentation },
},
} = adaptersSEG;

const {
Cornerstone3D: {
RTSS: { generateRTSSFromSegmentations },
},
} = adaptersRT;

const { downloadDICOMData } = helpers;

const commandsModule = ({
Expand Down Expand Up @@ -348,6 +363,40 @@ const commandsModule = ({

return naturalizedReport;
},
/**
* Converts segmentations into RTSS for download.
* This sample function retrieves all segentations and passes to
* cornerstone tool adapter to convert to DICOM RTSS format. It then
* converts dataset to downloadable blob.
*
*/
downloadRTSS: ({ segmentationId }) => {
const segmentations = segmentationService.getSegmentation(segmentationId);
const vtkUtils = {
vtkImageMarchingSquares,
vtkDataArray,
vtkImageData,
};

const RTSS = generateRTSSFromSegmentations(
segmentations,
classes.MetadataProvider,
DicomMetadataStore,
cache,
cornerstoneToolsEnums,
vtkUtils
);

try {
const reportBlob = datasetToBlob(RTSS);

//Create a URL for the binary.
const objectUrl = URL.createObjectURL(reportBlob);
window.location.assign(objectUrl);
} catch (e) {
console.warn(e);
}
},
};

const definitions = {
Expand All @@ -372,6 +421,9 @@ const commandsModule = ({
storeSegmentation: {
commandFn: actions.storeSegmentation,
},
downloadRTSS: {
commandFn: actions.downloadRTSS,
},
};

return {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createReportAsync } from '@ohif/extension-default';
import React, { useEffect, useState, useCallback } from 'react';
import PropTypes from 'prop-types';
import { SegmentationGroupTable } from '@ohif/ui';
import { SegmentationGroupTable, LegacyButtonGroup, LegacyButton } from '@ohif/ui';

import callInputDialog from './callInputDialog';
import callColorPickerDialog from './colorPickerDialog';
Expand Down Expand Up @@ -215,6 +215,12 @@ export default function PanelSegmentation({
}
};

const onSegmentationDownloadRTSS = segmentationId => {
commandsManager.runCommand('downloadRTSS', {
segmentationId,
});
};

return (
<>
<div className="ohif-scrollbar flex min-h-0 flex-auto select-none flex-col justify-between overflow-auto">
Expand All @@ -227,6 +233,7 @@ export default function PanelSegmentation({
onSegmentationClick={onSegmentationClick}
onSegmentationDelete={onSegmentationDelete}
onSegmentationDownload={onSegmentationDownload}
onSegmentationDownloadRTSS={onSegmentationDownloadRTSS}
storeSegmentation={storeSegmentation}
onSegmentationEdit={onSegmentationEdit}
onSegmentClick={onSegmentClick}
Expand Down
30 changes: 15 additions & 15 deletions extensions/cornerstone-dicom-seg/src/panels/SegmentationToolbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ const TOOL_TYPES = {
SPHERE_BRUSH: 'SphereBrush',
CIRCULAR_ERASER: 'CircularEraser',
SPHERE_ERASER: 'SphereEraser',
CIRCLE_SCISSOR: 'CircleScissor',
RECTANGLE_SCISSOR: 'RectangleScissor',
SPHERE_SCISSOR: 'SphereScissor',
CIRCLE_SHAPE: 'CircleScissor',
RECTANGLE_SHAPE: 'RectangleScissor',
SPHERE_SHAPE: 'SphereScissor',
THRESHOLD_CIRCULAR_BRUSH: 'ThresholdCircularBrush',
THRESHOLD_SPHERE_BRUSH: 'ThresholdSphereBrush',
};
Expand All @@ -31,7 +31,7 @@ const initialState = {
brushSize: 15,
mode: 'CircularEraser', // Can be 'CircularEraser' or 'SphereEraser'
},
Scissors: {
Shapes: {
brushSize: 15,
mode: 'CircleScissor', // E.g., 'CircleScissor', 'RectangleScissor', or 'SphereScissor'
},
Expand Down Expand Up @@ -301,24 +301,24 @@ function SegmentationToolbox({ servicesManager, extensionManager }) {
],
},
{
name: 'Scissor',
icon: 'icon-tool-scissor',
name: 'Shapes',
icon: 'icon-tool-shape',
disabled: !toolsEnabled,
active:
state.activeTool === TOOL_TYPES.CIRCLE_SCISSOR ||
state.activeTool === TOOL_TYPES.RECTANGLE_SCISSOR ||
state.activeTool === TOOL_TYPES.SPHERE_SCISSOR,
onClick: () => setToolActive(TOOL_TYPES.CIRCLE_SCISSOR),
state.activeTool === TOOL_TYPES.CIRCLE_SHAPE ||
state.activeTool === TOOL_TYPES.RECTANGLE_SHAPE ||
state.activeTool === TOOL_TYPES.SPHERE_SHAPE,
onClick: () => setToolActive(TOOL_TYPES.CIRCLE_SHAPE),
options: [
{
name: 'Mode',
type: 'radio',
value: state.Scissors.mode,
id: 'scissor-mode',
value: state.Shapes.mode,
id: 'shape-mode',
values: [
{ value: TOOL_TYPES.CIRCLE_SCISSOR, label: 'Circle' },
{ value: TOOL_TYPES.RECTANGLE_SCISSOR, label: 'Rectangle' },
{ value: TOOL_TYPES.SPHERE_SCISSOR, label: 'Sphere' },
{ value: TOOL_TYPES.CIRCLE_SHAPE, label: 'Circle' },
{ value: TOOL_TYPES.RECTANGLE_SHAPE, label: 'Rectangle' },
{ value: TOOL_TYPES.SPHERE_SHAPE, label: 'Sphere' },
],
onChange: value => setToolActive(value),
},
Expand Down
6 changes: 3 additions & 3 deletions extensions/cornerstone-dicom-sr/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@
},
"dependencies": {
"@babel/runtime": "^7.20.13",
"@cornerstonejs/adapters": "^1.19.4",
"@cornerstonejs/core": "^1.19.4",
"@cornerstonejs/tools": "^1.19.4",
"@cornerstonejs/adapters": "^1.20.1",
"@cornerstonejs/core": "^1.20.1",
"@cornerstonejs/tools": "^1.20.1",
"classnames": "^2.3.2"
}
}
10 changes: 5 additions & 5 deletions extensions/cornerstone/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"@cornerstonejs/codec-libjpeg-turbo-8bit": "^1.2.2",
"@cornerstonejs/codec-openjpeg": "^1.2.2",
"@cornerstonejs/codec-openjph": "^2.4.2",
"@cornerstonejs/dicom-image-loader": "^1.19.4",
"@cornerstonejs/dicom-image-loader": "^1.20.1",
"@ohif/core": "3.7.0-beta.101",
"@ohif/ui": "3.7.0-beta.101",
"dcmjs": "^0.29.6",
Expand All @@ -52,10 +52,10 @@
},
"dependencies": {
"@babel/runtime": "^7.20.13",
"@cornerstonejs/adapters": "^1.19.4",
"@cornerstonejs/core": "^1.19.4",
"@cornerstonejs/streaming-image-volume-loader": "^1.19.4",
"@cornerstonejs/tools": "^1.19.4",
"@cornerstonejs/adapters": "^1.20.1",
"@cornerstonejs/core": "^1.20.1",
"@cornerstonejs/streaming-image-volume-loader": "^1.20.1",
"@cornerstonejs/tools": "^1.20.1",
"@kitware/vtk.js": "27.3.1",
"html2canvas": "^1.4.1",
"lodash.debounce": "4.0.8",
Expand Down
4 changes: 2 additions & 2 deletions extensions/measurement-tracking/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
"start": "yarn run dev"
},
"peerDependencies": {
"@cornerstonejs/core": "^1.19.4",
"@cornerstonejs/tools": "^1.19.4",
"@cornerstonejs/core": "^1.20.1",
"@cornerstonejs/tools": "^1.20.1",
"@ohif/core": "3.7.0-beta.101",
"@ohif/extension-cornerstone-dicom-sr": "3.7.0-beta.101",
"@ohif/ui": "3.7.0-beta.101",
Expand Down
Loading