Skip to content

Commit

Permalink
Merge pull request #1340 from astrofrog/fix-transparency
Browse files Browse the repository at this point in the history
Further fixes to image viewer
  • Loading branch information
astrofrog authored Jul 12, 2017
2 parents 164b3b2 + c526496 commit 75bf94e
Show file tree
Hide file tree
Showing 10 changed files with 427 additions and 144 deletions.
22 changes: 22 additions & 0 deletions glue/core/qt/data_combo_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,11 +334,33 @@ def __init__(self, data_combo, data_collection):
self._datasets = []
self.hub = data_collection.hub

def set_multiple_data(self, datasets):
"""
Add multiple datasets to the combo in one go (and clear any previous datasets).
Parameters
----------
datasets : list
The list of :class:`~glue.core.data.Data` objects to add
"""

try:
self._datasets.clear()
except AttributeError: # PY2
self._datasets[:] = []
for data in datasets:
self._datasets.append(data)
self.refresh()

def append_data(self, data):
if data in self._datasets:
return
self._datasets.append(data)
self.refresh()

def remove_data(self, data):
if data not in self._datasets:
return
self._datasets.remove(data)
self.refresh()

Expand Down
10 changes: 5 additions & 5 deletions glue/icons/qt/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@ def layer_artist_icon(artist):

# TODO: need a test for this

from glue.viewers.image.layer_artist import ImageLayerArtist
from glue.viewers.scatter.layer_artist import ScatterLayerArtist

if not artist.enabled:
bm = QtGui.QBitmap(icon_path('glue_delete'))
elif isinstance(artist, ImageLayerArtist):
bm = QtGui.QBitmap(icon_path('glue_image'))
else:
elif isinstance(artist, ScatterLayerArtist):
bm = QtGui.QBitmap(icon_path(POINT_ICONS.get(artist.layer.style.marker,
'glue_circle_point')))
else:
bm = QtGui.QBitmap(icon_path('glue_box_point'))
color = mpl_to_qt4_color(artist.layer.style.color)

pm = tint_pixmap(bm, color)
Expand All @@ -74,4 +74,4 @@ def get_icon(icon_name):
-------
A QtGui.QIcon object
"""
return QtGui.QIcon(icon_path(icon_name))
return QtGui.QIcon(icon_path(icon_name))
22 changes: 12 additions & 10 deletions glue/viewers/image/composite_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ def allocate(self, uuid):

def deallocate(self, uuid):
self.layers.pop(uuid)
if len(self.layers) == 0:
self.shape = None

def set(self, uuid, **kwargs):
for key, value in kwargs.items():
Expand Down Expand Up @@ -105,17 +103,18 @@ def __getitem__(self, view):
# Compute colormapped image
plane = layer['color'](data)

alpha_plane = layer['alpha'] * plane[:, :, 3]

# Use traditional alpha compositing
plane[:, :, 0] = plane[:, :, 0] * layer['alpha'] * plane[:, :, 3]
plane[:, :, 1] = plane[:, :, 1] * layer['alpha'] * plane[:, :, 3]
plane[:, :, 2] = plane[:, :, 2] * layer['alpha'] * plane[:, :, 3]
plane[:, :, 0] = plane[:, :, 0] * alpha_plane
plane[:, :, 1] = plane[:, :, 1] * alpha_plane
plane[:, :, 2] = plane[:, :, 2] * alpha_plane

img[:, :, 0] *= (1 - plane[:, :, 3])
img[:, :, 1] *= (1 - plane[:, :, 3])
img[:, :, 2] *= (1 - plane[:, :, 3])
img[:, :, 0] *= (1 - alpha_plane)
img[:, :, 1] *= (1 - alpha_plane)
img[:, :, 2] *= (1 - alpha_plane)
img[:, :, 3] = 1


else:

if img is None:
Expand All @@ -136,7 +135,10 @@ def __getitem__(self, view):
img += plane

if img is None:
img = np.zeros(self.shape + (4,))
if self.shape is None:
return None
else:
img = np.zeros(self.shape + (4,))

img = np.clip(img, 0, 1)

Expand Down
10 changes: 10 additions & 0 deletions glue/viewers/image/layer_artist.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ def _update_compatibility(self, *args, **kwargs):
match and the pixel component IDs have to be equivalent.
"""

if self._viewer_state.reference_data is None:
self._compatible_with_reference_data = False
self.disable('No reference data defined')
return

if self.layer is self._viewer_state.reference_data:
self._compatible_with_reference_data = True
self.enable()
Expand Down Expand Up @@ -113,6 +118,11 @@ def __init__(self, axes, viewer_state, layer_state=None, layer=None):
self.composite.set(self.uuid, array=self.get_image_data)
self.composite_image = self.axes._composite_image

def enable(self):
if hasattr(self, 'composite_image'):
self.composite_image.invalidate_cache()
super(ImageLayerArtist, self).enable()

def get_image_data(self):

if not self._compatible_with_reference_data:
Expand Down
Loading

0 comments on commit 75bf94e

Please sign in to comment.