-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
914 lines (835 loc) · 39.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
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
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
<!DOCTYPE html>
<html lang="en">
<head>
<title>Melanoma</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"
integrity="sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz"
crossorigin="anonymous"></script>
<style>
@font-face {
font-family: 'Aptos';
src: URL('Aptos.ttf') format('truetype');
}
@font-face {
font-family: 'Aptos';
src: url('Aptos-Bold.ttf') format('truetype');
font-weight: bold;
}
body {
background-color: #000;
color: #fff;
padding: 0;
margin: 0;
overflow: hidden;
font-family: Aptos, Calibri, sans-serif;
font-size: 12px;
text-align: center;
}
#info {
background-color: transparent;
position: absolute;
width: 100%;
top: 0px;
padding: 5px;
z-index: 999;
}
a {
color: #0080ff;
}
b {
color: orange
}
.sidebar {
position: fixed;
z-index: 999;
right: 0;
top: 50px;
width: 33%;
height: 100%;
overflow: auto;
background-color: transparent;
color: white;
padding: 20px;
box-sizing: border-box;
border-radius: 10px;
}
#description.sidebar {
left: 0;
right: auto;
}
.table>:not(caption)>*>* {
padding: 3px;
}
.label {
color: white;
font-size: 13px;
top: -15px;
}
.tt {
top: 0px;
color: black;
}
#heatmaps {
text-align: left;
margin-bottom: 40px;
}
.legend {
height: 40px;
width: 200px;
background: linear-gradient(in hsl longer hue to left, hsl(0, 100%, 50%), hsl(240, 100%, 50%));
float: right;
position: relative;
margin-top: 30px;
}
.legend #max {
right: 0px;
top: -17px;
position: absolute;
}
.legend #min {
left: 0px;
top: -17px;
position: absolute;
}
.legend #label {
position: absolute;
width: 100%;
text-align: center;
top: -17px;
}
#controls {
position: absolute;
left: 5%;
bottom: 10%;
}
input[type="radio" i]:disabled {
display: none;
}
</style>
</head>
<body>
<div id="info">
<div class="btn-group btn-group-toggle" data-toggle="buttons">
<label class="btn btn-secondary active">
<input class="form-check-input mt-0" type="radio" name="options" id="skin_button" autocomplete="off"
checked> Skin selection tool
</label>
<label class="btn btn-secondary">
<input class="form-check-input mt-0" type="radio" name="options" id="heatmaps_button" autocomplete="off"
disabled> Heatmaps
</label>
</div>
Controls: left mouse button to rotate, right mouse button to pan. Mouse wheel to zoom. Double click to focus
</div>
<div id="container"></div>
<div id="sidebar" class="sidebar show">
<div id="skin_selection">
<h3>Lymphatic Drainage Statistics</h3>
<table class="table table-hover table-dark">
<thead>
<th>Code</th>
<th>Node Field</th>
<th># Cases</th>
<th>Mean Drainage % </th>
<th>95%CI</th>
</thead>
<tbody id="tbody">
<tr>
<td colspan="5">Click an element to populate this table</td>
</tr>
</tbody>
</table>
<label class="btn btn-secondary active">
<input type="checkbox" id="show_patient_counts" checked> Display #Cases
</label>
<label class="btn btn-secondary active">
<input type="checkbox" id="show_nodecodes" checked> Display Codes
</label>
<label class="btn btn-secondary active">
<input type="checkbox" id="show_drainage" checked> Display Drainage %
</label>
</div>
<div id="heatmaps" style="display:none">
<table class="table table-bordered table-striped table-dark table-hover text-start">
<thead>
<tr>
<th>Region</th>
<th class="text-center">Left</th>
<th class="text-center">Right</th>
</tr>
</thead>
<tbody>
<tr>
<th>Head and Neck</th>
<td></td>
<td></td>
</tr>
<tr>
<td> -  Occipital</td>
<td class="text-center"><input type="radio" name="heatmap" value="Left Occipital"></td>
<td class="text-center"><input type="radio" name="heatmap" value="Right Occipital"></td>
</tr>
<tr>
<td> -  Preauricular</td>
<td class="text-center"><input type="radio" name="heatmap" value="Left Preauricular"></td>
<td class="text-center"><input type="radio" name="heatmap" value="Right Preauricular"></td>
</tr>
<tr>
<td> -  Postauricular</td>
<td class="text-center"><input type="radio" name="heatmap" value="Left Postauricular"></td>
<td class="text-center"><input type="radio" name="heatmap" value="Right Postauricular"></td>
</tr>
<tr>
<td> -  Cervical Level I</td>
<td class="text-center"><input type="radio" name="heatmap" value="Left Cervical Level I"></td>
<td class="text-center"><input type="radio" name="heatmap" value="Right Cervical Level I"></td>
</tr>
<tr>
<td> -  Cervical Level II</td>
<td class="text-center"><input type="radio" name="heatmap" value="Left Cervical Level II"></td>
<td class="text-center"><input type="radio" name="heatmap" value="Right Cervical Level II"></td>
</tr>
<tr>
<td> -  Cervical Level III</td>
<td class="text-center"><input type="radio" name="heatmap" value="Left Cervical Level III"></td>
<td class="text-center"><input type="radio" name="heatmap" value="Right Cervical Level III">
</td>
</tr>
<tr>
<td> -  Cervical Level IV</td>
<td class="text-center"><input type="radio" name="heatmap" value="Left Cervical Level IV"></td>
<td class="text-center"><input type="radio" name="heatmap" value="Right Cervical Level IV"></td>
</tr>
<tr>
<td> -  Cervical Level V</td>
<td class="text-center"><input type="radio" name="heatmap" value="Left Cervical Level V"></td>
<td class="text-center"><input type="radio" name="heatmap" value="Right Cervical Level V"></td>
</tr>
<tr>
<td> -  Submental</td>
<td class="text-center"><input type="radio" name="heatmap" value="Submental"></td>
<td class="text-center"><input type="radio" name="heatmap" value="Submental"></td>
</tr>
<tr>
<td> -  Anterior Node Fields</td>
<td class="text-center"><input type="radio" name="heatmap" value="Anterior Head"></td>
<td class="text-center"><input type="radio" name="heatmap" value="Anterior Head"></td>
</tr>
<tr>
<td> -  Posterior Node Fields</td>
<td class="text-center"><input type="radio" name="heatmap" value="Posterior Head">
</td>
<td class="text-center"><input type="radio" name="heatmap" value="Posterior Head">
</td>
</tr>
<tr>
<th>Axilla</th>
<td></td>
<td></td>
</tr>
<tr>
<td> -  Combined Levels I, II, III</td>
<td class="text-center"><input type="radio" name="heatmap" value="Left Axilla"></td>
<td class="text-center"><input type="radio" name="heatmap" value="Right Axilla" checked></td>
</tr>
<tr>
<td> -  Level I Anterior</td>
<td class="text-center"><input type="radio" name="heatmap"
value="Left Axilla/Sub-Node Fields Laa"></td>
<td class="text-center"><input type="radio" name="heatmap"
value="Right Axilla/Sub-Node Fields Raa"></td>
</tr>
<tr>
<td> -  Level I Mid</td>
<td class="text-center"><input type="radio" name="heatmap"
value="Left Axilla/Sub-Node Fields Lam"></td>
<td class="text-center"><input type="radio" name="heatmap"
value="Right Axilla/Sub-Node Fields Ram"></td>
</tr>
<tr>
<td> -  Level I Posterior</td>
<td class="text-center"><input type="radio" name="heatmap"
value="Left Axilla/Sub-Node Fields Lap"></td>
<td class="text-center"><input type="radio" name="heatmap"
value="Right Axilla/Sub-Node Fields Rap"></td>
</tr>
<tr>
<td> -  Level I Lateral</td>
<td class="text-center"><input type="radio" name="heatmap"
value="Left Axilla/Sub-Node Fields Lal"></td>
<td class="text-center"><input type="radio" name="heatmap"
value="Right Axilla/Sub-Node Fields Ral"></td>
</tr>
<tr>
<td>Triangular Intermuscular Space</td>
<td class="text-center"><input type="radio" name="heatmap"
value="Left Triangular Intermuscular Space"></td>
<td class="text-center"><input type="radio" name="heatmap"
value="Right Triangular Intermuscular Space"></td>
</tr>
<tr>
<td>Supraclavicular Fossa</td>
<td class="text-center"><input type="radio" name="heatmap" value="Left Supraclavicular Fossa">
</td>
<td class="text-center"><input type="radio" name="heatmap" value="Right Supraclavicular Fossa">
</td>
</tr>
<tr>
<td>Epitrochlear</td>
<td class="text-center"><input type="radio" name="heatmap" value="Left Epitrochlear"></td>
<td class="text-center"><input type="radio" name="heatmap" value="Right Epitrochlear"></td>
</tr>
<tr>
<th>Groin</th>
<td></td>
<td></td>
</tr>
<tr>
<td> -  Combined</td>
<td class="text-center"><input type="radio" name="heatmap" value="Left Groin"></td>
<td class="text-center"><input type="radio" name="heatmap" value="Right Groin"></td>
</tr>
<tr>
<td> -  External Iliac</td>
<td class="text-center"><input type="radio" name="heatmap"
value="Left Groin/Sub-Node Fields Liei"></td>
<td class="text-center"><input type="radio" name="heatmap"
value="Right Groin/Sub-Node Fields Riei"></td>
</tr>
<tr>
<td> -  Femoral</td>
<td class="text-center"><input type="radio" name="heatmap"
value="Left Groin/Sub-Node Fields Lif"></td>
<td class="text-center"><input type="radio" name="heatmap"
value="Right Groin/Sub-Node Fields Rif"></td>
</tr>
<tr>
<td> -  Inguinal</td>
<td class="text-center"><input type="radio" name="heatmap"
value="Left Groin/Sub-Node Fields Lii"></td>
<td class="text-center"><input type="radio" name="heatmap"
value="Right Groin/Sub-Node Fields Rii"></td>
</tr>
<tr>
<td>Popliteal</td>
<td class="text-center"><input type="radio" name="heatmap" value="Left Popliteal"></td>
<td class="text-center"><input type="radio" name="heatmap" value="Right Popliteal"></td>
</tr>
</tbody>
</table>
<table class="table table-bordered table-striped table-dark table-hover">
<thead>
<th># Node Fields</th>
<th>1</th>
<th>2+</th>
<th>3+</th>
<th>4+</th>
</thead>
<tr>
<td></td>
<td class="text-center"><input type="radio" name="heatmap" value="1 Draining Node Fields"></td>
<td class="text-center"><input type="radio" name="heatmap" value="2 Or More Draining Node Fields">
</td>
<td class="text-center"><input type="radio" name="heatmap" value="3 Or More Draining Node Fields">
</td>
<td class="text-center"><input type="radio" name="heatmap" value="4 Or More Draining Node Fields">
</td>
</tr>
</table>
<table class="table table-bordered table-striped table-dark table-hover "
style="width:50%;display:inline-block">
<tr>
<td>Display melanoma sites</td>
<td><input type="checkbox" id="display_melanoma_sites" checked></td>
</tr>
<tr>
<td>Frequency</td>
<td><input type="radio" name="patient_data" id="freq"></td>
</tr>
<tr>
<td>Normalised (% Drainage likelihood)</td>
<td><input type="radio" name="patient_data" id="norm" checked></td>
</tr>
</table>
<div class="legend"><span id="label">% Drainage likelihood</span><span id="max">100</span><span
id="min">0</span></div>
</div>
</div>
<div id="description" class="sidebar">
<h5 class="modal-title">About this tool</h5>
Researchers at The University of Auckland's Maurice Wilkins Centre have
mapped melanoma lymphoscintigraphy data from the Sydney Melanoma Unit (SMU) onto a 3D anatomically based
computer model of the skin and lymph nodes. This mapped data has enabled visualisation of the likely node fields
for melanoma metastasis.
Data was mapped by <a href="https://profiles.auckland.ac.nz/hayley-reynolds" target="blank">Dr Hayley
Reynolds</a> at the Auckland Bioengineering Institute, supervised
by Dr Nicolas Smith and Assoc Prof Rod Dunbar. Lymphoscintigraphy data from the SMU is courtesy of Prof Roger
Uren MD and Prof John Thompson MD.<br>
<br>
The mapped data can be viewed in two different displays. Click the 'Skin Selection Tool' option in the menubar
above to view the potential sentinel lymph node fields
by selecting different regions of skin. Alternatively, the 'Heatmaps' option on the menubar shows various heat
maps visualising the
percentage likelihood that the skin will show lymphatic drainage to a specified node field.
<br>
<br>
<strong>SKIN SELECTION TOOL:</strong><br>
Click on regions of skin on the image below to display the potential sentinel lymph node fields that will
receive melanoma cells if the cancer has spread
beyond the skin. The node fields displayed are scaled in size according to the drainage likelihood, and the
total number of patient cases are displayed on the selected skin regions. The table of statistics details the
number of patient cases draining to each node field and the
percentage likelihood of drainage to that node field.<br><br>
<strong>HEAT MAPS:</strong><br>
The heat maps show the percentage likelihood that a primary melanoma site will show lymphatic drainage to a
specified node field. Regions of skin with no lymphatic drainage to the node field are coloured blue. Different
node field displays can be seen by clicking on the corresponding buttons.<br><br>
<div id="controls" class="btn-group-vertical">
<h4>View:</h4>
<button type="button" class="btn btn-primary">Anterior</button>
<button type="button" class="btn btn-primary">Posterior</button>
<button type="button" class="btn btn-primary">Left lateral</button>
<button type="button" class="btn btn-primary">Right lateral</button>
<button type="button" class="btn btn-primary">All</button>
</div>
</div>
<script type="importmap">
{
"imports": {
"three": "https://cdn.jsdelivr.net/npm/three@0.170.0/build/three.module.js",
"three/addons/": "https://cdn.jsdelivr.net/npm/three@0.170.0/examples/jsm/"
}
}
</script>
<script defer type="module">
$('td').click(function (event) {
if (event.target.localName == 'td') {
$('input', this).trigger('click');
}
});
import $ from 'https://cdn.jsdelivr.net/npm/jquery@3.7.1/+esm'
import * as THREE from 'three';
window.THREE = THREE;
//import Stats from 'three/addons/libs/stats.module.js';
import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';
import WebGL from 'three/addons/capabilities/WebGL.js';
import { ArcballControls } from 'three/addons/controls/ArcballControls.js';
import { CSS2DRenderer, CSS2DObject } from 'three/addons/renderers/CSS2DRenderer.js';
/*
import { LineGeometry } from 'three/addons/lines/LineGeometry.js';
import { LineMaterial } from 'three/addons/lines/LineMaterial.js';
import { Line2 } from 'three/addons/lines/Line2.js';
*/
let container = document.getElementById('container')
let stats;
let camera, cameraTarget, scene, renderer, controls, labelRenderer, raycaster, INTERSECTED, SELECTED;
let selectable = [];
var offset = new THREE.Vector3(-270, -200, 900);
let main_scene, heatmap_scene, heatmaps, discrete_points_normalized;
let discrete_points = new THREE.Scene();
const pointer = new THREE.Vector2();
let data_elements;
let sphereGeometry = new THREE.SphereGeometry(10, 32, 32);
let rows = [];
init();
function addLabel(text, position, additional_class = "landmark") {
const labelDiv = document.createElement('div');
labelDiv.className = `label ${additional_class}`;
labelDiv.textContent = text;
const label = new CSS2DObject(labelDiv);
label.position.copy(position);
scene.add(label);
return label;
}
let tooltip = addLabel("Element name", new THREE.Vector3(0, 0, 0), "tt");
tooltip.visible = false;
function addSphere(position) {
const sphere = new THREE.Mesh(sphereGeometry, new THREE.MeshPhongMaterial({ color: 0x00ff00 }));
sphere.position.copy(position)
scene.add(sphere);
return sphere;
}
let lymphs = await fetch("lymphs_positions.json").then(response => response.json());
console.log("lymphs", lymphs);
window.lymph_lookup = {}
for (var l of lymphs) {
var position = new THREE.Vector3(l.position[0], l.position[1], l.position[2]).add(offset);
let sphere = addSphere(position);
let label = addLabel(l.label, position, "lymph");
lymph_lookup[l.label] = {
"sphere": sphere,
"label": label
}
}
data_elements = await fetch("src/data/data_elements.json").then(response => response.json());
console.log("data_elements", data_elements)
let patient_counts = await fetch("element_patient_counts.json").then(response => response.json());
console.log("patient_counts", patient_counts)
function parseColor(color) {
let r = color >> 16 & 255;
let g = color >> 8 & 255;
let b = color & 255;
return [r / 255, g / 255, b / 255];
}
function addDiscretePoints() {
var enabled = $("#display_melanoma_sites").is(":checked");
var selected_radio = $("input[name=patient_data]:checked").attr("id");
console.log(enabled, selected_radio)
heatmap_scene.remove(discrete_points);
var region = $("input[name='heatmap']:checked").attr("value");
var have_norm = discrete_points_normalized[region] != undefined;
var have_freq = discrete_points_normalized[region + " Frequency"] != undefined;
if ((selected_radio == "freq") && !have_freq) {
$("#norm").prop("checked", true);
selected_radio = "norm";
}
$("#freq").prop("disabled", !have_freq);
$("#norm").prop("disabled", !have_norm);
if (!enabled) return;
discrete_points = new THREE.Scene();
heatmap_scene.add(discrete_points)
if (selected_radio == "freq") {
region += " Frequency";
}
var patient_data = discrete_points_normalized[region]
if (!patient_data) return;
for (var i = 0; i < patient_data.positions.length; i++) {
var pos = patient_data.positions[i];
pos = new THREE.Vector3(pos[0], pos[1], pos[2])//.add(offset);
//var scale = patient_data.scales[i];
if (selected_radio == "freq") {
var color = parseColor(0);
} else {
var color = parseColor(patient_data.colors[i]);
}
var sphere = addSphere(pos);
sphere.material = new THREE.MeshPhongMaterial({
color: new THREE.Color(color[0], color[1], color[2]),
specular: "#33334C",
opacity: 1,
transparent: false,
shininess: 20,
flatShading: false,
side: THREE.DoubleSide
});
sphere.scale.setScalar(.5);
//sphere.scale.setScalar(scale / 100).clampScalar(.5, 50);
discrete_points.add(sphere);
}
}
function capitilize(s) {
s = s.replace(
/\w\S*/g,
text => text.charAt(0).toUpperCase() + text.substring(1).toLowerCase()
);
s = s.replace("Iii", "III");
s = s.replace("Ii", "II");
s = s.replace("Iv", "IV");
return s
}
function init() {
if (!WebGL.isWebGLAvailable()) {
const warning = WebGL.getWebGLErrorMessage();
container.appendChild(warning);
return;
}
camera = new THREE.PerspectiveCamera(35, window.innerWidth / window.innerHeight, 1, 10000);
window.camera = camera;
camera.position.set(1496.96865501004, 3213.1316867226697, -232.08816356744805);
camera.up = new THREE.Vector3(0, 0, 1);
scene = new THREE.Scene();
const loader = new GLTFLoader();
loader.load("scene.glb", (root) => {
console.log(root)
root = root.scene.children[0];
console.log(root)
for (var i in root.children) {
var child = root.children[i];
child.geometry.computeVertexNormals()
if (child.name == "Lines") {
console.log(child)
const material = new THREE.LineBasicMaterial({ color: 0x000000 });
const mesh = new THREE.LineSegments(child.geometry, material);
mesh.position.add(offset);
//root.children[i] = mesh;
root.children[i].visible = false;
scene.add(mesh);
} else {
child.material = new THREE.MeshPhongMaterial({
color: "#E5B27F",
specular: "#33334C",
opacity: .5,
transparent: true,
shininess: 20,
flatShading: false,
side: THREE.DoubleSide
});
selectable.push(child);
}
}
root.position.add(offset);
main_scene = root;
scene.add(root);
});
fetch("heat_maps_verts_colors.json").then(response => response.json()).then(result => {
heatmaps = result;
console.log("heatmaps", heatmaps)
var sorted_keys = Object.keys(heatmaps).sort()
for (var k of sorted_keys) {
let colors = heatmaps[k].map(c => parseColor(c)).flat();
heatmaps[k] = new THREE.Float32BufferAttribute(colors, 3)
}
for (var elem of $("input[name=heatmap]")) {
if (heatmaps[elem.value]) {
elem.disabled = false;
} else {
elem.disabled = true;
}
}
loader.load("human_mesh.glb", (root) => {
console.log("human_mesh.glb", root)
root = root.scene.children[0];
console.log("human_mesh.glb", root)
var child = root.children[0];
console.log("human_mesh.glb", child)
child.geometry.computeVertexNormals()
child.material = new THREE.MeshPhongMaterial({
color: "#FFFFFF",
specular: "#33334C",
opacity: 1,
transparent: false,
shininess: 20,
flatShading: false,
side: THREE.DoubleSide,
vertexColors: true
});
child.geometry.setAttribute('color', heatmaps["Right Axilla"]);
//child.geometry.attributes.color.needsUpdate = true;
root.position.add(offset);
heatmap_scene = root;
heatmap_scene.visible = false;
//root.position.set(0, 0, 0);
scene.add(root);
$("#heatmaps_button").prop("disabled", false);
fetch("discrete_points_normalized.json").then(response => response.json()).then(result => {
console.log("discrete_points_normalized", result)
discrete_points_normalized = result;
});
});
});
// lights
const dirLight1 = new THREE.DirectionalLight(0xffffff, 3);
dirLight1.position.set(1, 1, 1);
scene.add(dirLight1);
const dirLight2 = new THREE.DirectionalLight(0xffffff, 3);
dirLight2.position.set(-1, -1, -1);
scene.add(dirLight2);
const ambientLight = new THREE.AmbientLight(0x404040, 10);
scene.add(ambientLight);
raycaster = new THREE.Raycaster();
// renderer
renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(window.devicePixelRatio);
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setAnimationLoop(animate);
renderer.shadowMap.enabled = true;
container.appendChild(renderer.domElement);
labelRenderer = new CSS2DRenderer();
labelRenderer.setSize(window.innerWidth, window.innerHeight);
labelRenderer.domElement.style.position = 'absolute';
labelRenderer.domElement.style.top = '0px';
document.body.appendChild(labelRenderer.domElement);
//controls
controls = new ArcballControls(camera, labelRenderer.domElement, scene);
//controls.addEventListener('change', render);
controls.setGizmosVisible(false); // defaults to true
window.controls = controls;
//controls.minDistance = 1
//controls.maxDistance = 2000
// axes
//const axesHelper = new THREE.AxesHelper(250);
//scene.add(axesHelper);
// stats
/*stats = new Stats();
container.appendChild(stats.dom);
*/
window.addEventListener('mousemove', onPointerMove);
window.addEventListener('resize', onWindowResize);
//window.addEventListener('keydown', onKeyDown);
let drag = false;
document.addEventListener('mousedown', () => drag = false);
document.addEventListener('mousemove', () => drag = true);
document.addEventListener('mouseup', function () {
if (!drag && main_scene?.visible && INTERSECTED) {
if (data_elements) {
if (SELECTED) {
SELECTED.material.color.setHex(0xE5B27F);
SELECTED.material.opacity = .5;
}
SELECTED = INTERSECTED;
console.log("clicked", SELECTED.name, SELECTED)
SELECTED.material.color.setHex(0xFF0000);
//SELECTED.material.opacity = .5;
//$("#sidebar h3").text("Statistics for " + INTERSECTED.name.replace(/_/g, " "));
$("#tbody").empty()
for (var lymph_objects of Object.values(lymph_lookup)) {
lymph_objects.sphere.visible = false;
lymph_objects.label.visible = false;
}
rows = data_elements[INTERSECTED.name]
if (!rows) {
rows = data_elements[INTERSECTED.name.replace(/_/g, " ")]
}
if (tooltip) {
// Set tooltip position to center of hit face
function getCenterPoint(mesh) {
var geometry = mesh.geometry;
geometry.computeBoundingBox();
var center = new THREE.Vector3();
geometry.boundingBox.getCenter(center);
mesh.localToWorld(center);
return center;
}
tooltip.position.copy(getCenterPoint(SELECTED));
tooltip.element.textContent = patient_counts[SELECTED.name.replace("element_", "")] || 0;
tooltip.visible = $("#show_patient_counts").is(":checked");
}
if (!rows) {
console.warn(INTERSECTED.name)
$("#tbody").append(`<tr><td colspan="5">No data available</td></tr>`)
return;
}
for (var d of rows) {
if (lymph_lookup[d.code]) {
lymph_lookup[d.code].sphere.visible = true;
lymph_lookup[d.code].label.visible = true;
lymph_lookup[d.code].label.element.textContent = `${d.code} (${d.percentage.trim()}%)`;
let pct = parseFloat(d.percentage) / 50
lymph_lookup[d.code].sphere.scale.setScalar(pct).clampScalar(.5, 1);
}
$("#tbody").append(`<tr><td>${d.code}</td><td>${capitilize(d.name)}</td><td>${d.count}</td><td>${d.percentage}</td><td>${d.CI}</td></tr>`)
}
set_labels();
}
}
});
}
function onWindowResize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
labelRenderer.setSize(window.innerWidth, window.innerHeight);
}
function onPointerMove(event) {
pointer.x = (event.clientX / window.innerWidth) * 2 - 1;
pointer.y = - (event.clientY / window.innerHeight) * 2 + 1;
}
function animate() {
render();
//stats.update();
}
function render() {
if (main_scene?.visible) {
raycaster.setFromCamera(pointer, camera);
const intersects = raycaster.intersectObjects(selectable, true);
if (intersects.length > 0) {
if (INTERSECTED != intersects[0].object) {
//console.log("Hover on ", intersects[0].object)
if (INTERSECTED) INTERSECTED.material.emissive?.setHex(0x000000);
INTERSECTED = intersects[0].object;
INTERSECTED.material.emissive.setHex(0xFF0000);
}
} else {
// Reset emissive color
if (INTERSECTED) INTERSECTED.material.emissive.setHex(0x000000);
INTERSECTED = null;
}
}
renderer.render(scene, camera);
labelRenderer.render(scene, camera);
}
function onKeyDown(event) {
if (event.key === 'c') {
if (event.ctrlKey || event.metaKey) {
controls.copyState();
}
} else if (event.key === 'v') {
if (event.ctrlKey || event.metaKey) {
controls.pasteState();
}
}
}
$("#heatmaps_button").click(function () {
main_scene.visible = false;
heatmap_scene.visible = true;
for (var lymph_objects of Object.values(lymph_lookup)) {
lymph_objects.sphere.visible = false;
lymph_objects.label.visible = false;
}
$("#skin_selection").hide();
$("#heatmaps").show();
addDiscretePoints();
tooltip.visible = false;
});
$("#skin_button").click(function () {
main_scene.visible = true;
heatmap_scene.visible = false;
tooltip.visible = true;
$("#skin_selection").show();
$("#heatmaps").hide();
set_labels();
});
$("#controls button").click(function () {
let action = $(this).text();
var currentDistance = camera.position.length();
controls.reset();
if (["Reset", "All"].includes(action)) {
// pass
} else if (action == "Anterior") {
camera.position.set(0, currentDistance, 0);
} else if (action == "Posterior") {
camera.position.set(0, -currentDistance, 0);
} else if (action == "Left lateral") {
camera.position.set(-currentDistance, 0, 0);
} else if (action == "Right lateral") {
camera.position.set(currentDistance, 0, 0);
}
camera.up = new THREE.Vector3(0, 0, 1);
controls.update();
})
$("input[name='heatmap']").change(function () {
console.log(this.value)
if (heatmaps[this.value]) {
heatmap_scene.children[0].geometry.setAttribute('color', heatmaps[this.value]);
}
addDiscretePoints();
//heatmap_scene.children[0].geometry.attributes.color.needsUpdate = true;
})
$("input[name=patient_data],#display_melanoma_sites").change(function () {
addDiscretePoints();
})
function set_labels() {
var show_nodecode = $("#show_nodecodes").is(":checked");
var show_drainage = $("#show_drainage").is(":checked");
var show_patient_counts = $("#show_patient_counts").is(":checked");
tooltip.visible = show_patient_counts;
for (var d of rows) {
lymph_lookup[d.code].label.visible = show_nodecode || show_drainage;
lymph_lookup[d.code].sphere.visible = true;
if (show_nodecode && !show_drainage) {
lymph_lookup[d.code].label.element.textContent = d.code
} else if (!show_nodecode && show_drainage) {
lymph_lookup[d.code].label.element.textContent = d.percentage.trim() + "%"
} else if (show_nodecode && show_drainage) {
lymph_lookup[d.code].label.element.textContent = `${d.code} (${d.percentage.trim()}%)`;
}
}
}
$("#show_nodecodes,#show_drainage,#show_patient_counts").change(set_labels)
</script>
</body>
</html>