Skip to content

Commit

Permalink
feat(VolumeViewport): Add optional flag to assume fallbacks for ZSpac…
Browse files Browse the repository at this point in the history
…ing for volumes (#435)

* Add support for multiframe images without position frame metadata

* Add console.log warnings

* Refactoring according PR reviews

* Refactoring metadataMaanger.js

* add flag for non strict z spacing

* update api
  • Loading branch information
rodrigobasilio2022 authored Apr 1, 2023
1 parent efb03af commit 162f78a
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 4 deletions.
1 change: 1 addition & 0 deletions common/reviews/api/core.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ type Cornerstone3DConfig = {
preferSizeOverAccuracy: boolean;
useNorm16Texture: boolean;
useCPURendering: boolean;
strictZSpacingForVolumeViewport: boolean;
};
};

Expand Down
1 change: 1 addition & 0 deletions common/reviews/api/streaming-image-volume-loader.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ type Cornerstone3DConfig = {
// https://bugs.webkit.org/show_bug.cgi?id=252039
useNorm16Texture: boolean;
useCPURendering: boolean;
strictZSpacingForVolumeViewport: boolean;
};
};

Expand Down
1 change: 1 addition & 0 deletions common/reviews/api/tools.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -924,6 +924,7 @@ type Cornerstone3DConfig = {
// https://bugs.webkit.org/show_bug.cgi?id=252039
useNorm16Texture: boolean;
useCPURendering: boolean;
strictZSpacingForVolumeViewport: boolean;
};
};

Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const defaultConfig = {
preferSizeOverAccuracy: false,
useCPURendering: false,
useNorm16Texture: false, // _hasNorm16TextureSupport(),
strictZSpacingForVolumeViewport: true,
},
// cache
// ...
Expand All @@ -24,6 +25,7 @@ let config = {
preferSizeOverAccuracy: false,
useCPURendering: false,
useNorm16Texture: false, // _hasNorm16TextureSupport(),
strictZSpacingForVolumeViewport: true,
},
// cache
// ...
Expand Down
10 changes: 10 additions & 0 deletions packages/core/src/types/Cornerstone3DConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@ type Cornerstone3DConfig = {
// https://bugs.webkit.org/show_bug.cgi?id=252039
useNorm16Texture: boolean;
useCPURendering: boolean;
/**
* flag to control whether to use fallback behavior for z-spacing calculation in
* volume viewports when the necessary metadata is missing. If enabled,
* we will fall back to using slice thickness or a default value of 1 to render
* the volume viewport when z-spacing cannot be calculated from images
* This can help improve the usability and robustness of the visualization
* in scenarios where the metadata is incomplete or missing, but
* it might be wrong assumption in certain scenarios.
*/
strictZSpacingForVolumeViewport: boolean;
};
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { vec3 } from 'gl-matrix';
import { metaData } from '@cornerstonejs/core';
import { metaData, getConfiguration } from '@cornerstonejs/core';
import type { Types } from '@cornerstonejs/core';

type SortedImageIdsItem = {
Expand Down Expand Up @@ -28,7 +28,7 @@ export default function sortImageIdsAndGetSpacing(
const refIppVec = vec3.create();

// Check if we are using wadouri scheme
const usingWadoUri = imageIds[0].split(':')[0] === 'wadouri'
const usingWadoUri = imageIds[0].split(':')[0] === 'wadouri';

vec3.set(
refIppVec,
Expand Down Expand Up @@ -126,11 +126,28 @@ export default function sortImageIdsAndGetSpacing(
Math.floor(imageIds.length / 2);
}

const { imagePositionPatient: origin } = metaData.get(
const { imagePositionPatient: origin, sliceThickness } = metaData.get(
'imagePlaneModule',
sortedImageIds[0]
);

const { strictZSpacingForVolumeViewport } = getConfiguration().rendering;

// We implemented these lines for multiframe dicom files that does not have
// position for each frame, leading to incorrect calculation of zSpacing = 0
// If possible, we use the sliceThickness, but we warn about this dicom file
// weirdness. If sliceThickness is not available, we set to 1 just to render
if (zSpacing === 0 && !strictZSpacingForVolumeViewport) {
if (sliceThickness) {
console.log('Could not calculate zSpacing. Using sliceThickness');
zSpacing = sliceThickness;
} else {
console.log(
'Could not calculate zSpacing. The VolumeViewport visualization is compromised. Setting zSpacing to 1 to render'
);
zSpacing = 1;
}
}
const result: SortedImageIdsItem = {
zSpacing,
origin,
Expand Down
1 change: 0 additions & 1 deletion utils/demo/helpers/createImageIdsAndCacheMetaData.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ export default async function createImageIdsAndCacheMetaData({
const client = new api.DICOMwebClient({ url: wadoRsRoot });
const instances = await client.retrieveSeriesMetadata(studySearchOptions);
const modality = instances[0][MODALITY].Value[0];

let imageIds = instances.map((instanceMetaData) => {
const SeriesInstanceUID = instanceMetaData[SERIES_INSTANCE_UID].Value[0];
const SOPInstanceUID = instanceMetaData[SOP_INSTANCE_UID].Value[0];
Expand Down

0 comments on commit 162f78a

Please sign in to comment.