From 44a7d72f3a6359689bf553c8edd1fb8a473ace86 Mon Sep 17 00:00:00 2001 From: Ross Date: Sun, 6 Dec 2020 14:47:56 +0000 Subject: [PATCH] enable image annotations --- index.html | 2 +- js/viewer.js | 32 ++++++++++++++++++++++++++++++-- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/index.html b/index.html index acf9705..aab00ac 100644 --- a/index.html +++ b/index.html @@ -180,7 +180,7 @@ - + diff --git a/js/viewer.js b/js/viewer.js index 8e9b166..a277f63 100644 --- a/js/viewer.js +++ b/js/viewer.js @@ -508,14 +508,30 @@ export function openMainImage(current_question, t, source) { * Load image * @param {*} images - list of images */ - async function load(images) { + function loadAnnotation(imageId, annotation) { + const toolStateManager = cornerstoneTools.globalImageIdSpecificToolStateManager; + + if (annotation.length < 1) { return } + + let tool_state_no_id = JSON.parse(annotation); + + let tool_state = {}; + tool_state[imageId] = tool_state_no_id; + + toolStateManager.restoreToolState(tool_state); + } + async function load(images, annotations) { const imageIds = []; for (let i = 0; i < images.length; i++) { const data_url = images[i]; + const annotation = annotations[i]; + // check stack type if (data_url.startsWith("data:image")) { const imageId = "base64://" + data_url.split(",")[1]; + loadAnnotation(imageId, annotation); + imageIds.push(imageId); } else if (data_url.startsWith("data:application/dicom")) { // stack = stack.split(";")[1]; @@ -525,6 +541,9 @@ export function openMainImage(current_question, t, source) { const imageId = cornerstoneWADOImageLoader.wadouri.fileManager.add( dfile ); + + loadAnnotation(imageId, annotation); + imageIds.push(imageId); // cornerstone.loadImage(imageId).then(function(image) { // tempFunction(image); @@ -574,12 +593,21 @@ export function openMainImage(current_question, t, source) { let images = current_question.images[figure_to_load.split("-")[1]]; // images = current_question.images + // Make sure we have an array if (!Array.isArray(images)) { images = [images]; } - load(images); + let annotations = []; + if (current_question.annotations) { + annotations = current_question.annotations[figure_to_load.split("-")[1]]; + if (!Array.isArray(annotations)) { + annotations = [annotations]; + } + } + + load(images, annotations); } }