@niivue/niivue 0.29.1 → 0.30.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
@@ -1095,7 +1095,7 @@ void main() {
1095
1095
  //if (aout <= 0.0) return;
1096
1096
  //color.rgb = ((ocolor.rgb * ocolor.a) + (color.rgb * color.a * (1.0 - ocolor.a))) / aout;
1097
1097
  color.rgb = mix(color.rgb, ocolor.rgb, ocolor.a);
1098
- color.a = 1.0;
1098
+ //color.a = 1.0;
1099
1099
  }`;
1100
1100
  var fragRectShader = `#version 300 es
1101
1101
  #line 189
@@ -106861,7 +106861,12 @@ NVImage.loadFromUrl = async function({
106861
106861
  throw Error(response.statusText);
106862
106862
  }
106863
106863
  var re = /(?:\.([^.]+))?$/;
106864
- let ext = re.exec(url)[1];
106864
+ let ext = "";
106865
+ if (name === "") {
106866
+ ext = re.exec(url)[1];
106867
+ } else {
106868
+ ext = re.exec(name)[1];
106869
+ }
106865
106870
  if (ext.toUpperCase() === "NHDR")
106866
106871
  ;
106867
106872
  else if (ext.toUpperCase() === "HEAD") {
@@ -106870,17 +106875,17 @@ NVImage.loadFromUrl = async function({
106870
106875
  }
106871
106876
  }
106872
106877
  let urlParts;
106873
- try {
106874
- urlParts = new URL(url).pathname.split("/");
106875
- } catch (e) {
106876
- urlParts = url.split("/");
106877
- }
106878
- console.log(url, name, urlParts);
106879
- name = urlParts.slice(-1)[0];
106880
- if (name.indexOf("?") > -1) {
106881
- name = name.slice(0, name.indexOf("?"));
106878
+ if (name === "") {
106879
+ try {
106880
+ urlParts = new URL(url).pathname.split("/");
106881
+ } catch (e) {
106882
+ urlParts = url.split("/");
106883
+ }
106884
+ name = urlParts.slice(-1)[0];
106885
+ if (name.indexOf("?") > -1) {
106886
+ name = name.slice(0, name.indexOf("?"));
106887
+ }
106882
106888
  }
106883
- console.log(name);
106884
106889
  let dataBuffer = await response.arrayBuffer();
106885
106890
  let pairedImgData = null;
106886
106891
  if (urlImgData.length > 0) {
@@ -112117,6 +112122,8 @@ function Niivue(options = {}) {
112117
112122
  },
112118
112123
  onImageLoaded: () => {
112119
112124
  },
112125
+ onFrameChange: () => {
112126
+ },
112120
112127
  onError: () => {
112121
112128
  },
112122
112129
  onInfo: () => {
@@ -112438,9 +112445,9 @@ Niivue.prototype.handleMessage = function(msg, sessionCreatedCallback, sessionJo
112438
112445
  break;
112439
112446
  case REMOVE_VOLUME_URL:
112440
112447
  {
112441
- let volume = this.getMediaByUrl(msg["url"]);
112442
- if (volume) {
112443
- this.removeVolume(volume, false);
112448
+ let volume2 = this.getMediaByUrl(msg["url"]);
112449
+ if (volume2) {
112450
+ this.removeVolume(volume2, false);
112444
112451
  }
112445
112452
  }
112446
112453
  break;
@@ -112452,16 +112459,16 @@ Niivue.prototype.handleMessage = function(msg, sessionCreatedCallback, sessionJo
112452
112459
  }
112453
112460
  case SET_4D_VOL_INDEX:
112454
112461
  {
112455
- let volume = this.getMediaByUrl(msg["url"]);
112456
- if (volume) {
112457
- this.setFrame4D(volume.id, msg["index"]);
112462
+ let volume2 = this.getMediaByUrl(msg["url"]);
112463
+ if (volume2) {
112464
+ this.setFrame4D(volume2.id, msg["index"]);
112458
112465
  }
112459
112466
  }
112460
112467
  break;
112461
112468
  case UPDATE_IMAGE_OPTIONS: {
112462
- let volume = this.getMediaByUrl(msg["urlImageOptions"].url);
112463
- if (volume) {
112464
- volume.applyOptionsUpdate(msg["urlImageOptions"]);
112469
+ let volume2 = this.getMediaByUrl(msg["urlImageOptions"].url);
112470
+ if (volume2) {
112471
+ volume2.applyOptionsUpdate(msg["urlImageOptions"]);
112465
112472
  this.updateGLVolume();
112466
112473
  }
112467
112474
  }
@@ -112918,37 +112925,37 @@ Niivue.prototype.getFileExt = function(fullname, upperCase = true) {
112918
112925
  return upperCase ? ext : ext.toLowerCase();
112919
112926
  };
112920
112927
  Niivue.prototype.loadVolumeFromUrl = async function(imageOptions) {
112921
- let volume = await NVImage.loadFromUrl(imageOptions);
112922
- return volume;
112928
+ let volume2 = await NVImage.loadFromUrl(imageOptions);
112929
+ return volume2;
112923
112930
  };
112924
- Niivue.prototype.notifySubscribersOfOptionChange = function(volume) {
112931
+ Niivue.prototype.notifySubscribersOfOptionChange = function(volume2) {
112925
112932
  if (this.isInSession) {
112926
- if (this.mediaUrlMap.has(volume)) {
112927
- let imageOptions = volume.getImageOptions();
112928
- imageOptions.url = this.mediaUrlMap.get(volume);
112933
+ if (this.mediaUrlMap.has(volume2)) {
112934
+ let imageOptions = volume2.getImageOptions();
112935
+ imageOptions.url = this.mediaUrlMap.get(volume2);
112929
112936
  this.serverConnection$.next(new NVMessage(UPDATE_IMAGE_OPTIONS, imageOptions, this.sessionKey));
112930
112937
  console.log("update called");
112931
112938
  }
112932
112939
  }
112933
112940
  };
112934
112941
  Niivue.prototype.addVolumeFromUrl = async function(imageOptions, notifySubscribers = true) {
112935
- let volume = await this.loadVolumeFromUrl(imageOptions);
112936
- this.addVolume(volume);
112937
- if (!this.mediaUrlMap.has(volume) && imageOptions.url) {
112938
- this.mediaUrlMap.set(volume, imageOptions.url);
112942
+ let volume2 = await this.loadVolumeFromUrl(imageOptions);
112943
+ this.addVolume(volume2);
112944
+ if (!this.mediaUrlMap.has(volume2) && imageOptions.url) {
112945
+ this.mediaUrlMap.set(volume2, imageOptions.url);
112939
112946
  if (this.isInSession && notifySubscribers) {
112940
112947
  this.serverConnection$.next(new NVMessage(ADD_VOLUME_URL, imageOptions, this.sessionKey));
112941
112948
  }
112942
112949
  }
112943
- return volume;
112950
+ return volume2;
112944
112951
  };
112945
112952
  Niivue.prototype.getMediaByUrl = function(url) {
112946
112953
  return [...this.mediaUrlMap.entries()].filter((v) => v[1] == url).map((v) => v[0]).pop();
112947
112954
  };
112948
112955
  Niivue.prototype.removeVolumeByUrl = function(url) {
112949
- let volume = this.getMediaByUrl(url);
112950
- if (volume) {
112951
- this.removeVolume(volume);
112956
+ let volume2 = this.getMediaByUrl(url);
112957
+ if (volume2) {
112958
+ this.removeVolume(volume2);
112952
112959
  }
112953
112960
  };
112954
112961
  Niivue.prototype.readDirectory = function(directory) {
@@ -112975,13 +112982,13 @@ Niivue.prototype.readDirectory = function(directory) {
112975
112982
  readEntries();
112976
112983
  } else {
112977
112984
  let allFileObects = await getFileObjects(allEntiresInDir);
112978
- let volume = await NVImage.loadFromFile({
112985
+ let volume2 = await NVImage.loadFromFile({
112979
112986
  file: allFileObects,
112980
112987
  name: directory.name,
112981
112988
  urlImgData: null,
112982
112989
  isDICOMDIR: true
112983
112990
  });
112984
- this.addVolume(volume);
112991
+ this.addVolume(volume2);
112985
112992
  }
112986
112993
  });
112987
112994
  };
@@ -113054,18 +113061,18 @@ Niivue.prototype.dropListener = async function(e) {
113054
113061
  entry.file(async (file) => {
113055
113062
  if (pairedImageData !== "") {
113056
113063
  pairedImageData.file(async (imgfile) => {
113057
- let volume = await NVImage.loadFromFile({
113064
+ let volume2 = await NVImage.loadFromFile({
113058
113065
  file,
113059
113066
  urlImgData: imgfile
113060
113067
  });
113061
- this.addVolume(volume);
113068
+ this.addVolume(volume2);
113062
113069
  });
113063
113070
  } else {
113064
- let volume = await NVImage.loadFromFile({
113071
+ let volume2 = await NVImage.loadFromFile({
113065
113072
  file,
113066
113073
  urlImgData: pairedImageData
113067
113074
  });
113068
- this.addVolume(volume);
113075
+ this.addVolume(volume2);
113069
113076
  }
113070
113077
  });
113071
113078
  } else if (entry.isDirectory) {
@@ -113109,11 +113116,11 @@ Niivue.prototype.setHighResolutionCapable = function(isHighResolutionCapable) {
113109
113116
  this.resizeListener();
113110
113117
  this.drawScene();
113111
113118
  };
113112
- Niivue.prototype.addVolume = function(volume) {
113113
- this.volumes.push(volume);
113119
+ Niivue.prototype.addVolume = function(volume2) {
113120
+ this.volumes.push(volume2);
113114
113121
  let idx = this.volumes.length === 1 ? 0 : this.volumes.length - 1;
113115
- this.setVolume(volume, idx);
113116
- this.opts.onImageLoaded(volume);
113122
+ this.setVolume(volume2, idx);
113123
+ this.opts.onImageLoaded(volume2);
113117
113124
  };
113118
113125
  Niivue.prototype.addMesh = function(mesh) {
113119
113126
  this.meshes.push(mesh);
@@ -113237,15 +113244,15 @@ Niivue.prototype.loadDrawing = async function(fnm) {
113237
113244
  if (this.drawBitmap)
113238
113245
  console.log("Overwriting open drawing!");
113239
113246
  this.drawClearAllUndoBitmaps();
113240
- let volume = await this.addVolumeFromUrl(new NVImageFromUrlOptions(fnm));
113241
- let dims = volume.hdr.dims;
113247
+ let volume2 = await this.addVolumeFromUrl(new NVImageFromUrlOptions(fnm));
113248
+ let dims = volume2.hdr.dims;
113242
113249
  if (dims[1] !== this.back.hdr.dims[1] || dims[2] !== this.back.hdr.dims[2] || dims[3] !== this.back.hdr.dims[3]) {
113243
113250
  console.log("drawing dimensions do not match background image");
113244
113251
  return false;
113245
113252
  }
113246
- if (volume.img.constructor !== Uint8Array)
113253
+ if (volume2.img.constructor !== Uint8Array)
113247
113254
  console.log("Drawings should be UINT8");
113248
- let perm = volume.permRAS;
113255
+ let perm = volume2.permRAS;
113249
113256
  let vx = dims[1] * dims[2] * dims[3];
113250
113257
  this.drawBitmap = new Uint8Array(vx);
113251
113258
  this.drawTexture = this.r8Tex(this.drawTexture, this.gl.TEXTURE7, this.back.dims, true);
@@ -113287,7 +113294,7 @@ Niivue.prototype.loadDrawing = async function(fnm) {
113287
113294
  zlut = range(dims[3] - 1, 0, -1);
113288
113295
  for (let i2 = 0; i2 < dims[3]; i2++)
113289
113296
  zlut[i2] *= instride[2];
113290
- let inVs = volume.img;
113297
+ let inVs = volume2.img;
113291
113298
  let outVs = this.drawBitmap;
113292
113299
  let j = 0;
113293
113300
  for (let z = 0; z < dims[3]; z++) {
@@ -113432,7 +113439,7 @@ Niivue.prototype.getOverlayIndexByID = function(id) {
113432
113439
  }
113433
113440
  return -1;
113434
113441
  };
113435
- Niivue.prototype.setVolume = function(volume, toIndex = 0) {
113442
+ Niivue.prototype.setVolume = function(volume2, toIndex = 0) {
113436
113443
  this.volumes.map((v) => {
113437
113444
  log.debug(v.name);
113438
113445
  });
@@ -113440,14 +113447,14 @@ Niivue.prototype.setVolume = function(volume, toIndex = 0) {
113440
113447
  if (toIndex > numberOfLoadedImages) {
113441
113448
  return;
113442
113449
  }
113443
- let volIndex = this.getVolumeIndexByID(volume.id);
113450
+ let volIndex = this.getVolumeIndexByID(volume2.id);
113444
113451
  if (toIndex === 0) {
113445
113452
  this.volumes.splice(volIndex, 1);
113446
- this.volumes.unshift(volume);
113453
+ this.volumes.unshift(volume2);
113447
113454
  this.back = this.volumes[0];
113448
113455
  this.overlays = this.volumes.slice(1);
113449
113456
  } else if (toIndex < 0) {
113450
- this.volumes.splice(this.getVolumeIndexByID(volume.id), 1);
113457
+ this.volumes.splice(this.getVolumeIndexByID(volume2.id), 1);
113451
113458
  this.back = this.volumes[0];
113452
113459
  if (this.volumes.length > 1) {
113453
113460
  this.overlays = this.volumes.slice(1);
@@ -113456,7 +113463,7 @@ Niivue.prototype.setVolume = function(volume, toIndex = 0) {
113456
113463
  }
113457
113464
  } else {
113458
113465
  this.volumes.splice(volIndex, 1);
113459
- this.volumes.splice(toIndex, 0, volume);
113466
+ this.volumes.splice(toIndex, 0, volume2);
113460
113467
  this.overlays = this.volumes.slice(1);
113461
113468
  this.back = this.volumes[0];
113462
113469
  }
@@ -113488,14 +113495,14 @@ Niivue.prototype.setMesh = function(mesh, toIndex = 0) {
113488
113495
  log.debug(m.name);
113489
113496
  });
113490
113497
  };
113491
- Niivue.prototype.removeVolume = function(volume, notifySubscribers = true) {
113492
- this.setVolume(volume, -1);
113493
- if (this.mediaUrlMap.has(volume)) {
113494
- let url = this.mediaUrlMap.get(volume);
113498
+ Niivue.prototype.removeVolume = function(volume2, notifySubscribers = true) {
113499
+ this.setVolume(volume2, -1);
113500
+ if (this.mediaUrlMap.has(volume2)) {
113501
+ let url = this.mediaUrlMap.get(volume2);
113495
113502
  if (notifySubscribers && this.isInSession) {
113496
113503
  this.serverConnection$.next(new NVMessage(REMOVE_VOLUME_URL, url, this.sessionKey));
113497
113504
  }
113498
- this.mediaUrlMap.delete(volume);
113505
+ this.mediaUrlMap.delete(volume2);
113499
113506
  }
113500
113507
  };
113501
113508
  Niivue.prototype.removeVolumeByIndex = function(index) {
@@ -113526,19 +113533,19 @@ Niivue.prototype.removeMesh = function(mesh, notifySubscribers = true) {
113526
113533
  }
113527
113534
  }
113528
113535
  };
113529
- Niivue.prototype.moveVolumeToBottom = function(volume) {
113530
- this.setVolume(volume, 0);
113536
+ Niivue.prototype.moveVolumeToBottom = function(volume2) {
113537
+ this.setVolume(volume2, 0);
113531
113538
  };
113532
- Niivue.prototype.moveVolumeUp = function(volume) {
113533
- let volIdx = this.getVolumeIndexByID(volume.id);
113534
- this.setVolume(volume, volIdx + 1);
113539
+ Niivue.prototype.moveVolumeUp = function(volume2) {
113540
+ let volIdx = this.getVolumeIndexByID(volume2.id);
113541
+ this.setVolume(volume2, volIdx + 1);
113535
113542
  };
113536
- Niivue.prototype.moveVolumeDown = function(volume) {
113537
- let volIdx = this.getVolumeIndexByID(volume.id);
113538
- this.setVolume(volume, volIdx - 1);
113543
+ Niivue.prototype.moveVolumeDown = function(volume2) {
113544
+ let volIdx = this.getVolumeIndexByID(volume2.id);
113545
+ this.setVolume(volume2, volIdx - 1);
113539
113546
  };
113540
- Niivue.prototype.moveVolumeToTop = function(volume) {
113541
- this.setVolume(volume, this.volumes.length - 1);
113547
+ Niivue.prototype.moveVolumeToTop = function(volume2) {
113548
+ this.setVolume(volume2, this.volumes.length - 1);
113542
113549
  };
113543
113550
  Niivue.prototype.mouseDown = function mouseDown(x2, y) {
113544
113551
  x2 *= this.scene.dpr;
@@ -113641,8 +113648,8 @@ Niivue.prototype.setClipPlaneColor = function(color) {
113641
113648
  this.gl.uniform4fv(this.renderShader.clipPlaneClrLoc, this.opts.clipPlaneColor);
113642
113649
  this.drawScene();
113643
113650
  };
113644
- Niivue.prototype.overlayRGBA = function(volume) {
113645
- let hdr = volume.hdr;
113651
+ Niivue.prototype.overlayRGBA = function(volume2) {
113652
+ let hdr = volume2.hdr;
113646
113653
  let vox = hdr.dims[1] * hdr.dims[2] * hdr.dims[3];
113647
113654
  let imgRGBA = new Uint8ClampedArray(vox * 4);
113648
113655
  let radius = 0.2 * Math.min(Math.min(hdr.dims[1], hdr.dims[2]), hdr.dims[3]);
@@ -113814,9 +113821,9 @@ Niivue.prototype.r16Tex = function(texID, activeID, dims, img16 = []) {
113814
113821
  this.gl.texSubImage3D(this.gl.TEXTURE_3D, 0, 0, 0, 0, dims[1], dims[2], dims[3], this.gl.RED_INTEGER, this.gl.SHORT, img16);
113815
113822
  return texID;
113816
113823
  };
113817
- function img2ras16(volume) {
113818
- let dims = volume.hdr.dims;
113819
- let perm = volume.permRAS;
113824
+ function img2ras16(volume2) {
113825
+ let dims = volume2.hdr.dims;
113826
+ let perm = volume2.permRAS;
113820
113827
  let vx = dims[1] * dims[2] * dims[3];
113821
113828
  let img16 = new Int16Array(vx);
113822
113829
  let layout = [0, 0, 0];
@@ -113861,7 +113868,7 @@ function img2ras16(volume) {
113861
113868
  for (let z = 0; z < dims[3]; z++) {
113862
113869
  for (let y = 0; y < dims[2]; y++) {
113863
113870
  for (let x2 = 0; x2 < dims[1]; x2++) {
113864
- img16[xlut[x2] + ylut[y] + zlut[z]] = volume.img[j];
113871
+ img16[xlut[x2] + ylut[y] + zlut[z]] = volume2.img[j];
113865
113872
  j++;
113866
113873
  }
113867
113874
  }
@@ -114958,6 +114965,7 @@ Niivue.prototype.setFrame4D = function(id, frame4D) {
114958
114965
  let url = this.mediaUrlMap.get(this.volumes[idx]);
114959
114966
  this.serverConnection$.next(new NVMessage(SET_4D_VOL_INDEX, new NVMessageSet4DVolumeIndexData(url, frame4D), this.sessionKey));
114960
114967
  }
114968
+ this.opts.onFrameChange({ volume, frame4D });
114961
114969
  };
114962
114970
  Niivue.prototype.getFrame4D = function(id) {
114963
114971
  let idx = this.getVolumeIndexByID(id);
@@ -115078,8 +115086,7 @@ Niivue.prototype.mouseClick = function(x2, y, posChange = 0, isDelta = true) {
115078
115086
  let pos = [x2 - this.graph.plotLTWH[0], y - this.graph.plotLTWH[1]];
115079
115087
  if (pos[0] > 0 && pos[1] > 0 && pos[0] <= this.graph.plotLTWH[2] && pos[1] <= this.graph.plotLTWH[3]) {
115080
115088
  let vol = Math.round(pos[0] / this.graph.plotLTWH[2] * (this.volumes[0].nFrame4D - 1));
115081
- this.volumes[0].frame4D = vol;
115082
- this.updateGLVolume();
115089
+ this.setFrame4D(this.volumes[0].id, vol);
115083
115090
  return;
115084
115091
  }
115085
115092
  }
@@ -115784,6 +115791,8 @@ Niivue.prototype.draw2DMM = function(leftTopWidthHeight, axCorSag, customMM = Na
115784
115791
  this.sliceMMShader.use(this.gl);
115785
115792
  gl.uniform1i(this.sliceMMShader.backgroundMasksOverlaysLoc, this.backgroundMasksOverlays);
115786
115793
  gl.uniform1f(this.sliceMMShader.drawOpacityLoc, this.drawOpacity);
115794
+ gl.enable(gl.BLEND);
115795
+ gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA);
115787
115796
  gl.uniform1f(this.sliceMMShader.opacityLoc, this.volumes[0].opacity);
115788
115797
  gl.uniform1i(this.sliceMMShader.axCorSagLoc, axCorSag);
115789
115798
  gl.uniform1f(this.sliceMMShader.sliceLoc, sliceFrac);
@@ -115813,7 +115822,6 @@ Niivue.prototype.draw2DMM = function(leftTopWidthHeight, axCorSag, customMM = Na
115813
115822
  this.drawSliceOrientationText(leftTopWidthHeight, axCorSag);
115814
115823
  this.readyForSync = true;
115815
115824
  };
115816
- Niivue.prototype.drawCro;
115817
115825
  Niivue.prototype.draw2DVox = function(leftTopWidthHeight, axCorSag, customMM = NaN) {
115818
115826
  let gl = this.gl;
115819
115827
  let fovMM = this.screenFieldOfViewMM(axCorSag);
@@ -115857,6 +115865,8 @@ Niivue.prototype.draw2DVox = function(leftTopWidthHeight, axCorSag, customMM = N
115857
115865
  isMirrorLR = !isMirrorLR;
115858
115866
  this.sliceShader.use(this.gl);
115859
115867
  gl.uniform1f(this.sliceShader.drawOpacityLoc, this.drawOpacity);
115868
+ gl.enable(gl.BLEND);
115869
+ gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA);
115860
115870
  gl.uniform1f(this.sliceShader.opacityLoc, this.volumes[0].opacity);
115861
115871
  gl.uniform1i(this.sliceShader.backgroundMasksOverlaysLoc, this.backgroundMasksOverlays);
115862
115872
  gl.uniform1i(this.sliceShader.axCorSagLoc, axCorSag);