io

Submodule to load/write meshes and other objects in different formats, and other I/O functionalities.

Video

class vedo.io.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 assumes ffmpeg command is in the path.

makeVideo.py makeVideo.py

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

Automatic shooting of a static scene by specifying 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

  • cam2 (cam1) – 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. Return the current Plotter instance.

pause(pause=0)[source]

Insert a pause, in seconds.

ask

vedo.io.ask(*question, **kwarg)[source]

Ask a question from command line. Return the answer as a string. See function printc() for the description of the options.

Parameters
  • options (list) – a python list of possible answers to choose from.

  • default (str) – the default answer when just hitting return.

Example

import vedo
res = vedo.io.ask("Continue?", options=['Y','n'], default='Y', c='g')
print(res)

download

vedo.io.download(url, force=False, verbose=True)[source]

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

exportWindow

vedo.io.exportWindow(fileoutput, binary=False)[source]

Exporter which writes out the renderered scene into an HTML, X3D or Numpy file.

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.npz by pressing E keyboard at any moment during visualization.

gunzip

vedo.io.gunzip(filename)[source]

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

importWindow

vedo.io.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.io.load(inputobj, unpack=True, force=False)[source]

Load Mesh, Volume and Picture objects from file or from the web.

The output will depend on the file extension. See examples below. Unzip on the fly, if it ends with .gz. Can load an object directly from a URL address.

Parameters
  • unpack (bool) – unpack MultiBlockData into a flat list of objects.

  • force (bool) – when downloading a file ignore any previous cached downloads and force a new one.

Examples
from vedo import dataurl, load, show

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

# Return a list of 2 meshes
g = load([dataurl+'250.vtk', dataurl+'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('mydicomdir/')
show(g)

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

# Download a file from a URL address and unzip it on the fly
g = load('https://vedo.embl.es/examples/panther.stl.gz')
show(g)

loadRectilinearGrid

vedo.io.loadRectilinearGrid(filename)[source]

Load and return a vtkRectilinearGrid object from file.

loadStructuredGrid

vedo.io.loadStructuredGrid(filename)[source]

Load and return a vtkStructuredGrid object from file.

loadStructuredPoints

vedo.io.loadStructuredPoints(filename)[source]

Load and return a vtkStructuredPoints object from file.

loadTransform

vedo.io.loadTransform(filename)[source]

Load a vtkTransform from a file.mat.

Returns

  • T (vtkTransform) – The transformation to be applied to some object (use applyTransform()).

  • comment (str) – a comment string associated to this transformation file.

loadUnStructuredGrid

vedo.io.loadUnStructuredGrid(filename)[source]

Load and return a vtkunStructuredGrid object from file.

screenshot

vedo.io.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.io.write(objct, fileoutput, binary=True)[source]

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

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

writeTransform

vedo.io.writeTransform(inobj, filename='transform.mat', comment='')[source]

Save a transformation for a mesh or pointcloud to ASCII file.

Parameters
  • filename (str, optional) – output file name. The default is ‘transform.mat’.

  • comment (str, optional) – some optional comment. The default is ‘’.

Returns

Return type

None.