Skip to content

Commit

Permalink
Merge pull request #173 from allen-cell-animated/feature/load-enabled…
Browse files Browse the repository at this point in the history
…-channels-only

Only load enabled channels
  • Loading branch information
frasercl authored Jan 8, 2024
2 parents af99f64 + 378b4e7 commit 0b6e1c7
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 12 deletions.
16 changes: 10 additions & 6 deletions src/Volume.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,11 @@ interface VolumeDataObserver {
*/
export default class Volume {
public imageInfo: ImageInfo;
public loadSpec: LoadSpec;
public loadSpec: Required<LoadSpec>;
public loader?: IVolumeLoader;
// `LoadSpec` representing the minimum data required to display what's in the viewer (subregion, channels, etc.).
// Used to intelligently issue load requests whenever required by a state change. Modify with `updateRequiredData`.
private loadSpecRequired: Required<LoadSpec>;
public loadSpecRequired: Required<LoadSpec>;
public channelLoadCallback?: PerChannelCallback;
public imageMetadata: Record<string, unknown>;
public name: string;
Expand Down Expand Up @@ -169,13 +169,16 @@ export default class Volume {
this.loaded = false;
this.imageInfo = imageInfo;
this.name = this.imageInfo.name;
this.loadSpec = loadSpec;
this.loadSpecRequired = {
this.loadSpec = {
// Fill in defaults for optional properties
multiscaleLevel: 0,
channels: Array.from({ length: this.imageInfo.numChannels }, (_val, idx) => idx),
...loadSpec,
subregion: loadSpec.subregion.clone(),
};
this.loadSpecRequired = {
...this.loadSpec,
channels: this.loadSpec.channels.slice(),
subregion: this.loadSpec.subregion.clone(),
};
this.loader = loader;
// imageMetadata to be filled in by Volume Loaders
Expand Down Expand Up @@ -241,7 +244,8 @@ export default class Volume {
this.loadSpecRequired = { ...this.loadSpecRequired, ...required };
let noReload =
this.loadSpec.time === this.loadSpecRequired.time &&
this.loadSpec.subregion.containsBox(this.loadSpecRequired.subregion);
this.loadSpec.subregion.containsBox(this.loadSpecRequired.subregion) &&
this.loadSpecRequired.channels.every((channel) => this.loadSpec.channels.includes(channel));

// An update to `subregion` should trigger a reload when the new subregion is not contained in the old one
// OR when the new subregion is smaller than the old one by enough that we can load a higher scale level.
Expand Down
15 changes: 10 additions & 5 deletions src/VolumeDrawable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -497,12 +497,17 @@ export default class VolumeDrawable {
// flip the color to the "null" value
this.fusion[channelIndex].rgbColor = enabled ? this.channelColors[channelIndex] : 0;
// if all are nulled out, then hide the volume element from the scene.
if (this.fusion.every((elem) => elem.rgbColor === 0)) {
this.settings.visible = false;
} else {
this.settings.visible = true;
}
this.settings.visible = !this.fusion.every((elem) => elem.rgbColor === 0);
this.volumeRendering.updateSettings(this.settings, SettingsFlags.VIEW);

// add or remove this channel from the list of required channels to load
const { channels } = this.volume.loadSpecRequired;
const channelRequired = channels.includes(channelIndex);
if (enabled && !channelRequired) {
this.volume.updateRequiredData({ channels: [...channels, channelIndex] });
} else if (!enabled && channelRequired) {
this.volume.updateRequiredData({ channels: channels.filter((i) => i !== channelIndex) });
}
}

isVolumeChannelEnabled(channelIndex: number): boolean {
Expand Down
2 changes: 1 addition & 1 deletion src/loaders/OmeZarrLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ class OMEZarrLoader implements IVolumeLoader {
// First, cancel any pending requests for this volume
this.requestQueue.cancelAllRequests(CHUNK_REQUEST_CANCEL_REASON);

vol.loadSpec = explicitLoadSpec ?? vol.loadSpec;
vol.loadSpec = { ...explicitLoadSpec, ...vol.loadSpec };
const maxExtent = this.maxExtent ?? new Box3(new Vector3(0, 0, 0), new Vector3(1, 1, 1));
const [z, y, x] = this.axesTCZYX.slice(2);
const subregion = composeSubregion(vol.loadSpec.subregion, maxExtent);
Expand Down

0 comments on commit 0b6e1c7

Please sign in to comment.