@aics/vole-core 3.15.3 → 3.15.5

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/es/Line3d.js CHANGED
@@ -1,8 +1,8 @@
1
1
  import { Group, Vector3 } from "three";
2
- import { LineMaterial } from "three/addons/lines/LineMaterial";
3
- import { MESH_LAYER, OVERLAY_LAYER } from "./ThreeJsPanel";
4
- import { LineSegments2 } from "three/addons/lines/LineSegments2";
5
- import { LineSegmentsGeometry } from "three/addons/lines/LineSegmentsGeometry";
2
+ import { LineMaterial } from "three/addons/lines/LineMaterial.js";
3
+ import { MESH_LAYER, OVERLAY_LAYER } from "./ThreeJsPanel.js";
4
+ import { LineSegments2 } from "three/addons/lines/LineSegments2.js";
5
+ import { LineSegmentsGeometry } from "three/addons/lines/LineSegmentsGeometry.js";
6
6
  const DEFAULT_VERTEX_BUFFER_SIZE = 1020;
7
7
 
8
8
  /**
@@ -48,6 +48,7 @@ export class ThreeJsPanel {
48
48
  this.timestepIndicatorElement = document.createElement("div");
49
49
  this.showTimestepIndicator = false;
50
50
  this.animateFuncs = [];
51
+ this.postAnimateFuncs = [];
51
52
 
52
53
  // are we in a constant render loop or not?
53
54
  this.inRenderLoop = false;
@@ -572,6 +573,11 @@ export class ThreeJsPanel {
572
573
  this.renderer.render(this.axisHelperScene, this.axisCamera);
573
574
  this.renderer.autoClear = true;
574
575
  }
576
+ for (let i = 0; i < this.postAnimateFuncs.length; i++) {
577
+ if (this.postAnimateFuncs[i]) {
578
+ this.postAnimateFuncs[i](this.renderer, this.camera, this.meshRenderTarget.depthTexture);
579
+ }
580
+ }
575
581
  if (this.dataurlcallback) {
576
582
  this.dataurlcallback(this.canvas.toDataURL());
577
583
  this.dataurlcallback = undefined;
@@ -594,6 +600,7 @@ export class ThreeJsPanel {
594
600
  const delta = this.timer.lastFrameMs / 1000.0;
595
601
  this.controls.update(delta);
596
602
  this.render();
603
+ this.onRenderCallback?.();
597
604
  }
598
605
  startRenderLoop() {
599
606
  this.inRenderLoop = true;
@@ -610,6 +617,9 @@ export class ThreeJsPanel {
610
617
  }
611
618
  this.timer.end();
612
619
  }
620
+ setOnRenderCallback(callback) {
621
+ this.onRenderCallback = callback ?? undefined;
622
+ }
613
623
  removeControlHandlers() {
614
624
  if (this.controlStartHandler) {
615
625
  this.controls.removeEventListener("start", this.controlStartHandler);
package/es/View3d.js CHANGED
@@ -1,4 +1,4 @@
1
- import { AmbientLight, Vector3, Object3D, SpotLight, DirectionalLight, Euler, Scene, Color } from "three";
1
+ import { AmbientLight, Vector3, Object3D, SpotLight, DirectionalLight, Euler, Scene, Color, Matrix4 } from "three";
2
2
  import { Pane } from "tweakpane";
3
3
  import { MESH_LAYER, ThreeJsPanel } from "./ThreeJsPanel.js";
4
4
  import lightSettings from "./constants/lights.js";
@@ -107,6 +107,18 @@ export class View3d {
107
107
  this.redraw();
108
108
  }
109
109
 
110
+ /**
111
+ * Returns the view projection matrix, which transforms from world coordinates
112
+ * to clip space coordinates.
113
+ *
114
+ * 3D coordinates within the camera's view frustum will be transformed to a
115
+ * [-1, 1] range in the X and Y axes, and a [0, 1] range in the Z axis.
116
+ */
117
+ getViewProjectionMatrix() {
118
+ const camera = this.canvas3d.camera;
119
+ return new Matrix4().multiplyMatrices(camera.projectionMatrix, camera.matrixWorldInverse);
120
+ }
121
+
110
122
  /**
111
123
  * Force a redraw.
112
124
  * @param synchronous If true, the redraw will be done synchronously. If false (default), the
@@ -120,10 +132,18 @@ export class View3d {
120
132
  this.canvas3d.redraw();
121
133
  }
122
134
  }
135
+
136
+ /**
137
+ * Sets a listener that will be called after the 3D canvas renders.
138
+ */
139
+ setOnRenderCallback(callback) {
140
+ this.canvas3d.setOnRenderCallback(callback);
141
+ }
123
142
  unsetImage() {
124
143
  if (this.image) {
125
144
  this.canvas3d.removeControlHandlers();
126
145
  this.canvas3d.animateFuncs = [];
146
+ this.canvas3d.postAnimateFuncs = [];
127
147
  this.scene.remove(this.image.sceneRoot);
128
148
  }
129
149
  return this.image;
@@ -325,7 +345,11 @@ export class View3d {
325
345
  this.canvas3d.setControlHandlers(this.onStartControls.bind(this), this.onChangeControls.bind(this), this.onEndControls.bind(this));
326
346
  this.canvas3d.animateFuncs.push(this.preRender.bind(this));
327
347
  this.canvas3d.animateFuncs.push(img.onAnimate.bind(img));
328
- this.canvas3d.animateFuncs.push(img.fillPickBuffer.bind(img));
348
+ // NOTE: `fillPickBuffer` MUST run after render occurs. This is because the
349
+ // pick buffer needs to access the `meshRenderTarget`'s depth texture, but
350
+ // during a resize, the texture is disposed of and not recreated until the
351
+ // next render.
352
+ this.canvas3d.postAnimateFuncs.push(img.fillPickBuffer.bind(img));
329
353
  this.updatePerspectiveScaleBar(img.volume);
330
354
  this.updateTimestepIndicator(img.volume);
331
355
 
package/es/Volume.js CHANGED
@@ -14,13 +14,30 @@ export default class Volume {
14
14
  * Used to intelligently issue load requests whenever required by a state change. Modify with `updateRequiredData`.
15
15
  */
16
16
 
17
- /** The maximum of the measurements of 3 axes in physical units (pixels*physicalSize) */
17
+ /**
18
+ * The maximum of the measurements of 3 axes in physical units.
19
+ *
20
+ * Equivalent to `Math.max(physicalSize.x, physicalSize.y, physicalSize.z)`.
21
+ */
18
22
 
19
- /** The physical size of a voxel in the original level 0 volume */
23
+ /**
24
+ * The size of a voxel in the original level 0 volume in real-world (physical)
25
+ * units (e.g. μm).
26
+ */
20
27
 
21
- /** The physical dims of the whole volume (not accounting for subregion) */
28
+ /**
29
+ * The dimensions of the whole volume (not accounting for subregion) in
30
+ * real-world (physical) units. Equivalent to `imageInfo.originalSize *
31
+ * physicalPixelSize`.
32
+ */
22
33
 
23
- /** Normalized physical size of the whole volume (not accounting for subregion) */
34
+ /**
35
+ * Physical size of the whole volume (not accounting for subregion) normalized
36
+ * along the largest axis, so that all dimensions are `<= 1`.
37
+ *
38
+ * Example: If the physical size is `[100, 50, 25]` μm, then the
39
+ * normPhysicalSize will be `[1, 0.5, 0.25]`.
40
+ */
24
41
 
25
42
  constructor(imageInfo = defaultImageInfo(), loadSpec = new LoadSpec(), loader) {
26
43
  this.loaded = false;
@@ -1,5 +1,5 @@
1
1
  import { Color, Euler, Group, Vector3 } from "three";
2
- import { IDrawableObject } from "./types";
2
+ import { IDrawableObject } from "./types.js";
3
3
  /**
4
4
  * Simple wrapper for a 3D line segments object, with controls for vertex data,
5
5
  * color, width, and segments visible.
@@ -13,13 +13,15 @@ export type CameraState = {
13
13
  /** The scale value for the orthographic camera controls; undefined for perspective cameras. */
14
14
  orthoScale?: number;
15
15
  };
16
+ type AnimateFunction = (renderer: WebGLRenderer, camera: PerspectiveCamera | OrthographicCamera, depthTexture?: DepthTexture | null) => void;
16
17
  export declare class ThreeJsPanel {
17
18
  containerdiv: HTMLDivElement;
18
19
  private canvas;
19
20
  scene: Scene;
20
21
  private meshRenderTarget;
21
22
  private meshRenderToBuffer;
22
- animateFuncs: ((renderer: WebGLRenderer, camera: PerspectiveCamera | OrthographicCamera, depthTexture?: DepthTexture | null) => void)[];
23
+ animateFuncs: AnimateFunction[];
24
+ postAnimateFuncs: AnimateFunction[];
23
25
  private inRenderLoop;
24
26
  private requestedRender;
25
27
  hasWebGL2: boolean;
@@ -54,6 +56,7 @@ export declare class ThreeJsPanel {
54
56
  private timestepIndicatorElement;
55
57
  showTimestepIndicator: boolean;
56
58
  private dataurlcallback?;
59
+ private onRenderCallback?;
57
60
  constructor(parentElement: HTMLElement | undefined, _useWebGL2: boolean);
58
61
  updateCameraFocus(fov: number, _focalDistance: number, _apertureSize: number): void;
59
62
  resetPerspectiveCamera(): void;
@@ -103,7 +106,9 @@ export declare class ThreeJsPanel {
103
106
  onAnimationLoop(): void;
104
107
  startRenderLoop(): void;
105
108
  stopRenderLoop(): void;
109
+ setOnRenderCallback(callback: (() => void) | null): void;
106
110
  removeControlHandlers(): void;
107
111
  setControlHandlers(onstart: EventListener<Event, "start", TrackballControls>, onchange: EventListener<Event, "change", TrackballControls>, onend: EventListener<Event, "end", TrackballControls>): void;
108
112
  hitTest(offsetX: number, offsetY: number, pickBuffer: WebGLRenderTarget | undefined): number;
109
113
  }
114
+ export {};
@@ -1,3 +1,4 @@
1
+ import { Matrix4 } from "three";
1
2
  import { CameraState } from "./ThreeJsPanel.js";
2
3
  import VolumeDrawable from "./VolumeDrawable.js";
3
4
  import { Light } from "./Light.js";
@@ -53,6 +54,14 @@ export declare class View3d {
53
54
  getCanvasDOMElement(): HTMLCanvasElement;
54
55
  getCameraState(): CameraState;
55
56
  setCameraState(transform: Partial<CameraState>): void;
57
+ /**
58
+ * Returns the view projection matrix, which transforms from world coordinates
59
+ * to clip space coordinates.
60
+ *
61
+ * 3D coordinates within the camera's view frustum will be transformed to a
62
+ * [-1, 1] range in the X and Y axes, and a [0, 1] range in the Z axis.
63
+ */
64
+ getViewProjectionMatrix(): Matrix4;
56
65
  /**
57
66
  * Force a redraw.
58
67
  * @param synchronous If true, the redraw will be done synchronously. If false (default), the
@@ -60,6 +69,10 @@ export declare class View3d {
60
69
  * whenever possible for the best performance.
61
70
  */
62
71
  redraw(synchronous?: boolean): void;
72
+ /**
73
+ * Sets a listener that will be called after the 3D canvas renders.
74
+ */
75
+ setOnRenderCallback(callback: (() => void) | null): void;
63
76
  unsetImage(): VolumeDrawable | undefined;
64
77
  /**
65
78
  * Add a new volume image to the viewer. (The viewer currently only supports a single image at a time - adding repeatedly, without removing in between, is a potential resource leak)
@@ -30,13 +30,30 @@ export default class Volume {
30
30
  numChannels: number;
31
31
  channelNames: string[];
32
32
  channelColorsDefault: [number, number, number][];
33
- /** The maximum of the measurements of 3 axes in physical units (pixels*physicalSize) */
33
+ /**
34
+ * The maximum of the measurements of 3 axes in physical units.
35
+ *
36
+ * Equivalent to `Math.max(physicalSize.x, physicalSize.y, physicalSize.z)`.
37
+ */
34
38
  physicalScale: number;
35
- /** The physical size of a voxel in the original level 0 volume */
39
+ /**
40
+ * The size of a voxel in the original level 0 volume in real-world (physical)
41
+ * units (e.g. μm).
42
+ */
36
43
  physicalPixelSize: Vector3;
37
- /** The physical dims of the whole volume (not accounting for subregion) */
44
+ /**
45
+ * The dimensions of the whole volume (not accounting for subregion) in
46
+ * real-world (physical) units. Equivalent to `imageInfo.originalSize *
47
+ * physicalPixelSize`.
48
+ */
38
49
  physicalSize: Vector3;
39
- /** Normalized physical size of the whole volume (not accounting for subregion) */
50
+ /**
51
+ * Physical size of the whole volume (not accounting for subregion) normalized
52
+ * along the largest axis, so that all dimensions are `<= 1`.
53
+ *
54
+ * Example: If the physical size is `[100, 50, 25]` μm, then the
55
+ * normPhysicalSize will be `[1, 0.5, 0.25]`.
56
+ */
40
57
  normPhysicalSize: Vector3;
41
58
  normRegionSize: Vector3;
42
59
  normRegionOffset: Vector3;
@@ -1,4 +1,4 @@
1
- import { PrefetchDirection, TCZYX } from "./types";
1
+ import { PrefetchDirection, TCZYX } from "./types.js";
2
2
  type TZYX = [number, number, number, number];
3
3
  type PrefetchDirectionState = {
4
4
  direction: PrefetchDirection;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aics/vole-core",
3
- "version": "3.15.3",
3
+ "version": "3.15.5",
4
4
  "description": "volume renderer for 3d, 4d, or 5d imaging data with OME-Zarr support",
5
5
  "main": "es/index.js",
6
6
  "type": "module",