summaryrefslogtreecommitdiff
path: root/silx/gui/plot/backends/BackendOpenGL.py
diff options
context:
space:
mode:
Diffstat (limited to 'silx/gui/plot/backends/BackendOpenGL.py')
-rwxr-xr-xsilx/gui/plot/backends/BackendOpenGL.py78
1 files changed, 44 insertions, 34 deletions
diff --git a/silx/gui/plot/backends/BackendOpenGL.py b/silx/gui/plot/backends/BackendOpenGL.py
index 27f3894..cf1da31 100755
--- a/silx/gui/plot/backends/BackendOpenGL.py
+++ b/silx/gui/plot/backends/BackendOpenGL.py
@@ -1,7 +1,7 @@
# coding: utf-8
# /*##########################################################################
#
-# Copyright (c) 2014-2019 European Synchrotron Radiation Facility
+# Copyright (c) 2014-2020 European Synchrotron Radiation Facility
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
@@ -31,7 +31,6 @@ __license__ = "MIT"
__date__ = "21/12/2018"
import logging
-import warnings
import weakref
import numpy
@@ -62,7 +61,7 @@ _logger = logging.getLogger(__name__)
# Content #####################################################################
class _ShapeItem(dict):
- def __init__(self, x, y, shape, color, fill, overlay, z,
+ def __init__(self, x, y, shape, color, fill, overlay,
linestyle, linewidth, linebgcolor):
super(_ShapeItem, self).__init__()
@@ -249,11 +248,6 @@ class BackendOpenGL(BackendBase.BackendBase, glu.OpenGLWidget):
_MOUSE_BTNS = {1: 'left', 2: 'right', 4: 'middle'}
- def contextMenuEvent(self, event):
- """Override QWidget.contextMenuEvent to implement the context menu"""
- # Makes sure it is overridden (issue with PySide)
- BackendBase.BackendBase.contextMenuEvent(self, event)
-
def sizeHint(self):
return qt.QSize(8 * 80, 6 * 80) # Mimic MatplotlibBackend
@@ -431,6 +425,7 @@ class BackendOpenGL(BackendBase.BackendBase, glu.OpenGLWidget):
plotWidth, plotHeight = self.getPlotBoundsInPixels()[2:]
isXLog = self._plotFrame.xAxis.isLog
isYLog = self._plotFrame.yAxis.isLog
+ isYInverted = self._plotFrame.isYAxisInverted
# Used by marker rendering
labels = []
@@ -572,13 +567,20 @@ class BackendOpenGL(BackendBase.BackendBase, glu.OpenGLWidget):
# Do not render markers outside visible plot area
continue
+ if isYInverted:
+ valign = BOTTOM
+ vPixelOffset = -pixelOffset
+ else:
+ valign = TOP
+ vPixelOffset = pixelOffset
+
if item['text'] is not None:
x = pixelPos[0] + pixelOffset
- y = pixelPos[1] + pixelOffset
+ y = pixelPos[1] + vPixelOffset
label = Text2D(item['text'], x, y,
color=item['color'],
bgColor=(1., 1., 1., 0.5),
- align=LEFT, valign=TOP)
+ align=LEFT, valign=valign)
labels.append(label)
# For now simple implementation: using a curve for each marker
@@ -726,10 +728,10 @@ class BackendOpenGL(BackendBase.BackendBase, glu.OpenGLWidget):
def addCurve(self, x, y,
color, symbol, linewidth, linestyle,
yaxis,
- xerror, yerror, z,
+ xerror, yerror,
fill, alpha, symbolsize, baseline):
for parameter in (x, y, color, symbol, linewidth, linestyle,
- yaxis, z, fill, symbolsize):
+ yaxis, fill, symbolsize):
assert parameter is not None
assert yaxis in ('left', 'right')
@@ -767,8 +769,7 @@ class BackendOpenGL(BackendBase.BackendBase, glu.OpenGLWidget):
xErrorMinus, xErrorPlus = xerror[0], xerror[1]
else:
xErrorMinus, xErrorPlus = xerror, xerror
- with warnings.catch_warnings():
- warnings.simplefilter('ignore', category=RuntimeWarning)
+ with numpy.errstate(divide='ignore', invalid='ignore'):
# Ignore divide by zero, invalid value encountered in log10
xErrorMinus = logX - numpy.log10(x - xErrorMinus)
xErrorPlus = numpy.log10(x + xErrorPlus) - logX
@@ -790,8 +791,7 @@ class BackendOpenGL(BackendBase.BackendBase, glu.OpenGLWidget):
yErrorMinus, yErrorPlus = yerror[0], yerror[1]
else:
yErrorMinus, yErrorPlus = yerror, yerror
- with warnings.catch_warnings():
- warnings.simplefilter('ignore', category=RuntimeWarning)
+ with numpy.errstate(divide='ignore', invalid='ignore'):
# Ignore divide by zero, invalid value encountered in log10
yErrorMinus = logY - numpy.log10(y - yErrorMinus)
yErrorPlus = numpy.log10(y + yErrorPlus) - logY
@@ -846,9 +846,9 @@ class BackendOpenGL(BackendBase.BackendBase, glu.OpenGLWidget):
return curve
def addImage(self, data,
- origin, scale, z,
+ origin, scale,
colormap, alpha):
- for parameter in (data, origin, scale, z):
+ for parameter in (data, origin, scale):
assert parameter is not None
if data.ndim == 2:
@@ -860,17 +860,25 @@ class BackendOpenGL(BackendBase.BackendBase, glu.OpenGLWidget):
'addImage: Convert %s data to float32', str(data.dtype))
data = numpy.array(data, dtype=numpy.float32, order='C')
- colormapIsLog = colormap.getNormalization() == 'log'
- cmapRange = colormap.getColormapRange(data=data)
- colormapLut = colormap.getNColors(nbColors=256)
-
- image = GLPlotColormap(data,
- origin,
- scale,
- colormapLut,
- colormapIsLog,
- cmapRange,
- alpha)
+ normalization = colormap.getNormalization()
+ if normalization in GLPlotColormap.SUPPORTED_NORMALIZATIONS:
+ # Fast path applying colormap on the GPU
+ cmapRange = colormap.getColormapRange(data=data)
+ colormapLut = colormap.getNColors(nbColors=256)
+ gamma = colormap.getGammaNormalizationParameter()
+
+ image = GLPlotColormap(data,
+ origin,
+ scale,
+ colormapLut,
+ normalization,
+ gamma,
+ cmapRange,
+ alpha)
+
+ else: # Fallback applying colormap on CPU
+ rgba = colormap.applyToData(data)
+ image = GLPlotRGBAImage(rgba, origin, scale, alpha)
elif len(data.shape) == 3:
# For RGB, RGBA data
@@ -878,6 +886,8 @@ class BackendOpenGL(BackendBase.BackendBase, glu.OpenGLWidget):
if numpy.issubdtype(data.dtype, numpy.floating):
data = numpy.array(data, dtype=numpy.float32, copy=False)
+ elif data.dtype in [numpy.uint8, numpy.uint16]:
+ pass
elif numpy.issubdtype(data.dtype, numpy.integer):
data = numpy.array(data, dtype=numpy.uint8, copy=False)
else:
@@ -899,7 +909,7 @@ class BackendOpenGL(BackendBase.BackendBase, glu.OpenGLWidget):
return image
def addTriangles(self, x, y, triangles,
- color, z, alpha):
+ color, alpha):
# Handle axes log scale: convert data
if self._plotFrame.xAxis.isLog:
x = numpy.log10(x)
@@ -910,8 +920,8 @@ class BackendOpenGL(BackendBase.BackendBase, glu.OpenGLWidget):
return triangles
- def addItem(self, x, y, shape, color, fill, overlay, z,
- linestyle, linewidth, linebgcolor):
+ def addShape(self, x, y, shape, color, fill, overlay,
+ linestyle, linewidth, linebgcolor):
x = numpy.array(x, copy=False)
y = numpy.array(y, copy=False)
@@ -923,7 +933,7 @@ class BackendOpenGL(BackendBase.BackendBase, glu.OpenGLWidget):
raise RuntimeError(
'Cannot add item with Y <= 0 with Y axis log scale')
- return _ShapeItem(x, y, shape, color, fill, overlay, z,
+ return _ShapeItem(x, y, shape, color, fill, overlay,
linestyle, linewidth, linebgcolor)
def addMarker(self, x, y, text, color,
@@ -971,7 +981,7 @@ class BackendOpenGL(BackendBase.BackendBase, glu.OpenGLWidget):
super(BackendOpenGL, self).setCursor(qt.QCursor(cursor))
def setGraphCursor(self, flag, color, linewidth, linestyle):
- if linestyle is not '-':
+ if linestyle != '-':
_logger.warning(
"BackendOpenGL.setGraphCursor linestyle parameter ignored")