@niivue/niivue 0.44.2-dev.1 → 0.44.2-dev.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@niivue/niivue",
3
- "version": "0.44.2-dev.1",
3
+ "version": "0.44.2-dev.2",
4
4
  "description": "minimal webgl2 nifti image viewer",
5
5
  "types": "./build/index.d.ts",
6
6
  "main": "./build/index.js",
@@ -104,10 +104,19 @@
104
104
  drawBtn.onclick = function () {
105
105
  nv1.setDrawingEnabled(!nv1.opts.drawingEnabled)
106
106
  if (nv1.opts.drawingEnabled) {
107
+ nv1.drawOpacity = 0.4
107
108
  nv1.opts.clickToSegment = true;
108
109
  nv1.setPenValue(penColor, false) // red and filled
110
+ // hide the crosshair
111
+ nv1.opts.crosshairWidth = 0;
112
+ // hide the mouse cursor
113
+ nv1.canvas.style.cursor = "none";
109
114
  } else {
110
115
  nv1.opts.clickToSegment = false;
116
+ // show the crosshair
117
+ nv1.opts.crosshairWidth = 1;
118
+ // show the mouse cursor
119
+ nv1.canvas.style.cursor = "default";
111
120
  }
112
121
  }
113
122
  growBtn.onclick = function () {
@@ -121,6 +130,12 @@
121
130
  }
122
131
 
123
132
  const onDragRelease = (data) => {
133
+ // if there is a div with the id dragReleaseDiv, remove it
134
+ const divToRemove = document.getElementById("dragReleaseDiv");
135
+ if (divToRemove) {
136
+ divToRemove.remove();
137
+ }
138
+
124
139
  console.log("drag release", data);
125
140
  let obj = nv1.getDescriptives({
126
141
  layer: 0,
@@ -129,37 +144,90 @@
129
144
  roiIsMask: true,
130
145
  });
131
146
  console.log(obj);
147
+ // get dpr
148
+ const dpr = window.devicePixelRatio;
149
+ // get mouse x,y. Divide by dpr to get the correct position
150
+ const x = nv1.uiData.dragEnd[0] / dpr;
151
+ const y = nv1.uiData.dragEnd[1] / dpr;
152
+ console.log(x, y);
153
+ const pad = 5;
154
+ const div = document.createElement("div");
155
+ // set id for removal on the next pass
156
+ div.id = "dragReleaseDiv";
157
+ div.style.color = "red";
158
+ div.style.position = "absolute";
159
+ div.style.backgroundColor = "black";
160
+ div.style.opacity = 0.8;
161
+ div.style.padding = "5px";
162
+ // set z-index to be well above the canvas
163
+ div.style.zIndex = 1000;
164
+ div.innerHTML = `Mean: ${obj.mean}<br>Area: ${obj.area}<br>Stdev: ${obj.stdev}`;
165
+ // set position to be at the mouse x,y relative to the canvas
166
+ div.style.left = x + pad + "px";
167
+ div.style.top = y + pad + "px";
168
+ // get the canvas element reference from niivue
169
+ const canvas = nv1.gl.canvas;
170
+ // niivue should always be in a container, so get the parent of the canvas
171
+ const parentDiv = canvas.parentElement;
172
+ parentDiv.appendChild(div);
173
+ };
174
+
175
+ const onLocationChange = (data) => {
176
+ // remove the stats div if it exists when the user clicks away
177
+ const divToRemove = document.getElementById("dragReleaseDiv");
178
+ if (divToRemove) {
179
+ divToRemove.remove();
180
+ }
181
+ // console.log(data.string)
132
182
  };
133
183
 
134
- var volumeList1 = [{ url: "../demos/images/FLAIR.nii.gz" }];
184
+
185
+ var volumeList1 = [
186
+ { url: "../demos/images/FLAIR.nii.gz" },
187
+ ];
188
+ let clicks = 0;
189
+ const defaultPercent = 0.02;
135
190
  let defaults = {
136
191
  backColor: [0, 0, 0, 1],
137
192
  show3Dcrosshair: true,
138
193
  loglevel: 'debug',
139
194
  isRuler: true,
140
195
  clickToSegmentRadius: 3, // in mm
141
- clickToSegmentPercent: 0.2,
196
+ clickToSegmentPercent: defaultPercent,
142
197
  clickToSegmentAutoIntensity: true,
143
- clickToSegmentMaxDistanceMM: 10,
198
+ clickToSegmentMaxDistanceMM: 50,
199
+ clickToSegmentIs2D: true,
200
+ floodFillNeighbors: 6,
144
201
  penSize: 3, // in voxels, but overridden by clickToSegmentRadius
145
- maxDrawUndoBitmaps: 30,
202
+ maxDrawUndoBitmaps: 100, // large number for undo
146
203
  onDragRelease: onDragRelease,
204
+ onLocationChange: onLocationChange,
147
205
  selectionBoxColor: [1, 0, 0, 0.5],
148
206
  dragMode: DRAG_MODE.roiSelection,
149
- selectionBoxIsOutline: true
207
+ selectionBoxIsOutline: true,
208
+ scrollRequiresFocus: false
150
209
  };
151
210
  var nv1 = new Niivue(defaults);
152
211
  nv1.attachToCanvas(gl1);
153
- // multiplanarShowRender is the preferred option now,
154
- // but multiplanarForceRender is still available for backwards compatibility
155
- // previous use was: nv1.opts.multiplanarForceRender = true;
156
212
  nv1.opts.multiplanarShowRender = SHOW_RENDER.AUTO
213
+ nv1.setSliceType(0)
214
+ nv1.setInterpolation(false)
157
215
  await nv1.loadVolumes(volumeList1);
158
216
  equalCheck.onchange()
159
217
 
160
- // set drawing enabled
161
- // nv1.setDrawingEnabled(true);
162
- // nv1.setPenValue(1, true) // red and filled
218
+ // store mouse position
219
+ const mouse = { x: 0, y: 0 };
220
+
221
+ // when the user presses "t" toggle the overlay opacity between 0 and 1
222
+ document.addEventListener("keydown", (e) => {
223
+ if (e.key === "t") {
224
+ if (nv1.volumes.length < 2) {
225
+ return;
226
+ }
227
+ const currentOpacity = nv1.volumes[1].opacity;
228
+ nv1.setOpacity(1, currentOpacity === 0 ? 0.5 : 0);
229
+ }
230
+ });
163
231
  </script>
164
232
  </body>
165
233
  </html>
@@ -70,10 +70,18 @@
70
70
  </select>
71
71
  <label for="syncDrop"> Broadcast</label>
72
72
  <select id="syncDrop">
73
- <option value="0">Sync Disabled</option>
74
- <option value="1">Sync 2D</option>
75
- <option value="2">Sync 3D</option>
76
- <option value="3" selected>Sync 2D and 3D</option>
73
+ <option value="disabled">Sync Disabled</option>
74
+ <option value="2d">Sync 2D</option>
75
+ <option value="3d">Sync 3D</option>
76
+ <option value="crosshair" selected>crosshair</option>
77
+ <option value="zoomPan">zoomPan</option>
78
+ <option value="gamma">gamma</option>
79
+ <option value="sliceType">sliceType</option>
80
+ <option value="clipPlane">clipPlane</option>
81
+ <option value="cal_min">cal_min</option>
82
+ <option value="cal_max">cal_max</option>
83
+ <!-- everything -->
84
+ <option value="all">all except intensity</option>
77
85
  </select>
78
86
  <!-- slider for gamma -->
79
87
  <label for="gammaSlider">Gamma</label>
@@ -171,19 +179,54 @@
171
179
  nv1.gl.canvas.blur()
172
180
  }
173
181
 
174
- syncDrop.onchange = function() {
175
- const v = parseInt(syncDrop.value)
176
- let is2D = false
177
- let is3D = false
178
- if (v % 2) {
179
- is2D = true
182
+ syncDrop.onchange = function(e) {
183
+ const v = e.target.value
184
+ // let is2D = false
185
+ // let is3D = false
186
+ // if (v % 2) {
187
+ // is2D = true
188
+ // }
189
+ // if (v > 1) {
190
+ // is3D = true
191
+ // }
192
+
193
+ // check if v === "all", if so, add everything
194
+ if (v === "all") {
195
+ nv1.broadcastTo([nv2, nv3], {
196
+ ['3d']: true,
197
+ crosshair: true,
198
+ zoomPan: true,
199
+ gamma: true,
200
+ sliceType: true,
201
+ clipPlane: true,
202
+ // cal_min: true,
203
+ // cal_max: true,
204
+ })
205
+ nv2.broadcastTo([nv1, nv3], {
206
+ ['3d']: true,
207
+ crosshair: true,
208
+ zoomPan: true,
209
+ gamma: true,
210
+ sliceType: true,
211
+ clipPlane: true,
212
+ // cal_min: true,
213
+ // cal_max: true,
214
+ })
215
+ nv3.broadcastTo([nv1, nv2], {
216
+ ['3d']: true,
217
+ crosshair: true,
218
+ zoomPan: true,
219
+ gamma: true,
220
+ sliceType: true,
221
+ clipPlane: true,
222
+ // cal_min: true,
223
+ // cal_max: true,
224
+ })
225
+ return
180
226
  }
181
- if (v > 1) {
182
- is3D = true
183
- }
184
- nv1.broadcastTo([nv2, nv3], { "2d": is2D, "3d": is3D })
185
- nv2.broadcastTo([nv1, nv3], { "2d": is2D, "3d": is3D })
186
- nv3.broadcastTo([nv1, nv2], { "2d": is2D, "3d": is3D })
227
+ nv1.broadcastTo([nv2, nv3], { [v]: true })
228
+ nv2.broadcastTo([nv1, nv3], { [v]: true })
229
+ nv3.broadcastTo([nv1, nv2], { [v]: true })
187
230
  }
188
231
 
189
232
  calMin.onchange = function() {
@@ -229,9 +272,10 @@
229
272
  show3Dcrosshair: true,
230
273
  onLocationChange: handleIntensityChange,
231
274
  backColor: [1, 1, 1, 1],
232
- // dragMode: 3,
275
+ dragMode: 3,
233
276
  sliceType: 3,
234
- multiplanarShowRender: SHOW_RENDER.ALWAYS
277
+ multiplanarShowRender: SHOW_RENDER.ALWAYS,
278
+ isRadiologicalConvention: true
235
279
  });
236
280
  nv1.attachTo("gl1");
237
281
  var volumeList1 = [{ url: "../demos/images/pcasl.nii.gz" }];
@@ -240,7 +284,7 @@
240
284
  show3Dcrosshair: true,
241
285
  onLocationChange: handleIntensityChange2,
242
286
  backColor: [1, 1, 1, 1],
243
- // dragMode: 3,
287
+ dragMode: 3,
244
288
  sliceType: 3,
245
289
  multiplanarShowRender: SHOW_RENDER.ALWAYS
246
290
  });
@@ -249,7 +293,7 @@
249
293
  show3Dcrosshair: true,
250
294
  onLocationChange: handleIntensityChange3,
251
295
  backColor: [1, 1, 1, 1],
252
- // dragMode: 0,
296
+ dragMode: 0,
253
297
  sliceType: 3,
254
298
  multiplanarShowRender: SHOW_RENDER.ALWAYS
255
299
  });