Re IDC #2765: fix loading of segmentations at first startup (#2768)

Re IDC #2761: fix loading of segmentations

update dcmjs to 0.19.9
This commit is contained in:
Davide Punzo authored and GitHub committed 2022-04-05 09:39:22 +02:00
1 parent b94d4782d1
commit 32828d9a6e
15 files changed
+173 -177

No files matched your search

@@ -105,6 +105,11 @@ class Viewer extends Component {
if (this.props.dialog) {
this.props.dialog.dismissAll();
}
document.removeEventListener(
'segmentationLoadingError',
this._updateThumbnails
);
}
retrieveTimepoints = filter => {
@@ -212,6 +217,12 @@ class Viewer extends Component {
),
});
}
document.addEventListener(
'segmentationLoadingError',
this._updateThumbnails.bind(this),
false
);
}
componentDidUpdate(prevProps) {
@@ -255,6 +266,20 @@ class Viewer extends Component {
}
}
_updateThumbnails() {
const { studies, activeViewportIndex, viewports } = this.props;
const activeViewport = viewports[activeViewportIndex];
const activeDisplaySetInstanceUID = activeViewport
? activeViewport.displaySetInstanceUID
: undefined;
this.setState({
thumbnails: _mapStudiesToThumbnails(studies, activeDisplaySetInstanceUID),
activeDisplaySetInstanceUID,
});
}
_getActiveViewport() {
return this.props.viewports[this.props.activeViewportIndex];
}
@@ -461,9 +486,7 @@ const _checkForDerivedDisplaySets = async function(displaySet, study) {
/**
* Async function to check if there are any inconsistences in the series.
*
* For segmentation checks that the geometry is consistent with the source images:
* 1) no frames out of plane;
* 2) have the same width and height.
* For segmentation returns any error during loading.
*
* For reconstructable 3D volume:
* 1) Is series multiframe?
@@ -477,10 +500,7 @@ const _checkForDerivedDisplaySets = async function(displaySet, study) {
* @param {*object} displaySet
* @returns {[string]} an array of strings containing the warnings
*/
const _checkForSeriesInconsistencesWarnings = async function(
displaySet,
studies
) {
const _checkForSeriesInconsistencesWarnings = async function(displaySet) {
if (displaySet.inconsistencyWarnings) {
// warnings already checked and cached in displaySet
return displaySet.inconsistencyWarnings;
@@ -546,98 +566,14 @@ const _checkForSeriesInconsistencesWarnings = async function(
if (displaySet.isModalitySupported === false) {
inconsistencyWarnings.push('The datasets modality is not supported.');
}
displaySet.inconsistencyWarnings = inconsistencyWarnings;
} else {
const segMetadata = displaySet.metadata;
if (!segMetadata) {
return inconsistencyWarnings;
}
const { referencedDisplaySet } = displaySet.getSourceDisplaySet(
studies,
false
);
if (!referencedDisplaySet) {
return inconsistencyWarnings;
}
const imageIds = referencedDisplaySet.images.map(image =>
image.getImageId()
);
if (!imageIds || imageIds.length === 0) {
return inconsistencyWarnings;
}
for (
let i = 0,
groupsLen = segMetadata.PerFrameFunctionalGroupsSequence.length;
i < groupsLen;
++i
) {
const PerFrameFunctionalGroups =
segMetadata.PerFrameFunctionalGroupsSequence[i];
if (!PerFrameFunctionalGroups) {
continue;
}
let SourceImageSequence = undefined;
if (segMetadata.SourceImageSequence) {
SourceImageSequence = segMetadata.SourceImageSequence[i];
} else if (PerFrameFunctionalGroups.DerivationImageSequence) {
SourceImageSequence =
PerFrameFunctionalGroups.DerivationImageSequence.SourceImageSequence;
}
if (!SourceImageSequence) {
if (inconsistencyWarnings.length === 0) {
const warningMessage =
'The segmentation ' +
'has frames out of plane respect to the source images.';
inconsistencyWarnings.push(warningMessage);
}
continue;
}
const { ReferencedSOPInstanceUID } = SourceImageSequence;
const imageId = imageIds.find(imageId => {
const sopCommonModule = cornerstone.metaData.get(
'sopCommonModule',
imageId
);
if (!sopCommonModule) {
return;
}
return sopCommonModule.sopInstanceUID === ReferencedSOPInstanceUID;
});
if (!imageId) {
continue;
}
const sourceImageMetadata = cornerstone.metaData.get('instance', imageId);
if (
segMetadata.Rows !== sourceImageMetadata.Rows ||
segMetadata.Columns !== sourceImageMetadata.Columns
) {
const warningMessage =
'The segmentation ' +
'has frames with different geometry ' +
'dimensions (Rows and Columns) respect to the source images.';
inconsistencyWarnings.push(warningMessage);
break;
}
}
if (inconsistencyWarnings.length !== 0) {
const warningMessage =
'The segmentation format is not supported yet. ' +
'The segmentation data (segments) could not be loaded.';
inconsistencyWarnings.push(warningMessage);
if (displaySet.loadError) {
inconsistencyWarnings.push(displaySet.segLoadErrorMessagge);
displaySet.inconsistencyWarnings = inconsistencyWarnings;
}
}
// cache the warnings
displaySet.inconsistencyWarnings = inconsistencyWarnings;
return inconsistencyWarnings;
};
@@ -736,10 +672,7 @@ const _mapStudiesToThumbnails = function(studies, activeDisplaySetInstanceUID) {
altImageText = displaySet.Modality ? displaySet.Modality : 'UN';
}
const hasWarnings = _checkForSeriesInconsistencesWarnings(
displaySet,
studies
);
const hasWarnings = _checkForSeriesInconsistencesWarnings(displaySet);
const hasDerivedDisplaySets = _checkForDerivedDisplaySets(
displaySet,