* feat: add initial sop class handler for SEG * feat: move segmentation service * update segmentation service methods * fix: viewport data structure * feat: Add initial render for the DICOM SEG for each displaySet * fix: various wrong architectural dependencies between services * feat: initial separate SEG display in each viewport * feat: refactore viewport action bar * initial work for SEG hydration * fix: various bugs regarding drag and dropping different viewports * fix: rendering issues for multiple seg displaysets * fix: bugs for thumbnail and hydration * feat: fix the initial segment color * update after rebase * feat: initial design for the segmentation group table * feat: initial new design for the segmentation panel * feat: segmentation panel * feat: make segmentation appear on all related viewports * fix: segmentation load bug based on functional groups * initial work for segmentation crosshairs * fix: various stylings and functionality * fix: various stylings for the seg panel * fix: overflow styles * feat: add more ui components * feat: added segmentation config * feat: add jump to segment * feat: add jump to segment for DICOM SEG viewport * fix: bugs after rebase * feat: jump in segmentation viewport * fix: mpr support for seg * feat: add more icons * feat: new icons * feat: add new side panel * feat: add segmentation config * feat: add loading indicator to ohif * feat: make hanging protocols follow matching rules for viewports * feat: enhance drag and drop to be hanging protocol aware * fix: mpr restore previous layout * fix: crosshairs toggle * fix: add auth headers to the dicom loader via dicomwebclient * fix: bug for crosshairs toggle in mpr * fix: seg viewport reusing old toolGroup * feat: add loading animation with lottie * fix: various bugs for Segmentation hydration in mpr * feat: change outline alpha to outline opacity * feat: loading indicator for seg viewport * fix: various segmentation group styles * fix: local mode for seg * feat: add animation for the highlight * fix: loading indicatro to show segment indices * feat: enhance modality drop down ui * fix: panels * fix: download form * fix: layout shift in loading indicator * fix: loading indicator to have correct values * fix: update software number * fix: image jump between MPR and default * fix: segmentation cleanup and cine service cleanup * fix: segmentation toolgroup clena up * fix: highlight interval should not trigger again * fix: issue with multiframe sorting * rename: change onSeriesChange to onArrowsClick * fix: buttons for tmtv and layout shift * fix: various bugs wrt crosshairs * fix: crosshairs re init on reset camera * fix: middle slice calculation different from cs middle reset camera * fix: reset camera should reset viewport camera * fix: loading segments in MPR mode * fix: tmtv hp back to before * fix: layout shift * feat: orientation markers for volume viewport * fix: capture for volume viewports * fix: memory leak for back to worklist * fix: loading bar bg color * fix: side panel for only one panel * fix: react select style in production * fix: various styling for segmentation groups * fix: various ui styles * feat: add new segmentation config styles * fix: hover state for segmentation item * fix: side panel layout shift * temp add panels * try to fix scrollbar for thimbnail * fix: scroll not appearing for side panels * feat: changed styles for scrollbar * feat: add cpu fallback warning * fix: webworker destroy * fix: select styles * fix: orientation marker color and position * fix: capture screenshot for volume viewports * fix: hide segment visibility on mpr * fix: reloading an already loaded seg displayset * feat: add is equal * fix: mpr jump to measurements * apply review comments * fix: optimization for the segmentation load * fix: remove unnecessary context menu and hp service reset * fix: segmentation service wrt brush settings * feat: initial work for the stack synchronization * fix: add validateDisplaySetSelectorsForNewDisplaySets to make sure drag and drop can follow requirements * fix: various react proptypes * fix: thumbnails for the tmtv and change default props to default params * feat: make showing loading indicator configurable and add docs * bump versions and add more docs * fix demo * update cornerstone versions * apply review comments * feat: add reference lines * fix build * fix unit tests * add reference lines icon * fix: e2e tests * fix static wado config * docs: add segmentation service docs * fix: docker build * fix: keep camera and bump versions * Try re-enabling minification to fix deploy previews Co-authored-by: Erik Ziegler <erik.sweed@gmail.com>
298 lines
8.9 KiB
TypeScript
298 lines
8.9 KiB
TypeScript
import React, { useEffect, useState, useCallback, useReducer } from 'react';
|
|
import PropTypes from 'prop-types';
|
|
import { SegmentationTable, Button, Icon } from '@ohif/ui';
|
|
import classnames from 'classnames';
|
|
|
|
import { useTranslation } from 'react-i18next';
|
|
import segmentationEditHandler from './segmentationEditHandler';
|
|
import ExportReports from './ExportReports';
|
|
import ROIThresholdConfiguration, {
|
|
ROI_STAT,
|
|
} from './ROIThresholdConfiguration';
|
|
|
|
const LOWER_THRESHOLD_DEFAULT = 0;
|
|
const UPPER_THRESHOLD_DEFAULT = 100;
|
|
const WEIGHT_DEFAULT = 0.41; // a default weight for suv max often used in the literature
|
|
const DEFAULT_STRATEGY = ROI_STAT;
|
|
|
|
function reducer(state, action) {
|
|
const { payload } = action;
|
|
const { strategy, lower, upper, weight } = payload;
|
|
|
|
switch (action.type) {
|
|
case 'setStrategy':
|
|
return {
|
|
...state,
|
|
strategy,
|
|
};
|
|
case 'setThreshold':
|
|
return {
|
|
...state,
|
|
lower: lower ? lower : state.lower,
|
|
upper: upper ? upper : state.upper,
|
|
};
|
|
case 'setWeight':
|
|
return {
|
|
...state,
|
|
weight,
|
|
};
|
|
default:
|
|
return state;
|
|
}
|
|
}
|
|
|
|
export default function PanelRoiThresholdSegmentation({
|
|
servicesManager,
|
|
commandsManager,
|
|
}) {
|
|
const { SegmentationService } = servicesManager.services;
|
|
|
|
const { t } = useTranslation('PanelSUV');
|
|
const [showConfig, setShowConfig] = useState(false);
|
|
const [labelmapLoading, setLabelmapLoading] = useState(false);
|
|
const [selectedSegmentationId, setSelectedSegmentationId] = useState(null);
|
|
const [segmentations, setSegmentations] = useState(() =>
|
|
SegmentationService.getSegmentations()
|
|
);
|
|
|
|
const [config, dispatch] = useReducer(reducer, {
|
|
strategy: DEFAULT_STRATEGY,
|
|
lower: LOWER_THRESHOLD_DEFAULT,
|
|
upper: UPPER_THRESHOLD_DEFAULT,
|
|
weight: WEIGHT_DEFAULT,
|
|
});
|
|
|
|
const [tmtvValue, setTmtvValue] = useState(null);
|
|
|
|
const runCommand = useCallback(
|
|
(commandName, commandOptions = {}) => {
|
|
return commandsManager.runCommand(commandName, commandOptions);
|
|
},
|
|
[commandsManager]
|
|
);
|
|
|
|
const handleTMTVCalculation = useCallback(() => {
|
|
const tmtv = runCommand('calculateTMTV', { segmentations });
|
|
|
|
if (tmtv !== undefined) {
|
|
setTmtvValue(tmtv.toFixed(2));
|
|
}
|
|
}, [segmentations, runCommand]);
|
|
|
|
const handleROIThresholding = useCallback(() => {
|
|
const labelmap = runCommand('thresholdSegmentationByRectangleROITool', {
|
|
segmentationId: selectedSegmentationId,
|
|
config,
|
|
});
|
|
|
|
const lesionStats = runCommand('getLesionStats', { labelmap });
|
|
const suvPeak = runCommand('calculateSuvPeak', { labelmap });
|
|
const lesionGlyoclysisStats = lesionStats.volume * lesionStats.meanValue;
|
|
|
|
// update segDetails with the suv peak for the active segmentation
|
|
const segmentation = SegmentationService.getSegmentation(
|
|
selectedSegmentationId
|
|
);
|
|
|
|
const cachedStats = {
|
|
lesionStats,
|
|
suvPeak,
|
|
lesionGlyoclysisStats,
|
|
};
|
|
|
|
const notYetUpdatedAtSource = true;
|
|
SegmentationService.addOrUpdateSegmentation(
|
|
{
|
|
...segmentation,
|
|
...Object.assign(segmentation.cachedStats, cachedStats),
|
|
displayText: [`SUV Peak: ${suvPeak.suvPeak.toFixed(2)}`],
|
|
},
|
|
notYetUpdatedAtSource
|
|
);
|
|
|
|
handleTMTVCalculation();
|
|
}, [selectedSegmentationId, config]);
|
|
|
|
/**
|
|
* Update UI based on segmentation changes (added, removed, updated)
|
|
*/
|
|
useEffect(() => {
|
|
// ~~ Subscription
|
|
const added = SegmentationService.EVENTS.SEGMENTATION_ADDED;
|
|
const updated = SegmentationService.EVENTS.SEGMENTATION_UPDATED;
|
|
const subscriptions = [];
|
|
|
|
[added, updated].forEach(evt => {
|
|
const { unsubscribe } = SegmentationService.subscribe(evt, () => {
|
|
const segmentations = SegmentationService.getSegmentations();
|
|
setSegmentations(segmentations);
|
|
});
|
|
subscriptions.push(unsubscribe);
|
|
});
|
|
|
|
return () => {
|
|
subscriptions.forEach(unsub => {
|
|
unsub();
|
|
});
|
|
};
|
|
}, []);
|
|
|
|
useEffect(() => {
|
|
const { unsubscribe } = SegmentationService.subscribe(
|
|
SegmentationService.EVENTS.SEGMENTATION_REMOVED,
|
|
() => {
|
|
const segmentations = SegmentationService.getSegmentations();
|
|
setSegmentations(segmentations);
|
|
|
|
if (segmentations.length > 0) {
|
|
setSelectedSegmentationId(segmentations[0].id);
|
|
handleTMTVCalculation();
|
|
} else {
|
|
setSelectedSegmentationId(null);
|
|
setTmtvValue(null);
|
|
}
|
|
}
|
|
);
|
|
|
|
return () => {
|
|
unsubscribe();
|
|
};
|
|
}, []);
|
|
|
|
/**
|
|
* Whenever the segmentations change, update the TMTV calculations
|
|
*/
|
|
useEffect(() => {
|
|
if (!selectedSegmentationId && segmentations.length > 0) {
|
|
setSelectedSegmentationId(segmentations[0].id);
|
|
}
|
|
|
|
handleTMTVCalculation();
|
|
}, [segmentations, selectedSegmentationId]);
|
|
|
|
return (
|
|
<div className="flex flex-col">
|
|
<div className="overflow-x-hidden overflow-y-auto invisible-scrollbar">
|
|
<div className="flex mx-4 my-4 mb-4 space-x-4">
|
|
<Button
|
|
color="primary"
|
|
onClick={() => {
|
|
setLabelmapLoading(true);
|
|
setTimeout(() => {
|
|
runCommand('createNewLabelmapFromPT').then(segmentationId => {
|
|
setLabelmapLoading(false);
|
|
setSelectedSegmentationId(segmentationId);
|
|
});
|
|
});
|
|
}}
|
|
>
|
|
{labelmapLoading ? 'loading ...' : 'New Label'}
|
|
</Button>
|
|
<Button color="primary" onClick={handleROIThresholding}>
|
|
Run
|
|
</Button>
|
|
</div>
|
|
<div
|
|
className="flex items-center justify-around h-8 mb-2 border-t outline-none cursor-pointer select-none bg-secondary-dark first:border-0 border-secondary-light"
|
|
onClick={() => {
|
|
setShowConfig(!showConfig);
|
|
}}
|
|
>
|
|
<div className="px-4 text-base text-white">
|
|
{t('ROI Threshold Configuration')}
|
|
</div>
|
|
</div>
|
|
{showConfig && (
|
|
<ROIThresholdConfiguration
|
|
config={config}
|
|
dispatch={dispatch}
|
|
runCommand={runCommand}
|
|
/>
|
|
)}
|
|
{/* show segmentation table */}
|
|
<div className="mt-4">
|
|
{segmentations?.length ? (
|
|
<SegmentationTable
|
|
title={t('Segmentations')}
|
|
segmentations={segmentations}
|
|
activeSegmentationId={selectedSegmentationId}
|
|
onClick={id => {
|
|
runCommand('setSegmentationActiveForToolGroups', {
|
|
segmentationId: id,
|
|
});
|
|
setSelectedSegmentationId(id);
|
|
}}
|
|
onToggleVisibility={id => {
|
|
SegmentationService.toggleSegmentationVisibility(id);
|
|
}}
|
|
onToggleVisibilityAll={ids => {
|
|
ids.map(id => {
|
|
SegmentationService.toggleSegmentationVisibility(id);
|
|
});
|
|
}}
|
|
onDelete={id => {
|
|
SegmentationService.remove(id);
|
|
}}
|
|
onEdit={id => {
|
|
segmentationEditHandler({
|
|
id,
|
|
servicesManager,
|
|
});
|
|
}}
|
|
/>
|
|
) : null}
|
|
</div>
|
|
{tmtvValue !== null ? (
|
|
<div className="flex items-baseline justify-between px-2 py-1 mt-4 bg-secondary-dark">
|
|
<span className="text-base font-bold tracking-widest text-white uppercase">
|
|
{'TMTV:'}
|
|
</span>
|
|
<div className="text-white">{`${tmtvValue} mL`}</div>
|
|
</div>
|
|
) : null}
|
|
<ExportReports
|
|
segmentations={segmentations}
|
|
tmtvValue={tmtvValue}
|
|
config={config}
|
|
commandsManager={commandsManager}
|
|
/>
|
|
</div>
|
|
<div
|
|
className="opacity-50 hover:opacity-80 flex items-center justify-center text-blue-400 mt-auto cursor-pointer mb-4"
|
|
onClick={() => {
|
|
// navigate to a url in a new tab
|
|
window.open(
|
|
'https://github.com/OHIF/Viewers/blob/v3-stable/modes/tmtv/README.md',
|
|
'_blank'
|
|
);
|
|
}}
|
|
>
|
|
<Icon
|
|
width="15px"
|
|
height="15px"
|
|
name={'info'}
|
|
className={'ml-4 mr-3 text-primary-active'}
|
|
/>
|
|
<span>{'User Guide'}</span>
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
PanelRoiThresholdSegmentation.propTypes = {
|
|
commandsManager: PropTypes.shape({
|
|
runCommand: PropTypes.func.isRequired,
|
|
}),
|
|
servicesManager: PropTypes.shape({
|
|
services: PropTypes.shape({
|
|
SegmentationService: PropTypes.shape({
|
|
getSegmentation: PropTypes.func.isRequired,
|
|
getSegmentations: PropTypes.func.isRequired,
|
|
toggleSegmentationVisibility: PropTypes.func.isRequired,
|
|
subscribe: PropTypes.func.isRequired,
|
|
EVENTS: PropTypes.object.isRequired,
|
|
}).isRequired,
|
|
}).isRequired,
|
|
}).isRequired,
|
|
};
|