Skip to content

Commit 89ee6e8

Browse files
authored
Merge pull request #500 from will-moore/channel_limit
Support max_active_channels
2 parents b4102d4 + c6029c6 commit 89ee6e8

File tree

7 files changed

+74
-1
lines changed

7 files changed

+74
-1
lines changed

plugin/omero_iviewer/iviewer_settings.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,15 @@
3535
"omero.pixeldata.max_projection_bytes will be used or "
3636
"the lower value if both are set.")],
3737

38+
"omero.web.iviewer.max_active_channels":
39+
["MAX_ACTIVE_CHANNELS",
40+
10,
41+
int,
42+
("Default maximum number of active channels. "
43+
"If the /omero_ms_image_region/ microservice endpoint "
44+
"is provided, the options.maxActiveChannels "
45+
"from that response will be used instead.")],
46+
3847
"omero.web.iviewer.roi_page_size":
3948
["ROI_PAGE_SIZE",
4049
500,

plugin/omero_iviewer/views.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
ROI_PAGE_SIZE = getattr(iviewer_settings, 'ROI_PAGE_SIZE')
5151
ROI_PAGE_SIZE = min(MAX_LIMIT, ROI_PAGE_SIZE)
5252
MAX_PROJECTION_BYTES = getattr(iviewer_settings, 'MAX_PROJECTION_BYTES')
53+
MAX_ACTIVE_CHANNELS = getattr(iviewer_settings, 'MAX_ACTIVE_CHANNELS')
5354
ROI_COLOR_PALETTE = getattr(iviewer_settings, 'ROI_COLOR_PALETTE')
5455
SHOW_PALETTE_ONLY = getattr(iviewer_settings, 'SHOW_PALETTE_ONLY')
5556
ENABLE_MIRROR = getattr(iviewer_settings, 'ENABLE_MIRROR')
@@ -114,6 +115,7 @@ def index(request, iid=None, conn=None, **kwargs):
114115
nodedescriptors = None
115116

116117
params['MAX_PROJECTION_BYTES'] = max_bytes
118+
params['MAX_ACTIVE_CHANNELS'] = MAX_ACTIVE_CHANNELS
117119
params['NODEDESCRIPTORS'] = nodedescriptors
118120
params['ROI_COLOR_PALETTE'] = ROI_COLOR_PALETTE
119121
params['SHOW_PALETTE_ONLY'] = SHOW_PALETTE_ONLY

src/app/context.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,14 @@ export default class Context {
191191
*/
192192
luts = new Map();
193193

194+
/**
195+
* max active channels - default is loaded from iviewer_settings
196+
*
197+
* @memberof Context
198+
* @type {number}
199+
*/
200+
max_active_channels = 10;
201+
194202
/**
195203
* the lookup png
196204
*
@@ -243,6 +251,9 @@ export default class Context {
243251
// set up luts
244252
this.setUpLuts();
245253

254+
// load max active channels
255+
this.loadMaxActiveChannels();
256+
246257
// initialize Open_with
247258
OpenWith.initOpenWith();
248259

@@ -344,6 +355,25 @@ export default class Context {
344355
});
345356
}
346357

358+
loadMaxActiveChannels() {
359+
// query microservice endpoint...
360+
let url = this.server + "/omero_ms_image_region/";
361+
fetch(url, {method: "OPTIONS"})
362+
.then(r => r.json())
363+
.then(data => {
364+
if (Number.isInteger(data.options?.maxActiveChannels)) {
365+
this.max_active_channels = data.options.maxActiveChannels;
366+
// in case the images loaded already (this query took longer than
367+
// expected), let's update them...
368+
for (let [id, conf] of this.image_configs) {
369+
conf.image_info.applyMaxActiveChannels(this.max_active_channels);
370+
}
371+
}
372+
}).catch(() => {
373+
console.log("failed to load omero_ms_image_region info");
374+
});
375+
}
376+
347377
/**
348378
* Depending on what received as the inital parameters
349379
* (image(s), dataset, etc) we continue to create and add
@@ -458,6 +488,7 @@ export default class Context {
458488
this.max_projection_bytes = parseInt(this.initParams[REQUEST_PARAMS.MAX_PROJECTION_BYTES], 10)
459489
|| (1024 * 1024 * 256);
460490
this.max_projection_bytes = parseInt(this.initParams[REQUEST_PARAMS.MAX_PROJECTION_BYTES], 10) || (1024 * 1024 * 256);
491+
this.max_active_channels = parseInt(this.initParams[REQUEST_PARAMS.MAX_ACTIVE_CHANNELS], 10) || 10;
461492
let userPalette = `${this.initParams[REQUEST_PARAMS.ROI_COLOR_PALETTE]}`
462493
if (userPalette) {
463494
let arr = userPalette.match(/\[[^\[\]]*\]/g)

src/model/image_info.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,9 @@ export default class ImageInfo {
458458
// If we've viewed this image before, apply cached settings
459459
this.applyCachedSettings(response);
460460

461+
// enforce max_active_channels
462+
this.applyMaxActiveChannels(this.context.max_active_channels);
463+
461464
// signal that we are ready
462465
this.ready = true;
463466
this.tmp_data = response;
@@ -470,6 +473,25 @@ export default class ImageInfo {
470473
this.requestDeltaT();
471474
}
472475

476+
applyMaxActiveChannels(max_active_channels) {
477+
// let conf = this.context.getImageConfig(this.config_id);
478+
if (this.channels == null) {
479+
return;
480+
}
481+
let channels = this.channels;
482+
let activeCount = 0;
483+
484+
for (let i=0;i<channels.length;i++) {
485+
let c = channels[i];
486+
if (c.active) {
487+
activeCount += 1;
488+
}
489+
if (activeCount > max_active_channels && c.active) {
490+
c.active = false;
491+
};
492+
};
493+
}
494+
473495
/**
474496
* Gets cached image settings from context and updates our settings
475497
*

src/settings/channel-range.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import Context from '../app/context';
2020
import Misc from '../utils/misc';
21+
import Ui from '../utils/ui';
2122
import {
2223
CHANNEL_SETTINGS_MODE, FLOATING_POINT_PRECISION, URI_PREFIX
2324
} from '../utils/constants';
@@ -543,6 +544,14 @@ export default class ChannelRange {
543544
if (imgConf.image_info.model === 'greyscale' &&
544545
this.channel.active) return;
545546

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

548557
// toggle channel active state

src/settings/channel-settings.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
// js
2020
import Context from '../app/context';
21-
import Misc from '../utils/misc';
2221
import {inject, customElement, bindable, BindingEngine} from 'aurelia-framework';
2322
import {CHANNEL_SETTINGS_MODE, WEBGATEWAY} from '../utils/constants';
2423
import {

src/utils/constants.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ export const REQUEST_PARAMS = {
134134
ZOOM: 'ZM',
135135
ROI_PAGE_SIZE: 'ROI_PAGE_SIZE',
136136
MAX_PROJECTION_BYTES: 'MAX_PROJECTION_BYTES',
137+
MAX_ACTIVE_CHANNELS: 'MAX_ACTIVE_CHANNELS',
137138
ROI_COLOR_PALETTE: 'ROI_COLOR_PALETTE',
138139
SHOW_PALETTE_ONLY: 'SHOW_PALETTE_ONLY',
139140
ENABLE_MIRROR: 'ENABLE_MIRROR',

0 commit comments

Comments
 (0)