Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamic LUT for iviewer #485

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions plugin/omero_iviewer/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,6 @@
# Find the index of an ROI within all ROIs for the Image (for pagination)
re_path(r'^(?P<obj_type>(roi|shape))/(?P<obj_id>[0-9]+)/page_data/$',
views.roi_page_data, name='omero_iviewer_roi_page_data'),
re_path('^is_dynamic_lut/$', views.is_dynamic_lut,
name='iviewer_dynamic_lut'),
]
20 changes: 19 additions & 1 deletion plugin/omero_iviewer/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from django.shortcuts import render
from django.http import JsonResponse, Http404
from django.conf import settings
from django.urls import reverse
from django.urls import reverse, NoReverseMatch

from os.path import splitext
from collections import defaultdict
Expand Down Expand Up @@ -892,3 +892,21 @@ def shape_stats(request, conn=None, **kwargs):
return JsonResponse({"error": api_exception.message})
except Exception as stats_call_exception:
return JsonResponse({"error": repr(stats_call_exception)})


@login_required()
def is_dynamic_lut(request, **kwargs):
"""
Return true or false for dynamic lut usage URL based on the
current omero-web version.
"""
dynamic_lut = False
try:
# Try to reverse the URL dynamically, which might be version-dependent
_ = reverse("webgateway_luts_png")
dynamic_lut = True
except NoReverseMatch:
# Fallback URL if the dynamic route is not available
pass
# Return the lut_url as JSON
return JsonResponse({'is_dynamic_lut': dynamic_lut})
85 changes: 50 additions & 35 deletions src/app/context.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import {
REGIONS_STORED_SHAPES
} from '../events/events';
import {
APP_NAME, IMAGE_CONFIG_RELOAD, IVIEWER, INITIAL_TYPES, LUTS_NAMES,
APP_NAME, IMAGE_CONFIG_RELOAD, IVIEWER, INITIAL_TYPES,
LUTS_PNG_URL, PLUGIN_NAME, PLUGIN_PREFIX, REQUEST_PARAMS, SYNC_LOCK,
TABS, URI_PREFIX, WEB_API_BASE, WEBCLIENT, WEBGATEWAY
} from '../utils/constants';
Expand Down Expand Up @@ -301,41 +301,56 @@ export default class Context {
* @memberof Context
*/
setUpLuts() {
this.luts_png.url =
this.server + this.getPrefixedURI(WEBGATEWAY, true) + LUTS_PNG_URL;

// determine the luts png height
let lutsPng = new Image();
lutsPng.onload = (e) => {
this.luts_png.height = e.target.naturalHeight;
this.luts_png.image = lutsPng;
for (let [id, conf] of this.image_configs) conf.changed();
}
lutsPng.src = this.luts_png.url;

// now query the luts list
let server = this.server;
let uri_prefix = this.getPrefixedURI(WEBGATEWAY);
$.ajax(
{url : server + uri_prefix + "/luts/",
{url : this.server + this.getPrefixedURI(IVIEWER) + "/is_dynamic_lut/",
success : (response) => {
if (typeof response !== 'object' || response === null ||
!Misc.isArray(response.luts)) return;

let i=0;
response.luts.map(
(l) => {
let isInList = LUTS_NAMES.indexOf(l.name) !== -1;
let mapValue =
Object.assign({
nice_name :
l.name.replace(/.lut/g, "").replace(/_/g, " "),
index : isInList ? i : -1
}, l);
this.luts.set(mapValue.name, mapValue);
if (isInList) i++;
});
for (let [id, conf] of this.image_configs) conf.changed();
// Check first whether omero-web can provides LUT dynamically
// and set URL accordingly
let is_dynamic_lut = response.is_dynamic_lut;
if (is_dynamic_lut) {
this.luts_png.url =
this.server + this.getPrefixedURI(WEBGATEWAY, false) + "/luts_png/";
} else {
this.luts_png.url =
this.server + this.getPrefixedURI(WEBGATEWAY, true) + LUTS_PNG_URL;
}

// determine the luts png height
let lutsPng = new Image();
lutsPng.onload = (e) => {
this.luts_png.height = e.target.naturalHeight;
this.luts_png.image = lutsPng;
for (let [id, conf] of this.image_configs) conf.changed();
}
lutsPng.src = this.luts_png.url;

// now query the luts list
let server = this.server;
let uri_prefix = this.getPrefixedURI(WEBGATEWAY);
$.ajax(
{url : server + uri_prefix + "/luts/",
success : (response) => {
if (typeof response !== 'object' || response === null ||
!Misc.isArray(response.luts)) return;

if (is_dynamic_lut) {
// If it's dynamic, uses the new list instead
response.png_luts = response.png_luts_new
}

response.luts.map(
(l) => {
let mapValue =
Object.assign({
nice_name :
l.name.replace(/.lut/g, "").replace(/_/g, " "),
index : is_dynamic_lut ? l.png_index_new : l.png_index
}, l);
this.luts.set(mapValue.name, mapValue);
});
for (let [id, conf] of this.image_configs) conf.changed();
}
});
}
});
}
Expand Down Expand Up @@ -463,7 +478,7 @@ export default class Context {
}
}
this.show_palette_only = (this.initParams[REQUEST_PARAMS.SHOW_PALETTE_ONLY] != 'False') || false
this.enable_mirror = (this.initParams[REQUEST_PARAMS.ENABLE_MIRROR] != 'False') || false
this.enable_mirror = (this.initParams[REQUEST_PARAMS.ENABLE_MIRROR] != 'False') || false
// nodedescriptors can be empty string or "None" (undefined)
let nds = this.initParams[REQUEST_PARAMS.NODEDESCRIPTORS];
this.nodedescriptors = nds == 'None' ? undefined : nds
Expand Down
46 changes: 0 additions & 46 deletions src/utils/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,52 +204,6 @@ export const PERMISSION_TOOLTIPS = {
*/
export const LUTS_PNG_URL = '/img/luts_10.png';

/**
* luts list for pre-generated png
* @type {Object}
*/
export const LUTS_NAMES = [
'16_colors.lut',
'3-3-2_rgb.lut',
'5_ramps.lut',
'6_shades.lut',
'blue_orange_icb.lut',
'brgbcmyw.lut',
'cool.lut',
'cyan_hot.lut',
'edges.lut',
'fire.lut',
'gem.lut',
'glasbey.lut',
'glasbey_inverted.lut',
'glow.lut',
'grays.lut',
'green_fire_blue.lut',
'hilo.lut',
'ica.lut',
'ica2.lut',
'ica3.lut',
'ice.lut',
'magenta_hot.lut',
'orange_hot.lut',
'phase.lut',
'physics.lut',
'pup_br.lut',
'pup_nr.lut',
'rainbow_rgb.lut',
'red-green.lut',
'red_hot.lut',
'royal.lut',
'sepia.lut',
'smart.lut',
'spectrum.lut',
'thal.lut',
'thallium.lut',
'thermal.lut',
'unionjack.lut',
'yellow_hot.lut'
];

/**
* the right hand panel tab names
* @type {Object}
Expand Down