initiate
This commit is contained in:
+101
@@ -0,0 +1,101 @@
|
||||
.canvas-panel {
|
||||
height: 100%;
|
||||
position: relative;
|
||||
color: white;
|
||||
}
|
||||
|
||||
|
||||
#dicom-overlay {
|
||||
position: absolute;
|
||||
bottom: 0;
|
||||
}
|
||||
|
||||
#image-thumbs {
|
||||
position: absolute;
|
||||
right: 0;
|
||||
top: 50%;
|
||||
transform: translateY(-50%);
|
||||
overflow-y: auto;
|
||||
max-height: 100%;
|
||||
max-width: 30%;
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
.thumbnail {
|
||||
pointer-events: none;
|
||||
display: block;
|
||||
margin: auto;
|
||||
}
|
||||
|
||||
.thumb {
|
||||
position: relative;
|
||||
border: 1px dotted blue;
|
||||
}
|
||||
|
||||
.thumb-active {
|
||||
border: 5px dotted blue;
|
||||
}
|
||||
|
||||
.thumb span {
|
||||
position: absolute;
|
||||
right: 0;
|
||||
color: lightblue;
|
||||
}
|
||||
|
||||
.single-dicom-viewer {
|
||||
position: relative;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.dicom-button {
|
||||
font-size: 40px;
|
||||
z-index: 99;
|
||||
opacity: 20%;
|
||||
color: gray;
|
||||
top: 0;
|
||||
}
|
||||
|
||||
.dicom-button:hover {
|
||||
opacity: 100%;
|
||||
}
|
||||
|
||||
#dicom-toggle-mode-button {
|
||||
position: absolute;
|
||||
left: 0;
|
||||
}
|
||||
|
||||
#dicom-settings-button {
|
||||
position: absolute;
|
||||
right: 0;
|
||||
}
|
||||
|
||||
#dicom-fullscreen-button {
|
||||
position: absolute;
|
||||
transform: translate(0, -20%);
|
||||
right: 50%;
|
||||
}
|
||||
|
||||
#dicom-settings-panel {
|
||||
display: none;
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
transform: translate(-50%, -50%);
|
||||
padding-left: 30px;
|
||||
padding-right: 30px;
|
||||
padding-bottom: 20px;
|
||||
background-color: rgba(0, 0, 0, 0.8); /* Black w/ opacity */
|
||||
max-width: 100%;
|
||||
max-height: 100%;
|
||||
z-index: 999;
|
||||
}
|
||||
|
||||
#dicom-window-panel {
|
||||
position: absolute;
|
||||
top: 100%;
|
||||
transform: translate(0, -100%);
|
||||
opacity: 0.0;
|
||||
}
|
||||
#dicom-window-panel:hover {
|
||||
opacity: 1;
|
||||
}
|
||||
+644
@@ -0,0 +1,644 @@
|
||||
// Dicom saved settings
|
||||
var dicom_settings_db = new Dexie("dicom_settings");
|
||||
dicom_settings_db.version(1).stores({
|
||||
mouse_bindings: "button,mode,tool",
|
||||
});
|
||||
|
||||
|
||||
cornerstoneBase64ImageLoader.external.cornerstone = cornerstone;
|
||||
cornerstoneWebImageLoader.external.cornerstone = cornerstone;
|
||||
cornerstoneWADOImageLoader.external.cornerstone = cornerstone;
|
||||
|
||||
cornerstoneTools.init();
|
||||
|
||||
|
||||
|
||||
export function loadCornerstone(main_element, db, images, annotations_to_load, load_as_stack = false) {
|
||||
// canvas-panel holds the enabled elements and all tools / menus
|
||||
main_element.append("<div class='canvas-panel'></div>");
|
||||
$(".canvas-panel").append($("<div class='single-dicom-viewer'></div>"));
|
||||
|
||||
let single_dicom_viewer = main_element.find(".single-dicom-viewer").get(0);
|
||||
console.log(single_dicom_viewer);
|
||||
// Add generic settings menus to canvas-panel
|
||||
$(".canvas-panel").append(
|
||||
$(`<div id='dicom-settings-panel'>
|
||||
<span id="dicom-settings-close" class="close-button"><a href="#">close</a></span>
|
||||
<h3>Image viewer settings:</h3>
|
||||
|
||||
Primary
|
||||
<div id="primary-mouse-binding">
|
||||
<label for="left-mouse-dicom">Left mouse button:</label>
|
||||
<select
|
||||
id="left-mouse-dicom"
|
||||
class="mouse-binding-select"
|
||||
data-button="1"
|
||||
data-mode="0"
|
||||
>
|
||||
</select>
|
||||
<label for="middle-mouse-dicom">Middle mouse button:</label>
|
||||
<select
|
||||
id="middle-mouse-dicom"
|
||||
class="mouse-binding-select"
|
||||
data-button="4"
|
||||
data-mode="0"
|
||||
>
|
||||
</select>
|
||||
<label for="right-mouse-dicom">Right mouse button:</label>
|
||||
<select
|
||||
id="right-mouse-dicom"
|
||||
class="mouse-binding-select"
|
||||
data-button="2"
|
||||
data-mode="0"
|
||||
>
|
||||
</select>
|
||||
</div>
|
||||
<br />
|
||||
Secondary (Ctrl)
|
||||
<div id="secondary-mouse-binding">
|
||||
<label for="left-mouse-dicom-secondary">Left mouse button:</label>
|
||||
<select
|
||||
id="left-mouse-dicom-secondary"
|
||||
class="mouse-binding-select"
|
||||
data-button="1"
|
||||
data-mode="1"
|
||||
>
|
||||
</select>
|
||||
<label for="middle-mouse-dicom-secondary">Middle mouse button:</label>
|
||||
<select
|
||||
id="middle-mouse-dicom-secondary"
|
||||
class="mouse-binding-select"
|
||||
data-button="4"
|
||||
data-mode="1"
|
||||
>
|
||||
</select>
|
||||
<label for="right-mouse-dicom-secondary">Right mouse button:</label>
|
||||
<select
|
||||
id="right-mouse-dicom-secondary"
|
||||
class="mouse-binding-select"
|
||||
data-button="2"
|
||||
data-mode="1"
|
||||
>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
</div>`)
|
||||
)
|
||||
.append($("<span id='dicom-toggle-mode-button' class='dicom-button' title='toggle stack/thumbnail view'>↻</span>"))
|
||||
.append($("<span id='dicom-fullscreen-button' class='dicom-button' title='toggle stack/thumbnail view'>⛶</span>"))
|
||||
.append($("<span id='dicom-settings-button' class='dicom-button' title='open settings'>⚙</span>"));
|
||||
|
||||
$(single_dicom_viewer).append(
|
||||
$(
|
||||
"<div id='dicom-overlay'>Image <span id='current_image_number'></span> of <span id='total_image_number'></span><br />wc: <span id='wc'></span> ww: <span id='ww'></span></div>"
|
||||
)
|
||||
)
|
||||
// Add buttons
|
||||
.append(
|
||||
$(`<div id='dicom-window-panel'>
|
||||
<button id='window-btn-abdomen'>Abdomen</button>
|
||||
<button id='window-btn-liver'>Liver</button>
|
||||
<button id='window-btn-mediastinum'>Mediastinum</button>
|
||||
<button id='window-btn-lung'>Lungs</button>
|
||||
<button id='window-btn-brain'>Brain</button>
|
||||
<button id='window-btn-stroke'>Stroke</button>
|
||||
<button id='window-btn-bone'>Bone</button>
|
||||
</div>`)
|
||||
);
|
||||
|
||||
let window_presets = {
|
||||
"window-btn-abdomen": [400, 50],
|
||||
"window-btn-liver": [150, 30],
|
||||
"window-btn-mediastinum": [350, 50],
|
||||
"window-btn-lung": [1500, -600],
|
||||
"window-btn-brain": [80, 40],
|
||||
"window-btn-stroke": [40, 40],
|
||||
"window-btn-bone": [1800, 400]
|
||||
}
|
||||
|
||||
$("#dicom-window-panel button").each((n, el) => {
|
||||
$(el).click((e) => {
|
||||
console.log(e);
|
||||
console.log(e.target);
|
||||
let button_id = e.target.id;
|
||||
let [ww, wc] = window_presets[button_id];
|
||||
|
||||
let viewport = cornerstone.getViewport(single_dicom_viewer);
|
||||
viewport.voi.windowWidth = parseFloat(ww);
|
||||
viewport.voi.windowCenter = parseFloat(wc);
|
||||
cornerstone.setViewport(single_dicom_viewer, viewport);
|
||||
|
||||
e.preventDefault();
|
||||
})
|
||||
})
|
||||
|
||||
$("#dicom-settings-close").click(e => {
|
||||
$("#dicom-settings-panel").hide();
|
||||
e.preventDefault();
|
||||
});
|
||||
$("#dicom-settings-button").click(e => {
|
||||
$("#dicom-settings-panel").toggle();
|
||||
});
|
||||
$("#dicom-fullscreen-button").click(e => {
|
||||
if (!document.fullscreenElement) {
|
||||
$(".canvas-panel").get(0).requestFullscreen().catch(err => {
|
||||
alert(`Error attempting to enable full-screen mode: ${err.message} (${err.name})`);
|
||||
});
|
||||
} else {
|
||||
document.exitFullscreen();
|
||||
}
|
||||
});
|
||||
$("#dicom-toggle-mode-button").click(e => {
|
||||
//$("#dicom-settings-panel").toggle();
|
||||
let stack = !load_as_stack;
|
||||
$(main_element).empty();
|
||||
loadCornerstone(main_element, db, images, annotations_to_load, stack)
|
||||
});
|
||||
|
||||
//let images = data["images"];
|
||||
|
||||
// Make sure we have an array
|
||||
if (!Array.isArray(images)) {
|
||||
images = [images];
|
||||
}
|
||||
|
||||
//let annotations = [];
|
||||
//if (annotations_to_load) {
|
||||
//annotations = annotations_to_load[figure_to_load.split("-")[1]];
|
||||
//if (!Array.isArray(annotations)) {
|
||||
//annotations = [annotations];
|
||||
//}
|
||||
//}
|
||||
let annotations = annotations_to_load;
|
||||
if (!Array.isArray(annotations)) {
|
||||
annotations = [annotations];
|
||||
}
|
||||
console.log("annon", annotations);
|
||||
|
||||
|
||||
function loadAnnotation(imageId, annotation) {
|
||||
console.log("loadAnnotations", imageId, annotations);
|
||||
const toolStateManager = cornerstoneTools.globalImageIdSpecificToolStateManager;
|
||||
|
||||
if (annotation == undefined || annotation.length < 1) { return }
|
||||
|
||||
console.log(annotation);
|
||||
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) {
|
||||
console.log("LOAD");
|
||||
let imageIds = [];
|
||||
for (let i = 0; i < images.length; i++) {
|
||||
let data_url = images[i];
|
||||
const annotation = annotations[i];
|
||||
// check stack type
|
||||
if (data_url.startsWith("data:image")) {
|
||||
let imageId = "base64://" + data_url.split(",")[1];
|
||||
|
||||
loadAnnotation(imageId, annotation);
|
||||
|
||||
imageIds.push(imageId);
|
||||
|
||||
// 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;
|
||||
if (data_url.startsWith("http")) {
|
||||
url = data_url;
|
||||
} else {
|
||||
url = window.location.href.replace(/\/\#\/?$/, '') + "/" + 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;
|
||||
}
|
||||
|
||||
loadAnnotation(url, annotation);
|
||||
|
||||
imageIds.push(url);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
const stack = {
|
||||
currentImageIdIndex: 0,
|
||||
imageIds
|
||||
};
|
||||
//cornerstone.loadAndCacheImage(imageIds[0]).then(function(image) {
|
||||
console.log("load and cache", imageIds[0])
|
||||
cornerstone.loadAndCacheImage(imageIds[0]).then(function (image) {
|
||||
|
||||
console.log("LOAD and cache, then");
|
||||
loadCornerstoneMainImage(single_dicom_viewer, image, stack, db, load_as_stack);
|
||||
})
|
||||
.catch((err, err2) => {
|
||||
console.log(err);
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
if (images.length > 1 && load_as_stack == false) {
|
||||
$(".canvas-panel").append("<div id='image-thumbs'></div>");
|
||||
for (let id = 0; id < images.length; id++) {
|
||||
let n = id + 1;
|
||||
let thumb = $(
|
||||
"<div class='thumb' id='thumb-" +
|
||||
id +
|
||||
"' data-id=" +
|
||||
id +
|
||||
"><span>" +
|
||||
n +
|
||||
"</span></div>"
|
||||
);
|
||||
$("#image-thumbs").append(thumb);
|
||||
$("#thumb-" + id).click(selectThumbClick).mousedown(stopEvent);
|
||||
|
||||
let image_url = images[id];
|
||||
|
||||
let img;
|
||||
|
||||
if (image_url.startsWith("data")) {
|
||||
// based (image) data url, just load the image directly
|
||||
if (image_url.startsWith("data:image/")) {
|
||||
img = $("<img />", {
|
||||
src: image_url,
|
||||
id: "thumb-image-" + id,
|
||||
class: "thumbnail",
|
||||
title: "Click on the thumbnail to view and manipulate the image.",
|
||||
draggable: "false",
|
||||
style: "height: 100px;"
|
||||
});
|
||||
|
||||
$("#thumb-" + id).append(img);
|
||||
|
||||
// otherwise try to load it as a dicom
|
||||
} else {
|
||||
// convert the data url to a file
|
||||
urltoFile(image_url, "dicom", "application/dicom").then(function (
|
||||
dfile
|
||||
) {
|
||||
// load the file using cornerstoneWADO file loader
|
||||
const imageId = cornerstoneWADOImageLoader.wadouri.fileManager.add(
|
||||
dfile
|
||||
);
|
||||
cornerstone.loadAndCacheImage(imageId).then(function (image) {
|
||||
img = $("<div></div>").get(0);
|
||||
img.id = "thumb-image-" + id;
|
||||
img.class = "thumbnail";
|
||||
img.title =
|
||||
"Click on the thumbnail to view and manipulate the image.";
|
||||
img.draggable = "false";
|
||||
img.style = "height: 100px; width: 100px";
|
||||
$("#thumb-" + id).append(img);
|
||||
|
||||
const element = document.getElementById("thumb-image-" + id);
|
||||
cornerstone.enable(element);
|
||||
cornerstone.displayImage(element, image);
|
||||
cornerstone.resize(element);
|
||||
}); //.catch( function(error) {
|
||||
});
|
||||
}
|
||||
} else {
|
||||
if (!image_url.endsWith("dicom") && !image_url.endsWith("dcm")) {
|
||||
img = $("<img />", {
|
||||
src: image_url,
|
||||
id: "thumb-image-" + id,
|
||||
class: "thumbnail",
|
||||
title: "Click on the thumbnail to view and manipulate the image.",
|
||||
draggable: "false",
|
||||
style: "height: 100px;"
|
||||
});
|
||||
|
||||
$("#thumb-" + id).append(img);
|
||||
|
||||
// otherwise try to load it as a dicom
|
||||
} else {
|
||||
|
||||
let url = "wadouri:" + image_url;
|
||||
cornerstone.loadAndCacheImage(url).then(function (image) {
|
||||
img = $("<div></div>").get(0);
|
||||
img.id = "thumb-image-" + id;
|
||||
img.class = "thumbnail";
|
||||
img.title =
|
||||
"Click on the thumbnail to view and manipulate the image.";
|
||||
img.draggable = "false";
|
||||
img.style = "height: 100px; width: 100px";
|
||||
$("#thumb-" + id).append(img);
|
||||
|
||||
const element = document.getElementById("thumb-image-" + id);
|
||||
cornerstone.enable(element);
|
||||
cornerstone.displayImage(element, image);
|
||||
cornerstone.resize(element);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
load(images, annotations);
|
||||
}
|
||||
|
||||
function loadCornerstoneMainImage(element, image, stack, db, load_as_stack) {
|
||||
console.log("loadCornerstoneMainImage")
|
||||
console.log("load as stack:", load_as_stack)
|
||||
// It is probably silly to do this each time we load a question
|
||||
const PanTool = cornerstoneTools.PanTool;
|
||||
const ZoomTool = cornerstoneTools.ZoomTool;
|
||||
const ZoomMouseWheelTool = cornerstoneTools.ZoomMouseWheelTool;
|
||||
const StackScrollMouseWheelTool = cornerstoneTools.StackScrollMouseWheelTool;
|
||||
const WwwcTool = cornerstoneTools.WwwcTool;
|
||||
const WwwcRegionTool = cornerstoneTools.WwwcRegionTool;
|
||||
const RotateTool = cornerstoneTools.RotateTool;
|
||||
const StackScrollTool = cornerstoneTools.StackScrollTool;
|
||||
const MagnifyTool = cornerstoneTools.MagnifyTool;
|
||||
const ArrowAnnotateTool = cornerstoneTools.ArrowAnnotateTool;
|
||||
const LengthTool = cornerstoneTools.LengthTool;
|
||||
|
||||
console.log("enable element", element);
|
||||
cornerstone.enable(element);
|
||||
|
||||
cornerstone.displayImage(element, image);
|
||||
|
||||
cornerstoneTools.addStackStateManager(element, ["stack"]);
|
||||
cornerstoneTools.addToolState(element, "stack", stack);
|
||||
|
||||
cornerstoneTools.addTool(PanTool);
|
||||
cornerstoneTools.addTool(ZoomTool);
|
||||
cornerstoneTools.addTool(ZoomMouseWheelTool);
|
||||
cornerstoneTools.addTool(StackScrollMouseWheelTool);
|
||||
cornerstoneTools.addTool(WwwcTool);
|
||||
cornerstoneTools.addTool(WwwcRegionTool);
|
||||
cornerstoneTools.addTool(RotateTool);
|
||||
cornerstoneTools.addTool(StackScrollTool);
|
||||
cornerstoneTools.addTool(MagnifyTool);
|
||||
cornerstoneTools.addTool(LengthTool);
|
||||
|
||||
cornerstoneTools.addTool(ArrowAnnotateTool, {
|
||||
configuration: {
|
||||
getTextCallback: () => { },
|
||||
changeTextCallback: () => { },
|
||||
allowEmptyLabel: true,
|
||||
renderDashed: false,
|
||||
drawHandles: false,
|
||||
drawHandlesOnHover: true,
|
||||
},
|
||||
});
|
||||
|
||||
cornerstoneTools.setToolEnabled("ArrowAnnotate");
|
||||
|
||||
|
||||
let available_tools = [
|
||||
"Pan",
|
||||
"Zoom",
|
||||
"Wwwc",
|
||||
"WwwcRegion",
|
||||
"Rotate",
|
||||
"StackScroll",
|
||||
"Magnify",
|
||||
"Length",
|
||||
];
|
||||
$(".mouse-binding-select option").remove();
|
||||
|
||||
available_tools.forEach(function (tool) {
|
||||
let option = "<option value=" + tool + ">" + tool + "</option>";
|
||||
$(".mouse-binding-select").append(option);
|
||||
//$("#left-mouse-dicom").append(option);
|
||||
//$("#middle-mouse-dicom").append(option);
|
||||
//$("#right-mouse-dicom").append(option);
|
||||
});
|
||||
$(".mouse-binding-select").on("change", function (e) {
|
||||
changeMouseBinding(e, db);
|
||||
});
|
||||
|
||||
// Set default tools
|
||||
$("#primary-mouse-binding .mouse-binding-select[data-button=1]").val("Pan");
|
||||
$("#primary-mouse-binding .mouse-binding-select[data-button=2]").val("Wwwc");
|
||||
$("#primary-mouse-binding .mouse-binding-select[data-button=4]").val("Zoom");
|
||||
//cornerstoneTools.setToolActive("Pan", { mouseButtonMask: 1 });
|
||||
|
||||
console.log(load_as_stack);
|
||||
if (load_as_stack) {
|
||||
cornerstoneTools.setToolActive("StackScrollMouseWheel", { mouseButtonMask: 3 });
|
||||
} else {
|
||||
cornerstoneTools.setToolActive("ZoomMouseWheel", { mouseButtonMask: 3 });
|
||||
}
|
||||
//cornerstoneTools.setToolActive("Zoom", { mouseButtonMask: 4 });
|
||||
//cornerstoneTools.setToolActive("Wwwc", { mouseButtonMask: 2 });
|
||||
$("#secondary-mouse-binding .mouse-binding-select[data-button=1]").val(
|
||||
"Magnify"
|
||||
);
|
||||
$("#secondary-mouse-binding .mouse-binding-select[data-button=2]").val(
|
||||
"Rotate"
|
||||
);
|
||||
$("#secondary-mouse-binding .mouse-binding-select[data-button=4]").val(
|
||||
"WwwcRegion"
|
||||
);
|
||||
|
||||
loadPrimaryDicomInterface(db);
|
||||
loadAltDicomInterface(db);
|
||||
|
||||
element.addEventListener("cornerstoneimagerendered", onImageRendered);
|
||||
|
||||
//setDicomCanvasNonFullscreen(element);
|
||||
cornerstone.reset(element);
|
||||
//element.scrollIntoView(false);
|
||||
//element.scrollTo(0);
|
||||
|
||||
$(element).dblclick(function () {
|
||||
cornerstone.reset(this);
|
||||
});
|
||||
|
||||
element.removeEventListener("wheel", element.wheelEventHandler);
|
||||
|
||||
// Add tool selector
|
||||
//$(".canvas-panel").append(
|
||||
// '<select class="control-overlay"><option value="pan">pan</option><option value="zoom">zoom</option><option value="rotate">rotate</option><option value="scroll" hidden="" disabled="">scroll (1/1)</option><option value="window">window ()</option><option value="abdomen" hidden="" disabled="">window = abdomen</option><option value="pulmonary" hidden="" disabled="">window = pulmonary</option><option value="brain" hidden="" disabled="">window = brain</option><option value="bone" hidden="" disabled="">window = bone</option><option value="reset">reset</option></select>'
|
||||
//);
|
||||
|
||||
//$(".control-overlay")
|
||||
// .get(0)
|
||||
// .addEventListener("change", changeControlSelection);
|
||||
|
||||
resizeHandler();
|
||||
|
||||
window.addEventListener("resize", resizeHandler);
|
||||
element.addEventListener(
|
||||
"contextmenu",
|
||||
function (e) {
|
||||
// do something here...
|
||||
e.preventDefault();
|
||||
},
|
||||
false
|
||||
);
|
||||
|
||||
|
||||
$(element).on("mouseup", function (event) {
|
||||
$(".magnifyTool").hide();
|
||||
});
|
||||
}
|
||||
|
||||
function resizeHandler() {
|
||||
let element = document.getElementsByClassName("single-dicom-viewer")[0];
|
||||
let h = window.innerHeight - $("#header").height() - 16;
|
||||
$(element).height(h);
|
||||
cornerstone.resize(element, true);
|
||||
}
|
||||
|
||||
async function loadPrimaryDicomInterface(db) {
|
||||
const bindings = await dicom_settings_db.mouse_bindings.where({ mode: "0" }).toArray().catch((err) => { console.log(err); });
|
||||
bindings.forEach(function (b) {
|
||||
let sel = $("#primary-mouse-binding select[data-button=" + b.button + "]").get(
|
||||
0
|
||||
);
|
||||
sel.value = b.tool;
|
||||
//sel.dispatchEvent(new Event("change"));
|
||||
});
|
||||
registerPrimaryDicomInterface();
|
||||
}
|
||||
|
||||
async function loadAltDicomInterface(db) {
|
||||
const bindings = await dicom_settings_db.mouse_bindings.where({ mode: "1" }).toArray().catch((err) => { console.log(err); });
|
||||
bindings.forEach(function (b) {
|
||||
let sel = $(
|
||||
"#secondary-mouse-binding select[data-button=" + b.button + "]"
|
||||
).get(0);
|
||||
sel.value = b.tool;
|
||||
});
|
||||
}
|
||||
|
||||
// Called when the dicom image is loaded / rendered
|
||||
function onImageRendered(e) {
|
||||
const eventData = e.detail;
|
||||
//console.log(e);
|
||||
|
||||
// Update ww/wl
|
||||
$("#wc").text(Math.round(eventData.viewport.voi.windowCenter));
|
||||
$("#ww").text(Math.round(eventData.viewport.voi.windowWidth));
|
||||
|
||||
// update stack data
|
||||
let stack = eventData.enabledElement.toolStateManager.toolState.stack.data[0];
|
||||
|
||||
$("#total_image_number").text(stack.imageIds.length);
|
||||
$("#current_image_number").text(parseInt(stack.currentImageIdIndex) + 1);
|
||||
|
||||
if (stack.imageIds.length > 1) {
|
||||
$(".thumb").removeClass("thumb-active");
|
||||
$("#thumb-" + stack.currentImageIdIndex).addClass("thumb-active");
|
||||
}
|
||||
//if (stack.imageIds.length > 1) {
|
||||
// $("option[value=scroll").prop("disabled", false);
|
||||
// $("option[value=scroll").prop("hidden", false);
|
||||
// $("option[value=scroll").text(
|
||||
// "scroll (" +
|
||||
// (stack.currentImageIdIndex + 1) +
|
||||
// "/" +
|
||||
// stack.imageIds.length +
|
||||
// ")"
|
||||
// );
|
||||
}
|
||||
|
||||
function stopEvent(evt) {
|
||||
console.log("stop", evt)
|
||||
evt.preventDefault();
|
||||
evt.stopPropagation();
|
||||
}
|
||||
|
||||
function selectThumbClick(evt) {
|
||||
let new_index = evt.currentTarget.dataset.id;
|
||||
selectThumb(new_index);
|
||||
evt.preventDefault();
|
||||
}
|
||||
|
||||
|
||||
export function registerPrimaryDicomInterface() {
|
||||
// Set mousetools based upon the selected options
|
||||
let selections = $("#primary-mouse-binding select");
|
||||
selections.each((i, option) => {
|
||||
cornerstoneTools.setToolActive(option.value, {
|
||||
mouseButtonMask: parseInt(option.dataset.button)
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
export function registerAltDicomInterface(e) {
|
||||
// Called when control is pressed
|
||||
|
||||
// Set mousetools based upon the selected options
|
||||
let selections = $("#secondary-mouse-binding select");
|
||||
selections.each((i, option) => {
|
||||
cornerstoneTools.setToolActive(option.value, {
|
||||
mouseButtonMask: parseInt(option.dataset.button)
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function changeMouseBinding(e, db) {
|
||||
let select = e.currentTarget;
|
||||
let button = select.dataset.button;
|
||||
let mode = select.dataset.mode;
|
||||
let tool = select.value;
|
||||
|
||||
// Directly activate primary tools (secondary will be activated when modifier
|
||||
// key is pressed
|
||||
if (mode == "0") {
|
||||
cornerstoneTools.setToolActive(tool, { mouseButtonMask: parseInt(button) });
|
||||
}
|
||||
|
||||
dicom_settings_db.mouse_bindings.put({ button: button, mode: mode, tool: tool });
|
||||
//db.mouse_bindings.put({button: button, mode: mode, tool: tool}).then(loadPrimaryDicomInterface());
|
||||
}
|
||||
|
||||
export function selectThumb(new_index) {
|
||||
console.log("select thumb new index", new_index);
|
||||
// There must be a better way to do this...
|
||||
let dicom_element = document.getElementsByClassName("single-dicom-viewer")[0];
|
||||
if (dicom_element == null) {
|
||||
return;
|
||||
}
|
||||
let c = cornerstone.getEnabledElement(dicom_element);
|
||||
// let current_index =
|
||||
// c.toolStateManager.toolState.stack.data[0].currentImageIdIndex;
|
||||
c.toolStateManager.toolState.stack.data[0].currentImageIdIndex = new_index;
|
||||
let id = c.toolStateManager.toolState.stack.data[0].imageIds[new_index];
|
||||
console.log("select thumb id", id);
|
||||
console.log("select thumb el", dicom_element);
|
||||
cornerstone.loadImage(id).then(b => {
|
||||
console.log("b", b);
|
||||
cornerstone.displayImage(dicom_element, b);
|
||||
});
|
||||
//c = cornerstone.getEnabledElement(dicom_element)
|
||||
}
|
||||
function urltoFile(url, filename, mimeType) {
|
||||
return fetch(url)
|
||||
.then(function (res) {
|
||||
return res.arrayBuffer();
|
||||
})
|
||||
.then(function (buf) {
|
||||
return new File([buf], filename, { type: mimeType });
|
||||
});
|
||||
}
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title></title>
|
||||
|
||||
<link rel="stylesheet" href="dicomViewer.css">
|
||||
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/dexie/3.0.3/dexie.min.js" integrity="sha512-aEtNzq8X5E0ambgeM68H174SOXaANJ6wDqJ0TuVIx4R2J4fRdUA0nLzx0faA1mmViqb+r0VX7cOXkskxyJENUA==" crossorigin="anonymous"></script>
|
||||
<script src="lib/cornerstone/hammer.js"></script>
|
||||
<script src="lib/cornerstone/cornerstone.min.js"></script>
|
||||
<script src="lib/cornerstone/dicomParser.min.js"></script>
|
||||
<script src="lib/cornerstone/cornerstoneMath.min.js"></script>
|
||||
<script src="lib/cornerstone/cornerstoneTools.min.js"></script>
|
||||
<script src="lib/cornerstone/cornerstoneWebImageLoader.min.js"></script>
|
||||
<script src="lib/cornerstone/cornerstoneWADOImageLoader.js"></script>
|
||||
<script src="lib/cornerstone/cornerstone-base64-image-loader.umd.js"></script>
|
||||
|
||||
<script src="loader.js" defer="defer" type="module"></script>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
<header></header>
|
||||
<main>
|
||||
<h1>A dicom viewer</h1>
|
||||
|
||||
<div id="dicom-viewer" class="dicom-viewer" style="height: 600px;" data-images="test_images/IMG1.dcm,test_images/IMG2.dcm" data-annotations=''></div>
|
||||
|
||||
</main>
|
||||
<footer></footer>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,242 @@
|
||||
/*! *****************************************************************************
|
||||
Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
||||
this file except in compliance with the License. You may obtain a copy of the
|
||||
License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
|
||||
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
|
||||
MERCHANTABLITY OR NON-INFRINGEMENT.
|
||||
|
||||
See the Apache Version 2.0 License for specific language governing permissions
|
||||
and limitations under the License.
|
||||
***************************************************************************** */
|
||||
|
||||
var __assign = function() {
|
||||
__assign = Object.assign || function __assign(t) {
|
||||
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
||||
s = arguments[i];
|
||||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
||||
}
|
||||
return t;
|
||||
};
|
||||
return __assign.apply(this, arguments);
|
||||
};
|
||||
|
||||
var _defaultOptions = {
|
||||
channel: 4,
|
||||
width: null,
|
||||
height: null,
|
||||
schema: 'base64://'
|
||||
};
|
||||
|
||||
var CornerstoneBase64ImageLoader = /** @class */ (function () {
|
||||
function CornerstoneBase64ImageLoader(cornerstone, options) {
|
||||
if (options === void 0) { options = _defaultOptions; }
|
||||
this._cornerstone = cornerstone;
|
||||
this._options = options;
|
||||
this._lastImageIdDrawn = null;
|
||||
this._UPNG = null;
|
||||
this._canvas = document.createElement('canvas');
|
||||
this.arrayBufferToImage = this.arrayBufferToImage.bind(this);
|
||||
this.getArrayBuffer = this.getArrayBuffer.bind(this);
|
||||
this.decodeBase64 = this.decodeBase64.bind(this);
|
||||
this.createImage = this.createImage.bind(this);
|
||||
this.imageLoader = this.imageLoader.bind(this);
|
||||
this.replaceImage = this.replaceImage.bind(this);
|
||||
}
|
||||
CornerstoneBase64ImageLoader.prototype.arrayBufferToImage = function (arrayBuffer) {
|
||||
return new Promise(function (resolve, reject) {
|
||||
var image = new Image();
|
||||
var arrayBufferView = new Uint8Array(arrayBuffer);
|
||||
var blob = new Blob([arrayBufferView]);
|
||||
var urlCreator = window.URL || window.webkitURL;
|
||||
var imageUrl = urlCreator.createObjectURL(blob);
|
||||
image.src = imageUrl;
|
||||
image.onload = function () {
|
||||
urlCreator.revokeObjectURL(imageUrl);
|
||||
resolve(image);
|
||||
};
|
||||
image.onerror = function (error) {
|
||||
urlCreator.revokeObjectURL(imageUrl);
|
||||
reject(error);
|
||||
};
|
||||
});
|
||||
};
|
||||
CornerstoneBase64ImageLoader.prototype.getArrayBuffer = function (str) {
|
||||
var buf = new ArrayBuffer(str.length);
|
||||
var bufView = new Uint8Array(buf);
|
||||
Array.from(str).map(function (ch, idx) {
|
||||
bufView[idx] = ch.charCodeAt(0);
|
||||
return ch;
|
||||
});
|
||||
return bufView;
|
||||
};
|
||||
CornerstoneBase64ImageLoader.prototype.decodeBase64 = function (base64PixelData) {
|
||||
var pixelDataAsString = window.atob(base64PixelData);
|
||||
var arrayBuffer = this.getArrayBuffer(pixelDataAsString);
|
||||
return arrayBuffer;
|
||||
};
|
||||
CornerstoneBase64ImageLoader.prototype.createImage = function (image, imageId) {
|
||||
var _this = this;
|
||||
var rows = image.naturalHeight;
|
||||
var columns = image.naturalWidth;
|
||||
var getImageData = function () {
|
||||
var context;
|
||||
if (_this._lastImageIdDrawn === imageId) {
|
||||
context = _this._canvas.getContext('2d');
|
||||
}
|
||||
else {
|
||||
_this._canvas.height = image.naturalHeight;
|
||||
_this._canvas.width = image.naturalWidth;
|
||||
context = _this._canvas.getContext('2d');
|
||||
context.drawImage(image, 0, 0);
|
||||
_this._lastImageIdDrawn = imageId;
|
||||
}
|
||||
return context.getImageData(0, 0, image.naturalWidth, image.naturalHeight);
|
||||
};
|
||||
var getPixelData = function () {
|
||||
var imageData = getImageData();
|
||||
return imageData.data;
|
||||
};
|
||||
var getCanvas = function () {
|
||||
if (_this._lastImageIdDrawn === imageId) {
|
||||
return _this._canvas;
|
||||
}
|
||||
_this._canvas.height = image.naturalHeight;
|
||||
_this._canvas.width = image.naturalWidth;
|
||||
var context = _this._canvas.getContext('2d');
|
||||
context.drawImage(image, 0, 0);
|
||||
_this._lastImageIdDrawn = imageId;
|
||||
return _this._canvas;
|
||||
};
|
||||
var setLastImageIdDrawn = function (nextLastImageIdDrawn) {
|
||||
if (nextLastImageIdDrawn === void 0) { nextLastImageIdDrawn = null; }
|
||||
_this._lastImageIdDrawn = nextLastImageIdDrawn;
|
||||
};
|
||||
return {
|
||||
imageId: imageId,
|
||||
minPixelValue: 0,
|
||||
maxPixelValue: 255,
|
||||
slope: 1,
|
||||
intercept: 0,
|
||||
windowCenter: 128,
|
||||
windowWidth: 255,
|
||||
render: this.cornerstone.renderWebImage,
|
||||
getPixelData: getPixelData,
|
||||
getCanvas: getCanvas,
|
||||
getImage: function () { return image; },
|
||||
setLastImageIdDrawn: setLastImageIdDrawn,
|
||||
rows: rows,
|
||||
columns: columns,
|
||||
height: rows,
|
||||
width: columns,
|
||||
color: true,
|
||||
rgba: false,
|
||||
columnPixelSpacing: null,
|
||||
rowPixelSpacing: null,
|
||||
invert: false,
|
||||
sizeInBytes: rows * columns * this._options.channel
|
||||
};
|
||||
};
|
||||
CornerstoneBase64ImageLoader.prototype.imageLoader = function (imageId) {
|
||||
var _this = this;
|
||||
// const schema = imageId.split('://')[0]
|
||||
var base64PixelData = imageId.replace(this._options.schema, '');
|
||||
var arrayBuffer;
|
||||
if (this._options.width && this._options.height && this._UPNG) {
|
||||
var columns = this._options.width;
|
||||
var rows = this._options.height;
|
||||
arrayBuffer = new Uint8Array(columns * rows * this._options.channel);
|
||||
arrayBuffer = this._UPNG.encode([arrayBuffer.buffer], columns, rows, 0);
|
||||
}
|
||||
else {
|
||||
arrayBuffer = this.decodeBase64(base64PixelData);
|
||||
}
|
||||
var imagePromise = this.arrayBufferToImage(arrayBuffer);
|
||||
var promise = new Promise(function (resolve, reject) {
|
||||
imagePromise.then(function (image) {
|
||||
var imageObject = _this.createImage(image, imageId);
|
||||
resolve(imageObject);
|
||||
}, reject);
|
||||
});
|
||||
return {
|
||||
promise: promise
|
||||
};
|
||||
};
|
||||
CornerstoneBase64ImageLoader.prototype.replaceImage = function (layer, arrayBuffer) {
|
||||
var _this = this;
|
||||
if (!this._UPNG) {
|
||||
return null;
|
||||
}
|
||||
var png = this._UPNG.encode([arrayBuffer.buffer], layer.image.columns, layer.image.rows, 0);
|
||||
var imagePromise = this.arrayBufferToImage(png);
|
||||
return imagePromise.then(function (image) {
|
||||
layer.image = _this.createImage(image, layer.image.imageId);
|
||||
});
|
||||
};
|
||||
Object.defineProperty(CornerstoneBase64ImageLoader.prototype, "options", {
|
||||
get: function () {
|
||||
return __assign({}, this._options);
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(CornerstoneBase64ImageLoader.prototype, "cornerstone", {
|
||||
get: function () {
|
||||
return this._cornerstone;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(CornerstoneBase64ImageLoader.prototype, "UPNG", {
|
||||
get: function () {
|
||||
return this._UPNG;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
CornerstoneBase64ImageLoader.prototype.setUPNG = function (UPNG) {
|
||||
this._UPNG = UPNG;
|
||||
};
|
||||
CornerstoneBase64ImageLoader.prototype.registerLoaders = function () {
|
||||
this.cornerstone.registerImageLoader('base64', this.imageLoader);
|
||||
};
|
||||
return CornerstoneBase64ImageLoader;
|
||||
}());
|
||||
|
||||
var _imageLoader;
|
||||
var _options = __assign({}, _defaultOptions);
|
||||
var cornerstoneBase64ImageLoader = {
|
||||
external: {
|
||||
set cornerstone(cs) {
|
||||
_imageLoader = new CornerstoneBase64ImageLoader(cs, _options);
|
||||
_imageLoader.registerLoaders();
|
||||
},
|
||||
get cornerstone() {
|
||||
return _imageLoader.cornerstone;
|
||||
},
|
||||
get UPNG() {
|
||||
return _imageLoader.UPNG;
|
||||
},
|
||||
set UPNG(_UPNG) {
|
||||
_imageLoader.setUPNG(_UPNG);
|
||||
}
|
||||
},
|
||||
initOptions: function () {
|
||||
_options = __assign({}, _defaultOptions);
|
||||
},
|
||||
set options(newOptions) {
|
||||
_options = __assign({}, _options, newOptions);
|
||||
},
|
||||
get options() {
|
||||
return __assign({}, _options);
|
||||
},
|
||||
get imageLoader() {
|
||||
return _imageLoader;
|
||||
}
|
||||
};
|
||||
|
||||
export default cornerstoneBase64ImageLoader;
|
||||
//# sourceMappingURL=cornerstone-base64-image-loader.es5.js.map
|
||||
@@ -0,0 +1,250 @@
|
||||
(function (global, factory) {
|
||||
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
|
||||
typeof define === 'function' && define.amd ? define(factory) :
|
||||
(global.cornerstoneBase64ImageLoader = factory());
|
||||
}(this, (function () { 'use strict';
|
||||
|
||||
/*! *****************************************************************************
|
||||
Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
||||
this file except in compliance with the License. You may obtain a copy of the
|
||||
License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
|
||||
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
|
||||
MERCHANTABLITY OR NON-INFRINGEMENT.
|
||||
|
||||
See the Apache Version 2.0 License for specific language governing permissions
|
||||
and limitations under the License.
|
||||
***************************************************************************** */
|
||||
|
||||
var __assign = function() {
|
||||
__assign = Object.assign || function __assign(t) {
|
||||
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
||||
s = arguments[i];
|
||||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
||||
}
|
||||
return t;
|
||||
};
|
||||
return __assign.apply(this, arguments);
|
||||
};
|
||||
|
||||
var _defaultOptions = {
|
||||
channel: 4,
|
||||
width: null,
|
||||
height: null,
|
||||
schema: 'base64://'
|
||||
};
|
||||
|
||||
var CornerstoneBase64ImageLoader = /** @class */ (function () {
|
||||
function CornerstoneBase64ImageLoader(cornerstone, options) {
|
||||
if (options === void 0) { options = _defaultOptions; }
|
||||
this._cornerstone = cornerstone;
|
||||
this._options = options;
|
||||
this._lastImageIdDrawn = null;
|
||||
this._UPNG = null;
|
||||
this._canvas = document.createElement('canvas');
|
||||
this.arrayBufferToImage = this.arrayBufferToImage.bind(this);
|
||||
this.getArrayBuffer = this.getArrayBuffer.bind(this);
|
||||
this.decodeBase64 = this.decodeBase64.bind(this);
|
||||
this.createImage = this.createImage.bind(this);
|
||||
this.imageLoader = this.imageLoader.bind(this);
|
||||
this.replaceImage = this.replaceImage.bind(this);
|
||||
}
|
||||
CornerstoneBase64ImageLoader.prototype.arrayBufferToImage = function (arrayBuffer) {
|
||||
return new Promise(function (resolve, reject) {
|
||||
var image = new Image();
|
||||
var arrayBufferView = new Uint8Array(arrayBuffer);
|
||||
var blob = new Blob([arrayBufferView]);
|
||||
var urlCreator = window.URL || window.webkitURL;
|
||||
var imageUrl = urlCreator.createObjectURL(blob);
|
||||
image.src = imageUrl;
|
||||
image.onload = function () {
|
||||
urlCreator.revokeObjectURL(imageUrl);
|
||||
resolve(image);
|
||||
};
|
||||
image.onerror = function (error) {
|
||||
urlCreator.revokeObjectURL(imageUrl);
|
||||
reject(error);
|
||||
};
|
||||
});
|
||||
};
|
||||
CornerstoneBase64ImageLoader.prototype.getArrayBuffer = function (str) {
|
||||
var buf = new ArrayBuffer(str.length);
|
||||
var bufView = new Uint8Array(buf);
|
||||
Array.from(str).map(function (ch, idx) {
|
||||
bufView[idx] = ch.charCodeAt(0);
|
||||
return ch;
|
||||
});
|
||||
return bufView;
|
||||
};
|
||||
CornerstoneBase64ImageLoader.prototype.decodeBase64 = function (base64PixelData) {
|
||||
var pixelDataAsString = window.atob(base64PixelData);
|
||||
var arrayBuffer = this.getArrayBuffer(pixelDataAsString);
|
||||
return arrayBuffer;
|
||||
};
|
||||
CornerstoneBase64ImageLoader.prototype.createImage = function (image, imageId) {
|
||||
var _this = this;
|
||||
var rows = image.naturalHeight;
|
||||
var columns = image.naturalWidth;
|
||||
var getImageData = function () {
|
||||
var context;
|
||||
if (_this._lastImageIdDrawn === imageId) {
|
||||
context = _this._canvas.getContext('2d');
|
||||
}
|
||||
else {
|
||||
_this._canvas.height = image.naturalHeight;
|
||||
_this._canvas.width = image.naturalWidth;
|
||||
context = _this._canvas.getContext('2d');
|
||||
context.drawImage(image, 0, 0);
|
||||
_this._lastImageIdDrawn = imageId;
|
||||
}
|
||||
return context.getImageData(0, 0, image.naturalWidth, image.naturalHeight);
|
||||
};
|
||||
var getPixelData = function () {
|
||||
var imageData = getImageData();
|
||||
return imageData.data;
|
||||
};
|
||||
var getCanvas = function () {
|
||||
if (_this._lastImageIdDrawn === imageId) {
|
||||
return _this._canvas;
|
||||
}
|
||||
_this._canvas.height = image.naturalHeight;
|
||||
_this._canvas.width = image.naturalWidth;
|
||||
var context = _this._canvas.getContext('2d');
|
||||
context.drawImage(image, 0, 0);
|
||||
_this._lastImageIdDrawn = imageId;
|
||||
return _this._canvas;
|
||||
};
|
||||
var setLastImageIdDrawn = function (nextLastImageIdDrawn) {
|
||||
if (nextLastImageIdDrawn === void 0) { nextLastImageIdDrawn = null; }
|
||||
_this._lastImageIdDrawn = nextLastImageIdDrawn;
|
||||
};
|
||||
return {
|
||||
imageId: imageId,
|
||||
minPixelValue: 0,
|
||||
maxPixelValue: 255,
|
||||
slope: 1,
|
||||
intercept: 0,
|
||||
windowCenter: 128,
|
||||
windowWidth: 255,
|
||||
render: this.cornerstone.renderWebImage,
|
||||
getPixelData: getPixelData,
|
||||
getCanvas: getCanvas,
|
||||
getImage: function () { return image; },
|
||||
setLastImageIdDrawn: setLastImageIdDrawn,
|
||||
rows: rows,
|
||||
columns: columns,
|
||||
height: rows,
|
||||
width: columns,
|
||||
color: true,
|
||||
rgba: false,
|
||||
columnPixelSpacing: null,
|
||||
rowPixelSpacing: null,
|
||||
invert: false,
|
||||
sizeInBytes: rows * columns * this._options.channel
|
||||
};
|
||||
};
|
||||
CornerstoneBase64ImageLoader.prototype.imageLoader = function (imageId) {
|
||||
var _this = this;
|
||||
// const schema = imageId.split('://')[0]
|
||||
var base64PixelData = imageId.replace(this._options.schema, '');
|
||||
var arrayBuffer;
|
||||
if (this._options.width && this._options.height && this._UPNG) {
|
||||
var columns = this._options.width;
|
||||
var rows = this._options.height;
|
||||
arrayBuffer = new Uint8Array(columns * rows * this._options.channel);
|
||||
arrayBuffer = this._UPNG.encode([arrayBuffer.buffer], columns, rows, 0);
|
||||
}
|
||||
else {
|
||||
arrayBuffer = this.decodeBase64(base64PixelData);
|
||||
}
|
||||
var imagePromise = this.arrayBufferToImage(arrayBuffer);
|
||||
var promise = new Promise(function (resolve, reject) {
|
||||
imagePromise.then(function (image) {
|
||||
var imageObject = _this.createImage(image, imageId);
|
||||
resolve(imageObject);
|
||||
}, reject);
|
||||
});
|
||||
return {
|
||||
promise: promise
|
||||
};
|
||||
};
|
||||
CornerstoneBase64ImageLoader.prototype.replaceImage = function (layer, arrayBuffer) {
|
||||
var _this = this;
|
||||
if (!this._UPNG) {
|
||||
return null;
|
||||
}
|
||||
var png = this._UPNG.encode([arrayBuffer.buffer], layer.image.columns, layer.image.rows, 0);
|
||||
var imagePromise = this.arrayBufferToImage(png);
|
||||
return imagePromise.then(function (image) {
|
||||
layer.image = _this.createImage(image, layer.image.imageId);
|
||||
});
|
||||
};
|
||||
Object.defineProperty(CornerstoneBase64ImageLoader.prototype, "options", {
|
||||
get: function () {
|
||||
return __assign({}, this._options);
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(CornerstoneBase64ImageLoader.prototype, "cornerstone", {
|
||||
get: function () {
|
||||
return this._cornerstone;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(CornerstoneBase64ImageLoader.prototype, "UPNG", {
|
||||
get: function () {
|
||||
return this._UPNG;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
CornerstoneBase64ImageLoader.prototype.setUPNG = function (UPNG) {
|
||||
this._UPNG = UPNG;
|
||||
};
|
||||
CornerstoneBase64ImageLoader.prototype.registerLoaders = function () {
|
||||
this.cornerstone.registerImageLoader('base64', this.imageLoader);
|
||||
};
|
||||
return CornerstoneBase64ImageLoader;
|
||||
}());
|
||||
|
||||
var _imageLoader;
|
||||
var _options = __assign({}, _defaultOptions);
|
||||
var cornerstoneBase64ImageLoader = {
|
||||
external: {
|
||||
set cornerstone(cs) {
|
||||
_imageLoader = new CornerstoneBase64ImageLoader(cs, _options);
|
||||
_imageLoader.registerLoaders();
|
||||
},
|
||||
get cornerstone() {
|
||||
return _imageLoader.cornerstone;
|
||||
},
|
||||
get UPNG() {
|
||||
return _imageLoader.UPNG;
|
||||
},
|
||||
set UPNG(_UPNG) {
|
||||
_imageLoader.setUPNG(_UPNG);
|
||||
}
|
||||
},
|
||||
initOptions: function () {
|
||||
_options = __assign({}, _defaultOptions);
|
||||
},
|
||||
set options(newOptions) {
|
||||
_options = __assign({}, _options, newOptions);
|
||||
},
|
||||
get options() {
|
||||
return __assign({}, _options);
|
||||
},
|
||||
get imageLoader() {
|
||||
return _imageLoader;
|
||||
}
|
||||
};
|
||||
|
||||
return cornerstoneBase64ImageLoader;
|
||||
|
||||
})));
|
||||
//# sourceMappingURL=cornerstone-base64-image-loader.umd.js.map
|
||||
File diff suppressed because one or more lines are too long
Vendored
+1
@@ -0,0 +1 @@
|
||||
/*! cornerstone - v0.9.0 - 2016-02-03 | (c) 2014 Chris Hafey | https://github.com/chafey/cornerstone */.cornerstone-enabled-image{-webkit-touch-callout:none;-webkit-user-select:none;-khtml-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;cursor:default}
|
||||
Vendored
+3
File diff suppressed because one or more lines are too long
+3
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load Diff
+3
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -0,0 +1,3 @@
|
||||
/*! cornerstone-web-image-loader - 2.1.1 - 2018-12-05 | (c) 2016 Chris Hafey | https://github.com/cornerstonejs/cornerstoneWebImageLoader */
|
||||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("cornerstoneWebImageLoader",[],t):"object"==typeof exports?exports.cornerstoneWebImageLoader=t():e.cornerstoneWebImageLoader=t()}(window,function(){return function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{configurable:!1,enumerable:!0,get:r})},n.r=function(e){Object.defineProperty(e,"__esModule",{value:!0})},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=5)}([function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.external=void 0;var r,o=n(4),a=(r=o)&&r.__esModule?r:{default:r};var u=void 0,i={set cornerstone(e){u=e,(0,a.default)(u)},get cornerstone(){return u}};t.external=i},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.loadImage=function(e){var t=r.external.cornerstone,n=new XMLHttpRequest;return n.open("GET",e,!0),n.responseType="arraybuffer",i.beforeSend(n),n.onprogress=function(n){if(n.lengthComputable){var r=n.loaded,o=n.total,a=Math.round(r/o*100),u={imageId:e,loaded:r,total:o,percentComplete:a};t.triggerEvent(t.events,"cornerstoneimageloadprogress",u)}},{promise:new Promise(function(t,r){n.onload=function(){(0,o.default)(this.response).then(function(n){var r=(0,a.default)(n,e);t(r)},r)},n.send()}),cancelFn:function(){n.abort()}}},t.configure=function(e){i=e};var r=n(0),o=u(n(3)),a=u(n(2));function u(e){return e&&e.__esModule?e:{default:e}}var i={beforeSend:function(){}}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.default=function(e,t){var n=e.naturalHeight,u=e.naturalWidth;return{imageId:t,minPixelValue:0,maxPixelValue:255,slope:1,intercept:0,windowCenter:128,windowWidth:255,render:r.external.cornerstone.renderWebImage,getPixelData:function(){return(n=void 0,a===t?n=o.getContext("2d"):(o.height=e.naturalHeight,o.width=e.naturalWidth,(n=o.getContext("2d")).drawImage(e,0,0),a=t),n.getImageData(0,0,e.naturalWidth,e.naturalHeight)).data;var n},getCanvas:function(){return a===t?o:(o.height=e.naturalHeight,o.width=e.naturalWidth,o.getContext("2d").drawImage(e,0,0),a=t,o)},getImage:function(){return e},rows:n,columns:u,height:n,width:u,color:!0,rgba:!1,columnPixelSpacing:void 0,rowPixelSpacing:void 0,invert:!1,sizeInBytes:n*u*4}};var r=n(0),o=document.createElement("canvas"),a=void 0},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.default=function(e){return new Promise(function(t,n){var r=new Image,o=new Uint8Array(e),a=new Blob([o]),u=window.URL||window.webkitURL,i=u.createObjectURL(a);r.src=i,r.onload=function(){t(r),u.revokeObjectURL(i)},r.onerror=function(e){u.revokeObjectURL(i),n(e)}})}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.default=function(e){e.registerImageLoader("http",r.loadImage),e.registerImageLoader("https",r.loadImage)};var r=n(1)},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.external=t.configure=t.loadImage=t.createImage=t.arrayBufferToImage=void 0;var r=i(n(3)),o=i(n(2)),a=n(1),u=n(0);function i(e){return e&&e.__esModule?e:{default:e}}var d={arrayBufferToImage:r.default,createImage:o.default,loadImage:a.loadImage,configure:a.configure,external:u.external};t.arrayBufferToImage=r.default,t.createImage=o.default,t.loadImage=a.loadImage,t.configure=a.configure,t.external=u.external,t.default=d}])});
|
||||
//# sourceMappingURL=cornerstoneWebImageLoader.min.js.map
|
||||
Vendored
+17
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load Diff
+4474
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,40 @@
|
||||
import * as dicomViewer from "./dicomViewer.js"
|
||||
|
||||
|
||||
$(document).ready(function () {
|
||||
|
||||
loadDicomViewer();
|
||||
});
|
||||
|
||||
function loadDicomViewer(images_to_load) {
|
||||
console.log("loadDicomViewer", images_to_load);
|
||||
let single_dicom = document.getElementById("dicom-viewer");
|
||||
if (single_dicom) {
|
||||
|
||||
let images = single_dicom.dataset.images;
|
||||
|
||||
if (images_to_load != undefined) {
|
||||
images = images_to_load;
|
||||
console.log("i1", images)
|
||||
} else if (images.indexOf(",") > 0) {
|
||||
images = images.split(",");
|
||||
}
|
||||
|
||||
console.log(images);
|
||||
|
||||
let annotations = single_dicom.dataset.annotations;
|
||||
if (annotations != undefined && annotations.indexOf(",") > 0) {
|
||||
annotations = annotations;
|
||||
}
|
||||
let load_as_stack;
|
||||
if (images.length > 5) {
|
||||
load_as_stack = true;
|
||||
} else {
|
||||
load_as_stack = false;
|
||||
}
|
||||
|
||||
if (images) {
|
||||
dicomViewer.loadCornerstone($(single_dicom), null, images, annotations, load_as_stack);
|
||||
}
|
||||
}
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user