.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "tutorial/04_filters/bonus/f_sampling_functions_3d.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code or to run this example in your browser via Binder .. rst-class:: sphx-glr-example-title .. _sphx_glr_tutorial_04_filters_bonus_f_sampling_functions_3d.py: Sample Function: Perlin Noise in 3D ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Here we use :func:`pyvista.core.utilities.features.sample_function` to sample Perlin noise over a region to generate random terrain. Video games like Minecraft use Perlin noise to create terrain. Here, we create a voxelized mesh similar to a Minecraft "cave". .. GENERATED FROM PYTHON SOURCE LINES 11-14 .. code-block:: Python import pyvista as pv .. GENERATED FROM PYTHON SOURCE LINES 15-24 Generate Perlin Noise over a 3D StructuredGrid ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Feel free to change the values of ``freq`` to change the shape of the "caves". For example, lowering the frequency will make the caves larger and more expansive, while a higher frequency in any direction will make the caves appear more "vein-like" and less open. Change the threshold to reduce or increase the percent of the terrain that is open or closed .. GENERATED FROM PYTHON SOURCE LINES 24-31 .. code-block:: Python freq = (1, 1, 1) noise = pv.perlin_noise(1, freq, (0, 0, 0)) grid = pv.sample_function(noise, [0, 3.0, -0, 1.0, 0, 1.0], dim=(120, 40, 40)) out = grid.threshold(0.02) out .. raw:: html
HeaderData Arrays
UnstructuredGridInformation
N Cells109863
N Points121638
X Bounds0.000e+00, 3.000e+00
Y Bounds0.000e+00, 1.000e+00
Z Bounds0.000e+00, 1.000e+00
N Arrays1
NameFieldTypeN CompMinMax
scalarsPointsfloat641-6.143e-029.082e-01


.. GENERATED FROM PYTHON SOURCE LINES 32-33 color limits without blue .. GENERATED FROM PYTHON SOURCE LINES 33-45 .. code-block:: Python mn, mx = [out['scalars'].min(), out['scalars'].max()] clim = (mn, mx * 1.8) out.plot( cmap='gist_earth_r', background='white', show_scalar_bar=False, lighting=True, clim=clim, show_edges=False, ) .. image-sg:: /tutorial/04_filters/bonus/images/sphx_glr_f_sampling_functions_3d_001.png :alt: f sampling functions 3d :srcset: /tutorial/04_filters/bonus/images/sphx_glr_f_sampling_functions_3d_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 46-53 .. raw:: html
Open In Colab
.. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.644 seconds) .. _sphx_glr_download_tutorial_04_filters_bonus_f_sampling_functions_3d.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: binder-badge .. image:: images/binder_badge_logo.svg :target: https://mybinder.org/v2/gh/pyvista/pyvista-tutorial/gh-pages?urlpath=lab/tree/notebooks/tutorial/04_filters/bonus/f_sampling_functions_3d.ipynb :alt: Launch binder :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: f_sampling_functions_3d.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: f_sampling_functions_3d.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_