From 6382c990ce99d9997f69fa6b089d1b494dfe14c6 Mon Sep 17 00:00:00 2001 From: Ross Date: Thu, 7 Apr 2022 21:58:32 +0100 Subject: [PATCH] . --- anatomy/static/js/anatomy.js | 64 ++++++++++++++++++++++++++++++++---- static/js/anatomy.js | 64 ++++++++++++++++++++++++++++++++---- 2 files changed, 116 insertions(+), 12 deletions(-) diff --git a/anatomy/static/js/anatomy.js b/anatomy/static/js/anatomy.js index 043fa887..88fc5edc 100644 --- a/anatomy/static/js/anatomy.js +++ b/anatomy/static/js/anatomy.js @@ -303,14 +303,66 @@ function setUpDicom(element) { const ArrowAnnotateTool = cornerstoneTools.ArrowAnnotateTool; - const imageIds = element.dataset.url.split(","); + const images = element.dataset.url.split(","); + + //console.log("Dicom - load imageId: ", imageIds); + //for (let index = 0; index < imageIds.length; index++) { + // if (imageIds[index].endsWith("dcm")) { + // imageIds[index] = "wadouri:" + imageIds[index]; + // } + + //} + let imageIds = []; + for (let i = 0; i < images.length; i++) { + let data_url = images[i]; + // check stack type + if (data_url.startsWith("data:image")) { + let imageId = "base64://" + data_url.split(",")[1]; + + imageIds.push(imageId); + } else if (data_url.startsWith("base64://") || data_url.startsWith("wadouri:")) { + + imageIds.push(data_url); + + // Treat application/octet-stream as if they are dicoms + } else if (data_url.startsWith("data:application/dicom") || data_url.startsWith("data:application/octet-stream")) { + //stack = stack.split(";")[1]; + + let dfile = await urltoFile(data_url, "dicom", "application/dicom"); + + const imageId = cornerstoneWADOImageLoader.wadouri.fileManager.add( + dfile + ); + + loadAnnotation(imageId, annotation); + + imageIds.push(imageId); + //cornerstone.loadImage(imageId).then(function(image) { + // tempFunction(image); + //}); + } else { + let url; + // This doesn't seem to have any benefit + //if (data_url.startsWith("http")) { + // url = data_url; + //} else { + // url = window.location.href.replace(/\/\#\/?$/, '') + "/" + data_url + //} + url = data_url; + + if (url.endsWith("dcm")) { + url = "wadouri:" + url; + } + + // if there is no extension treat it as a dicom + if (/(?:\/|^)[^.\/]+$/.test(url)) { + url = "wadouri:" + url; + } + + imageIds.push(url); + - console.log("Dicom - load imageId: ", imageIds); - for (let index = 0; index < imageIds.length; index++) { - if (imageIds[index].endsWith("dcm")) { - imageIds[index] = "wadouri:" + imageIds[index]; } - } cornerstone.enable(element); diff --git a/static/js/anatomy.js b/static/js/anatomy.js index 043fa887..88fc5edc 100644 --- a/static/js/anatomy.js +++ b/static/js/anatomy.js @@ -303,14 +303,66 @@ function setUpDicom(element) { const ArrowAnnotateTool = cornerstoneTools.ArrowAnnotateTool; - const imageIds = element.dataset.url.split(","); + const images = element.dataset.url.split(","); + + //console.log("Dicom - load imageId: ", imageIds); + //for (let index = 0; index < imageIds.length; index++) { + // if (imageIds[index].endsWith("dcm")) { + // imageIds[index] = "wadouri:" + imageIds[index]; + // } + + //} + let imageIds = []; + for (let i = 0; i < images.length; i++) { + let data_url = images[i]; + // check stack type + if (data_url.startsWith("data:image")) { + let imageId = "base64://" + data_url.split(",")[1]; + + imageIds.push(imageId); + } else if (data_url.startsWith("base64://") || data_url.startsWith("wadouri:")) { + + imageIds.push(data_url); + + // Treat application/octet-stream as if they are dicoms + } else if (data_url.startsWith("data:application/dicom") || data_url.startsWith("data:application/octet-stream")) { + //stack = stack.split(";")[1]; + + let dfile = await urltoFile(data_url, "dicom", "application/dicom"); + + const imageId = cornerstoneWADOImageLoader.wadouri.fileManager.add( + dfile + ); + + loadAnnotation(imageId, annotation); + + imageIds.push(imageId); + //cornerstone.loadImage(imageId).then(function(image) { + // tempFunction(image); + //}); + } else { + let url; + // This doesn't seem to have any benefit + //if (data_url.startsWith("http")) { + // url = data_url; + //} else { + // url = window.location.href.replace(/\/\#\/?$/, '') + "/" + data_url + //} + url = data_url; + + if (url.endsWith("dcm")) { + url = "wadouri:" + url; + } + + // if there is no extension treat it as a dicom + if (/(?:\/|^)[^.\/]+$/.test(url)) { + url = "wadouri:" + url; + } + + imageIds.push(url); + - console.log("Dicom - load imageId: ", imageIds); - for (let index = 0; index < imageIds.length; index++) { - if (imageIds[index].endsWith("dcm")) { - imageIds[index] = "wadouri:" + imageIds[index]; } - } cornerstone.enable(element);