feat: Add DICOM SEG support and MPR, referenceLines and StackSync and more (#3015)
* 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>
This commit is contained in:
1 parent
08c58b0634
commit
83ea228d86
254 files changed
+12856
-3141
No files matched your search
@@ -0,0 +1,428 @@
|
||||
import OHIF from '@ohif/core';
|
||||
import React from 'react';
|
||||
import { ContextMenuMeasurements } from '@ohif/ui';
|
||||
|
||||
import * as cornerstone from '@cornerstonejs/core';
|
||||
import * as cornerstoneTools from '@cornerstonejs/tools';
|
||||
import {
|
||||
init as cs3DInit,
|
||||
eventTarget,
|
||||
EVENTS,
|
||||
metaData,
|
||||
volumeLoader,
|
||||
imageLoader,
|
||||
imageLoadPoolManager,
|
||||
Settings,
|
||||
} from '@cornerstonejs/core';
|
||||
import { Enums, utilities, ReferenceLinesTool } from '@cornerstonejs/tools';
|
||||
import {
|
||||
cornerstoneStreamingImageVolumeLoader,
|
||||
sharedArrayBufferImageLoader,
|
||||
} from '@cornerstonejs/streaming-image-volume-loader';
|
||||
|
||||
import initWADOImageLoader from './initWADOImageLoader';
|
||||
import initCornerstoneTools from './initCornerstoneTools';
|
||||
|
||||
import { connectToolsToMeasurementService } from './initMeasurementService';
|
||||
import callInputDialog from './utils/callInputDialog';
|
||||
import initCineService from './initCineService';
|
||||
import interleaveCenterLoader from './utils/interleaveCenterLoader';
|
||||
import interleaveTopToBottom from './utils/interleaveTopToBottom';
|
||||
|
||||
const cs3DToolsEvents = Enums.Events;
|
||||
|
||||
let CONTEXT_MENU_OPEN = false;
|
||||
|
||||
// TODO: Cypress tests are currently grabbing this from the window?
|
||||
window.cornerstone = cornerstone;
|
||||
window.cornerstoneTools = cornerstoneTools;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
export default async function init({
|
||||
servicesManager,
|
||||
commandsManager,
|
||||
configuration,
|
||||
appConfig,
|
||||
}) {
|
||||
await cs3DInit();
|
||||
|
||||
// For debugging e2e tests that are failing on CI
|
||||
cornerstone.setUseCPURendering(Boolean(appConfig.useCPURendering));
|
||||
|
||||
// For debugging large datasets
|
||||
const MAX_CACHE_SIZE_1GB = 1073741824;
|
||||
const maxCacheSize = appConfig.maxCacheSize;
|
||||
cornerstone.cache.setMaxCacheSize(
|
||||
maxCacheSize ? maxCacheSize : MAX_CACHE_SIZE_1GB
|
||||
);
|
||||
|
||||
initCornerstoneTools();
|
||||
|
||||
Settings.getRuntimeSettings().set(
|
||||
'useCursors',
|
||||
Boolean(appConfig.useCursors)
|
||||
);
|
||||
|
||||
const {
|
||||
UserAuthenticationService,
|
||||
MeasurementService,
|
||||
DisplaySetService,
|
||||
UIDialogService,
|
||||
UIModalService,
|
||||
CineService,
|
||||
CornerstoneViewportService,
|
||||
HangingProtocolService,
|
||||
ToolGroupService,
|
||||
SegmentationService,
|
||||
ViewportGridService,
|
||||
} = servicesManager.services;
|
||||
|
||||
window.SegmentationService = SegmentationService;
|
||||
window.DisplaySetService = DisplaySetService;
|
||||
window.services = servicesManager.services;
|
||||
|
||||
if (cornerstone.getShouldUseCPURendering()) {
|
||||
_showCPURenderingModal(UIModalService, HangingProtocolService);
|
||||
}
|
||||
|
||||
const labelmapRepresentation =
|
||||
cornerstoneTools.Enums.SegmentationRepresentations.Labelmap;
|
||||
|
||||
cornerstoneTools.segmentation.config.setGlobalRepresentationConfig(
|
||||
labelmapRepresentation,
|
||||
{
|
||||
fillAlpha: 0.3,
|
||||
fillAlphaInactive: 0.2,
|
||||
outlineOpacity: 1,
|
||||
outlineOpacityInactive: 0.65,
|
||||
}
|
||||
);
|
||||
|
||||
const metadataProvider = OHIF.classes.MetadataProvider;
|
||||
|
||||
volumeLoader.registerVolumeLoader(
|
||||
'cornerstoneStreamingImageVolume',
|
||||
cornerstoneStreamingImageVolumeLoader
|
||||
);
|
||||
|
||||
HangingProtocolService.registerImageLoadStrategy(
|
||||
'interleaveCenter',
|
||||
interleaveCenterLoader
|
||||
);
|
||||
HangingProtocolService.registerImageLoadStrategy(
|
||||
'interleaveTopToBottom',
|
||||
interleaveTopToBottom
|
||||
);
|
||||
|
||||
imageLoader.registerImageLoader(
|
||||
'streaming-wadors',
|
||||
sharedArrayBufferImageLoader
|
||||
);
|
||||
|
||||
metaData.addProvider(metadataProvider.get.bind(metadataProvider), 9999);
|
||||
|
||||
imageLoadPoolManager.maxNumRequests = {
|
||||
interaction: appConfig?.maxNumRequests?.interaction || 100,
|
||||
thumbnail: appConfig?.maxNumRequests?.thumbnail || 75,
|
||||
prefetch: appConfig?.maxNumRequests?.prefetch || 10,
|
||||
};
|
||||
|
||||
initWADOImageLoader(UserAuthenticationService, appConfig);
|
||||
|
||||
/* Measurement Service */
|
||||
const measurementServiceSource = connectToolsToMeasurementService(
|
||||
MeasurementService,
|
||||
DisplaySetService,
|
||||
CornerstoneViewportService
|
||||
);
|
||||
|
||||
initCineService(CineService);
|
||||
|
||||
const _getDefaultPosition = event => ({
|
||||
x: (event && event.currentPoints.client[0]) || 0,
|
||||
y: (event && event.currentPoints.client[1]) || 0,
|
||||
});
|
||||
|
||||
const onRightClick = event => {
|
||||
if (!UIDialogService) {
|
||||
console.warn('Unable to show dialog; no UI Dialog Service available.');
|
||||
return;
|
||||
}
|
||||
|
||||
const onGetMenuItems = defaultMenuItems => {
|
||||
const { element, currentPoints } = event.detail;
|
||||
|
||||
const nearbyToolData = utilities.getAnnotationNearPoint(
|
||||
element,
|
||||
currentPoints.canvas
|
||||
);
|
||||
|
||||
const menuItems = [];
|
||||
if (nearbyToolData && nearbyToolData.metadata.toolName !== 'Crosshairs') {
|
||||
defaultMenuItems.forEach(item => {
|
||||
item.value = nearbyToolData;
|
||||
item.element = element;
|
||||
menuItems.push(item);
|
||||
});
|
||||
}
|
||||
|
||||
return menuItems;
|
||||
};
|
||||
|
||||
CONTEXT_MENU_OPEN = true;
|
||||
|
||||
UIDialogService.dismiss({ id: 'context-menu' });
|
||||
UIDialogService.create({
|
||||
id: 'context-menu',
|
||||
isDraggable: false,
|
||||
preservePosition: false,
|
||||
defaultPosition: _getDefaultPosition(event.detail),
|
||||
content: ContextMenuMeasurements,
|
||||
onClickOutside: () => {
|
||||
UIDialogService.dismiss({ id: 'context-menu' });
|
||||
CONTEXT_MENU_OPEN = false;
|
||||
},
|
||||
contentProps: {
|
||||
onGetMenuItems,
|
||||
eventData: event.detail,
|
||||
onDelete: item => {
|
||||
const { annotationUID } = item.value;
|
||||
|
||||
const uid = annotationUID;
|
||||
// Sync'd w/ Measurement Service
|
||||
if (uid) {
|
||||
measurementServiceSource.remove(uid, {
|
||||
element: item.element,
|
||||
});
|
||||
}
|
||||
CONTEXT_MENU_OPEN = false;
|
||||
},
|
||||
onClose: () => {
|
||||
CONTEXT_MENU_OPEN = false;
|
||||
UIDialogService.dismiss({ id: 'context-menu' });
|
||||
},
|
||||
onSetLabel: item => {
|
||||
const { annotationUID } = item.value;
|
||||
|
||||
const measurement = MeasurementService.getMeasurement(annotationUID);
|
||||
|
||||
callInputDialog(
|
||||
UIDialogService,
|
||||
measurement,
|
||||
(label, actionId) => {
|
||||
if (actionId === 'cancel') {
|
||||
return;
|
||||
}
|
||||
|
||||
const updatedMeasurement = Object.assign({}, measurement, {
|
||||
label,
|
||||
});
|
||||
|
||||
MeasurementService.update(
|
||||
updatedMeasurement.uid,
|
||||
updatedMeasurement,
|
||||
true
|
||||
);
|
||||
},
|
||||
false
|
||||
);
|
||||
|
||||
CONTEXT_MENU_OPEN = false;
|
||||
},
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
const resetContextMenu = () => {
|
||||
if (!UIDialogService) {
|
||||
console.warn('Unable to show dialog; no UI Dialog Service available.');
|
||||
return;
|
||||
}
|
||||
|
||||
CONTEXT_MENU_OPEN = false;
|
||||
|
||||
UIDialogService.dismiss({ id: 'context-menu' });
|
||||
};
|
||||
|
||||
// When a custom image load is performed, update the relevant viewports
|
||||
HangingProtocolService.subscribe(
|
||||
HangingProtocolService.EVENTS.CUSTOM_IMAGE_LOAD_PERFORMED,
|
||||
volumeInputArrayMap => {
|
||||
for (const entry of volumeInputArrayMap.entries()) {
|
||||
const [viewportId, volumeInputArray] = entry;
|
||||
const viewport = CornerstoneViewportService.getCornerstoneViewport(
|
||||
viewportId
|
||||
);
|
||||
|
||||
CornerstoneViewportService.setVolumesForViewport(
|
||||
viewport,
|
||||
volumeInputArray
|
||||
);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
/*
|
||||
* Because click gives us the native "mouse up", buttons will always be `0`
|
||||
* Need to fallback to event.which;
|
||||
*
|
||||
*/
|
||||
const contextMenuHandleClick = evt => {
|
||||
const mouseUpEvent = evt.detail.event;
|
||||
const isRightClick = mouseUpEvent.which === 3;
|
||||
|
||||
const clickMethodHandler = isRightClick ? onRightClick : resetContextMenu;
|
||||
clickMethodHandler(evt);
|
||||
};
|
||||
|
||||
// const cancelContextMenuIfOpen = evt => {
|
||||
// if (CONTEXT_MENU_OPEN) {
|
||||
// resetContextMenu();
|
||||
// }
|
||||
// };
|
||||
|
||||
const newStackCallback = evt => {
|
||||
const { element } = evt.detail;
|
||||
utilities.stackPrefetch.enable(element);
|
||||
};
|
||||
|
||||
const resetCrosshairs = evt => {
|
||||
const { element } = evt.detail;
|
||||
const { viewportId, renderingEngineId } = cornerstone.getEnabledElement(
|
||||
element
|
||||
);
|
||||
|
||||
const toolGroup = cornerstoneTools.ToolGroupManager.getToolGroupForViewport(
|
||||
viewportId,
|
||||
renderingEngineId
|
||||
);
|
||||
|
||||
if (!toolGroup || !toolGroup._toolInstances?.['Crosshairs']) {
|
||||
return;
|
||||
}
|
||||
|
||||
const mode = toolGroup._toolInstances['Crosshairs'].mode;
|
||||
|
||||
if (mode === Enums.ToolModes.Active) {
|
||||
toolGroup.setToolActive('Crosshairs');
|
||||
} else if (mode === Enums.ToolModes.Passive) {
|
||||
toolGroup.setToolPassive('Crosshairs');
|
||||
} else if (mode === Enums.ToolModes.Enabled) {
|
||||
toolGroup.setToolEnabled('Crosshairs');
|
||||
}
|
||||
};
|
||||
|
||||
function elementEnabledHandler(evt) {
|
||||
const { element } = evt.detail;
|
||||
|
||||
element.addEventListener(
|
||||
cs3DToolsEvents.MOUSE_CLICK,
|
||||
contextMenuHandleClick
|
||||
);
|
||||
|
||||
element.addEventListener(EVENTS.CAMERA_RESET, resetCrosshairs);
|
||||
|
||||
eventTarget.addEventListener(
|
||||
EVENTS.STACK_VIEWPORT_NEW_STACK,
|
||||
newStackCallback
|
||||
);
|
||||
}
|
||||
|
||||
function elementDisabledHandler(evt) {
|
||||
const { element } = evt.detail;
|
||||
|
||||
element.removeEventListener(
|
||||
cs3DToolsEvents.MOUSE_CLICK,
|
||||
contextMenuHandleClick
|
||||
);
|
||||
|
||||
element.removeEventListener(EVENTS.CAMERA_RESET, resetCrosshairs);
|
||||
|
||||
// TODO - consider removing the callback when all elements are gone
|
||||
// eventTarget.removeEventListener(
|
||||
// EVENTS.STACK_VIEWPORT_NEW_STACK,
|
||||
// newStackCallback
|
||||
// );
|
||||
}
|
||||
|
||||
eventTarget.addEventListener(
|
||||
EVENTS.ELEMENT_ENABLED,
|
||||
elementEnabledHandler.bind(null)
|
||||
);
|
||||
|
||||
eventTarget.addEventListener(
|
||||
EVENTS.ELEMENT_DISABLED,
|
||||
elementDisabledHandler.bind(null)
|
||||
);
|
||||
|
||||
ViewportGridService.subscribe(
|
||||
ViewportGridService.EVENTS.ACTIVE_VIEWPORT_INDEX_CHANGED,
|
||||
({ viewportIndex }) => {
|
||||
const viewportId = `viewport-${viewportIndex}`;
|
||||
const toolGroup = ToolGroupService.getToolGroupForViewport(viewportId);
|
||||
|
||||
if (!toolGroup) {
|
||||
return;
|
||||
}
|
||||
|
||||
// check if reference lines are active
|
||||
const referenceLinesEnabled =
|
||||
toolGroup._toolInstances?.['ReferenceLines'].mode ===
|
||||
Enums.ToolModes.Enabled;
|
||||
|
||||
if (!referenceLinesEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
toolGroup.setToolConfiguration(
|
||||
ReferenceLinesTool.toolName,
|
||||
{
|
||||
sourceViewportId: viewportId,
|
||||
},
|
||||
true // overwrite
|
||||
);
|
||||
|
||||
// make sure to set it to enabled again since we want to recalculate
|
||||
// the source-target lines
|
||||
toolGroup.setToolEnabled(ReferenceLinesTool.toolName);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
function CPUModal() {
|
||||
return (
|
||||
<div>
|
||||
<p>
|
||||
Your computer does not have enough GPU power to support the default GPU
|
||||
rendering mode. OHIF has switched to CPU rendering mode. Please note
|
||||
that CPU rendering does not support all features such as Volume
|
||||
Rendering, Multiplanar Reconstruction, and Segmentation Overlays.
|
||||
</p>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function _showCPURenderingModal(UIModalService, HangingProtocolService) {
|
||||
const callback = progress => {
|
||||
if (progress === 100) {
|
||||
UIModalService.show({
|
||||
content: CPUModal,
|
||||
title: 'OHIF Fell Back to CPU Rendering',
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
const { unsubscribe } = HangingProtocolService.subscribe(
|
||||
HangingProtocolService.EVENTS.HANGING_PROTOCOL_APPLIED_FOR_VIEWPORT,
|
||||
({ progress }) => {
|
||||
const done = callback(progress);
|
||||
|
||||
if (done) {
|
||||
unsubscribe();
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user