Skip to content

Commit 6dd0a45

Browse files
committed
Add pyvista example
Signed-off-by: martinRenou <[email protected]>
1 parent 6692ab0 commit 6dd0a45

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

environment.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ channels:
33
dependencies:
44
- vtk
55
- h5py
6+
- pyvista
67
- pythreejs
78
- nodejs
89
- ipygany=0.3.3

examples/pyvista.ipynb

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": null,
6+
"metadata": {},
7+
"outputs": [],
8+
"source": [
9+
"from pyvista import examples\n",
10+
"import numpy as np\n",
11+
"\n",
12+
"from ipywidgets import VBox, FloatSlider\n",
13+
"from ipygany import PolyMesh, Scene, IsoColor, WarpByScalar\n",
14+
"\n",
15+
"pvmesh = examples.download_topo_global()\n",
16+
"ugrid = pvmesh.cast_to_unstructured_grid()\n",
17+
"\n",
18+
"from ipygany import PolyMesh, Scene, IsoColor, WarpByScalar\n",
19+
"\n",
20+
"# Turn the PyVista mesh into a PolyMesh\n",
21+
"mesh = PolyMesh.from_vtk(ugrid)\n",
22+
"\n",
23+
"colored_mesh = IsoColor(mesh, min=-10421.0, max=6527.0)\n",
24+
"warped_mesh = WarpByScalar(colored_mesh, input='altitude', factor=0.5e-5)\n",
25+
"\n",
26+
"# Link a slider to the warp value\n",
27+
"warp_slider = FloatSlider(min=0., max=5., value=0.5)\n",
28+
"\n",
29+
"def on_slider_change(change):\n",
30+
" warped_mesh.factor = change['new'] * 1e-5\n",
31+
"\n",
32+
"warp_slider.observe(on_slider_change, 'value')\n",
33+
"\n",
34+
"VBox((warp_slider, Scene([warped_mesh])))"
35+
]
36+
}
37+
],
38+
"metadata": {
39+
"kernelspec": {
40+
"display_name": "Python 3",
41+
"language": "python",
42+
"name": "python3"
43+
},
44+
"language_info": {
45+
"codemirror_mode": {
46+
"name": "ipython",
47+
"version": 3
48+
},
49+
"file_extension": ".py",
50+
"mimetype": "text/x-python",
51+
"name": "python",
52+
"nbconvert_exporter": "python",
53+
"pygments_lexer": "ipython3",
54+
"version": "3.8.5"
55+
}
56+
},
57+
"nbformat": 4,
58+
"nbformat_minor": 4
59+
}

0 commit comments

Comments
 (0)