Skip to content

Commit

Permalink
updating doc
Browse files Browse the repository at this point in the history
  • Loading branch information
ARTUSI committed Sep 17, 2019
1 parent 1df0f87 commit b595405
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 5 deletions.
85 changes: 81 additions & 4 deletions examples/reference/panes/VTK.ipynb
Expand Up @@ -26,7 +26,10 @@
" - w: set representation of all actors to *wireframe*\n",
" - v: set representation of all actors to *vertex*\n",
" - r: center the actors and move the camera so that all actors are visible\n",
" \n",
" The mouse must be over the pane to work\n",
" <br>**Warning**: These keybindings may not work as expected in a notebook context, if they interact with already bound keys\n",
"* **``orientation_widget``** (bool): A boolean to activate/deactivate the orientation widget in the 3D pane. This widget is clickable and allows to rotate the scene in one of the orthographic projection\n",
"* **``object``** (str or object): Can be a string pointing to a local or remote file with a `.vtkjs` extension, or a `vtkRenderWindow` object \n",
"\n",
"___"
Expand All @@ -46,7 +49,7 @@
"outputs": [],
"source": [
"dragon = pn.pane.VTK('https://raw.githubusercontent.com/Kitware/vtk-js/master/Data/StanfordDragon.vtkjs',\n",
" sizing_mode='stretch_width', height=400)\n",
" sizing_mode='stretch_width', height=400, enable_keybindings=True, orientation_widget=True)\n",
"dragon"
]
},
Expand All @@ -66,6 +69,16 @@
"dragon.object = \"https://github.com/Kitware/vtk-js-datasets/raw/master/data/vtkjs/TBarAssembly.vtkjs\""
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"dragon.orientation_widget = False # remove the orientation widget\n",
"dragon.enable_keybindings = False # remove the key bindings"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down Expand Up @@ -144,9 +157,9 @@
"metadata": {},
"outputs": [],
"source": [
"if dragon.camera:\n",
" dragon.camera['viewAngle'] = 50\n",
" dragon.param.trigger('camera')"
"if dragon1.camera:\n",
" dragon1.camera['viewAngle'] = 50\n",
" dragon1.param.trigger('camera')"
]
},
{
Expand Down Expand Up @@ -236,6 +249,70 @@
"\n",
"geom_pane.param.trigger('object')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Construction of ColorBars for VTK objects\n",
"\n",
"When working with VTK objects, a `scalar array` can be associated to `vertices` or `cells` of an `actor` `mesh`. With the help of a `look-up table`, scalar values are associated to colors at the rendering time.\n",
"\n",
"**Colorbars** are used to represent the association between scalars and colors. `VTK pane` allows to construct the colorbars of the `vtk actors` in the scene using the method `construct_colorbars`. This method will return a bokeh plot with all the colorbars associated to the actors (if the actor use a scalar array and a lookup table).\n",
"\n",
"If no colorbar is found in the scene the method return `None`."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We present an example of the use of `construct_colorbars`. Here we use `pyvista` module which simplify the construction of VTK scenes"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import pyvista as pv\n",
"import numpy as np\n",
"def make_points():\n",
" \"\"\"Helper to make XYZ points\"\"\"\n",
" theta = np.linspace(-4 * np.pi, 4 * np.pi, 100)\n",
" z = np.linspace(-2, 2, 100)\n",
" r = z**2 + 1\n",
" x = r * np.sin(theta)\n",
" y = r * np.cos(theta)\n",
" return np.column_stack((x, y, z))\n",
"\n",
"def lines_from_points(points):\n",
" \"\"\"Given an array of points, make a line set\"\"\"\n",
" poly = pv.PolyData()\n",
" poly.points = points\n",
" cells = np.full((len(points)-1, 3), 2, dtype=np.int)\n",
" cells[:, 1] = np.arange(0, len(points)-1, dtype=np.int)\n",
" cells[:, 2] = np.arange(1, len(points), dtype=np.int)\n",
" poly.lines = cells\n",
" return poly\n",
"\n",
"points = make_points()\n",
"line = lines_from_points(points)\n",
"line[\"scalars\"] = np.arange(line.n_points) # By default pyvista use viridis colormap\n",
"tube = line.tube(radius=0.1) #=> the object we will represent in the scene\n",
"\n",
"\n",
"#pyvista plotter => it constructs a vtkRenderWindow under the attribute ren_win\n",
"pl = pv.Plotter(notebook=True)\n",
"pl.camera_position = [(4.440892098500626e-16, -21.75168228149414, 4.258553981781006),\n",
" (4.440892098500626e-16, 0.8581731039809382, 0),\n",
" (0, 0.1850949078798294, 0.982720673084259)]\n",
"\n",
"pl.add_mesh(tube, smooth_shading=True)\n",
"pan = pn.panel(pl.ren_win, sizing_mode='stretch_width', orientation_widget=True)\n",
"pn.Row(pn.Column(pan, pan.construct_colorbars()), pn.pane.Str(type(pl.ren_win), width=500))"
]
}
],
"metadata": {
Expand Down
7 changes: 6 additions & 1 deletion setup.py
Expand Up @@ -29,6 +29,7 @@ def get_setup_version(reponame):
print("WARNING: param>=1.6.0 unavailable. If you are installing a package, this warning can safely be ignored. If you are creating a package or otherwise operating in a git repository, you should install param>=1.6.0.")
return json.load(open(version_file_path, 'r'))['version_string']


def _build_models():
try:
from panel.compiler import build_custom_models
Expand All @@ -45,20 +46,23 @@ def run(self):
_build_models()
develop.run(self)


class CustomInstallCommand(install):
"""Custom installation for install mode."""

def run(self):
_build_models()
install.run(self)


class CustomSdistCommand(sdist):
"""Custom installation for sdist mode."""

def run(self):
_build_models()
sdist.run(self)


_COMMANDS = {
'develop': CustomDevelopCommand,
'install': CustomInstallCommand,
Expand Down Expand Up @@ -126,7 +130,8 @@ def run(self):
'sphinx <2',
'selenium',
'phantomjs',
'lxml'
'lxml',
'pyvista'
]
}

Expand Down

0 comments on commit b595405

Please sign in to comment.