vtkio

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

Video

class vtkplotter.vtkio.Video(name='movie.avi', **kwargs)[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

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

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

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

exportWindow

vtkplotter.vtkio.exportWindow(fileoutput, binary=False, speed=None, html=True)[source]

Exporter which writes out the renderered scene into an OBJ, 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.
  • html (bool) – generate a test html page 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

vtkplotter.vtkio.gunzip(filename)[source]

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

importWindow

vtkplotter.vtkio.importWindow(fileinput)[source]

Import a whole scene from a Numpy file. Return Plotter instance.

load

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

Load Actor and Volume from file.

The output will depend on the file extension. See examples below.

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 Actor 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 vtkplotter import datadir, load, show

# Return an Actor
g = load(datadir+'250.vtk')
show(g)

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

# Return a list of actors 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 an Actor from a SLC volume with automatic thresholding
g = load(datadir+'embryo.slc', threshold=True)
show(g)

loadRectilinearGrid

vtkplotter.vtkio.loadRectilinearGrid(filename)[source]

Load a vtkRectilinearGrid object from file.

loadStructuredGrid

vtkplotter.vtkio.loadStructuredGrid(filename)[source]

Load a vtkStructuredGrid object from file.

loadStructuredPoints

vtkplotter.vtkio.loadStructuredPoints(filename)[source]

Load a vtkStructuredPoints object from file.

loadUnStructuredGrid

vtkplotter.vtkio.loadUnStructuredGrid(filename)[source]

Load a vtkunStructuredGrid object from file.

save

vtkplotter.vtkio.save(objct, fileoutput, binary=True)[source]

Save 3D object to file. (same as write()).

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

screenshot

vtkplotter.vtkio.screenshot(filename='screenshot.png')[source]

Save a screenshot of the current rendering window.

write

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