|
| 1 | +WarpByScalar |
| 2 | +============ |
| 3 | + |
| 4 | +The ``WarpByScalar`` widget will modify the mesh geometry. |
| 5 | + |
| 6 | +It is similar to ``Paraview``, ``PyVista`` and ``vtk``'s warp-by-scalar effect, but instead of computing the transformation on the CPU, |
| 7 | +it is entirely computed on the GPU. Which means that changing the warp factor does not involve looping over the mesh vertices, |
| 8 | +we only send the new ``factor`` value to the GPU. |
| 9 | + |
| 10 | +The ``input`` attribute should be a 1-D data. For example, if your mesh has a 1-D ``Data`` named ``"height"``, your can set the input to be: |
| 11 | + |
| 12 | +.. code:: |
| 13 | +
|
| 14 | + warped_mesh = WarpByScalar(mesh, input='height') # Warp by 'height' data |
| 15 | +
|
| 16 | +
|
| 17 | +Examples |
| 18 | +-------- |
| 19 | + |
| 20 | +.. code:: Python |
| 21 | +
|
| 22 | + from pyvista import examples |
| 23 | + import numpy as np |
| 24 | +
|
| 25 | + from ipywidgets import VBox, FloatSlider |
| 26 | + from ipygany import PolyMesh, Scene, IsoColor, WarpByScalar |
| 27 | +
|
| 28 | + pvmesh = examples.download_topo_global() |
| 29 | + ugrid = pvmesh.cast_to_unstructured_grid() |
| 30 | +
|
| 31 | + from ipygany import PolyMesh, Scene, IsoColor, WarpByScalar |
| 32 | +
|
| 33 | + # Turn the PyVista mesh into a PolyMesh |
| 34 | + mesh = PolyMesh.from_vtk(ugrid) |
| 35 | +
|
| 36 | + colored_mesh = IsoColor(mesh, min=-10421.0, max=6527.0) |
| 37 | + warped_mesh = WarpByScalar(colored_mesh, input='altitude', factor=0.5e-5) |
| 38 | +
|
| 39 | + # Link a slider to the warp value |
| 40 | + warp_slider = FloatSlider(min=0., max=5., value=0.5) |
| 41 | +
|
| 42 | + def on_slider_change(change): |
| 43 | + warped_mesh.factor = change['new'] * 1e-5 |
| 44 | +
|
| 45 | + warp_slider.observe(on_slider_change, 'value') |
| 46 | +
|
| 47 | + VBox((warp_slider, Scene([warped_mesh]))) |
| 48 | +
|
| 49 | +.. image:: warpscalar.gif |
| 50 | + :alt: warpscalar |
0 commit comments