base¶
Base classes. Do not instantiate these.
Base3DProp¶

class
vedo.base.
Base3DProp
[source]¶ Bases:
object

address
()[source]¶ Return a unique memory address integer which can serve as the ID of the object, or passed to c++ code.

alignToBoundingBox
(msh, rigid=False)[source]¶ Align the current object’s bounding box to the bounding box of the input object.
 Parameters
rigid (bool) – do not allow scaling if set to True
 Example
from vedo import * eli = Ellipsoid().alpha(0.4) cube= Cube().pos(3,2,1).rotateX(10).rotateZ(10).alpha(0.4) eli.alignToBoundingBox(cube, rigid=False) axes1 = Axes(eli, c='db') axes2 = Axes(cube, c='dg') show(eli, cube, axes1, axes2)

bounds
()[source]¶ Get the object bounds. Returns a list in format [xmin,xmax, ymin,ymax, zmin,zmax].

buildAxes
(**kargs)[source]¶ Generate axes for the input object or for a specified range. Returns an
Assembly
object. Example
from vedo import Box, show b = Box(pos=(1,2,3), length=8, width=9, height=7).alpha(0) bax = b.buildAxes(c='k') # returns Assembly object show(b, bax)

getTransform
(invert=False)[source]¶ Check if
object.transform
exists and returns avtkTransform
. Otherwise return current user transformation (where the object is currently placed). Parameters
invert (bool) – return the inverse of the current transformation
 Example
from vedo import * c1 = Cube() c2 = c1.clone().c('violet').alpha(0.5) # copy of c1 v = vector(0.2,1,0) p = vector(1,0,0) # axis passes through this point c2.rotate(90, axis=v, point=p) # get the inverse of the current transformation T = c2.getTransform(invert=True) c2.applyTransform(T) # put back c2 in place l = Line(pv, p+v).lw(3).c('red') show(c1.wireframe().lw(3), l, c2, axes=1)

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.
 Example
from vedo import * objs = [] for i in range(5, 5): p = [i/3, i/2, i] v = vector(i/10, i/20, 1) c = Circle(r=i/5+1.2).pos(p).orientation(v).lw(3) objs += [c, Arrow(p,p+v)] show(objs, axes=1)

origin
(x=None, y=None, z=None)[source]¶ Set/get object’s origin. Relevant to control the scaling with scale() and rotations. Has no effect on position.

rotate
(angle, axis=(1, 0, 0), point=(0, 0, 0), rad=False)[source]¶ Rotate around an arbitrary axis passing through point.
 Example
from vedo import * c1 = Cube() c2 = c1.clone().c('violet').alpha(0.5) # copy of c1 v = vector(0.2,1,0) p = vector(1,0,0) # axis passes through this point c2.rotate(90, axis=v, point=p) l = Line(v+p, v+p).lw(3).c('red') show(c1, l, c2, axes=1)

scale
(s=None, absolute=False)[source]¶ Set/get object’s scaling factor.
 Parameters
Note
if s=(sx,sy,sz) scale differently in the three coordinates.

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
new (bool) – if set to True, a call to
show
will instantiate a newPlotter
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 vedo import * s = Sphere() s.show(at=1, N=2) c = Cube() c.show(at=0, interactive=True)

BaseActor¶

class
vedo.base.
BaseActor
[source]¶ Bases:
vedo.base.Base3DProp
Adds functionality to
Mesh
,Assembly
,Volume
andPicture
objects.Warning
Do not use this class to instance objects, use the above ones.

addIDs
(asfield=False)[source]¶ Generate point and cell ids.
 Parameters
asfield (bool) – flag to control whether to generate scalar or field data.

addScalarBar
(title='', pos=(0.8, 0.05), titleYOffset=15, titleFontSize=12, size=(None, None), nlabels=None, c=None, horizontal=False, useAlpha=True)[source]¶ Add a 2D scalar bar for the specified obj.

addScalarBar3D
(title='', pos=None, sx=None, sy=None, titleFont='', titleXOffset= 1.5, titleYOffset=0.0, titleSize=1.5, titleRotation=0.0, nlabels=9, labelFont='', labelOffset=0.375, italic=0, c=None, useAlpha=True, drawBox=True, aboveText=None, belowText=None, nanText='NaN')[source]¶ Draw a 3D scalar bar.
obj
input can be:a list of numbers,
a list of two numbers in the form (min, max),
a
Mesh
already containing a set of scalars associated to vertices or cells,if
None
the last object in the list of actors will be used.
Return an
Assembly
object. Parameters
title (str) – scalar bar title
sx (float) – thickness of scalarbar
sy (float) – length of scalarbar
titleXOffset (float) – horizontal space btw title and color scalarbar
titleYOffset (float) – vertical space offset
titleSize (float) – size of title wrt numeric labels
titleRotation (float) – title rotation in degrees
nlabels (int) – number of numeric labels
labelOffset (float) – space btw numeric labels and scale
useAlpha (bool) – render transparency of the color bar, otherwise ignore
drawBox (bool) – draw a box around the colorbar (useful with useAlpha=True)
aboveText (str) – text to show for above scale values
belowText (str) – text to show for below scale values
nanText (str) – text to show for nan values

c
(color=False, alpha=None)[source]¶ Shortcut for color(). If None is passed as input, will use colors from current active scalars.

divergence
(arrname=None, on='points', fast=False)[source]¶ Compute and return the divergence of a vector field as a numpy array.

findCellsWithin
(xbounds=(), ybounds=(), zbounds=(), c=None)[source]¶ Find cells that are within specified bounds. Setting a color will add a vtk array to colorize these cells.

getCellArray
(name=0)[source]¶ Return cell array content as a
numpy.array
. This can be identified either as a string or by an integer number.Getting an array also makes it the active one, if more than one is present.

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.Getting an array also makes it the active one, if more than one is present.

gradient
(arrname=None, on='points', fast=False)[source]¶ Compute and return the gradiend of a scalar field as a numpy array.
 Parameters

lighting
(style='', ambient=None, diffuse=None, specular=None, specularPower=None, specularColor=None)[source]¶ Set the ambient, diffuse, specular and specularPower lighting constants.
 Parameters
style (str,int) – preset style, option presets are [metallic, plastic, shiny, glossy, ambient, off]
ambient (float) – ambient fraction of emission [01]
diffuse (float) – emission of diffused light in fraction [01]
specular (float) – fraction of reflected light [01]
specularPower (float) – precision of reflection [1100]
specularColor (color) – color that is being reflected by the surface

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.

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
orMesh
. 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
char – use boldface
title (str) – histogram title
 Example
from vedo 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

selectCellArray
(name)[source]¶ Make this cell array the active one. Name can be a string or integer.

selectPointArray
(name)[source]¶ Make this point array the active one. Name can be a string or integer.

BaseGrid¶

class
vedo.base.
BaseGrid
[source]¶ Bases:
vedo.base.BaseActor

alpha
(alpha)[source]¶ Assign a set of tranparencies along the range of the scalar value. A single constant value can also be assigned.
E.g.: say alpha=(0.0, 0.3, 0.9, 1) and the scalar range goes from 10 to 150. Then all cells with a value close to 10 will be completely transparent, cells at 1/4 of the range will get an alpha equal to 0.3 and voxels with value close to 150 will be completely opaque.
As a second option one can set explicit (x, alpha_x) pairs to define the transfer function. E.g.: say alpha=[(5, 0), (35, 0.4) (123,0.9)] and the scalar range goes from 10 to 150. Then all cells below 5 will be completely transparent, cells with a scalar value of 35 will get an opacity of 40% and above 123 alpha is set to 90%.

alphaUnit
(u=None)[source]¶ Defines light attenuation per unit length. Default is 1. The larger the unit length, the further light has to travel to attenuate the same amount.
E.g., if you set the unit distance to 0, you will get full opacity. It means that when light travels 0 distance it’s already attenuated a finite amount. Thus, any finite distance should attenuate all light. The larger you make the unit distance, the more transparent the rendering becomes.

cells
()[source]¶ Get the cells connectivity ids as a numpy array. The output format is: [[id0 … idn], [id0 … idm], etc].

color
(col, alpha=None)[source]¶ Assign a color or a set of colors along the range of the scalar value. A single constant color can also be assigned. Any matplotlib color map name is also accepted, e.g.
volume.color('jet')
.E.g.: say that your cells scalar runs from 3 to 6, and you want 3 to show red and 1.5 violet and 6 green, then just set:
volume.color(['red', 'violet', 'green'])

cutWithBoundingBox
(box)[source]¶ Cut the grid with the specified bounding box.
Parameter box has format [xmin, xmax, ymin, ymax, zmin, zmax]. If a Mesh is passed, its bounding box is used.
Example
from vedo import * tetmesh = TetMesh(datadir+'limb_ugrid.vtk') tetmesh.color('rainbow') cu = Cube(side=500).x(500) # any Mesh works tetmesh.cutWithBox(cu).show(axes=1)

cutWithMesh
(mesh, invert=False, wholeCells=False, onlyBoundary=False)[source]¶ Cut a UGrid, TetMesh or Volume mesh with a Mesh.
 Parameters
invert (bool) – if True return cut off part of the input TetMesh.

cutWithPlane
(origin=(0, 0, 0), normal=(1, 0, 0))[source]¶ Cut the mesh with the plane defined by a point and a normal.
 Parameters
origin – the cutting plane goes through this point
normal – normal of the cutting plane

extractCellsByID
(idlist, usePointIDs=False)[source]¶ Return a new UGrid composed of the specified subset of indices.

isosurface
(threshold=None, largest=False)[source]¶ Return an
Mesh
isosurface extracted from theVolume
object. Parameters

legosurface
(vmin=None, vmax=None, invert=False, cmap='afmhot_r')[source]¶ Represent an object  typically a Volume  as lego blocks (voxels). By default colors correspond to the volume’s scalar. Returns an
Mesh
. Parameters

points
(pts=None, transformed=True, copy=False)[source]¶ Set/Get the vertex coordinates of the mesh. Argument can be an index, a set of indices or a complete new set of points to update the mesh.

tetralize
(tetsOnly=True)[source]¶ Tetralize the grid. If tetsOnly=True will cull all 1D and 2D cells from the output.
Return a TetMesh.
Example
from vedo import * ug = loadUnStructuredGrid(datadir+'ugrid.vtk') tmesh = tetralize(ug) tmesh.write('ugrid.vtu').show(axes=1)

tomesh
(fill=True, shrink=1.0)[source]¶ Build a polygonal Mesh from the current Grid object.
If fill=True, the interior faces of all the cells are created. (setting a shrink value slightly smaller than the default 1.0 can avoid flickering due to internal adjacent faces). If fill=False, only the boundary faces will be generated.

probeLine¶

vedo.base.
probeLine
(dataset, p1, p2, res=100)[source]¶ Takes a
Volume
(or any other vtk data set) and probes its scalars along a line defined by 2 points p1 and p2.Note that a mask is also output with valid/invalid points which can be accessed with mesh.getPointArray(‘vtkValidPointMask’).
 Parameters
res (int) – nr of points along the line
probePlane¶
probePoints¶
streamLines¶

vedo.base.
streamLines
(domain, probe, activeVectors='', integrator='rk4', direction='forward', initialStepSize=None, maxPropagation=None, maxSteps=10000, stepLength=None, extrapolateToBoundingBox=(), surfaceConstrain=False, computeVorticity=True, ribbons=None, tubes={}, scalarRange=None, lw=None)[source]¶ Integrate a vector field on a domain (a Mesh or other vtk datasets types) to generate streamlines.
The integration is performed using a specified integrator (RungeKutta). The length of a streamline is governed by specifying a maximum value either in physical arc length or in (local) cell length. Otherwise, the integration terminates upon exiting the field domain.
 Parameters
domain – the vtk object that contains the vector field
activeVectors (str) – name of the vector array
probe (Mesh,list) – the Mesh that probes the domain. Its coordinates will be the seeds for the streamlines, can also be an array of positions.
integrator (str) – RungeKutta integrator, either ‘rk2’, ‘rk4’ of ‘rk45’
initialStepSize (float) – initial step size of integration
maxPropagation (float) – maximum physical length of the streamline
maxSteps (int) – maximum nr of steps allowed
stepLength (float) – length of step integration.
extrapolateToBoundingBox (dict) –
Vectors defined on a surface are extrapolated to the entire volume defined by its bounding box
kernel, (str)  interpolation kernel type [shepard]
radius (float) radius of the local search
bounds, (list)  bounding box of the output Volume
dims, (list)  dimensions of the output Volume object
nullValue, (float)  value to be assigned to invalid points
surfaceConstrain (bool) – force streamlines to be computed on a surface
computeVorticity (bool) – Turn on/off vorticity computation at streamline points (necessary for generating proper streamribbons)
ribbons (int) – render lines as ribbons by joining them. An integer value represent the ratio of joining (e.g.: ribbons=2 groups lines 2 by 2)
tubes (dict) –
dictionary containing the parameters for the tube representation:
ratio, (int)  draws tube as longitudinal stripes
res, (int)  tube resolution (nr. of sides, 12 by default)
maxRadiusFactor (float)  max tube radius as a multiple of the min radius
varyRadius, (int)  radius varies based on the scalar or vector magnitude:
0  do not vary radius
1  vary radius by scalar
2  vary radius by vector
3  vary radius by absolute value of scalar
scalarRange (list) – specify the scalar range for coloring