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
@@ -8,10 +8,11 @@ import {
|
||||
eventTarget,
|
||||
getEnabledElement,
|
||||
StackViewport,
|
||||
utilities as csUtils,
|
||||
CONSTANTS,
|
||||
} from '@cornerstonejs/core';
|
||||
|
||||
import { setEnabledElement } from '../state';
|
||||
import CornerstoneCacheService from '../services/ViewportService/CornerstoneCacheService';
|
||||
|
||||
import './OHIFCornerstoneViewport.css';
|
||||
import CornerstoneOverlays from './Overlays/CornerstoneOverlays';
|
||||
@@ -46,24 +47,44 @@ function areEqual(prevProps, nextProps) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const prevDisplaySets = prevProps.displaySets[0];
|
||||
const nextDisplaySets = nextProps.displaySets[0];
|
||||
const prevDisplaySets = prevProps.displaySets;
|
||||
const nextDisplaySets = nextProps.displaySets;
|
||||
|
||||
if (prevDisplaySets && nextDisplaySets) {
|
||||
const areSameDisplaySetInstanceUIDs =
|
||||
prevDisplaySets.displaySetInstanceUID ===
|
||||
nextDisplaySets.displaySetInstanceUID;
|
||||
const areSameImageLength =
|
||||
prevDisplaySets.images.length === nextDisplaySets.images.length;
|
||||
const areSameImageIds = prevDisplaySets.images.every(
|
||||
(prevImage, index) =>
|
||||
prevImage.imageId === nextDisplaySets.images[index].imageId
|
||||
);
|
||||
return (
|
||||
areSameDisplaySetInstanceUIDs && areSameImageLength && areSameImageIds
|
||||
);
|
||||
if (prevDisplaySets.length !== nextDisplaySets.length) {
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
|
||||
for (let i = 0; i < prevDisplaySets.length; i++) {
|
||||
const prevDisplaySet = prevDisplaySets[i];
|
||||
|
||||
const foundDisplaySet = nextDisplaySets.find(
|
||||
nextDisplaySet =>
|
||||
nextDisplaySet.displaySetInstanceUID ===
|
||||
prevDisplaySet.displaySetInstanceUID
|
||||
);
|
||||
|
||||
if (!foundDisplaySet) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// check they contain the same image
|
||||
if (foundDisplaySet.images?.length !== prevDisplaySet.images?.length) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// check if their imageIds are the same
|
||||
if (foundDisplaySet.images?.length) {
|
||||
for (let j = 0; j < foundDisplaySet.images.length; j++) {
|
||||
if (
|
||||
foundDisplaySet.images[j].imageId !== prevDisplaySet.images[j].imageId
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Todo: This should be done with expose of internal API similar to react-vtkjs-viewport
|
||||
@@ -85,8 +106,6 @@ const OHIFCornerstoneViewport = React.memo(props => {
|
||||
} = props;
|
||||
|
||||
const [scrollbarHeight, setScrollbarHeight] = useState('100px');
|
||||
const [viewportData, setViewportData] = useState(null);
|
||||
const [_, viewportGridService] = useViewportGrid();
|
||||
|
||||
const elementRef = useRef();
|
||||
|
||||
@@ -97,6 +116,8 @@ const OHIFCornerstoneViewport = React.memo(props => {
|
||||
ToolGroupService,
|
||||
SyncGroupService,
|
||||
CornerstoneViewportService,
|
||||
CornerstoneCacheService,
|
||||
ViewportGridService,
|
||||
} = servicesManager.services;
|
||||
|
||||
// useCallback for scroll bar height calculation
|
||||
@@ -153,7 +174,7 @@ const OHIFCornerstoneViewport = React.memo(props => {
|
||||
|
||||
// disable the element upon unmounting
|
||||
useEffect(() => {
|
||||
CornerstoneViewportService.enableElement(
|
||||
CornerstoneViewportService.enableViewport(
|
||||
viewportIndex,
|
||||
viewportOptions,
|
||||
elementRef.current
|
||||
@@ -175,7 +196,11 @@ const OHIFCornerstoneViewport = React.memo(props => {
|
||||
const renderingEngineId = viewportInfo.getRenderingEngineId();
|
||||
const syncGroups = viewportInfo.getSyncGroups();
|
||||
|
||||
ToolGroupService.disable(viewportId, renderingEngineId);
|
||||
ToolGroupService.removeViewportFromToolGroup(
|
||||
viewportId,
|
||||
renderingEngineId
|
||||
);
|
||||
|
||||
SyncGroupService.removeViewportFromSyncGroup(
|
||||
viewportId,
|
||||
renderingEngineId,
|
||||
@@ -184,14 +209,14 @@ const OHIFCornerstoneViewport = React.memo(props => {
|
||||
|
||||
CornerstoneViewportService.disableElement(viewportIndex);
|
||||
|
||||
if (onElementDisabled) {
|
||||
onElementDisabled(viewportInfo);
|
||||
}
|
||||
|
||||
eventTarget.removeEventListener(
|
||||
Enums.Events.ELEMENT_ENABLED,
|
||||
elementEnabledHandler
|
||||
);
|
||||
|
||||
if (onElementDisabled) {
|
||||
onElementDisabled();
|
||||
}
|
||||
};
|
||||
}, []);
|
||||
|
||||
@@ -207,11 +232,12 @@ const OHIFCornerstoneViewport = React.memo(props => {
|
||||
const { unsubscribe } = DisplaySetService.subscribe(
|
||||
DisplaySetService.EVENTS.DISPLAY_SET_SERIES_METADATA_INVALIDATED,
|
||||
async invalidatedDisplaySetInstanceUID => {
|
||||
if (
|
||||
viewportData.displaySetInstanceUIDs.includes(
|
||||
invalidatedDisplaySetInstanceUID
|
||||
)
|
||||
) {
|
||||
const viewportInfo = CornerstoneViewportService.getViewportInfoByIndex(
|
||||
viewportIndex
|
||||
);
|
||||
|
||||
if (viewportInfo.hasDisplaySet(invalidatedDisplaySetInstanceUID)) {
|
||||
const viewportData = viewportInfo.getViewportData();
|
||||
const newViewportData = await CornerstoneCacheService.invalidateViewportData(
|
||||
viewportData,
|
||||
invalidatedDisplaySetInstanceUID,
|
||||
@@ -225,15 +251,13 @@ const OHIFCornerstoneViewport = React.memo(props => {
|
||||
newViewportData,
|
||||
keepCamera
|
||||
);
|
||||
|
||||
setViewportData(newViewportData);
|
||||
}
|
||||
}
|
||||
);
|
||||
return () => {
|
||||
unsubscribe();
|
||||
};
|
||||
}, [viewportData, viewportIndex]);
|
||||
}, [viewportIndex]);
|
||||
|
||||
useEffect(() => {
|
||||
// handle the default viewportType to be stack
|
||||
@@ -242,22 +266,19 @@ const OHIFCornerstoneViewport = React.memo(props => {
|
||||
}
|
||||
|
||||
const loadViewportData = async () => {
|
||||
await CornerstoneCacheService.getViewportData(
|
||||
viewportIndex,
|
||||
const viewportData = await CornerstoneCacheService.createViewportData(
|
||||
displaySets,
|
||||
viewportOptions.viewportType,
|
||||
viewportOptions,
|
||||
dataSource,
|
||||
viewportDataLoaded => {
|
||||
CornerstoneViewportService.setViewportDisplaySets(
|
||||
viewportIndex,
|
||||
viewportDataLoaded,
|
||||
viewportOptions,
|
||||
displaySetOptions
|
||||
);
|
||||
setViewportData(viewportDataLoaded);
|
||||
},
|
||||
initialImageIndex
|
||||
);
|
||||
|
||||
CornerstoneViewportService.setViewportData(
|
||||
viewportIndex,
|
||||
viewportData,
|
||||
viewportOptions,
|
||||
displaySetOptions
|
||||
);
|
||||
};
|
||||
|
||||
loadViewportData();
|
||||
@@ -280,7 +301,8 @@ const OHIFCornerstoneViewport = React.memo(props => {
|
||||
elementRef,
|
||||
viewportIndex,
|
||||
displaySets,
|
||||
viewportGridService
|
||||
ViewportGridService,
|
||||
CornerstoneViewportService
|
||||
);
|
||||
|
||||
_checkForCachedJumpToMeasurementEvents(
|
||||
@@ -289,13 +311,14 @@ const OHIFCornerstoneViewport = React.memo(props => {
|
||||
elementRef,
|
||||
viewportIndex,
|
||||
displaySets,
|
||||
viewportGridService
|
||||
ViewportGridService,
|
||||
CornerstoneViewportService
|
||||
);
|
||||
|
||||
return () => {
|
||||
unsubscribeFromJumpToMeasurementEvents();
|
||||
};
|
||||
}, [displaySets, elementRef, viewportIndex, viewportData]);
|
||||
}, [displaySets, elementRef, viewportIndex]);
|
||||
|
||||
return (
|
||||
<div className="viewport-wrapper">
|
||||
@@ -303,7 +326,7 @@ const OHIFCornerstoneViewport = React.memo(props => {
|
||||
handleWidth
|
||||
handleHeight
|
||||
skipOnMount={true} // Todo: make these configurable
|
||||
refreshMode={'debounce'}
|
||||
refreshMode={'throttle'}
|
||||
refreshRate={100}
|
||||
onResize={onResize}
|
||||
targetRef={elementRef.current}
|
||||
@@ -332,7 +355,8 @@ function _subscribeToJumpToMeasurementEvents(
|
||||
elementRef,
|
||||
viewportIndex,
|
||||
displaySets,
|
||||
viewportGridService
|
||||
viewportGridService,
|
||||
CornerstoneViewportService
|
||||
) {
|
||||
const displaysUIDs = displaySets.map(
|
||||
displaySet => displaySet.displaySetInstanceUID
|
||||
@@ -350,7 +374,8 @@ function _subscribeToJumpToMeasurementEvents(
|
||||
viewportIndex,
|
||||
MeasurementService,
|
||||
DisplaySetService,
|
||||
viewportGridService
|
||||
ViewportGridService,
|
||||
CornerstoneViewportService
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -366,7 +391,8 @@ function _checkForCachedJumpToMeasurementEvents(
|
||||
elementRef,
|
||||
viewportIndex,
|
||||
displaySets,
|
||||
viewportGridService
|
||||
ViewportGridService,
|
||||
CornerstoneViewportService
|
||||
) {
|
||||
const displaysUIDs = displaySets.map(
|
||||
displaySet => displaySet.displaySetInstanceUID
|
||||
@@ -389,7 +415,8 @@ function _checkForCachedJumpToMeasurementEvents(
|
||||
viewportIndex,
|
||||
MeasurementService,
|
||||
DisplaySetService,
|
||||
viewportGridService
|
||||
ViewportGridService,
|
||||
CornerstoneViewportService
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -401,7 +428,8 @@ function _jumpToMeasurement(
|
||||
viewportIndex,
|
||||
MeasurementService,
|
||||
DisplaySetService,
|
||||
viewportGridService
|
||||
ViewportGridService,
|
||||
CornerstoneViewportService
|
||||
) {
|
||||
const targetElement = targetElementRef.current;
|
||||
const { displaySetInstanceUID, SOPInstanceUID, frameNumber } = measurement;
|
||||
@@ -418,14 +446,20 @@ function _jumpToMeasurement(
|
||||
// to set it properly
|
||||
// setCornerstoneMeasurementActive(measurement);
|
||||
|
||||
viewportGridService.setActiveViewportIndex(viewportIndex);
|
||||
ViewportGridService.setActiveViewportIndex(viewportIndex);
|
||||
|
||||
const enableElement = getEnabledElement(targetElement);
|
||||
|
||||
const viewportInfo = CornerstoneViewportService.getViewportInfoByIndex(
|
||||
viewportIndex
|
||||
);
|
||||
|
||||
if (enableElement) {
|
||||
// See how the jumpToSlice() of Cornerstone3D deals with imageIdx param.
|
||||
const viewport = enableElement.viewport as IStackViewport | IVolumeViewport;
|
||||
|
||||
let imageIdIndex = 0;
|
||||
let viewportCameraDirectionMatch = true;
|
||||
|
||||
if (viewport instanceof StackViewport) {
|
||||
const imageIds = viewport.getImageIds();
|
||||
@@ -440,9 +474,29 @@ function _jumpToMeasurement(
|
||||
);
|
||||
});
|
||||
} else {
|
||||
// for volume viewport we can't rely on the imageIdIndex since it can be
|
||||
// a reconstructed view that doesn't match the original slice numbers etc.
|
||||
const { viewPlaneNormal } = measurement.metadata;
|
||||
imageIdIndex = referencedDisplaySet.images.findIndex(
|
||||
i => i.SOPInstanceUID === SOPInstanceUID
|
||||
);
|
||||
|
||||
const { orientation } = viewportInfo.getViewportOptions();
|
||||
|
||||
if (
|
||||
orientation &&
|
||||
viewPlaneNormal &&
|
||||
!csUtils.isEqual(
|
||||
CONSTANTS.MPR_CAMERA_VALUES[orientation]?.viewPlaneNormal,
|
||||
viewPlaneNormal
|
||||
)
|
||||
) {
|
||||
viewportCameraDirectionMatch = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!viewportCameraDirectionMatch || imageIdIndex === -1) {
|
||||
return;
|
||||
}
|
||||
|
||||
cs3DTools.utilities.jumpToSlice(targetElement, {
|
||||
|
||||
@@ -3,8 +3,7 @@ import React, { useEffect, useState } from 'react';
|
||||
import ViewportImageScrollbar from './ViewportImageScrollbar';
|
||||
import ViewportOverlay from './ViewportOverlay';
|
||||
import ViewportOrientationMarkers from './ViewportOrientationMarkers';
|
||||
import ViewportLoadingIndicator from './ViewportLoadingIndicator';
|
||||
import CornerstoneCacheService from '../../services/ViewportService/CornerstoneCacheService';
|
||||
import ViewportImageSliceLoadingIndicator from './ViewportImageSliceLoadingIndicator';
|
||||
|
||||
function CornerstoneOverlays(props) {
|
||||
const { viewportIndex, element, scrollbarHeight, servicesManager } = props;
|
||||
@@ -16,8 +15,8 @@ function CornerstoneOverlays(props) {
|
||||
const [viewportData, setViewportData] = useState(null);
|
||||
|
||||
useEffect(() => {
|
||||
const { unsubscribe } = CornerstoneCacheService.subscribe(
|
||||
CornerstoneCacheService.EVENTS.VIEWPORT_DATA_CHANGED,
|
||||
const { unsubscribe } = CornerstoneViewportService.subscribe(
|
||||
CornerstoneViewportService.EVENTS.VIEWPORT_DATA_CHANGED,
|
||||
props => {
|
||||
if (props.viewportIndex !== viewportIndex) {
|
||||
return;
|
||||
@@ -47,7 +46,7 @@ function CornerstoneOverlays(props) {
|
||||
}
|
||||
|
||||
return (
|
||||
<div>
|
||||
<div className="noselect">
|
||||
<ViewportImageScrollbar
|
||||
viewportIndex={viewportIndex}
|
||||
viewportData={viewportData}
|
||||
@@ -64,11 +63,15 @@ function CornerstoneOverlays(props) {
|
||||
servicesManager={servicesManager}
|
||||
element={element}
|
||||
/>
|
||||
<ViewportLoadingIndicator viewportData={viewportData} element={element} />
|
||||
<ViewportImageSliceLoadingIndicator
|
||||
viewportData={viewportData}
|
||||
element={element}
|
||||
/>
|
||||
<ViewportOrientationMarkers
|
||||
imageSliceData={imageSliceData}
|
||||
element={element}
|
||||
viewportData={viewportData}
|
||||
servicesManager={servicesManager}
|
||||
viewportIndex={viewportIndex}
|
||||
/>
|
||||
</div>
|
||||
|
||||
@@ -57,7 +57,7 @@ function CornerstoneImageScrollbar({
|
||||
|
||||
setImageSliceData({
|
||||
imageIndex: imageIndex,
|
||||
numberOfSlices: viewportData.imageIds.length,
|
||||
numberOfSlices: viewportData.data.imageIds.length,
|
||||
});
|
||||
|
||||
return;
|
||||
@@ -87,7 +87,7 @@ function CornerstoneImageScrollbar({
|
||||
// find the index of imageId in the imageIds
|
||||
setImageSliceData({
|
||||
imageIndex: newImageIdIndex,
|
||||
numberOfSlices: viewportData.imageIds.length,
|
||||
numberOfSlices: viewportData.data.imageIds.length,
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
+4
-4
@@ -2,7 +2,7 @@ import React, { useEffect, useState, useRef } from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import { Enums } from '@cornerstonejs/core';
|
||||
|
||||
function ViewportLoadingIndicator({ viewportData, element }) {
|
||||
function ViewportImageSliceLoadingIndicator({ viewportData, element }) {
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [error, setError] = useState(false);
|
||||
|
||||
@@ -89,15 +89,15 @@ function ViewportLoadingIndicator({ viewportData, element }) {
|
||||
return null;
|
||||
}
|
||||
|
||||
ViewportLoadingIndicator.propTypes = {
|
||||
ViewportImageSliceLoadingIndicator.propTypes = {
|
||||
percentComplete: PropTypes.number,
|
||||
error: PropTypes.object,
|
||||
element: PropTypes.object,
|
||||
};
|
||||
|
||||
ViewportLoadingIndicator.defaultProps = {
|
||||
ViewportImageSliceLoadingIndicator.defaultProps = {
|
||||
percentComplete: 0,
|
||||
error: null,
|
||||
};
|
||||
|
||||
export default ViewportLoadingIndicator;
|
||||
export default ViewportImageSliceLoadingIndicator;
|
||||
@@ -11,7 +11,7 @@
|
||||
position: absolute;
|
||||
}
|
||||
.ViewportOrientationMarkers .top-mid {
|
||||
top: 5px;
|
||||
top: 0.6rem;
|
||||
left: 50%;
|
||||
}
|
||||
.ViewportOrientationMarkers .left-mid {
|
||||
@@ -23,7 +23,7 @@
|
||||
left: calc(100% - var(--marker-width) - var(--scrollbar-width));
|
||||
}
|
||||
.ViewportOrientationMarkers .bottom-mid {
|
||||
top: calc(100% - var(--marker-height) - 5px);
|
||||
top: calc(100% - var(--marker-height) - 0.6rem);
|
||||
left: 47%;
|
||||
}
|
||||
.ViewportOrientationMarkers .right-mid .orientation-marker-value {
|
||||
|
||||
@@ -1,10 +1,158 @@
|
||||
import React, { useEffect, useState, useCallback } from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import { metaData, Enums, Types } from '@cornerstonejs/core';
|
||||
import React, { useEffect, useState, useMemo } from 'react';
|
||||
import {
|
||||
metaData,
|
||||
Enums,
|
||||
Types,
|
||||
getEnabledElement,
|
||||
utilities as csUtils,
|
||||
} from '@cornerstonejs/core';
|
||||
import { utilities } from '@cornerstonejs/tools';
|
||||
import PropTypes from 'prop-types';
|
||||
import { vec3 } from 'gl-matrix';
|
||||
|
||||
import './ViewportOrientationMarkers.css';
|
||||
import { getEnabledElement } from '../../state';
|
||||
|
||||
const {
|
||||
getOrientationStringLPS,
|
||||
invertOrientationStringLPS,
|
||||
} = utilities.orientation;
|
||||
|
||||
function ViewportOrientationMarkers({
|
||||
element,
|
||||
viewportData,
|
||||
imageSliceData,
|
||||
viewportIndex,
|
||||
servicesManager,
|
||||
orientationMarkers = ['top', 'left'],
|
||||
}) {
|
||||
// Rotation is in degrees
|
||||
const [rotation, setRotation] = useState(0);
|
||||
const [flipHorizontal, setFlipHorizontal] = useState(false);
|
||||
const [flipVertical, setFlipVertical] = useState(false);
|
||||
const { CornerstoneViewportService } = servicesManager.services;
|
||||
|
||||
useEffect(() => {
|
||||
const cameraModifiedListener = (
|
||||
evt: Types.EventTypes.CameraModifiedEvent
|
||||
) => {
|
||||
const { rotation, previousCamera, camera } = evt.detail;
|
||||
|
||||
if (rotation !== undefined) {
|
||||
setRotation(rotation);
|
||||
}
|
||||
|
||||
if (
|
||||
camera.flipHorizontal !== undefined &&
|
||||
previousCamera.flipHorizontal !== camera.flipHorizontal
|
||||
) {
|
||||
setFlipHorizontal(camera.flipHorizontal);
|
||||
}
|
||||
|
||||
if (
|
||||
camera.flipVertical !== undefined &&
|
||||
previousCamera.flipVertical !== camera.flipVertical
|
||||
) {
|
||||
setFlipVertical(camera.flipVertical);
|
||||
}
|
||||
};
|
||||
|
||||
element.addEventListener(
|
||||
Enums.Events.CAMERA_MODIFIED,
|
||||
cameraModifiedListener
|
||||
);
|
||||
|
||||
return () => {
|
||||
element.removeEventListener(
|
||||
Enums.Events.CAMERA_MODIFIED,
|
||||
cameraModifiedListener
|
||||
);
|
||||
};
|
||||
}, []);
|
||||
|
||||
const markers = useMemo(() => {
|
||||
if (!viewportData) {
|
||||
return '';
|
||||
}
|
||||
|
||||
let rowCosines, columnCosines;
|
||||
if (viewportData.viewportType === 'stack') {
|
||||
const imageIndex = imageSliceData.imageIndex;
|
||||
const imageId = viewportData.data.imageIds?.[imageIndex];
|
||||
|
||||
// Workaround for below TODO stub
|
||||
if (!imageId) {
|
||||
return false;
|
||||
}
|
||||
|
||||
({ rowCosines, columnCosines } =
|
||||
metaData.get('imagePlaneModule', imageId) || {});
|
||||
} else {
|
||||
if (!element || !getEnabledElement(element)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
const { viewport } = getEnabledElement(element);
|
||||
const { viewUp, viewPlaneNormal } = viewport.getCamera();
|
||||
|
||||
const viewRight = vec3.create();
|
||||
vec3.cross(viewRight, viewUp, viewPlaneNormal);
|
||||
|
||||
columnCosines = [-viewUp[0], -viewUp[1], -viewUp[2]];
|
||||
rowCosines = viewRight;
|
||||
}
|
||||
|
||||
if (!rowCosines || !columnCosines || rotation === undefined) {
|
||||
return '';
|
||||
}
|
||||
|
||||
const markers = _getOrientationMarkers(
|
||||
rowCosines,
|
||||
columnCosines,
|
||||
rotation,
|
||||
flipVertical,
|
||||
flipHorizontal
|
||||
);
|
||||
|
||||
const ohifViewport = CornerstoneViewportService.getViewportInfoByIndex(
|
||||
viewportIndex
|
||||
);
|
||||
|
||||
const backgroundColor = ohifViewport.getViewportOptions().background;
|
||||
|
||||
const isLight = backgroundColor
|
||||
? csUtils.isEqual(backgroundColor, [1, 1, 1])
|
||||
: false;
|
||||
|
||||
return orientationMarkers.map((m, index) => (
|
||||
<div
|
||||
className={`${m}-mid orientation-marker`}
|
||||
key={`${m}-mid orientation-marker`}
|
||||
>
|
||||
<div className="orientation-marker-value">{markers[m]}</div>
|
||||
</div>
|
||||
));
|
||||
}, [
|
||||
viewportData,
|
||||
imageSliceData,
|
||||
rotation,
|
||||
flipVertical,
|
||||
flipHorizontal,
|
||||
orientationMarkers,
|
||||
element,
|
||||
]);
|
||||
|
||||
return <div className="ViewportOrientationMarkers noselect">{markers}</div>;
|
||||
}
|
||||
|
||||
ViewportOrientationMarkers.propTypes = {
|
||||
percentComplete: PropTypes.number,
|
||||
error: PropTypes.object,
|
||||
};
|
||||
|
||||
ViewportOrientationMarkers.defaultProps = {
|
||||
percentComplete: 0,
|
||||
error: null,
|
||||
};
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -16,17 +164,13 @@ import { getEnabledElement } from '../../state';
|
||||
* @param {*} rotation in degrees
|
||||
* @returns
|
||||
*/
|
||||
function getOrientationMarkers(
|
||||
function _getOrientationMarkers(
|
||||
rowCosines,
|
||||
columnCosines,
|
||||
rotation,
|
||||
flipVertical,
|
||||
flipHorizontal
|
||||
) {
|
||||
const {
|
||||
getOrientationStringLPS,
|
||||
invertOrientationStringLPS,
|
||||
} = utilities.orientation;
|
||||
const rowString = getOrientationStringLPS(rowCosines);
|
||||
const columnString = getOrientationStringLPS(columnCosines);
|
||||
const oppositeRowString = invertOrientationStringLPS(rowString);
|
||||
@@ -79,117 +223,4 @@ function getOrientationMarkers(
|
||||
return markers;
|
||||
}
|
||||
|
||||
function ViewportOrientationMarkers({
|
||||
element,
|
||||
viewportData,
|
||||
imageSliceData,
|
||||
viewportIndex,
|
||||
orientationMarkers = ['top', 'left'],
|
||||
}) {
|
||||
// Rotation is in degrees
|
||||
const [rotation, setRotation] = useState(0);
|
||||
const [flipHorizontal, setFlipHorizontal] = useState(false);
|
||||
const [flipVertical, setFlipVertical] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
const cameraModifiedListener = (
|
||||
evt: Types.EventTypes.CameraModifiedEvent
|
||||
) => {
|
||||
|
||||
const { rotation, previousCamera, camera } = evt.detail;
|
||||
|
||||
if (rotation !== undefined) {
|
||||
setRotation(rotation);
|
||||
}
|
||||
|
||||
if (camera.flipHorizontal !== undefined &&
|
||||
previousCamera.flipHorizontal !== camera.flipHorizontal) {
|
||||
setFlipHorizontal(camera.flipHorizontal);
|
||||
}
|
||||
|
||||
if (camera.flipVertical !== undefined &&
|
||||
previousCamera.flipVertical !== camera.flipVertical) {
|
||||
setFlipVertical(camera.flipVertical);
|
||||
}
|
||||
};
|
||||
|
||||
element.addEventListener(
|
||||
Enums.Events.CAMERA_MODIFIED,
|
||||
cameraModifiedListener
|
||||
);
|
||||
|
||||
return () => {
|
||||
element.removeEventListener(
|
||||
Enums.Events.CAMERA_MODIFIED,
|
||||
cameraModifiedListener
|
||||
);
|
||||
};
|
||||
}, []);
|
||||
|
||||
const getMarkers = useCallback(
|
||||
orientationMarkers => {
|
||||
// Todo: support orientation markers for the volume viewports
|
||||
if (
|
||||
!viewportData ||
|
||||
viewportData.viewportType === Enums.ViewportType.ORTHOGRAPHIC
|
||||
) {
|
||||
return '';
|
||||
}
|
||||
|
||||
const imageIndex = imageSliceData.imageIndex;
|
||||
const imageId = viewportData.imageIds?.[imageIndex];
|
||||
|
||||
// Workaround for below TODO stub
|
||||
if (!imageId) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const { rowCosines, columnCosines } =
|
||||
metaData.get('imagePlaneModule', imageId) || {};
|
||||
|
||||
if (!rowCosines || !columnCosines || rotation === undefined) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!rowCosines || !columnCosines) {
|
||||
return '';
|
||||
}
|
||||
|
||||
const markers = getOrientationMarkers(
|
||||
rowCosines,
|
||||
columnCosines,
|
||||
rotation,
|
||||
flipVertical,
|
||||
flipHorizontal
|
||||
);
|
||||
|
||||
return orientationMarkers.map((m, index) => (
|
||||
<div
|
||||
className={`${m}-mid orientation-marker`}
|
||||
key={`${m}-mid orientation-marker`}
|
||||
>
|
||||
<div className="orientation-marker-value">{markers[m]}</div>
|
||||
</div>
|
||||
));
|
||||
},
|
||||
[flipHorizontal, flipVertical, rotation, viewportData, imageSliceData]
|
||||
);
|
||||
|
||||
return (
|
||||
<div className="ViewportOrientationMarkers noselect">
|
||||
{getMarkers(orientationMarkers)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
ViewportOrientationMarkers.propTypes = {
|
||||
percentComplete: PropTypes.number,
|
||||
error: PropTypes.object,
|
||||
};
|
||||
|
||||
ViewportOrientationMarkers.defaultProps = {
|
||||
percentComplete: 0,
|
||||
error: null,
|
||||
};
|
||||
|
||||
export default ViewportOrientationMarkers;
|
||||
@@ -28,6 +28,25 @@ function CornerstoneViewportOverlay({
|
||||
setActiveTools(ToolBarService.getActiveTools());
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
let isMounted = true;
|
||||
const { unsubscribe } = ToolBarService.subscribe(
|
||||
ToolBarService.EVENTS.TOOL_BAR_STATE_MODIFIED,
|
||||
() => {
|
||||
if (!isMounted) {
|
||||
return;
|
||||
}
|
||||
|
||||
setActiveTools(ToolBarService.getActiveTools());
|
||||
}
|
||||
);
|
||||
|
||||
return () => {
|
||||
isMounted = false;
|
||||
unsubscribe();
|
||||
};
|
||||
}, []);
|
||||
|
||||
/**
|
||||
* Updating the VOI when the viewport changes its voi
|
||||
*/
|
||||
@@ -100,23 +119,6 @@ function CornerstoneViewportOverlay({
|
||||
};
|
||||
}, [viewportIndex, viewportData]);
|
||||
|
||||
/**
|
||||
* Updating the active tools when the toolbar changes
|
||||
*/
|
||||
// Todo: this should act on the toolGroups instead of the toolbar state
|
||||
useEffect(() => {
|
||||
const { unsubscribe } = ToolBarService.subscribe(
|
||||
ToolBarService.EVENTS.TOOL_BAR_STATE_MODIFIED,
|
||||
() => {
|
||||
setActiveTools(ToolBarService.getActiveTools());
|
||||
}
|
||||
);
|
||||
|
||||
return () => {
|
||||
unsubscribe();
|
||||
};
|
||||
}, [ToolBarService]);
|
||||
|
||||
const getTopLeftContent = useCallback(() => {
|
||||
const { windowWidth, windowCenter } = voi;
|
||||
|
||||
@@ -186,12 +188,6 @@ function CornerstoneViewportOverlay({
|
||||
return null;
|
||||
}
|
||||
|
||||
if (viewportData.imageIds.length === 0) {
|
||||
throw new Error(
|
||||
'ViewportOverlay: only viewports with imageIds is supported at this time'
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<ViewportOverlay
|
||||
topLeft={getTopLeftContent()}
|
||||
@@ -201,7 +197,7 @@ function CornerstoneViewportOverlay({
|
||||
}
|
||||
|
||||
function _getInstanceNumberFromStack(viewportData, imageIndex) {
|
||||
const imageIds = viewportData.imageIds;
|
||||
const imageIds = viewportData.data.imageIds;
|
||||
const imageId = imageIds[imageIndex];
|
||||
|
||||
if (!imageId) {
|
||||
|
||||
Reference in new issue
Block a user