forked from cornerstonejs/cornerstoneWADOImageLoader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
746 lines (499 loc) · 16.7 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
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
<!DOCTYPE html>
<html>
<head>
<!-- twitter bootstrap CSS stylesheet - included to make things pretty, not needed or used by cornerstone -->
<link href="../bootstrap.min.css" rel="stylesheet" />
<link href="../cornerstone.min.css" rel="stylesheet" />
</head>
<body>
<div class="container">
<div class="page-header">
<h1>Example of using a custom web worker</h1>
<p class="lead">
Enter a URL for a DICOM P10 object below to view it using cornerstone.
<button id="toggleCollapseInfo" class="btn btn-primary" type="button">
Click for more info
</button>
</p>
</div>
<div id="collapseInfo" class="collapse" style="display: none">
<p>
This example illustrates how to use the cornerstoneWADOImageLoader to
get a DICOM P10 SOP instance using HTTP and display it in your web browser
using cornerstone. Not all transfer syntaxes are currently supported,
<a
href="https://github.com/cornerstonejs/cornerstoneWADOImageLoader/blob/master/docs/TransferSyntaxes.md"
>
click here for the full list.
</a>
For WADO-URI requests, you can request that the server return the SOP
Instance in explicit little endian by appending the following query string
to your URL:
<code>&transferSyntax=1.2.840.10008.1.2.1</code>
</p>
<p>
Use the query string parameter
<i>frame</i>
to specify which frame to display from a multiframe object (defaults to
the first frame if not specified).
<code>?frame=2</code>
</p>
<strong>
If you get an HTTP error and your URL is correct, it is probably because
the server is not configured to allow
<a href="http://en.wikipedia.org/wiki/Cross-origin_resource_sharing">
Cross Origin Requests
</a>
. Most browsers will allow you to enable cross domain requests via settings
or command line switches, you can start chrome with the command line switch
<code>--disable-web-security</code>
to allow cross origin requests. See the
<a href="http://enable-cors.org/">Enable CORS site</a>
for information about CORS.
</strong>
<br />
<br />
<p>
Looking for a CORS proxy? Try
<a href="https://www.npmjs.com/package/corsproxy">CORSProxy</a>
</p>
<strong>
Use of this example require IE10+ or any other modern browser.
</strong>
<hr />
</div>
<div class="row">
<form id="form" class="form-horizontal">
<div class="form-group">
<label class="control-label col-sm-1" for="wadoURL">URL</label>
<div class="col-sm-8">
<input
class="form-control"
type="text"
id="wadoURL"
placeholder="Enter WADO URL"
value="https://raw.githubusercontent.com/cornerstonejs/cornerstoneWADOImageLoader/master/testImages/CT2_J2KR"
/>
</div>
<div class="col-sm-3">
<button
class="form-control btn btn-primary"
type="button"
id="downloadAndView"
>
Download and View
</button>
</div>
</div>
<div class="form-group">
<div class="col-sm-3">
<button
class="form-control"
type="button"
id="startWebWorker"
class="btn btn-primary"
>
Start 1 Sleep Tasks
</button>
</div>
<div class="col-sm-3">
<button
class="form-control"
type="button"
id="start10WebWorkers"
class="btn btn-primary"
>
Start 10 Sleep Tasks
</button>
</div>
<div class="col-sm-3">
<button
class="form-control"
type="button"
id="sharpen"
class="btn btn-primary"
>
Sharpen Image
</button>
</div>
<div class="col-sm-3">
<button
class="form-control"
type="button"
id="edgeDetect"
class="btn btn-primary"
>
Edge Enhance
</button>
</div>
<div class="col-sm-3">
<button
class="form-control"
type="button"
id="boxBlur"
class="btn btn-primary"
>
Box Blur
</button>
</div>
<div class="col-sm-3">
<button
class="form-control"
type="button"
id="gaussianBlur"
class="btn btn-primary"
>
Gaussian Blur
</button>
</div>
<div class="col-sm-3">
<button
class="form-control"
type="button"
id="emboss"
class="btn btn-primary"
>
Emboss
</button>
</div>
<div class="col-sm-3">
<button
class="form-control"
type="button"
id="unsharp"
class="btn btn-primary"
>
Unsharp
</button>
</div>
</div>
</form>
</div>
<br />
<div class="row">
<div class="col-md-6">
<div
style="
width: 512px;
height: 512px;
position: relative;
color: white;
display: inline-block;
border-style: solid;
border-color: black;
"
oncontextmenu="return false"
class="disable-selection noIbar"
unselectable="on"
onselectstart="return false;"
onmousedown="return false;"
>
<div
id="dicomImage"
style="
width: 512px;
height: 512px;
top: 0px;
left: 0px;
position: absolute;
"
>
</div>
</div>
</div>
<div class="col-md-6">
<span>Max Web Workers: </span>
<span id="maxWebWorkers"></span>
<br />
<span>Num Web Workers: </span>
<span id="numWebWorkers"></span>
<br />
<span>Num Queued Tasks: </span>
<span id="numQueuedTasks"></span>
<br />
<span>Num Tasks Executing: </span>
<span id="numTasksExecuting"></span>
<br />
<span>Total Tasks Executed: </span>
<span id="totalTasksExecuted"></span>
<br />
<span>Total Task Execution Time: </span>
<span id="totalTaskExecutionTime"></span>
<br />
<span>Total Task Delay Time: </span>
<span id="totalTaskDelayTime"></span>
<br />
</div>
</div>
</div>
</body>
<!-- include the cornerstone library -->
<script src="../cornerstone.min.js"></script>
<script src="../cornerstoneMath.min.js"></script>
<script src="../cornerstoneTools.min.js"></script>
<!-- include the dicomParser library as the WADO image loader depends on it -->
<script src="../dicomParser.min.js"></script>
<!-- include the cornerstoneWADOImageLoader library -->
<script src="../../dist/cornerstoneWADOImageLoader.bundle.min.js"></script>
<!-- Lines ONLY required for this example to run without building the project -->
<script>
window.cornerstoneWADOImageLoader ||
document.write(
'<script src="https://unpkg.com/cornerstone-wado-image-loader">\x3C/script>'
);
</script>
<script src="../utils/customWebWorkersConfig.js"></script>
<script>
// Initialize the web worker manager with our custom web worker task
// window.customWebWorkerConfig contains custom web worker config and a fallback in case there is no dist folder
config = window.customWebWorkerConfig;
cornerstoneWADOImageLoader.external.cornerstone = cornerstone;
cornerstoneWADOImageLoader.webWorkerManager.initialize(config);
document.getElementById('numWebWorkers').textContent = config.maxWebWorkers;
let loaded = false;
let loadedImage;
function loadAndViewImage(imageId) {
const element = document.getElementById('dicomImage');
try {
const start = new Date().getTime();
cornerstone.loadAndCacheImage(imageId).then(
function (image) {
console.log(image);
loadedImage = image;
updateStatistics();
const viewport = cornerstone.getDefaultViewportForImage(
element,
image
);
cornerstone.displayImage(element, image, viewport);
if (loaded === false) {
cornerstoneTools.mouseInput.enable(element);
cornerstoneTools.mouseWheelInput.enable(element);
cornerstoneTools.wwwc.activate(element, 1); // ww/wc is the default tool for left mouse button
cornerstoneTools.pan.activate(element, 2); // pan is the default tool for middle mouse button
cornerstoneTools.zoom.activate(element, 4); // zoom is the default tool for right mouse button
cornerstoneTools.zoomWheel.activate(element); // zoom is the default tool for middle mouse wheel
loaded = true;
}
},
function (err) {
alert(err);
}
);
} catch (err) {
alert(err);
}
}
function downloadAndView() {
let url = document.getElementById('wadoURL').value;
// prefix the url with wadouri: so cornerstone can find the image loader
url = 'wadouri:' + url;
// image enable the dicomImage element and activate a few tools
loadAndViewImage(url);
}
function getUrlWithoutFrame() {
const url = document.getElementById('wadoURL').value;
const frameIndex = url.indexOf('frame=');
if (frameIndex !== -1) {
url = url.substr(0, frameIndex - 1);
}
return url;
}
function updateStatistics() {
var stats = cornerstoneWADOImageLoader.webWorkerManager.getStatistics();
document.getElementById('maxWebWorkers').textContent =
stats.maxWebWorkers;
document.getElementById('numWebWorkers').textContent =
stats.numWebWorkers;
document.getElementById('numQueuedTasks').textContent =
stats.numTasksQueued;
document.getElementById('numTasksExecuting').textContent =
stats.numTasksExecuting;
document.getElementById('totalTasksExecuted').textContent =
stats.numTasksCompleted;
document.getElementById('totalTaskExecutionTime').textContent =
stats.totalTaskTimeInMS;
document.getElementById('totalTaskDelayTime').textContent =
stats.totalTimeDelayedInMS;
}
var sleepTaskLoaded = false;
function startWebWorker() {
// dyanmically load the sleep task
if (!sleepTaskLoaded) {
sleepTaskLoaded = true;
// TODO: This URL probably won't work on hosted site
cornerstoneWADOImageLoader.webWorkerManager.loadWebWorkerTask(
`${window.location.protocol}//${window.location.host}/examples/customWebWorkerTask/sleepTask.js`,
{
sleepTask: {
sleepTime: 3000,
},
}
);
}
const task = cornerstoneWADOImageLoader.webWorkerManager.addTask(
'sleepTask',
{},
-10
);
const promise = task.promise;
promise.then(function (result) {
console.log('sleep task completed');
updateStatistics();
});
updateStatistics();
}
const element = document.getElementById('dicomImage');
cornerstone.enable(element);
document
.getElementById('downloadAndView')
.addEventListener('click', function (e) {
downloadAndView();
});
document
.getElementById('startWebWorker')
.addEventListener('click', function (e) {
startWebWorker();
});
document
.getElementById('start10WebWorkers')
.addEventListener('click', function (e) {
for (let i = 0; i < 10; i++) {
startWebWorker();
}
});
function convolute(kernel, multiplier, calculateWWWC) {
const task = cornerstoneWADOImageLoader.webWorkerManager.addTask(
'convolveTask',
{
pixelData: loadedImage.getPixelData(),
kernel: kernel,
multiplier: multiplier,
imageFrame: {
typedArrayName: loadedImage.getPixelData().constructor.name,
width: loadedImage.width,
height: loadedImage.height,
},
},
-8
);
setInterval(console.log('TASK:', task.promise), 1000);
task.promise.then(function (result) {
console.log('convolveTask task completed');
result.pixelData = new Int16Array(result.pixelData);
const sharpenedImage = {
color: false,
columns: loadedImage.columns,
rows: loadedImage.rows,
width: loadedImage.width,
height: loadedImage.height,
imageId: new Date().toISOString(),
maxPixelValue: result.minMax.max,
minPixelValue: result.minMax.min,
windowWidth: calculateWWWC
? result.minMax.max - result.minMax.max
: loadedImage.windowWidth,
windowLevel: calculateWWWC
? (result.minMax.max + result.minMax.max) / 2
: loadedImage.windowLevel,
sizeInBytes: loadedImage.sizeInBytes,
render: loadedImage.render,
slope: loadedImage.slope,
intercept: loadedImage.intercept,
invert: loadedImage.invert,
getPixelData: function () {
return result.pixelData;
},
};
cornerstone.displayImage(element, sharpenedImage);
loadedImage = sharpenedImage;
updateStatistics();
});
}
document.getElementById('sharpen').addEventListener('click', function (e) {
convolute(
[
[0, -1, 0],
[-1, 5, -1],
[0, -1, 0],
],
1
);
});
document
.getElementById('edgeDetect')
.addEventListener('click', function (e) {
convolute(
[
[-1, -1, -1],
[-1, 9, -1],
[-1, -1, -1],
],
1
);
});
document.getElementById('boxBlur').addEventListener('click', function (e) {
convolute(
[
[1, 1, 1],
[1, 1, 1],
[1, 1, 1],
],
1 / 9
);
});
document
.getElementById('gaussianBlur')
.addEventListener('click', function (e) {
convolute(
[
[1, 2, 1],
[2, 4, 2],
[1, 2, 1],
],
1 / 16
);
});
document.getElementById('emboss').addEventListener('click', function (e) {
convolute(
[
[-2, 1, 0],
[-1, 1, 1],
[0, 1, 2],
],
1 / 3
);
});
document.getElementById('unsharp').addEventListener('click', function (e) {
convolute(
[
[1, 4, 6, 4, 1],
[4, 16, 24, 16, 4],
[6, 24, -476, 24, 6],
[4, 16, 24, 16, 4],
[1, 4, 6, 4, 1],
],
-1 / 256
);
});
const form = document.getElementById('form');
form.addEventListener('submit', function () {
downloadAndView();
return false;
});
document
.getElementById('toggleCollapseInfo')
.addEventListener('click', function () {
if (document.getElementById('collapseInfo').style.display === 'none') {
document.getElementById('collapseInfo').style.display = 'block';
} else {
document.getElementById('collapseInfo').style.display = 'none';
}
});
// set an interval timer to periodically update the statistics for a real time view of
// what the web workers are doing
setInterval(function () {
updateStatistics();
}, 100);
</script>
</html>