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

Codomain web #4839

Merged
merged 19 commits into from
Oct 27, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
32ff94c
Add reverse intensity methods to Blitz Gateway.
will-moore Sep 9, 2016
743dd85
Add reverseMap support to webgateway split_channel_info()
will-moore Sep 9, 2016
ff794dc
Move Blitz isReverseIntensity() to channel from image
will-moore Sep 12, 2016
7c3bc03
channelMarshal includes reverseIntensity: boolean
will-moore Sep 12, 2016
d3fe66a
Show 'Reverse Intensity' checkbox in colorpicker dialog
will-moore Sep 12, 2016
a5ca492
Adding cyan to list of colors in colorpicker
will-moore Sep 12, 2016
d768054
Handle 'reverseIntensity' in undo, save, compare channels
will-moore Sep 12, 2016
6b5dd2e
Include 'reverseIntensity' in Blitz image.getAllRenderingDefs()
will-moore Sep 12, 2016
6bb7066
Use no 'r' in rdef string to disable reverse
will-moore Sep 12, 2016
50a077b
Include 'r' for reverseIntensity in copy_image_rdef_json
will-moore Sep 13, 2016
6cfb26b
Update image marshal test to expect 'reverseIntensity' in channels
will-moore Sep 22, 2016
bea20b8
Use '-r' flag to turn OFF reverse intensity explicitly
will-moore Sep 23, 2016
614ebc1
Handle -r flag in setQuery()
will-moore Sep 23, 2016
e79b5a9
Fix Click user thumbnail rdef removes reverse-intensity
will-moore Sep 29, 2016
5b0479d
Reverse Intensity checkbox doesn't scroll in dialog
will-moore Sep 30, 2016
0a1c0ae
Merge remote-tracking branch 'origin/develop' into codomain_web
will-moore Oct 5, 2016
54689c0
Merge remote-tracking branch 'origin/develop' into codomain_web
will-moore Oct 5, 2016
996a4da
Include reverseIntensity in test copy_paste rdefs
will-moore Oct 17, 2016
f616178
Include reverseIntensity in test_all_rendering_defs
will-moore Oct 17, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
48 changes: 47 additions & 1 deletion components/tools/OmeroPy/src/omero/gateway/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6812,6 +6812,23 @@ def getWindowMax(self):
return None
return si.getGlobalMax().val

def isReverseIntensity(self):
"""
Returns True if this channel has ReverseIntensityContext
set on it.

:return: True if ReverseIntensityContext found
:rtype: Boolean
"""
if self._re is None:
return None
ctx = self._re.getCodomainMapContext(self._idx)
reverse = False
for c in ctx:
if isinstance(c, omero.model.ReverseIntensityContext):
reverse = True
return reverse

ChannelWrapper = _ChannelWrapper


Expand Down Expand Up @@ -7656,7 +7673,8 @@ def getZoomLevelScaling(self):
rv[i] = float(level)/sizeXList[0]
return rv

def setActiveChannels(self, channels, windows=None, colors=None):
def setActiveChannels(self, channels, windows=None, colors=None,
reverseMaps=None):
"""
Sets the active channels on the rendering engine.
Also sets rendering windows and channel colors
Expand All @@ -7680,12 +7698,17 @@ def setActiveChannels(self, channels, windows=None, colors=None):
Must be list for each channel
:param colors: List of colors. ['F00', None, '00FF00'].
Must be item for each channel
:param reverseMaps: List of boolean (or None). If True/False then
set/remove reverseIntensityMap on channel
"""
abs_channels = [abs(c) for c in channels]
idx = 0 # index of windows/colors args above
for c in range(len(self.getChannels())):
self._re.setActive(c, (c+1) in channels, self._conn.SERVICE_OPTS)
if (c+1) in channels:
if (reverseMaps is not None and
reverseMaps[idx] is not None):
self.setReverseIntensity(c, reverseMaps[idx])
if (windows is not None
and windows[idx][0] is not None
and windows[idx][1] is not None):
Expand Down Expand Up @@ -7932,6 +7955,24 @@ def isGreyscaleRenderingModel(self):
"""
return self.getRenderingModel().value.lower() == 'greyscale'

@assert_re()
def setReverseIntensity(self, channelIndex, reverse=True):
"""
Sets or removes a ReverseIntensityMapContext from the
specified channel. If set, the intensity of the channel
is mapped in reverse: brightest -> darkest.

:param channelIndex: The index of channel (int)
:param reverse: If True, set reverse intensity (boolean)
"""
r = omero.romio.ReverseIntensityMapContext()
# Always remove map from channel
# (doesn't throw exception, even if not on channel)
self._re.removeCodomainMapFromChannel(r, channelIndex)
# If we want to reverse, add it to the channel (again)
if reverse:
self._re.addCodomainMapToChannel(r, channelIndex)

@assert_re(ignoreExceptions=(omero.ConcurrencyException))
def getRenderingDefId(self):
"""
Expand Down Expand Up @@ -7976,13 +8017,18 @@ def getAllRenderingDefs(self, eid=-1):
waves = rdef.iterateWaveRendering()
d['c'] = []
for w in waves:
reverse = False
for c in w.copySpatialDomainEnhancement():
if isinstance(c, omero.model.ReverseIntensityContext):
reverse = True
color = ColorHolder.fromRGBA(
w.getRed().val, w.getGreen().val, w.getBlue().val, 255)
r = {
'active': w.getActive().val,
'start': w.getInputStart().val,
'end': w.getInputEnd().val,
'color': color.getHtml(),
'reverseIntensity': reverse,
'rgb': {'red': w.getRed().val,
'green': w.getGreen().val,
'blue': w.getBlue().val}
Expand Down
5 changes: 3 additions & 2 deletions components/tools/OmeroWeb/omeroweb/webclient/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1600,8 +1600,9 @@ def load_metadata_preview(request, c_type, c_id, conn=None, share_id=None,
if c['active']:
act = ""
color = c['lut'] if 'lut' in c else c['color']
chs.append('%s%s|%d:%d$%s'
% (act, i+1, c['start'], c['end'], color))
reverse = 'r' if c['reverseIntensity'] else '-r'
chs.append('%s%s|%d:%d%s$%s'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you went with the proposal for ':' separation then it'd need to be

chs.append('%s%s|%d:%d:%s$%s'

% (act, i+1, c['start'], c['end'], reverse, color))
rdefQueries.append({
'id': r['id'],
'owner': r['owner'],
Expand Down
1 change: 1 addition & 0 deletions components/tools/OmeroWeb/omeroweb/webgateway/marshal.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def channelMarshal(channel):
chan = {'emissionWave': channel.getEmissionWave(),
'label': channel.getLabel(),
'color': channel.getColor().getHtml(),
'reverseIntensity': channel.isReverseIntensity(),
'window': {'min': channel.getWindowMin(),
'max': channel.getWindowMax(),
'start': channel.getWindowStart(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,8 @@
}
.lutpicker input {
width: 10px;
}
#reverseIntensity {
display: block;
float: left;
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ $.fn.colorbtn = function(cfg) {
};
var that = this;

var colors = ["FF0000", "00FF00", "0000FF", "FFFFFF", "FFFF00", "EE82EE"];
var colorNames = ["red", "green", "blue", "white", "yellow", "magenta"];
var colors = ["FF0000", "00FF00", "0000FF", "FFFFFF", "FFFF00", "EE00EE", "00FFFF"];
var colorNames = ["red", "green", "blue", "white", "yellow", "magenta", "cyan"];
var picker = null;

/* The basic setup */
Expand All @@ -39,10 +39,14 @@ $.fn.colorbtn = function(cfg) {
var ok_callback = function () {
// On 'OK' we get the color saved by 'callback' above and apply it to the color-btn, then trigger
var data_color = self.attr('data-picked-color');
var reverse_intensity = self.data('data-reverse-intensity');
// data_color could be 'FF0000' or 'cool.lut'
if (data_color) {
self.attr('data-color', data_color);
self.trigger('changed');
} else if (reverse_intensity !== undefined) {
self.data('data-reverse-intensity', reverse_intensity);
self.trigger('changed');
}
};

Expand All @@ -53,6 +57,11 @@ $.fn.colorbtn = function(cfg) {
var box = jQuery("#"+this.cfg.prefix+"-box").append('<h1>Choose color</h1>');
box.postit();

var reverseIntensityHtml = '<div><input id="reverseIntensity" type="checkbox" style="width:20px"></input>';
reverseIntensityHtml += '<label for="reverseIntensity" style="font-size:15px; font-weight: normal;">Reverse Intensity</label></div>';
reverseIntensityHtml += '<div style="clear:both"></div>';
$(reverseIntensityHtml).appendTo(box);

// Add Lookup Table list - gets populated in show_picker() below.
var $luts = $('<div id="' + this.cfg.prefix + '-luts" class="lutpicker"></div>').appendTo(box);

Expand Down Expand Up @@ -99,6 +108,8 @@ $.fn.colorbtn = function(cfg) {
}

this.show_picker = function () {
// 'data-reverse-intensity' is a string in template, not boolean.
var reverse_intensity = self.data('data-reverse-intensity');
if (!picker) {
if (jQuery('#'+this.cfg.prefix+'-box').length === 0) {
this._prepare_picker();
Expand All @@ -108,7 +119,7 @@ $.fn.colorbtn = function(cfg) {
}
var currColor = self.attr('data-color');

// lookup LUTs
// lookup LUTs & build list with other colors
var $luts = $("#" + this.cfg.prefix + "-luts");
if ($luts.is(':empty')) {
$.getJSON(cfg.server + '/luts/', function(data){
Expand Down Expand Up @@ -141,11 +152,12 @@ $.fn.colorbtn = function(cfg) {
$('.cpickerPane').hide();
$luts.show();
$('.showColorPicker a').html('Show Color Picker');
$('#reverseIntensity').prop('checked', reverse_intensity);
// Highlight current color/lut
$("label", $luts).css('background', 'none');
$("label[for='" + currColor + "']", $luts).css('background', '#cddcfc')

// bind appropriate handler (wraps ref to button)
// unbind and re-bind appropriate handler (wraps ref to button)
$("#cbpicker-OK-btn").unbind('click').bind('click', ok_callback)
.bind('click',function(){
jQuery("#"+that.cfg.prefix+"-box").hide();
Expand All @@ -154,6 +166,10 @@ $.fn.colorbtn = function(cfg) {
self.attr('data-picked-color', this.value);
ok_callback();
});
$("#reverseIntensity").off('click').click(function(){
self.data('data-reverse-intensity', this.checked);
ok_callback();
});
self.removeAttr('data-picked-color');

var oldColor = self.attr("data-color"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,16 @@ jQuery._WeblitzViewport = function (container, server, options) {
this.setChannelActive(idx, !_this.loadedImg.channels[idx].active);
};

this.setChannelReverseIntensity = function (idx, reverse, noreload) {
if (_this.loadedImg.channels[idx].reverseIntensity !== reverse) {
_this.loadedImg.channels[idx].reverseIntensity = reverse;
_this.self.trigger('channelChange', [_this, idx, _this.loadedImg.channels[idx]]);
if (!noreload) {
_load();
}
}
};

this.getCCount = function () {
return _this.loadedImg.size.c;
};
Expand Down Expand Up @@ -950,6 +960,7 @@ jQuery._WeblitzViewport = function (container, server, options) {
e1.channels[i].color == e2.channels[i].color &&
e1.channels[i].windowStart == e2.channels[i].windowStart &&
e1.channels[i].windowEnd == e2.channels[i].windowEnd &&
e1.channels[i].reverseIntensity == e2.channels[i].reverseIntensity &&
e1.channels[i].metalabel == e2.channels[i].metalabel)) {
return false;
}
Expand All @@ -966,6 +977,7 @@ jQuery._WeblitzViewport = function (container, server, options) {
color: channels[i].color,
windowStart: channels[i].window.start,
windowEnd: channels[i].window.end,
reverseIntensity: channels[i].reverseIntensity,
metalabel: channels[i].metalabel};
entry.channels.push(channel);
}
Expand All @@ -991,6 +1003,7 @@ jQuery._WeblitzViewport = function (container, server, options) {
this.setChannelColor(i, entry.channels[i].color, true);
this.setChannelActive(i, entry.channels[i].active, true);
this.setChannelLabel(i, entry.channels[i].metalabel, true);
this.setChannelReverseIntensity(i, entry.channels[i].reverseIntensity, true);
}
_load();
}
Expand Down Expand Up @@ -1067,6 +1080,7 @@ jQuery._WeblitzViewport = function (container, server, options) {
var ch = channels[i].active ? '' : '-';
ch += parseInt(i, 10)+1;
ch += '|' + channels[i].window.start + ':' + channels[i].window.end;
ch += channels[i].reverseIntensity ? 'r' : '-r';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you went with the proposal for ':' separation then it'd need to be

ch += ':' + channels[i].reverseIntensity ? 'r' : '-r';

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you went with the proposal for ':' separation then it'd need to be

ch += ':' + channels[i].reverseIntensity ? 'r' : '-r';

ch += '$' + OME.rgbToHex(channels[i].color);
chs.push(ch);
}
Expand Down Expand Up @@ -1136,6 +1150,12 @@ jQuery._WeblitzViewport = function (container, server, options) {
}
if (t.length > 1) {
t = t[1].split('$');
if (t[0].endsWith('-r')) {
this.setChannelReverseIntensity(idx, false, true);
} else if (t[0].endsWith('r')) {
this.setChannelReverseIntensity(idx, true, true);
}
t[0] = t[0].replace('-r', '').replace('r', ''); // remove 'r' if present
var range = t[0].split(':');
if (range.length == 2) {
Copy link
Member

@waxenegger waxenegger Oct 4, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you went with the proposal for ':' separation then it'd need to be

if (range.length == 3) this.setChannelReverseIntensity(idx, range[2].length > 0 && range[2] === 'r', true)

this.setChannelWindow(idx, parseFloat(range[0], 10), parseFloat(range[1], 10), true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,10 @@
$('#wblitz-ch'+i+'-cw-start').val(channels[i].window.start).change();
$('#wblitz-ch'+i+'-cw-end').val(channels[i].window.end).change();
}
// Colorpicker buttons store 'reverse-intensity' with .data() to populate colorbtn dialog
$(".picker").each(function(i, pickerBtn) {
$(pickerBtn).data('data-reverse-intensity', channels[i].reverseIntensity);
});
hidePicker();

updateUndoRedo(viewport);
Expand Down Expand Up @@ -244,9 +248,12 @@
if (on_batchCopyRDefs) {
return batchCopyRDefs_action('ok');
}
var revInt;
for (var i=0; i<viewport.getCCount(); i++) {
viewport.setChannelActive(i, $('#rd-wblitz-ch'+i).get(0).checked, true);
viewport.setChannelColor(i, $('#wblitz-ch'+i+'-color').attr('data-color'), true);
revInt = $('#wblitz-ch'+i+'-color').data('data-reverse-intensity');
if (revInt !== undefined) {viewport.setChannelReverseIntensity(i, revInt, true);}
var noreload = ((i+1) < viewport.getCCount()); // prevent reload, except on the last loop
viewport.setChannelWindow(i, $('#wblitz-ch'+i+'-cw-start').get(0).value, $('#wblitz-ch'+i+'-cw-end').get(0).value, noreload);
}
Expand Down Expand Up @@ -515,6 +522,10 @@


/* Prepare color picker buttons */
$(".picker").each(function(i, pickerBtn) {
console.log(this, channels[i].reverseIntensity);
$(pickerBtn).data('data-reverse-intensity', channels[i].reverseIntensity);
});
$(".picker")
.colorbtn({'server': viewport.viewport_server})
.bind('showing', function () {
Expand Down
30 changes: 24 additions & 6 deletions components/tools/OmeroWeb/omeroweb/webgateway/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,19 +207,35 @@ def _split_channel_info(rchannels):
channels = []
windows = []
colors = []
reverses = []
for chan in rchannels.split(','):
# chan 1|12:1386r$0000FF
chan = chan.split('|', 1)
# chan ['1', '12:1386r$0000FF']
t = chan[0].strip()
# t = '1'
color = None
rev = None
# Not normally used...
if t.find('$') >= 0:
t, color = t.split('$')
try:
channels.append(int(t))
ch_window = (None, None)
if len(chan) > 1:
t = chan[1].strip()
# t = '12:1386r$0000FF'
if t.find('$') >= 0:
t, color = t.split('$', 1)
# color = '0000FF'
# t = 12:1386r
# Optional flag to enable reverse codomain
if t.endswith('-r'):
rev = False
t = t[:-2]
elif t.endswith('r'):
rev = True
t = t[:-1]
t = t.split(':')
if len(t) == 2:
try:
Expand All @@ -228,10 +244,11 @@ def _split_channel_info(rchannels):
pass
windows.append(ch_window)
colors.append(color)
reverses.append(rev)
except ValueError:
pass
logger.debug(str(channels)+","+str(windows)+","+str(colors))
return channels, windows, colors
return channels, windows, colors, reverses


def getImgDetailsFromReq(request, as_string=False):
Expand Down Expand Up @@ -755,8 +772,8 @@ def _get_prepared_image(request, iid, server_id=None, conn=None,
return
if 'c' in r:
logger.debug("c="+r['c'])
channels, windows, colors = _split_channel_info(r['c'])
if not img.setActiveChannels(channels, windows, colors):
channels, windows, colors, reverses = _split_channel_info(r['c'])
if not img.setActiveChannels(channels, windows, colors, reverses):
logger.debug(
"Something bad happened while setting the active channels...")
if r.get('m', None) == 'g':
Expand Down Expand Up @@ -1854,19 +1871,20 @@ def getRenderingSettings(image):
start = ch.getWindowStart()
end = ch.getWindowEnd()
color = ch.getLut()
rev = 'r' if ch.isReverseIntensity() else ''
if not color or len(color) == 0:
color = ch.getColor().getHtml()
chs.append("%s%s|%s:%s$%s" % (act, i+1, start, end, color))
chs.append("%s%s|%s:%s%s$%s" % (act, i+1, start, end, rev, color))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you went with the proposal for ':' separation then it'd need to be

chs.append("%s%s|%s:%s:%s$%s" % (act, i+1, start, end, rev, color))

should the first 2 %s be %d? it probably doesn't matter if they are implicitly converted.

rv['c'] = ",".join(chs)
rv['m'] = "g" if image.isGreyscaleRenderingModel() else "c"
rv['z'] = image.getDefaultZ() + 1
rv['t'] = image.getDefaultT() + 1
return rv

def applyRenderingSettings(image, rdef):
channels, windows, colors = _split_channel_info(rdef['c'])
channels, windows, colors, reverse = _split_channel_info(rdef['c'])
# also prepares _re
image.setActiveChannels(channels, windows, colors)
image.setActiveChannels(channels, windows, colors, reverse)
if rdef['m'] == 'g':
image.setGreyscaleRenderingModel()
else:
Expand Down
1 change: 1 addition & 0 deletions components/tools/OmeroWeb/test/integration/test_marshal.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ def test_image_detail(self):
'start': 88,
'min': 88
},
'reverseIntensity': False,
'emissionWave': 500,
'label': "500"
}
Expand Down