base

Submodule extending the vtkActor, vtkVolume and vtkImageActor objects functionality.

ActorBase

class vtkplotter.base.ActorBase[source]

Bases: object

Adds functionality to Mesh(vtkActor), Assembly, Volume and Picture objects.

Warning

Do not use this class to instance objects, use the above ones.

N()[source]

Retrieve number of points. Shortcut for NPoints().

NCells()[source]

Retrieve number of cells.

NPoints()[source]

Retrieve number of points. Same as N().

addCellScalars(scalars, name)[source]

Add cell scalars and assign it a name.

addCellVectors(vectors, name)[source]

Add a vector field to each object cell and assign it a name.

addPointScalars(scalars, name)[source]

Add point scalars and assign it a name.

mesh_coloring.py mesh_coloring.py

addPointVectors(vectors, name)[source]

Add a point vector field to the object and assign it a name.

addPos(dp_x=None, dy=None, dz=None)[source]

Add vector to current object position.

bounds()[source]

Get the bounds of the data object.

box(scale=1)[source]

Return the bounding box as a new Mesh.

Parameters

scale (float) – box size can be scaled by a factor

Hint

latex.py

buildAxes(**kargs)[source]

Draw axes on a Mesh or Volume. Returns a Assembly object.

  • xtitle, [‘x’], x-axis title text.

  • ytitle, [‘y’], y-axis title text.

  • ztitle, [‘z’], z-axis title text.

  • numberOfDivisions,[None], approximate number of divisions on the longest axis

  • axesLineWidth, [1], width of the axes lines

  • gridLineWidth, [1], width of the grid lines

  • reorientShortTitle, [True], titles shorter than 2 letter are placed horizontally

  • originMarkerSize, [0.01], draw a small cube on the axis where the origin is

  • titleDepth, [0], extrusion fractional depth of title text

  • xyGrid, [True], show a gridded wall on plane xy

  • yzGrid, [True], show a gridded wall on plane yz

  • zxGrid, [True], show a gridded wall on plane zx

  • zxGrid2, [False], show zx plane on opposite side of the bounding box

  • xyGridTransparent [False], make grid plane completely transparent

  • xyGrid2Transparent [False], make grid plane completely transparent on opposite side box

  • xyPlaneColor, [‘gray’], color of the plane

  • xyGridColor, [‘gray’], grid line color

  • xyAlpha, [0.15], grid plane opacity

  • showTicks, [True], show major ticks

  • xTitlePosition, [0.32], title fractional positions along axis

  • xTitleOffset, [0.05], title fractional offset distance from axis line

  • xTitleJustify, [“top-right”], title justification

  • xTitleRotation, [0], add a rotation of the axis title

  • xLineColor, [automatic], color of the x-axis

  • xTitleColor, [automatic], color of the axis title

  • xTitleBackfaceColor, [None], color of axis title on its backface

  • xTitleSize, [0.025], size of the axis title

  • xHighlightZero, [True], draw a line highlighting zero position if in range

  • xHighlightZeroColor, [automatic], color of the line highlighting the zero position

  • xTickRadius, [0.005], radius of the major ticks

  • xTickThickness, [0.0025], thickness of the major ticks along their axis

  • xTickColor, [automatic], color of major ticks

  • xMinorTicks, [1], number of minor ticks between two major ticks

  • tipSize, [0.01], size of the arrow tip

  • xPositionsAndLabels [], assign custom tick positions and labels [(pos1, label1), …]

  • xLabelPrecision, [2], nr. of significative digits to be shown

  • xLabelSize, [0.015], size of the numeric labels along axis

  • xLabelOffset, [0.025], offset of numeric labels

  • limitRatio, [0.04], below this ratio don’t plot small axis

Example
from vtkplotter import Box, show

b = Box(pos=(1,2,3), length=8, width=9, height=7).alpha(0)
bax = buildAxes(b, c='white')  # returns Assembly object

show(b, bax)

customAxes.py customAxes.py

customIndividualAxes.py customIndividualAxes.py

c(color=False)[source]

Shortcut for color(). If None is passed as input, will use colors from current active scalars.

flag(text=None)[source]

Add a flag label which becomes visible when hovering the object with mouse. Can be later disabled by setting flag(False).

getArrayNames()[source]
getCellArray(name=0)[source]

Return cell array content as a numpy.array.

getPointArray(name=0)[source]

Return point array content as a numpy.array. This can be identified either as a string or by an integer number.

getTransform()[source]

Check if info['transform'] exists and returns it. Otherwise return current user transformation (where the object is currently placed).

inputdata()[source]

Return the VTK input data object.

legend(txt=None)[source]

Set/get Mesh legend text.

Parameters

txt (str) – legend text.

Size and positions can be modified by setting attributes Plotter.legendSize, Plotter.legendBC and Plotter.legendPos.

lighting(style='', ambient=None, diffuse=None, specular=None, specularPower=None, specularColor=None, enabled=True)[source]

Set the ambient, diffuse, specular and specularPower lighting constants.

Parameters
  • style (str,int) – preset style, can be [metallic, plastic, shiny, glossy, ambient]

  • ambient (float) – ambient fraction of emission [0-1]

  • diffuse (float) – emission of diffused light in fraction [0-1]

  • specular (float) – fraction of reflected light [0-1]

  • specularPower (float) – precision of reflection [1-100]

  • specularColor (color) – color that is being reflected by the surface

  • enabled (bool) – enable/disable all surface light emission

wikiphong

specular.py specular.py

mapCellsToPoints()[source]

Transform cell data (i.e., data specified per cell) into point data (i.e., data specified at each vertex). The method of transformation is based on averaging the data values of all cells using a particular point.

mapPointsToCells()[source]

Transform point data (i.e., data specified per point) into cell data (i.e., data specified per cell). The method of transformation is based on averaging the data values of all points defining a particular cell.

mesh_map2cell.py mesh_map2cell.py

mapper(newMapper=None)[source]

Return the vtkMapper data object, or update it with a new one.

off()[source]

Switch off object visibility. Object is not removed.

on()[source]

Switch on object visibility. Object is not removed.

orientation(newaxis=None, rotation=0, rad=False)[source]

Set/Get object orientation.

Parameters
  • rotation – If != 0 rotate object around newaxis.

  • rad – set to True if angle is in radians.

gyroscope2.py gyroscope2.py

pickable(value=None)[source]

Set/get pickable property of mesh.

pos(x=None, y=None, z=None)[source]

Set/Get object position.

print()[source]

Print Mesh, Assembly, Volume or Image infos.

printHistogram(bins=10, height=10, logscale=False, minbin=0, horizontal=False, char='▉', c=None, bold=True, title='Histogram')[source]

Ascii histogram printing. Input can also be Volume or Mesh. Returns the raw data before binning (useful when passing vtk objects).

Parameters
  • bins (int) – number of histogram bins

  • height (int) – height of the histogram in character units

  • logscale (bool) – use logscale for frequencies

  • minbin (int) – ignore bins before minbin

  • horizontal (bool) – show histogram horizontally

  • char (bool) – character to be used

  • c (str,int) – ascii color

  • char – use boldface

  • title (str) – histogram title

Example
from vtkplotter import printHistogram
import numpy as np
d = np.random.normal(size=1000)
data = printHistogram(d, c='blue', logscale=True, title='my scalars')
data = printHistogram(d, c=1, horizontal=1)
print(np.mean(data)) # data here is same as d

printhisto

printInfo()[source]

Print information about a vtk object.

rotate(angle, axis=(1, 0, 0), axis_point=(0, 0, 0), rad=False)[source]

Rotate around an arbitrary axis passing through axis_point.

rotateX(angle, rad=False)[source]

Rotate around x-axis. If angle is in radians set rad=True.

NB: mesh.rotateX(12).rotateY(14) will rotate FIRST around Y THEN around X.

rotateY(angle, rad=False)[source]

Rotate around y-axis. If angle is in radians set rad=True.

NB: mesh.rotateX(12).rotateY(14) will rotate FIRST around Y THEN around X.

rotateZ(angle, rad=False)[source]

Rotate around z-axis. If angle is in radians set rad=True.

NB: mesh.rotateX(12).rotateZ(14) will rotate FIRST around Z THEN around X.

scale(s=None)[source]

Set/get object’s scaling factor.

Parameters

s (float, list) – scaling factor(s).

Note

if s==(sx,sy,sz) scale differently in the three coordinates.

setTransform(T)[source]

Transform object position and orientation.

show(**options)[source]

Create on the fly an instance of class Plotter or use the last existing one to show one single object.

This is meant as a shortcut. If more than one object needs to be visualised please use the syntax show([mesh1, mesh2, volume, …], options).

Parameters

newPlotter (bool) – if set to True, a call to show will instantiate a new Plotter object (a new window) instead of reusing the first created. See e.g.: readVolumeAsIsoSurface.py

Returns

the current Plotter class instance.

Note

E.g.:

from vtkplotter import *
s = Sphere()
s.show(at=1, N=2)
c = Cube()
c.show(at=0, interactive=True)
time(t=None)[source]

Set/get object’s absolute time.

x(position=None)[source]

Set/Get object position along x axis.

y(position=None)[source]

Set/Get object position along y axis.

z(position=None)[source]

Set/Get object position along z axis.