@niivue/niivue 0.31.0 → 0.32.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/dist/niivue.es.js CHANGED
@@ -758,7 +758,7 @@ const kDrawFunc = `
758
758
  return dcolor;
759
759
  }`;
760
760
  const kRenderFunc = `vec3 GetBackPosition(vec3 startPositionTex) {
761
- vec3 startPosition = startPositionTex * volScale;
761
+ vec3 startPosition = startPositionTex * volScale;
762
762
  vec3 invR = 1.0 / rayDir;
763
763
  vec3 tbot = invR * (vec3(0.0)-startPosition);
764
764
  vec3 ttop = invR * (volScale-startPosition);
@@ -1033,7 +1033,7 @@ out vec4 color;` + kDrawFunc + `void main() {
1033
1033
  vec3 vxA = vec3(texPos.x, texPos.y+vx.y, texPos.z);
1034
1034
  vec3 vxP = vec3(texPos.x, texPos.y-vx.y, texPos.z);
1035
1035
  vec3 vxS = vec3(texPos.x, texPos.y, texPos.z+vx.z);
1036
- vec3 vxI = vec3(texPos.x, texPos.y, texPos.z-vx.z);
1036
+ vec3 vxI = vec3(texPos.x, texPos.y, texPos.z-vx.z);
1037
1037
  float a = 1.0;
1038
1038
  if (axCorSag != 2) {
1039
1039
  a = min(a, texture(overlay, vxR).a);
@@ -1283,7 +1283,7 @@ uniform float opacity;
1283
1283
  uniform mat4 mtx;
1284
1284
  void main(void) {
1285
1285
  vec4 vx = vec4(TexCoord.xy, coordZ, 1.0) * mtx;
1286
- if ((vx.x < 0.0) || (vx.x > 1.0) || (vx.y < 0.0) || (vx.y > 1.0) || (vx.z < 0.0) || (vx.z > 1.0)) {
1286
+ if ((vx.x < 0.0) || (vx.x > 1.0) || (vx.y < 0.0) || (vx.y > 1.0) || (vx.z < 0.0) || (vx.z > 1.0)) {
1287
1287
  //set transparent if out of range
1288
1288
  //https://webglfundamentals.org/webgl/webgl-3d-textures-repeat-clamp.html
1289
1289
  FragColor = vec4(0.0, 0.0, 0.0, 0.0);
@@ -1292,7 +1292,7 @@ void main(void) {
1292
1292
  float f = (scl_slope * float(texture(intensityVol, vx.xyz).r)) + scl_inter;
1293
1293
  float mn = cal_min;
1294
1294
  float mx = cal_max;
1295
- if (isAlphaThreshold)
1295
+ if (isAlphaThreshold)
1296
1296
  mn = 0.0;
1297
1297
  float r = max(0.00001, abs(mx - mn));
1298
1298
  mn = min(mn, mx);
@@ -1300,15 +1300,17 @@ void main(void) {
1300
1300
  //https://stackoverflow.com/questions/5879403/opengl-texture-coordinates-in-pixel-space
1301
1301
  float nlayer = float(textureSize(colormap, 0).y);
1302
1302
  float y = (layer + 0.5)/nlayer;
1303
- if (!isnan(cal_minNeg))
1303
+ //if (!isnan(cal_minNeg)) //Radeon drivers have issues NaN
1304
+ if (cal_minNeg < cal_maxNeg)
1304
1305
  y = (layer + 1.5)/nlayer;
1305
1306
  FragColor = texture(colormap, vec2(txl, y)).rgba;
1306
1307
  //negative colors
1307
1308
  mn = cal_minNeg;
1308
1309
  mx = cal_maxNeg;
1309
- if (isAlphaThreshold)
1310
- mx = 0.0;
1311
- if ((!isnan(cal_minNeg)) && ( f < mx)) {
1310
+ if (isAlphaThreshold)
1311
+ mx = 0.0;
1312
+ //if ((!isnan(cal_minNeg)) && ( f < mx)) {
1313
+ if ((cal_minNeg < cal_maxNeg) && ( f < mx)) {
1312
1314
  r = max(0.00001, abs(mx - mn));
1313
1315
  mn = min(mn, mx);
1314
1316
  txl = 1.0 - mix(0.0, 1.0, (f - mn) / r);
@@ -1321,7 +1323,7 @@ void main(void) {
1321
1323
  // FragColor.a *= texture(modulationVol, vx.xyz).r;
1322
1324
  // FragColor.rgb *= texture(modulationVol, vx.xyz).r;
1323
1325
  if (isAlphaThreshold) {
1324
- if ((cal_minNeg != cal_maxNeg) && ( f < 0.0) && (f > cal_maxNeg))
1326
+ if ((cal_minNeg != cal_maxNeg) && ( f < 0.0) && (f > cal_maxNeg))
1325
1327
  FragColor.a = pow(-f / -cal_maxNeg, 2.0);
1326
1328
  else if ((f > 0.0) && (cal_min > 0.0))
1327
1329
  FragColor.a *= pow(f / cal_min, 2.0); //issue435: A = (V/X)**2
@@ -1580,6 +1582,26 @@ void main() {
1580
1582
  color.rgb = a + d + s;
1581
1583
  color.a = opacity;
1582
1584
  }`;
1585
+ var fragMeshEdgeShader = `#version 300 es
1586
+ precision highp int;
1587
+ precision highp float;
1588
+ uniform float opacity;
1589
+ in vec4 vClr;
1590
+ in vec3 vN;
1591
+ out vec4 color;
1592
+ void main() {
1593
+ vec3 r = vec3(0.0, 0.0, 1.0); //rayDir: for orthographic projections moving in Z direction (no need for normal matrix)
1594
+ float diffuse = 1.0;
1595
+ float specular = 0.2;
1596
+ float shininess = 10.0;
1597
+ vec3 n = normalize(vN);
1598
+ vec3 lightPosition = vec3(0.0, 0.0, -5.0);
1599
+ vec3 l = normalize(lightPosition);
1600
+ float lightNormDot = max(dot(n, l), 0.0);
1601
+ vec3 d = lightNormDot * vClr.rgb * diffuse;
1602
+ float s = specular * pow(max(dot(reflect(l, n), r), 0.0), shininess);
1603
+ color = vec4(d + s, opacity);
1604
+ }`;
1583
1605
  var fragMeshShader = `#version 300 es
1584
1606
  precision highp int;
1585
1607
  precision highp float;
@@ -110775,6 +110797,8 @@ NVMesh.prototype.updateMesh = function(gl) {
110775
110797
  layer.cal_min = Math.max(0, layer.cal_min);
110776
110798
  layer.cal_max = Math.max(layer.cal_min + 1e-6, layer.cal_max);
110777
110799
  }
110800
+ if (!layer.hasOwnProperty("isTransparentBelowCalMin"))
110801
+ layer.isTransparentBelowCalMin = true;
110778
110802
  let scale255 = 255 / (layer.cal_max - layer.cal_min);
110779
110803
  if (!layer.isOutlineBorder) {
110780
110804
  for (let j = 0; j < nvtx; j++) {
@@ -116310,6 +116334,10 @@ function Niivue(options = {}) {
116310
116334
  Name: "Hemispheric",
116311
116335
  Frag: fragMeshHemiShader
116312
116336
  },
116337
+ {
116338
+ Name: "Edge",
116339
+ Frag: fragMeshEdgeShader
116340
+ },
116313
116341
  {
116314
116342
  Name: "Outline",
116315
116343
  Frag: fragMeshOutlineShader
@@ -116501,7 +116529,7 @@ Niivue.prototype.attachToCanvas = async function(canvas, isAntiAlias = null) {
116501
116529
  alert("unable to get webgl2 context. Perhaps this browser does not support webgl2");
116502
116530
  log.warn("unable to get webgl2 context. Perhaps this browser does not support webgl2");
116503
116531
  }
116504
- console.log("NIIVUE VERSION ", "0.30.0");
116532
+ console.log("NIIVUE VERSION ", "0.32.0");
116505
116533
  this.canvas.parentElement.style.backgroundColor = "black";
116506
116534
  if (this.opts.isResizeCanvas) {
116507
116535
  this.canvas.style.width = "100%";
@@ -116947,7 +116975,7 @@ Niivue.prototype.keyDownListener = function(e) {
116947
116975
  } else if (e.code === "ArrowRight") {
116948
116976
  this.setFrame4D(this.volumes[0].id, this.volumes[0].frame4D + 1);
116949
116977
  } else if (e.code === "Slash" && e.shiftKey) {
116950
- alert(`NIIVUE VERSION: ${"0.30.0"}`);
116978
+ alert(`NIIVUE VERSION: ${"0.32.0"}`);
116951
116979
  }
116952
116980
  };
116953
116981
  Niivue.prototype.wheelListener = function(e) {
@@ -119221,8 +119249,8 @@ Niivue.prototype.refreshLayers = function(overlayItem, layer) {
119221
119249
  this.gl.uniform1i(orientShader.uniforms["isAlphaThreshold"], overlayItem.alphaThreshold);
119222
119250
  this.gl.uniform1f(orientShader.uniforms["cal_min"], overlayItem.cal_min);
119223
119251
  this.gl.uniform1f(orientShader.uniforms["cal_max"], overlayItem.cal_max);
119224
- let mnNeg = NaN;
119225
- let mxNeg = NaN;
119252
+ let mnNeg = Number.POSITIVE_INFINITY;
119253
+ let mxNeg = Number.NEGATIVE_INFINITY;
119226
119254
  if (overlayItem.colorMapNegative.length > 0) {
119227
119255
  mnNeg = Math.min(-overlayItem.cal_min, -overlayItem.cal_max);
119228
119256
  mxNeg = Math.max(-overlayItem.cal_min, -overlayItem.cal_max);
@@ -120731,7 +120759,7 @@ Niivue.prototype.depthPicker = function(leftTopWidthHeight, mvpMatrix) {
120731
120759
  let frac = this.mm2frac(mm, 0, true);
120732
120760
  if (frac[0] < 0 || frac[0] > 1 || frac[1] < 0 || frac[1] > 1 || frac[2] < 0 || frac[2] > 1)
120733
120761
  return;
120734
- this.scene.crosshairPos = this.mm2frac(mm);
120762
+ this.scene.crosshairPos = this.mm2frac(mm, 0, true);
120735
120763
  };
120736
120764
  Niivue.prototype.drawImage3D = function(mvpMatrix, azimuth, elevation) {
120737
120765
  if (this.volumes.length === 0)
@@ -120744,12 +120772,6 @@ Niivue.prototype.drawImage3D = function(mvpMatrix, azimuth, elevation) {
120744
120772
  gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA);
120745
120773
  gl.enable(gl.CULL_FACE);
120746
120774
  gl.cullFace(gl.FRONT);
120747
- this.gl.activeTexture(this.gl.TEXTURE0);
120748
- this.gl.bindTexture(this.gl.TEXTURE_3D, this.volumeTexture);
120749
- this.gl.activeTexture(this.gl.TEXTURE2);
120750
- this.gl.bindTexture(this.gl.TEXTURE_3D, this.overlayTexture);
120751
- this.gl.activeTexture(this.gl.TEXTURE7);
120752
- this.gl.bindTexture(this.gl.TEXTURE_3D, this.drawTexture);
120753
120775
  let shader = this.renderShader;
120754
120776
  if (this.uiData.mouseDepthPicker)
120755
120777
  shader = this.pickingImageShader;