forked from cornerstonejs/cornerstoneTools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
397 lines (348 loc) · 14.4 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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
<!DOCTYPE html>
<html>
<head>
<!-- support for mobile touch devices -->
<meta name="viewport" content="user-scalable=no, width=device-width, initial-scale=1, maximum-scale=1" />
<script src="https://polyfill.io/v3/polyfill.js?features=es5,es6,es7&flags=gated"></script>
<link rel="stylesheet" href="netlify-example/reset.css" />
<link rel="stylesheet" href="netlify-example/app.css" />
<link rel="stylesheet" href="netlify-example/icon-classes.css" />
<style>
/**
* ~~ MagnifyTool:
* You need to supply your own styling for the created magnifyTool div.
* Note: The element wrapper needs `position: relative` for the positioning to work.
*/
.magnifyTool {
border: 4px white solid;
box-shadow: 2px 2px 10px #1e1e1e;
border-radius: 50%;
display: none;
cursor: none;
z-index: 100;
}
</style>
</head>
<body>
<div id="app">
<div class="wrapper">
<!-- Select Tool Category -->
<ul class="tool-category-list">
<li>
<a class="active" data-category="annotation" href="#">Annotation</a>
</li>
<li><a data-category="drag" href="#">Drag</a></li>
<li>
<a data-category="multitouch-pinch" href="#">Multi-Touch / Pinch (touch only)</a>
</li>
<li><a data-category="mousewheel" href="#">MouseWheel</a></li>
<li><a data-category="double-tap" href="#">DoubleTap</a></li>
<li><a data-category="overlay" href="#">Overlay</a></li>
</ul>
<!-- Select Active Tool -->
<ul class="tool-category active" data-tool-category="annotation">
<li><a href="#" data-tool="ArrowAnnotate">ArrowAnnotate</a></li>
<li><a href="#" data-tool="Angle">Angle</a></li>
<li><a href="#" data-tool="Bidirectional">Bidirectional</a></li>
<li><a href="#" data-tool="CircleRoi">CircleRoi</a></li>
<li><a href="#" data-tool="CobbAngle">Cobb Angle</a></li>
<li><a href="#" data-tool="EllipticalRoi">EllipticalRoi</a></li>
<li><a href="#" data-tool="Eraser">Eraser</a></li>
<li><a href="#" data-tool="FreehandMouse">FreehandMouse</a></li>
<li>
<a href="#" data-tool="FreehandSculpterMouse">FreehandSculpterMouse</a>
</li>
<li><a href="#" data-tool="Brush">BrushTool</a></li>
<li><a href="#" data-tool="TextMarker">TextMarker</a></li>
<li><a href="#" data-tool="Length">Length</a></li>
<li><a href="#" data-tool="Probe">Probe</a></li>
<li><a href="#" data-tool="RectangleRoi">RectangleRoi</a></li>
</ul>
<ul class="tool-category" data-tool-category="drag">
<li><a href="#" data-tool="Crosshairs">Crosshairs</a></li>
<!-- <li><a href="#" data-tool="DragProbe">DragProbe</a></li> -->
<li><a href="#" data-tool="Magnify">Magnify</a></li>
<li><a href="#" data-tool="Pan">Pan</a></li>
<li><a href="#" data-tool="Rotate">Rotate</a></li>
<li><a href="#" data-tool="StackScroll">StackScroll</a></li>
<li><a href="#" data-tool="Wwwc">WWWC</a></li>
<li><a href="#" data-tool="WwwcRegion">WWWCRegion</a></li>
<li><a href="#" data-tool="Zoom">Zoom</a></li>
</ul>
<ul class="tool-category" data-tool-category="double-tap">
<li>
<a href="#" data-tool="DoubleTapFitToWindow">DoubleTapFitToWindow</a>
</li>
</ul>
<ul class="tool-category" data-tool-category="multitouch-pinch">
<li>
<a href="#" data-tool="PanMultiTouch" data-tool-type="multitouch">PanMultiTouch</a>
</li>
<li>
<a href="#" data-tool="ZoomTouchPinch" data-tool-type="pinch">ZoomTouchPinch</a>
</li>
<li>
<a href="#" data-tool="RotateTouch" data-tool-type="pinch">RotateTouch</a>
</li>
<li>
<a href="#" data-tool="StackScrollMultiTouch" data-tool-type="multitouch">StackScrollMultiTouch</a>
</li>
</ul>
<ul class="tool-category" data-tool-category="mousewheel">
<li>
<a href="#" data-tool="StackScrollMouseWheel" data-tool-type="wheel">StackScrollMouseWheel</a>
</li>
<li>
<a href="#" data-tool="ZoomMouseWheel" data-tool-type="wheel">ZoomMouseWheel</a>
</li>
</ul>
<ul class="tool-category" data-tool-category="overlay">
<li>
<label id="scaleOverlay" class="checkbox-label" for="scaleOverlayCheckbox">
ScaleOverlay <label class="label-on"> ON</label>
<label class="label-off"> OFF</label>
</label>
<input id="scaleOverlayCheckbox" class="hide" data-tool="ScaleOverlay" data-tool-type="none"
type="checkbox" />
</li>
</ul>
<!-- Our beautiful element targets -->
<div class="cornerstone-element-wrapper">
<a href="#" class="save-btn" data-index="0">Save</a>
<div class="cornerstone-element" data-index="0" oncontextmenu="return false"></div>
<a href="#" class="save-btn" data-index="1">Save</a>
<div class="cornerstone-element" data-index="1" oncontextmenu="return false"></div>
</div>
</div>
</div>
</body>
<!-- include the hammer.js library for touch gestures -->
<script src="https://unpkg.com/[email protected]/hammer.js"></script>
<!-- include the cornerstone library -->
<script src="https://unpkg.com/[email protected]/dist/cornerstone.js"></script>
<script src="https://unpkg.com/[email protected]/dist/cornerstoneMath.js"></script>
<script src="./dist/cornerstoneTools.js"></script>
<script>
window.cornerstoneTools ||
document.write(
'<script src="https://unpkg.com/cornerstone-tools">\x3C/script>'
);
</script>
<!-- include special code for these examples which provides images -->
<script src="netlify-example/imageLoader.js"></script>
<script>
cornerstoneTools.init({
showSVGCursors: true
});
var imageIds = ['example://1', 'example://2', 'example://3'];
var stack = {
currentImageIdIndex: 0,
imageIds: imageIds
}; // Enable & Setup all of our elements
var elements = document.querySelectorAll('.cornerstone-element');
Array.from(elements).forEach(function (element) {
cornerstone.enable(element);
element.tabIndex = 0;
element.focus();
cornerstone.loadImage(imageIds[0]).then(function (image) {
cornerstone.displayImage(element, image);
cornerstoneTools.addStackStateManager(element, ['stack']);
cornerstoneTools.addToolState(element, 'stack', stack);
}); //Save As Tool
var index = element.getAttribute('data-index');
var saveBtn = element.parentElement.querySelector("a[data-index='".concat(index, "']"));
saveBtn.addEventListener('click', function (evt) {
cornerstoneTools.SaveAs(element, 'viewportImage.png');
}); // Log measurement events
var _cornerstoneTools = cornerstoneTools,
EVENTS = _cornerstoneTools.EVENTS;
var log = function log(event) {
var type = "MEASUREMENT_".concat(event.type.replace('cornerstonetoolsmeasurement', '').toUpperCase());
var color = {
MEASUREMENT_ADDED: '#27e',
MEASUREMENT_MODIFIED: '#e72',
MEASUREMENT_COMPLETED: '#5b5',
MEASUREMENT_REMOVED: '#f55'
}[type];
var getData = function getData(detail) {
var _detail$measurementDa = detail.measurementData,
measurementData = _detail$measurementDa === void 0 ? {} : _detail$measurementDa;
var out = {};
var measurementKeys = ['length', 'rAngle', 'value', 'text', 'str', 'text', 'longestDiameter', 'shortestDiameter'];
if (measurementData.cachedStats) {
Object.keys(measurementData.cachedStats).forEach(function (key) {
out[key] = measurementData.cachedStats[key];
});
}
measurementKeys.forEach(function (key) {
if (key in measurementData) {
out[key] = measurementData[key];
}
});
if (Object.keys(out).length === 0) {
return measurementData;
} else {
return JSON.stringify(out);
}
};
console.log('%c %s %c %s %c %o', "background: ".concat(color, "; color: white; padding: 4px 0;"), type, // The tool type
"color: ".concat(color, "; font-family: monospace;"), event.detail.toolType || event.detail.toolName, '', getData(event.detail) // event.detail
);
};
element.addEventListener(EVENTS.MEASUREMENT_ADDED, log);
element.addEventListener(EVENTS.MEASUREMENT_MODIFIED, log);
element.addEventListener(EVENTS.MEASUREMENT_COMPLETED, log);
element.addEventListener(EVENTS.MEASUREMENT_REMOVED, log);
}); // Iterate over all tool-category links
var toolCategoryLinks = document.querySelectorAll('ul.tool-category-list a');
var toolCategorySections = document.querySelectorAll('ul.tool-category');
Array.from(toolCategoryLinks).forEach(function (link) {
//
var categoryName = link.getAttribute('data-category');
var categoryElement = document.querySelector("section[data-tool-category=\"".concat(categoryName, "\"]")); // Setup listener
link.addEventListener('click', function (evt) {
evt.preventDefault();
setToolCategoryActive(categoryName);
});
}); // Iterate over all tool buttons
var toolButtons = document.querySelectorAll('a[data-tool]');
Array.from(toolButtons).forEach(function (toolBtn) {
// Add the tool
var toolName = toolBtn.getAttribute('data-tool');
var apiTool = cornerstoneTools["".concat(toolName, "Tool")];
if (apiTool) {
cornerstoneTools.addTool(apiTool);
} else {
console.warn("unable to add tool with name ".concat(toolName, "Tool"));
console.log(cornerstoneTools);
} // Setup button listener
// Prevent right click context menu for our menu buttons
toolBtn.addEventListener('contextmenu', function (event) {
return event.preventDefault();
}, true); // Prevent middle click opening a new tab on Chrome & FF
toolBtn.addEventListener('auxclick', function (event) {
if (event.button && event.button === 1) {
event.preventDefault();
}
}, false);
toolBtn.addEventListener('mousedown', function (evt) {
var mouseButtonMask = evt.buttons ? evt.buttons : convertMouseEventWhichToButtons(evt.which);
var toolType = evt.target.getAttribute('data-tool-type');
setButtonActive(toolName, mouseButtonMask, toolType);
cornerstoneTools.setToolActive(toolName, {
mouseButtonMask: mouseButtonMask,
isTouchActive: true
});
evt.preventDefault();
evt.stopPropagation();
evt.stopImmediatePropagation();
return false;
});
}); // Iterate through swtich ON/OFF tools
var stateTools = document.querySelectorAll('input[type="checkbox"]');
Array.from(stateTools).forEach(function (toolCheckBox) {
var toolName = toolCheckBox.getAttribute('data-tool');
var toolLabel = document.querySelector("#".concat(toolName));
var apiTool = cornerstoneTools["".concat(toolName, "Tool")];
if (apiTool) {
cornerstoneTools.addTool(apiTool);
}
cornerstoneTools.setToolDisabled(toolName);
toolCheckBox.addEventListener('change', function (evt) {
if (evt.currentTarget.checked) {
cornerstoneTools.setToolEnabled(toolName);
} else {
cornerstoneTools.setToolDisabled(toolName);
}
var toolLabel = document.querySelector('#scaleOverlay');
toolLabel.classList.toggle('turned-on');
});
}); // Activate first tool
cornerstoneTools.setToolActive(cornerstoneTools.store.state.tools[0].name, {
mouseButtonMask: 1,
isTouchActive: true
});
var setToolCategoryActive = function setToolCategoryActive(categoryName) {
Array.from(toolCategoryLinks).forEach(function (toolLink) {
if (categoryName === toolLink.getAttribute('data-category')) {
toolLink.classList.remove('active');
toolLink.classList.add('active');
} else {
toolLink.classList.remove('active');
}
});
Array.from(toolCategorySections).forEach(function (toolCategorySection) {
if (categoryName === toolCategorySection.getAttribute('data-tool-category')) {
toolCategorySection.classList.remove('active');
toolCategorySection.classList.add('active');
} else {
toolCategorySection.classList.remove('active');
}
});
};
var setButtonActive = function setButtonActive(toolName, mouseButtonMask, toolType) {
Array.from(toolButtons).forEach(function (toolBtn) {
// Classes we need to set & remove
var mouseButtonIcon = "mousebutton-".concat(mouseButtonMask);
var touchIcon = "touch-1"; // Update classes depending on the toolType we clicked
if (toolType === 'none') {
return;
} else if (toolType === 'multitouch') {
mouseButtonIcon = null;
touchIcon = 'touch-2';
} else if (toolType === 'pinch') {
mouseButtonIcon = null;
touchIcon = 'touch-pinch';
} else if (toolType === 'wheel') {
mouseButtonIcon = 'mousebutton-wheel';
touchIcon = null;
} // Update our target button
if (toolName === toolBtn.getAttribute('data-tool')) {
toolBtn.className = '';
toolBtn.classList.add('active');
if (mouseButtonIcon) {
toolBtn.classList.add(mouseButtonIcon);
}
if (touchIcon) {
toolBtn.classList.add(touchIcon);
} // Remove relevant classes from other buttons
} else {
if (mouseButtonIcon && toolBtn.classList.contains(mouseButtonIcon)) {
toolBtn.classList.remove(mouseButtonIcon);
}
if (touchIcon && toolBtn.classList.contains(touchIcon)) {
toolBtn.classList.remove(touchIcon);
}
if (toolBtn.classList.length === 1 && toolBtn.classList[0] === 'active') {
toolBtn.classList.remove('active');
}
}
});
}; // Find all and configure each textMarkers
var textMarkerTools = cornerstoneTools.store.state.tools.forEach(function (element) {
if (element.name === 'TextMarker') {
element.configuration.markers = ['F5', 'F4', 'F3', 'F2', 'F1'];
element.configuration.current = 'F5';
element.configuration.ascending = true;
element.configuration.loop = true;
}
});
var convertMouseEventWhichToButtons = function convertMouseEventWhichToButtons(which) {
switch (which) {
// no button
case 0:
return 0;
// left
case 1:
return 1;
// middle
case 2:
return 4;
// right
case 3:
return 2;
}
return 0;
};
</script>
</html>