| 1 |
""" |
| 2 |
.. _image_depth_example: |
| 3 |
|
| 4 |
Render a depth image |
| 5 |
~~~~~~~~~~~~~~~~~~~~ |
| 6 |
|
| 7 |
Use :meth:`~pyvista.Plotter.get_image_depth` to plot a depth image as viewed from a |
| 8 |
camera overlooking the :func:`~pyvista.examples.examples.load_random_hills` example mesh. |
| 9 |
""" |
| 10 |
|
| 11 |
import matplotlib.pyplot as plt |
| 12 |
|
| 13 |
# sphinx_gallery_thumbnail_number = 2 |
| 14 |
import pyvista as pv |
| 15 |
from pyvista import examples |
| 16 |
|
| 17 |
# Load an interesting example of geometry |
| 18 |
mesh = examples.load_random_hills() |
| 19 |
|
| 20 |
# Establish geometry within a pv.Plotter() and enable storing image depth |
| 21 |
pl = pv.Plotter() |
| 22 |
pl.add_mesh(mesh, color=True) |
| 23 |
pl.show(store_image_depth=True) |
| 24 |
|
| 25 |
# %% |
| 26 |
# Record depth image without and with a custom fill value |
| 27 |
zval = pl.get_image_depth() |
| 28 |
zval_filled_by_42s = pl.get_image_depth(fill_value=42.0) |
| 29 |
|
| 30 |
# %% |
| 31 |
# Visualize depth images |
| 32 |
plt.figure() |
| 33 |
plt.imshow(zval) |
| 34 |
plt.colorbar(label='Distance to Camera') |
| 35 |
plt.title('Depth image') |
| 36 |
plt.xlabel('X Pixel') |
| 37 |
plt.ylabel('Y Pixel') |
| 38 |
plt.show() |
| 39 |
|
| 40 |
# %% |
| 41 |
plt.figure() |
| 42 |
plt.imshow(zval_filled_by_42s) |
| 43 |
plt.title('Depth image (custom fill_value)') |
| 44 |
plt.colorbar(label='Distance to Camera') |
| 45 |
plt.xlabel('X Pixel') |
| 46 |
plt.ylabel('Y Pixel') |
| 47 |
plt.show() |
| 48 |
# %% |
| 49 |
# .. tags:: plot |