A python module for scientific visualization, analysis of 3D objects and point clouds.
Primary classes for representing and manipulating 3D data including meshes, point clouds, volumetric data, and 2D images. These objects form the foundation of the vedo library and provide extensive functionality for scientific visualization and analysis.
The Mesh class handles triangular meshes and polygonal data, providing comprehensive functionality for 3D surface representation, manipulation, and analysis.
class Mesh(MeshVisual, Points):
"""
Build an instance of object Mesh derived from vedo.Points.
Parameters:
- inputobj: str, vtkPolyData, vtkActor, or vedo.Mesh
Input data to create mesh from. Can be filename, VTK object, or existing mesh.
- c: str or tuple, default "gold"
Color specification (name, hex, RGB tuple)
- alpha: float, default 1
Transparency value (0=transparent, 1=opaque)
"""
def __init__(self, inputobj=None, c="gold", alpha=1): ...Usage example:
# Create mesh from file
mesh = vedo.Mesh("model.stl")
# Create mesh from vertices and faces
vertices = [[0,0,0], [1,0,0], [0,1,0]]
faces = [[0,1,2]]
mesh = vedo.Mesh([vertices, faces])
# Apply properties
mesh.color('red').alpha(0.8)def compute_normals(self, points=True, cells=True, feature_angle=None, consistency=True):
"""
Compute point and/or cell normals for the mesh.
Parameters:
- points: bool, default True
Compute point normals
- cells: bool, default True
Compute cell normals
- feature_angle: float, optional
Feature angle for splitting normals at sharp edges
- consistency: bool, default True
Enforce consistency of normal orientation
Returns:
Mesh object with computed normals
"""
def triangulate(self, verts=True, lines=True):
"""
Convert mesh to triangular representation.
Parameters:
- verts: bool, default True
Triangulate vertex cells
- lines: bool, default True
Triangulate line cells
Returns:
Triangulated Mesh object
"""
def smooth(self, niter=15, pass_band=0.1, edge_angle=15, feature_angle=60, boundary=False):
"""
Smooth mesh using Windowed Sinc algorithm.
Parameters:
- niter: int, default 15
Number of smoothing iterations
- pass_band: float, default 0.1
Pass band frequency (0-2)
- edge_angle: float, default 15
Edge angle threshold for feature detection
- feature_angle: float, default 60
Feature angle threshold
- boundary: bool, default False
Smooth boundary points
Returns:
Smoothed Mesh object
"""
def subdivide(self, n=1, method=0, mel=None):
"""
Increase mesh resolution through subdivision.
Parameters:
- n: int, default 1
Number of subdivision levels
- method: int, default 0
Subdivision method (0=linear, 1=butterfly, 2=loop)
- mel: float, optional
Maximum edge length for adaptive subdivision
Returns:
Subdivided Mesh object
"""
def decimate(self, fraction=0.5, n=None, preserve_volume=True, regularization=0.0):
"""
Reduce mesh complexity while preserving shape.
Parameters:
- fraction: float, default 0.5
Target reduction fraction (0-1)
- n: int, optional
Target number of triangles (alternative to fraction)
- preserve_volume: bool, default True
Preserve mesh volume during decimation
- regularization: float, default 0.0
Regularization factor
Returns:
Decimated Mesh object
"""
def boolean(self, operation, mesh2, method=0, tol=None):
"""
Perform boolean operations between meshes.
Parameters:
- operation: str
Boolean operation ('plus', 'intersect', 'minus')
- mesh2: Mesh
Second mesh for operation
- method: int, default 0
Algorithm method (0=boolean, 1=loop)
- tol: float, optional
Tolerance for point coincidence
Returns:
Mesh object result of boolean operation
"""
def intersect_with(self, mesh2, tol=1e-06):
"""
Compute intersection with another mesh.
Parameters:
- mesh2: Mesh
Mesh to intersect with
- tol: float, default 1e-06
Intersection tolerance
Returns:
Mesh object containing intersection lines
"""
def slice(self, origin=(0, 0, 0), normal=(1, 0, 0)):
"""
Slice mesh with a plane.
Parameters:
- origin: tuple, default (0, 0, 0)
Point on the cutting plane
- normal: tuple, default (1, 0, 0)
Normal vector of the cutting plane
Returns:
Mesh object containing sliced geometry
"""
def cut_with_plane(self, origin=(0, 0, 0), normal=(1, 0, 0)):
"""
Cut mesh with a plane, keeping one side.
Parameters:
- origin: tuple, default (0, 0, 0)
Point on the cutting plane
- normal: tuple, default (1, 0, 0)
Normal vector of the cutting plane
Returns:
Mesh object with geometry on one side of plane
"""
def fill_holes(self, size=None):
"""
Fill holes in the mesh surface.
Parameters:
- size: float, optional
Maximum hole size to fill (None=fill all)
Returns:
Mesh object with filled holes
"""
def compute_quality(self, metric=6):
"""
Compute mesh quality metrics for triangles.
Parameters:
- metric: int, default 6
Quality metric (0=edge ratio, 6=scaled Jacobian, etc.)
Returns:
Mesh object with quality scalars added
"""
def compute_curvature(self, method=0):
"""
Compute surface curvature at mesh points.
Parameters:
- method: int, default 0
Curvature method (0=Gaussian, 1=mean)
Returns:
Mesh object with curvature scalars
"""
def geodesic(self, start, end):
"""
Compute geodesic path between two points on surface.
Parameters:
- start: int or tuple
Starting point index or coordinates
- end: int or tuple
Ending point index or coordinates
Returns:
Mesh object containing geodesic path
"""
def volume(self):
"""
Compute the volume of closed mesh.
Returns:
float: Mesh volume
"""
def area(self):
"""
Compute the surface area of mesh.
Returns:
float: Total surface area
"""
def is_closed(self):
"""
Check if mesh is a closed surface.
Returns:
bool: True if mesh is closed
"""
def boundaries(self, return_ids=False, return_cell_ids=False, cell_edge=False):
"""
Return mesh boundary edges as a new mesh.
Parameters:
- return_ids: bool, default False
Return boundary point indices
- return_cell_ids: bool, default False
Return boundary cell indices
- cell_edge: bool, default False
Consider cell edges instead of point edges
Returns:
Mesh object containing boundary or indices array
"""
def clean(self, tol=None):
"""
Clean mesh by merging duplicate points and removing unused points.
Parameters:
- tol: float, optional
Tolerance for merging points
Returns:
Cleaned Mesh object
"""
def reverse(self, cells=True, normals=False):
"""
Reverse mesh orientation by flipping face normals.
Parameters:
- cells: bool, default True
Reverse cell orientation
- normals: bool, default False
Reverse normal vectors
Returns:
Mesh object with reversed orientation
"""
def extrude(self, zshift=1.0, direction=(), rotation=0.0, dr=0.0, cap=True, res=1):
"""
Extrude mesh along a direction to create a 3D object.
Parameters:
- zshift: float, default 1.0
Extrusion distance
- direction: tuple, optional
Extrusion direction vector
- rotation: float, default 0.0
Twist rotation angle during extrusion
- dr: float, default 0.0
Radial expansion/contraction
- cap: bool, default True
Cap the extruded ends
- res: int, default 1
Number of intermediate layers
Returns:
Extruded Mesh object
"""
def boolean(self, operation: str, mesh2, method=0, tol=None):
"""
Perform boolean operations between meshes.
Parameters:
- operation: str
Boolean operation ("plus", "minus", "intersect")
- mesh2: Mesh
Second mesh for the operation
- method: int, default 0
Boolean algorithm method (0, 1, or 2)
- tol: float, optional
Tolerance for surface intersection
Returns:
Mesh object with boolean operation result
"""
def subdivide(self, n=1, method=0, mel=None):
"""
Subdivide mesh faces to increase resolution.
Parameters:
- n: int, default 1
Number of subdivision iterations
- method: int, default 0
Subdivision algorithm (0=linear, 1=butterfly, 2=loop)
- mel: float, optional
Maximum edge length for adaptive subdivision
Returns:
Subdivided Mesh object
"""
def decimate(self, fraction=0.5, n=None, preserve_volume=True, regularization=0.0):
"""
Reduce mesh complexity by decimating triangles.
Parameters:
- fraction: float, default 0.5
Target reduction fraction (0-1)
- n: int, optional
Target number of triangles (overrides fraction)
- preserve_volume: bool, default True
Preserve mesh volume during decimation
- regularization: float, default 0.0
Regularization strength for edge collapse
Returns:
Decimated Mesh object
"""
def smooth(self, niter=15, pass_band=0.1, edge_angle=15, feature_angle=60, boundary=False):
"""
Smooth mesh surface using iterative smoothing.
Parameters:
- niter: int, default 15
Number of smoothing iterations
- pass_band: float, default 0.1
Pass band frequency for smoothing
- edge_angle: float, default 15
Edge angle threshold for feature preservation
- feature_angle: float, default 60
Feature angle threshold
- boundary: bool, default False
Smooth boundary edges
Returns:
Smoothed Mesh object
"""
def fill_holes(self, size=None):
"""
Fill holes in mesh surface.
Parameters:
- size: float, optional
Maximum hole size to fill
Returns:
Mesh object with holes filled
"""
def compute_normals(self, points=True, cells=True, feature_angle=None, consistency=True):
"""
Compute point and/or cell normal vectors.
Parameters:
- points: bool, default True
Compute point normals
- cells: bool, default True
Compute cell normals
- feature_angle: float, optional
Feature angle for normal computation
- consistency: bool, default True
Enforce normal consistency
Returns:
Mesh object with computed normals
"""
def triangulate(self, verts=True, lines=True):
"""
Convert mesh to triangular faces.
Parameters:
- verts: bool, default True
Triangulate vertices
- lines: bool, default True
Triangulate lines
Returns:
Triangulated Mesh object
"""
def compute_quality(self, metric=6):
"""
Compute mesh quality metrics.
Parameters:
- metric: int, default 6
Quality metric (0-7: edge ratio, aspect ratio, radius ratio, etc.)
Returns:
Mesh object with quality scalars
"""
def intersect_with_line(self, p0, p1=None, return_ids=False, tol=0):
"""
Find intersection points between mesh and a line.
Parameters:
- p0: tuple or array
First point of line or line direction
- p1: tuple, optional
Second point of line
- return_ids: bool, default False
Return cell IDs of intersected cells
- tol: float, default 0
Intersection tolerance
Returns:
Array of intersection points or tuple with cell IDs
"""
def intersect_with_plane(self, origin=(0, 0, 0), normal=(1, 0, 0)):
"""
Intersect mesh with a plane to create a line contour.
Parameters:
- origin: tuple, default (0, 0, 0)
Point on the cutting plane
- normal: tuple, default (1, 0, 0)
Normal vector of the cutting plane
Returns:
Mesh object containing intersection lines
"""
def contains(self, point: tuple, tol=1e-05):
"""
Check if a point is inside the mesh (for closed meshes).
Parameters:
- point: tuple
3D coordinates to test
- tol: float, default 1e-05
Tolerance for containment test
Returns:
bool: True if point is inside mesh
"""
def geodesic(self, start, end):
"""
Compute geodesic path between two points on mesh surface.
Parameters:
- start: int or tuple
Starting point (vertex index or coordinates)
- end: int or tuple
Ending point (vertex index or coordinates)
Returns:
Mesh object representing geodesic path
"""
def is_manifold(self):
"""
Check if mesh is manifold (no non-manifold edges).
Returns:
bool: True if mesh is manifold
"""
def euler_characteristic(self):
"""
Compute Euler characteristic (V - E + F).
Returns:
int: Euler characteristic value
"""
def genus(self):
"""
Compute genus of closed mesh surface.
Returns:
int: Genus value (0 for sphere, 1 for torus, etc.)
"""The Points class manages point cloud data with extensive algorithms for analysis, fitting, and visualization of discrete 3D point sets.
class Points(PointsVisual, PointAlgorithms):
"""
Build an instance of object Points for point cloud data.
Parameters:
- inputobj: array-like, str, or vtkPolyData
Point coordinates as Nx3 array, filename, or VTK object
- r: float, default 4
Point size/radius for visualization
- c: str or tuple, default "red"
Color specification
- alpha: float, default 1
Transparency value
"""
def __init__(self, inputobj=None, r=4, c="red", alpha=1): ...def align_to(self, target, iters=100, rigid=False, invert=False, use_centroids=False):
"""
Align point cloud to target using iterative closest point (ICP).
Parameters:
- target: Points or array-like
Target point set to align to
- iters: int, default 100
Maximum number of iterations
- rigid: bool, default False
Use rigid transformation only (no scaling)
- invert: bool, default False
Invert the transformation
- use_centroids: bool, default False
Use centroids for initial alignment
Returns:
Aligned Points object
"""
def clean(self):
"""
Clean point cloud by removing duplicate points.
Returns:
Cleaned Points object
"""
def subsample(self, fraction, absolute=False):
"""
Subsample points randomly or uniformly.
Parameters:
- fraction: float
Fraction of points to keep (0-1) or absolute number if absolute=True
- absolute: bool, default False
Treat fraction as absolute number of points
Returns:
Subsampled Points object
"""
def remove_outliers(self, radius, neighbors=5):
"""
Remove outlier points based on local density.
Parameters:
- radius: float
Search radius for neighbors
- neighbors: int, default 5
Minimum number of neighbors required
Returns:
Points object with outliers removed
"""
def compute_normals_with_pca(self, n=20, orientation_point=None, invert=False):
"""
Compute point normals using Principal Component Analysis.
Parameters:
- n: int, default 20
Number of neighbors for PCA analysis
- orientation_point: tuple, optional
Reference point for normal orientation
- invert: bool, default False
Invert computed normals
Returns:
Points object with normals computed
"""
def distance_to(self, pcloud, signed=False, invert=False, name="Distance"):
"""
Compute distance from each point to target point cloud.
Parameters:
- pcloud: Points
Target point cloud
- signed: bool, default False
Compute signed distance
- invert: bool, default False
Invert distance values
- name: str, default "Distance"
Name for distance array
Returns:
Distance array for each point
"""
def closest_point(self, pt, n=1, radius=None, return_point_id=False, return_point_coord=True):
"""
Find closest point(s) to a query point.
Parameters:
- pt: tuple
Query point coordinates
- n: int, default 1
Number of closest points to find
- radius: float, optional
Search radius limit
- return_point_id: bool, default False
Return point indices
- return_point_coord: bool, default True
Return point coordinates
Returns:
Closest point coordinates or indices
"""
def densify(self, target_distance=0.1, nclosest=6, radius=None, niter=1, nmax=None):
"""
Add points to regions with low point density.
Parameters:
- target_distance: float, default 0.1
Target distance between points
- nclosest: int, default 6
Number of closest points to consider
- radius: float, optional
Maximum search radius
- niter: int, default 1
Number of iterations
- nmax: int, optional
Maximum number of points to add
Returns:
Densified Points object
"""
def smooth_mls_1d(self, f=0.2, radius=None, n=0):
"""
Smooth 1D point set using Moving Least Squares.
Parameters:
- f: float, default 0.2
Smoothing factor
- radius: float, optional
Smoothing radius
- n: int, default 0
Polynomial order
Returns:
Smoothed Points object
"""
def smooth_mls_2d(self, f=0.2, radius=None, n=0):
"""
Smooth 2D point set using Moving Least Squares.
Parameters:
- f: float, default 0.2
Smoothing factor
- radius: float, optional
Smoothing radius
- n: int, default 0
Polynomial order
Returns:
Smoothed Points object
"""
def generate_mesh(self, radius=None, dims=(25, 25, 25), bounds=(), c="gold", alpha=1):
"""
Generate mesh surface from point cloud using various algorithms.
Parameters:
- radius: float, optional
Sampling radius for mesh generation
- dims: tuple, default (25, 25, 25)
Grid dimensions for volume-based methods
- bounds: tuple, optional
Bounding box for mesh generation
- c: str, default "gold"
Mesh color
- alpha: float, default 1
Mesh transparency
Returns:
Generated Mesh object
"""
def reconstruct_surface(self, dims=(100, 100, 100), radius=None, sample_size=None, hole_filling=True, bounds=(), pad=0.1):
"""
Reconstruct surface from point cloud using Poisson reconstruction.
Parameters:
- dims: tuple, default (100, 100, 100)
Volume dimensions for reconstruction
- radius: float, optional
Sampling radius
- sample_size: int, optional
Number of sample points
- hole_filling: bool, default True
Fill holes in reconstruction
- bounds: tuple, optional
Bounding region
- pad: float, default 0.1
Padding factor
Returns:
Reconstructed Mesh object
"""
def compute_clustering(self, radius):
"""
Compute point clusters based on proximity.
Parameters:
- radius: float
Clustering radius
Returns:
Points object with cluster IDs as scalars
"""
def project_on_plane(self, plane="z", point=None, direction=None):
"""
Project points onto a plane.
Parameters:
- plane: str or array, default "z"
Plane specification ("x", "y", "z" or normal vector)
- point: tuple, optional
Point on the plane
- direction: tuple, optional
Projection direction
Returns:
Projected Points object
"""
def cut_with_plane(self, origin=(0, 0, 0), normal=(1, 0, 0), invert=False):
"""
Cut point cloud with a plane.
Parameters:
- origin: tuple, default (0, 0, 0)
Point on cutting plane
- normal: tuple, default (1, 0, 0)
Plane normal vector
- invert: bool, default False
Keep points on opposite side
Returns:
Cut Points object
"""
def cut_with_box(self, bounds, invert=False):
"""
Cut point cloud with a bounding box.
Parameters:
- bounds: tuple or list
Bounding box coordinates [xmin, xmax, ymin, ymax, zmin, zmax]
- invert: bool, default False
Keep points outside box
Returns:
Cut Points object
"""
def cut_with_sphere(self, center=(0, 0, 0), r=1.0, invert=False):
"""
Cut point cloud with a sphere.
Parameters:
- center: tuple, default (0, 0, 0)
Sphere center coordinates
- r: float, default 1.0
Sphere radius
- invert: bool, default False
Keep points outside sphere
Returns:
Cut Points object
"""
def generate_delaunay2d(self, mode="xy", boundaries=(), alpha=0, tol=None, transform=None):
"""
Generate 2D Delaunay triangulation from point cloud.
Parameters:
- mode: str, default "xy"
Projection plane ("xy", "xz", "yz")
- boundaries: tuple, optional
Boundary constraints
- alpha: float, default 0
Alpha value for alpha-shape filtering
- tol: float, optional
Tolerance for point merging
- transform: array, optional
Transformation matrix
Returns:
Mesh object with Delaunay triangulation
"""
def generate_delaunay3d(self, radius=0, tol=None):
"""
Generate 3D Delaunay tetrahedralization from point cloud.
Parameters:
- radius: float, default 0
Alpha radius for alpha-shape filtering
- tol: float, optional
Tolerance for duplicate point removal
Returns:
TetMesh object with Delaunay tetrahedralization
"""
def hausdorff_distance(self, points):
"""
Compute Hausdorff distance to another point set.
Parameters:
- points: Points or array-like
Target point set
Returns:
float: Hausdorff distance
"""Functions for creating individual points and combining multiple point sets or meshes.
def Point(pos=(0, 0, 0), r=12, c="red", alpha=1.0):
"""
Create a single point marker.
Parameters:
- pos: tuple, default (0, 0, 0)
3D position coordinates
- r: float, default 12
Point size/radius
- c: str or tuple, default "red"
Color specification
- alpha: float, default 1.0
Transparency value
Returns:
Points object representing single point
"""
def merge(*meshs, flag=False):
"""
Build a new Mesh or Points formed by the fusion of inputs.
Parameters:
- *meshs: variable arguments of Mesh or Points objects
Objects to merge together
- flag: bool, default False
If True, keeps track of original identities
Returns:
Union[Mesh, Points, None]: Merged object
"""The Volume class handles 3D scalar and vector field data for volumetric visualization and analysis.
class Volume(VolumeAlgorithms, VolumeVisual):
"""
Class to describe datasets defined on voxels (3D equivalent of 2D pixels).
Parameters:
- inputobj: str, numpy array, or vtkImageData
Volume data source - filename, 3D array, or VTK image data
- c: str, default "RdYlBu_r"
Colormap name for volume rendering
- alpha: tuple, default (0.0, 0.0, 0.2, 0.4, 0.8, 1.0)
Opacity transfer function values
"""
def __init__(
self,
inputobj=None,
c="RdYlBu_r",
alpha=(0.0, 0.0, 0.2, 0.4, 0.8, 1.0)
): ...def slice_plane(self, origin, normal, autocrop=False, border=0.5, mode="linear"):
"""
Slice volume with a plane to create a 2D mesh.
Parameters:
- origin: tuple
Point on the cutting plane
- normal: tuple
Normal vector of the cutting plane
- autocrop: bool, default False
Automatically crop to volume bounds
- border: float, default 0.5
Border padding factor
- mode: str, default "linear"
Interpolation mode ("linear", "cubic", "nearest")
Returns:
Mesh object representing the slice
"""
def xslice(self, i):
"""
Extract a slice at x-index i.
Parameters:
- i: int
X-axis slice index
Returns:
Mesh object representing YZ slice
"""
def yslice(self, j):
"""
Extract a slice at y-index j.
Parameters:
- j: int
Y-axis slice index
Returns:
Mesh object representing XZ slice
"""
def zslice(self, k):
"""
Extract a slice at z-index k.
Parameters:
- k: int
Z-axis slice index
Returns:
Mesh object representing XY slice
"""
def threshold(self, above=None, below=None, replace=None, replace_value=None):
"""
Apply threshold filtering to volume data.
Parameters:
- above: float, optional
Keep values above this threshold
- below: float, optional
Keep values below this threshold
- replace: str, optional
Replace values ("above", "below")
- replace_value: float, optional
Replacement value
Returns:
Thresholded Volume object
"""
def crop(self, left=None, right=None, back=None, front=None, bottom=None, top=None, VOI=()):
"""
Crop volume to specified bounds.
Parameters:
- left: int, optional
Left boundary (x-min)
- right: int, optional
Right boundary (x-max)
- back: int, optional
Back boundary (y-min)
- front: int, optional
Front boundary (y-max)
- bottom: int, optional
Bottom boundary (z-min)
- top: int, optional
Top boundary (z-max)
- VOI: tuple, optional
Volume of interest bounds [x0,x1,y0,y1,z0,z1]
Returns:
Cropped Volume object
"""
def resize(self, newdims):
"""
Resize volume to new dimensions.
Parameters:
- newdims: tuple
New dimensions (nx, ny, nz)
Returns:
Resized Volume object
"""
def smooth_gaussian(self, sigma=(2, 2, 2), radius=None):
"""
Apply Gaussian smoothing filter.
Parameters:
- sigma: tuple, default (2, 2, 2)
Standard deviation for each axis
- radius: tuple, optional
Kernel radius for each axis
Returns:
Smoothed Volume object
"""
def smooth_median(self, neighbours=(2, 2, 2)):
"""
Apply median smoothing filter.
Parameters:
- neighbours: tuple, default (2, 2, 2)
Neighborhood size for each axis
Returns:
Smoothed Volume object
"""
def resample(self, new_spacing, interpolation=1):
"""
Resample volume to new voxel spacing.
Parameters:
- new_spacing: tuple
New voxel spacing (dx, dy, dz)
- interpolation: int, default 1
Interpolation method (0=nearest, 1=linear, 3=cubic)
Returns:
Resampled Volume object
"""
def pad(self, voxels=10, value=0):
"""
Pad volume with additional voxels.
Parameters:
- voxels: int or tuple, default 10
Number of voxels to add on each side
- value: float, default 0
Padding value
Returns:
Padded Volume object
"""
def mirror(self, axis="x"):
"""
Mirror volume along specified axis.
Parameters:
- axis: str, default "x"
Axis to mirror along ("x", "y", "z")
Returns:
Mirrored Volume object
"""
def operation(self, operation, volume2=None):
"""
Apply mathematical operations between volumes.
Parameters:
- operation: str
Operation type ("+", "-", "*", "/", "max", "min")
- volume2: Volume, optional
Second volume for binary operations
Returns:
Volume object with operation result
"""
def euclidean_distance(self, anisotropy=False, max_distance=None):
"""
Compute Euclidean distance transform.
Parameters:
- anisotropy: bool, default False
Consider voxel spacing for anisotropic distances
- max_distance: float, optional
Maximum distance to compute
Returns:
Volume object with distance values
"""
def topoints(self):
"""
Convert volume to point cloud representation.
Returns:
Points object with coordinates and scalar values
"""
def tonumpy(self):
"""
Convert volume data to numpy array.
Returns:
numpy.ndarray: Volume data array
"""The Image class provides functionality for 2D image data visualization and manipulation.
class Image(ImageVisual):
"""
Class for 2D image data handling and visualization.
Parameters:
- obj: str, numpy array, or PIL Image
Image data source - filename, array, or image object
- channels: int, default 3
Number of color channels (1=grayscale, 3=RGB, 4=RGBA)
"""
def __init__(self, obj=None, channels=3): ...Specialized grid classes for structured and unstructured data visualization.
class UnstructuredGrid(PointAlgorithms, MeshVisual):
"""Support for UnstructuredGrid objects with mixed cell types."""
def __init__(self, inputobj=None, c="gold", alpha=1): ...
class TetMesh(UnstructuredGrid):
"""Tetrahedral mesh support for 3D finite element data."""
def __init__(self, inputobj, c="gold", alpha=1): ...
class RectilinearGrid(PointAlgorithms, MeshVisual):
"""Rectilinear grid data structure for structured datasets."""
def __init__(self, inputobj=None, c="gold", alpha=1): ...
class StructuredGrid(PointAlgorithms, MeshVisual):
"""Structured grid data structure with regular connectivity."""
def __init__(self, inputobj=None, c="gold", alpha=1): ...Advanced analysis functions for fitting geometric primitives to point data.
def fit_line(points):
"""
Fit a line through points using linear regression.
Parameters:
- points: array-like or Points object
Input point coordinates
Returns:
Line object representing fitted line
"""
def fit_circle(points):
"""
Fit a circle through 2D or 3D points.
Parameters:
- points: array-like or Points object
Input point coordinates
Returns:
tuple: (center, radius, normal) of fitted circle
"""
def fit_plane(points, signed=False):
"""
Fit a plane through 3D points.
Parameters:
- points: array-like or Points object
Input point coordinates
- signed: bool, default False
Whether to return signed distance
Returns:
Plane object representing fitted plane
"""
def fit_sphere(coords):
"""
Fit a sphere through 3D points.
Parameters:
- coords: array-like or Points object
Input point coordinates
Returns:
Sphere object representing fitted sphere
"""
def pca_ellipse(points, pvalue=0.673, res=60):
"""
Create PCA ellipse from point distribution.
Parameters:
- points: array-like or Points object
Input point coordinates
- pvalue: float, default 0.673
Confidence level for ellipse size
- res: int, default 60
Resolution of ellipse boundary
Returns:
Circle object representing PCA ellipse, or None
"""
def pca_ellipsoid(points, pvalue=0.673, res=24):
"""
Create PCA ellipsoid from 3D point distribution.
Parameters:
- points: array-like or Points object
Input point coordinates
- pvalue: float, default 0.673
Confidence level for ellipsoid size
- res: int, default 24
Resolution of ellipsoid surface
Returns:
Ellipsoid object representing PCA ellipsoid, or None
"""import vedo
import numpy as np
# Create and analyze point cloud
points_data = np.random.rand(100, 3) * 10
points = vedo.Points(points_data, c='blue', r=6)
# Clean and process point cloud
points = points.clean().remove_outliers(radius=1.0, neighbors=5)
points = points.smooth_mls_2d(f=0.3).densify(target_distance=0.2)
# Fit geometric primitives
fitted_plane = vedo.fit_plane(points)
fitted_sphere = vedo.fit_sphere(points)
pca_ellipsoid = vedo.pca_ellipsoid(points)
# Create and process mesh
vertices = [[0,0,0], [1,0,0], [0,1,0], [0,0,1]]
faces = [[0,1,2], [0,1,3], [0,2,3], [1,2,3]]
mesh = vedo.Mesh([vertices, faces], c='yellow')
# Apply mesh processing operations
mesh = mesh.triangulate().compute_normals().smooth(niter=10)
mesh = mesh.subdivide(n=2).fill_holes()
# Mesh analysis and operations
print(f"Mesh volume: {mesh.volume():.3f}")
print(f"Mesh area: {mesh.area():.3f}")
print(f"Is closed: {mesh.is_closed()}")
# Boolean operations between meshes
sphere1 = vedo.Sphere(r=1.0).pos(0, 0, 0)
sphere2 = vedo.Sphere(r=0.8).pos(0.5, 0, 0)
union = sphere1.boolean("plus", sphere2)
intersection = sphere1.boolean("intersect", sphere2)
difference = sphere1.boolean("minus", sphere2)
# Volume processing example
volume_data = np.random.rand(50, 50, 50)
volume = vedo.Volume(volume_data)
# Process volume
volume = volume.smooth_gaussian(sigma=(1, 1, 1))
volume = volume.threshold(above=0.3, below=0.8)
volume = volume.crop(left=10, right=40, bottom=10, top=40)
# Extract volume slices
x_slice = volume.xslice(25)
y_slice = volume.yslice(25)
z_slice = volume.zslice(25)
# Convert volume to points and mesh
volume_points = volume.topoints()
volume_mesh = volume_points.generate_mesh(radius=0.5)
# Load and combine objects
mesh1 = vedo.load("model1.stl")
mesh2 = vedo.load("model2.obj")
combined = vedo.merge(mesh1, mesh2, flag=True)
# Visualize all objects
vedo.show(points, fitted_plane, union, intersection, x_slice,
title="Advanced Data Processing", axes=True)Install with Tessl CLI
npx tessl i tessl/pypi-vedo