Skip to content

Commit db10cc0

Browse files
committed
Add WarpByScalar documentation
Signed-off-by: martinRenou <[email protected]>
1 parent 3ebb5e3 commit db10cc0

File tree

4 files changed

+52
-1
lines changed

4 files changed

+52
-1
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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
9.26 MB
Loading

docs/source/api_reference/water.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ If you have under-water meshes on which you want to cast caustics, you need to c
1717
1818
Then you'll need to pass those under-water meshes to the water effect:
1919

20-
.. code::
20+
.. code:: Python
2121
2222
underwater_mesh1 = UnderWater(mesh1, input='underwater')
2323
underwater_mesh2 = UnderWater(mesh2, input='underwater')

docs/source/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ ipygany: Scientific visualization in the Jupyter notebook
2626

2727
api_reference/isocolor
2828
api_reference/warp
29+
api_reference/warpbyscalar
2930
api_reference/threshold
3031

3132
.. toctree::

0 commit comments

Comments
 (0)