# base¶

Base classes. Do not instantiate these.

## Base3DProp¶

class vedo.base.Base3DProp[source]

Bases: object

addPos(dx=0, dy=0, dz=0)[source]

Add vector to current object position. Same as shift().

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)

applyTransform(T)[source]

Transform object position and orientation.

bounds()[source]

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

box(scale=1, pad=0, fill=False)[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]

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)

diagonalSize()[source]

Get the length of the diagonal of mesh bounding box.

draggable(value=None)[source]

Set/get draggable property of an object.

getTransform()[source]

Check if info.transform exists and returns a vtkTransform. Otherwise return current user transformation (where the object is currently placed).

maxBoundSize()[source]

Get the maximum size in x, y or z of the bounding box.

minBoundSize()[source]

Get the minimum size in x, y or z of the bounding box.

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.

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.

pickable(value=None)[source]

Set/get pickable property of an object.

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

Set/Get object position.

printInfo()[source]

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)

rotateX(angle, rad=False)[source]

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

rotateY(angle, rad=False)[source]

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

rotateZ(angle, rad=False)[source]

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

scale(s=None, absolute=False)[source]

Set/get object’s scaling factor.

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

• absolute (bool) – if True previous scaling factors are ignored.

Note

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

shift(dx=0, dy=0, dz=0)[source]

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 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 vedo 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.

useBounds(ub=True)[source]

Instruct the current camera to either take into account or ignore the object bounds when resetting.

x(position=None)[source]

Set/Get object position along x axis.

xbounds(i=None)[source]

Get the bounds [xmin,xmax]. Can specify upper or lower with i (0,1).

y(position=None)[source]

Set/Get object position along y axis.

ybounds(i=None)[source]

Get the bounds [ymin,ymax]. Can specify upper or lower with i (0,1).

z(position=None)[source]

Set/Get object position along z axis.

zbounds(i=None)[source]

Get the bounds [zmin,zmax]. Can specify upper or lower with i (0,1).

## BaseActor¶

class vedo.base.BaseActor[source]

Adds functionality to Mesh, 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().

addCellArray(input_array, name)[source]

Add Cell array and assign it a name.

addIDs(asfield=False)[source]

Generate point and cell ids.

Parameters

asfield (bool) – flag to control whether to generate scalar or field data.

addPointArray(input_array, name)[source]

Add point array and assign it a name.

addScalarBar(pos=0.8, 0.05, title='', 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(pos=None, sx=None, sy=None, title='', 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
• sx (float) – thickness of scalarbar

• sy (float) – length of scalarbar

• title (str) – scalar bar title

• 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

• italic (bool,float) – use italic font for title and labels

• 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.

cellCenters()[source]

Get the coordinates of the cell centers.

divergence(arrname=None, on='points', fast=False)[source]

Compute and return the divergence of a vector field as a numpy array.

Parameters
• arrname (str) – name of an existing field

• on (str) – defined either on ‘points’ or ‘cells’

• fast (bool) – if True, will use a less accurate algorithm that performs fewer derivative calculations (and is therefore faster).

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.

getArrayNames()[source]
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
• arrname (str) – name of an existing field

• on (str) – defined either on ‘points’ or ‘cells’

• fast (bool) – if True, will use a less accurate algorithm that performs fewer derivative calculations (and is therefore faster).

inputdata()[source]

Return the VTK input data object.

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 [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

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.

mapper(newMapper=None)[source]

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

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 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


removeCellArray(name)[source]

Reomve cell array from object.

removePointArray(name)[source]

Reomve point array from object.

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.

vorticity(arrname=None, on='points', fast=False)[source]

Compute and return the vorticity of a vector field as a numpy array.

Parameters
• arrname (str) – name of an existing field

• on (str) – defined either on ‘points’ or ‘cells’

• fast (bool) – if True, will use a less accurate algorithm that performs fewer derivative calculations (and is therefore faster).

write(filename, binary=True)[source]

Write object to file.

## BaseGrid¶

class vedo.base.BaseGrid[source]
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.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 the Volume object.

Parameters
• threshold (float,list) – value or list of values to draw the isosurface(s)

• largest (bool) – if True keep only the largest portion of the mesh

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
• vmin (float) – the lower threshold, voxels below this value are not shown.

• vmax (float) – the upper threshold, voxels above this value are not shown.

• cmap (str) – color mapping of the scalar associated to the voxels.

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.

Parameters
• transformed (bool) – if False ignore any previous transformation applied to the mesh.

• copy (bool) – if False return the reference to the points so that they can be modified in place, otherwise a copy is built.

shrink(fraction=0.8)[source]

Shrink the individual cells to improve visibility.

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 *
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¶

vedo.base.probePlane(dataset, origin=0, 0, 0, normal=1, 0, 0)[source]

Takes a Volume (or any other vtk data set) and probes its scalars on a plane defined by a point and a normal.

## probePoints¶

vedo.base.probePoints(dataset, pts)[source]

Takes a Volume (or any other vtk data set) and probes its scalars at the specified points in space.

Note that a mask is also output with valid/invalid points which can be accessed with mesh.getPointArray(‘vtkValidPointMask’).

## 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 (Runge-Kutta). 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) – Runge-Kutta 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]

• 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 stream-ribbons)

• 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)

• 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

Hint