# Examples from pyvista.DataSetFilters.voxelize_rectilinear
# =========================================================

# Create a voxel volume of a nut. By default, the spacing is automatically
# estimated.
import pyvista as pv
from pyvista import examples
mesh = pv.examples.load_nut()
vox = mesh.voxelize_rectilinear()

# Plot the mesh together with its volume.
pl = pv.Plotter()
_ = pl.add_mesh(mesh=vox, show_edges=True)
_ = pl.add_mesh(mesh=mesh, show_edges=True, opacity=1)
pl.show()

# Load a mesh of a cow.
mesh = examples.download_cow()

# Create an equal density voxel volume and plot the result.
vox = mesh.voxelize_rectilinear(spacing=0.15)
cpos = pv.CameraPosition(
    position=(15, 3, 15), focal_point=(0, 0, 0), viewup=(0, 1, 0)
)
vox.plot(scalars='mask', show_edges=True, cpos=cpos)

# Slice the voxel volume to view the `mask` scalars.
slices = vox.slice_orthogonal()
slices.plot(scalars='mask', show_edges=True)

# Create a voxel volume from unequal density dimensions and plot result.
vox = mesh.voxelize_rectilinear(spacing=(0.15, 0.15, 0.5))
vox.plot(scalars='mask', show_edges=True, cpos=cpos)

# Slice the unequal density voxel volume to view the `mask` scalars.
slices = vox.slice_orthogonal()
slices.plot(scalars='mask', show_edges=True, cpos=cpos)

# ----------------------------------------------------------------------
# Generated by sphinx-examples-as-code https://github.com/pyvista/sphinx-examples-as-code
