A python module for scientific visualization, analysis of 3D objects and point clouds.
Comprehensive file format support for loading and saving 3D data, with functions for various mesh formats, volumetric data, images, and specialized scientific data formats. Vedo provides extensive I/O capabilities for integrating with existing workflows and data pipelines.
Primary functions for loading various 3D file formats and data sources.
def load(filename, unpack=True, force=False):
"""
Load 3D objects from various file formats.
Supported formats: STL, OBJ, PLY, VTK, VTP, VTU, VTS, VTI, XML,
3DS, X3D, COLLADA, OFF, NRRD, DICOM, TIF, PNG, JPG, BMP, and more.
Parameters:
- filename: str or list
File path(s) to load
- unpack: bool, default True
If False, return list even for single file
- force: bool, default False
Force reload even if already cached
Returns:
Mesh, Points, Volume, Image, or list: Loaded object(s)
"""
def read(filename, unpack=True, force=False):
"""
Alias for load() function.
Parameters:
- filename: str or list
File path(s) to load
- unpack: bool, default True
If False, return list even for single file
- force: bool, default False
Force reload even if already cached
Returns:
Mesh, Points, Volume, Image, or list: Loaded object(s)
"""
def download(url, filename=None, force=False, verbose=True):
"""
Download files from URLs.
Parameters:
- url: str
URL to download from
- filename: str, optional
Local filename to save to
- force: bool, default False
Force re-download if file exists
- verbose: bool, default True
Print download progress
Returns:
str: Path to downloaded file
"""
def gunzip(filename):
"""
Decompress gzipped files.
Parameters:
- filename: str
Path to gzipped file
Returns:
str: Path to decompressed file
"""Functions for exporting vedo objects to various file formats.
def save(obj, filename, binary=True):
"""
Save vedo objects to files.
Supported formats: STL, OBJ, PLY, VTK, VTP, VTU, X3D,
COLLADA, OFF, and more based on file extension.
Parameters:
- obj: vedo object
Object to save (Mesh, Points, Volume, etc.)
- filename: str
Output file path with extension
- binary: bool, default True
Use binary format when available
Returns:
str: Path to saved file
"""
def write(obj, filename, binary=True):
"""
Alias for save() function.
Parameters:
- obj: vedo object
Object to save
- filename: str
Output file path
- binary: bool, default True
Use binary format when available
Returns:
str: Path to saved file
"""Functions for loading specific data types and formats.
def loadStructuredPoints(filename):
"""
Load VTK structured points data.
Parameters:
- filename: str
Path to structured points file
Returns:
Volume: Loaded volume object
"""
def loadStructuredGrid(filename):
"""
Load VTK structured grid data.
Parameters:
- filename: str
Path to structured grid file
Returns:
StructuredGrid: Loaded grid object
"""Functions for capturing and managing visualization windows.
def screenshot(filename="screenshot.png", scale=1, asarray=False):
"""
Capture screenshot of current visualization.
Parameters:
- filename: str, default "screenshot.png"
Output image filename
- scale: int, default 1
Image scaling factor for resolution
- asarray: bool, default False
Return numpy array instead of saving file
Returns:
str or numpy.ndarray: Filename or image array
"""
def export_window(filename, binary=False):
"""
Export entire rendering window state.
Parameters:
- filename: str
Output file path
- binary: bool, default False
Use binary format
Returns:
str: Path to exported file
"""
def import_window(filename):
"""
Import rendering window state from file.
Parameters:
- filename: str
Path to window state file
Returns:
Plotter: Restored plotter instance
"""Class for creating animations and video sequences.
class Video:
"""
Create video sequences from vedo visualizations.
Parameters:
- name: str, default "movie.mp4"
Output video filename
- fps: int, default 24
Frames per second
- duration: float, optional
Total video duration in seconds
- backend: str, default "ffmpeg"
Video encoding backend
"""
def __init__(self, name="movie.mp4", fps=24, duration=None, backend="ffmpeg"): ...
def add_frame(self):
"""Add current visualization as video frame."""
def pause(self, pause=0):
"""
Add pause/delay in video.
Parameters:
- pause: float, default 0
Pause duration in seconds
"""
def close(self):
"""Finalize and save video file."""Details about supported file formats and their capabilities.
# Supported input formats (load/read):
MESH_FORMATS = [
".stl", # Stereolithography
".obj", # Wavefront OBJ
".ply", # Polygon File Format
".vtk", # VTK Legacy
".vtp", # VTK PolyData
".vtu", # VTK Unstructured Grid
".vts", # VTK Structured Grid
".vti", # VTK Image Data
".xml", # VTK XML formats
".3ds", # 3D Studio
".x3d", # X3D
".dae", # COLLADA
".off", # Object File Format
".facet" # Facet format
]
VOLUME_FORMATS = [
".nrrd", # Nearly Raw Raster Data
".nii", # NIfTI
".mhd", # MetaImage
".vti", # VTK Image Data
".tif", # TIFF stacks
".dcm" # DICOM
]
IMAGE_FORMATS = [
".png", # Portable Network Graphics
".jpg", # JPEG
".jpeg", # JPEG
".bmp", # Bitmap
".tif", # TIFF
".tiff" # TIFF
]
# Supported output formats (save/write):
OUTPUT_FORMATS = [
".stl", # Stereolithography (binary/ASCII)
".obj", # Wavefront OBJ
".ply", # Polygon File Format (binary/ASCII)
".vtk", # VTK Legacy (binary/ASCII)
".vtp", # VTK PolyData XML
".vtu", # VTK Unstructured Grid XML
".x3d", # X3D
".dae", # COLLADA
".off", # Object File Format
".png", # Images (screenshots)
".jpg", # Images (screenshots)
".pdf", # Vector graphics (2D plots)
".svg", # Vector graphics (2D plots)
".eps" # Vector graphics (2D plots)
]import vedo
import numpy as np
# Load various 3D file formats
mesh = vedo.load("model.stl")
points = vedo.load("pointcloud.ply")
volume = vedo.load("ct_scan.nrrd")
# Load multiple files at once
objects = vedo.load(["file1.obj", "file2.stl", "file3.ply"])
# Download data from URL
vedo.download("https://example.com/data.vtk", "local_data.vtk")
downloaded_mesh = vedo.load("local_data.vtk")
# Save objects in different formats
vedo.save(mesh, "output.obj") # Wavefront OBJ
vedo.save(mesh, "output.ply") # PLY format
vedo.save(points, "points.vtk") # VTK legacy
vedo.save(volume, "volume.vti") # VTK image data
# Create and save complex scenes
sphere = vedo.Sphere(c='red')
box = vedo.Box(c='blue')
combined = vedo.merge(sphere, box)
vedo.save(combined, "scene.stl", binary=True)
# Screenshot and video creation
vedo.show(mesh, title="3D Model")
vedo.screenshot("model_view.png", scale=2) # High-res screenshot
# Create animation video
video = vedo.Video("rotation.mp4", fps=30)
for i in range(360):
mesh.rotate_z(1) # Rotate 1 degree
vedo.show(mesh, interactive=False)
video.add_frame()
video.close()
# Advanced I/O with format specification
# Load structured data
grid = vedo.loadStructuredGrid("simulation.vts")
structured_vol = vedo.loadStructuredPoints("field.vti")
# Export rendering window state
vedo.show(mesh, box, sphere)
vedo.export_window("scene_state.vtk")
# Later restore the complete scene
restored_plotter = vedo.import_window("scene_state.vtk")
# Handle compressed files
vedo.gunzip("compressed_model.stl.gz")
uncompressed_mesh = vedo.load("compressed_model.stl")
# Batch processing example
import glob
stl_files = glob.glob("*.stl")
meshes = []
for filename in stl_files:
mesh = vedo.load(filename)
mesh.color('random') # Random colors
meshes.append(mesh)
# Save combined result
combined_mesh = vedo.merge(*meshes)
vedo.save(combined_mesh, "combined_models.ply")Install with Tessl CLI
npx tessl i tessl/pypi-vedo