-
Notifications
You must be signed in to change notification settings - Fork 0
/
registration.html
executable file
·1135 lines (820 loc) · 42.6 KB
/
registration.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
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html>
<head>
<title>Report on the quality of MRI registration</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<!-- Stylesheets -->
<style>
/* Opacity of canvas itself set due to HTML5 globalAlpha drawing bug */
canvas {
opacity: 0.7;
}
.sliderNext {
position: absolute;
top: 40%;
right: 2.5%;
object-fit: none;
object-position: 0 -150px;
width: 50px;
height: 150px;
}
.sliderNext:hover {
object-position: -50px -150px;
}
.sliderPrev {
position: absolute;
top: 40%;
left: 2.5%;
object-fit: none;
object-position: 0 0;
width: 50px;
height: 150px;
}
.sliderPrev:hover {
object-position: -50px 0;
}
@keyframes flickerAnimation {
from { opacity: 1; }
to { opacity: 0;}
}
.register {
display: inline-block;
}
/* .register img:hover {
animation-name: flickerAnimation;
animation-duration: 1s;
animation-iteration-count: 1;
animation-direction: normal;
animation-timing-function: ease-in-out;
animation-fill-mode: both;
}*/
.reg_img_hover {
animation-name: flickerAnimation;
animation-duration: 1s;
animation-iteration-count: infinite;
animation-direction: alternate;
animation-timing-function: ease-in-out;
animation-fill-mode: both;
}
.button_hotkey_letter {
text-decoration: underline;
}
.cs-reg-img {
text-align: center;
}
#registration-pass, #registration-maybe, #registration-fail, #registration-unmark,
#registration-undo-point, #registration-clear-points {
box-shadow: 0 2px 4px -1px rgba(0,0,0,0.1),
0 4px 5px 0 rgba(0,0,0,0.1),
0 1px 10px 0 rgba(0,0,0,0.12) !important;
}
#registration-unmark, #registration-undo-point, #registration-clear-points {
background-color: #A1A1A1;
border-color: #A1A1A1;
color: #FFFFFF;
}
#registration-unmark:hover {
background-color: #808080;
border-color: #808080;
}
/* Styling for T1 registration image error painting */
#cs-reg-img {
width:256px; height:256px;
margin:20px 60px;
border:1px solid blue;
}
#T1-indVsTemplate {
/*width:100%;*/
height:100%;
position:relative;
}
#T1-img {
/*width:100%; height:100%; */
position:absolute; top:0px; left:0px;
}
#T1-canvas {
/*width:70%; height:70%; */
position: absolute;
top:0px; left:0px;
/*background-color: rgba(255,0,0,.1);*/
}
</style>
<!-- General styles for the dashboard -->
<link rel="stylesheet" type="text/css" href="assets/general/css/qc_dash.css" />
<!-- Keen.io -->
<link rel="stylesheet" type="text/css" href="lib/bootstrap/bootstrap.min.css" />
<link rel="stylesheet" type="text/css" href="lib/keen/keen-dashboards.css" />
<!-- Select2 -->
<link href="lib/select2/select2.min.css" rel="stylesheet" />
</head>
<body class="application">
<!-- Navbar -->
<div class="navbar navbar-inverse navbar-fixed-top" role="navigation">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="https://dashqc-fmri.readthedocs.io/en/latest/index.html">
dashQC_fmri
</a>
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav navbar-left">
<li class="navbar_item"><a href="index.html">Summary</a></li>
<li class="navbar_item navbar-brand-current"><a href="registration.html">Registration</a></li>
<li class="navbar_item"><a href="motion.html">Motion</a></li>
</ul>
<ul class="nav navbar-nav navbar-right">
<!-- <li><button type="button" class="btn btn-light dashQC_fmri-navbar-button" id="dashQC_fmri-import-button">Import data</button></li> -->
<li>
<input type="file" name="file" id="file" class="inputfile" />
<label for="file">
<span>Load QC</span>
</label>
</li>
<li>
<a href="" id="qcdash-export-link">
<button type="button" class="btn btn-light qcdash-navbar-button" id="qcdash-export-button" style="margin-right: 1em !important;">Save QC</button>
</a>
</li>
</ul>
</div>
</div>
</div>
<!-- Contents -->
<div class="container-fluid" >
<!-- Registration images -->
<div class="row">
<!-- Individual vs template T1 scan for subject -->
<div class="col-sm-6">
<div class="chart-wrapper" id="t1-chart-wrapper">
<div class="chart-title" id="t1-chart-title">
Individual vs template T1 scan for subject
<!-- <select class=#subject-select" style="width: 50%"></select> -->
</div>
<div class="chart-stage cs-reg-img" id="t1-chart-stage">
<div id="T1-indVsTemplate" class="register">
<img class="T1 montage" id="T1-img">
<canvas id="T1-canvas"></canvas>
</div>
<img class="sliderNext" src="lib/jsImageSlider/navbuttons.png" >
<img class="sliderPrev" src="lib/jsImageSlider/navbuttons.png" >
</div>
<div class="chart-notes">Click or press left/right arrows for prev/next subject. Hover over image for template scan. Move mouse away to revert to original image.</div>
</div>
</div>
<!-- BOLD vs T1 scan for subject -->
<div class="col-sm-6">
<div class="chart-wrapper">
<div class="chart-title" id="bold-chart-title">
BOLD vs T1 scan for subject
<!-- <select id=#subject-select" class=#subject-select" style="width: 50%"></select> -->
</div>
<div class="chart-stage cs-reg-img">
<div id="boldVsT1" class="register">
<img class="BOLD montage" id="BOLD-img">
</div>
<img class="sliderNext" src="lib/jsImageSlider/navbuttons.png" >
<img class="sliderPrev" src="lib/jsImageSlider/navbuttons.png" >
</div>
<div class="chart-notes">
Click or press left/right arrows for prev/next subject. Hover over image for individual T1 scan. Move mouse away to revert to original image.
</div>
</div>
</div>
</div>
<!-- QC Click Controls -->
<div class="row" style="margin: 1em 0 1em 1em;">
<div class="col-sm-3">
<button type="button" class="btn btn-md" id="registration-undo-point" style="margin-right: 1em; min-width: 8em;" disabled>Undo Point</button>
<button type="button" class="btn btn-md" id="registration-clear-points" style="margin-right: 1em; min-width: 8em;" disabled>Clear Points</button>
</div>
<div class="col-sm-9"></div>
</div>
<!-- Comment form and registration qc buttons -->
<div class="row">
<div class="col-sm-3"></div>
<div class="col-sm-6">
<div class="chart-wrapper">
<div class="chart-title">
<span>Current subject </span>
<select id="subject-select" style="width: 50%"></select>
<div style="float: right; padding-top: 0.25em;">
<span>Status: </span>
<span id="subject-status-span" style="font-weight: normal;"></span>
</div>
</div>
<!-- Saving form data:
https://stackoverflow.com/questions/13685263/can-i-save-input-from-form-to-txt-in-html-using-javascript-jquery-and-then-us -->
<!-- NOTE: Solutions to consider
(1) https://stackoverflow.com/questions/21012580/is-it-possible-to-write-data-to-file-using-only-javascript
(2) https://codeburst.io/using-html5-web-storage-a450294484bb
(3) https://scotch.io/tutorials/use-the-html5-file-api-to-work-with-files-locally-in-the-browser
-->
<div class="form-group">
<!-- <a id="mylink" download="./assets/general/mystuff.txt">Download link</a> -->
<!-- <label for="mytestinput">Comment:</label> -->
<textarea class="form-control" rows="7" id="registration-comment-textarea"></textarea>
</div>
<div class="chart-notes">
<!-- <button type="submit" class="btn btn-success" id="formsavebutton">Success</button>
<input id="the-file-input" type="file"> -->
</div>
</div>
</div>
<div class="col-sm-2">
<div class="qcdash-buttonarea">
<div class="row">
<div class="col-sm-1"></div>
<div class="col-sm-4">
<div class="row" style="margin-bottom: 1em;">
<button type="button" class="btn btn-success btn-md" id="registration-pass" style="margin-right: 1em; min-width: 8em;"><span class="button_hotkey_letter">P</span>ass</button>
<!-- color: #FFF; background-color: #23D160; border-color: #23D160; -->
</div>
<div class="row" style="margin-bottom: 1em;">
<button type="button" class="btn btn-warning btn-md" id="registration-maybe" style="margin-right: 1em; min-width: 8em;"><span class="button_hotkey_letter">M</span>aybe</button>
<!-- color: #FFF; background-color: #FFDD57; border-color: #FFDD57; -->
</div>
<div class="row" style="margin-bottom: 1em;">
<button type="button" class="btn btn-danger btn-md" id="registration-fail" style="margin-right: 1em; min-width: 8em;"><span class="button_hotkey_letter">F</span>ail</button>
<!-- color: #FFF; background-color: #FF3860; border-color: #FF3860; -->
</div>
<div class="row" style="margin-bottom: 1em;">
<button type="button" class="btn btn-md" id="registration-unmark" style="margin-right: 1em; min-width: 8em;"><span class="button_hotkey_letter">U</span>nmark</button>
<!-- color: #FFF; background-color: #D7D7D7; border-color: #D7D7D7; -->
</div>
</div>
</div>
</div>
<div class="col-sm-7"></div>
<!-- <div style="float: right; position: relative; transform: -ms-transform: translate(0%, 150%); transform: translate(0%, 150%);"></div> -->
</div>
</div>
</div>
<hr>
<!-- Footer -->
<footer class="footer">
<div class="container-fluid">
<div class="row">
<div class="col-sm-12">
<p class="small text-muted">Built with ♥ by <a href="http://simexp-lab.org">SIMEXP Lab.</a></p>
</div>
</div>
</div>
</footer>
<!-- Dependencies -->
<!-- For D3 -->
<script type="text/javascript" src="lib/d3js/d3.min.js" charset="utf-8"></script>
<!-- jQuery -->
<script type="text/javascript" src="lib/jquery/jquery.min.js"></script>
<!-- Twitter Bootstrap -->
<script type="text/javascript" src="lib/bootstrap/bootstrap.min.js"></script>
<!-- Keen.io -->
<script type="text/javascript" src="lib/keen/keen.min.js"></script>
<script type="text/javascript" src="lib/keen/meta.js"></script>
<!-- Select 2 -->
<script src="lib/select2/select2.min.js"></script>
<!-- Data in JS form -->
<!-- Description of input files and options -->
<script type="text/javascript" src="assets/summary/js/filesIn.js"></script>
<!-- List of subjects -->
<script src="assets/group/js/listSubject.js"></script>
<!-- Unique ID(s) for this dataset -->
<script src="assets/registration/js/datasetID.js"></script>
<!-- Custom external scripts -->
<!-- DashQC Objects -->
<script type="text/javascript" src="assets/general/js/qc_dash_objects.js"></script>
<!-- Live reload - for development use only -->
<!-- <script>document.write('<script src="http://' + (location.host || '${1:localhost}').split(':')[0] + ':${2:35729}/livereload.js?snipver=1"></' + 'script>')</script> -->
<!-- Main script -->
<script>
// === Dynamic bootstrap loading test (pre-document.ready) === //
// let bodyTag = document.getElementsByTagName("body")[0];
// let bootstrapRow = document.createElement("div");
// bootstrapRow.className = "row";
// let bootstrapCol1 = document.createElement("div");
// bootstrapCol1.className = "col-sm-5";
// bootstrapCol1.style.border = "thick solid #0000FF";
// let p1 = document.createElement("p");
// p1.innerHTML = "My first column";
// bootstrapCol1.appendChild(p1);
// let bootstrapCol2 = document.createElement("div");
// bootstrapCol2.className = "col-sm-7";
// bootstrapCol2.style.border = "thick solid #FF00FF";
// let p2 = document.createElement("p");
// p2.innerHTML = "My second column";
// bootstrapCol2.appendChild(p2);
// bodyTag.appendChild(bootstrapRow);
// bootstrapRow.appendChild(bootstrapCol1);
// bootstrapRow.appendChild(bootstrapCol2);
// Registration string status enum
const registrationStatus = {
UNMARKED: "Unmarked",
PASS: "Pass",
MAYBE: "Maybe",
FAIL: "Fail"
};
// Registration keypress enum
const registrationHotKeys = {
// Image navigation
LEFT_ARROW: 37,
RIGHT_ARROW: 39,
// Statuses
UNMARKED_UPPERCASE: 85,
UNMARKED_LOWERCASE: 117,
PASS_UPPERCASE: 80,
PASS_LOWERCASE: 112,
MAYBE_UPPERCASE: 77,
MAYBE_LOWERCASE: 109,
FAIL_UPPERCASE: 70,
FAIL_LOWERCASE: 102
};
// Element IDs
const elementIDs = {
boldDiv: "boldVsT1",
boldImg: "BOLD-img",
t1ChartWrapper: "t1-chart-wrapper",
t1ChartStage: "t1-chart-stage",
t1ChartTitle: "t1-chart-title",
t1Div: "T1-indVsTemplate",
t1Img: "T1-img",
t1Canvas: "T1-canvas",
undoPointsButton: "registration-undo-point",
clearPointsButton: "registration-clear-points"
};
// QC clicked points characteristics
const qcPoints = {
alpha: 0.7,
color: "rgb(255,221,87)",
radius: 8,
width: 3,
startAngle: 0,
endAngle: 2 * Math.PI
};
var webStorageElement = null;
// Perform when all have loaded
$(document).ready(function() {
// === Registration Image Functions === //
function clearPoints() {
console.log("clearPoints");
let canvas = document.getElementById(elementIDs.t1Canvas);
let canvasContext = canvas.getContext("2d");
// 1. Clear all points from the canvas
canvasContext.clearRect(0, 0, canvas.width, canvas.height);
// 2. Clear all points from the current subject
webStorageElement.clearPoints();
// 3. Disable undo and clear buttons
document.getElementById(elementIDs.undoPointsButton).setAttribute("disabled", "disabled");
document.getElementById(elementIDs.clearPointsButton).setAttribute("disabled", "disabled");
}
// Draws mark on point clicked in registration image
function drawDot(p_x, p_y, p_imageID, p_canvasID){
var image = document.getElementById(p_imageID);
var canvas = document.getElementById(p_canvasID);
// Adjust canvas coordinate system to match underlying image
canvas.style.position = "absolute";
canvas.style.left = image.offsetLeft + "px";
canvas.style.top = image.offsetTop + "px";
// Draw circular mark on the canvas
var canvasContext = canvas.getContext("2d");
canvasContext.imageSmoothingEnabled = true;
// canvasContext.globalAlpha = qcPoints.alpha;
canvasContext.lineWidth = qcPoints.width;
canvasContext.strokeStyle = qcPoints.color;
canvasContext.beginPath();
canvasContext.arc(p_x, p_y,
qcPoints.radius,
qcPoints.startAngle, qcPoints.endAngle,
false);
canvasContext.stroke();
}
// Draws a dot on the corresponding registration image and records the point for session storage
function recordPointClick(p_event) {
// 'this' in this context should be the tag with this assigned click event
// let t1ImgDOM = document.getElementById(elementIDs.t1Img);
// let t1ChartWrapper = document.getElementById(elementIDs.t1ChartWrapper);
// let t1ChartStage = document.getElementById(elementIDs.t1ChartStage);
// let t1ChartTitle = document.getElementById(elementIDs.t1ChartTitle);
// let t1DivDOM = document.getElementById(elementIDs.t1Div);
// var x = p_event.pageX - t1ChartWrapper.offsetLeft - t1ChartStage.offsetLeft - t1DivDOM.offsetLeft - t1ImgDOM.offsetLeft;
// var y = p_event.pageY - t1ChartWrapper.offsetTop - t1ChartStage.offsetTop - t1ChartTitle.offsetTop - t1DivDOM.offsetTop - t1ImgDOM.offsetTop;
let t1Canvas = document.getElementById(elementIDs.t1Canvas);
var rect = t1Canvas.getBoundingClientRect();
var x = p_event.clientX - rect.left;
var y = p_event.clientY - rect.top;
// Draw point
//drawX(x, y, xLength, xColor, canvasID);
drawDot(x, y, elementIDs.t1Img, elementIDs.t1Canvas);
// Record point for current subject into local and web storage
webStorageElement.addPoint(x, y);
// Enable the undo and clear buttons
document.getElementById(elementIDs.undoPointsButton).removeAttribute("disabled");
document.getElementById(elementIDs.clearPointsButton).removeAttribute("disabled");
}
// Redraws points onto registration image
function redrawAllPoints(p_ignoreDrawStatus) {
// console.log("redrawAllPoints");
// console.log("number of points for subject " + webStorageElement.m_currentSubject + " " + webStorageElement.points.length);
let subjectPoints = webStorageElement.points;
for ( let index = 0; index < subjectPoints.length; index++ ){
// Already drawn check
if ( p_ignoreDrawStatus || !subjectPoints[index][2] ) {
subjectPoints[index][2] = true;
drawDot(subjectPoints[index][0], subjectPoints[index][1],
elementIDs.t1Img, elementIDs.t1Canvas);
}
}
}
// Removes last drawn point
function undoLastPoint() {
// 1. Clear all points from the canvas
let canvas = document.getElementById(elementIDs.t1Canvas);
let canvasContext = canvas.getContext("2d");
canvasContext.clearRect(0, 0, canvas.width, canvas.height);
// 2. Remove the last drawn point from the current subject's point list
webStorageElement.removeLastPoint();
// 3. Unmark all points as having been drawn
webStorageElement.unmarkPoints();
// 4. Redraw all points to the canvas
redrawAllPoints(false);
// 5. Disable undo and clear buttons if no more points left for the current subject
if ( 0 == webStorageElement.pointCount() ) {
document.getElementById(elementIDs.undoPointsButton).setAttribute("disabled", "disabled");
document.getElementById(elementIDs.clearPointsButton).setAttribute("disabled", "disabled");
}
}
// === Functions === //
// Gets current subject name from select2 dropdown
function currentSubject() {
return $("#subject-select option[value=\"" + $("#subject-select").val() + "\"]").text();
}
// Find subject ID number in provided data given a subject name
function findSubjectIDFromName(p_data, p_subject) {
let foundID = null;
for ( let index = 0; index < p_data.length; index++ ) {
if ( p_data[index].text === p_subject ) {
foundID = p_data[index].id;
break;
}
}
return foundID;
}
// Function to parse the page parameters
function getParameterByName(p_name, p_url) {
if ( !p_url ) {
p_url = window.location.href;
}
p_name = p_name.replace(/[\[\]]/g, "\\$&");
var regex = new RegExp("[?&]" + p_name + "(=([^&#]*)|&|#|$)"),
results = regex.exec(p_url);
if ( !results ) {
return null;
}
if ( !results[2] ) {
return '';
}
return decodeURIComponent(results[2].replace(/\+/g, " "));
}
// Moves on to the next subject
function nextSubject() {
// Get current subject list ID from subject select dropdown
let subjectListID = parseInt($("#subject-select").val());
// Increment list ID to next subject list ID or reset back to first subject list ID
subjectListID = ( subjectListID < listSubject.length ) ? subjectListID + 1 : 1;
// Switch to registration image/QC status of subject with this list ID
switchSubjects({ params: { data: { id: subjectListID.toString() } } });
}
// Moves back to the previous subject
function previousSubject() {
// Get current subject list ID from subject select dropdown
let subjectListID = parseInt($("#subject-select").val());
// Decrement list ID to previous subject list ID or reset back to last subject list ID
subjectListID = ( subjectListID < listSubject.length ) ? subjectListID - 1 : listSubject.length;
// Switch to registration image/QC status of subject with this list ID
switchSubjects({ params: { data: { id: subjectListID.toString() } } });
}
/* Idea from Erin - ability to look through scans, keeping best and worst as stickies to allow scrolling through images for rejection/approval purposes - March 12, 2019
*/
// Changes subjects with left and right arrows (previous and next, respectively)
function registrationKeyDown(p_key) {
// Hotkeys only work if textarea does not currently have focus
if ( $("#registration-comment-textarea").is(":focus") ) {
return;
}
// Perform appropriate behavior for keypress
switch ( p_key ) {
// Arrow keys (left, right)
case registrationHotKeys.LEFT_ARROW:
previousSubject();
break;
case registrationHotKeys.RIGHT_ARROW:
nextSubject();
break;
// Status hot keys (Uu unmarked, Pp pass, Mm maybe, Ff fail)
case registrationHotKeys.UNMARKED_UPPERCASE:
case registrationHotKeys.UNMARKED_LOWERCASE:
setSubjectStatus(currentSubject(), registrationHotKeys.UNMARKED_UPPERCASE);
break;
case registrationHotKeys.PASS_UPPERCASE:
case registrationHotKeys.PASS_LOWERCASE:
setSubjectStatus(currentSubject(), registrationHotKeys.PASS_UPPERCASE);
break;
case registrationHotKeys.MAYBE_UPPERCASE:
case registrationHotKeys.MAYBE_LOWERCASE:
setSubjectStatus(currentSubject(), registrationHotKeys.MAYBE_UPPERCASE);
break;
case registrationHotKeys.FAIL_UPPERCASE:
case registrationHotKeys.FAIL_LOWERCASE:
setSubjectStatus(currentSubject(), registrationHotKeys.FAIL_UPPERCASE);
break
}
}
// Updates images
function setImage (p_event) {
// Get subject index and ID
var id = p_event.params.data.id;
subject = $("#subject-select option[value=" + id + "]").text();
// Update the selection of the subject button
let subjectSelectDropdown = $("#subject-select");
subjectSelectDropdown.val(id);
subjectSelectDropdown.trigger("change");
// Grab the T1 and BOLD div, and build new empty figures
var figBOLD = $(".BOLD");
var newFigBOLD = document.createElement("img");
var figT1 = $(".T1");
var newFigT1 = document.createElement("img");
// Populate figures
newFigBOLD.src = "assets/registration/images/" + subject + "_func.png";
newFigBOLD.setAttribute("width", "70%");
newFigBOLD.style.position = "relative";
newFigBOLD.style.left = "0px";
newFigBOLD.className = "BOLD";
newFigT1.src = "assets/registration/images/" + subject + "_anat.png";
newFigT1.setAttribute("width", "70%");
newFigT1.style.position = "relative";
newFigT1.style.left = "0px";
newFigT1.className = "T1";
newFigT1.id = "T1-img";
// Update figures
figBOLD.replaceWith(newFigBOLD);
figT1.replaceWith(newFigT1);
figBoldVsT1 = $("#boldVsT1");
figBoldVsT1.css("backgroundImage","url('assets/registration/images/" + subject + "_anat.png')");
figBoldVsT1.css("display", "inline-block");
figBoldVsT1.css("backgroundSize","70%");
figBoldVsT1.css("backgroundRepeat","no-repeat");
figBoldVsT1.css("backgroundPosition","50% 0%");
figT1vsTemplate = $("#T1-indVsTemplate");
figT1vsTemplate.css("backgroundImage","url('assets/group/images/template_stereotaxic.png')");
figT1vsTemplate.css("display", "inline-block");
figT1vsTemplate.css("backgroundSize","70%");
figT1vsTemplate.css("backgroundRepeat","no-repeat");
figT1vsTemplate.css("backgroundPosition","50% 0%");
// Set up images for point-clicking
var t1Img = $("#" + elementIDs.t1Img);
var t1Canvas = $("#" + elementIDs.t1Canvas);
// t1Img.on("click", recordPointClick);
t1Img.on("load", function() {
let t1ImgDOM = document.getElementById(elementIDs.t1Img);
t1Canvas.attr({
"width": t1ImgDOM.clientWidth,
"height": t1ImgDOM.clientHeight,
});
t1Canvas.on("mouseup", recordPointClick);
t1Canvas.css({
// "position": "absolute",
"left": t1ImgDOM.offsetLeft + "px",
"top": t1ImgDOM.offsetTop + "px"
});
redrawAllPoints(true);
});
// Pass through of canvas hover to img hover
// var context = t1Canvas.getContext("2d");
t1Canvas.hover(function() {
t1Img.addClass("reg_img_hover");
t1Img.css("-webkit-animation-play-state", "running");
}, function() {
t1Img.css("-webkit-animation-play-state", "paused");
});
}
// Translates a status hot key to text, displays the status onscreen, and stores it
function setSubjectStatus(p_subject, p_key) {
let translatedStatus = registrationStatus.UNMARKED;
// Translate keypress code to registration status string
switch ( p_key ) {
case registrationHotKeys.UNMARKED_UPPERCASE:
case registrationHotKeys.UNMARKED_LOWERCASE:
translatedStatus = registrationStatus.UNMARKED;
break;
case registrationHotKeys.PASS_UPPERCASE:
case registrationHotKeys.PASS_LOWERCASE:
translatedStatus = registrationStatus.PASS;
break;
case registrationHotKeys.MAYBE_UPPERCASE:
case registrationHotKeys.MAYBE_LOWERCASE:
translatedStatus = registrationStatus.MAYBE;
break;
case registrationHotKeys.FAIL_UPPERCASE:
case registrationHotKeys.FAIL_LOWERCASE:
translatedStatus = registrationStatus.FAIL;
break;
}
// Display the status text on the subject data widget
$("#subject-status-span").text(translatedStatus);
// Set the new registration status for this subject image in web storage
webStorageElement.setSubjectStatus(p_subject, translatedStatus);
}
function setUIToCurrentSubject(p_webStorageObject, p_subjectList, p_uiList) {
let subjectName = p_webStorageObject.currentSubject;
// Get current subject ID in data list from name
let foundID = null;
for ( let index = 0; index < p_subjectList.length; index++ ) {
if ( p_subjectList[index].text === subjectName ) {
foundID = p_subjectList[index].id;
break;
}
}
if ( null == foundID ) {
// Error
return;
}
// Switch subjects
switchSubjects({ params: { data: { id: findSubjectIDFromName(listSubject, subjectName)} } });
// Fill in DOM objects
$("#" + p_uiList.select).select({ params: { data: { id: foundID } } });
if ( subjectName in p_webStorageObject.subjects ) {
$("#" + p_uiList.comments).val(p_webStorageObject.subjects[subjectName].comments);
$("#" + p_uiList.status).text(p_webStorageObject.subjects[subjectName].status);
}
// Redraw points for the current subject
redrawAllPoints(true);
}
// Translates key press to subject status text
function statusKeyToText(p_key) {
let text = "Unmarked";
if ( "" != p_key ) {
switch ( p_key ) {
case 80:
case 112:
text = "Pass";
break;
case 77:
case 109:
text = "Maybe";
break;
case 70:
case 102:
text = "Fail";
break;
}
}
return text;
}
// Code to execute when switching between subjects for registration
function switchSubjects(p_event) {
let newSubject = $("#subject-select option[value=" +
p_event.params.data.id + "]").text();
let status = "";
// Set up a new subject for session storage input (status/comments)
if ( webStorageElement ) {
webStorageElement.setSubject(newSubject, p_event.params.data.id);
status = webStorageElement.getSubjectStatus(newSubject);
// Change text area to any previous comments for new subject
webStorageElement.restoreCommentsToTextArea();
}
// Get the QC status of this subject
if ( "" == status ) {
status = "Unmarked";
}
// Change images
setImage(p_event);
// Restore any previous clicked qc points for new subject
if ( webStorageElement ) {
// Enable undo and clear buttons if there are points for this subject
if ( webStorageElement.pointCount() > 0 ) {
document.getElementById(elementIDs.undoPointsButton).removeAttribute("disabled");
document.getElementById(elementIDs.clearPointsButton).removeAttribute("disabled");
}
}
// Change chart titles
$("#t1-chart-title").text("Individual vs template T1 scan for " + newSubject);
$("#bold-chart-title").text("BOLD vs T1 scan for " + newSubject);
$("#subject-status-span").text(status);
}
// === Main script === //
// 1. Get initial scan file info for first subject
var event = { params: { data: { id: "1" } } };
var filesIn = buildFilesIn(event);
// 2. Add a subject select dropdown based on the subject list
$("#subject-select").select2({ data: listSubject });
$("#subject-select").on("select2:select", function (p_event) {
// Get new file information for this subject
filesIn = buildFilesIn(p_event);
// Perform actions necessary to switch subjects (loading new data, new images)