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

fix(multiframe): metadata handling of NM studies and loading order #4540

Merged
merged 20 commits into from
Nov 27, 2024
Merged
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
2 changes: 0 additions & 2 deletions .docker/Viewer-v3.x/default.conf.template
Original file line number Diff line number Diff line change
@@ -5,8 +5,6 @@ server {
root /usr/share/nginx/html;
index index.html index.htm;
try_files $uri $uri/ /index.html;
add_header Cross-Origin-Opener-Policy same-origin;
add_header Cross-Origin-Embedder-Policy require-corp;
add_header Cross-Origin-Resource-Policy same-origin;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
2 changes: 0 additions & 2 deletions .docker/Viewer-v3.x/default.ssl.conf.template
Original file line number Diff line number Diff line change
@@ -7,8 +7,6 @@ server {
root /usr/share/nginx/html;
index index.html index.htm;
try_files $uri $uri/ /index.html;
add_header Cross-Origin-Opener-Policy same-origin;
add_header Cross-Origin-Embedder-Policy require-corp;
add_header Cross-Origin-Resource-Policy same-origin;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
6 changes: 1 addition & 5 deletions .webpack/webpack.base.js
Original file line number Diff line number Diff line change
@@ -57,10 +57,6 @@ if (!process.env.APP_CONFIG) {
}

module.exports = (env, argv, { SRC_DIR, ENTRY }) => {
if (!process.env.NODE_ENV) {
throw new Error('process.env.NODE_ENV not set');
}

const mode = NODE_ENV === 'production' ? 'production' : 'development';
const isProdBuild = NODE_ENV === 'production';
const isQuickBuild = QUICK_BUILD === 'true';
@@ -108,7 +104,7 @@ module.exports = (env, argv, { SRC_DIR, ENTRY }) => {
exclude: /node_modules/,
loader: 'babel-loader',
options: {
plugins: ['react-refresh/babel'],
plugins: isProdBuild ? [] : ['react-refresh/babel'],
},
},
]),
4 changes: 2 additions & 2 deletions extensions/cornerstone-dicom-pmap/package.json
Original file line number Diff line number Diff line change
@@ -46,8 +46,8 @@
},
"dependencies": {
"@babel/runtime": "^7.20.13",
"@cornerstonejs/adapters": "^2.2.4",
"@cornerstonejs/core": "^2.2.4",
"@cornerstonejs/adapters": "^2.2.20",
"@cornerstonejs/core": "^2.2.20",
"@kitware/vtk.js": "32.1.0",
"react-color": "^2.19.3"
}
4 changes: 2 additions & 2 deletions extensions/cornerstone-dicom-seg/package.json
Original file line number Diff line number Diff line change
@@ -46,8 +46,8 @@
},
"dependencies": {
"@babel/runtime": "^7.20.13",
"@cornerstonejs/adapters": "^2.2.4",
"@cornerstonejs/core": "^2.2.4",
"@cornerstonejs/adapters": "^2.2.20",
"@cornerstonejs/core": "^2.2.20",
"@kitware/vtk.js": "32.1.0",
"react-color": "^2.19.3"
}
6 changes: 3 additions & 3 deletions extensions/cornerstone-dicom-sr/package.json
Original file line number Diff line number Diff line change
@@ -46,9 +46,9 @@
},
"dependencies": {
"@babel/runtime": "^7.20.13",
"@cornerstonejs/adapters": "^2.2.4",
"@cornerstonejs/core": "^2.2.4",
"@cornerstonejs/tools": "^2.2.4",
"@cornerstonejs/adapters": "^2.2.20",
"@cornerstonejs/core": "^2.2.20",
"@cornerstonejs/tools": "^2.2.20",
"classnames": "^2.3.2"
}
}
4 changes: 2 additions & 2 deletions extensions/cornerstone-dynamic-volume/package.json
Original file line number Diff line number Diff line change
@@ -42,8 +42,8 @@
},
"dependencies": {
"@babel/runtime": "^7.20.13",
"@cornerstonejs/core": "^2.2.4",
"@cornerstonejs/tools": "^2.2.4",
"@cornerstonejs/core": "^2.2.20",
"@cornerstonejs/tools": "^2.2.20",
"classnames": "^2.3.2"
}
}
8 changes: 4 additions & 4 deletions extensions/cornerstone/package.json
Original file line number Diff line number Diff line change
@@ -38,7 +38,7 @@
"@cornerstonejs/codec-libjpeg-turbo-8bit": "^1.2.2",
"@cornerstonejs/codec-openjpeg": "^1.2.4",
"@cornerstonejs/codec-openjph": "^2.4.5",
"@cornerstonejs/dicom-image-loader": "^2.2.4",
"@cornerstonejs/dicom-image-loader": "^2.2.20",
"@icr/polyseg-wasm": "^0.4.0",
"@ohif/core": "3.9.1",
"@ohif/ui": "3.9.1",
@@ -55,9 +55,9 @@
},
"dependencies": {
"@babel/runtime": "^7.20.13",
"@cornerstonejs/adapters": "^2.2.4",
"@cornerstonejs/core": "^2.2.4",
"@cornerstonejs/tools": "^2.2.4",
"@cornerstonejs/adapters": "^2.2.20",
"@cornerstonejs/core": "^2.2.20",
"@cornerstonejs/tools": "^2.2.20",
"@icr/polyseg-wasm": "^0.4.0",
"@kitware/vtk.js": "32.1.0",
"html2canvas": "^1.4.1",
2 changes: 1 addition & 1 deletion extensions/cornerstone/src/index.tsx
Original file line number Diff line number Diff line change
@@ -45,7 +45,7 @@ import {
useSegmentationPresentationStore,
useSynchronizersStore,
} from './stores';
import { useToggleOneUpViewportGridStore } from '../../default/src/stores/useToggleOneUpViewportGridStore';
import { useToggleOneUpViewportGridStore } from '@ohif/extension-default';
import { useActiveViewportSegmentationRepresentations } from './hooks/useActiveViewportSegmentationRepresentations';
import { useMeasurements } from './hooks/useMeasurements';
import getPanelModule from './getPanelModule';
41 changes: 38 additions & 3 deletions extensions/cornerstone/src/init.tsx
Original file line number Diff line number Diff line change
@@ -38,6 +38,7 @@ import { SegmentationRepresentations } from '@cornerstonejs/tools/enums';
import { useLutPresentationStore } from './stores/useLutPresentationStore';
import { usePositionPresentationStore } from './stores/usePositionPresentationStore';
import { useSegmentationPresentationStore } from './stores/useSegmentationPresentationStore';
import { imageRetrieveMetadataProvider } from '@cornerstonejs/core/utilities';

const { registerColormap } = csUtilities.colormap;

@@ -135,9 +136,21 @@ export default async function init({
cornerstoneStreamingDynamicImageVolumeLoader
);

hangingProtocolService.registerImageLoadStrategy('interleaveCenter', interleaveCenterLoader);
hangingProtocolService.registerImageLoadStrategy('interleaveTopToBottom', interleaveTopToBottom);
hangingProtocolService.registerImageLoadStrategy('nth', nthLoader);
// Register strategies using the wrapper
const imageLoadStrategies = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we indicate that these are deprecated in favour of setting a image load strategy metadata? The three image loaders are not as robust as the new CS3D image loader because it doesn't work effectively with the priority fetching mechanism. Ideally, just setting one of those strategies in the hanging protocol and applying that into the metadata would allow new strategies to be defined directly in the hanging protocol as JSON data.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if they are the same. The hanging protocol loading strategy and the cs3d image loaders work per series, so you can't implement an interleave CT, PT (one CT, one PT) with cs3d, as far as I know, right?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It uses the priority to do the interleaved strategy, and allows for more complex interleaving, even if the image viewing starts at slightly different times.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like that, do we have an example of that somewhere in cornerstone3D? Let's discuss tomorrow

interleaveCenter: interleaveCenterLoader,
interleaveTopToBottom: interleaveTopToBottom,
nth: nthLoader,
};

Object.entries(imageLoadStrategies).forEach(([name, strategyFn]) => {
hangingProtocolService.registerImageLoadStrategy(
name,
createMetadataWrappedStrategy(strategyFn)
);
});

// ... existing code ...

// add metadata providers
metaData.addProvider(
@@ -296,6 +309,28 @@ function initializeWebWorkerProgressHandler(uiNotificationService) {
});
}

/**
* Creates a wrapped image load strategy with metadata handling
* @param strategyFn - The image loading strategy function to wrap
* @returns A wrapped strategy function that handles metadata configuration
*/
const createMetadataWrappedStrategy = (strategyFn: (args: any) => any) => {
return (args: any) => {
const clonedConfig = imageRetrieveMetadataProvider.clone();
imageRetrieveMetadataProvider.clear();

try {
const result = strategyFn(args);
return result;
} finally {
// Ensure metadata is always restored, even if there's an error
setTimeout(() => {
imageRetrieveMetadataProvider.restore(clonedConfig);
}, 10);
}
};
};

function CPUModal() {
return (
<div>
4 changes: 2 additions & 2 deletions extensions/cornerstone/src/initMeasurementService.ts
Original file line number Diff line number Diff line change
@@ -59,10 +59,10 @@ const initMeasurementService = (
'Crosshairs',
Length.matchingCriteria,
() => {
console.warn('Crosshairs mapping not implemented.');
return null;
},
() => {
console.warn('Crosshairs mapping not implemented.');
return null;
}
);

Original file line number Diff line number Diff line change
@@ -1043,6 +1043,11 @@ class CornerstoneViewportService extends PubSubService implements IViewportServi
// Store the current position presentations for each viewport.
viewports.forEach(({ id: viewportId }) => {
const presentation = this._getPositionPresentation(viewportId);

// During a resize, the slice index should remain unchanged. This is a temporary fix for
// a larger issue regarding the definition of slice index with slab thickness.
// We need to revisit this to make it more robust and understandable.
delete presentation.viewReference.sliceIndex;
this.beforeResizePositionPresentations.set(viewportId, presentation);
});

@@ -1051,10 +1056,12 @@ class CornerstoneViewportService extends PubSubService implements IViewportServi
renderingEngine.resize(isImmediate);
renderingEngine.render();

// Reset the camera for viewports that should reset their camera on resize,
// Reset the camera for all viewports using position presentation to maintain relative size/position
// which means only those viewports that have a zoom level of 1.
this.beforeResizePositionPresentations.forEach((positionPresentation, viewportId) => {
this.setPresentations(viewportId, { positionPresentation });
this.setPresentations(viewportId, {
positionPresentation,
});
});

// Resize and render the rendering engine again.
2 changes: 1 addition & 1 deletion extensions/cornerstone/src/utils/interleaveTopToBottom.ts
Original file line number Diff line number Diff line change
@@ -108,7 +108,7 @@ export default function interleaveTopToBottom({
volumes.forEach(volume => {
const requests = volume.getImageLoadRequests();

if (!requests.length || !requests[0] || !requests[0].imageId) {
if (!requests?.[0]?.imageId) {
return;
}

2 changes: 1 addition & 1 deletion extensions/default/src/DicomJSONDataSource/index.js
Original file line number Diff line number Diff line change
@@ -93,7 +93,7 @@ function createDicomJSONApi(dicomJsonConfig) {

const { query } = qs.parseUrl(instance.url);

// Add imageId specific mapping to this data as the URL isn't necessarliy WADO-URI.
// Add imageId specific mapping to this data as the URL isn't necessarily WADO-URI.
metadataProvider.addImageIdToUIDs(imageId, {
StudyInstanceUID,
SeriesInstanceUID,
36 changes: 22 additions & 14 deletions extensions/default/src/DicomLocalDataSource/index.js
Original file line number Diff line number Diff line change
@@ -142,9 +142,7 @@ function createDicomLocalApi(dicomLocalConfig) {
study.series.forEach(aSeries => {
const { SeriesInstanceUID } = aSeries;

const isMultiframe = aSeries.instances[0].NumberOfFrames > 1;

aSeries.instances.forEach((instance, index) => {
aSeries.instances.forEach(instance => {
const {
url: imageId,
StudyInstanceUID,
@@ -153,14 +151,22 @@ function createDicomLocalApi(dicomLocalConfig) {
} = instance;

instance.imageId = imageId;

// Add imageId specific mapping to this data as the URL isn't necessarily WADO-URI.
metadataProvider.addImageIdToUIDs(imageId, {
StudyInstanceUID,
SeriesInstanceUID,
SOPInstanceUID,
frameIndex: isMultiframe ? index : 1,
});
const numberOfFrames = instance.NumberOfFrames || 1;
// Process all frames consistently, whether single or multiframe
for (let i = 0; i < numberOfFrames; i++) {
const frameNumber = i + 1;
const frameImageId = implementation.getImageIdsForInstance({
instance,
frame: frameNumber,
});
// Add imageId specific mapping to this data as the URL isn't necessarily WADO-URI.
metadataProvider.addImageIdToUIDs(frameImageId, {
StudyInstanceUID,
SeriesInstanceUID,
SOPInstanceUID,
frameNumber: numberOfFrames > 1 ? frameNumber : undefined,
});
}
});

DicomMetadataStore._broadcastEvent(EVENTS.INSTANCES_ADDED, {
@@ -209,9 +215,11 @@ function createDicomLocalApi(dicomLocalConfig) {
return imageIds;
},
getImageIdsForInstance({ instance, frame }) {
if (instance.imageId) {
return instance.imageId;
}
// Important: Never use instance.imageId because it might be multiframe,
// which would make it an invalid imageId.
// if (instance.imageId) {
// return instance.imageId;
// }

const { StudyInstanceUID, SeriesInstanceUID, SOPInstanceUID } = instance;
const storedInstance = DicomMetadataStore.getInstance(
33 changes: 21 additions & 12 deletions extensions/default/src/DicomWebDataSource/index.js
Original file line number Diff line number Diff line change
@@ -434,23 +434,32 @@ function createDicomWebApi(dicomWebConfig, servicesManager) {
instance.wadoRoot = dicomWebConfig.wadoRoot;
instance.wadoUri = dicomWebConfig.wadoUri;

const imageId = implementation.getImageIdsForInstance({
instance,
});
const { StudyInstanceUID, SeriesInstanceUID, SOPInstanceUID } = instance;

const numberOfFrames = instance.NumberOfFrames || 1;
// Process all frames consistently, whether single or multiframe
for (let i = 0; i < numberOfFrames; i++) {
const frameNumber = i + 1;
const frameImageId = implementation.getImageIdsForInstance({
instance,
frame: frameNumber,
});
// Add imageId specific mapping to this data as the URL isn't necessarily WADO-URI.
metadataProvider.addImageIdToUIDs(frameImageId, {
StudyInstanceUID,
SeriesInstanceUID,
SOPInstanceUID,
frameNumber: numberOfFrames > 1 ? frameNumber : undefined,
});
}

// Adding imageId to each instance
// Todo: This is not the best way I can think of to let external
// metadata handlers know about the imageId that is stored in the store
instance.imageId = imageId;

// Adding UIDs to metadataProvider
// Note: storing imageURI in metadataProvider since stack viewports
// will use the same imageURI
metadataProvider.addImageIdToUIDs(imageId, {
StudyInstanceUID,
SeriesInstanceUID: instance.SeriesInstanceUID,
SOPInstanceUID: instance.SOPInstanceUID,
const imageId = implementation.getImageIdsForInstance({
instance,
});
instance.imageId = imageId;
});

DicomMetadataStore.addInstances(naturalizedInstances, madeInClient);
4 changes: 2 additions & 2 deletions extensions/measurement-tracking/package.json
Original file line number Diff line number Diff line change
@@ -32,8 +32,8 @@
"start": "yarn run dev"
},
"peerDependencies": {
"@cornerstonejs/core": "^2.2.4",
"@cornerstonejs/tools": "^2.2.4",
"@cornerstonejs/core": "^2.2.20",
"@cornerstonejs/tools": "^2.2.20",
"@ohif/core": "3.9.1",
"@ohif/extension-cornerstone-dicom-sr": "3.9.1",
"@ohif/extension-default": "3.9.1",
Loading