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 #4554

Merged
merged 7 commits into from
Nov 28, 2024
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
2 changes: 0 additions & 2 deletions .docker/Viewer-v3.x/default.conf.template
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 0 additions & 2 deletions .docker/Viewer-v3.x/default.ssl.conf.template
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 1 addition & 5 deletions .webpack/webpack.base.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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'],
},
},
]),
Expand Down
4 changes: 2 additions & 2 deletions extensions/cornerstone-dicom-pmap/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@
},
"dependencies": {
"@babel/runtime": "^7.20.13",
"@cornerstonejs/adapters": "^2.2.13",
"@cornerstonejs/core": "^2.2.13",
"@cornerstonejs/adapters": "^2.2.20",
"@cornerstonejs/core": "^2.2.20",
"@kitware/vtk.js": "32.1.1",
"react-color": "^2.19.3"
}
Expand Down
4 changes: 2 additions & 2 deletions extensions/cornerstone-dicom-seg/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@
},
"dependencies": {
"@babel/runtime": "^7.20.13",
"@cornerstonejs/adapters": "^2.2.13",
"@cornerstonejs/core": "^2.2.13",
"@cornerstonejs/adapters": "^2.2.20",
"@cornerstonejs/core": "^2.2.20",
"@kitware/vtk.js": "32.1.1",
"react-color": "^2.19.3"
}
Expand Down
6 changes: 3 additions & 3 deletions extensions/cornerstone-dicom-sr/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@
},
"dependencies": {
"@babel/runtime": "^7.20.13",
"@cornerstonejs/adapters": "^2.2.13",
"@cornerstonejs/core": "^2.2.13",
"@cornerstonejs/tools": "^2.2.13",
"@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
Expand Up @@ -42,8 +42,8 @@
},
"dependencies": {
"@babel/runtime": "^7.20.13",
"@cornerstonejs/core": "^2.2.13",
"@cornerstonejs/tools": "^2.2.13",
"@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
Expand Up @@ -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.13",
"@cornerstonejs/dicom-image-loader": "^2.2.20",
"@icr/polyseg-wasm": "^0.4.0",
"@ohif/core": "3.10.0-beta.10",
"@ohif/ui": "3.10.0-beta.10",
Expand All @@ -55,9 +55,9 @@
},
"dependencies": {
"@babel/runtime": "^7.20.13",
"@cornerstonejs/adapters": "^2.2.13",
"@cornerstonejs/core": "^2.2.13",
"@cornerstonejs/tools": "^2.2.13",
"@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.1",
"html2canvas": "^1.4.1",
Expand Down
2 changes: 1 addition & 1 deletion extensions/cornerstone/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
41 changes: 38 additions & 3 deletions extensions/cornerstone/src/init.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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 = {
interleaveCenter: interleaveCenterLoader,
interleaveTopToBottom: interleaveTopToBottom,
nth: nthLoader,
};

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

// ... existing code ...

// add metadata providers
metaData.addProvider(
Expand Down Expand Up @@ -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>
Expand Down
4 changes: 2 additions & 2 deletions extensions/cornerstone/src/initMeasurementService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1058,6 +1058,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);
});

Expand All @@ -1066,10 +1071,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.
Expand Down
2 changes: 1 addition & 1 deletion extensions/cornerstone/src/utils/interleaveTopToBottom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion extensions/default/src/DicomJSONDataSource/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
36 changes: 22 additions & 14 deletions extensions/default/src/DicomLocalDataSource/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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, {
Expand Down Expand Up @@ -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(
Expand Down
33 changes: 21 additions & 12 deletions extensions/default/src/DicomWebDataSource/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
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 @@
"start": "yarn run dev"
},
"peerDependencies": {
"@cornerstonejs/core": "^2.2.13",
"@cornerstonejs/tools": "^2.2.13",
"@cornerstonejs/core": "^2.2.20",
"@cornerstonejs/tools": "^2.2.20",
"@ohif/core": "3.10.0-beta.10",
"@ohif/extension-cornerstone-dicom-sr": "3.10.0-beta.10",
"@ohif/extension-default": "3.10.0-beta.10",
Expand Down
Loading