@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 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.19.1/dist/niivue.umd.js"></script>
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 scale$1(out, a, v) {
335
- var x = v[0], y = v[1], z = v[2];
336
- out[0] = a[0] * x;
337
- out[1] = a[1] * x;
338
- out[2] = a[2] * x;
339
- out[3] = a[3] * x;
340
- out[4] = a[4] * y;
341
- out[5] = a[5] * y;
342
- out[6] = a[6] * y;
343
- out[7] = a[7] * y;
344
- out[8] = a[8] * z;
345
- out[9] = a[9] * z;
346
- out[10] = a[10] * z;
347
- out[11] = a[11] * z;
348
- out[12] = a[12];
349
- out[13] = a[13];
350
- out[14] = a[14];
351
- out[15] = a[15];
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 rotate(out, a, rad, axis) {
355
- var x = axis[0], y = axis[1], z = axis[2];
356
- var len = Math.hypot(x, y, z);
357
- var s, c, t;
358
- var a00, a01, a02, a03;
359
- var a10, a11, a12, a13;
360
- var a20, a21, a22, a23;
361
- var b00, b01, b02;
362
- var b10, b11, b12;
363
- var b20, b21, b22;
364
- if (len < EPSILON) {
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, length2) => {
6485
- if (s.bi_valid > Buf_size - length2) {
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 += length2 - Buf_size;
6451
+ s.bi_valid += length - Buf_size;
6490
6452
  } else {
6491
6453
  s.bi_buf |= value << s.bi_valid & 65535;
6492
- s.bi_valid += length2;
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 length2;
6567
+ let length;
6606
6568
  let code;
6607
6569
  let dist;
6608
6570
  const bl_count = new Array(MAX_BITS$1 + 1);
6609
- length2 = 0;
6571
+ length = 0;
6610
6572
  for (code = 0; code < LENGTH_CODES$1 - 1; code++) {
6611
- base_length[code] = length2;
6573
+ base_length[code] = length;
6612
6574
  for (n = 0; n < 1 << extra_lbits[code]; n++) {
6613
- _length_code[length2++] = code;
6575
+ _length_code[length++] = code;
6614
6576
  }
6615
6577
  }
6616
- _length_code[length2 - 1] = 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
- if (absR[6] > absR[0] && absR[6] > absR[3])
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
- if (R2[5] < 0)
10556
+ }
10557
+ if (R2[5] < 0) {
10588
10558
  flip[1] = 1;
10589
- if (R2[10] < 0)
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.hdr.dims[1] / 2) * this.hdr.pixDims[1],
10891
- right: this.hdr.dims[1] / 2 * this.hdr.pixDims[1],
10892
- posterior: -(this.hdr.dims[3] / 2) * this.hdr.pixDims[3],
10893
- anterior: this.hdr.dims[3] / 2 * this.hdr.pixDims[3],
10894
- inferior: -(this.hdr.dims[2] / 2) * this.hdr.pixDims[2],
10895
- superior: this.hdr.dims[2] / 2 * this.hdr.pixDims[2]
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: 0 - maxExtent[0] / 2,
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 bottom = cuboid.inferior;
10926
- let top = cuboid.superior;
10927
- let front = cuboid.anterior;
10928
- let back = cuboid.posterior;
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
- bottom,
10932
- front,
10905
+ posterior,
10906
+ superior,
10933
10907
  right,
10934
- bottom,
10935
- front,
10908
+ posterior,
10909
+ superior,
10936
10910
  right,
10937
- top,
10938
- front,
10911
+ anterior,
10912
+ superior,
10939
10913
  left,
10940
- top,
10941
- front,
10914
+ anterior,
10915
+ superior,
10942
10916
  left,
10943
- bottom,
10944
- back,
10917
+ posterior,
10918
+ inferior,
10945
10919
  left,
10946
- top,
10947
- back,
10920
+ anterior,
10921
+ inferior,
10948
10922
  right,
10949
- top,
10950
- back,
10923
+ anterior,
10924
+ inferior,
10951
10925
  right,
10952
- bottom,
10953
- back,
10926
+ posterior,
10927
+ inferior,
10954
10928
  left,
10955
- top,
10956
- back,
10929
+ anterior,
10930
+ inferior,
10957
10931
  left,
10958
- top,
10959
- front,
10932
+ anterior,
10933
+ superior,
10960
10934
  right,
10961
- top,
10962
- front,
10935
+ anterior,
10936
+ superior,
10963
10937
  right,
10964
- top,
10965
- back,
10938
+ anterior,
10939
+ inferior,
10966
10940
  left,
10967
- bottom,
10968
- back,
10941
+ posterior,
10942
+ inferior,
10969
10943
  right,
10970
- bottom,
10971
- back,
10944
+ posterior,
10945
+ inferior,
10972
10946
  right,
10973
- bottom,
10974
- front,
10947
+ posterior,
10948
+ superior,
10975
10949
  left,
10976
- bottom,
10977
- front,
10950
+ posterior,
10951
+ superior,
10978
10952
  right,
10979
- bottom,
10980
- back,
10953
+ posterior,
10954
+ inferior,
10981
10955
  right,
10982
- top,
10983
- back,
10956
+ anterior,
10957
+ inferior,
10984
10958
  right,
10985
- top,
10986
- front,
10959
+ anterior,
10960
+ superior,
10987
10961
  right,
10988
- bottom,
10989
- front,
10962
+ posterior,
10963
+ superior,
10990
10964
  left,
10991
- bottom,
10992
- back,
10965
+ posterior,
10966
+ inferior,
10993
10967
  left,
10994
- bottom,
10995
- front,
10968
+ posterior,
10969
+ superior,
10996
10970
  left,
10997
- top,
10998
- front,
10971
+ anterior,
10972
+ superior,
10999
10973
  left,
11000
- top,
11001
- back
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 = -45;
12743
- this.scene.renderElevation = -165;
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(scale2) {
13295
- this.volScaleMultiplier = scale2;
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 = overlayItem.toRAS;
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(scale2, str) {
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 += scale2 * this.fontMets[bytes[i]].xadv;
13984
+ w += scale * this.fontMets[bytes[i]].xadv;
14009
13985
  return w;
14010
13986
  };
14011
- Niivue.prototype.drawChar = function(xy, scale2, char) {
13987
+ Niivue.prototype.drawChar = function(xy, scale, char) {
14012
13988
  let metrics2 = this.fontMets[char];
14013
- let l = xy[0] + scale2 * metrics2.lbwh[0];
14014
- let b = -(scale2 * metrics2.lbwh[1]);
14015
- let w = scale2 * metrics2.lbwh[2];
14016
- let h = scale2 * metrics2.lbwh[3];
14017
- let t = xy[1] + (b - h) + scale2;
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 scale2 * metrics2.xadv;
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, scale2 = 1) {
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 * scale2;
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, scale2 = 1) {
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, scale2);
14027
+ this.drawText(xy, str, scale);
14052
14028
  };
14053
- Niivue.prototype.drawTextBelow = function(xy, str, scale2 = 1) {
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 * scale2;
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, scale2);
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
- const range = create$1();
14139
- subtract(range, object3D.extentsMax, object3D.extentsMin);
14140
- const offset = create$1();
14141
- scale(offset, range, 0.5);
14142
- add$1(offset, object3D.extentsMin, offset);
14143
- scale(offset, offset, -1);
14144
- const radius = length(range);
14145
- const aspect = this.gl.canvas.clientWidth / this.gl.canvas.clientHeight;
14146
- const zNear = 0.1;
14147
- const zFar = radius * 3;
14148
- const halfWorldWidth = this.gl.canvas.clientWidth / 2;
14149
- const ratio = aspect;
14150
- const projectionMatrix = create$2();
14151
- ortho(projectionMatrix, -halfWorldWidth, halfWorldWidth, -halfWorldWidth / ratio, halfWorldWidth / ratio, zNear, zFar);
14152
- const modelViewMatrix = create$2();
14153
- translate(modelViewMatrix, modelViewMatrix, [-0, 0, -radius * 2]);
14154
- var rad = (90 - this.scene.renderElevation) * Math.PI / 180;
14155
- rotate(modelViewMatrix, modelViewMatrix, rad, [1, 0, 0]);
14156
- rad = this.scene.renderAzimuth * Math.PI / 180;
14157
- rotate(modelViewMatrix, modelViewMatrix, rad, [0, 0, -1]);
14158
- scale$1(modelViewMatrix, modelViewMatrix, [
14159
- this.volScaleMultiplier,
14160
- this.volScaleMultiplier,
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.BACK);
14234
+ this.gl.cullFace(this.gl.FRONT);
14264
14235
  }
14265
14236
  } else {
14266
14237
  this.gl.disable(this.gl.CULL_FACE);