Last active
January 27, 2020 16:07
-
-
Save dannyrb/63e5f4e76711f8539aea934357344e21 to your computer and use it in GitHub Desktop.
Cornerstone Tool v3 - Simplest example, using Web Image Loader
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>My first Cornerstone Tools app</title> | |
<!-- Dependencies --> | |
<script src="https://cdn.jsdelivr.net/npm/[email protected]"></script> | |
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/cornerstoneMath.js"></script> | |
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/cornerstone.js"></script> | |
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/cornerstoneWebImageLoader.js"></script> | |
<!-- development version, includes helpful console warnings --> | |
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/cornerstoneTools.js"></script> | |
<style> | |
.cornerstone-element-wrapper, | |
.cornerstone-element { | |
width: 512px; | |
height: 512px; | |
margin: 0 auto; | |
} | |
</style> | |
</head> | |
<body> | |
<!-- Our beautiful element target --> | |
<div class="cornerstone-element-wrapper"> | |
<div class="cornerstone-element" data-index="0" oncontextmenu="return false"></div> | |
</div> | |
<script> | |
// Register the web image loader (JPEG & PNG) | |
cornerstoneWebImageLoader.external.cornerstone = window.cornerstone; | |
cornerstone.registerImageLoader('http', cornerstoneWebImageLoader.loadImage); | |
cornerstone.registerImageLoader('https', cornerstoneWebImageLoader.loadImage); | |
// Initialize cornerstone tools, and create an "enabled element" | |
// RE: An element that contains our canvas/viewport | |
const csTools = cornerstoneTools.init(); | |
const element = document.querySelector('.cornerstone-element'); | |
cornerstone.enable(element); | |
// Display our image on the "enabled element" | |
const imageId = | |
'https://www.asteris.biz/Keystone/ImageDownload.aspx?ClinicCode=TESTKEYSTONE&ImageId=01b1755e-33d1-4b24-b9af-a4a019689d5f&ImageType=PreviewImage&FrameIndex=0'; | |
cornerstone.loadImage(imageId).then(function (image) { | |
cornerstone.displayImage(element, image); | |
}); | |
</script> | |
</body> | |
</html> |
Thank you
@dannyrb The image loader is the same as the v3 example then? Only the wado image loader changed?
I don't believe the WebImageLoader has changed much / at all. It's a bit easier to setup, so I tend to use the WADO Image Loader in examples as it tends to trip people up more frequently. It's also almost always preferable to use the WADO Image Loader.
Makes sense. Thank you
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here is a simple code sandbox that uses up-to-date version of cornerstone-tools and the WADO image loader:
https://codesandbox.io/s/cstools411-eu7wt