@niivue/niivue 0.43.4 → 0.43.6

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/build/index.d.ts CHANGED
@@ -1176,6 +1176,7 @@ declare class NVMesh {
1176
1176
  createFiberDensityMap(): void;
1177
1177
  updateFibers(gl: WebGL2RenderingContext): void;
1178
1178
  indexNearestXYZmm(Xmm: number, Ymm: number, Zmm: number): number[];
1179
+ unloadMesh(gl: WebGL2RenderingContext): void;
1179
1180
  updateMesh(gl: WebGL2RenderingContext): void;
1180
1181
  reverseFaces(gl: WebGL2RenderingContext): void;
1181
1182
  setLayerProperty(id: number, key: keyof NVMeshLayer, val: number | string | boolean, gl: WebGL2RenderingContext): void;
@@ -1686,6 +1687,7 @@ declare class Niivue {
1686
1687
  private resizeObserver;
1687
1688
  syncOpts: Record<string, unknown>;
1688
1689
  readyForSync: boolean;
1690
+ centerMosaic: boolean;
1689
1691
  uiData: UIData;
1690
1692
  back: NVImage | null;
1691
1693
  overlays: NVImage[];
package/build/index.js CHANGED
@@ -13,7 +13,7 @@ var __publicField = (obj, key, value) => {
13
13
  import { mat4 as mat46, vec2, vec3 as vec311, vec4 as vec48 } from "gl-matrix";
14
14
 
15
15
  // package.json
16
- var version = "0.43.4";
16
+ var version = "0.43.6";
17
17
 
18
18
  // src/logger.ts
19
19
  var _Log = class _Log {
@@ -76,29 +76,12 @@ var log = new Log({ name: "niivue", level: "info" });
76
76
  // src/shader.ts
77
77
  var compileShader = function(gl, vert, frag) {
78
78
  const vs = gl.createShader(gl.VERTEX_SHADER);
79
- if (vs === null) {
80
- throw new Error("could not create vertex shader");
81
- }
82
79
  gl.shaderSource(vs, vert);
83
80
  gl.compileShader(vs);
84
- if (!gl.getShaderParameter(vs, gl.COMPILE_STATUS)) {
85
- log.error(gl.getShaderInfoLog(vs));
86
- throw new Error("Vertex shader failed to compile, see console for log");
87
- }
88
81
  const fs = gl.createShader(gl.FRAGMENT_SHADER);
89
- if (fs === null) {
90
- throw new Error("could not create fragment shader");
91
- }
92
82
  gl.shaderSource(fs, frag);
93
83
  gl.compileShader(fs);
94
- if (!gl.getShaderParameter(fs, gl.COMPILE_STATUS)) {
95
- log.error(gl.getShaderInfoLog(fs));
96
- throw new Error("Fragment shader failed to compile, see console for log");
97
- }
98
84
  const program = gl.createProgram();
99
- if (program === null) {
100
- throw new Error("could not create GL program");
101
- }
102
85
  gl.attachShader(program, vs);
103
86
  gl.attachShader(program, fs);
104
87
  gl.linkProgram(program);
@@ -15649,6 +15632,34 @@ var NVMesh2 = class _NVMesh {
15649
15632
  return [mnIdx, mnDx];
15650
15633
  }
15651
15634
  // indexNearestXYZmm()
15635
+ // internal function discards GPU resources
15636
+ unloadMesh(gl) {
15637
+ gl.bindBuffer(gl.ARRAY_BUFFER, null);
15638
+ gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, null);
15639
+ gl.bindVertexArray(null);
15640
+ gl.deleteBuffer(this.vertexBuffer);
15641
+ gl.deleteBuffer(this.indexBuffer);
15642
+ gl.deleteVertexArray(this.vao);
15643
+ gl.deleteVertexArray(this.vaoFiber);
15644
+ this.offsetPt0 = null;
15645
+ this.tris = null;
15646
+ this.pts = null;
15647
+ if (this.layers && this.layers.length > 0) {
15648
+ for (let i = 0; i < this.layers.length; i++) {
15649
+ this.layers[i].values = null;
15650
+ }
15651
+ }
15652
+ if (this.dpg && this.dpg.length > 0) {
15653
+ for (let i = 0; i < this.dpg.length; i++) {
15654
+ this.dpg[i].vals = null;
15655
+ }
15656
+ }
15657
+ if (this.dps && this.dps.length > 0) {
15658
+ for (let i = 0; i < this.dps.length; i++) {
15659
+ this.dps[i].vals = null;
15660
+ }
15661
+ }
15662
+ }
15652
15663
  // internal function filters mesh to identify which color of triangulated mesh vertices
15653
15664
  updateMesh(gl) {
15654
15665
  if (this.offsetPt0) {
@@ -22000,11 +22011,11 @@ var DEFAULT_OPTIONS = {
22000
22011
  var INITIAL_SCENE_DATA = {
22001
22012
  azimuth: 110,
22002
22013
  elevation: 10,
22003
- crosshairPos: vec38.fromValues(0.5, 0.5, 0.5),
22014
+ crosshairPos: vec38.create(),
22004
22015
  clipPlane: [0, 0, 0, 0],
22005
22016
  clipPlaneDepthAziElev: [2, 0, 0],
22006
22017
  volScaleMultiplier: 1,
22007
- pan2Dxyzmm: vec46.fromValues(0, 0, 0, 1),
22018
+ pan2Dxyzmm: vec46.create(),
22008
22019
  clipThick: 2,
22009
22020
  clipVolumeLow: [0, 0, 0],
22010
22021
  clipVolumeHigh: [1, 1, 1]
@@ -22033,7 +22044,11 @@ var NVDocument = class _NVDocument {
22033
22044
  },
22034
22045
  onZoom3DChange: () => {
22035
22046
  },
22036
- sceneData: { ...INITIAL_SCENE_DATA },
22047
+ sceneData: {
22048
+ ...INITIAL_SCENE_DATA,
22049
+ pan2Dxyzmm: vec46.fromValues(0, 0, 0, 1),
22050
+ crosshairPos: vec38.fromValues(0.5, 0.5, 0.5)
22051
+ },
22037
22052
  get renderAzimuth() {
22038
22053
  return this.sceneData.azimuth;
22039
22054
  },
@@ -23768,6 +23783,7 @@ var Niivue = class _Niivue {
23768
23783
  __publicField(this, "resizeObserver", null);
23769
23784
  __publicField(this, "syncOpts", {});
23770
23785
  __publicField(this, "readyForSync", false);
23786
+ __publicField(this, "centerMosaic", false);
23771
23787
  // UI Data
23772
23788
  __publicField(this, "uiData", {
23773
23789
  mousedown: false,
@@ -24231,7 +24247,7 @@ var Niivue = class _Niivue {
24231
24247
  */
24232
24248
  syncWith(otherNV, syncOpts = { "2d": true, "3d": true }) {
24233
24249
  this.otherNV = otherNV;
24234
- this.syncOpts = syncOpts;
24250
+ this.syncOpts = { ...syncOpts };
24235
24251
  }
24236
24252
  /**
24237
24253
  * Sync the scene controls (orientation, crosshair location, etc.) from one Niivue instance to others. useful for using one canvas to drive another.
@@ -24268,10 +24284,12 @@ var Niivue = class _Niivue {
24268
24284
  if (this.otherNV instanceof _Niivue) {
24269
24285
  if (this.syncOpts["2d"]) {
24270
24286
  this.otherNV.scene.crosshairPos = this.otherNV.mm2frac(thisMM);
24287
+ this.otherNV.scene.pan2Dxyzmm = vec48.clone(this.scene.pan2Dxyzmm);
24271
24288
  }
24272
24289
  if (this.syncOpts["3d"]) {
24273
24290
  this.otherNV.scene.renderAzimuth = this.scene.renderAzimuth;
24274
24291
  this.otherNV.scene.renderElevation = this.scene.renderElevation;
24292
+ this.otherNV.scene.volScaleMultiplier = this.scene.volScaleMultiplier;
24275
24293
  }
24276
24294
  this.otherNV.drawScene();
24277
24295
  this.otherNV.createOnLocationChange();
@@ -24282,10 +24300,12 @@ var Niivue = class _Niivue {
24282
24300
  }
24283
24301
  if (this.syncOpts["2d"]) {
24284
24302
  this.otherNV[i].scene.crosshairPos = this.otherNV[i].mm2frac(thisMM);
24303
+ this.otherNV[i].scene.pan2Dxyzmm = vec48.clone(this.scene.pan2Dxyzmm);
24285
24304
  }
24286
24305
  if (this.syncOpts["3d"]) {
24287
24306
  this.otherNV[i].scene.renderAzimuth = this.scene.renderAzimuth;
24288
24307
  this.otherNV[i].scene.renderElevation = this.scene.renderElevation;
24308
+ this.otherNV[i].scene.volScaleMultiplier = this.scene.volScaleMultiplier;
24289
24309
  }
24290
24310
  this.otherNV[i].drawScene();
24291
24311
  this.otherNV[i].createOnLocationChange();
@@ -26051,6 +26071,7 @@ var Niivue = class _Niivue {
26051
26071
  * @see {@link https://niivue.github.io/niivue/features/multiuser.meshes.html | live demo usage}
26052
26072
  */
26053
26073
  removeMesh(mesh) {
26074
+ mesh.unloadMesh(this.gl);
26054
26075
  this.setMesh(mesh, -1);
26055
26076
  if (this.mediaUrlMap.has(mesh)) {
26056
26077
  const url = this.mediaUrlMap.get(mesh);
@@ -32128,6 +32149,8 @@ var Niivue = class _Niivue {
32128
32149
  const items = mosaicStr.split(/\s+/);
32129
32150
  let scale = 1;
32130
32151
  const labelSize = this.opts.textHeight;
32152
+ let marginLeft = 0;
32153
+ let marginTop = 0;
32131
32154
  for (let pass = 0; pass < 2; pass++) {
32132
32155
  let isRender = false;
32133
32156
  let isCrossLines = false;
@@ -32203,7 +32226,7 @@ var Niivue = class _Niivue {
32203
32226
  }
32204
32227
  }
32205
32228
  } else {
32206
- const ltwh = [scale * left, scale * top, scale * w, scale * h];
32229
+ const ltwh = [marginLeft + scale * left, marginTop + scale * top, scale * w, scale * h];
32207
32230
  this.opts.textHeight = isLabel ? labelSize : 0;
32208
32231
  if (isRender) {
32209
32232
  let inf = sliceMM < 0 ? -Infinity : Infinity;
@@ -32231,6 +32254,10 @@ var Niivue = class _Niivue {
32231
32254
  const scaleW = this.gl.canvas.width / mxRowWid;
32232
32255
  const scaleH = this.effectiveCanvasHeight() / top;
32233
32256
  scale = Math.min(scaleW, scaleH);
32257
+ if (this.centerMosaic) {
32258
+ marginLeft = Math.floor(0.5 * (this.gl.canvas.width - mxRowWid * scale));
32259
+ marginTop = Math.floor(0.5 * (this.effectiveCanvasHeight() - top * scale));
32260
+ }
32234
32261
  }
32235
32262
  this.opts.textHeight = labelSize;
32236
32263
  }