2020-08-10 11:20:31 +02:00
|
|
|
import { utils, log } from '@ohif/core';
|
|
|
|
|
import cornerstoneTools from 'cornerstone-tools';
|
|
|
|
|
import refreshViewports from './refreshViewports';
|
|
|
|
|
|
|
|
|
|
const { studyMetadataManager } = utils;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
* @param {*} viewportSpecificData
|
|
|
|
|
* @param {*} studies
|
|
|
|
|
* @param {*} displaySet
|
|
|
|
|
* @param {*} firstImageId
|
|
|
|
|
* @param {*} activeLabelmapIndex
|
|
|
|
|
* @returns
|
|
|
|
|
*/
|
|
|
|
|
export default async function setActiveLabelmap(
|
|
|
|
|
referencedDisplaySet,
|
|
|
|
|
studies,
|
|
|
|
|
displaySet,
|
|
|
|
|
callback = () => {},
|
|
|
|
|
onDisplaySetLoadFailure = err => {
|
|
|
|
|
throw new Error(err.message);
|
|
|
|
|
}
|
|
|
|
|
) {
|
|
|
|
|
const studyMetadata = studyMetadataManager.get(
|
|
|
|
|
referencedDisplaySet.StudyInstanceUID
|
|
|
|
|
);
|
|
|
|
|
const firstImageId = studyMetadata.getFirstImageId(
|
|
|
|
|
referencedDisplaySet.displaySetInstanceUID
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
let { state } = cornerstoneTools.getModule('segmentation');
|
|
|
|
|
|
|
|
|
|
let brushStackState = state.series[firstImageId];
|
|
|
|
|
const activeLabelmapIndex = brushStackState
|
|
|
|
|
? brushStackState.activeLabelmapIndex
|
|
|
|
|
: undefined;
|
|
|
|
|
|
2021-01-16 01:19:12 -03:00
|
|
|
let labelmapIndex =
|
|
|
|
|
displaySet.hasOverlapping === true
|
|
|
|
|
? displaySet.originLabelMapIndex
|
|
|
|
|
: displaySet.labelmapIndex;
|
|
|
|
|
|
|
|
|
|
if (labelmapIndex === activeLabelmapIndex) {
|
2020-08-10 11:20:31 +02:00
|
|
|
log.warn(`${activeLabelmapIndex} is already the active labelmap`);
|
2021-01-16 01:19:12 -03:00
|
|
|
return labelmapIndex;
|
2020-08-10 11:20:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!displaySet.isLoaded) {
|
|
|
|
|
const loadPromise = displaySet.load(referencedDisplaySet, studies);
|
|
|
|
|
|
|
|
|
|
loadPromise.catch(error => {
|
|
|
|
|
onDisplaySetLoadFailure(error);
|
|
|
|
|
|
|
|
|
|
// Return old index.
|
|
|
|
|
return activeLabelmapIndex;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
await loadPromise;
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-16 01:19:12 -03:00
|
|
|
labelmapIndex =
|
|
|
|
|
displaySet.hasOverlapping === true
|
|
|
|
|
? displaySet.originLabelMapIndex
|
|
|
|
|
: displaySet.labelmapIndex;
|
|
|
|
|
|
2020-08-10 11:20:31 +02:00
|
|
|
// This might have just been created, so need to use the non-cached value.
|
|
|
|
|
state = cornerstoneTools.getModule('segmentation').state;
|
|
|
|
|
brushStackState = state.series[firstImageId];
|
2021-01-16 01:19:12 -03:00
|
|
|
brushStackState.activeLabelmapIndex = labelmapIndex;
|
2020-08-10 11:20:31 +02:00
|
|
|
|
|
|
|
|
refreshViewports();
|
|
|
|
|
callback();
|
|
|
|
|
|
2021-01-16 01:19:12 -03:00
|
|
|
return labelmapIndex;
|
2020-08-10 11:20:31 +02:00
|
|
|
}
|