ScalarFieldView: 3D volume scalar data viewer

This module provides a window to view a 3D scalar field.

It supports iso-surfaces, a cutting plane and the definition of a region of interest.

For sample code using ScalarFieldView, see viewer3DVolume.py

ScalarFieldView

class silx.gui.plot3d.ScalarFieldView.ScalarFieldView(parent=None)[source]

Bases: silx.gui.plot3d.Plot3DWindow.Plot3DWindow

Widget computing and displaying an iso-surface from a 3D scalar dataset.

Limitation: Currently, iso-surfaces are generated with higher values than the iso-level ‘inside’ the surface.

Parameters:parent – See QMainWindow
sigDataChanged

Signal emitted when the scalar data field has changed.

sigSelectedRegionChanged

Signal emitted when the selected region has changed.

This signal provides the new selected region.

saveConfig(ioDevice)[source]

Saves this view state. Only isosurfaces at the moment. Does not save the isosurface’s function.

Parameters:ioDevice (qt.QIODevice) – A qt.QIODevice.
loadConfig(ioDevice)[source]

Loads this view state. See ScalarFieldView.saveView to know what is supported at the moment.

Parameters:ioDevice (qt.QIODevice) – A qt.QIODevice.
setInteractiveMode(mode)[source]

Choose the current interaction.

Parameters:mode (str) – Either plane or camera
getInteractiveMode()[source]

Returns the current interaction mode, see setInteractiveMode()

setData(data, copy=True)[source]

Set the 3D scalar data set to use for building the iso-surface.

Dataset order is zyx (i.e., first dimension is z).

Parameters:
  • data (3D numpy.ndarray of float32 with shape at least (2, 2, 2)) – scalar field from which to extract the iso-surface
  • copy (bool) – True (default) to make a copy, False to avoid copy (DO NOT MODIFY data afterwards)
getData(copy=True)[source]

Get the 3D scalar data currently used to build the iso-surface.

Parameters:copy (bool) – True (default) to get a copy, False to get the internal data (DO NOT modify!)
Returns:The data set (or None if not set)
getDataRange()[source]

Return the range of the data as a 2-tuple (min, max)

setScale(sx=1.0, sy=1.0, sz=1.0)[source]

Set the scale of the 3D scalar field (i.e., size of a voxel).

Parameters:
  • sx (float) – Scale factor along the X axis
  • sy (float) – Scale factor along the Y axis
  • sz (float) – Scale factor along the Z axis
getScale()[source]

Returns the scales provided by setScale() as a numpy.ndarray.

setTranslation(x=0.0, y=0.0, z=0.0)[source]

Set the translation of the origin of the data array in data coordinates.

Parameters:
  • x (float) – Offset of the data origin on the X axis
  • y (float) – Offset of the data origin on the Y axis
  • z (float) – Offset of the data origin on the Z axis
getTranslation()[source]

Returns the offset set by setTranslation() as a numpy.ndarray.

setAxesLabels(xlabel=None, ylabel=None, zlabel=None)[source]

Set the text labels of the axes.

Parameters:
  • xlabel (str) – Label of the X axis, None to leave unchanged.
  • ylabel (str) – Label of the Y axis, None to leave unchanged.
  • zlabel (str) – Label of the Z axis, None to leave unchanged.
getAxesLabels()[source]

Returns the text labels of the axes

>>> widget = ScalarFieldView()
>>> widget.setAxesLabels(xlabel='X')

You can get the labels either as a 3-tuple:

>>> xlabel, ylabel, zlabel = widget.getAxesLabels()

Or as an object with methods getXLabel, getYLabel and getZLabel:

>>> labels = widget.getAxesLabels()
>>> labels.getXLabel()
... 'X'
Returns:object describing the labels
getForegroundColor()[source]

Return color used for text and bounding box (QColor)

setForegroundColor(color)[source]

Set the foreground color.

Parameters:color (QColor, str or array-like of 3 or 4 float in [0., 1.] or uint8) – RGB color: name, #RRGGBB or RGB values
getHighlightColor()[source]

Return color used for highlighted item bounding box (QColor)

setHighlightColor(color)[source]

Set hightlighted item color.

Parameters:color (QColor, str or array-like of 3 or 4 float in [0., 1.] or uint8) – RGB color: name, #RRGGBB or RGB values
getCutPlanes()[source]

Return an iterable of all cut planes of the view.

This includes hidden cut planes.

For now, there is always one cut plane.

setSelectedRegion(zrange=None, yrange=None, xrange_=None)[source]

Set the 3D selected region aligned with the axes.

Provided range are array indices range. The provided ranges are clipped to the data. If a range is None, the range of the array on this dimension is used.

Parameters:
  • zrange – (zmin, zmax) range of the selection
  • yrange – (ymin, ymax) range of the selection
  • xrange – (xmin, xmax) range of the selection
getSelectedRegion()[source]

Returns the currently selected region or None.

sigIsosurfaceAdded

Signal emitted when a new iso-surface is added to the view.

The newly added iso-surface is provided by this signal

sigIsosurfaceRemoved

Signal emitted when an iso-surface is removed from the view

The removed iso-surface is provided by this signal.

addIsosurface(level, color)[source]

Add an iso-surface to the view.

Parameters:
  • level (float or callable) – The value at which to build the iso-surface or a callable (e.g., a function) taking a 3D numpy.ndarray as input and returning a float. Example: numpy.mean(data) + numpy.std(data)
  • color (str or array-like of 4 float in [0., 1.]) – RGBA color of the isosurface
Returns:

Isosurface object describing this isosurface

getIsosurfaces()[source]

Return an iterable of all iso-surfaces of the view

removeIsosurface(isosurface)[source]

Remove an iso-surface from the view.

Parameters:isosurface – The isosurface object to remove
clearIsosurfaces()[source]

Remove all iso-surfaces from the view.

Helper classes

Those classes are used by ScalarFieldView.

Colormap

class silx.gui.plot3d.ScalarFieldView.Colormap(name, norm='linear', vmin=None, vmax=None)[source]

Bases: object

Description of a colormap

Parameters:
  • name (str) – Name of the colormap
  • norm (str) – Normalization: ‘linear’ (default) or ‘log’
  • vmin (float) – Lower bound of the colormap or None for autoscale (default)
  • vmax (float) – Upper bounds of the colormap or None for autoscale (default)
isAutoscale()[source]

True if both min and max are in autoscale mode

getName()[source]

Return the name of the colormap (str)

getNorm()[source]

Return the normalization of the colormap (str)

getVMin()[source]

Return the lower bound of the colormap or None

getVMax()[source]

Return the upper bounds of the colormap or None

CutPlane

class silx.gui.plot3d.ScalarFieldView.CutPlane(sfView)[source]

Bases: PyQt4.QtCore.QObject

Class representing a cutting plane

Parameters:sfView (ScalarFieldView) – Widget in which the cut plane is applied.
sigVisibilityChanged

Signal emitted when the cut visibility has changed.

This signal provides the new visibility status.

sigDataChanged

Signal emitted when the data this plane is cutting has changed.

sigPlaneChanged

Signal emitted when the cut plane has moved

sigColormapChanged

Signal emitted when the colormap has changed

This signal provides the new colormap.

sigInterpolationChanged

Signal emitted when the cut plane interpolation has changed

This signal provides the new interpolation mode.

moveToCenter()[source]

Move cut plane to center of data set

isValid()[source]

Returns whether the cut plane is defined or not (bool)

getNormal()[source]

Returns the normal of the plane (as a unit vector)

Returns:Normal (nx, ny, nz), vector is 0 if no plane is defined
Return type:numpy.ndarray
setNormal(normal)[source]

Set the normal of the plane

Parameters:normal – 3-tuple of float: nx, ny, nz
getPoint()[source]

Returns a point on the plane

Returns:(x, y, z)
Return type:numpy.ndarray
getParameters()[source]

Returns the plane equation parameters: a*x + b*y + c*z + d = 0

Returns:Plane equation parameters: (a, b, c, d)
Return type:numpy.ndarray
isVisible()[source]

Returns True if the plane is visible, False otherwise

setVisible(visible)[source]

Set the visibility of the plane

Parameters:visible (bool) – True to make plane visible
getStrokeColor()[source]

Returns the color of the plane border (QColor)

setStrokeColor(color)[source]

Set the color of the plane border.

Parameters:color (QColor, str or array-like of 3 or 4 float in [0., 1.] or uint8) – RGB color: name, #RRGGBB or RGB values
getImageData()[source]

Returns the data and information corresponding to the cut plane.

The returned data is not interpolated, it is a slice of the 3D scalar field.

Image data axes are so that plane normal is towards the point of view.

Returns:An object containing the 2D data slice and information
getInterpolation()[source]

Returns the interpolation used to display to cut plane.

Returns:‘nearest’ or ‘linear’
Return type:str
setInterpolation(interpolation)[source]

Set the interpolation used to display to cut plane

The default interpolation is ‘linear’

Parameters:interpolation (str) – ‘nearest’ or ‘linear’
getColormap()[source]

Returns the colormap set by getColormap().

Returns:The colormap
Return type:Colormap
setColormap(name='gray', norm='linear', vmin=None, vmax=None)[source]

Set the colormap to use.

Parameters:
  • name (str) – Name of the colormap in ‘gray’, ‘reversed gray’, ‘temperature’, ‘red’, ‘green’, ‘blue’.
  • norm (str) – Colormap mapping: ‘linear’ or ‘log’.
  • vmin (float) – The minimum value of the range or None for autoscale
  • vmax (float) – The maximum value of the range or None for autoscale
getColormapEffectiveRange()[source]

Returns the currently used range of the colormap.

This range is computed from the data set if colormap is in autoscale. Range is clipped to positive values when using log scale.

Returns:2-tuple of float

IsoSurface

class silx.gui.plot3d.ScalarFieldView.Isosurface(parent)[source]

Bases: PyQt4.QtCore.QObject

Class representing an iso-surface

Parameters:parent – The View widget this iso-surface belongs to
sigLevelChanged

Signal emitted when the iso-surface level has changed.

This signal provides the new level value (might be nan).

sigColorChanged

Signal emitted when the iso-surface color has changed

sigVisibilityChanged

Signal emitted when the iso-surface visibility has changed.

This signal provides the new visibility status.

isVisible()[source]

Returns True if iso-surface is visible, else False

setVisible(visible)[source]

Set the visibility of the iso-surface in the view.

Parameters:visible (bool) – True to show the iso-surface, False to hide
getLevel()[source]

Return the level of this iso-surface (float)

setLevel(level)[source]

Set the value at which to build the iso-surface.

Setting this value reset auto-level function

Parameters:level (float) – The value at which to build the iso-surface
isAutoLevel()[source]

True if iso-level is rebuild for each data set.

getAutoLevelFunction()[source]

Return the function computing the iso-level (callable or None)

setAutoLevelFunction(autoLevel)[source]

Set the function used to compute the iso-level.

WARNING: The function might get called in a thread.

Parameters:autoLevel (callable) – A function taking a 3D numpy.ndarray of float32 and returning a float used as iso-level. Example: numpy.mean(data) + numpy.std(data)
getColor()[source]

Return the color of this iso-surface (QColor)

setColor(color)[source]

Set the color of the iso-surface

Parameters:color (QColor, str or array-like of 4 float in [0., 1.]) – RGBA color of the isosurface

SelectedRegion

class silx.gui.plot3d.ScalarFieldView.SelectedRegion(arrayRange, translation=(0.0, 0.0, 0.0), scale=(1.0, 1.0, 1.0))[source]

Bases: object

Selection of a 3D region aligned with the axis.

Parameters:
  • arrayRange – Range of the selection in the array ((zmin, zmax), (ymin, ymax), (xmin, xmax))
  • translation – Offset from array to data coordinates (ox, oy, oz)
  • scale – Scale from array to data coordinates (sx, sy, sz)
getArrayRange()[source]

Returns array ranges of the selection: 3x2 array of int

Returns:A numpy array with ((zmin, zmax), (ymin, ymax), (xmin, xmax))
Return type:numpy.ndarray
getArraySlices()[source]

Slices corresponding to the selected range in the array

Returns:A numpy array with (zslice, yslice, zslice)
Return type:numpy.ndarray
getDataRange()[source]

Range in the data coordinates of the selection: 3x2 array of float

Returns:A numpy array with ((xmin, xmax), (ymin, ymax), (zmin, zmax))
Return type:numpy.ndarray
getDataScale()[source]

Scale from array to data coordinates: (sx, sy, sz)

Returns:A numpy array with (sx, sy, sz)
Return type:numpy.ndarray
getDataTranslation()[source]

Offset from array to data coordinates: (ox, oy, oz)

Returns:A numpy array with (ox, oy, oz)
Return type:numpy.ndarray