| 1 |
""" |
| 2 |
.. _warp_by_vector_example: |
| 3 |
|
| 4 |
Warping by Vectors |
| 5 |
~~~~~~~~~~~~~~~~~~ |
| 6 |
|
| 7 |
This example applies the :meth:`~pyvista.DataSetFilters.warp_by_vector` |
| 8 |
filter to a sphere mesh that has 3D displacement vectors defined at each node. |
| 9 |
""" |
| 10 |
|
| 11 |
# %% |
| 12 |
# We first compare the unwarped sphere to the warped sphere. |
| 13 |
from itertools import product |
| 14 |
|
| 15 |
import pyvista as pv |
| 16 |
from pyvista import examples |
| 17 |
|
| 18 |
sphere = examples.load_sphere_vectors() |
| 19 |
warped = sphere.warp_by_vector() |
| 20 |
|
| 21 |
pl = pv.Plotter(shape=(1, 2)) |
| 22 |
pl.subplot(0, 0) |
| 23 |
pl.add_text('Before warp') |
| 24 |
pl.add_mesh(sphere, color='white') |
| 25 |
pl.subplot(0, 1) |
| 26 |
pl.add_text('After warp') |
| 27 |
pl.add_mesh(warped, color='white') |
| 28 |
pl.show() |
| 29 |
|
| 30 |
# %% |
| 31 |
# We then use several values for the scale factor applied to the warp |
| 32 |
# operation. Applying a warping factor that is too high can often lead to |
| 33 |
# unrealistic results. |
| 34 |
|
| 35 |
warp_factors = [0, 1.5, 3.5, 5.5] |
| 36 |
pl = pv.Plotter(shape=(2, 2)) |
| 37 |
for i, j in product(range(2), repeat=2): |
| 38 |
idx = 2 * i + j |
| 39 |
pl.subplot(i, j) |
| 40 |
pl.add_mesh(sphere.warp_by_vector(factor=warp_factors[idx])) |
| 41 |
pl.add_text(f'factor={warp_factors[idx]}') |
| 42 |
pl.show() |
| 43 |
# %% |
| 44 |
# .. tags:: filter |