Skip to content

Pure Python 3D Viz Example

Compare
Choose a tag to compare
@lheagy lheagy released this 26 Feb 05:44

This provides updates to the vtkModule documentation that reflect recent development in vtki and a new example for 3D visualization. Check out the new example and the types of 3D renderings that are now possible in a pure Python environment (also its Python 3 friendly!):

vtki_laguna_del_maule

Example in Brief

Using vtki, any discretize mesh can now be immediately rendered using the toVTK() method. Be sure to check out the vtki docs to learn more about using vtki!

import discretize
import numpy as np
import vtki
vtki.set_plot_theme('document')

# Create a TensorMesh
h1 = np.linspace(.1, .5, 3)
h2 = np.linspace(.1, .5, 5)
h3 = np.linspace(.1, .8, 3)
mesh = discretize.TensorMesh([h1, h2, h3])

# Get a VTK data object
dataset = mesh.toVTK()

# Defined a rotated reference frame
mesh.axis_u = (1,-1,0)
mesh.axis_v = (-1,-1,0)
mesh.axis_w = (0,0,1)
# Check that the reference frame is valid
mesh._validate_orientation()

# Yield the rotated vtkStructuredGrid
dataset_r = mesh.toVTK()

p = vtki.BackgroundPlotter()
p.add_mesh(dataset, color='green', show_edges=True)
p.add_mesh(dataset_r, color='maroon', show_edges=True)
p.show_grid()
p.screenshot('vtk-rotated-example.png')

vtk-rotated-example