Compare commits

..
2 Commits
Author SHA1 Message Date
Ross 174c7a444f add the ability to load by imageid 2024-10-07 08:55:36 +01:00
Ross 5ceacc441d fix loading in some situations 2024-02-25 09:26:08 +00:00
3 changed files with 49 additions and 34 deletions
+43 -32
View File
@@ -585,13 +585,14 @@ export function loadCornerstone(main_element, db, images, annotations_to_load, l
//});
} 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;
// Cornerstone needs the whole url to load? (not relative)
if (data_url.startsWith("http")) {
url = data_url;
} else {
url = window.location.href.replace(/\/\#\/?$/, '').replace("index.html", "") + "/" + data_url
}
//url = data_url;
if (url.endsWith("dcm")) {
url = "wadouri:" + url;
@@ -618,7 +619,11 @@ export function loadCornerstone(main_element, db, images, annotations_to_load, l
//console.log("LOAD and cache, then", image);
loadCornerstoneMainImage(element, image, stack, db, load_as_stack);
checkAnonStatus(image.data)
// We can only check dicom data if it exists (e.g. not on jpegs)
if (image.data != undefined) {
checkAnonStatus(image.data)
}
let load_annotation_image = true;
if (load_annotation_image) {
@@ -1215,6 +1220,12 @@ export function loadStackIndex(new_index, dicom_element) {
//c = cornerstone.getEnabledElement(dicom_element)
}
export function loadImageById(imageId, dicom_element) {
cornerstone.loadImage(imageId).then(b => {
cornerstone.displayImage(dicom_element, b);
});
}
function urltoFile(url, filename, mimeType) {
return fetch(url)
.then(function (res) {
@@ -1277,34 +1288,34 @@ export function getNextAnnotationImage(element) {
}
function manualScrollDicom(n, dicom_element) {
// There must be a better way to do this...
//dicom_element = document.getElementById("dicom-image");
let c = cornerstone.getEnabledElement(dicom_element);
// There must be a better way to do this...
//dicom_element = document.getElementById("dicom-image");
let c = cornerstone.getEnabledElement(dicom_element);
let max = c.toolStateManager.toolState.stack.data[0].imageIds.length;
let max = c.toolStateManager.toolState.stack.data[0].imageIds.length;
if (max < 2) {
return;
}
if (max < 2) {
return;
}
let current_index =
c.toolStateManager.toolState.stack.data[0].currentImageIdIndex;
let current_index =
c.toolStateManager.toolState.stack.data[0].currentImageIdIndex;
let new_index = current_index + n
let corrected_index = Math.min(Math.max(new_index, 0), max)
let new_index = current_index + n
// TODO: if loop
//if (new_index >= max) {
// corrected_index = new_index - max;
//} else if (new_index < 0) {
// corrected_index = new_index + max;
//}
let corrected_index = Math.min(Math.max(new_index, 0), max)
c.toolStateManager.toolState.stack.data[0].currentImageIdIndex = corrected_index;
let id = c.toolStateManager.toolState.stack.data[0].imageIds[corrected_index];
cornerstone.loadImage(id).then((b) => {
cornerstone.displayImage(dicom_element, b);
});
// c = cornerstone.getEnabledElement(dicom_element)
// TODO: if loop
//if (new_index >= max) {
// corrected_index = new_index - max;
//} else if (new_index < 0) {
// corrected_index = new_index + max;
//}
c.toolStateManager.toolState.stack.data[0].currentImageIdIndex = corrected_index;
let id = c.toolStateManager.toolState.stack.data[0].imageIds[corrected_index];
cornerstone.loadImage(id).then((b) => {
cornerstone.displayImage(dicom_element, b);
});
// c = cornerstone.getEnabledElement(dicom_element)
}
+3 -1
View File
@@ -24,11 +24,13 @@
<main>
<h1>A dicom viewer</h1>
<div id="dicom-viewer" class="dicom-viewer" style="height: 600px;" data-images='["test_images/1.jpg","test_images/IMG1.dcm"]' data-annotations=""></div></div>
<!-- <div id="dicom-viewer" class="dicom-viewer" style="height: 600px;" data-images='["test_images/IMG1.dcm","test_images/IMG1.dcm"]' data-annotations='[&quot;{\&quot;ArrowAnnotate\&quot;:{\&quot;data\&quot;:[{\&quot;visible\&quot;:true,\&quot;active\&quot;:false,\&quot;handles\&quot;:{\&quot;start\&quot;:{\&quot;x\&quot;:450.01249999999993,\&quot;y\&quot;:592.8031510416666,\&quot;highlight\&quot;:true,\&quot;active\&quot;:false},\&quot;end\&quot;:{\&quot;x\&quot;:283.38750000000005,\&quot;y\&quot;:343.976484375,\&quot;highlight\&quot;:true,\&quot;active\&quot;:false,\&quot;moving\&quot;:false},\&quot;textBox\&quot;:{\&quot;active\&quot;:false,\&quot;hasMoved\&quot;:false,\&quot;movesIndependently\&quot;:false,\&quot;drawnIndependently\&quot;:true,\&quot;allowedOutsideImage\&quot;:true,\&quot;hasBoundingBox\&quot;:true}},\&quot;uuid\&quot;:\&quot;51ca68b0-734c-4046-b3da-dd2886496fd5\&quot;,\&quot;invalidated\&quot;:true}]}}&quot;, null]'></div></div> -->
<div id="dicom-viewer" class="dicom-viewer" style="height: 600px;" data-images='["test_images/IMG1.dcm", "test_images/IMG2.dcm", "test_images/IMG3.dcm", "test_images/IMG4.dcm", "test_images/IMG5.dcm", "test_images/IMG6.dcm"]' data-annotations=''></div>
<!-- <div id="dicom-viewer" class="dicom-viewer" style="height: 600px;" data-images='["test_images/IMG1.dcm", "test_images/IMG2.dcm", "test_images/IMG3.dcm", "test_images/IMG4.dcm", "test_images/IMG5.dcm", "test_images/IMG6.dcm"]' data-annotations=''></div> -->
<!-- <div id="dicom-viewer2" class="dicom-viewer" style="height: 600px;" data-images='["test_images/IMG1.dcm", "test_images/IMG2.dcm", "test_images/IMG3.dcm", "test_images/IMG4.dcm", "test_images/IMG5.dcm", "test_images/IMG6.dcm"]' data-annotations=''></div> -->
<!-- <div id="dicom-viewer" class="dicom-viewer" style="height: 600px;" data-images='["test_images/CXR.dcm"]' data-annotations=''></div></div> -->
</main>
<footer></footer>
</body>
+3 -1
View File
@@ -79,4 +79,6 @@ function loadDicomViewer(images_to_load, annotations_to_load) {
dicomViewer.loadCornerstone($(single_dicom2), null, images, annotations, load_as_stack);
}
}
}
}
window.dicomViewer = dicomViewer;