Scientific Visualisations with Python

PyVista

PyVista is an open-source Python library built on top of VTK (Visualization Toolkit). It simplifies 3D visualization and mesh analysis by providing an intuitive API for creating, manipulating, and visualizing 3D data.

Key Features

Intuitive Interface Simplifies VTK workflows.
3D Plotting Generate 3D visualizations with minimal code.
Mesh Operations Create, edit, and process 3D meshes.
Interactivity Interactive plotting windows with support for user interaction.
Integration Works seamlessly with NumPy for numerical computations.

Fundamental Concepts

Mesh Objects PyVista uses pyvista.PolyData for surfaces and point clouds, and pyvista.UnstructuredGrid for volumetric meshes.
Plotting The pyvista.Plotter class enables the creation of multiple interactive render windows.
Filters Provides methods to transform meshes (e.g., slicing, contouring, and clipping).


# Example

Visualizing a Sphere

import pyvista as pv
sphere = pv.Sphere()
plotter = pv.Plotter()
plotter.add_mesh(sphere, color='blue', show_edges=True)
plotter.show()

# Example

Boolean Operations

import pyvista as pv
cube = pv.Cube().triangulate().subdivide(3)
sphere = pv.Sphere(radius=0.6)
result = cube.boolean_difference(sphere)
result.plot(color='lightblue')
#hr

PyVedo

PyVedo is a Python library for 3D visualization and mesh manipulation. It builds on top of VTK and offers an easy-to-use API for creating and interacting with 3D graphics.

Key Features

Mesh Manipulation Load, edit, and analyze meshes.
Actors Create geometric objects and add them as actors in a scene.
Rendering Provides a high-level interface to render 3D objects interactively.
Integration with NumPy Directly work with mesh vertices and faces using NumPy arrays.

Fundamental Concepts

Actor Represents a 3D object or mesh to be displayed.
Plotter Manages the 3D rendering environment and camera settings.
Meshes The vedo.Mesh class allows creating, modifying, and rendering 3D models.


# Example

Displaying a Cube

from vedo import Cube, show
cube = Cube().c('cyan').lw(3)
show(cube, "Cube Example", axes=1)

# Example

Combining Multiple Objects

from vedo import Sphere, Cone, show
# Create a sphere and a cone
sphere = Sphere(r=1).c('red').pos(0, 0, 0)
cone = Cone(height=2).c('blue').pos(2, 0, 0)
# Show both objects in a single scene
show([sphere, cone], "Multiple Objects", axes=1)

Comparison: PyVista vs PyVedo

Feature PyVista PyVedo
Ease of Use Simplified VTK workflows Intuitive 3D object creation
Main Focus Mesh analysis and visualization Interactive 3D graphics
Integration Works closely with NumPy Direct manipulation of actors

Both PyVista and PyVedo are powerful tools for 3D visualization and mesh analysis. PyVista is more suited for scientific applications with extensive support for mesh operations, while PyVedo is ideal for creating intuitive and interactive 3D graphics.