-
Notifications
You must be signed in to change notification settings - Fork 598
/
index.html
114 lines (94 loc) · 4.34 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<!DOCTYPE HTML>
<html>
<head>
<!-- twitter bootstrap CSS stylesheet - not required by cornerstone -->
<link href="https://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<div class="container">
<h1>
ctimage/index.html
</h1>
This is an example of displaying a ct image along with buttons to set ww/wc presets. You can
manually adjust the ww/wc by dragging the left mouse button
<br>
<br>
<div id="dicomImage"
style="width:512px;height:512px"
oncontextmenu="return false"
onmousedown="return false">
</div>
<br>
<button id="softTissue" class="btn">Soft Tissue</button>
<button id="lung" class="btn">Lung</button>
<button id="bone" class="btn">Bone</button>
<span id="window">WW/WC:</span>
</div>
</body>
<!-- include the cornerstone library -->
<script src="../../dist/cornerstone.js"></script>
<script>window.cornerstone || document.write('<script src="https://unpkg.com/cornerstone-core">\x3C/script>')</script>
<!-- include special code for these examples which provides images -->
<script src="../exampleImageIdLoaderCt.js"></script>
<script>
// image enable the dicomImage element
const element = document.getElementById('dicomImage');
cornerstone.enable(element);
// load and display the image
const imageId = 'ctexample://1';
cornerstone.loadImage(imageId).then(function(image) {
cornerstone.displayImage(element, image);
const viewport = cornerstone.getViewport(element);
document.getElementById('window').textContent = "WW/WC:" + Math.round(viewport.voi.windowWidth)
+ "/" + Math.round(viewport.voi.windowCenter);
// Add event handler for the ww/wc presets
document.getElementById('softTissue').addEventListener('click', function() {
let viewport = cornerstone.getViewport(element);
viewport.voi.windowWidth = 400;
viewport.voi.windowCenter = 20;
cornerstone.setViewport(element, viewport);
document.getElementById('window').textContent = "WW/WC:" + Math.round(viewport.voi.windowWidth)
+ "/" + Math.round(viewport.voi.windowCenter);
});
document.getElementById('lung').addEventListener('click', function() {
let viewport = cornerstone.getViewport(element);
viewport.voi.windowWidth = 1600;
viewport.voi.windowCenter = -600;
cornerstone.setViewport(element, viewport);
document.getElementById('window').textContent = "WW/WC:" + Math.round(viewport.voi.windowWidth)
+ "/" + Math.round(viewport.voi.windowCenter);
});
document.getElementById('bone').addEventListener('click', function() {
let viewport = cornerstone.getViewport(element);
viewport.voi.windowWidth = 2000;
viewport.voi.windowCenter = 300;
cornerstone.setViewport(element, viewport);
document.getElementById('window').textContent = "WW/WC:" + Math.round(viewport.voi.windowWidth)
+ "/" + Math.round(viewport.voi.windowCenter);
});
// add event handlers to mouse move to adjust window/center
element.addEventListener('mousedown', function (e) {
let lastX = e.pageX;
let lastY = e.pageY;
function mouseMoveHandler(e) {
const deltaX = e.pageX - lastX;
const deltaY = e.pageY - lastY;
lastX = e.pageX;
lastY = e.pageY;
let viewport = cornerstone.getViewport(element);
viewport.voi.windowWidth += (deltaX / viewport.scale);
viewport.voi.windowCenter += (deltaY / viewport.scale);
cornerstone.setViewport(element, viewport);
document.getElementById('window').textContent = "WW/WC:" + Math.round(viewport.voi.windowWidth)
+ "/" + Math.round(viewport.voi.windowCenter);
}
function mouseUpHandler() {
document.removeEventListener('mousemove', mouseMoveHandler);
document.removeEventListener('mouseup', mouseUpHandler);
}
document.addEventListener('mousemove', mouseMoveHandler);
document.addEventListener('mouseup', mouseUpHandler);
});
});
</script>
</html>