Repository navigation
Conversation
| } | ||
|
|
||
| async loadRawChannelData( | ||
| async loadData( |
There was a problem hiding this comment.
Is this API surfaced to external clients? Do you have plans to make any kind of migration guide from v4 to v5?
There was a problem hiding this comment.
It is, though the idea of this batch of work is that external clients ought to not call it at all anymore. Which is an even larger change and an even bigger migration effort! I'm not certain where a migration guide would go though. As a .md built on our docs page?
There was a problem hiding this comment.
We could literally rebuild every single pre-existing json+PNG volume from their original data and put them into zarrs. It's nearly impossible this format exists anywhere else outside of Allen. (except that strangely, the OpenCell data set is strikingly similar).
Either way, this is a legacy data format and vol-e should make as few concessions as possible to handle it. The stuff in this module can not influence vol-e 👿
| import { VolumeDims } from "../VolumeDims.js"; | ||
| import { CreateLoaderOptions, PrefetchDirection, VolumeFileFormat, pathToFileType } from "../loaders/index.js"; | ||
| import { VolumeLoader, LoadSpec, RawChannelDataCallback, LoadedVolumeInfo } from "../loaders/VolumeLoader.js"; | ||
| import type { VolumeLoader, LoadSpec, RawChannelDataCallback, LoadedVolumeInfo } from "../loaders/VolumeLoader.js"; |
There was a problem hiding this comment.
We should really install some plugins to do this for us...
There was a problem hiding this comment.
I've really been feeling this repo's lack of import sorting and type-import validation lately. Might track you down for help putting those things in place later.
| // TODO pass in load specs here? | ||
| const { loadSpec, imageInfo } = loader.getImageInfo(infoSpec); |
There was a problem hiding this comment.
What does the TODO here mean? Is it still relevant?
There was a problem hiding this comment.
I... have no idea. Looks like I added this whole function in one commit, so best guess it was a note I left for myself while I was working on that? I'll get rid of it.
| this.loader = loader; | ||
| // TODO pass in load specs here? | ||
| const { loadSpec, imageInfo } = loader.getImageInfo(infoSpec); | ||
| this.imageInfo.imageInfo = imageInfo; |
There was a problem hiding this comment.
Nit: slightly unfortunate variable + property naming here
There was a problem hiding this comment.
Yeah, I'm not a huge fan of this, but that's how CImageInfo works right now.
(I do think, someday soon, we gotta kill CImageInfo.)
There was a problem hiding this comment.
Yeah, the imageInfo data structure is an old metadata spec totally invented by me for the json+PNG precomputed volume data. It could be replaced by the standard OME data model, or some better thing that suits vol-e better, or nothing at all?
d5f1891 to
971e8c5
Compare
83318e6 to
09e674e
Compare
| } | ||
|
|
||
| function playTimeSeries(onNewFrameCallback: () => void) { | ||
| if (myState.isPlaying) { |
There was a problem hiding this comment.
I remember my youth, when myState.isPlaying == true
toloudis
left a comment
There was a problem hiding this comment.
This is looking really nice now. I had lots of comments/questions but my main concern is just the handling of single channels vs arrays of channels, whether that allows for good performance.
| const spec = { ...volume.loadSpec, ...loadSpecOverride }; | ||
| return this.loadRawChannelData(volume.imageInfo.imageInfo, spec, onUpdateMetadata, onChannelData); | ||
| } | ||
| updateFetchOptions(options: Partial<ZarrLoaderFetchOptions>): void; |
| /** | ||
| * @deprecated Will be removed in the next major version. | ||
| * Use `Volume.addEventListener("loadError", (event) => { ... }) instead. | ||
| */ |
There was a problem hiding this comment.
hmm, should errors be events like everything else? just a tiny code smell, for me. I guess if we were passing in an error handler before, then it makes sense.
| volume.addEventListener("loadChannel", this.onVolumeData); | ||
| volume.addEventListener("loadError", this.onVolumeLoadError); | ||
| volume.addEventListener("channelAdded", this.onVolumeChannelAdded); | ||
| volume.addEventListener("channelRemoved", this.onVolumeChannelRemoved); |
There was a problem hiding this comment.
this pattern looks like it breaks the multi-volume nature of the View3D api. do each of the mapped listeners check that the current volume matches volume ?
|
|
||
| // channels is an array of channel indices for which new data just arrived. | ||
| onVolumeData(volume: Volume, channels: number[]): void { | ||
| onVolumeData({ volume, channelIndex }: VolumeEvents["loadChannel"]): void { |
There was a problem hiding this comment.
I guess this should do a sanity check that this.image.volume === volume? or some equivalent check...
| loadEnd: VolumeEvent; | ||
| loadError: VolumeEvent<{ error: unknown }>; | ||
| channelAdded: VolumeEvent<{ channelIndex: number }>; | ||
| channelRemoved: VolumeEvent<{ channelIndex: number }>; |
There was a problem hiding this comment.
I think in a previous review I recommended that this be the place where each event gets its documentation/description of what it means.
Also, might it make sense to have loadChannel potentially send an array of channels that all arrived at the same time? The handler of loadChannel might incur some relatively heavy UI updates and they might happen in rapid succession causing redraws. Testing would reveal this
| this.loader = loader; | ||
| // TODO pass in load specs here? | ||
| const { loadSpec, imageInfo } = loader.getImageInfo(infoSpec); | ||
| this.imageInfo.imageInfo = imageInfo; |
There was a problem hiding this comment.
Yeah, the imageInfo data structure is an old metadata spec totally invented by me for the json+PNG precomputed volume data. It could be replaced by the standard OME data model, or some better thing that suits vol-e better, or nothing at all?
| } catch (e) { | ||
| this.volumeDataObservers.forEach((observer) => observer.onVolumeLoadError(this, e)); | ||
| throw e; | ||
| await this.loader?.loadData( |
There was a problem hiding this comment.
Question: does this await force us to wait for all channels to be loaded, ie. does it prevent incremental loading, say, per-channel? is this Volume.load the main api for causing volume data to be loaded?
| if (channelOptions.isosurfaceEnabled) { | ||
| this.meshVolume.destroyIsosurface(idx); | ||
| const { isovalue, isosurfaceOpacity } = channelOptions; | ||
| this.meshVolume.createIsosurface(idx, this.channelColors[idx], isovalue, isosurfaceOpacity); |
There was a problem hiding this comment.
just curious, where did the onChannelDataReadyCalback go? was it doing anything ?
| } | ||
|
|
||
| async loadRawChannelData( | ||
| async loadData( |
There was a problem hiding this comment.
We could literally rebuild every single pre-existing json+PNG volume from their original data and put them into zarrs. It's nearly impossible this format exists anywhere else outside of Allen. (except that strangely, the OpenCell data set is strikingly similar).
Either way, this is a legacy data format and vol-e should make as few concessions as possible to handle it. The stuff in this module can not influence vol-e 👿
| volume.channelLoadCallback = onChannelDataArrived; | ||
| loader.loadVolumeData(volume, { ...volume.loadSpec, channels }); | ||
| volume.addEventListener("loadChannel", ({ channelIndex }) => onChannelDataArrived(volume, channelIndex)); | ||
| volume.load(); |
There was a problem hiding this comment.
just looking at this, it feels scary to just call "load" on a new volume like this. what is going to be loaded? was that all set up inside of onVolumeCreated? That must be where the initial loadSpec is set up. Maybe it would be more instructive/educational to see it more explicit in this function.
Review time: medium (~30min)
This PR takes the final step in this stack's aim to make our new event model (#448) the preferred way to observe the volume lifecycle.
It contains several semi-related refactors:
loadVolumeDatafrom theVolumeLoaderabstract class. This method called the lower-levelloadRawChannelDatamethod, then put the data in the passedVolume. With this gone,VolumeLoaderis philosophically more like a file system handle: it retrieves metadata about the data it points to synchronously and retrieves data asynchronously, but does not take any action with that data on its own. It also contains no meaningful behavior to justify being anabstract classrather than aninterface, so now it's just aninterface.Volume:loadChannel,loadEnd,loadError,channelAdded,channelRemoved. These should be how client code responds to the volume's load cycle going forward, rather than initiating loads themselves via aVolumeLoaderand passing a callback.Volumea bit to be more of a container/controller of aVolumeLoader. Accordingly, it gets a new publicsetLoaderand reworkedloadmethod with a simpler interface.VolumeDataObserver, currently only used to informView3dof load events; andsetLoadErrorHandler, used to listen for and respond to errors. The latter is now marked deprecated; the former is removed entirely.Potential future work:
VolumeLoader.loadDatato return a promise rather than relying on its current callback interface. Alas, I wasn't able to fully purge its callbacky-ness on this iteration.Volumeto remove the public methodssetChannelDataFromAtlasandsetChannelDataFromVolume(in favor, again, ofVolumeLoaders being the single interface to volume data). This would have allowed these implementation-simple but interface-verbose methods to be brought inside other functions and simplified the code flow for loading data a bit further.VolumeMaker, a class full of utility functions for generating procedural volumes, which is currently the only way we ever generate data to feed to either of the above methods. I think building aVolumeLoaderthat accepts SDFs and uses them to generate volume channels would be great, and would allow the refactor above to proceed, but it's a slightly larger project than this PR.