@niivue/niivue 0.19.1 → 0.20.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/niivue.es.js +194 -223
- package/dist/niivue.umd.js +29 -29
- package/package.json +1 -1
- package/src/AIL.nii.gz +0 -0
- package/src/index.html +3 -3
- package/src/niivue.js +70 -61
- package/src/nvimage.js +104 -90
package/README.md
CHANGED
|
@@ -38,7 +38,7 @@ We host many NiiVue examples via github pages. These are updated and deployed au
|
|
|
38
38
|
|
|
39
39
|
## existing html page
|
|
40
40
|
```html
|
|
41
|
-
<script src="https://unpkg.com/@niivue/niivue@0.
|
|
41
|
+
<script src="https://unpkg.com/@niivue/niivue@0.20.0/dist/niivue.umd.js"></script>
|
|
42
42
|
|
|
43
43
|
<canvas id="gl" height=480 width=640></canvas>
|
|
44
44
|
|
package/dist/niivue.es.js
CHANGED
|
@@ -53,7 +53,6 @@ var compileShader = function(gl, vert, frag) {
|
|
|
53
53
|
}
|
|
54
54
|
return program;
|
|
55
55
|
};
|
|
56
|
-
var EPSILON = 1e-6;
|
|
57
56
|
var ARRAY_TYPE = typeof Float32Array !== "undefined" ? Float32Array : Array;
|
|
58
57
|
if (!Math.hypot)
|
|
59
58
|
Math.hypot = function() {
|
|
@@ -331,85 +330,66 @@ function translate(out, a, v) {
|
|
|
331
330
|
}
|
|
332
331
|
return out;
|
|
333
332
|
}
|
|
334
|
-
function
|
|
335
|
-
var
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
333
|
+
function rotateX(out, a, rad) {
|
|
334
|
+
var s = Math.sin(rad);
|
|
335
|
+
var c = Math.cos(rad);
|
|
336
|
+
var a10 = a[4];
|
|
337
|
+
var a11 = a[5];
|
|
338
|
+
var a12 = a[6];
|
|
339
|
+
var a13 = a[7];
|
|
340
|
+
var a20 = a[8];
|
|
341
|
+
var a21 = a[9];
|
|
342
|
+
var a22 = a[10];
|
|
343
|
+
var a23 = a[11];
|
|
344
|
+
if (a !== out) {
|
|
345
|
+
out[0] = a[0];
|
|
346
|
+
out[1] = a[1];
|
|
347
|
+
out[2] = a[2];
|
|
348
|
+
out[3] = a[3];
|
|
349
|
+
out[12] = a[12];
|
|
350
|
+
out[13] = a[13];
|
|
351
|
+
out[14] = a[14];
|
|
352
|
+
out[15] = a[15];
|
|
353
|
+
}
|
|
354
|
+
out[4] = a10 * c + a20 * s;
|
|
355
|
+
out[5] = a11 * c + a21 * s;
|
|
356
|
+
out[6] = a12 * c + a22 * s;
|
|
357
|
+
out[7] = a13 * c + a23 * s;
|
|
358
|
+
out[8] = a20 * c - a10 * s;
|
|
359
|
+
out[9] = a21 * c - a11 * s;
|
|
360
|
+
out[10] = a22 * c - a12 * s;
|
|
361
|
+
out[11] = a23 * c - a13 * s;
|
|
352
362
|
return out;
|
|
353
363
|
}
|
|
354
|
-
function
|
|
355
|
-
var
|
|
356
|
-
var
|
|
357
|
-
var
|
|
358
|
-
var
|
|
359
|
-
var
|
|
360
|
-
var
|
|
361
|
-
var
|
|
362
|
-
var
|
|
363
|
-
var
|
|
364
|
-
|
|
365
|
-
return null;
|
|
366
|
-
}
|
|
367
|
-
len = 1 / len;
|
|
368
|
-
x *= len;
|
|
369
|
-
y *= len;
|
|
370
|
-
z *= len;
|
|
371
|
-
s = Math.sin(rad);
|
|
372
|
-
c = Math.cos(rad);
|
|
373
|
-
t = 1 - c;
|
|
374
|
-
a00 = a[0];
|
|
375
|
-
a01 = a[1];
|
|
376
|
-
a02 = a[2];
|
|
377
|
-
a03 = a[3];
|
|
378
|
-
a10 = a[4];
|
|
379
|
-
a11 = a[5];
|
|
380
|
-
a12 = a[6];
|
|
381
|
-
a13 = a[7];
|
|
382
|
-
a20 = a[8];
|
|
383
|
-
a21 = a[9];
|
|
384
|
-
a22 = a[10];
|
|
385
|
-
a23 = a[11];
|
|
386
|
-
b00 = x * x * t + c;
|
|
387
|
-
b01 = y * x * t + z * s;
|
|
388
|
-
b02 = z * x * t - y * s;
|
|
389
|
-
b10 = x * y * t - z * s;
|
|
390
|
-
b11 = y * y * t + c;
|
|
391
|
-
b12 = z * y * t + x * s;
|
|
392
|
-
b20 = x * z * t + y * s;
|
|
393
|
-
b21 = y * z * t - x * s;
|
|
394
|
-
b22 = z * z * t + c;
|
|
395
|
-
out[0] = a00 * b00 + a10 * b01 + a20 * b02;
|
|
396
|
-
out[1] = a01 * b00 + a11 * b01 + a21 * b02;
|
|
397
|
-
out[2] = a02 * b00 + a12 * b01 + a22 * b02;
|
|
398
|
-
out[3] = a03 * b00 + a13 * b01 + a23 * b02;
|
|
399
|
-
out[4] = a00 * b10 + a10 * b11 + a20 * b12;
|
|
400
|
-
out[5] = a01 * b10 + a11 * b11 + a21 * b12;
|
|
401
|
-
out[6] = a02 * b10 + a12 * b11 + a22 * b12;
|
|
402
|
-
out[7] = a03 * b10 + a13 * b11 + a23 * b12;
|
|
403
|
-
out[8] = a00 * b20 + a10 * b21 + a20 * b22;
|
|
404
|
-
out[9] = a01 * b20 + a11 * b21 + a21 * b22;
|
|
405
|
-
out[10] = a02 * b20 + a12 * b21 + a22 * b22;
|
|
406
|
-
out[11] = a03 * b20 + a13 * b21 + a23 * b22;
|
|
364
|
+
function rotateZ(out, a, rad) {
|
|
365
|
+
var s = Math.sin(rad);
|
|
366
|
+
var c = Math.cos(rad);
|
|
367
|
+
var a00 = a[0];
|
|
368
|
+
var a01 = a[1];
|
|
369
|
+
var a02 = a[2];
|
|
370
|
+
var a03 = a[3];
|
|
371
|
+
var a10 = a[4];
|
|
372
|
+
var a11 = a[5];
|
|
373
|
+
var a12 = a[6];
|
|
374
|
+
var a13 = a[7];
|
|
407
375
|
if (a !== out) {
|
|
376
|
+
out[8] = a[8];
|
|
377
|
+
out[9] = a[9];
|
|
378
|
+
out[10] = a[10];
|
|
379
|
+
out[11] = a[11];
|
|
408
380
|
out[12] = a[12];
|
|
409
381
|
out[13] = a[13];
|
|
410
382
|
out[14] = a[14];
|
|
411
383
|
out[15] = a[15];
|
|
412
384
|
}
|
|
385
|
+
out[0] = a00 * c + a10 * s;
|
|
386
|
+
out[1] = a01 * c + a11 * s;
|
|
387
|
+
out[2] = a02 * c + a12 * s;
|
|
388
|
+
out[3] = a03 * c + a13 * s;
|
|
389
|
+
out[4] = a10 * c - a00 * s;
|
|
390
|
+
out[5] = a11 * c - a01 * s;
|
|
391
|
+
out[6] = a12 * c - a02 * s;
|
|
392
|
+
out[7] = a13 * c - a03 * s;
|
|
413
393
|
return out;
|
|
414
394
|
}
|
|
415
395
|
function orthoNO(out, left, right, bottom, top, near, far) {
|
|
@@ -444,12 +424,6 @@ function create$1() {
|
|
|
444
424
|
}
|
|
445
425
|
return out;
|
|
446
426
|
}
|
|
447
|
-
function length(a) {
|
|
448
|
-
var x = a[0];
|
|
449
|
-
var y = a[1];
|
|
450
|
-
var z = a[2];
|
|
451
|
-
return Math.hypot(x, y, z);
|
|
452
|
-
}
|
|
453
427
|
function fromValues$1(x, y, z) {
|
|
454
428
|
var out = new ARRAY_TYPE(3);
|
|
455
429
|
out[0] = x;
|
|
@@ -457,24 +431,12 @@ function fromValues$1(x, y, z) {
|
|
|
457
431
|
out[2] = z;
|
|
458
432
|
return out;
|
|
459
433
|
}
|
|
460
|
-
function add$1(out, a, b) {
|
|
461
|
-
out[0] = a[0] + b[0];
|
|
462
|
-
out[1] = a[1] + b[1];
|
|
463
|
-
out[2] = a[2] + b[2];
|
|
464
|
-
return out;
|
|
465
|
-
}
|
|
466
434
|
function subtract(out, a, b) {
|
|
467
435
|
out[0] = a[0] - b[0];
|
|
468
436
|
out[1] = a[1] - b[1];
|
|
469
437
|
out[2] = a[2] - b[2];
|
|
470
438
|
return out;
|
|
471
439
|
}
|
|
472
|
-
function scale(out, a, b) {
|
|
473
|
-
out[0] = a[0] * b;
|
|
474
|
-
out[1] = a[1] * b;
|
|
475
|
-
out[2] = a[2] * b;
|
|
476
|
-
return out;
|
|
477
|
-
}
|
|
478
440
|
function normalize(out, a) {
|
|
479
441
|
var x = a[0];
|
|
480
442
|
var y = a[1];
|
|
@@ -6481,15 +6443,15 @@ const put_short = (s, w) => {
|
|
|
6481
6443
|
s.pending_buf[s.pending++] = w & 255;
|
|
6482
6444
|
s.pending_buf[s.pending++] = w >>> 8 & 255;
|
|
6483
6445
|
};
|
|
6484
|
-
const send_bits = (s, value,
|
|
6485
|
-
if (s.bi_valid > Buf_size -
|
|
6446
|
+
const send_bits = (s, value, length) => {
|
|
6447
|
+
if (s.bi_valid > Buf_size - length) {
|
|
6486
6448
|
s.bi_buf |= value << s.bi_valid & 65535;
|
|
6487
6449
|
put_short(s, s.bi_buf);
|
|
6488
6450
|
s.bi_buf = value >> Buf_size - s.bi_valid;
|
|
6489
|
-
s.bi_valid +=
|
|
6451
|
+
s.bi_valid += length - Buf_size;
|
|
6490
6452
|
} else {
|
|
6491
6453
|
s.bi_buf |= value << s.bi_valid & 65535;
|
|
6492
|
-
s.bi_valid +=
|
|
6454
|
+
s.bi_valid += length;
|
|
6493
6455
|
}
|
|
6494
6456
|
};
|
|
6495
6457
|
const send_code = (s, c, tree) => {
|
|
@@ -6602,18 +6564,18 @@ const gen_codes = (tree, max_code, bl_count) => {
|
|
|
6602
6564
|
const tr_static_init = () => {
|
|
6603
6565
|
let n;
|
|
6604
6566
|
let bits;
|
|
6605
|
-
let
|
|
6567
|
+
let length;
|
|
6606
6568
|
let code;
|
|
6607
6569
|
let dist;
|
|
6608
6570
|
const bl_count = new Array(MAX_BITS$1 + 1);
|
|
6609
|
-
|
|
6571
|
+
length = 0;
|
|
6610
6572
|
for (code = 0; code < LENGTH_CODES$1 - 1; code++) {
|
|
6611
|
-
base_length[code] =
|
|
6573
|
+
base_length[code] = length;
|
|
6612
6574
|
for (n = 0; n < 1 << extra_lbits[code]; n++) {
|
|
6613
|
-
_length_code[
|
|
6575
|
+
_length_code[length++] = code;
|
|
6614
6576
|
}
|
|
6615
6577
|
}
|
|
6616
|
-
_length_code[
|
|
6578
|
+
_length_code[length - 1] = code;
|
|
6617
6579
|
dist = 0;
|
|
6618
6580
|
for (code = 0; code < 16; code++) {
|
|
6619
6581
|
base_dist[code] = dist;
|
|
@@ -10545,26 +10507,31 @@ NVImage.prototype.calculateRAS = function() {
|
|
|
10545
10507
|
let header = this.hdr;
|
|
10546
10508
|
let absR = fromValues$3(Math.abs(a[0][0]), Math.abs(a[0][1]), Math.abs(a[0][2]), Math.abs(a[1][0]), Math.abs(a[1][1]), Math.abs(a[1][2]), Math.abs(a[2][0]), Math.abs(a[2][1]), Math.abs(a[2][2]));
|
|
10547
10509
|
let ixyz = [1, 1, 1];
|
|
10548
|
-
if (absR[3] > absR[0])
|
|
10510
|
+
if (absR[3] > absR[0]) {
|
|
10549
10511
|
ixyz[0] = 2;
|
|
10550
|
-
|
|
10512
|
+
}
|
|
10513
|
+
if (absR[6] > absR[0] && absR[6] > absR[3]) {
|
|
10551
10514
|
ixyz[0] = 3;
|
|
10515
|
+
}
|
|
10552
10516
|
ixyz[1] = 1;
|
|
10553
10517
|
if (ixyz[0] === 1) {
|
|
10554
|
-
if (absR[4] > absR[7])
|
|
10518
|
+
if (absR[4] > absR[7]) {
|
|
10555
10519
|
ixyz[1] = 2;
|
|
10556
|
-
else
|
|
10520
|
+
} else {
|
|
10557
10521
|
ixyz[1] = 3;
|
|
10522
|
+
}
|
|
10558
10523
|
} else if (ixyz[0] === 2) {
|
|
10559
|
-
if (absR[1] > absR[7])
|
|
10524
|
+
if (absR[1] > absR[7]) {
|
|
10560
10525
|
ixyz[1] = 1;
|
|
10561
|
-
else
|
|
10526
|
+
} else {
|
|
10562
10527
|
ixyz[1] = 3;
|
|
10528
|
+
}
|
|
10563
10529
|
} else {
|
|
10564
|
-
if (absR[1] > absR[4])
|
|
10530
|
+
if (absR[1] > absR[4]) {
|
|
10565
10531
|
ixyz[1] = 1;
|
|
10566
|
-
else
|
|
10532
|
+
} else {
|
|
10567
10533
|
ixyz[1] = 2;
|
|
10534
|
+
}
|
|
10568
10535
|
}
|
|
10569
10536
|
ixyz[2] = 6 - ixyz[1] - ixyz[0];
|
|
10570
10537
|
let perm = [1, 2, 3];
|
|
@@ -10578,16 +10545,21 @@ NVImage.prototype.calculateRAS = function() {
|
|
|
10578
10545
|
this.mm001 = this.vox2mm([-0.5, -0.5, header.dims[3] - 0.5], rotM);
|
|
10579
10546
|
let R2 = create$2();
|
|
10580
10547
|
copy(R2, rotM);
|
|
10581
|
-
for (let i = 0; i < 3; i++)
|
|
10582
|
-
for (let j = 0; j < 3; j++)
|
|
10548
|
+
for (let i = 0; i < 3; i++) {
|
|
10549
|
+
for (let j = 0; j < 3; j++) {
|
|
10583
10550
|
R2[i * 4 + j] = rotM[i * 4 + perm[j] - 1];
|
|
10551
|
+
}
|
|
10552
|
+
}
|
|
10584
10553
|
let flip = [0, 0, 0];
|
|
10585
|
-
if (R2[0] < 0)
|
|
10554
|
+
if (R2[0] < 0) {
|
|
10586
10555
|
flip[0] = 1;
|
|
10587
|
-
|
|
10556
|
+
}
|
|
10557
|
+
if (R2[5] < 0) {
|
|
10588
10558
|
flip[1] = 1;
|
|
10589
|
-
|
|
10559
|
+
}
|
|
10560
|
+
if (R2[10] < 0) {
|
|
10590
10561
|
flip[2] = 1;
|
|
10562
|
+
}
|
|
10591
10563
|
this.dimsRAS = [
|
|
10592
10564
|
header.dims[0],
|
|
10593
10565
|
header.dims[perm[0]],
|
|
@@ -10624,6 +10596,8 @@ NVImage.prototype.calculateRAS = function() {
|
|
|
10624
10596
|
rotM[3 + 1 * 4] = flip[1];
|
|
10625
10597
|
rotM[3 + 2 * 4] = flip[2];
|
|
10626
10598
|
this.toRAS = clone(rotM);
|
|
10599
|
+
console.log(this.hdr.dims);
|
|
10600
|
+
console.log(this.dimsRAS);
|
|
10627
10601
|
};
|
|
10628
10602
|
NVImage.prototype.vox2mm = function(XYZ, mtx) {
|
|
10629
10603
|
let sform = clone(mtx);
|
|
@@ -10887,12 +10861,12 @@ function getExtents(positions) {
|
|
|
10887
10861
|
}
|
|
10888
10862
|
NVImage.prototype.method1 = function() {
|
|
10889
10863
|
return {
|
|
10890
|
-
left: -(this.
|
|
10891
|
-
right: this.
|
|
10892
|
-
posterior: -(this.
|
|
10893
|
-
anterior: this.
|
|
10894
|
-
inferior: -(this.
|
|
10895
|
-
superior: this.
|
|
10864
|
+
left: -(this.dimsRAS[1] / 2) * this.pixDimsRAS[1],
|
|
10865
|
+
right: this.dimsRAS[1] / 2 * this.pixDimsRAS[1],
|
|
10866
|
+
posterior: -(this.dimsRAS[2] / 2) * this.pixDimsRAS[2],
|
|
10867
|
+
anterior: this.dimsRAS[2] / 2 * this.pixDimsRAS[2],
|
|
10868
|
+
inferior: -(this.dimsRAS[3] / 2) * this.pixDimsRAS[3],
|
|
10869
|
+
superior: this.dimsRAS[3] / 2 * this.pixDimsRAS[3]
|
|
10896
10870
|
};
|
|
10897
10871
|
};
|
|
10898
10872
|
NVImage.prototype.method2 = function() {
|
|
@@ -10908,8 +10882,8 @@ NVImage.prototype.method2 = function() {
|
|
|
10908
10882
|
let maxExtent = create();
|
|
10909
10883
|
transformMat4(maxExtent, rightTopFront, affineMatrix);
|
|
10910
10884
|
return {
|
|
10911
|
-
left:
|
|
10912
|
-
right: maxExtent[0] / 2,
|
|
10885
|
+
left: maxExtent[0] / 2,
|
|
10886
|
+
right: 0 - maxExtent[0] / 2,
|
|
10913
10887
|
posterior: 0 - maxExtent[1] / 2,
|
|
10914
10888
|
anterior: maxExtent[1] / 2,
|
|
10915
10889
|
inferior: 0 - maxExtent[2] / 2,
|
|
@@ -10922,83 +10896,83 @@ NVImage.prototype.toNiivueObject3D = function(id, gl) {
|
|
|
10922
10896
|
let cuboid = this.method1();
|
|
10923
10897
|
let left = cuboid.left;
|
|
10924
10898
|
let right = cuboid.right;
|
|
10925
|
-
let
|
|
10926
|
-
let
|
|
10927
|
-
let
|
|
10928
|
-
let
|
|
10899
|
+
let posterior = cuboid.posterior;
|
|
10900
|
+
let anterior = cuboid.anterior;
|
|
10901
|
+
let inferior = cuboid.inferior;
|
|
10902
|
+
let superior = cuboid.superior;
|
|
10929
10903
|
const positions = [
|
|
10930
10904
|
left,
|
|
10931
|
-
|
|
10932
|
-
|
|
10905
|
+
posterior,
|
|
10906
|
+
superior,
|
|
10933
10907
|
right,
|
|
10934
|
-
|
|
10935
|
-
|
|
10908
|
+
posterior,
|
|
10909
|
+
superior,
|
|
10936
10910
|
right,
|
|
10937
|
-
|
|
10938
|
-
|
|
10911
|
+
anterior,
|
|
10912
|
+
superior,
|
|
10939
10913
|
left,
|
|
10940
|
-
|
|
10941
|
-
|
|
10914
|
+
anterior,
|
|
10915
|
+
superior,
|
|
10942
10916
|
left,
|
|
10943
|
-
|
|
10944
|
-
|
|
10917
|
+
posterior,
|
|
10918
|
+
inferior,
|
|
10945
10919
|
left,
|
|
10946
|
-
|
|
10947
|
-
|
|
10920
|
+
anterior,
|
|
10921
|
+
inferior,
|
|
10948
10922
|
right,
|
|
10949
|
-
|
|
10950
|
-
|
|
10923
|
+
anterior,
|
|
10924
|
+
inferior,
|
|
10951
10925
|
right,
|
|
10952
|
-
|
|
10953
|
-
|
|
10926
|
+
posterior,
|
|
10927
|
+
inferior,
|
|
10954
10928
|
left,
|
|
10955
|
-
|
|
10956
|
-
|
|
10929
|
+
anterior,
|
|
10930
|
+
inferior,
|
|
10957
10931
|
left,
|
|
10958
|
-
|
|
10959
|
-
|
|
10932
|
+
anterior,
|
|
10933
|
+
superior,
|
|
10960
10934
|
right,
|
|
10961
|
-
|
|
10962
|
-
|
|
10935
|
+
anterior,
|
|
10936
|
+
superior,
|
|
10963
10937
|
right,
|
|
10964
|
-
|
|
10965
|
-
|
|
10938
|
+
anterior,
|
|
10939
|
+
inferior,
|
|
10966
10940
|
left,
|
|
10967
|
-
|
|
10968
|
-
|
|
10941
|
+
posterior,
|
|
10942
|
+
inferior,
|
|
10969
10943
|
right,
|
|
10970
|
-
|
|
10971
|
-
|
|
10944
|
+
posterior,
|
|
10945
|
+
inferior,
|
|
10972
10946
|
right,
|
|
10973
|
-
|
|
10974
|
-
|
|
10947
|
+
posterior,
|
|
10948
|
+
superior,
|
|
10975
10949
|
left,
|
|
10976
|
-
|
|
10977
|
-
|
|
10950
|
+
posterior,
|
|
10951
|
+
superior,
|
|
10978
10952
|
right,
|
|
10979
|
-
|
|
10980
|
-
|
|
10953
|
+
posterior,
|
|
10954
|
+
inferior,
|
|
10981
10955
|
right,
|
|
10982
|
-
|
|
10983
|
-
|
|
10956
|
+
anterior,
|
|
10957
|
+
inferior,
|
|
10984
10958
|
right,
|
|
10985
|
-
|
|
10986
|
-
|
|
10959
|
+
anterior,
|
|
10960
|
+
superior,
|
|
10987
10961
|
right,
|
|
10988
|
-
|
|
10989
|
-
|
|
10962
|
+
posterior,
|
|
10963
|
+
superior,
|
|
10990
10964
|
left,
|
|
10991
|
-
|
|
10992
|
-
|
|
10965
|
+
posterior,
|
|
10966
|
+
inferior,
|
|
10993
10967
|
left,
|
|
10994
|
-
|
|
10995
|
-
|
|
10968
|
+
posterior,
|
|
10969
|
+
superior,
|
|
10996
10970
|
left,
|
|
10997
|
-
|
|
10998
|
-
|
|
10971
|
+
anterior,
|
|
10972
|
+
superior,
|
|
10999
10973
|
left,
|
|
11000
|
-
|
|
11001
|
-
|
|
10974
|
+
anterior,
|
|
10975
|
+
inferior
|
|
11002
10976
|
];
|
|
11003
10977
|
const textureCoordinates = [
|
|
11004
10978
|
0,
|
|
@@ -12739,8 +12713,8 @@ const Niivue = function(options = {}) {
|
|
|
12739
12713
|
this.sliceTypeRender = 4;
|
|
12740
12714
|
this.sliceType = this.sliceTypeMultiplanar;
|
|
12741
12715
|
this.scene = {};
|
|
12742
|
-
this.scene.renderAzimuth = -
|
|
12743
|
-
this.scene.renderElevation =
|
|
12716
|
+
this.scene.renderAzimuth = -90;
|
|
12717
|
+
this.scene.renderElevation = 90;
|
|
12744
12718
|
this.scene.crosshairPos = [0.5, 0.5, 0.5];
|
|
12745
12719
|
this.scene.clipPlane = [0, 0, 0, 0];
|
|
12746
12720
|
this.scene.mousedown = false;
|
|
@@ -13291,8 +13265,8 @@ Niivue.prototype.setOpacity = function(volIdx, newOpacity) {
|
|
|
13291
13265
|
}
|
|
13292
13266
|
this.updateGLVolume();
|
|
13293
13267
|
};
|
|
13294
|
-
Niivue.prototype.setScale = function(
|
|
13295
|
-
this.volScaleMultiplier =
|
|
13268
|
+
Niivue.prototype.setScale = function(scale) {
|
|
13269
|
+
this.volScaleMultiplier = scale;
|
|
13296
13270
|
this.drawScene();
|
|
13297
13271
|
};
|
|
13298
13272
|
Niivue.prototype.setClipPlaneColor = function(color) {
|
|
@@ -13633,12 +13607,13 @@ Niivue.prototype.refreshLayers = function(overlayItem, layer, numLayers) {
|
|
|
13633
13607
|
let img = overlayItem.img;
|
|
13634
13608
|
let opacity = overlayItem.opacity;
|
|
13635
13609
|
let outTexture = null;
|
|
13636
|
-
let mtx =
|
|
13610
|
+
let mtx = clone(overlayItem.toRAS);
|
|
13637
13611
|
if (layer === 0) {
|
|
13638
13612
|
this.volumeObject3D = overlayItem.toNiivueObject3D(this.VOLUME_ID, this.gl);
|
|
13639
13613
|
this.volumeObject3D.glFlags = this.volumeObject3D.CULL_FACE;
|
|
13640
13614
|
this.objectsToRender3D.splice(0, 1, this.volumeObject3D);
|
|
13641
|
-
mtx
|
|
13615
|
+
invert(mtx, mtx);
|
|
13616
|
+
log.debug(`mtx layer ${layer}`, mtx);
|
|
13642
13617
|
this.back.matRAS = overlayItem.matRAS;
|
|
13643
13618
|
this.back.dims = overlayItem.dimsRAS;
|
|
13644
13619
|
this.back.pixDims = overlayItem.pixDimsRAS;
|
|
@@ -13764,6 +13739,7 @@ Niivue.prototype.refreshLayers = function(overlayItem, layer, numLayers) {
|
|
|
13764
13739
|
this.gl.uniform1f(orientShader.uniforms["scl_slope"], hdr.scl_slope);
|
|
13765
13740
|
this.gl.uniform1f(orientShader.uniforms["opacity"], opacity);
|
|
13766
13741
|
this.gl.uniformMatrix4fv(orientShader.uniforms["mtx"], false, mtx);
|
|
13742
|
+
log.debug("back dims: ", this.back.dims);
|
|
13767
13743
|
for (let i = 0; i < this.back.dims[3]; i++) {
|
|
13768
13744
|
let coordZ = 1 / this.back.dims[3] * (i + 0.5);
|
|
13769
13745
|
this.gl.uniform1f(orientShader.uniforms["coordZ"], coordZ);
|
|
@@ -14001,24 +13977,24 @@ Niivue.prototype.drawColorbar = function(leftTopWidthHeight) {
|
|
|
14001
13977
|
this.gl.texParameteri(this.gl.TEXTURE_2D, this.gl.TEXTURE_MIN_FILTER, this.gl.LINEAR);
|
|
14002
13978
|
this.gl.texParameteri(this.gl.TEXTURE_2D, this.gl.TEXTURE_MAG_FILTER, this.gl.LINEAR);
|
|
14003
13979
|
};
|
|
14004
|
-
Niivue.prototype.textWidth = function(
|
|
13980
|
+
Niivue.prototype.textWidth = function(scale, str) {
|
|
14005
13981
|
let w = 0;
|
|
14006
13982
|
var bytes = new TextEncoder().encode(str);
|
|
14007
13983
|
for (let i = 0; i < str.length; i++)
|
|
14008
|
-
w +=
|
|
13984
|
+
w += scale * this.fontMets[bytes[i]].xadv;
|
|
14009
13985
|
return w;
|
|
14010
13986
|
};
|
|
14011
|
-
Niivue.prototype.drawChar = function(xy,
|
|
13987
|
+
Niivue.prototype.drawChar = function(xy, scale, char) {
|
|
14012
13988
|
let metrics2 = this.fontMets[char];
|
|
14013
|
-
let l = xy[0] +
|
|
14014
|
-
let b = -(
|
|
14015
|
-
let w =
|
|
14016
|
-
let h =
|
|
14017
|
-
let t = xy[1] + (b - h) +
|
|
13989
|
+
let l = xy[0] + scale * metrics2.lbwh[0];
|
|
13990
|
+
let b = -(scale * metrics2.lbwh[1]);
|
|
13991
|
+
let w = scale * metrics2.lbwh[2];
|
|
13992
|
+
let h = scale * metrics2.lbwh[3];
|
|
13993
|
+
let t = xy[1] + (b - h) + scale;
|
|
14018
13994
|
this.gl.uniform4f(this.fontShader.uniforms["leftTopWidthHeight"], l, t, w, h);
|
|
14019
13995
|
this.gl.uniform4fv(this.fontShader.uniforms["uvLeftTopWidthHeight"], metrics2.uv_lbwh);
|
|
14020
13996
|
this.gl.drawArrays(this.gl.TRIANGLE_STRIP, 5, 4);
|
|
14021
|
-
return
|
|
13997
|
+
return scale * metrics2.xadv;
|
|
14022
13998
|
};
|
|
14023
13999
|
Niivue.prototype.drawLoadingText = function(text) {
|
|
14024
14000
|
this.gl.viewport(0, 0, this.gl.canvas.width, this.gl.canvas.height);
|
|
@@ -14029,11 +14005,11 @@ Niivue.prototype.drawLoadingText = function(text) {
|
|
|
14029
14005
|
this.drawTextBelow([this.canvas.width / 2, this.canvas.height / 2], text, 3);
|
|
14030
14006
|
this.canvas.focus();
|
|
14031
14007
|
};
|
|
14032
|
-
Niivue.prototype.drawText = function(xy, str,
|
|
14008
|
+
Niivue.prototype.drawText = function(xy, str, scale = 1) {
|
|
14033
14009
|
if (this.opts.textHeight <= 0)
|
|
14034
14010
|
return;
|
|
14035
14011
|
this.fontShader.use(this.gl);
|
|
14036
|
-
let size = this.opts.textHeight * this.gl.canvas.height *
|
|
14012
|
+
let size = this.opts.textHeight * this.gl.canvas.height * scale;
|
|
14037
14013
|
this.gl.enable(this.gl.BLEND);
|
|
14038
14014
|
this.gl.uniform2f(this.fontShader.uniforms["canvasWidthHeight"], this.gl.canvas.width, this.gl.canvas.height);
|
|
14039
14015
|
this.gl.uniform4fv(this.fontShader.uniforms["fontColor"], this.opts.crosshairColor);
|
|
@@ -14044,18 +14020,18 @@ Niivue.prototype.drawText = function(xy, str, scale2 = 1) {
|
|
|
14044
14020
|
for (let i = 0; i < str.length; i++)
|
|
14045
14021
|
xy[0] += this.drawChar(xy, size, bytes[i]);
|
|
14046
14022
|
};
|
|
14047
|
-
Niivue.prototype.drawTextRight = function(xy, str,
|
|
14023
|
+
Niivue.prototype.drawTextRight = function(xy, str, scale = 1) {
|
|
14048
14024
|
if (this.opts.textHeight <= 0)
|
|
14049
14025
|
return;
|
|
14050
14026
|
xy[1] -= 0.5 * this.opts.textHeight * this.gl.canvas.height;
|
|
14051
|
-
this.drawText(xy, str,
|
|
14027
|
+
this.drawText(xy, str, scale);
|
|
14052
14028
|
};
|
|
14053
|
-
Niivue.prototype.drawTextBelow = function(xy, str,
|
|
14029
|
+
Niivue.prototype.drawTextBelow = function(xy, str, scale = 1) {
|
|
14054
14030
|
if (this.opts.textHeight <= 0)
|
|
14055
14031
|
return;
|
|
14056
|
-
let size = this.opts.textHeight * this.gl.canvas.height *
|
|
14032
|
+
let size = this.opts.textHeight * this.gl.canvas.height * scale;
|
|
14057
14033
|
xy[0] -= 0.5 * this.textWidth(size, str);
|
|
14058
|
-
this.drawText(xy, str,
|
|
14034
|
+
this.drawText(xy, str, scale);
|
|
14059
14035
|
};
|
|
14060
14036
|
Niivue.prototype.draw2D = function(leftTopWidthHeight, axCorSag) {
|
|
14061
14037
|
this.gl.cullFace(this.gl.FRONT);
|
|
@@ -14135,34 +14111,29 @@ Niivue.prototype.draw2D = function(leftTopWidthHeight, axCorSag) {
|
|
|
14135
14111
|
this.sync();
|
|
14136
14112
|
};
|
|
14137
14113
|
Niivue.prototype.calculateMvpMatrix = function(object3D) {
|
|
14138
|
-
|
|
14139
|
-
|
|
14140
|
-
|
|
14141
|
-
|
|
14142
|
-
|
|
14143
|
-
|
|
14144
|
-
|
|
14145
|
-
|
|
14146
|
-
|
|
14147
|
-
|
|
14148
|
-
|
|
14149
|
-
|
|
14150
|
-
|
|
14151
|
-
|
|
14152
|
-
const
|
|
14153
|
-
|
|
14154
|
-
|
|
14155
|
-
|
|
14156
|
-
|
|
14157
|
-
|
|
14158
|
-
|
|
14159
|
-
|
|
14160
|
-
|
|
14161
|
-
this.volScaleMultiplier
|
|
14162
|
-
]);
|
|
14163
|
-
const mvpMatrix = create$2();
|
|
14164
|
-
multiply$1(mvpMatrix, projectionMatrix, modelViewMatrix);
|
|
14165
|
-
return mvpMatrix;
|
|
14114
|
+
function deg2rad(deg) {
|
|
14115
|
+
return deg * (Math.PI / 180);
|
|
14116
|
+
}
|
|
14117
|
+
let whratio = this.gl.canvas.clientWidth / this.gl.canvas.clientHeight;
|
|
14118
|
+
let projectionMatrix = create$2();
|
|
14119
|
+
let dx = Math.max(Math.abs(object3D.extentsMax[0]), Math.abs(object3D.extentsMin[0]));
|
|
14120
|
+
let dy = Math.max(Math.abs(object3D.extentsMax[1]), Math.abs(object3D.extentsMin[1]));
|
|
14121
|
+
let dz = Math.max(Math.abs(object3D.extentsMax[2]), Math.abs(object3D.extentsMin[2]));
|
|
14122
|
+
let furthestVertexFromOrigin = Math.sqrt(dx * dx + dy * dy + dz * dz);
|
|
14123
|
+
let scale = 0.7 * furthestVertexFromOrigin * 1 / this.volScaleMultiplier;
|
|
14124
|
+
if (whratio < 1)
|
|
14125
|
+
ortho(projectionMatrix, -scale, scale, -scale / whratio, scale / whratio, 0.01, scale * 8);
|
|
14126
|
+
else
|
|
14127
|
+
ortho(projectionMatrix, -scale * whratio, scale * whratio, -scale, scale, 0.01, scale * 8);
|
|
14128
|
+
const modelMatrix = create$2();
|
|
14129
|
+
modelMatrix[0] = -1;
|
|
14130
|
+
let translateVec3 = fromValues$1(0, 0, -scale * 1.8);
|
|
14131
|
+
translate(modelMatrix, modelMatrix, translateVec3);
|
|
14132
|
+
rotateX(modelMatrix, modelMatrix, deg2rad(270 - this.scene.renderElevation));
|
|
14133
|
+
rotateZ(modelMatrix, modelMatrix, deg2rad(this.scene.renderAzimuth - 180));
|
|
14134
|
+
let modelViewProjectionMatrix = create$2();
|
|
14135
|
+
multiply$1(modelViewProjectionMatrix, projectionMatrix, modelMatrix);
|
|
14136
|
+
return modelViewProjectionMatrix;
|
|
14166
14137
|
};
|
|
14167
14138
|
Niivue.prototype.calculateRayDirection = function(mvpMatrix) {
|
|
14168
14139
|
var inv = create$2();
|
|
@@ -14260,7 +14231,7 @@ Niivue.prototype.draw3D = function() {
|
|
|
14260
14231
|
if (object3D.glFlags & object3D.CULL_FRONT) {
|
|
14261
14232
|
this.gl.cullFace(this.gl.FRONT);
|
|
14262
14233
|
} else {
|
|
14263
|
-
this.gl.cullFace(this.gl.
|
|
14234
|
+
this.gl.cullFace(this.gl.FRONT);
|
|
14264
14235
|
}
|
|
14265
14236
|
} else {
|
|
14266
14237
|
this.gl.disable(this.gl.CULL_FACE);
|