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

  • pad (float,list) – a constant pad can be added (can be a list [padx,pady,padz])

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)

customAxes1.py customAxes1.py customAxes2.py customAxes3.py

customIndividualAxes.py customIndividualAxes.py

diagonalSize()[source]

Get the length of the diagonal of mesh bounding box.

draggable(value=None)[source]

Set/get draggable property of an object.

getTransform(invert=False)[source]

Check if object.transform exists and returns a vtkTransform. 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(p-v, p+v).lw(3).c('red')
show(c1.wireframe().lw(3), l, c2, axes=1)
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.

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

gyroscope2.py gyroscope2.py

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.

print()[source]

Print information about an object.

printInfo()[source]

Obsolete, use print() instead.

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, locally=False)[source]

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

Parameters

locally (bool) – ignore previous transformations. Rotate around object local origin.

rotateY(angle, rad=False, locally=False)[source]

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

Parameters

locally (bool) – ignore previous transformations. Rotate around object local origin.

rotateZ(angle, rad=False, locally=False)[source]

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

Parameters

locally (bool) – ignore previous transformations. Rotate around object local origin.

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]

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

show(**options)[source]

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

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

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]

Bases: vedo.base.Base3DProp

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]

Deprecated. Use myobj.celldata[name] = input_array` instead.

addIDs(asfield=False)[source]

Generate point and cell ids.

addPointArray(input_array, name)[source]

Deprecated. Use myobj.pointdata[name] = input_array` instead.

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='', labelSize=1, labelOffset=0.375, labelRotation=0, italic=0, c=None, useAlpha=True, drawBox=True, aboveText=None, belowText=None, nanText='NaN', categories=None)[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

  • labelFont (str) – font type for labels

  • labelSize (float) – label scale factor

  • labelOffset (float) – space btw numeric labels and scale

  • labelRotation (float) – label rotation in degrees

  • 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

mesh_coloring.py mesh_coloring.py

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.

delaunay2d.py delaunay2d.py

property celldata

Create and/or return a numpy.array associated to cells (faces). A data array can be indexed either as a string or by an integer number. E.g.: myobj.celldata["arrayname"]

Use:

myobj.celldata.keys() to return the available data array names

myobj.celldata.select(name) to make this array the active one

myobj.celldata.remove(name) to remove this array

deleteCells(ids)[source]

Remove cells from the mesh object by ID. Points (vertices) are not affected.

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.

getCellArray(name=0)[source]

Deprecated. Use myobj.celldata[name]` instead.

getPointArray(name=0)[source]

Deprecated. Use myobj.pointdata[name]` instead.

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

isolines.py isolines.py

inputdata()[source]

Return the VTK input data object.

lighting(style='', ambient=None, diffuse=None, specular=None, specularPower=None, specularColor=None, metallicity=None, roughness=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

wikiphong

specular.py specular.py

mapCellsToPoints()[source]

Interpolate cell data (i.e., data specified per cell or face) 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]

Interpolate point data (i.e., data specified per point or vertex) 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.

property pointdata

Create and/or return a numpy.array associated to points (vertices). A data array can be indexed either as a string or by an integer number. E.g.: myobj.pointdata["arrayname"]

Use:

myobj.pointdata.keys() to return the available data array names

myobj.pointdata.select(name) to make this array the active one

myobj.pointdata.remove(name) to remove this array

points(pts=None, transformed=True)[source]

Set/Get the vertex coordinates of a mesh or point cloud. 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.

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

printhisto

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]

Bases: vedo.base.BaseActor

alpha(alpha, vmin=None, vmax=None)[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, vmin=None, vmax=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'])

Parameters
  • alpha (list) – use a list to specify transparencies along the scalar range

  • vmin (float) – force the min of the scalar range to be this value

  • vmax (float) – force the max of the scalar range to be this value

cutWithBox(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(dataurl+'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 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

isosurfaces.py isosurfaces.py

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.

legosurface.py legosurface.py

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.

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.pointdata[‘vtkValidPointMask’].

Parameters

res (int) – nr of points along the line

probeLine1.py probeLine1.py probeLine2.py

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.pointdata[‘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]

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

    • 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