def test_contour3d(self): """Test contour3d function""" coords = numpy.linspace(-10, 10, 64) z = coords.reshape(-1, 1, 1) y = coords.reshape(1, -1, 1) x = coords.reshape(1, 1, -1) data = numpy.sin(x * y * z) / (x * y * z) # Just data window = sx.contour3d(data) isosurfaces = window.getIsosurfaces() self.assertEqual(len(isosurfaces), 1) self._expose_and_close(window) # N contours + color colors = ['red', 'green', 'blue'] window = sx.contour3d(data, copy=False, contours=len(colors), color=colors) isosurfaces = window.getIsosurfaces() self.assertEqual(len(isosurfaces), len(colors)) for iso, color in zip(isosurfaces, colors): self.assertEqual(rgba(iso.getColor()), rgba(color)) self._expose_and_close(window) # by isolevel, single color contours = 0.2, 0.5 window = sx.contour3d(data, copy=False, contours=contours, color='yellow') isosurfaces = window.getIsosurfaces() self.assertEqual(len(isosurfaces), len(contours)) for iso, level in zip(isosurfaces, contours): self.assertEqual(iso.getLevel(), level) self.assertEqual(rgba(iso.getColor()), rgba('yellow')) self._expose_and_close(window) # Single isolevel, colormap window = sx.contour3d(data, copy=False, contours=0.5, colormap='gray', vmin=0.6, opacity=0.4) isosurfaces = window.getIsosurfaces() self.assertEqual(len(isosurfaces), 1) self.assertEqual(isosurfaces[0].getLevel(), 0.5) self.assertEqual(rgba(isosurfaces[0].getColor()), (0., 0., 0., 0.4)) self._expose_and_close(window)
def __init__(self, parent): super(Isosurface, self).__init__(parent=parent) self._level = float('nan') self._autoLevelFunction = None self._color = rgba('#FFD700FF') self._data = None self._group = scene.Group()
def setStrokeColor(self, color): """Set the color of the plane border. :param color: RGB color: name, #RRGGBB or RGB values :type color: QColor, str or array-like of 3 or 4 float in [0., 1.] or uint8 """ self._plane.color = rgba(color)
def setBackgroundColor(self, color): """Set the background color of the OpenGL view. :param color: RGB color of the isosurface: name, #RRGGBB or RGB values :type color: QColor, str or array-like of 3 or 4 float in [0., 1.] or uint8 """ color = rgba(color) self.viewport.background = color self.overview.background = color[0]*0.5, color[1]*0.5, color[2]*0.5, 1.
def setBackgroundColor(self, color): """Set the background color of the OpenGL view. :param color: RGB color of the isosurface: name, #RRGGBB or RGB values :type color: QColor, str or array-like of 3 or 4 float in [0., 1.] or uint8 """ color = rgba(color) if color != self.viewport.background: self.viewport.background = color self.sigStyleChanged.emit('backgroundColor')
def setHighlightColor(self, color): """Set hightlighted item color. :param color: RGB color: name, #RRGGBB or RGB values :type color: QColor, str or array-like of 3 or 4 float in [0., 1.] or uint8 """ color = rgba(color) if color != self._highlightColor: self._highlightColor = color self._updateColors()
def setForegroundColor(self, color): """Set the foreground color. :param color: RGB color: name, #RRGGBB or RGB values :type color: QColor, str or array-like of 3 or 4 float in [0., 1.] or uint8 """ color = rgba(color) if color != self._foregroundColor: self._foregroundColor = color self._updateColors()
def setColor(self, color): """Set the color of the iso-surface :param color: RGBA color of the isosurface :type color: QColor, str or array-like of 4 float in [0., 1.] """ color = rgba(color) if color != self._color: self._color = color if len(self._group.children) != 0: self._group.children[0].setAttribute('color', self._color) self.sigColorChanged.emit()
def __init__(self, parent=None, plot=None, mask=None): """ :param parent: Parent QWidget :param plot: Plot widget on which to operate :param mask: Instance of subclass of :class:`BaseMask` (e.g. :class:`ImageMask`) """ super(BaseMaskToolsWidget, self).__init__(parent) # register if the user as force a color for the corresponding mask level self._defaultColors = numpy.ones((self._maxLevelNumber + 1), dtype=numpy.bool) # overlays colors set by the user self._overlayColors = numpy.zeros((self._maxLevelNumber + 1, 3), dtype=numpy.float32) # as parent have to be the first argument of the widget to fit # QtDesigner need but here plot can't be None by default. assert plot is not None self._plot = plot self._maskName = '__MASK_TOOLS_%d' % id(self) # Legend of the mask self._colormap = Colormap(name="", normalization='linear', vmin=0, vmax=self._maxLevelNumber, colors=None) self._defaultOverlayColor = rgba('gray') # Color of the mask self._setMaskColors(1, 0.5) if not isinstance(mask, BaseMask): raise TypeError("mask is not an instance of BaseMask") self._mask = mask self._mask.sigChanged.connect(self._updatePlotMask) self._mask.sigChanged.connect(self._emitSigMaskChanged) self._drawingMode = None # Store current drawing mode self._lastPencilPos = None self._multipleMasks = 'exclusive' self._maskFileDir = qt.QDir.home().absolutePath() self.plot.sigInteractiveModeChanged.connect( self._interactiveModeChanged) self._initWidgets()
def background(self, color): color = rgba(color) if self._background != color: self._background = color self._changed()
def background(self, color): if color is not None: color = rgba(color) if self._background != color: self._background = color self._changed()