-
Notifications
You must be signed in to change notification settings - Fork 456
/
index.html
490 lines (447 loc) · 15.8 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
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
<!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" />
<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="segmentation" href="#">Segmentation</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="FreehandRoi">FreehandRoi</a></li>
<li>
<a href="#" data-tool="FreehandRoiSculptor">FreehandRoiSculptor</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="segmentation">
<li>
<a href="#" data-tool="Brush">BrushTool</a>
</li>
<li>
<a href="#" data-tool="SphericalBrush">SphericalBrushTool</a>
</li>
<li>
<a href="#" data-tool="FreehandScissors">FreehandScissors</a>
</li>
<li>
<a href="#" data-tool="RectangleScissors">RectangleScissors</a>
</li>
<li>
<a href="#" data-tool="CircleScissors">CircleScissors</a>
</li>
<li>
<a href="#" data-tool="CorrectionScissors">CorrectionScissors</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>
<li><a href="#" data-tool="DragProbe">DragProbe</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-interaction="multitouch">PanMultiTouch</a>
</li>
<li>
<a href="#" data-tool="ZoomTouchPinch" data-tool-interaction="pinch">ZoomTouchPinch</a>
</li>
<li>
<a href="#" data-tool="RotateTouch" data-tool-interaction="pinch">RotateTouch</a>
</li>
<li>
<a href="#" data-tool="StackScrollMultiTouch" data-tool-interaction="multitouch">StackScrollMultiTouch</a>
</li>
</ul>
<ul class="tool-category" data-tool-category="mousewheel">
<li>
<a href="#" data-tool="StackScrollMouseWheel" data-tool-interaction="wheel">StackScrollMouseWheel</a>
</li>
<li>
<a href="#" data-tool="ZoomMouseWheel" data-tool-interaction="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-interaction="none"
type="checkbox" />
</li>
<li>
<label id="overlay" class="checkbox-label" for="overlayCheckbox">
Overlay <label class="label-on"> ON</label>
<label class="label-off"> OFF</label>
</label>
<input id="overlayCheckbox" class="hide" data-tool="Overlay" data-tool-interaction="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 src="./netlify-example/metaDataProvider.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([
{
moduleName: 'globalConfiguration',
configuration: {
showSVGCursors: true
}
},
{
moduleName: 'segmentation',
configuration: {
outlineWidth: 2
}
}
]);
const imageIds = ['example://1', 'example://2', 'example://3'];
const stack = {
currentImageIdIndex: 0,
imageIds: imageIds,
};
// Enable & Setup all of our elements
const elements = document.querySelectorAll('.cornerstone-element');
Array.from(elements).forEach(element => {
cornerstone.enable(element);
element.tabIndex = 0;
element.focus();
cornerstone.loadImage(imageIds[0]).then(function (image) {
cornerstoneTools.addStackStateManager(element, ['stack']);
cornerstone.displayImage(element, image);
cornerstoneTools.addToolState(element, 'stack', stack);
});
//Save As Tool
const index = element.getAttribute('data-index');
const saveBtn = element.parentElement.querySelector(
`a[data-index='${index}']`
);
saveBtn.addEventListener('click', evt => {
cornerstoneTools.SaveAs(element, 'viewportImage.png');
});
// Log measurement events
const { EVENTS } = cornerstoneTools;
const log = event => {
const type = `MEASUREMENT_${event.type
.replace('cornerstonetoolsmeasurement', '')
.toUpperCase()}`;
const color = {
MEASUREMENT_ADDED: '#27e',
MEASUREMENT_MODIFIED: '#e72',
MEASUREMENT_COMPLETED: '#5b5',
MEASUREMENT_REMOVED: '#f55',
}[type];
const getData = detail => {
const { measurementData = {} } = detail;
const out = {};
const measurementKeys = [
'length',
'rAngle',
'value',
'text',
'str',
'text',
'longestDiameter',
'shortestDiameter',
];
if (measurementData.cachedStats) {
Object.keys(measurementData.cachedStats).forEach(key => {
out[key] = measurementData.cachedStats[key];
});
}
measurementKeys.forEach(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: ${color}; color: white; padding: 4px 0;`,
type,
// The tool type
`color: ${color}; font-family: monospace;`,
event.detail.toolInteraction || 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
const toolCategoryLinks = document.querySelectorAll(
'ul.tool-category-list a'
);
const toolCategorySections = document.querySelectorAll('ul.tool-category');
Array.from(toolCategoryLinks).forEach(link => {
//
const categoryName = link.getAttribute('data-category');
const categoryElement = document.querySelector(
`section[data-tool-category="${categoryName}"]`
);
// Setup listener
link.addEventListener('click', evt => {
evt.preventDefault();
setToolCategoryActive(categoryName);
});
});
// Iterate over all tool buttons
const toolButtons = document.querySelectorAll('a[data-tool]');
Array.from(toolButtons).forEach(toolBtn => {
// Add the tool
const toolName = toolBtn.getAttribute('data-tool');
const apiTool = cornerstoneTools[`${toolName}Tool`];
if (apiTool) {
cornerstoneTools.addTool(apiTool);
} else {
console.warn(`unable to add tool with name ${toolName}Tool`);
console.log(cornerstoneTools);
}
// Setup button listener
// Prevent right click context menu for our menu buttons
toolBtn.addEventListener(
'contextmenu',
event => event.preventDefault(),
true
);
// Prevent middle click opening a new tab on Chrome & FF
toolBtn.addEventListener(
'auxclick',
event => {
if (event.button && event.button === 1) {
event.preventDefault();
}
},
false
);
toolBtn.addEventListener('mousedown', evt => {
const mouseButtonMask = evt.buttons
? evt.buttons
: convertMouseEventWhichToButtons(evt.which);
const toolInteraction = evt.target.getAttribute('data-tool-interaction');
setButtonActive(toolName, mouseButtonMask, toolInteraction);
cornerstoneTools.setToolActive(toolName, {
mouseButtonMask,
isTouchActive: true,
});
evt.preventDefault();
evt.stopPropagation();
evt.stopImmediatePropagation();
return false;
});
});
// Iterate through swtich ON/OFF tools
const stateTools = document.querySelectorAll('input[type="checkbox"]');
Array.from(stateTools).forEach(toolCheckBox => {
const toolName = toolCheckBox.getAttribute('data-tool');
const toolLabel = document.querySelector(`#${toolName}`);
const apiTool = cornerstoneTools[`${toolName}Tool`];
if (apiTool) {
cornerstoneTools.addTool(apiTool);
}
cornerstoneTools.setToolDisabled(toolName);
toolCheckBox.addEventListener('change', evt => {
if (evt.currentTarget.checked) {
cornerstoneTools.setToolEnabled(toolName);
} else {
cornerstoneTools.setToolDisabled(toolName);
}
const toolLabelId =
toolName.charAt(0).toLowerCase() + toolName.slice(1);
const toolLabel = document.querySelector(`#${toolLabelId}`); //scaleOverlay or overlay
toolLabel.classList.toggle('turned-on');
});
});
// Activate first tool
cornerstoneTools.setToolActive(
cornerstoneTools.store.state.tools[0].name,
{
mouseButtonMask: 1,
isTouchActive: true,
}
);
const setToolCategoryActive = categoryName => {
Array.from(toolCategoryLinks).forEach(toolLink => {
if (categoryName === toolLink.getAttribute('data-category')) {
toolLink.classList.remove('active');
toolLink.classList.add('active');
} else {
toolLink.classList.remove('active');
}
});
Array.from(toolCategorySections).forEach(toolCategorySection => {
if (
categoryName ===
toolCategorySection.getAttribute('data-tool-category')
) {
toolCategorySection.classList.remove('active');
toolCategorySection.classList.add('active');
} else {
toolCategorySection.classList.remove('active');
}
});
};
const setButtonActive = (toolName, mouseButtonMask, toolInteraction) => {
Array.from(toolButtons).forEach(toolBtn => {
// Classes we need to set & remove
let mouseButtonIcon = `mousebutton-${mouseButtonMask}`;
let touchIcon = `touch-1`;
// Update classes depending on the toolInteraction we clicked
if (toolInteraction === 'none') {
return;
} else if (toolInteraction === 'multitouch') {
mouseButtonIcon = null;
touchIcon = 'touch-2';
} else if (toolInteraction === 'pinch') {
mouseButtonIcon = null;
touchIcon = 'touch-pinch';
} else if (toolInteraction === '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
const textMarkerTools = cornerstoneTools.store.state.tools.forEach(
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;
}
}
);
const 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>