Not sure what happening, but image is loading correctly, but the tool won't show. I don't load the tool until the image is actually in the Dom (that's what the bottom is for). all the modules in the console.log print to console just fine. any help would be appreciated. Fyi rich tnow im running with vs code live server,
html file
<!DOCTYPE html>
<html>
<head>
<script src="./wado/dicomParser.min.js"></script>
<script src="./wado/cornerstoneWADOImageLoader.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]"></script>
<script src="./wado/cornerstone.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/cornerstoneTools.js"></script>
</head>
<body>
<input type="file" id="fileInput" multiple />
<div style="width: 512px; height: 512px" id="image"></div>
<button id="addTools">Add Tool</button>
<script src="main.js"></script>
</body>
</html>
Javascript
cornerstoneWADOImageLoader.external.cornerstone = cornerstone;
cornerstoneTools.external.cornerstone = cornerstone;
cornerstoneTools.external.Hammer = Hammer;
cornerstoneTools.external.cornerstoneMath = cornerstoneMath;
cornerstone.registerImageLoader("wadouri", loadAndViewImage);
const csTools = cornerstoneTools.init();
const LengthTool = cornerstoneTools.LengthTool;
console.log("cornerstone", cornerstone);
console.log("loader", cornerstoneWADOImageLoader);
console.log("tools", cornerstoneTools);
console.log("cstools", csTools);
console.log("math", cornerstoneMath);
console.log("hammer", Hammer);
const imageHolder = document.getElementById("image");
cornerstone.enable(imageHolder);
const toolButton = document.getElementById("addTools");
toolButton.addEventListener("click", (e) => {
loadTool();
});
fileInput.addEventListener("change", (e) => {
const file = fileInput.files;
const ima = file[0];
const imageId = cornerstoneWADOImageLoader.wadouri.fileManager.add(ima);
loadAndViewImage(imageId);
});
function loadAndViewImage(imageId) {
cornerstone
.loadImage(imageId)
.then((image) => {
const viewport = {
invert: false,
pixelReplication: false,
// voi: {
// windowWidth: 256,
// windowCenter: 256,
// },
scale: 1.5,
translation: {
x: 0,
y: 0,
},
};
cornerstone.displayImage(imageHolder, image, viewport);
console.log(image);
console.log(image.data.uint16("x00280010"));
console.log(image.data.uint32("x00020000"));
})
.catch((e) => console.log(e));
}
function loadTool() {
csTools.addTool(LengthTool);
csTools.setToolActive(LengthTool.name, {
mouseButtonMask: 1,
});
console.log(csTools.store.state);
}
Im answering my own question here, I switched to imports and redid some of the code. the following seems to work fine so far.