vtkio

Submodule to load meshes of different formats, and other I/O functionalities.

Video

class vedo.vtkio.Video(name='movie.mp4', duration=None, fps=24, backend='ffmpeg')[source]

Bases: object

Class to generate a video from the specified rendering window. Program ffmpeg is used to create video from each generated frame. :param str name: name of the output file. :param int fps: set the number of frames per second. :param float duration: set the total duration of the video and recalculates fps accordingly. :param str ffmpeg: set path to ffmpeg program. Default value considers ffmpeg is in the path.

makeVideo.py makeVideo.py

action(elevation_range=0, 80, azimuth_range=0, 359, zoom=None, cam1=None, cam2=None)[source]

Automatic shooting of the video with rotation and elevation ranges.

Parameters
  • elevation_range (list) – initial and final elevation angles

  • azimuth_range (list) – initial and final azimuth angles

  • zoom (float) – initial zooming

  • cam12 – initial and final camera position, can be dictionary or a vtkCamera

addFrame()[source]

Add frame to current video.

close()[source]

Render the video and write to file.

pause(pause=0)[source]

Insert a pause, in seconds.

download

vedo.vtkio.download(url, prefix='')[source]

Retrieve a file from a url, save it locally and return its path.

exportWindow

vedo.vtkio.exportWindow(fileoutput, binary=False, speed=None)[source]

Exporter which writes out the renderered scene into an HTML, X3D or Numpy file. X3D is an XML-based format for representation 3D scenes (similar to VRML). Check out http://www.web3d.org/x3d for more details.

Parameters

speed (float) – set speed for x3d files.

export_x3d.py export_x3d.py

generated webpage

See also: FEniCS test webpage.

Note

the rendering window can also be exported to numpy file scene.npy by pressing E keyboard at any moment during visualization.

gunzip

vedo.vtkio.gunzip(filename)[source]

Unzip a .gz file to a temporary file and returns its path.

importWindow

vedo.vtkio.importWindow(fileinput, mtlFile=None, texturePath=None)[source]

Import a whole scene from a Numpy or OBJ wavefront file. Return a Plotter instance.

Parameters
  • mtlFile (str) – MTL file for OBJ wavefront files.

  • texturePath (str) – path of the texture files directory.

load

vedo.vtkio.load(inputobj, c=None, alpha=1, threshold=False, spacing=(), unpack=True)[source]

Load Mesh, Volume and Picture objects from file.

The output will depend on the file extension. See examples below. Unzip on the fly, if it ends with .gz.

Parameters
  • c – color in RGB format, hex, symbol or name

  • alpha – transparency/opacity of the polygonal data.

For volumetric data (tiff, slc, vti etc..):

Parameters
  • c (list) – can be a list of any length of colors. This list represents the color transfer function values equally spaced along the range of the volumetric scalar.

  • alpha (list) – can be a list of any length of tranparencies. This list represents the transparency transfer function values equally spaced along the range of the volumetric scalar.

  • threshold (float) – value to draw the isosurface, False by default to return a Volume. If set to True will return an Mesh with automatic choice of the isosurfacing threshold.

  • spacing (list) – specify the voxel spacing in the three dimensions

  • unpack (bool) – only for multiblock data, if True returns a flat list of objects.

Examples
from vedo import datadir, load, show

# Return a Mesh object
g = load(datadir+'250.vtk')
show(g)

# Return a list of 2 meshes
g = load([datadir+'250.vtk', datadir+'270.vtk'])
show(g)

# Return a list of meshes by reading all files in a directory
# (if directory contains DICOM files then a Volume is returned)
g = load(datadir+'timecourse1d/')
show(g)

# Return a Volume. Color/Opacity transfer functions can be specified too.
g = load(datadir+'embryo.slc')
g.c(['y','lb','w']).alpha((0.0, 0.4, 0.9, 1))
show(g)

# Return a Mesh from a SLC volume with automatic thresholding
g = load(datadir+'embryo.slc', threshold=True)
show(g)

loadRectilinearGrid

vedo.vtkio.loadRectilinearGrid(filename)[source]

Load a vtkRectilinearGrid object from file.

loadStructuredGrid

vedo.vtkio.loadStructuredGrid(filename)[source]

Load a vtkStructuredGrid object from file.

loadStructuredPoints

vedo.vtkio.loadStructuredPoints(filename)[source]

Load a vtkStructuredPoints object from file.

loadUnStructuredGrid

vedo.vtkio.loadUnStructuredGrid(filename)[source]

Load a vtkunStructuredGrid object from file.

screenshot

vedo.vtkio.screenshot(filename='screenshot.png', scale=None, returnNumpy=False)[source]

Save a screenshot of the current rendering window.

Parameters
  • scale (int) – set image magnification

  • returnNumpy (bool) – return a numpy array of the image

write

vedo.vtkio.write(objct, fileoutput, binary=True)[source]

Write 3D object to file. (same as save()).

Possile extensions are:
  • vtk, vti, npy, ply, obj, stl, byu, vtp, vti, mhd, xyz, tif, png, bmp.