vis module¶
Classes and functions to deal with the visualisation of the AmpObjects. These include wrappers for vtk and Qt Copyright: Joshua Steer 2020, Joshua.Steer@soton.ac.uk
-
class
ampActor
(CMap=None, bands=128) Bases:
sphinx.ext.autodoc.importer._MockObject
A wrapper around the classic vtkActor that makes it easier to transfer data from the ampObject
-
addSlices
(slices) Adds slices into the AmpActor which can then be rendered
Parameters: slices (array_like) – The values in the z-axis of which to make the slices
-
setCMap
(CMap, bands=128) Sets the colormap used to display scalar values
Parameters: - CMap (array_like) – The base colors used to define the color map
- bands (int, default 128) – The number of contour bands to divide up the color map
-
setColor
(color=[1.0, 1.0, 1.0]) Sets the color of the ampActor
Parameters: color (array_like, default [1.0, 1.0, 1.0]) – The RGB values as floats of the ampActor colour between [0, 1]
-
setFaces
(faces, deep=0) Sets the faces of the ampActor
Parameters: - faces (ndarray) – The numpy array specifying the faces, or connectivity index based upon the vertex array
- deep (int, default 0) – If 1, the numpy array will be deep-copied to the ampActor
-
setNorm
(norm=None, deep=0) Sets or calculates the vertex normals
Parameters: - norm (ndarray, default None) – The numpy array specifying the face normals. If None, the inbuilt vtk method will be used to calculate the normals
- deep (int, default 0) – If 1, the numpy array will be deep-copied to the ampActor
-
setOpacity
(opacity=1.0) Sets the opacity of the ampActor
Parameters: opacity (float, default 1.0) – Opacity value between [0 1]
-
setScalarRange
(sRange) Sets the scalar range on the ampActor
Parameters: sRange (array_like) – Specifies the lower and upper bound of the scalar range to display
-
setShading
(shading=True) Sets whether shading is used on the ampActor
Parameters: shading (boolean, default True) – If True, shading is used in the display of the ampActor
-
setValues
(values, deep=0) Set the values of the ampActor
Parameters: - values (ndarray) – Scalar data attached to each vertex
- deep (int, default 0) – If 1, the numpy array will be deep-copied to the ampActor
-
setVert
(vert, deep=0) Set the vertices of the ampActor
Parameters: - vert (ndarray) – The numpy array specifying the vertices
- deep (int, default 0) – If 1, the numpy array will be deep-copied to the ampActor
-
-
class
qtVtkWindow
Bases:
sphinx.ext.autodoc.importer._MockObject
This provides the interface between Qt and the vtkRenWin
-
class
visMixin
Bases:
object
Set of visualisation methods that are contained within the AmpActor
-
addActor
(CMap=None, bands=128, sRange=[0, 8]) Creates an ampActor based upon the ampObject
-
createCMap
(cmap=None, n=50) Function to generate a linear colormap for the AmpObj based upon base colours
- cmap: array_like
- The rgb float values of the base colors used to generate the colormap
- n: int, default 50
- The number of bands that form the colormap
-
display
() Function to display the ampActor within in an interactable vtkRenWin window
Returns: win – The generated vtkRenWin Return type: vtkRenWin
-
genIm
(size=[512, 512], views=[[0, -1, 0]], background=[1.0, 1.0, 1.0], projection=True, shading=True, mag=10, out='im', fh='test.tiff', zoom=1.0, az=0, el=0, crop=False, cam=None) Creates a temporary off screen vtkRenWin which is then either returned as a numpy array or saved as a .png file
Parameters: - out (str: default 'im') – If ‘im’ the the image will be returned as an array, if ‘fh’ the image will be saved as .png image
- size (array_like, default [512, 512]) – The width and height of the vtkRenWin to create
- views (array_like, default [[0, -1, 0],]) – The camera view set for each viewport, the length of this also sets the number of viewports
- background (array_like, default [1, 1, 1]) – The RGB values as floats of the background colour between [0, 1]
- projection (boolean, default True) – If true, then perspective will be used as the projection for the camera
- shading (boolean, default True) – If true, shading will be used on the ampActor
- mag (int, default 10) – The magnification for saving the image
- fh (str) – The file handle used if out =’fh’
Returns: im – The array representation of the image if out = ‘im’
Return type: ndarray
-
-
class
vtkRenWin
Bases:
sphinx.ext.autodoc.importer._MockObject
This class inherits from the vtkRenderWindow and wraps extra functions on top
This window can be either be used on it’s own, or embedded within a Qt Window
-
Pick_point
(loc) This receives coordinates in the GUI where user has picked, converts it to mesh coordinates using vtkCellPicker, and places a sphere at picked location as a visual aid. Also places a label at the point in the render window. TO-DO: Add functionality so user can type the label in, rather than have it read ‘Mid Patella’ every time
-
addAxes
(actors, viewport=0, color=[1.0, 1.0, 1.0], font=None) Add 3D axes to the vtk window
Parameters: - actors (list) – List of ampActors, this is used to determine the necessary limits of the axes
- viewport (int, default 0) – The index of the viewport add the axes into
- color (array_like) – The RGB values as floats of the axes line and text colour between [0, 1]
-
addTriad
(actors, viewport=0, color=[1.0, 1.0, 1.0], font=None) Add 3D axes to the vtk window
Parameters: - actors (list) – List of ampActors, this is used to determine the necessary limits of the axes
- viewport (int, default 0) – The index of the viewport add the axes into
- color (array_like) – The RGB values as floats of the axes line and text colour between [0, 1]
-
delMarker
() removes the sphere marker and label from the renderer
-
getImage
() Return an array representation of the image
Returns: im – The array representation of the image Return type: ndarray
-
getScreenshot
(fname, mag=10) Generate a screenshot of the window and save to a png file
Parameters: - fname (str) – The file handle to save the image to
- mag (int, default 10) – The magnificaiton of the image, this will scale the resolution of the saved image by this face
-
mark
(x, y, z) mark the picked point with a sphere
-
renderActors
(actors, viewport=0, zoom=1.0) Given a list of ampActors, this function removes those which are not in the new list, and adds in the new ones
Parameters: - actors (list of ampActors) – A list of actors to be displayed in the render window
- viewport (int, default 0) – The viewport index to render the actor within
- zoom (float, default 1.0) – The zoom magnitude of the camera
-
setBackground
(color=[0.1, 0.2, 0.4]) Set the background colour of the renderer
Parameters: color (array_like) – The RGB values as floats of the background colour between [0, 1]
-
setProjection
(perspective=False, viewport=0) Set the projection of the camera to either parallel or perspective
Parameters: - perspective (boolean, default False) – If true, then perspective will be used as the projection for the camera
- viewport (int, default 0) – The index of the viewport to set the projection of the camera in
-
setScalarBar
(actor, viewport=0, title='') Set the scalar bar within the window based upon a look-up table defined within an actor
Parameters: - actor (ampActor) – The actor from which the lut is read from, the actor must have the attribute actor.lut
- viewport (int, default 0) – The viewport index to render the scalar bar within
- title (str) – The accompanying title for the scalar bar
Returns: A vtkScalarBarActor attribute to the vtkRenWin
Return type: scalar_bar
-
setView
(view=[0, -1, 0], viewport=0) Function to set the camera view within the specified viewport
Parameters: - view (array_like, default [0, -1, 0]) – The view of the vtk camera
- viewport (int, default 0) – The index of the viewport to set the camera view
-
setnumViewports
(n) Function to set multiple viewports within the vtkWindow
Parameters: n (int) – number of viewports required
-