@niivue/niivue 0.26.2 → 0.26.3

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/dist/niivue.es.js CHANGED
@@ -364,26 +364,6 @@ function translate(out, a, v) {
364
364
  }
365
365
  return out;
366
366
  }
367
- function scale$1(out, a, v) {
368
- var x2 = v[0], y = v[1], z = v[2];
369
- out[0] = a[0] * x2;
370
- out[1] = a[1] * x2;
371
- out[2] = a[2] * x2;
372
- out[3] = a[3] * x2;
373
- out[4] = a[4] * y;
374
- out[5] = a[5] * y;
375
- out[6] = a[6] * y;
376
- out[7] = a[7] * y;
377
- out[8] = a[8] * z;
378
- out[9] = a[9] * z;
379
- out[10] = a[10] * z;
380
- out[11] = a[11] * z;
381
- out[12] = a[12];
382
- out[13] = a[13];
383
- out[14] = a[14];
384
- out[15] = a[15];
385
- return out;
386
- }
387
367
  function rotateX(out, a, rad) {
388
368
  var s = Math.sin(rad);
389
369
  var c2 = Math.cos(rad);
@@ -767,20 +747,7 @@ vec4 applyClip (vec3 dir, inout vec4 samplePos, inout float len, inout bool isCl
767
747
  samplePos = vec4(samplePos.xyz+dir * disBackFace, disBackFace);
768
748
  }
769
749
  return samplePos;
770
- }
771
- float frac2ndc(vec3 frac) {
772
- //https://stackoverflow.com/questions/7777913/how-to-render-depth-linearly-in-modern-opengl-with-gl-fragcoord-z-in-fragment-sh
773
- vec4 pos = vec4(frac.xyz, 1.0); //fraction
774
- vec4 dim = vec4(vec3(textureSize(volume, 0)), 1.0);
775
- pos = pos * dim;
776
- vec4 shim = vec4(-0.5, -0.5, -0.5, 0.0);
777
- pos += shim;
778
- vec4 mm = transpose(matRAS) * pos;
779
- float z_ndc = (mvpMtx * vec4(mm.xyz, 1.0)).z;
780
- return (z_ndc + 1.0) / 2.0;
781
-
782
- }
783
- `;
750
+ }`;
784
751
  var fragRenderShader = `#version 300 es
785
752
  #line 14
786
753
  precision highp int;
@@ -798,7 +765,20 @@ uniform mat4 matRAS;
798
765
  uniform vec4 clipPlaneColor;
799
766
  in vec3 vColor;
800
767
  out vec4 fColor;
801
- ` + kRenderFunc + `void main() {
768
+ ` + kRenderFunc + `
769
+ float frac2ndc(vec3 frac) {
770
+ //https://stackoverflow.com/questions/7777913/how-to-render-depth-linearly-in-modern-opengl-with-gl-fragcoord-z-in-fragment-sh
771
+ vec4 pos = vec4(frac.xyz, 1.0); //fraction
772
+ vec4 dim = vec4(vec3(textureSize(volume, 0)), 1.0);
773
+ pos = pos * dim;
774
+ vec4 shim = vec4(-0.5, -0.5, -0.5, 0.0);
775
+ pos += shim;
776
+ vec4 mm = transpose(matRAS) * pos;
777
+ float z_ndc = (mvpMtx * vec4(mm.xyz, 1.0)).z;
778
+ return (z_ndc + 1.0) / 2.0;
779
+
780
+ }
781
+ void main() {
802
782
  if (fColor.x > 2.0) {
803
783
  fColor = vec4(1.0, 0.0, 0.0, 0.5);
804
784
  return;
@@ -1549,6 +1529,7 @@ precision highp float;
1549
1529
  uniform float opacity;
1550
1530
  out vec4 color;
1551
1531
  vec4 packFloatToVec4i(const float value) {
1532
+ //this Papaya function uses BSD 3-clause license Copyright (c) 2012-2015, RII-UTHSCSA
1552
1533
  const vec4 bitSh = vec4(256.0*256.0*256.0, 256.0*256.0, 256.0, 1.0);
1553
1534
  const vec4 bitMsk = vec4(0.0, 1.0/256.0, 1.0/256.0, 1.0/256.0);
1554
1535
  vec4 res = fract(value * bitSh);
@@ -1753,6 +1734,15 @@ void main() {
1753
1734
  vec3 d = vClr.rgb * diffuse * SH(-reflect(n, vec3(l.x, l.y, -l.z)) );
1754
1735
  color = vec4(a + d + s, opacity);
1755
1736
  }`;
1737
+ var fragDepthPickingShader = `#version 300 es
1738
+ precision highp int;
1739
+ precision highp float;
1740
+ uniform int id;
1741
+ in vec3 vColor;
1742
+ out vec4 color;
1743
+ void main() {
1744
+ color = vec4(vColor, float(id & 255) / 255.0);
1745
+ }`;
1756
1746
  var fragVolumePickingShader = `#version 300 es
1757
1747
  #line 506
1758
1748
  //precision highp int;
@@ -1763,15 +1753,12 @@ uniform vec3 texVox;
1763
1753
  uniform vec4 clipPlane;
1764
1754
  uniform highp sampler3D volume, overlay;
1765
1755
  uniform float overlays;
1766
- uniform mat4 matRAS;
1767
- uniform mat4 mvpMtx;
1756
+ uniform int id;
1768
1757
  in vec3 vColor;
1769
1758
  out vec4 fColor;
1770
1759
  ` + kRenderFunc + `
1771
1760
  void main() {
1772
- int id = 254;
1773
1761
  vec3 start = vColor;
1774
- gl_FragDepth = 0.0;
1775
1762
  fColor = vec4(0.0, 0.0, 0.0, 0.0); //assume no hit: ID = 0
1776
1763
  float fid = float(id & 255)/ 255.0;
1777
1764
  vec3 backPosition = GetBackPosition(start);
@@ -1795,7 +1782,6 @@ void main() {
1795
1782
  float val = texture(volume, samplePos.xyz).a;
1796
1783
  if (val > 0.01) {
1797
1784
  fColor = vec4(samplePos.rgb, fid);
1798
- gl_FragDepth = frac2ndc(samplePos.xyz);
1799
1785
  break;
1800
1786
  }
1801
1787
  samplePos += deltaDirFast; //advance ray position
@@ -1812,7 +1798,6 @@ void main() {
1812
1798
  float val = texture(overlay, samplePos.xyz).a;
1813
1799
  if (val > 0.01) {
1814
1800
  fColor = vec4(samplePos.rgb, fid);
1815
- gl_FragDepth = frac2ndc(samplePos.xyz);
1816
1801
  return;
1817
1802
  }
1818
1803
  samplePos += deltaDirFast; //advance ray position
@@ -1820,34 +1805,6 @@ void main() {
1820
1805
  //if (fColor.a == 0.0) discard; //no hit in either background or overlays
1821
1806
  //you only get here if there is a hit with the background that is closer than any overlay
1822
1807
  }`;
1823
- var vertOrientCubeShader = `#version 300 es
1824
- // an attribute is an input (in) to a vertex shader.
1825
- // It will receive data from a buffer
1826
- layout(location=0) in vec3 a_position;
1827
- layout(location=1) in vec3 a_color;
1828
- // A matrix to transform the positions by
1829
- uniform mat4 u_matrix;
1830
- out vec3 vColor;
1831
- // all shaders have a main function
1832
- void main() {
1833
- // Multiply the position by the matrix.
1834
- vec4 pos = vec4(a_position, 1.0);
1835
- gl_Position = u_matrix * vec4(pos);
1836
- vColor = a_color;
1837
- }
1838
- `;
1839
- var fragOrientCubeShader = `#version 300 es
1840
- precision highp float;
1841
-
1842
- uniform vec4 u_color;
1843
- in vec3 vColor;
1844
- // we need to declare an output for the fragment shader
1845
- out vec4 outColor;
1846
-
1847
- void main() {
1848
- outColor = vec4(vColor, 1.0);
1849
- }
1850
- `;
1851
1808
  /*! *****************************************************************************
1852
1809
  Copyright (c) Microsoft Corporation.
1853
1810
 
@@ -2887,1016 +2844,6 @@ function interval(period, scheduler) {
2887
2844
  }
2888
2845
  return timer(period, period, scheduler);
2889
2846
  }
2890
- const orientCube = new Float32Array([
2891
- -1,
2892
- -1,
2893
- -1,
2894
- 0.28,
2895
- 0.28,
2896
- 0.28,
2897
- -1,
2898
- -1,
2899
- -1,
2900
- 0.28,
2901
- 0.28,
2902
- 0.28,
2903
- -1,
2904
- 1,
2905
- -1,
2906
- 0.28,
2907
- 0.28,
2908
- 0.28,
2909
- 1,
2910
- -1,
2911
- -1,
2912
- 0.28,
2913
- 0.28,
2914
- 0.28,
2915
- 1,
2916
- 1,
2917
- -1,
2918
- 0.28,
2919
- 0.28,
2920
- 0.28,
2921
- 1,
2922
- 1,
2923
- -1,
2924
- 0.28,
2925
- 0.28,
2926
- 0.28,
2927
- -1,
2928
- -1,
2929
- 1,
2930
- 0.8,
2931
- 0.8,
2932
- 0.8,
2933
- -1,
2934
- -1,
2935
- 1,
2936
- 0.8,
2937
- 0.8,
2938
- 0.8,
2939
- 1,
2940
- -1,
2941
- 1,
2942
- 0.8,
2943
- 0.8,
2944
- 0.8,
2945
- -1,
2946
- 1,
2947
- 1,
2948
- 0.8,
2949
- 0.8,
2950
- 0.8,
2951
- 1,
2952
- 1,
2953
- 1,
2954
- 0.8,
2955
- 0.8,
2956
- 0.8,
2957
- 1,
2958
- 1,
2959
- 1,
2960
- 0.8,
2961
- 0.8,
2962
- 0.8,
2963
- -1,
2964
- 1,
2965
- -1,
2966
- 0,
2967
- 0,
2968
- 0.74,
2969
- -1,
2970
- 1,
2971
- -1,
2972
- 0,
2973
- 0,
2974
- 0.74,
2975
- -1,
2976
- 1,
2977
- 1,
2978
- 0,
2979
- 0,
2980
- 0.74,
2981
- 1,
2982
- 1,
2983
- -1,
2984
- 0,
2985
- 0,
2986
- 0.74,
2987
- 1,
2988
- 1,
2989
- 1,
2990
- 0,
2991
- 0,
2992
- 0.74,
2993
- 1,
2994
- 1,
2995
- 1,
2996
- 0,
2997
- 0,
2998
- 0.74,
2999
- -1,
3000
- -1,
3001
- -1,
3002
- 0.42,
3003
- 0,
3004
- 0.42,
3005
- -1,
3006
- -1,
3007
- -1,
3008
- 0.42,
3009
- 0,
3010
- 0.42,
3011
- 1,
3012
- -1,
3013
- -1,
3014
- 0.42,
3015
- 0,
3016
- 0.42,
3017
- -1,
3018
- -1,
3019
- 1,
3020
- 0.42,
3021
- 0,
3022
- 0.42,
3023
- 1,
3024
- -1,
3025
- 1,
3026
- 0.42,
3027
- 0,
3028
- 0.42,
3029
- 1,
3030
- -1,
3031
- 1,
3032
- 0.42,
3033
- 0,
3034
- 0.42,
3035
- -1,
3036
- -1,
3037
- -1,
3038
- 0.64,
3039
- 0,
3040
- 0,
3041
- -1,
3042
- -1,
3043
- -1,
3044
- 0.64,
3045
- 0,
3046
- 0,
3047
- -1,
3048
- -1,
3049
- 1,
3050
- 0.64,
3051
- 0,
3052
- 0,
3053
- -1,
3054
- 1,
3055
- -1,
3056
- 0.64,
3057
- 0,
3058
- 0,
3059
- -1,
3060
- 1,
3061
- 1,
3062
- 0.64,
3063
- 0,
3064
- 0,
3065
- -1,
3066
- 1,
3067
- 1,
3068
- 0.64,
3069
- 0,
3070
- 0,
3071
- 1,
3072
- -1,
3073
- -1,
3074
- 0,
3075
- 0.5,
3076
- 0,
3077
- 1,
3078
- -1,
3079
- -1,
3080
- 0,
3081
- 0.5,
3082
- 0,
3083
- 1,
3084
- 1,
3085
- -1,
3086
- 0,
3087
- 0.5,
3088
- 0,
3089
- 1,
3090
- -1,
3091
- 1,
3092
- 0,
3093
- 0.5,
3094
- 0,
3095
- 1,
3096
- 1,
3097
- 1,
3098
- 0,
3099
- 0.5,
3100
- 0,
3101
- 1,
3102
- 1,
3103
- 1,
3104
- 0,
3105
- 0.5,
3106
- 0,
3107
- -0.45,
3108
- 1,
3109
- -0.8,
3110
- 0,
3111
- 0,
3112
- 0,
3113
- -0.45,
3114
- 1,
3115
- -0.8,
3116
- 0,
3117
- 0,
3118
- 0,
3119
- -0.45,
3120
- 1,
3121
- 0.8,
3122
- 0,
3123
- 0,
3124
- 0,
3125
- -0.25,
3126
- 1,
3127
- -0.8,
3128
- 0,
3129
- 0,
3130
- 0,
3131
- -0.25,
3132
- 1,
3133
- 0.8,
3134
- 0,
3135
- 0,
3136
- 0,
3137
- -0.25,
3138
- 1,
3139
- 0.8,
3140
- 0,
3141
- 0,
3142
- 0,
3143
- -0.25,
3144
- 1,
3145
- 0.6,
3146
- 0,
3147
- 0,
3148
- 0,
3149
- -0.25,
3150
- 1,
3151
- 0.6,
3152
- 0,
3153
- 0,
3154
- 0,
3155
- -0.25,
3156
- 1,
3157
- 0.8,
3158
- 0,
3159
- 0,
3160
- 0,
3161
- 0.45,
3162
- 1,
3163
- 0.6,
3164
- 0,
3165
- 0,
3166
- 0,
3167
- 0.25,
3168
- 1,
3169
- 0.8,
3170
- 0,
3171
- 0,
3172
- 0,
3173
- 0.25,
3174
- 1,
3175
- 0.8,
3176
- 0,
3177
- 0,
3178
- 0,
3179
- 0.25,
3180
- 1,
3181
- 0.1,
3182
- 0,
3183
- 0,
3184
- 0,
3185
- 0.25,
3186
- 1,
3187
- 0.1,
3188
- 0,
3189
- 0,
3190
- 0,
3191
- 0.25,
3192
- 1,
3193
- 0.6,
3194
- 0,
3195
- 0,
3196
- 0,
3197
- 0.45,
3198
- 1,
3199
- 0.1,
3200
- 0,
3201
- 0,
3202
- 0,
3203
- 0.45,
3204
- 1,
3205
- 0.6,
3206
- 0,
3207
- 0,
3208
- 0,
3209
- 0.45,
3210
- 1,
3211
- 0.6,
3212
- 0,
3213
- 0,
3214
- 0,
3215
- -0.25,
3216
- 1,
3217
- -0.1,
3218
- 0,
3219
- 0,
3220
- 0,
3221
- -0.25,
3222
- 1,
3223
- -0.1,
3224
- 0,
3225
- 0,
3226
- 0,
3227
- -0.25,
3228
- 1,
3229
- 0.1,
3230
- 0,
3231
- 0,
3232
- 0,
3233
- 0.25,
3234
- 1,
3235
- -0.1,
3236
- 0,
3237
- 0,
3238
- 0,
3239
- 0.45,
3240
- 1,
3241
- 0.1,
3242
- 0,
3243
- 0,
3244
- 0,
3245
- 0.45,
3246
- 1,
3247
- 0.1,
3248
- 0,
3249
- 0,
3250
- 0,
3251
- 0.45,
3252
- -1,
3253
- -0.8,
3254
- 0,
3255
- 0,
3256
- 0,
3257
- 0.45,
3258
- -1,
3259
- -0.8,
3260
- 0,
3261
- 0,
3262
- 0,
3263
- 0.05,
3264
- -1,
3265
- 0.8,
3266
- 0,
3267
- 0,
3268
- 0,
3269
- 0.25,
3270
- -1,
3271
- -0.8,
3272
- 0,
3273
- 0,
3274
- 0,
3275
- -0.15,
3276
- -1,
3277
- 0.8,
3278
- 0,
3279
- 0,
3280
- 0,
3281
- -0.15,
3282
- -1,
3283
- 0.8,
3284
- 0,
3285
- 0,
3286
- 0,
3287
- -0.25,
3288
- -1,
3289
- -0.8,
3290
- 0,
3291
- 0,
3292
- 0,
3293
- -0.25,
3294
- -1,
3295
- -0.8,
3296
- 0,
3297
- 0,
3298
- 0,
3299
- 0.05,
3300
- -1,
3301
- 0.8,
3302
- 0,
3303
- 0,
3304
- 0,
3305
- -0.45,
3306
- -1,
3307
- -0.8,
3308
- 0,
3309
- 0,
3310
- 0,
3311
- -0.15,
3312
- -1,
3313
- 0.8,
3314
- 0,
3315
- 0,
3316
- 0,
3317
- -0.15,
3318
- -1,
3319
- 0.8,
3320
- 0,
3321
- 0,
3322
- 0,
3323
- 0.13,
3324
- -1,
3325
- -0.3,
3326
- 0,
3327
- 0,
3328
- 0,
3329
- 0.13,
3330
- -1,
3331
- -0.3,
3332
- 0,
3333
- 0,
3334
- 0,
3335
- 0.07,
3336
- -1,
3337
- -0.1,
3338
- 0,
3339
- 0,
3340
- 0,
3341
- -0.33,
3342
- -1,
3343
- -0.3,
3344
- 0,
3345
- 0,
3346
- 0,
3347
- -0.27,
3348
- -1,
3349
- -0.1,
3350
- 0,
3351
- 0,
3352
- 0,
3353
- -0.27,
3354
- -1,
3355
- -0.1,
3356
- 0,
3357
- 0,
3358
- 0,
3359
- -0.45,
3360
- 0.6,
3361
- 1,
3362
- 0,
3363
- 0,
3364
- 0,
3365
- -0.45,
3366
- 0.6,
3367
- 1,
3368
- 0,
3369
- 0,
3370
- 0,
3371
- -0.45,
3372
- 0.4,
3373
- 1,
3374
- 0,
3375
- 0,
3376
- 0,
3377
- -0.25,
3378
- 0.8,
3379
- 1,
3380
- 0,
3381
- 0,
3382
- 0,
3383
- -0.25,
3384
- 0.4,
3385
- 1,
3386
- 0,
3387
- 0,
3388
- 0,
3389
- -0.25,
3390
- 0.4,
3391
- 1,
3392
- 0,
3393
- 0,
3394
- 0,
3395
- -0.25,
3396
- 0.8,
3397
- 1,
3398
- 0,
3399
- 0,
3400
- 0,
3401
- -0.25,
3402
- 0.8,
3403
- 1,
3404
- 0,
3405
- 0,
3406
- 0,
3407
- -0.25,
3408
- 0.6,
3409
- 1,
3410
- 0,
3411
- 0,
3412
- 0,
3413
- 0.25,
3414
- 0.8,
3415
- 1,
3416
- 0,
3417
- 0,
3418
- 0,
3419
- 0.45,
3420
- 0.6,
3421
- 1,
3422
- 0,
3423
- 0,
3424
- 0,
3425
- 0.45,
3426
- 0.6,
3427
- 1,
3428
- 0,
3429
- 0,
3430
- 0,
3431
- 0.25,
3432
- 0.8,
3433
- 1,
3434
- 0,
3435
- 0,
3436
- 0,
3437
- 0.25,
3438
- 0.8,
3439
- 1,
3440
- 0,
3441
- 0,
3442
- 0,
3443
- 0.25,
3444
- -0.1,
3445
- 1,
3446
- 0,
3447
- 0,
3448
- 0,
3449
- 0.45,
3450
- 0.6,
3451
- 1,
3452
- 0,
3453
- 0,
3454
- 0,
3455
- 0.45,
3456
- 0.1,
3457
- 1,
3458
- 0,
3459
- 0,
3460
- 0,
3461
- 0.45,
3462
- 0.1,
3463
- 1,
3464
- 0,
3465
- 0,
3466
- 0,
3467
- -0.25,
3468
- 0.1,
3469
- 1,
3470
- 0,
3471
- 0,
3472
- 0,
3473
- -0.25,
3474
- 0.1,
3475
- 1,
3476
- 0,
3477
- 0,
3478
- 0,
3479
- -0.45,
3480
- -0.1,
3481
- 1,
3482
- 0,
3483
- 0,
3484
- 0,
3485
- 0.25,
3486
- 0.1,
3487
- 1,
3488
- 0,
3489
- 0,
3490
- 0,
3491
- 0.25,
3492
- -0.1,
3493
- 1,
3494
- 0,
3495
- 0,
3496
- 0,
3497
- 0.25,
3498
- -0.1,
3499
- 1,
3500
- 0,
3501
- 0,
3502
- 0,
3503
- -0.45,
3504
- -0.1,
3505
- 1,
3506
- 0,
3507
- 0,
3508
- 0,
3509
- -0.45,
3510
- -0.1,
3511
- 1,
3512
- 0,
3513
- 0,
3514
- 0,
3515
- -0.45,
3516
- -0.6,
3517
- 1,
3518
- 0,
3519
- 0,
3520
- 0,
3521
- -0.25,
3522
- -0.1,
3523
- 1,
3524
- 0,
3525
- 0,
3526
- 0,
3527
- -0.25,
3528
- -0.8,
3529
- 1,
3530
- 0,
3531
- 0,
3532
- 0,
3533
- -0.25,
3534
- -0.8,
3535
- 1,
3536
- 0,
3537
- 0,
3538
- 0,
3539
- -0.25,
3540
- -0.6,
3541
- 1,
3542
- 0,
3543
- 0,
3544
- 0,
3545
- -0.25,
3546
- -0.6,
3547
- 1,
3548
- 0,
3549
- 0,
3550
- 0,
3551
- -0.25,
3552
- -0.8,
3553
- 1,
3554
- 0,
3555
- 0,
3556
- 0,
3557
- 0.45,
3558
- -0.6,
3559
- 1,
3560
- 0,
3561
- 0,
3562
- 0,
3563
- 0.25,
3564
- -0.8,
3565
- 1,
3566
- 0,
3567
- 0,
3568
- 0,
3569
- 0.25,
3570
- -0.8,
3571
- 1,
3572
- 0,
3573
- 0,
3574
- 0,
3575
- 0.25,
3576
- -0.4,
3577
- 1,
3578
- 0,
3579
- 0,
3580
- 0,
3581
- 0.25,
3582
- -0.4,
3583
- 1,
3584
- 0,
3585
- 0,
3586
- 0,
3587
- 0.25,
3588
- -0.6,
3589
- 1,
3590
- 0,
3591
- 0,
3592
- 0,
3593
- 0.45,
3594
- -0.4,
3595
- 1,
3596
- 0,
3597
- 0,
3598
- 0,
3599
- 0.45,
3600
- -0.6,
3601
- 1,
3602
- 0,
3603
- 0,
3604
- 0,
3605
- 0.45,
3606
- -0.6,
3607
- 1,
3608
- 0,
3609
- 0,
3610
- 0,
3611
- -0.1,
3612
- -0.8,
3613
- -1,
3614
- 0,
3615
- 0,
3616
- 0,
3617
- -0.1,
3618
- -0.8,
3619
- -1,
3620
- 0,
3621
- 0,
3622
- 0,
3623
- -0.1,
3624
- 0.8,
3625
- -1,
3626
- 0,
3627
- 0,
3628
- 0,
3629
- 0.1,
3630
- -0.8,
3631
- -1,
3632
- 0,
3633
- 0,
3634
- 0,
3635
- 0.1,
3636
- 0.8,
3637
- -1,
3638
- 0,
3639
- 0,
3640
- 0,
3641
- 0.1,
3642
- 0.8,
3643
- -1,
3644
- 0,
3645
- 0,
3646
- 0,
3647
- -1,
3648
- -0.45,
3649
- -0.8,
3650
- 0,
3651
- 0,
3652
- 0,
3653
- -1,
3654
- -0.45,
3655
- -0.8,
3656
- 0,
3657
- 0,
3658
- 0,
3659
- -1,
3660
- -0.45,
3661
- 0.8,
3662
- 0,
3663
- 0,
3664
- 0,
3665
- -1,
3666
- -0.25,
3667
- -0.8,
3668
- 0,
3669
- 0,
3670
- 0,
3671
- -1,
3672
- -0.25,
3673
- 0.8,
3674
- 0,
3675
- 0,
3676
- 0,
3677
- -1,
3678
- -0.25,
3679
- 0.8,
3680
- 0,
3681
- 0,
3682
- 0,
3683
- -1,
3684
- -0.25,
3685
- -0.8,
3686
- 0,
3687
- 0,
3688
- 0,
3689
- -1,
3690
- -0.25,
3691
- -0.8,
3692
- 0,
3693
- 0,
3694
- 0,
3695
- -1,
3696
- -0.25,
3697
- -0.6,
3698
- 0,
3699
- 0,
3700
- 0,
3701
- -1,
3702
- 0.45,
3703
- -0.8,
3704
- 0,
3705
- 0,
3706
- 0,
3707
- -1,
3708
- 0.45,
3709
- -0.6,
3710
- 0,
3711
- 0,
3712
- 0,
3713
- -1,
3714
- 0.45,
3715
- -0.6,
3716
- 0,
3717
- 0,
3718
- 0,
3719
- 1,
3720
- 0.45,
3721
- -0.8,
3722
- 0,
3723
- 0,
3724
- 0,
3725
- 1,
3726
- 0.45,
3727
- -0.8,
3728
- 0,
3729
- 0,
3730
- 0,
3731
- 1,
3732
- 0.45,
3733
- 0.8,
3734
- 0,
3735
- 0,
3736
- 0,
3737
- 1,
3738
- 0.25,
3739
- -0.8,
3740
- 0,
3741
- 0,
3742
- 0,
3743
- 1,
3744
- 0.25,
3745
- 0.8,
3746
- 0,
3747
- 0,
3748
- 0,
3749
- 1,
3750
- 0.25,
3751
- 0.8,
3752
- 0,
3753
- 0,
3754
- 0,
3755
- 1,
3756
- 0.25,
3757
- 0.6,
3758
- 0,
3759
- 0,
3760
- 0,
3761
- 1,
3762
- 0.25,
3763
- 0.6,
3764
- 0,
3765
- 0,
3766
- 0,
3767
- 1,
3768
- 0.25,
3769
- 0.8,
3770
- 0,
3771
- 0,
3772
- 0,
3773
- 1,
3774
- -0.45,
3775
- 0.6,
3776
- 0,
3777
- 0,
3778
- 0,
3779
- 1,
3780
- -0.25,
3781
- 0.8,
3782
- 0,
3783
- 0,
3784
- 0,
3785
- 1,
3786
- -0.25,
3787
- 0.8,
3788
- 0,
3789
- 0,
3790
- 0,
3791
- 1,
3792
- -0.25,
3793
- 0.1,
3794
- 0,
3795
- 0,
3796
- 0,
3797
- 1,
3798
- -0.25,
3799
- 0.1,
3800
- 0,
3801
- 0,
3802
- 0,
3803
- 1,
3804
- -0.25,
3805
- 0.6,
3806
- 0,
3807
- 0,
3808
- 0,
3809
- 1,
3810
- -0.45,
3811
- 0.1,
3812
- 0,
3813
- 0,
3814
- 0,
3815
- 1,
3816
- -0.45,
3817
- 0.6,
3818
- 0,
3819
- 0,
3820
- 0,
3821
- 1,
3822
- -0.45,
3823
- 0.6,
3824
- 0,
3825
- 0,
3826
- 0,
3827
- 1,
3828
- 0.25,
3829
- -0.1,
3830
- 0,
3831
- 0,
3832
- 0,
3833
- 1,
3834
- 0.25,
3835
- -0.1,
3836
- 0,
3837
- 0,
3838
- 0,
3839
- 1,
3840
- 0.25,
3841
- 0.1,
3842
- 0,
3843
- 0,
3844
- 0,
3845
- 1,
3846
- -0.25,
3847
- -0.1,
3848
- 0,
3849
- 0,
3850
- 0,
3851
- 1,
3852
- -0.45,
3853
- 0.1,
3854
- 0,
3855
- 0,
3856
- 0,
3857
- 1,
3858
- -0.45,
3859
- 0.1,
3860
- 0,
3861
- 0,
3862
- 0,
3863
- 1,
3864
- -0.25,
3865
- -0.8,
3866
- 0,
3867
- 0,
3868
- 0,
3869
- 1,
3870
- -0.25,
3871
- -0.8,
3872
- 0,
3873
- 0,
3874
- 0,
3875
- 1,
3876
- -0.05,
3877
- -0.1,
3878
- 0,
3879
- 0,
3880
- 0,
3881
- 1,
3882
- -0.45,
3883
- -0.8,
3884
- 0,
3885
- 0,
3886
- 0,
3887
- 1,
3888
- -0.25,
3889
- -0.1,
3890
- 0,
3891
- 0,
3892
- 0,
3893
- 1,
3894
- -0.25,
3895
- -0.1,
3896
- 0,
3897
- 0,
3898
- 0
3899
- ]);
3900
2847
  var NiivueObject3D = function(id, vertexBuffer, mode, indexCount, indexBuffer = null, vao = null) {
3901
2848
  this.BLEND = 1;
3902
2849
  this.CULL_FACE = 2;
@@ -111486,12 +110433,9 @@ function Niivue(options = {}) {
111486
110433
  isAtlasOutline: false,
111487
110434
  isRuler: false,
111488
110435
  isColorbar: false,
111489
- isOrientCube: false,
111490
- multiplanarPadPixels: 0,
111491
110436
  isRadiologicalConvention: false,
111492
110437
  meshThicknessOn2D: Infinity,
111493
110438
  isDragShowsMeasurementTool: false,
111494
- isDepthPickMesh: false,
111495
110439
  isCornerOrientationText: false,
111496
110440
  sagittalNoseLeft: false,
111497
110441
  isSliceMM: false,
@@ -111501,7 +110445,13 @@ function Niivue(options = {}) {
111501
110445
  drawingEnabled: false,
111502
110446
  penValue: 1,
111503
110447
  isFilledPen: false,
111504
- thumbnail: ""
110448
+ thumbnail: "",
110449
+ onLocationChange: () => {
110450
+ },
110451
+ onIntensityChange: () => {
110452
+ },
110453
+ onImageLoaded: () => {
110454
+ }
111505
110455
  };
111506
110456
  this.canvas = null;
111507
110457
  this.gl = null;
@@ -111522,13 +110472,10 @@ function Niivue(options = {}) {
111522
110472
  this.overlayTextureID = [];
111523
110473
  this.sliceShader = null;
111524
110474
  this.sliceMMShader = null;
111525
- this.orientCubeShader = null;
111526
- this.orientCubeShaderVAO = null;
111527
110475
  this.rectShader = null;
111528
110476
  this.graphShader = null;
111529
110477
  this.renderShader = null;
111530
- this.pickingMeshShader = null;
111531
- this.pickingImageShader = null;
110478
+ this.pickingShader = null;
111532
110479
  this.colorbarShader = null;
111533
110480
  this.fontShader = null;
111534
110481
  this.fontTexture = null;
@@ -111548,6 +110495,7 @@ function Niivue(options = {}) {
111548
110495
  this.genericVAO = null;
111549
110496
  this.unusedVAO = null;
111550
110497
  this.crosshairs3D = null;
110498
+ this.pickingSurfaceShader = null;
111551
110499
  this.DEFAULT_FONT_GLYPH_SHEET = defaultFontPNG;
111552
110500
  this.DEFAULT_FONT_METRICS = defaultFontMetrics;
111553
110501
  this.fontMets = null;
@@ -111601,10 +110549,7 @@ function Niivue(options = {}) {
111601
110549
  this.volumeObject3D = null;
111602
110550
  this.pivot3D = [0, 0, 0];
111603
110551
  this.furthestFromPivot = 10;
111604
- this.intensityRange$ = new Subject();
111605
- this.scene.location$ = new Subject();
111606
110552
  this.scene.loading$ = new Subject();
111607
- this.imageLoaded$ = new Subject();
111608
110553
  this.currentClipPlaneIndex = 0;
111609
110554
  this.lastCalled = new Date().getTime();
111610
110555
  this.multiTouchGesture = false;
@@ -111668,10 +110613,7 @@ function Niivue(options = {}) {
111668
110613
  this.loadingText = this.opts.loadingText;
111669
110614
  log.setLogLevel(this.opts.logging);
111670
110615
  this.eventsToSubjects = {
111671
- location: this.scene.location$,
111672
- loading: this.scene.loading$,
111673
- imageLoaded: this.imageLoaded$,
111674
- intensityRange: this.intensityRange$
110616
+ loading: this.scene.loading$
111675
110617
  };
111676
110618
  this.subscriptions = [];
111677
110619
  }
@@ -111967,7 +110909,7 @@ Niivue.prototype.calculateNewRange = function(volIdx = 0) {
111967
110909
  var mxScale = intensityRaw2Scaled(hdr, hi);
111968
110910
  this.volumes[volIdx].cal_min = mnScale;
111969
110911
  this.volumes[volIdx].cal_max = mxScale;
111970
- this.intensityRange$.next(this.volumes[volIdx]);
110912
+ this.opts.onIntensityChange(this.volumes[volIdx]);
111971
110913
  };
111972
110914
  Niivue.prototype.mouseUpListener = function() {
111973
110915
  this.scene.mousedown = false;
@@ -112027,8 +110969,9 @@ Niivue.prototype.mouseMoveListener = function(e) {
112027
110969
  };
112028
110970
  Niivue.prototype.resetBriCon = function(msg2 = null) {
112029
110971
  let isRender = false;
112030
- if (this.sliceType === this.sliceTypeRender)
110972
+ if (this.sliceType === this.sliceTypeRender) {
112031
110973
  isRender = true;
110974
+ }
112032
110975
  if (msg2 !== null) {
112033
110976
  if (this.inRenderTile(msg2.offsetX, msg2.offsetY) >= 0)
112034
110977
  isRender = true;
@@ -112041,7 +110984,7 @@ Niivue.prototype.resetBriCon = function(msg2 = null) {
112041
110984
  }
112042
110985
  this.volumes[0].cal_min = this.volumes[0].robust_min;
112043
110986
  this.volumes[0].cal_max = this.volumes[0].robust_max;
112044
- this.intensityRange$.next(this.volumes[0]);
110987
+ this.opts.onIntensityChange(this.volumes[0]);
112045
110988
  this.refreshLayers(this.volumes[0], 0, this.volumes.length);
112046
110989
  this.drawScene();
112047
110990
  };
@@ -112297,13 +111240,13 @@ Niivue.prototype.addVolume = function(volume) {
112297
111240
  this.volumes.push(volume);
112298
111241
  let idx = this.volumes.length === 1 ? 0 : this.volumes.length - 1;
112299
111242
  this.setVolume(volume, idx);
112300
- this.imageLoaded$.next(volume);
111243
+ this.opts.onImageLoaded(volume);
112301
111244
  };
112302
111245
  Niivue.prototype.addMesh = function(mesh) {
112303
111246
  this.meshes.push(mesh);
112304
111247
  let idx = this.meshes.length === 1 ? 0 : this.meshes.length - 1;
112305
111248
  this.setMesh(mesh, idx);
112306
- this.imageLoaded$.next(mesh);
111249
+ this.opts.onImageLoaded(mesh);
112307
111250
  };
112308
111251
  Niivue.prototype.getVolumeIndexByID = function(id) {
112309
111252
  let n = this.volumes.length;
@@ -113608,14 +112551,13 @@ Niivue.prototype.init = async function() {
113608
112551
  this.gl.enableVertexAttribArray(0);
113609
112552
  this.gl.vertexAttribPointer(0, 3, this.gl.FLOAT, false, 0, 0);
113610
112553
  this.gl.bindVertexArray(this.unusedVAO);
113611
- this.pickingMeshShader = new Shader(this.gl, vertMeshShader, fragMeshDepthShader);
113612
- this.pickingImageShader = new Shader(this.gl, vertRenderShader, fragVolumePickingShader);
113613
- this.pickingImageShader.use(this.gl);
113614
- this.gl.uniform1i(this.pickingImageShader.uniforms["volume"], 0);
113615
- this.gl.uniform1i(this.pickingImageShader.uniforms["overlay"], 2);
113616
- this.pickingImageShader.mvpUniformLoc = this.pickingImageShader.uniforms["mvpMtx"];
113617
- this.pickingImageShader.rayDirUniformLoc = this.pickingImageShader.uniforms["rayDir"];
113618
- this.pickingImageShader.clipPlaneUniformLoc = this.pickingImageShader.uniforms["clipPlane"];
112554
+ this.pickingShader = new Shader(this.gl, vertRenderShader, fragVolumePickingShader);
112555
+ this.pickingShader.use(this.gl);
112556
+ this.gl.uniform1i(this.pickingShader.uniforms["volume"], 0);
112557
+ this.gl.uniform1i(this.pickingShader.uniforms["overlay"], 2);
112558
+ this.pickingShader.mvpUniformLoc = this.pickingShader.uniforms["mvpMtx"];
112559
+ this.pickingShader.rayDirUniformLoc = this.pickingShader.uniforms["rayDir"];
112560
+ this.pickingShader.clipPlaneUniformLoc = this.pickingShader.uniforms["clipPlane"];
113619
112561
  this.sliceShader = new Shader(this.gl, vertSliceShader, fragSliceShader);
113620
112562
  this.sliceShader.use(this.gl);
113621
112563
  this.gl.uniform1i(this.sliceShader.uniforms["volume"], 0);
@@ -113628,21 +112570,6 @@ Niivue.prototype.init = async function() {
113628
112570
  this.gl.uniform1i(this.sliceMMShader.uniforms["overlay"], 2);
113629
112571
  this.gl.uniform1i(this.sliceMMShader.uniforms["drawing"], 7);
113630
112572
  this.gl.uniform1f(this.sliceMMShader.uniforms["drawOpacity"], this.drawOpacity);
113631
- this.orientCubeShader = new Shader(this.gl, vertOrientCubeShader, fragOrientCubeShader);
113632
- let gl = this.gl;
113633
- this.orientCubeShaderVAO = gl.createVertexArray();
113634
- gl.bindVertexArray(this.orientCubeShaderVAO);
113635
- let program = this.orientCubeShader.program;
113636
- this.orientCubeMtxLoc = gl.getUniformLocation(program, "u_matrix");
113637
- var positionBuffer = gl.createBuffer();
113638
- gl.enableVertexAttribArray(0);
113639
- gl.enableVertexAttribArray(1);
113640
- gl.bindBuffer(gl.ARRAY_BUFFER, positionBuffer);
113641
- gl.bufferData(gl.ARRAY_BUFFER, orientCube, gl.STATIC_DRAW);
113642
- gl.vertexAttribPointer(0, 3, gl.FLOAT, false, 24, 0);
113643
- gl.enableVertexAttribArray(1);
113644
- gl.vertexAttribPointer(1, 3, gl.FLOAT, false, 24, 12);
113645
- gl.bindVertexArray(this.unusedVAO);
113646
112573
  this.rectShader = new Shader(this.gl, vertRectShader, fragRectShader);
113647
112574
  this.lineShader = new Shader(this.gl, vertLineShader, fragRectShader);
113648
112575
  this.graphShader = new Shader(this.gl, vertGraphShader, fragRectShader);
@@ -113661,6 +112588,7 @@ Niivue.prototype.init = async function() {
113661
112588
  this.orientShaderI = new Shader(this.gl, vertOrientShader, fragOrientShaderI.concat(fragOrientShader));
113662
112589
  this.orientShaderF = new Shader(this.gl, vertOrientShader, fragOrientShaderF.concat(fragOrientShader));
113663
112590
  this.orientShaderRGBU = new Shader(this.gl, vertOrientShader, fragOrientShaderU.concat(fragRGBOrientShader));
112591
+ this.pickingSurfaceShader = new Shader(this.gl, vertRenderShader, fragDepthPickingShader);
113664
112592
  this.surfaceShader = new Shader(this.gl, vertSurfaceShader, fragSurfaceShader);
113665
112593
  this.fiberShader = new Shader(this.gl, vertFiberShader, fragFiberShader);
113666
112594
  this.meshShader = new Shader(this.gl, vertMeshShader, this.meshShaders[0].Frag);
@@ -113783,7 +112711,8 @@ Niivue.prototype.refreshLayers = function(overlayItem, layer, numLayers) {
113783
112711
  this.renderShader.use(this.gl);
113784
112712
  this.gl.uniform3fv(this.renderShader.uniforms["texVox"], vox2);
113785
112713
  this.gl.uniform3fv(this.renderShader.uniforms["volScale"], volScale2);
113786
- let pickingShader = this.pickingImageShader;
112714
+ this.renderShader;
112715
+ let pickingShader = this.pickingShader;
113787
112716
  pickingShader.use(this.gl);
113788
112717
  this.gl.uniform1i(pickingShader.uniforms["volume"], 0);
113789
112718
  this.gl.uniform1i(pickingShader.uniforms["colormap"], 1);
@@ -113970,9 +112899,9 @@ Niivue.prototype.refreshLayers = function(overlayItem, layer, numLayers) {
113970
112899
  this.gl.uniform4fv(this.renderShader.uniforms["clipPlane"], this.scene.clipPlane);
113971
112900
  this.gl.uniform3fv(this.renderShader.uniforms["texVox"], vox);
113972
112901
  this.gl.uniform3fv(this.renderShader.uniforms["volScale"], volScale);
113973
- this.pickingImageShader.use(this.gl);
113974
- this.gl.uniform1f(this.pickingImageShader.uniforms["overlays"], this.overlays.length);
113975
- this.gl.uniform3fv(this.pickingImageShader.uniforms["texVox"], vox);
112902
+ this.pickingShader.use(this.gl);
112903
+ this.gl.uniform1f(this.pickingShader.uniforms["overlays"], this.overlays.length);
112904
+ this.gl.uniform3fv(this.pickingShader.uniforms["texVox"], vox);
113976
112905
  this.sliceMMShader.use(this.gl);
113977
112906
  this.gl.uniform1f(this.sliceMMShader.uniforms["overlays"], this.overlays.length);
113978
112907
  this.gl.uniform1f(this.sliceMMShader.uniforms["drawOpacity"], this.drawOpacity);
@@ -114173,15 +113102,16 @@ Niivue.prototype.mouseClick = function(x2, y, posChange = 0, isDelta = true) {
114173
113102
  posFuture = 0;
114174
113103
  this.scene.crosshairPos[2 - axCorSag] = posFuture;
114175
113104
  this.drawScene();
114176
- this.scene.location$.next({
113105
+ this.opts.onLocationChange({
114177
113106
  mm: this.frac2mm(this.scene.crosshairPos),
114178
113107
  vox: this.frac2vox(this.scene.crosshairPos),
114179
113108
  frac: this.scene.crosshairPos,
113109
+ xy: [x2, y],
114180
113110
  values: this.volumes.map((v) => {
114181
113111
  let mm = this.frac2mm(this.scene.crosshairPos);
114182
113112
  let vox = v.mm2vox(mm);
114183
113113
  let val = v.getValue(...vox);
114184
- return val;
113114
+ return { name: v.name, value: val, id: v.id, mm, vox };
114185
113115
  })
114186
113116
  });
114187
113117
  return;
@@ -114208,15 +113138,16 @@ Niivue.prototype.mouseClick = function(x2, y, posChange = 0, isDelta = true) {
114208
113138
  this.refreshDrawing(false);
114209
113139
  }
114210
113140
  this.drawScene();
114211
- this.scene.location$.next({
113141
+ this.opts.onLocationChange({
114212
113142
  mm: this.frac2mm(this.scene.crosshairPos),
114213
113143
  vox: this.frac2vox(this.scene.crosshairPos),
114214
113144
  frac: this.scene.crosshairPos,
113145
+ xy: [x2, y],
114215
113146
  values: this.volumes.map((v) => {
114216
113147
  let mm = this.frac2mm(this.scene.crosshairPos);
114217
113148
  let vox = v.mm2vox(mm);
114218
113149
  let val = v.getValue(...vox);
114219
- return val;
113150
+ return { name: v.name, value: val, id: v.id, mm, vox };
114220
113151
  })
114221
113152
  });
114222
113153
  return;
@@ -114994,7 +113925,7 @@ Niivue.prototype.calculateRayDirection = function(azimuth, elevation) {
114994
113925
  rayDir[2] = tiny;
114995
113926
  return rayDir;
114996
113927
  };
114997
- Niivue.prototype.sceneExtentsMinMax = function() {
113928
+ Niivue.prototype.setPivot3D = function() {
114998
113929
  let mn = fromValues$1(0, 0, 0);
114999
113930
  let mx = fromValues$1(0, 0, 0);
115000
113931
  if (this.volumes.length > 0) {
@@ -115012,12 +113943,6 @@ Niivue.prototype.sceneExtentsMinMax = function() {
115012
113943
  max$T(mx, mx, v);
115013
113944
  }
115014
113945
  }
115015
- let range = create$1();
115016
- subtract(range, mx, mn);
115017
- return [mn, mx, range];
115018
- };
115019
- Niivue.prototype.setPivot3D = function() {
115020
- let [mn, mx] = this.sceneExtentsMinMax();
115021
113946
  let pivot = create$1();
115022
113947
  add$1(pivot, mn, mx);
115023
113948
  scale(pivot, pivot, 0.5);
@@ -115213,7 +114138,7 @@ Niivue.prototype.drawGraph = function() {
115213
114138
  if (i2 % 2 === 1) {
115214
114139
  thick *= 0.5;
115215
114140
  this.drawGraphLine([x2, plotLTWH[1], x2, plotLTWH[1] + plotLTWH[3]], thinColor, thick);
115216
- } else {
114141
+ } else if (i2 > 0) {
115217
114142
  let str = humanize(i2);
115218
114143
  if (fntSize > 0)
115219
114144
  this.drawTextBelow([x2, 2 + plotLTWH[1] + plotLTWH[3]], str, fntScale, graph.textColor);
@@ -115256,113 +114181,6 @@ function isRadiological(mtx) {
115256
114181
  transformMat4(vRotated, vRight, mtx);
115257
114182
  return vRotated[0];
115258
114183
  }
115259
- function unProject(winX, winY, winZ, mvpMatrix) {
115260
- let inp = fromValues(winX, winY, winZ, 1);
115261
- let finalMatrix = clone$1(mvpMatrix);
115262
- invert(finalMatrix, finalMatrix);
115263
- inp[0] = inp[0] * 2 - 1;
115264
- inp[1] = inp[1] * 2 - 1;
115265
- inp[2] = inp[2] * 2 - 1;
115266
- let out = create();
115267
- transformMat4(out, inp, finalMatrix);
115268
- if (out[3] === 0)
115269
- return out;
115270
- out[0] /= out[3];
115271
- out[1] /= out[3];
115272
- out[2] /= out[3];
115273
- return out;
115274
- }
115275
- function unpackFloatFromVec4i(val) {
115276
- var bitSh = [
115277
- 1 / (256 * 256 * 256),
115278
- 1 / (256 * 256),
115279
- 1 / 256,
115280
- 1
115281
- ];
115282
- return (val[0] * bitSh[0] + val[1] * bitSh[1] + val[2] * bitSh[2] + val[3] * bitSh[3]) / 255;
115283
- }
115284
- Niivue.prototype.depthPicker = function(leftTopWidthHeight, mvpMatrix) {
115285
- if (!this.scene.mouseDepthPicker)
115286
- return;
115287
- this.scene.mouseDepthPicker = false;
115288
- let gl = this.gl;
115289
- const pixelX = this.mousePos[0] * leftTopWidthHeight[2] / leftTopWidthHeight[2];
115290
- const pixelY = gl.canvas.height - this.mousePos[1] * leftTopWidthHeight[3] / leftTopWidthHeight[3] - 1;
115291
- console.log(pixelX + "/" + pixelY);
115292
- const rgbaPixel = new Uint8Array(4);
115293
- gl.readPixels(pixelX, pixelY, 1, 1, gl.RGBA, gl.UNSIGNED_BYTE, rgbaPixel);
115294
- this.selectedObjectId = rgbaPixel[3];
115295
- if (this.selectedObjectId === this.VOLUME_ID) {
115296
- this.scene.crosshairPos = new Float32Array(rgbaPixel.slice(0, 3)).map((x2) => x2 / 255);
115297
- return;
115298
- }
115299
- let depthZ = unpackFloatFromVec4i(rgbaPixel);
115300
- if (depthZ > 1)
115301
- return;
115302
- let fracX = (this.mousePos[0] - leftTopWidthHeight[0]) / leftTopWidthHeight[2];
115303
- let fracY = (gl.canvas.height - this.mousePos[1] - leftTopWidthHeight[1]) / leftTopWidthHeight[3];
115304
- let mm = unProject(fracX, fracY, depthZ, mvpMatrix);
115305
- let frac = this.mm2frac(mm);
115306
- if (frac[0] < 0 || frac[0] > 1 || frac[1] < 0 || frac[1] > 1 || frac[2] < 0 || frac[2] > 1)
115307
- return;
115308
- this.scene.crosshairPos = this.mm2frac(mm);
115309
- };
115310
- Niivue.prototype.drawImage3D = function(mvpMatrix, azimuth, elevation) {
115311
- if (this.volumes.length === 0)
115312
- return;
115313
- let gl = this.gl;
115314
- const rayDir = this.calculateRayDirection(azimuth, elevation);
115315
- let object3D = this.volumeObject3D;
115316
- if (object3D) {
115317
- gl.enable(gl.BLEND);
115318
- gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA);
115319
- gl.enable(gl.CULL_FACE);
115320
- gl.cullFace(gl.FRONT);
115321
- let shader = this.renderShader;
115322
- if (this.scene.mouseDepthPicker)
115323
- shader = this.pickingImageShader;
115324
- shader.use(this.gl);
115325
- gl.uniform1i(shader.uniforms["backgroundMasksOverlays"], this.backgroundMasksOverlays);
115326
- gl.uniformMatrix4fv(shader.mvpUniformLoc, false, mvpMatrix);
115327
- gl.uniformMatrix4fv(shader.mvpMatRASLoc, false, this.back.matRAS);
115328
- gl.uniform3fv(shader.rayDirUniformLoc, rayDir);
115329
- gl.uniform4fv(shader.clipPlaneUniformLoc, this.scene.clipPlane);
115330
- gl.bindVertexArray(object3D.vao);
115331
- gl.drawElements(object3D.mode, object3D.indexCount, gl.UNSIGNED_SHORT, 0);
115332
- gl.bindVertexArray(this.unusedVAO);
115333
- }
115334
- };
115335
- Niivue.prototype.drawOrientationCube = function(leftTopWidthHeight, azimuth = 0, elevation = 0) {
115336
- if (!this.opts.isOrientCube)
115337
- return;
115338
- let sz = 0.05 * Math.min(leftTopWidthHeight[2], leftTopWidthHeight[3]);
115339
- if (sz < 5)
115340
- return;
115341
- let gl = this.gl;
115342
- gl.enable(gl.CULL_FACE);
115343
- gl.cullFace(gl.BACK);
115344
- this.orientCubeShader.use(this.gl);
115345
- gl.bindVertexArray(this.orientCubeShaderVAO);
115346
- function deg2rad2(deg) {
115347
- return deg * (Math.PI / 180);
115348
- }
115349
- let modelMatrix = create$2();
115350
- let projectionMatrix = create$2();
115351
- ortho(projectionMatrix, 0, gl.canvas.width, 0, gl.canvas.height, -10 * sz, 10 * sz);
115352
- translate(modelMatrix, modelMatrix, [
115353
- 1.8 * sz + leftTopWidthHeight[0],
115354
- 1.8 * sz + leftTopWidthHeight[1],
115355
- 0
115356
- ]);
115357
- scale$1(modelMatrix, modelMatrix, [sz, sz, sz]);
115358
- rotateX(modelMatrix, modelMatrix, deg2rad2(270 - elevation));
115359
- rotateZ(modelMatrix, modelMatrix, deg2rad2(-azimuth));
115360
- let modelViewProjectionMatrix = create$2();
115361
- multiply(modelViewProjectionMatrix, projectionMatrix, modelMatrix);
115362
- gl.uniformMatrix4fv(this.orientCubeMtxLoc, false, modelViewProjectionMatrix);
115363
- gl.drawArrays(gl.TRIANGLE_STRIP, 0, 168);
115364
- gl.bindVertexArray(this.unusedVAO);
115365
- };
115366
114184
  Niivue.prototype.draw3D = function(leftTopWidthHeight = [0, 0, 0, 0], mvpMatrix = null, modelMatrix, normalMatrix, azimuth = null, elevation) {
115367
114185
  let isMosaic = azimuth !== null;
115368
114186
  this.setPivot3D();
@@ -115398,20 +114216,62 @@ Niivue.prototype.draw3D = function(leftTopWidthHeight = [0, 0, 0, 0], mvpMatrix
115398
114216
  gl.enable(gl.DEPTH_TEST);
115399
114217
  gl.depthFunc(gl.ALWAYS);
115400
114218
  gl.clearDepth(0);
115401
- if (this.volumes.length > 0)
115402
- this.drawImage3D(mvpMatrix, azimuth, elevation);
114219
+ if (this.volumes.length === 0) {
114220
+ gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
114221
+ this.drawMesh3D(true, 1, mvpMatrix, modelMatrix, normalMatrix);
114222
+ gl.viewport(0, 0, gl.canvas.width, gl.canvas.height);
114223
+ return;
114224
+ }
114225
+ const rayDir = this.calculateRayDirection(azimuth, elevation);
114226
+ let object3D = this.volumeObject3D;
114227
+ if (this.scene.mouseDepthPicker) {
114228
+ gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
114229
+ this.scene.mouseDepthPicker = false;
114230
+ if (object3D.isVisible && object3D.isPickable) {
114231
+ let shader = this.pickingShader;
114232
+ shader.use(this.gl);
114233
+ gl.enable(gl.CULL_FACE);
114234
+ gl.cullFace(gl.FRONT);
114235
+ gl.uniformMatrix4fv(shader.mvpUniformLoc, false, mvpMatrix);
114236
+ gl.uniform3fv(shader.rayDirUniformLoc, rayDir);
114237
+ gl.uniform4fv(shader.clipPlaneUniformLoc, this.scene.clipPlane);
114238
+ gl.uniform1i(shader.uniforms["id"], object3D.id);
114239
+ gl.bindVertexArray(object3D.vao);
114240
+ gl.drawElements(object3D.mode, object3D.indexCount, gl.UNSIGNED_SHORT, 0);
114241
+ gl.bindVertexArray(this.unusedVAO);
114242
+ }
114243
+ const pixelX = this.mousePos[0] * leftTopWidthHeight[2] / leftTopWidthHeight[2];
114244
+ const pixelY = gl.canvas.height - this.mousePos[1] * leftTopWidthHeight[3] / leftTopWidthHeight[3] - 1;
114245
+ const rgbaPixel = new Uint8Array(4);
114246
+ gl.readPixels(pixelX, pixelY, 1, 1, gl.RGBA, gl.UNSIGNED_BYTE, rgbaPixel);
114247
+ this.selectedObjectId = rgbaPixel[3];
114248
+ if (this.selectedObjectId === this.VOLUME_ID) {
114249
+ this.scene.crosshairPos = new Float32Array(rgbaPixel.slice(0, 3)).map((x2) => x2 / 255);
114250
+ }
114251
+ }
114252
+ if (this.volumeObject3D.isVisible) {
114253
+ gl.enable(gl.BLEND);
114254
+ gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA);
114255
+ gl.enable(gl.CULL_FACE);
114256
+ gl.cullFace(gl.FRONT);
114257
+ let shader = this.renderShader;
114258
+ shader.use(this.gl);
114259
+ gl.uniform1i(shader.uniforms["backgroundMasksOverlays"], this.backgroundMasksOverlays);
114260
+ gl.uniformMatrix4fv(shader.mvpUniformLoc, false, mvpMatrix);
114261
+ gl.uniformMatrix4fv(shader.mvpMatRASLoc, false, this.back.matRAS);
114262
+ gl.uniform3fv(shader.rayDirUniformLoc, rayDir);
114263
+ gl.uniform4fv(shader.clipPlaneUniformLoc, this.scene.clipPlane);
114264
+ gl.bindVertexArray(object3D.vao);
114265
+ gl.drawElements(object3D.mode, object3D.indexCount, gl.UNSIGNED_SHORT, 0);
114266
+ gl.bindVertexArray(this.unusedVAO);
114267
+ }
115403
114268
  if (!isMosaic)
115404
114269
  this.drawCrosshairs3D(true, 1, mvpMatrix);
115405
114270
  this.drawMesh3D(true, 1, mvpMatrix, modelMatrix, normalMatrix);
115406
- if (this.scene.mouseDepthPicker) {
115407
- this.depthPicker(leftTopWidthHeight, mvpMatrix, true);
115408
- return;
115409
- }
115410
114271
  this.drawMesh3D(false, 0.02, mvpMatrix, modelMatrix, normalMatrix);
115411
114272
  if (!isMosaic)
115412
114273
  this.drawCrosshairs3D(false, 0.15, mvpMatrix);
115413
114274
  gl.viewport(0, 0, gl.canvas.width, gl.canvas.height);
115414
- this.drawOrientationCube(leftTopWidthHeight, azimuth, elevation);
115415
114275
  let posString = "azimuth: " + this.scene.renderAzimuth.toFixed(0) + " elevation: " + this.scene.renderElevation.toFixed(0);
115416
114276
  this.drawGraph();
115417
114277
  this.readyForSync = true;
@@ -115436,14 +114296,11 @@ Niivue.prototype.drawMesh3D = function(isDepthTest = true, alpha = 1, m, modelMt
115436
114296
  gl.depthFunc(gl.ALWAYS);
115437
114297
  }
115438
114298
  gl.disable(gl.CULL_FACE);
115439
- let shader = this.meshShader;
115440
- if (this.scene.mouseDepthPicker)
115441
- shader = this.pickingMeshShader;
115442
- shader.use(this.gl);
115443
- gl.uniformMatrix4fv(shader.uniforms["mvpMtx"], false, m);
115444
- gl.uniformMatrix4fv(shader.uniforms["modelMtx"], false, modelMtx);
115445
- gl.uniformMatrix4fv(shader.uniforms["normMtx"], false, normMtx);
115446
- gl.uniform1f(shader.uniforms["opacity"], alpha);
114299
+ this.meshShader.use(this.gl);
114300
+ gl.uniformMatrix4fv(this.meshShader.uniforms["mvpMtx"], false, m);
114301
+ gl.uniformMatrix4fv(this.meshShader.uniforms["modelMtx"], false, modelMtx);
114302
+ gl.uniformMatrix4fv(this.meshShader.uniforms["normMtx"], false, normMtx);
114303
+ gl.uniform1f(this.meshShader.uniforms["opacity"], alpha);
115447
114304
  let hasFibers = false;
115448
114305
  for (let i2 = 0; i2 < this.meshes.length; i2++) {
115449
114306
  if (this.meshes[i2].indexCount < 3)
@@ -115461,7 +114318,7 @@ Niivue.prototype.drawMesh3D = function(isDepthTest = true, alpha = 1, m, modelMt
115461
114318
  gl.depthFunc(gl.ALWAYS);
115462
114319
  return;
115463
114320
  }
115464
- shader = this.fiberShader;
114321
+ let shader = this.fiberShader;
115465
114322
  shader.use(this.gl);
115466
114323
  gl.uniformMatrix4fv(shader.uniforms["mvpMtx"], false, m);
115467
114324
  gl.uniform1f(shader.uniforms["opacity"], alpha);
@@ -115488,13 +114345,8 @@ Niivue.prototype.drawCrosshairs3D = function(isDepthTest = true, alpha = 1, mvpM
115488
114345
  gl.deleteBuffer(this.crosshairs3D.indexBuffer);
115489
114346
  gl.deleteBuffer(this.crosshairs3D.vertexBuffer);
115490
114347
  }
115491
- let [mn, mx, range] = this.sceneExtentsMinMax();
115492
- let radius = 1;
115493
- if (this.volumes.length > 0)
115494
- radius = 0.5 * Math.min(Math.min(this.back.pixDims[1], this.back.pixDims[2]), this.back.pixDims[3]);
115495
- else if (range[0] < 50 || range[0] > 1e3)
115496
- radius = range[0] * 0.02;
115497
- this.crosshairs3D = NiivueObject3D.generateCrosshairs(this.gl, 1, mm, mn, mx, radius);
114348
+ let radius = 0.5 * Math.min(Math.min(this.back.pixDims[1], this.back.pixDims[2]), this.back.pixDims[3]);
114349
+ this.crosshairs3D = NiivueObject3D.generateCrosshairs(this.gl, 1, mm, this.volumeObject3D.extentsMin, this.volumeObject3D.extentsMax, radius);
115498
114350
  this.crosshairs3D.mm = mm;
115499
114351
  }
115500
114352
  let crosshairsShader = this.surfaceShader;
@@ -115521,14 +114373,6 @@ Niivue.prototype.drawCrosshairs3D = function(isDepthTest = true, alpha = 1, mvpM
115521
114373
  gl.bindVertexArray(this.unusedVAO);
115522
114374
  };
115523
114375
  Niivue.prototype.mm2frac = function(mm, volIdx = 0) {
115524
- if (this.volumes.length < 1) {
115525
- let frac2 = [0.1, 0.5, 0.5];
115526
- let [mn, mx, range] = this.sceneExtentsMinMax();
115527
- frac2[0] = (mm[0] - mn[0]) / range[0];
115528
- frac2[1] = (mm[1] - mn[1]) / range[1];
115529
- frac2[2] = (mm[2] - mn[2]) / range[2];
115530
- return frac2;
115531
- }
115532
114376
  let mm4 = fromValues(mm[0], mm[1], mm[2], 1);
115533
114377
  let d = this.volumes[volIdx].dimsRAS;
115534
114378
  let frac = [0, 0, 0];
@@ -115572,15 +114416,7 @@ Niivue.prototype.moveCrosshairInVox = function(x2, y, z) {
115572
114416
  };
115573
114417
  Niivue.prototype.frac2mm = function(frac, volIdx = 0) {
115574
114418
  let pos = fromValues(frac[0], frac[1], frac[2], 1);
115575
- if (this.volumes.length > 0)
115576
- transformMat4(pos, pos, this.volumes[volIdx].frac2mm);
115577
- else {
115578
- let [mn, mx] = this.sceneExtentsMinMax();
115579
- const lerp2 = (x2, y, a) => x2 * (1 - a) + y * a;
115580
- pos[0] = lerp2(mn[0], mx[0], frac[0]);
115581
- pos[1] = lerp2(mn[1], mx[1], frac[1]);
115582
- pos[2] = lerp2(mn[2], mx[2], frac[2]);
115583
- }
114419
+ transformMat4(pos, pos, this.volumes[volIdx].frac2mm);
115584
114420
  return pos;
115585
114421
  };
115586
114422
  Niivue.prototype.screenXY2TextureFrac = function(x2, y, i2) {
@@ -115642,17 +114478,15 @@ Niivue.prototype.canvasPos2frac = function(canvasPos) {
115642
114478
  }
115643
114479
  return [-1, -1, -1];
115644
114480
  };
115645
- Niivue.prototype.scaleSlice = function(w, h, widthPadPixels = 0, heightPadPixels = 0) {
115646
- let canvasW = this.gl.canvas.clientWidth - widthPadPixels;
115647
- let canvasH = this.effectiveCanvasHeight() - heightPadPixels;
115648
- let scalePix = canvasW / w;
115649
- if (h * scalePix > canvasH)
115650
- scalePix = canvasH / h;
114481
+ Niivue.prototype.scaleSlice = function(w, h) {
114482
+ let scalePix = this.gl.canvas.clientWidth / w;
114483
+ if (h * scalePix > this.effectiveCanvasHeight())
114484
+ scalePix = this.effectiveCanvasHeight() / h;
115651
114485
  let wPix = w * scalePix;
115652
114486
  let hPix = h * scalePix;
115653
114487
  let leftTopWidthHeight = [
115654
- (canvasW - wPix) * 0.5,
115655
- (canvasH - hPix) * 0.5,
114488
+ (this.gl.canvas.clientWidth - wPix) * 0.5,
114489
+ (this.effectiveCanvasHeight() - hPix) * 0.5,
115656
114490
  wPix,
115657
114491
  hPix
115658
114492
  ];
@@ -115991,7 +114825,7 @@ Niivue.prototype.drawScene = function() {
115991
114825
  }
115992
114826
  this.colorbarHeight = 0;
115993
114827
  this.gl.clearColor(this.opts.backColor[0], this.opts.backColor[1], this.opts.backColor[2], this.opts.backColor[3]);
115994
- this.gl.clear(this.gl.COLOR_BUFFER_BIT | this.gl.DEPTH_BUFFER_BIT);
114828
+ this.gl.clear(this.gl.COLOR_BUFFER_BIT);
115995
114829
  if (this.bmpTexture) {
115996
114830
  this.drawThumbnail();
115997
114831
  return;
@@ -116042,12 +114876,11 @@ Niivue.prototype.drawScene = function() {
116042
114876
  this.draw2D([0, 0, 0, 0], 2);
116043
114877
  } else {
116044
114878
  let { volScale, vox, longestAxis } = this.sliceScale();
116045
- let pad = this.opts.multiplanarPadPixels;
116046
- let ltwh = this.scaleSlice(volScale[0] + volScale[1], volScale[1] + volScale[2], pad * 1, pad * 1);
114879
+ let ltwh = this.scaleSlice(volScale[0] + volScale[1], volScale[1] + volScale[2]);
116047
114880
  let wX = ltwh[2] * volScale[0] / (volScale[0] + volScale[1]);
116048
- let ltwh3x1 = this.scaleSlice(volScale[0] + volScale[0] + volScale[1], Math.max(volScale[1], volScale[2]), pad * 2);
114881
+ let ltwh3x1 = this.scaleSlice(volScale[0] + volScale[0] + volScale[1], Math.max(volScale[1], volScale[2]));
116049
114882
  let mx = Math.max(Math.max(volScale[1], volScale[2]), volScale[0]);
116050
- let ltwh4x1 = this.scaleSlice(volScale[0] + volScale[0] + volScale[1] + mx, mx, pad * 3);
114883
+ let ltwh4x1 = this.scaleSlice(volScale[0] + volScale[0] + volScale[1] + mx, mx);
116051
114884
  let wX1 = ltwh3x1[2] * volScale[0] / (volScale[0] + volScale[0] + volScale[1]);
116052
114885
  if (wX1 > wX && !this.graph.autoSizeMultiplanar) {
116053
114886
  let pixScale = wX1 / volScale[0];
@@ -116056,24 +114889,24 @@ Niivue.prototype.drawScene = function() {
116056
114889
  if (ltwh3x1[3] === ltwh4x1[3]) {
116057
114890
  ltwh3x1 = ltwh4x1;
116058
114891
  this.draw3D([
116059
- ltwh3x1[0] + wX1 + wX1 + hY1 + pad * 3,
114892
+ ltwh3x1[0] + wX1 + wX1 + hY1,
116060
114893
  ltwh3x1[1],
116061
114894
  ltwh4x1[3],
116062
114895
  ltwh4x1[3]
116063
114896
  ]);
116064
114897
  }
116065
114898
  this.draw2D([ltwh3x1[0], ltwh3x1[1], wX1, hY1], 0);
116066
- this.draw2D([ltwh3x1[0] + wX1 + pad, ltwh3x1[1], wX1, hZ1], 1);
116067
- this.draw2D([ltwh3x1[0] + wX1 + wX1 + pad * 2, ltwh3x1[1], hY1, hZ1], 2);
114899
+ this.draw2D([ltwh3x1[0] + wX1, ltwh3x1[1], wX1, hZ1], 1);
114900
+ this.draw2D([ltwh3x1[0] + wX1 + wX1, ltwh3x1[1], hY1, hZ1], 2);
116068
114901
  } else {
116069
114902
  let wY = ltwh[2] - wX;
116070
114903
  let hY = ltwh[3] * volScale[1] / (volScale[1] + volScale[2]);
116071
114904
  let hZ = ltwh[3] - hY;
116072
- this.draw2D([ltwh[0], ltwh[1] + hZ + pad, wX, hY], 0);
114905
+ this.draw2D([ltwh[0], ltwh[1] + hZ, wX, hY], 0);
116073
114906
  this.draw2D([ltwh[0], ltwh[1], wX, hZ], 1);
116074
- this.draw2D([ltwh[0] + wX + pad, ltwh[1], wY, hZ], 2);
114907
+ this.draw2D([ltwh[0] + wX, ltwh[1], wY, hZ], 2);
116075
114908
  if (!this.graph.autoSizeMultiplanar)
116076
- this.draw3D([ltwh[0] + wX + pad, ltwh[1] + hZ + pad, wY, hY]);
114909
+ this.draw3D([ltwh[0] + wX, ltwh[1] + hZ, wY, hY]);
116077
114910
  }
116078
114911
  }
116079
114912
  }