@aics/vole-core 3.12.4

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.
Files changed (141) hide show
  1. package/LICENSE.txt +26 -0
  2. package/README.md +119 -0
  3. package/es/Atlas2DSlice.js +224 -0
  4. package/es/Channel.js +264 -0
  5. package/es/FileSaver.js +31 -0
  6. package/es/FusedChannelData.js +192 -0
  7. package/es/Histogram.js +250 -0
  8. package/es/ImageInfo.js +127 -0
  9. package/es/Light.js +74 -0
  10. package/es/Lut.js +500 -0
  11. package/es/MarchingCubes.js +507 -0
  12. package/es/MeshVolume.js +334 -0
  13. package/es/NaiveSurfaceNets.js +251 -0
  14. package/es/PathTracedVolume.js +482 -0
  15. package/es/RayMarchedAtlasVolume.js +250 -0
  16. package/es/RenderToBuffer.js +31 -0
  17. package/es/ThreeJsPanel.js +633 -0
  18. package/es/Timing.js +28 -0
  19. package/es/TrackballControls.js +538 -0
  20. package/es/View3d.js +848 -0
  21. package/es/Volume.js +352 -0
  22. package/es/VolumeCache.js +161 -0
  23. package/es/VolumeDims.js +16 -0
  24. package/es/VolumeDrawable.js +702 -0
  25. package/es/VolumeMaker.js +101 -0
  26. package/es/VolumeRenderImpl.js +1 -0
  27. package/es/VolumeRenderSettings.js +203 -0
  28. package/es/constants/basicShaders.js +29 -0
  29. package/es/constants/colors.js +59 -0
  30. package/es/constants/denoiseShader.js +43 -0
  31. package/es/constants/lights.js +42 -0
  32. package/es/constants/materials.js +85 -0
  33. package/es/constants/pathtraceOutputShader.js +13 -0
  34. package/es/constants/scaleBarSVG.js +21 -0
  35. package/es/constants/time.js +34 -0
  36. package/es/constants/volumePTshader.js +153 -0
  37. package/es/constants/volumeRayMarchShader.js +123 -0
  38. package/es/constants/volumeSliceShader.js +115 -0
  39. package/es/index.js +21 -0
  40. package/es/loaders/IVolumeLoader.js +131 -0
  41. package/es/loaders/JsonImageInfoLoader.js +255 -0
  42. package/es/loaders/OmeZarrLoader.js +495 -0
  43. package/es/loaders/OpenCellLoader.js +65 -0
  44. package/es/loaders/RawArrayLoader.js +89 -0
  45. package/es/loaders/TiffLoader.js +219 -0
  46. package/es/loaders/VolumeLoadError.js +44 -0
  47. package/es/loaders/VolumeLoaderUtils.js +221 -0
  48. package/es/loaders/index.js +40 -0
  49. package/es/loaders/zarr_utils/ChunkPrefetchIterator.js +143 -0
  50. package/es/loaders/zarr_utils/WrappedStore.js +51 -0
  51. package/es/loaders/zarr_utils/types.js +24 -0
  52. package/es/loaders/zarr_utils/utils.js +225 -0
  53. package/es/loaders/zarr_utils/validation.js +49 -0
  54. package/es/test/ChunkPrefetchIterator.test.js +208 -0
  55. package/es/test/RequestQueue.test.js +442 -0
  56. package/es/test/SubscribableRequestQueue.test.js +244 -0
  57. package/es/test/VolumeCache.test.js +118 -0
  58. package/es/test/VolumeRenderSettings.test.js +71 -0
  59. package/es/test/lut.test.js +671 -0
  60. package/es/test/num_utils.test.js +140 -0
  61. package/es/test/volume.test.js +98 -0
  62. package/es/test/zarr_utils.test.js +358 -0
  63. package/es/types/Atlas2DSlice.d.ts +41 -0
  64. package/es/types/Channel.d.ts +44 -0
  65. package/es/types/FileSaver.d.ts +6 -0
  66. package/es/types/FusedChannelData.d.ts +26 -0
  67. package/es/types/Histogram.d.ts +57 -0
  68. package/es/types/ImageInfo.d.ts +87 -0
  69. package/es/types/Light.d.ts +27 -0
  70. package/es/types/Lut.d.ts +67 -0
  71. package/es/types/MarchingCubes.d.ts +53 -0
  72. package/es/types/MeshVolume.d.ts +40 -0
  73. package/es/types/NaiveSurfaceNets.d.ts +11 -0
  74. package/es/types/PathTracedVolume.d.ts +65 -0
  75. package/es/types/RayMarchedAtlasVolume.d.ts +41 -0
  76. package/es/types/RenderToBuffer.d.ts +17 -0
  77. package/es/types/ThreeJsPanel.d.ts +107 -0
  78. package/es/types/Timing.d.ts +11 -0
  79. package/es/types/TrackballControls.d.ts +51 -0
  80. package/es/types/View3d.d.ts +357 -0
  81. package/es/types/Volume.d.ts +152 -0
  82. package/es/types/VolumeCache.d.ts +43 -0
  83. package/es/types/VolumeDims.d.ts +28 -0
  84. package/es/types/VolumeDrawable.d.ts +108 -0
  85. package/es/types/VolumeMaker.d.ts +49 -0
  86. package/es/types/VolumeRenderImpl.d.ts +22 -0
  87. package/es/types/VolumeRenderSettings.d.ts +98 -0
  88. package/es/types/constants/basicShaders.d.ts +4 -0
  89. package/es/types/constants/colors.d.ts +2 -0
  90. package/es/types/constants/denoiseShader.d.ts +40 -0
  91. package/es/types/constants/lights.d.ts +38 -0
  92. package/es/types/constants/materials.d.ts +20 -0
  93. package/es/types/constants/pathtraceOutputShader.d.ts +11 -0
  94. package/es/types/constants/scaleBarSVG.d.ts +2 -0
  95. package/es/types/constants/time.d.ts +19 -0
  96. package/es/types/constants/volumePTshader.d.ts +137 -0
  97. package/es/types/constants/volumeRayMarchShader.d.ts +117 -0
  98. package/es/types/constants/volumeSliceShader.d.ts +109 -0
  99. package/es/types/glsl.d.js +0 -0
  100. package/es/types/index.d.ts +28 -0
  101. package/es/types/loaders/IVolumeLoader.d.ts +113 -0
  102. package/es/types/loaders/JsonImageInfoLoader.d.ts +80 -0
  103. package/es/types/loaders/OmeZarrLoader.d.ts +87 -0
  104. package/es/types/loaders/OpenCellLoader.d.ts +9 -0
  105. package/es/types/loaders/RawArrayLoader.d.ts +33 -0
  106. package/es/types/loaders/TiffLoader.d.ts +45 -0
  107. package/es/types/loaders/VolumeLoadError.d.ts +18 -0
  108. package/es/types/loaders/VolumeLoaderUtils.d.ts +38 -0
  109. package/es/types/loaders/index.d.ts +22 -0
  110. package/es/types/loaders/zarr_utils/ChunkPrefetchIterator.d.ts +22 -0
  111. package/es/types/loaders/zarr_utils/WrappedStore.d.ts +24 -0
  112. package/es/types/loaders/zarr_utils/types.d.ts +94 -0
  113. package/es/types/loaders/zarr_utils/utils.d.ts +23 -0
  114. package/es/types/loaders/zarr_utils/validation.d.ts +7 -0
  115. package/es/types/test/ChunkPrefetchIterator.test.d.ts +1 -0
  116. package/es/types/test/RequestQueue.test.d.ts +1 -0
  117. package/es/types/test/SubscribableRequestQueue.test.d.ts +1 -0
  118. package/es/types/test/VolumeCache.test.d.ts +1 -0
  119. package/es/types/test/VolumeRenderSettings.test.d.ts +1 -0
  120. package/es/types/test/lut.test.d.ts +1 -0
  121. package/es/types/test/num_utils.test.d.ts +1 -0
  122. package/es/types/test/volume.test.d.ts +1 -0
  123. package/es/types/test/zarr_utils.test.d.ts +1 -0
  124. package/es/types/types.d.ts +115 -0
  125. package/es/types/utils/RequestQueue.d.ts +112 -0
  126. package/es/types/utils/SubscribableRequestQueue.d.ts +52 -0
  127. package/es/types/utils/num_utils.d.ts +43 -0
  128. package/es/types/workers/VolumeLoaderContext.d.ts +106 -0
  129. package/es/types/workers/types.d.ts +101 -0
  130. package/es/types/workers/util.d.ts +3 -0
  131. package/es/types.js +75 -0
  132. package/es/typings.d.js +0 -0
  133. package/es/utils/RequestQueue.js +267 -0
  134. package/es/utils/SubscribableRequestQueue.js +187 -0
  135. package/es/utils/num_utils.js +231 -0
  136. package/es/workers/FetchTiffWorker.js +153 -0
  137. package/es/workers/VolumeLoadWorker.js +129 -0
  138. package/es/workers/VolumeLoaderContext.js +271 -0
  139. package/es/workers/types.js +41 -0
  140. package/es/workers/util.js +8 -0
  141. package/package.json +83 -0
@@ -0,0 +1,357 @@
1
+ import { CameraState } from "./ThreeJsPanel.js";
2
+ import VolumeDrawable from "./VolumeDrawable.js";
3
+ import { Light } from "./Light.js";
4
+ import Volume from "./Volume.js";
5
+ import { type VolumeChannelDisplayOptions, type VolumeDisplayOptions, ViewportCorner, RenderMode } from "./types.js";
6
+ import { PerChannelCallback } from "./loaders/IVolumeLoader.js";
7
+ import VolumeLoaderContext from "./workers/VolumeLoaderContext.js";
8
+ export declare const RENDERMODE_RAYMARCH = RenderMode.RAYMARCH;
9
+ export declare const RENDERMODE_PATHTRACE = RenderMode.PATHTRACE;
10
+ export interface View3dOptions {
11
+ parentElement?: HTMLElement;
12
+ useWebGL2?: boolean;
13
+ }
14
+ /**
15
+ * @class
16
+ */
17
+ export declare class View3d {
18
+ loaderContext?: VolumeLoaderContext;
19
+ private canvas3d;
20
+ private scene;
21
+ private backgroundColor;
22
+ private pixelSamplingRate;
23
+ private exposure;
24
+ private volumeRenderMode;
25
+ private renderUpdateListener?;
26
+ private loadErrorHandler?;
27
+ private image?;
28
+ private lights;
29
+ private lightContainer;
30
+ private ambientLight;
31
+ private spotLight;
32
+ private reflectedLight;
33
+ private fillLight;
34
+ private tweakpane;
35
+ /**
36
+ * @param {Object} options Optional options.
37
+ * @param {boolean} options.useWebGL2 Default true
38
+ * @param {HTMLElement} options.parentElement An optional element to which to append the viewer element on creation.
39
+ * The viewer will attempt to fill this element if provided.
40
+ */
41
+ constructor(options?: View3dOptions);
42
+ preRender(): void;
43
+ private updateOrthoScaleBar;
44
+ private updatePerspectiveScaleBar;
45
+ private updateTimestepIndicator;
46
+ /**
47
+ * Capture the contents of this canvas to a data url
48
+ * @param {Object} dataurlcallback function to call when data url is ready; function accepts dataurl as string arg
49
+ */
50
+ capture(dataurlcallback: (name: string) => void): void;
51
+ getDOMElement(): HTMLDivElement;
52
+ getCameraState(): CameraState;
53
+ setCameraState(transform: Partial<CameraState>): void;
54
+ /**
55
+ * Force a redraw.
56
+ */
57
+ redraw(): void;
58
+ unsetImage(): VolumeDrawable | undefined;
59
+ /**
60
+ * 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)
61
+ * @param {Volume} volume
62
+ * @param {VolumeDisplayOptions} options
63
+ */
64
+ addVolume(volume: Volume, options?: VolumeDisplayOptions): void;
65
+ /**
66
+ * Apply a set of display options to a given channel of a volume
67
+ * @param {Volume} volume
68
+ * @param {number} channelIndex the channel index
69
+ * @param {VolumeChannelDisplayOptions} options
70
+ */
71
+ setVolumeChannelOptions(volume: Volume, channelIndex: number, options: VolumeChannelDisplayOptions): void;
72
+ /**
73
+ * Apply a set of display options to the given volume
74
+ * @param {Volume} volume
75
+ * @param {VolumeDisplayOptions} options
76
+ */
77
+ setVolumeDisplayOptions(volume: Volume, options: VolumeDisplayOptions): void;
78
+ /**
79
+ * Remove a volume image from the viewer. This will clean up the View3D's resources for the current volume
80
+ * @param {Volume} volume
81
+ */
82
+ removeVolume(volume: Volume): void;
83
+ /**
84
+ * Remove all volume images from the viewer.
85
+ */
86
+ removeAllVolumes(): void;
87
+ /**
88
+ * @param {function} callback a function that will receive the number of render iterations when it changes
89
+ */
90
+ setRenderUpdateListener(callback: (iteration: number) => void): void;
91
+ onVolumeData(volume: Volume, channels: number[]): void;
92
+ onVolumeChannelAdded(volume: Volume, newChannelIndex: number): void;
93
+ onVolumeLoadError(volume: Volume, error: unknown): void;
94
+ setLoadErrorHandler(handler: ((volume: Volume, error: unknown) => void) | undefined): void;
95
+ setTime(volume: Volume, time: number, onChannelLoaded?: PerChannelCallback): void;
96
+ /**
97
+ * Nudge the scale level loaded into this volume off the one chosen by the loader.
98
+ * E.g. a bias of `1` will load 1 scale level lower than "ideal."
99
+ */
100
+ setScaleLevelBias(volume: Volume, scaleLevelBias: number): void;
101
+ /**
102
+ * Assign a channel index as a mask channel (will multiply its color against the entire visible volume)
103
+ * @param {Object} volume
104
+ * @param {number} maskChannelIndex
105
+ */
106
+ setVolumeChannelAsMask(volume: Volume, maskChannelIndex: number): void;
107
+ /**
108
+ * Set voxel dimensions - controls volume scaling. For example, the physical measurements of the voxels from a biological data set
109
+ * @param {Object} volume
110
+ * @param {number} values Array of x,y,z floating point values for the physical voxel size scaling
111
+ * @param {string} unit The unit of `values`, if different than previous
112
+ */
113
+ setVoxelSize(volume: Volume, values: number[], unit?: string): void;
114
+ setRayStepSizes(volume: Volume, primary: number, secondary: number): void;
115
+ setShowBoundingBox(volume: Volume, showBoundingBox: boolean): void;
116
+ setBoundingBoxColor(volume: Volume, color: [number, number, number]): void;
117
+ setBackgroundColor(color: [number, number, number]): void;
118
+ /**
119
+ * Is an isosurface already created for this channel?
120
+ * @param {Object} volume
121
+ * @param {number} channel
122
+ * @return true if there is currently a mesh isosurface for this channel
123
+ */
124
+ hasIsosurface(volume: Volume, channel: number): boolean;
125
+ /**
126
+ * Save a channel's isosurface as a triangle mesh to either STL or GLTF2 format. File will be named automatically, using image name and channel name.
127
+ * @param {Object} volume
128
+ * @param {number} channelIndex
129
+ * @param {string} type Either 'GLTF' or 'STL'
130
+ */
131
+ saveChannelIsosurface(volume: Volume, channelIndex: number, type: string): void;
132
+ setImage(img: VolumeDrawable): VolumeDrawable | undefined;
133
+ onStartControls(): void;
134
+ onChangeControls(): void;
135
+ onEndControls(): void;
136
+ buildScene(): void;
137
+ /**
138
+ * Change the camera projection to look along an axis, or to view in a 3d perspective camera.
139
+ * @param {string} mode Mode can be "3D", or "XY" or "Z", or "YZ" or "X", or "XZ" or "Y". 3D is a perspective view, and all the others are orthographic projections
140
+ */
141
+ setCameraMode(mode: string): void;
142
+ setZSlice(volume: Volume, slice: number): boolean;
143
+ /**
144
+ * Enable or disable 3d axis display at lower left.
145
+ * @param {boolean} showAxis
146
+ */
147
+ setShowAxis(showAxis: boolean): void;
148
+ /**
149
+ * Enable or disable scale indicators.
150
+ * @param showScaleBar
151
+ */
152
+ setShowScaleBar(showScaleBar: boolean): void;
153
+ /**
154
+ * Enable or disable time indicator.
155
+ * @param showTimestepIndicator
156
+ */
157
+ setShowTimestepIndicator(showIndicator: boolean): void;
158
+ /**
159
+ * Set the position of the axis indicator, as a corner of the viewport and horizontal and vertical margins from the
160
+ * edge of the viewport.
161
+ * @param {number} marginX
162
+ * @param {number} marginY
163
+ * @param {string} [corner] The corner of the viewport in which the axis appears. Default: `"bottom_left"`.
164
+ * TypeScript users should use the `ViewportCorner` enum. Otherwise, corner is one of: `"top_left"`, `"top_right"`,
165
+ * `"bottom_left"`, `"bottom_right"`.
166
+ */
167
+ setAxisPosition(marginX: number, marginY: number, corner?: ViewportCorner): void;
168
+ /**
169
+ * Set the position of the scale bar, as a corner of the viewport and horizontal and vertical margins from the edge
170
+ * of the viewport.
171
+ * @param {number} marginX
172
+ * @param {number} marginY
173
+ * @param {string} [corner] The corner of the viewport in which the scale bar appears. Default: `"bottom_right"`.
174
+ * TypeScript users should use the `ViewportCorner` enum. Otherwise, corner is one of: `"top_left"`, `"top_right"`,
175
+ * `"bottom_left"`, `"bottom_right"`.
176
+ */
177
+ setScaleBarPosition(marginX: number, marginY: number, corner?: ViewportCorner): void;
178
+ /**
179
+ * Set the position of the time step indicator, as a corner of the viewport and horizontal and vertical margins from
180
+ * the edge of the viewport.
181
+ * @param {number} marginX
182
+ * @param {number} marginY
183
+ * @param {string} [corner] The corner of the viewport in which the scale bar appears. Default: `"bottom_right"`.
184
+ * TypeScript users should use the `ViewportCorner` enum. Otherwise, corner is one of: `"top_left"`, `"top_right"`,
185
+ * `"bottom_left"`, `"bottom_right"`.
186
+ */
187
+ setTimestepIndicatorPosition(marginX: number, marginY: number, corner?: ViewportCorner): void;
188
+ /**
189
+ * Enable or disable a turntable rotation mode. The display will continuously spin about the vertical screen axis.
190
+ * @param {boolean} autorotate
191
+ */
192
+ setAutoRotate(autorotate: boolean): void;
193
+ /**
194
+ * Set the unit symbol for the scale bar (e.g. µm)
195
+ * @param {string} unit
196
+ */
197
+ setScaleUnit(unit: string): void;
198
+ /**
199
+ * Invert axes of volume. -1 to invert, +1 NOT to invert.
200
+ * @param {Object} volume
201
+ * @param {number} flipX x axis sense
202
+ * @param {number} flipY y axis sense
203
+ * @param {number} flipZ z axis sense
204
+ */
205
+ setFlipVolume(volume: Volume, flipX: -1 | 1, flipY: -1 | 1, flipZ: -1 | 1): void;
206
+ setInterpolationEnabled(volume: Volume, active: boolean): void;
207
+ /**
208
+ * Notify the view that it has been resized. This will automatically be connected to the window when the View3d is created.
209
+ * @param {HTMLElement=} comp Ignored.
210
+ * @param {number=} w Width, or parent element's offsetWidth if not specified.
211
+ * @param {number=} h Height, or parent element's offsetHeight if not specified.
212
+ * @param {number=} ow Ignored.
213
+ * @param {number=} oh Ignored.
214
+ * @param {Object=} eOpts Ignored.
215
+ */
216
+ resize(comp: HTMLElement | null, w?: number, h?: number, ow?: number, oh?: number, eOpts?: unknown): void;
217
+ /**
218
+ * Set the volume scattering density
219
+ * @param {Object} volume
220
+ * @param {number} density 0..1 UI slider value
221
+ */
222
+ updateDensity(volume: Volume, density: number): void;
223
+ /**
224
+ * Set the shading method - applies to pathtraced render mode only
225
+ * @param {Object} volume
226
+ * @param {number} isbrdf 0: brdf, 1: isotropic phase function, 2: mixed
227
+ */
228
+ updateShadingMethod(volume: Volume, isbrdf: boolean): void;
229
+ /**
230
+ * Set gamma levels: this affects the transparency and brightness of the single pass ray march volume render
231
+ * @param {Object} volume
232
+ * @param {number} gmin
233
+ * @param {number} glevel
234
+ * @param {number} gmax
235
+ */
236
+ setGamma(volume: Volume, gmin: number, glevel: number, gmax: number): void;
237
+ /**
238
+ * Set max projection on or off - applies to single pass raymarch render mode only
239
+ * @param {Object} volume
240
+ * @param {boolean} isMaxProject true for max project, false for regular volume ray march integration
241
+ */
242
+ setMaxProjectMode(volume: Volume, isMaxProject: boolean): void;
243
+ /**
244
+ * Notify the view that the set of active volume channels has been modified.
245
+ * @param {Object} volume
246
+ */
247
+ updateActiveChannels(_volume: Volume): void;
248
+ /**
249
+ * Notify the view that transfer function lookup table data has been modified.
250
+ * @param {Object} volume
251
+ */
252
+ updateLuts(_volume: Volume): void;
253
+ /**
254
+ * Notify the view that color and appearance settings have been modified.
255
+ * @param {Object} volume
256
+ */
257
+ updateMaterial(_volume: Volume): void;
258
+ /**
259
+ * Increase or decrease the overall brightness of the rendered image
260
+ * @param {number} e 0..1
261
+ */
262
+ updateExposure(e: number): void;
263
+ /**
264
+ * Set camera focus properties.
265
+ * @param {number} fov Vertical field of view in degrees
266
+ * @param {number} focalDistance view-space units for center of focus
267
+ * @param {number} apertureSize view-space units for radius of camera aperture
268
+ */
269
+ updateCamera(fov: number, focalDistance: number, apertureSize: number): void;
270
+ /**
271
+ * Set clipping range (between 0 and 1, relative to bounds) for the current volume.
272
+ * @param {Object} volume
273
+ * @param {number} xmin 0..1, should be less than xmax
274
+ * @param {number} xmax 0..1, should be greater than xmin
275
+ * @param {number} ymin 0..1, should be less than ymax
276
+ * @param {number} ymax 0..1, should be greater than ymin
277
+ * @param {number} zmin 0..1, should be less than zmax
278
+ * @param {number} zmax 0..1, should be greater than zmin
279
+ */
280
+ updateClipRegion(volume: Volume, xmin: number, xmax: number, ymin: number, ymax: number, zmin: number, zmax: number): void;
281
+ /**
282
+ * Set clipping range (between 0 and 1) for a given axis.
283
+ * Calling this allows the rendering to compensate for changes in thickness in orthographic views that affect how bright the volume is.
284
+ * @param {Object} volume
285
+ * @param {string} axis x, y, or z axis
286
+ * @param {number} minval 0..1, should be less than maxval
287
+ * @param {number} maxval 0..1, should be greater than minval
288
+ * @param {boolean} isOrthoAxis is this an orthographic projection or just a clipping of the range for perspective view
289
+ */
290
+ setAxisClip(volume: Volume, axis: "x" | "y" | "z", minval: number, maxval: number, isOrthoAxis: boolean): void;
291
+ /**
292
+ * Update lights
293
+ * @param {Array} state array of Lights
294
+ */
295
+ updateLights(state: Light[]): void;
296
+ /**
297
+ * Set a sampling rate to trade performance for quality.
298
+ * @param {number} value (+epsilon..1) 1 is max quality, ~0.1 for lowest quality and highest speed
299
+ */
300
+ updatePixelSamplingRate(value: number): void;
301
+ /**
302
+ * Set the opacity of the mask channel
303
+ * @param {Object} volume
304
+ * @param {number} value (0..1) 0 for full transparent, 1 for fully opaque
305
+ */
306
+ updateMaskAlpha(volume: Volume, value: number): void;
307
+ /**
308
+ * Show / hide volume channels
309
+ * @param {Object} volume
310
+ * @param {number} channel
311
+ * @param {boolean} enabled
312
+ */
313
+ setVolumeChannelEnabled(volume: Volume, channel: number, enabled: boolean): void;
314
+ /**
315
+ * Set the material for a channel
316
+ * @param {Object} volume
317
+ * @param {number} channelIndex
318
+ * @param {Array.<number>} colorrgb [r,g,b]
319
+ * @param {Array.<number>} specularrgb [r,g,b]
320
+ * @param {Array.<number>} emissivergb [r,g,b]
321
+ * @param {number} glossiness
322
+ */
323
+ updateChannelMaterial(volume: Volume, channelIndex: number, colorrgb: [number, number, number], specularrgb: [number, number, number], emissivergb: [number, number, number], glossiness: number): void;
324
+ /**
325
+ * Set the color for a channel
326
+ * @param {Object} volume
327
+ * @param {number} channelIndex
328
+ * @param {Array.<number>} colorrgb [r,g,b]
329
+ */
330
+ updateChannelColor(volume: Volume, channelIndex: number, colorrgb: [number, number, number]): void;
331
+ /**
332
+ * Switch between single pass ray-marched volume rendering and progressive path traced rendering.
333
+ * @param {RenderMode} mode RAYMARCH for single pass ray march, PATHTRACE for progressive path trace
334
+ */
335
+ setVolumeRenderMode(mode: RenderMode.PATHTRACE | RenderMode.RAYMARCH): void;
336
+ /**
337
+ *
338
+ * @param {Object} volume
339
+ * @param {Array.<number>} xyz
340
+ */
341
+ setVolumeTranslation(volume: Volume, xyz: [number, number, number]): void;
342
+ /**
343
+ *
344
+ * @param {Object} volume
345
+ * @param {Array.<number>} eulerXYZ
346
+ */
347
+ setVolumeRotation(volume: Volume, eulerXYZ: [number, number, number]): void;
348
+ setVolumeScale(volume: Volume, xyz: [number, number, number]): void;
349
+ /**
350
+ * Reset the camera to its default position
351
+ */
352
+ resetCamera(): void;
353
+ hasWebGL2(): boolean;
354
+ handleKeydown: (event: KeyboardEvent) => void;
355
+ removeEventListeners(): void;
356
+ private setupGui;
357
+ }
@@ -0,0 +1,152 @@
1
+ import { Vector3 } from "three";
2
+ import Channel from "./Channel.js";
3
+ import Histogram from "./Histogram.js";
4
+ import { Lut } from "./Lut.js";
5
+ import { type IVolumeLoader, LoadSpec, type PerChannelCallback } from "./loaders/IVolumeLoader.js";
6
+ import type { NumberType, TypedArray } from "./types.js";
7
+ import { type ImageInfo, CImageInfo } from "./ImageInfo.js";
8
+ interface VolumeDataObserver {
9
+ onVolumeData: (vol: Volume, batch: number[]) => void;
10
+ onVolumeChannelAdded: (vol: Volume, idx: number) => void;
11
+ onVolumeLoadError: (vol: Volume, error: unknown) => void;
12
+ }
13
+ /**
14
+ * A renderable multichannel volume image with 8-bits per channel intensity values.
15
+ * @class
16
+ * @param {ImageInfo} imageInfo
17
+ */
18
+ export default class Volume {
19
+ imageInfo: CImageInfo;
20
+ loadSpec: Required<LoadSpec>;
21
+ loader?: IVolumeLoader;
22
+ /** `LoadSpec` representing the minimum data required to display what's in the viewer (subregion, channels, etc.).
23
+ * Used to intelligently issue load requests whenever required by a state change. Modify with `updateRequiredData`.
24
+ */
25
+ loadSpecRequired: Required<LoadSpec>;
26
+ channelLoadCallback?: PerChannelCallback;
27
+ imageMetadata: Record<string, unknown>;
28
+ name: string;
29
+ channels: Channel[];
30
+ numChannels: number;
31
+ channelNames: string[];
32
+ channelColorsDefault: [number, number, number][];
33
+ /** The maximum of the measurements of 3 axes in physical units (pixels*physicalSize) */
34
+ physicalScale: number;
35
+ /** The physical size of a voxel in the original level 0 volume */
36
+ physicalPixelSize: Vector3;
37
+ /** The physical dims of the whole volume (not accounting for subregion) */
38
+ physicalSize: Vector3;
39
+ /** Normalized physical size of the whole volume (not accounting for subregion) */
40
+ normPhysicalSize: Vector3;
41
+ normRegionSize: Vector3;
42
+ normRegionOffset: Vector3;
43
+ physicalUnitSymbol: string;
44
+ tickMarkPhysicalLength: number;
45
+ private volumeDataObservers;
46
+ private loaded;
47
+ constructor(imageInfo?: ImageInfo, loadSpec?: LoadSpec, loader?: IVolumeLoader);
48
+ private setUnloaded;
49
+ isLoaded(): boolean;
50
+ updateDimensions(): void;
51
+ /** Returns `true` iff differences between `loadSpec` and `loadSpecRequired` indicate new data *must* be loaded. */
52
+ private mustLoadNewData;
53
+ /**
54
+ * Returns `true` iff differences between `loadSpec` and `loadSpecRequired` indicate a new load *may* get a
55
+ * different scale level than is currently loaded.
56
+ *
57
+ * This checks for changes in properties that *can*, but do not *always*, change the scale level the loader picks.
58
+ * For example, a smaller `subregion` *may* mean a higher scale level will fit within memory constraints, or it may
59
+ * not. A higher `scaleLevelBias` *may* nudge the volume into a higher scale level, or we may already be at the max
60
+ * imposed by `multiscaleLevel`.
61
+ */
62
+ private mayLoadNewScaleLevel;
63
+ /** Call on any state update that may require new data to be loaded (subregion, enabled channels, time, etc.) */
64
+ updateRequiredData(required: Partial<LoadSpec>, onChannelLoaded?: PerChannelCallback): Promise<void>;
65
+ private loadScaleLevelDims;
66
+ /**
67
+ * Loads new data as specified in `this.loadSpecRequired`. Clones `loadSpecRequired` into `loadSpec` to indicate
68
+ * that the data that *must* be loaded is now the data that *has* been loaded.
69
+ */
70
+ private loadNewData;
71
+ setVoxelSize(size: Vector3): void;
72
+ setUnitSymbol(symbol: string): void;
73
+ /** Computes the center of the volume subset */
74
+ getContentCenter(): Vector3;
75
+ cleanup(): void;
76
+ getChannel(channelIndex: number): Channel;
77
+ onChannelLoaded(batch: number[]): void;
78
+ /**
79
+ * Assign volume data via a 2d array containing the z slices as tiles across it. Assumes that the incoming data is consistent with the image's pre-existing imageInfo tile metadata.
80
+ * @param {number} channelIndex
81
+ * @param {Uint8Array} atlasdata
82
+ * @param {number} atlaswidth
83
+ * @param {number} atlasheight
84
+ */
85
+ setChannelDataFromAtlas(channelIndex: number, atlasdata: TypedArray<NumberType>, atlaswidth: number, atlasheight: number, range: [number, number], dtype?: NumberType): void;
86
+ /**
87
+ * Assign volume data as a 3d array ordered x,y,z. The xy size must be equal to tilewidth*tileheight from the imageInfo used to construct this Volume. Assumes that the incoming data is consistent with the image's pre-existing imageInfo tile metadata.
88
+ * @param {number} channelIndex
89
+ * @param {Uint8Array} volumeData
90
+ */
91
+ setChannelDataFromVolume(channelIndex: number, volumeData: TypedArray<NumberType>, range: [number, number], dtype?: NumberType): void;
92
+ /**
93
+ * Add a new channel ready to receive data from one of the setChannelDataFrom* calls.
94
+ * Name and color will be defaulted if not provided. For now, leave imageInfo alone as the "original" data
95
+ * @param {string} name
96
+ * @param {Array.<number>} color [r,g,b]
97
+ */
98
+ appendEmptyChannel(name: string, color?: [number, number, number]): number;
99
+ /**
100
+ * Get a value from the volume data
101
+ * @return {number} the intensity value from the given channel at the given xyz location
102
+ * @param {number} c The channel index
103
+ * @param {number} x
104
+ * @param {number} y
105
+ * @param {number} z
106
+ */
107
+ getIntensity(c: number, x: number, y: number, z: number): number;
108
+ /**
109
+ * Get the 256-bin histogram for the given channel
110
+ * @return {Histogram} the histogram
111
+ * @param {number} c The channel index
112
+ */
113
+ getHistogram(c: number): Histogram;
114
+ /**
115
+ * Set the lut for the given channel
116
+ * @param {number} c The channel index
117
+ * @param {Array.<number>} lut The lut as a 256 element array
118
+ */
119
+ setLut(c: number, lut: Lut): void;
120
+ /**
121
+ * Set the color palette for the given channel
122
+ * @param {number} c The channel index
123
+ * @param {Array.<number>} palette The colors as a 256 element array * RGBA
124
+ */
125
+ setColorPalette(c: number, palette: Uint8Array): void;
126
+ /**
127
+ * Set the color palette alpha multiplier for the given channel.
128
+ * This will blend between the ordinary color lut and this colorPalette lut.
129
+ * @param {number} c The channel index
130
+ * @param {number} alpha The alpha value as a number from 0 to 1
131
+ */
132
+ setColorPaletteAlpha(c: number, alpha: number): void;
133
+ /**
134
+ * Return the intrinsic rotation associated with this volume (radians)
135
+ * @return {Array.<number>} the xyz Euler angles (radians)
136
+ */
137
+ getRotation(): [number, number, number];
138
+ /**
139
+ * Return the intrinsic translation (pivot center delta) associated with this volume, in normalized volume units
140
+ * @return {Array.<number>} the xyz translation in normalized volume units
141
+ */
142
+ getTranslation(): [number, number, number];
143
+ /**
144
+ * Return a translation in normalized volume units, given a translation in image voxels
145
+ * @return {Array.<number>} the xyz translation in normalized volume units
146
+ */
147
+ voxelsToWorldSpace(xyz: [number, number, number]): [number, number, number];
148
+ addVolumeDataObserver(o: VolumeDataObserver): void;
149
+ removeVolumeDataObserver(o: VolumeDataObserver): void;
150
+ removeAllVolumeDataObservers(): void;
151
+ }
152
+ export {};
@@ -0,0 +1,43 @@
1
+ export default class VolumeCache {
2
+ private entries;
3
+ readonly maxSize: number;
4
+ private currentSize;
5
+ private first;
6
+ private last;
7
+ constructor(maxSize?: number);
8
+ /** The size of all data arrays currently stored in this cache, in bytes. */
9
+ get size(): number;
10
+ /** The number of entries currently stored in this cache. */
11
+ get numberOfEntries(): number;
12
+ /**
13
+ * Removes an entry from a store but NOT the LRU list.
14
+ * Only call from a method with the word "evict" in it!
15
+ */
16
+ private removeEntryFromStore;
17
+ /**
18
+ * Removes an entry from the LRU list but NOT its store.
19
+ * Entry must be replaced in list or removed from store, or it will never be evicted!
20
+ */
21
+ private removeEntryFromList;
22
+ /** Adds an entry which is *not currently in the list* to the front of the list. */
23
+ private addEntryAsFirst;
24
+ /** Moves an entry which is *currently in the list* to the front of the list. */
25
+ private moveEntryToFirst;
26
+ /** Evicts the least recently used entry from the cache. */
27
+ private evictLast;
28
+ /** Evicts a specific entry from the cache. */
29
+ private evict;
30
+ /**
31
+ * Adds a new entry to the cache.
32
+ * @returns {boolean} a boolean indicating whether the insertion succeeded.
33
+ */
34
+ insert(key: string, data: ArrayBuffer): boolean;
35
+ /** Internal implementation of `get`. Returns all entry metadata, not just the raw data. */
36
+ private getEntry;
37
+ /** Attempts to get a single entry from the cache. */
38
+ get(key: string): ArrayBuffer | undefined;
39
+ /** Clears all cache entries whose keys begin with the specified prefix. */
40
+ clearWithPrefix(prefix: string): void;
41
+ /** Clears all data from the cache. */
42
+ clear(): void;
43
+ }
@@ -0,0 +1,28 @@
1
+ import { type NumberType } from "./types.js";
2
+ import { Vector3 } from "three";
3
+ export type VolumeDims = {
4
+ shape: [number, number, number, number, number];
5
+ spacing: [number, number, number, number, number];
6
+ spaceUnit: string;
7
+ /**
8
+ * Symbol of temporal unit used by `spacing[0]`, e.g. "hr".
9
+ *
10
+ * If units match one of the following, the viewer will automatically format
11
+ * timestamps to a d:hh:mm:ss.sss format, truncated as an integer of the unit specified.
12
+ * See https://ngff.openmicroscopy.org/latest/index.html#axes-md for a list of valid time units.
13
+ * - "ms", "millisecond" for milliseconds: `d:hh:mm:ss.sss`
14
+ * - "s", "sec", "second", or "seconds" for seconds: `d:hh:mm:ss`
15
+ * - "m", "min", "minute", or "minutes" for minutes: `d:hh:mm`
16
+ * - "h", "hr", "hour", or "hours" for hours: `d:hh`
17
+ * - "d", "day", or "days" for days: `d`
18
+ *
19
+ * The maximum timestamp value is used to determine the maximum unit shown.
20
+ * For example, if the time unit is in seconds, and the maximum time is 90 seconds, the timestamp
21
+ * will be formatted as "{m:ss} (m:s)", and the day and hour segments will be omitted.
22
+ */
23
+ timeUnit: string;
24
+ dataType: NumberType;
25
+ };
26
+ export declare function defaultVolumeDims(): VolumeDims;
27
+ export declare function volumeSize(volumeDims: VolumeDims): Vector3;
28
+ export declare function physicalPixelSize(volumeDims: VolumeDims): Vector3;