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: use the new prefetch stack in the cs3d #2820

Merged
merged 5 commits into from
Jun 6, 2022
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: 2 additions & 2 deletions extensions/cornerstone-dicom-sr/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"dependencies": {
"@babel/runtime": "7.16.3",
"classnames": "^2.2.6",
"@cornerstonejs/core": "^0.11.0",
"@cornerstonejs/tools": "^0.18.0"
"@cornerstonejs/core": "^0.12.0",
"@cornerstonejs/tools": "^0.19.0"
}
}
4 changes: 2 additions & 2 deletions extensions/cornerstone/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@
"@babel/runtime": "7.17.9",
"lodash.merge": "^4.6.2",
"lodash.debounce": "4.0.8",
"@cornerstonejs/core": "^0.11.0",
"@cornerstonejs/tools": "^0.18.0",
"@cornerstonejs/core": "^0.12.0",
"@cornerstonejs/tools": "^0.19.0",
"@cornerstonejs/streaming-image-volume-loader": "^0.3.4",
"shader-loader": "^1.3.1",
"@kitware/vtk.js": "^24.10.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ const OHIFCornerstoneViewport = React.memo(props => {
ToolBarService={ToolBarService}
element={elementRef.current}
scrollbarHeight={scrollbarHeight}
CornerstoneViewportService={CornerstoneViewportService}
servicesManager={servicesManager}
/>
</div>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,8 @@ import ViewportLoadingIndicator from './ViewportLoadingIndicator';
import CornerstoneCacheService from '../../services/ViewportService/CornerstoneCacheService';

function CornerstoneOverlays(props) {
const {
viewportIndex,
ToolBarService,
element,
scrollbarHeight,
CornerstoneViewportService,
} = props;
const { viewportIndex, element, scrollbarHeight, servicesManager } = props;
const { CornerstoneViewportService } = servicesManager.services;
const [imageSliceData, setImageSliceData] = useState({
imageIndex: 0,
numberOfSlices: 0,
Expand Down Expand Up @@ -52,22 +47,21 @@ function CornerstoneOverlays(props) {
}

return (
<>
<div>
<ViewportImageScrollbar
viewportIndex={viewportIndex}
viewportData={viewportData}
element={element}
imageSliceData={imageSliceData}
setImageSliceData={setImageSliceData}
scrollbarHeight={scrollbarHeight}
CornerstoneViewportService={CornerstoneViewportService}
servicesManager={servicesManager}
/>
<ViewportOverlay
imageSliceData={imageSliceData}
viewportData={viewportData}
viewportIndex={viewportIndex}
ToolBarService={ToolBarService}
CornerstoneViewportService={CornerstoneViewportService}
servicesManager={servicesManager}
element={element}
/>
<ViewportLoadingIndicator viewportData={viewportData} element={element} />
Expand All @@ -77,7 +71,7 @@ function CornerstoneOverlays(props) {
viewportData={viewportData}
viewportIndex={viewportIndex}
/>
</>
</div>
);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useCallback, useEffect } from 'react';
import React, { useEffect } from 'react';
import PropTypes from 'prop-types';
import { Enums, Types, utilities } from '@cornerstonejs/core';
import { utilities as csToolsUtils } from '@cornerstonejs/tools';
Expand All @@ -11,28 +11,29 @@ function CornerstoneImageScrollbar({
imageSliceData,
setImageSliceData,
scrollbarHeight,
CornerstoneViewportService,
servicesManager,
}) {
const onImageScrollbarChange = useCallback(
(imageIndex, viewportIndex) => {
const viewportInfo = CornerstoneViewportService.getViewportInfoByIndex(
viewportIndex
);
const { CineService, CornerstoneViewportService } = servicesManager.services;

const viewportId = viewportInfo.getViewportId();
const viewport = CornerstoneViewportService.getCornerstoneViewport(
viewportId
);
const onImageScrollbarChange = (imageIndex, viewportIndex) => {
const viewportInfo = CornerstoneViewportService.getViewportInfoByIndex(
viewportIndex
);

csToolsUtils.jumpToSlice(viewport.element, { imageIndex }).then(() => {
setImageSliceData({
...imageSliceData,
imageIndex: imageIndex,
});
});
},
[viewportIndex, viewportData, imageSliceData]
);
const viewportId = viewportInfo.getViewportId();
const viewport = CornerstoneViewportService.getCornerstoneViewport(
viewportId
);

// on image scrollbar change, stop the CINE if it is playing
CineService.stopClip(element);
CineService.setCine({ id: viewportIndex, isPlaying: false });

csToolsUtils.jumpToSlice(viewport.element, {
imageIndex,
debounceLoading: true,
});
};

useEffect(() => {
if (!viewportData) {
Expand All @@ -48,15 +49,10 @@ function CornerstoneImageScrollbar({
}

if (viewportData.viewportType === Enums.ViewportType.STACK) {
const imageId = viewport.getCurrentImageId();
const index = viewportData?.imageIds?.indexOf(imageId);

if (index === -1) {
return;
}
const imageIndex = viewport.getCurrentImageIdIndex();

setImageSliceData({
imageIndex: index,
imageIndex: imageIndex,
numberOfSlices: viewportData.imageIds.length,
});

Expand All @@ -78,40 +74,34 @@ function CornerstoneImageScrollbar({
}, [viewportIndex, viewportData]);

useEffect(() => {
if (
!viewportData ||
viewportData.viewportType !== Enums.ViewportType.STACK
) {
if (viewportData?.viewportType !== Enums.ViewportType.STACK) {
return;
}

const updateStackIndex = event => {
const { imageId } = event.detail;
const { newImageIdIndex } = event.detail;
// find the index of imageId in the imageIds
const index = viewportData?.imageIds?.indexOf(imageId);
if (index !== -1) {
setImageSliceData({
imageIndex: index,
numberOfSlices: viewportData.imageIds.length,
});
}
setImageSliceData({
imageIndex: newImageIdIndex,
numberOfSlices: viewportData.imageIds.length,
});
};

element.addEventListener(Enums.Events.STACK_NEW_IMAGE, updateStackIndex);
element.addEventListener(
Enums.Events.STACK_VIEWPORT_SCROLL,
updateStackIndex
);

return () => {
element.removeEventListener(
Enums.Events.STACK_NEW_IMAGE,
Enums.Events.STACK_VIEWPORT_SCROLL,
updateStackIndex
);
};
}, [viewportData, element]);

useEffect(() => {
if (
!viewportData ||
viewportData.viewportType !== Enums.ViewportType.ORTHOGRAPHIC
) {
if (viewportData?.viewportType !== Enums.ViewportType.ORTHOGRAPHIC) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,39 +9,34 @@ function ViewportLoadingIndicator({ viewportData, element }) {
const loadIndicatorRef = useRef(null);
const imageIdToBeLoaded = useRef(null);

useEffect(() => {
if (!element) {
return;
}
const setLoadingState = evt => {
clearTimeout(loadIndicatorRef.current);

const setLoadingState = evt => {
clearTimeout(loadIndicatorRef.current);
imageIdToBeLoaded.current = evt.detail.imageId;
loadIndicatorRef.current = setTimeout(() => {
setLoading(true);
}, 50);
};

loadIndicatorRef.current = setTimeout(() => {
if (imageIdToBeLoaded.current === evt.detail.imageId) {
setLoading(true);
}
}, 50);
};
const setFinishLoadingState = evt => {
clearTimeout(loadIndicatorRef.current);

const setFinishLoadingState = evt => {
clearTimeout(loadIndicatorRef.current);
setLoading(false);
};

setLoading(false);
imageIdToBeLoaded.current = null;
};
const setErrorState = evt => {
clearTimeout(loadIndicatorRef.current);

const setErrorState = evt => {
clearTimeout(loadIndicatorRef.current);

if (imageIdToBeLoaded.current === evt.detail.imageId) {
setError(evt.detail.error);
imageIdToBeLoaded.current = null;
}
};
if (imageIdToBeLoaded.current === evt.detail.imageId) {
setError(evt.detail.error);
imageIdToBeLoaded.current = null;
}
};

element.addEventListener(Enums.Events.PRE_STACK_NEW_IMAGE, setLoadingState);
useEffect(() => {
element.addEventListener(
Enums.Events.STACK_VIEWPORT_SCROLL,
setLoadingState
);
element.addEventListener(Enums.Events.IMAGE_LOAD_ERROR, setErrorState);
element.addEventListener(
Enums.Events.STACK_NEW_IMAGE,
Expand All @@ -50,7 +45,7 @@ function ViewportLoadingIndicator({ viewportData, element }) {

return () => {
element.removeEventListener(
Enums.Events.PRE_STACK_NEW_IMAGE,
Enums.Events.STACK_VIEWPORT_SCROLL,
setLoadingState
);

Expand Down Expand Up @@ -81,13 +76,13 @@ function ViewportLoadingIndicator({ viewportData, element }) {

if (loading) {
return (
<>
<div className="bg-black opacity-50 absolute h-full w-full top-0 left-0">
<div className="flex transparent items-center justify-center w-full h-full">
<p className="text-primary-light text-xl font-light">Loading...</p>
</div>
// IMPORTANT: we need to use the pointer-events-none class to prevent the loading indicator from
// interacting with the mouse, since scrolling should propagate to the viewport underneath
<div className="pointer-events-none bg-black opacity-50 absolute h-full w-full top-0 left-0">
<div className="flex transparent items-center justify-center w-full h-full">
<p className="text-primary-light text-xl font-light">Loading...</p>
</div>
</>
</div>
);
}

Expand All @@ -97,6 +92,7 @@ function ViewportLoadingIndicator({ viewportData, element }) {
ViewportLoadingIndicator.propTypes = {
percentComplete: PropTypes.number,
error: PropTypes.object,
element: PropTypes.object,
};

ViewportLoadingIndicator.defaultProps = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@ function CornerstoneViewportOverlay({
viewportData,
imageSliceData,
viewportIndex,
CornerstoneViewportService,
ToolBarService,
servicesManager,
}) {
const {
CornerstoneViewportService,
ToolBarService,
} = servicesManager.services;
const [voi, setVOI] = useState({ windowCenter: null, windowWidth: null });
const [scale, setScale] = useState(1);
const [activeTools, setActiveTools] = useState([]);
Expand Down
2 changes: 1 addition & 1 deletion extensions/cornerstone/src/commandsModule.js
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ const commandsModule = ({ servicesManager }) => {
const { viewport } = enabledElement;
const options = { delta: direction };

csToolsUtils.stackScrollTool.scrollThroughStack(viewport, options);
csToolsUtils.scroll(viewport, options);
},
async createSegmentationForDisplaySet({ displaySetInstanceUID }) {
const volumeId = displaySetInstanceUID;
Expand Down
20 changes: 11 additions & 9 deletions extensions/cornerstone/src/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ export default async function init({
metaData.addProvider(metadataProvider.get.bind(metadataProvider), 9999);

imageLoadPoolManager.maxNumRequests = {
interaction: 100,
thumbnail: 75,
prefetch: 20,
interaction: appConfig?.maxNumRequests?.interaction || 100,
thumbnail: appConfig?.maxNumRequests?.thumbnail || 75,
prefetch: appConfig?.maxNumRequests?.prefetch || 10,
};

initWADOImageLoader(UserAuthenticationService, appConfig);
Expand Down Expand Up @@ -260,9 +260,10 @@ export default async function init({
contextMenuHandleClick
);

// element.addEventListener(EVENTS.NEW_STACK_SET, () =>
// utilities.stackPrefetch.enable(element)
// );
eventTarget.addEventListener(EVENTS.STACK_VIEWPORT_NEW_STACK, evt => {
const { element } = evt.detail;
utilities.stackPrefetch.enable(element);
});
}

function elementDisabledHandler(evt) {
Expand All @@ -276,9 +277,10 @@ export default async function init({
contextMenuHandleClick
);

// element.removeEventListener(EVENTS.NEW_STACK_SET, () =>
// utilities.stackPrefetch.disable(element)
// );
eventTarget.removeEventListener(EVENTS.STACK_VIEWPORT_NEW_STACK, evt => {
const { element } = evt.detail;
utilities.stackPrefetch.disable(element);
});
}

eventTarget.addEventListener(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,6 @@ class CornerstoneViewportService implements IViewportService {

viewport.setStack(imageIds, initialImageIndexToUse).then(() => {
viewport.setProperties(properties);
csUtils.prefetchStack(imageIds);
});
}

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 @@ -32,8 +32,8 @@
"peerDependencies": {
"@ohif/core": "^3.0.0",
"classnames": "^2.2.6",
"@cornerstonejs/core": "^0.11.0",
"@cornerstonejs/tools": "^0.18.0",
"@cornerstonejs/core": "^0.12.0",
"@cornerstonejs/tools": "^0.19.0",
"@ohif/extension-cornerstone-dicom-sr": "^3.0.0",
"dcmjs": "^0.22.1",
"prop-types": "^15.6.2",
Expand Down
Loading