Note
Go to the end to download the full example code.
Isosurface Volume Rendering
Render a 3D volume with isosurface rendering..

Imageio: 'stent.npz' was not found on your computer; downloading it now.
Try 1. Download from https://github.com/imageio/imageio-binaries/raw/master/images/stent.npz (805 kB)
Downloading: 8192/824612 bytes (1.0%)824612/824612 bytes (100.0%)
Done
File saved as /home/docs/.imageio/images/stent.npz.
import imageio.v3 as iio
import numpy as np
from wgpu.gui.auto import WgpuCanvas, run
import pygfx as gfx
canvas = WgpuCanvas()
renderer = gfx.renderers.WgpuRenderer(canvas)
scene = gfx.Scene()
voldata = iio.imread("imageio:stent.npz").astype(np.float32)
geometry = gfx.Geometry(grid=voldata)
material = gfx.VolumeIsoMaterial(clim=(0, 2000), threshold=1000)
vol1 = gfx.Volume(geometry, material)
scene.add(vol1)
camera = gfx.PerspectiveCamera(70, 16 / 9)
camera.show_object(scene, view_dir=(-1, -1, -1), up=(0, 0, 1))
controller = gfx.OrbitController(camera, register_events=renderer)
def animate():
renderer.render(scene, camera)
canvas.request_draw()
if __name__ == "__main__":
canvas.request_draw(animate)
run()
Total running time of the script: (0 minutes 1.084 seconds)