2022-07-27 18:39:04 +02:00
|
|
|
import * as cornerstone from '@cornerstonejs/core';
|
|
|
|
|
import { volumeLoader } from '@cornerstonejs/core';
|
|
|
|
|
import { cornerstoneStreamingImageVolumeLoader } from '@cornerstonejs/streaming-image-volume-loader';
|
2023-04-27 02:55:56 +02:00
|
|
|
import dicomImageLoader, {
|
2022-11-16 20:19:52 +01:00
|
|
|
webWorkerManager,
|
2023-04-27 02:55:56 +02:00
|
|
|
} from '@cornerstonejs/dicom-image-loader';
|
2020-05-15 12:48:00 +02:00
|
|
|
import dicomParser from 'dicom-parser';
|
2021-09-24 09:06:52 +02:00
|
|
|
import { errorHandler } from '@ohif/core';
|
2020-05-15 12:48:00 +02:00
|
|
|
|
2022-07-27 18:39:04 +02:00
|
|
|
const { registerVolumeLoader } = volumeLoader;
|
|
|
|
|
|
2021-06-23 20:41:27 +02:00
|
|
|
let initialized = false;
|
2020-05-15 12:48:00 +02:00
|
|
|
|
2022-07-27 18:39:04 +02:00
|
|
|
function initWebWorkers(appConfig) {
|
2021-06-23 20:41:27 +02:00
|
|
|
const config = {
|
2022-07-27 18:39:04 +02:00
|
|
|
maxWebWorkers: Math.min(
|
|
|
|
|
Math.max(navigator.hardwareConcurrency - 1, 1),
|
|
|
|
|
appConfig.maxNumberOfWebWorkers
|
|
|
|
|
),
|
2021-06-23 20:41:27 +02:00
|
|
|
startWebWorkersOnDemand: true,
|
|
|
|
|
taskConfiguration: {
|
|
|
|
|
decodeTask: {
|
|
|
|
|
initializeCodecsOnStartup: false,
|
|
|
|
|
usePDFJS: false,
|
|
|
|
|
strict: false,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
};
|
2020-05-15 12:48:00 +02:00
|
|
|
|
2021-06-23 20:41:27 +02:00
|
|
|
if (!initialized) {
|
2023-04-27 02:55:56 +02:00
|
|
|
dicomImageLoader.webWorkerManager.initialize(config);
|
2021-06-23 20:41:27 +02:00
|
|
|
initialized = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-05-15 12:48:00 +02:00
|
|
|
|
2022-07-27 18:39:04 +02:00
|
|
|
export default function initWADOImageLoader(
|
2023-02-13 14:55:55 +01:00
|
|
|
userAuthenticationService,
|
2022-07-27 18:39:04 +02:00
|
|
|
appConfig
|
|
|
|
|
) {
|
2023-04-27 02:55:56 +02:00
|
|
|
dicomImageLoader.external.cornerstone = cornerstone;
|
|
|
|
|
dicomImageLoader.external.dicomParser = dicomParser;
|
2021-06-23 20:41:27 +02:00
|
|
|
|
2022-07-27 18:39:04 +02:00
|
|
|
registerVolumeLoader(
|
|
|
|
|
'cornerstoneStreamingImageVolume',
|
|
|
|
|
cornerstoneStreamingImageVolumeLoader
|
|
|
|
|
);
|
|
|
|
|
|
2023-04-27 02:55:56 +02:00
|
|
|
dicomImageLoader.configure({
|
2022-07-27 18:39:04 +02:00
|
|
|
decodeConfig: {
|
|
|
|
|
// !! IMPORTANT !!
|
2023-04-27 02:55:56 +02:00
|
|
|
// We should set this flag to false, since, by default @cornerstonejs/dicom-image-loader
|
2022-07-27 18:39:04 +02:00
|
|
|
// will convert everything to integers (to be able to work with cornerstone-2d).
|
|
|
|
|
// Until the default is set to true (which is the case for cornerstone3D),
|
|
|
|
|
// we should set this flag to false.
|
|
|
|
|
convertFloatPixelDataToInt: false,
|
|
|
|
|
},
|
2023-05-18 19:06:26 +02:00
|
|
|
beforeSend: function (xhr) {
|
2023-02-13 14:55:55 +01:00
|
|
|
const headers = userAuthenticationService.getAuthorizationHeader();
|
2021-06-23 20:41:27 +02:00
|
|
|
|
2021-09-24 09:06:52 +02:00
|
|
|
// Request:
|
|
|
|
|
// JPEG-LS Lossless (1.2.840.10008.1.2.4.80) if available, otherwise accept
|
|
|
|
|
// whatever transfer-syntax the origin server provides.
|
|
|
|
|
// For now we use image/jls and image/x-jls because some servers still use the old type
|
|
|
|
|
// http://dicom.nema.org/medical/dicom/current/output/html/part18.html
|
2023-05-18 19:06:26 +02:00
|
|
|
|
|
|
|
|
//Initialize the accept header content
|
|
|
|
|
const acceptHeader = ['multipart/related']
|
|
|
|
|
//Storing the requesting transfer syntax specified in OHIF config
|
|
|
|
|
const requestTransferSyntaxUID = appConfig.requestTransferSyntaxUID
|
|
|
|
|
|
|
|
|
|
if (requestTransferSyntaxUID) {
|
|
|
|
|
//Check TS is valid
|
|
|
|
|
if (!Object.keys(typeForTS).includes(requestTransferSyntaxUID)) {
|
|
|
|
|
console.warn(requestTransferSyntaxUID + 'is unexpected')
|
|
|
|
|
} else {
|
|
|
|
|
//Fetch type header according to requesting TS
|
|
|
|
|
let type = typeForTS[requestTransferSyntaxUID]
|
|
|
|
|
if (type === 'application/octet-stream' && !appConfig.omitQuotationForMultipartRequest) {
|
|
|
|
|
type = '"application/octet-stream"'
|
|
|
|
|
}
|
|
|
|
|
acceptHeader.push('type=' + type)
|
|
|
|
|
acceptHeader.push('transfer-syntax=' + requestTransferSyntaxUID)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
2021-09-24 09:06:52 +02:00
|
|
|
const xhrRequestHeaders = {
|
2023-05-18 19:06:26 +02:00
|
|
|
//Serialize Accept header
|
|
|
|
|
Accept: acceptHeader.join('; ')
|
|
|
|
|
}
|
2021-09-24 09:06:52 +02:00
|
|
|
|
2021-06-23 20:41:27 +02:00
|
|
|
if (headers && headers.Authorization) {
|
2021-09-24 09:06:52 +02:00
|
|
|
xhrRequestHeaders.Authorization = headers.Authorization;
|
2021-06-23 20:41:27 +02:00
|
|
|
}
|
2021-09-24 09:06:52 +02:00
|
|
|
|
|
|
|
|
return xhrRequestHeaders;
|
2021-06-23 20:41:27 +02:00
|
|
|
},
|
2021-06-24 18:30:38 +02:00
|
|
|
errorInterceptor: error => {
|
2021-09-24 09:06:52 +02:00
|
|
|
errorHandler.getHTTPErrorHandler(error);
|
2021-06-24 18:30:38 +02:00
|
|
|
},
|
2021-06-23 20:41:27 +02:00
|
|
|
});
|
|
|
|
|
|
2022-07-27 18:39:04 +02:00
|
|
|
initWebWorkers(appConfig);
|
2021-06-23 20:41:27 +02:00
|
|
|
}
|
2023-05-18 19:06:26 +02:00
|
|
|
const typeForTS = {
|
|
|
|
|
"*": "application/octet-stream",
|
|
|
|
|
"1.2.840.10008.1.2.1": "application/octet-stream",
|
|
|
|
|
"1.2.840.10008.1.2": "application/octet-stream",
|
|
|
|
|
"1.2.840.10008.1.2.2": "application/octet-stream",
|
|
|
|
|
"1.2.840.10008.1.2.4.70": "image/jpeg",
|
|
|
|
|
"1.2.840.10008.1.2.4.50": "image/jpeg",
|
|
|
|
|
"1.2.840.10008.1.2.4.51": "image/dicom+jpeg",
|
|
|
|
|
"1.2.840.10008.1.2.4.57": "image/jpeg",
|
|
|
|
|
"1.2.840.10008.1.2.5": "image/dicom-rle",
|
|
|
|
|
"1.2.840.10008.1.2.4.80": "image/jls",
|
|
|
|
|
"1.2.840.10008.1.2.4.81": "image/jls",
|
|
|
|
|
"1.2.840.10008.1.2.4.90": "image/jp2",
|
|
|
|
|
"1.2.840.10008.1.2.4.91": "image/jp2",
|
|
|
|
|
"1.2.840.10008.1.2.4.92": "image/jpx",
|
|
|
|
|
"1.2.840.10008.1.2.4.93": "image/jpx",
|
|
|
|
|
}
|
2022-11-16 20:19:52 +01:00
|
|
|
|
|
|
|
|
export function destroy() {
|
|
|
|
|
// Note: we don't want to call .terminate on the webWorkerManager since
|
|
|
|
|
// that resets the config
|
|
|
|
|
const webWorkers = webWorkerManager.webWorkers;
|
|
|
|
|
for (let i = 0; i < webWorkers.length; i++) {
|
|
|
|
|
webWorkers[i].worker.terminate();
|
|
|
|
|
}
|
|
|
|
|
webWorkers.length = 0;
|
|
|
|
|
}
|