base

Base classes. Do not instantiate these.

Base3DProp

class vedo.base.Base3DProp[source]

Bases: object

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

Add vector to current object position.

bounds()[source]

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

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

Draw axes for the input object or for a specified range. Returns an Assembly object.

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

  • xrange, [None], x-axis range in format (xmin, ymin), default is automatic.

  • 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 vedo import Box, show

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

show(b, bax)

customAxes.py customAxes.py

customIndividualAxes.py customIndividualAxes.py

diagonalSize()[source]

Get the length of the diagonal of mesh bounding box.

getTransform()[source]

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

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.

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.

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

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

Set/Get object position.

printInfo()[source]

Print information about an 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.

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.

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

x(position=None)[source]

Set/Get object position along x axis.

xbounds()[source]

Get the bounds [xmin,xmax].

y(position=None)[source]

Set/Get object position along y axis.

ybounds()[source]

Get the bounds [ymin,ymax].

z(position=None)[source]

Set/Get object position along z axis.

zbounds()[source]

Get the bounds [zmin,zmax].

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]

Add Cell array and assign it a name.

mesh_coloring.py mesh_coloring.py

addCellScalars(scalars, name)[source]

addCellScalars is OBSOLETE: use addCellArray.

addCellVectors(vectors, name)[source]

addCellVectors is OBSOLETE: use addCellArray.

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.

mesh_coloring.py mesh_coloring.py

addPointScalars(scalars, name)[source]

addPointScalars is OBSOLETE: use addPointArray.

addPointVectors(vectors, name)[source]

addPointVectors is OBSOLETE: use addPointArray.

addScalarBar(pos=0.8, 0.05, title='', titleXOffset=0, titleYOffset=15, titleFontSize=12, 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='', titleXOffset=- 1.5, titleYOffset=0.0, titleSize=1.5, titleRotation=0.0, nlabels=9, labelOffset=0.375, italic=0, c=None, useAlpha=True, drawBox=True)[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)

mesh_coloring.py mesh_coloring.py

c(color=False)[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

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.

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

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

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.

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

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.

write(filename, binary=True)[source]

Write object to file.

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)[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=True, connectivity=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)

  • connectivity (bool) – if True only keeps the largest portion of the polydata

isosurfaces.py isosurfaces.py

legosurface(vmin=None, vmax=None, invert=False, cmap='afmhot_r')[source]

Represent 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

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