Skip to content

Commit

Permalink
Merge pull request #500 from will-moore/channel_limit
Browse files Browse the repository at this point in the history
Support max_active_channels
  • Loading branch information
jburel authored Jan 27, 2025
2 parents b4102d4 + c6029c6 commit 89ee6e8
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 1 deletion.
9 changes: 9 additions & 0 deletions plugin/omero_iviewer/iviewer_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,15 @@
"omero.pixeldata.max_projection_bytes will be used or "
"the lower value if both are set.")],

"omero.web.iviewer.max_active_channels":
["MAX_ACTIVE_CHANNELS",
10,
int,
("Default maximum number of active channels. "
"If the /omero_ms_image_region/ microservice endpoint "
"is provided, the options.maxActiveChannels "
"from that response will be used instead.")],

"omero.web.iviewer.roi_page_size":
["ROI_PAGE_SIZE",
500,
Expand Down
2 changes: 2 additions & 0 deletions plugin/omero_iviewer/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
ROI_PAGE_SIZE = getattr(iviewer_settings, 'ROI_PAGE_SIZE')
ROI_PAGE_SIZE = min(MAX_LIMIT, ROI_PAGE_SIZE)
MAX_PROJECTION_BYTES = getattr(iviewer_settings, 'MAX_PROJECTION_BYTES')
MAX_ACTIVE_CHANNELS = getattr(iviewer_settings, 'MAX_ACTIVE_CHANNELS')
ROI_COLOR_PALETTE = getattr(iviewer_settings, 'ROI_COLOR_PALETTE')
SHOW_PALETTE_ONLY = getattr(iviewer_settings, 'SHOW_PALETTE_ONLY')
ENABLE_MIRROR = getattr(iviewer_settings, 'ENABLE_MIRROR')
Expand Down Expand Up @@ -114,6 +115,7 @@ def index(request, iid=None, conn=None, **kwargs):
nodedescriptors = None

params['MAX_PROJECTION_BYTES'] = max_bytes
params['MAX_ACTIVE_CHANNELS'] = MAX_ACTIVE_CHANNELS
params['NODEDESCRIPTORS'] = nodedescriptors
params['ROI_COLOR_PALETTE'] = ROI_COLOR_PALETTE
params['SHOW_PALETTE_ONLY'] = SHOW_PALETTE_ONLY
Expand Down
31 changes: 31 additions & 0 deletions src/app/context.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,14 @@ export default class Context {
*/
luts = new Map();

/**
* max active channels - default is loaded from iviewer_settings
*
* @memberof Context
* @type {number}
*/
max_active_channels = 10;

/**
* the lookup png
*
Expand Down Expand Up @@ -243,6 +251,9 @@ export default class Context {
// set up luts
this.setUpLuts();

// load max active channels
this.loadMaxActiveChannels();

// initialize Open_with
OpenWith.initOpenWith();

Expand Down Expand Up @@ -344,6 +355,25 @@ export default class Context {
});
}

loadMaxActiveChannels() {
// query microservice endpoint...
let url = this.server + "/omero_ms_image_region/";
fetch(url, {method: "OPTIONS"})
.then(r => r.json())
.then(data => {
if (Number.isInteger(data.options?.maxActiveChannels)) {
this.max_active_channels = data.options.maxActiveChannels;
// in case the images loaded already (this query took longer than
// expected), let's update them...
for (let [id, conf] of this.image_configs) {
conf.image_info.applyMaxActiveChannels(this.max_active_channels);
}
}
}).catch(() => {
console.log("failed to load omero_ms_image_region info");
});
}

/**
* Depending on what received as the inital parameters
* (image(s), dataset, etc) we continue to create and add
Expand Down Expand Up @@ -458,6 +488,7 @@ export default class Context {
this.max_projection_bytes = parseInt(this.initParams[REQUEST_PARAMS.MAX_PROJECTION_BYTES], 10)
|| (1024 * 1024 * 256);
this.max_projection_bytes = parseInt(this.initParams[REQUEST_PARAMS.MAX_PROJECTION_BYTES], 10) || (1024 * 1024 * 256);
this.max_active_channels = parseInt(this.initParams[REQUEST_PARAMS.MAX_ACTIVE_CHANNELS], 10) || 10;
let userPalette = `${this.initParams[REQUEST_PARAMS.ROI_COLOR_PALETTE]}`
if (userPalette) {
let arr = userPalette.match(/\[[^\[\]]*\]/g)
Expand Down
22 changes: 22 additions & 0 deletions src/model/image_info.js
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,9 @@ export default class ImageInfo {
// If we've viewed this image before, apply cached settings
this.applyCachedSettings(response);

// enforce max_active_channels
this.applyMaxActiveChannels(this.context.max_active_channels);

// signal that we are ready
this.ready = true;
this.tmp_data = response;
Expand All @@ -470,6 +473,25 @@ export default class ImageInfo {
this.requestDeltaT();
}

applyMaxActiveChannels(max_active_channels) {
// let conf = this.context.getImageConfig(this.config_id);
if (this.channels == null) {
return;
}
let channels = this.channels;
let activeCount = 0;

for (let i=0;i<channels.length;i++) {
let c = channels[i];
if (c.active) {
activeCount += 1;
}
if (activeCount > max_active_channels && c.active) {
c.active = false;
};
};
}

/**
* Gets cached image settings from context and updates our settings
*
Expand Down
9 changes: 9 additions & 0 deletions src/settings/channel-range.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import Context from '../app/context';
import Misc from '../utils/misc';
import Ui from '../utils/ui';
import {
CHANNEL_SETTINGS_MODE, FLOATING_POINT_PRECISION, URI_PREFIX
} from '../utils/constants';
Expand Down Expand Up @@ -543,6 +544,14 @@ export default class ChannelRange {
if (imgConf.image_info.model === 'greyscale' &&
this.channel.active) return;

// don't allow to exceed max_active_channels
let maxActive = this.context.max_active_channels;
let activeCount = imgConf.image_info.channels.reduce((count, ch) => count + (ch.active ? 1 : 0), 0);
if (!this.channel.active && activeCount >= maxActive) {
Ui.showModalMessage(`Cannot activate channel. The maximum number of channels is already active.`, "OK");
return;
}

let history = [];

// toggle channel active state
Expand Down
1 change: 0 additions & 1 deletion src/settings/channel-settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

// js
import Context from '../app/context';
import Misc from '../utils/misc';
import {inject, customElement, bindable, BindingEngine} from 'aurelia-framework';
import {CHANNEL_SETTINGS_MODE, WEBGATEWAY} from '../utils/constants';
import {
Expand Down
1 change: 1 addition & 0 deletions src/utils/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ export const REQUEST_PARAMS = {
ZOOM: 'ZM',
ROI_PAGE_SIZE: 'ROI_PAGE_SIZE',
MAX_PROJECTION_BYTES: 'MAX_PROJECTION_BYTES',
MAX_ACTIVE_CHANNELS: 'MAX_ACTIVE_CHANNELS',
ROI_COLOR_PALETTE: 'ROI_COLOR_PALETTE',
SHOW_PALETTE_ONLY: 'SHOW_PALETTE_ONLY',
ENABLE_MIRROR: 'ENABLE_MIRROR',
Expand Down

0 comments on commit 89ee6e8

Please sign in to comment.