Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[VTK] Add axes coordinates to VTK view #817

Merged
merged 7 commits into from
Dec 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions examples/reference/panes/VTK.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,20 @@
"* **``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 projections.\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",
"* **``serialize_on_instantiation``** (bool): It defines when the serialization of the 3D scene occurs. If set to `True` (default) the scene object is serialized when the panel is created else when the panel is displayed to the screen. This parameter is constant, once set it can't be modified\n",
"* **``axes``** (dict): A dictionnary with the parameters of the axes to construct in the 3d view.\n",
" Must contain at least ``xticker``, ``yticker`` and ``zticker``.\n",
" - ``[x|y|z]ticker`` is a dictionary which contains:\n",
" - ``ticks`` (array of numbers) - required. Positions in the scene coordinates\n",
" of the coresponding axe ticks\n",
" - ``labels`` (array of strings) - optional. Label displayed respectively to\n",
" the `ticks` positions.\n",
"\n",
" If `labels` are not defined they are infered from the `ticks` array.\n",
" - ``digits``: number of decimal digits when `ticks` are converted to `labels`.\n",
" - ``fontsize``: size in pts of the ticks labels.\n",
" - ``show_grid``: boolean. If true (default) the axes grid is visible.\n",
" - ``grid_opactity``: float between 0-1. Defines the grid opacity.\n",
" - ``axes_opactity``: float between 0-1. Defines the axes lines opacity.\n",
"___"
]
},
Expand Down Expand Up @@ -314,6 +328,36 @@
"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))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"## Adding axes to the VTK scene\n",
"\n",
"Using the `axes` parameter, it is possible to add an axes into the 3d view.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"axes = dict(\n",
" origin = [-5, 5, -2],\n",
" xticker = {'ticks': np.linspace(-5,5,5)},\n",
" yticker = {'ticks': np.linspace(-5,5,5)},\n",
" zticker = {'ticks': np.linspace(-2,2,5), 'labels': [''] + [str(int(item)) for item in np.linspace(-2,2,5)[1:]]},\n",
" fontsize = 12,\n",
" digits = 1,\n",
" grid_opacity = 0.5,\n",
" show_grid=True\n",
")\n",
"pan.axes = axes"
]
}
],
"metadata": {
Expand Down
3 changes: 1 addition & 2 deletions panel/models/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,4 @@ export {State} from "./state"
export {VegaPlot} from "./vega"
export {Video} from "./video"
export {VideoStream} from "./videostream"
export {VTKPlot} from "./vtk"
export {VTKVolumePlot} from "./vtkvolume"
export {VTKAxes, VTKPlot, VTKVolumePlot} from "./vtk"
32 changes: 30 additions & 2 deletions panel/models/vtk.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,37 @@
"""
Defines custom VTKPlot bokeh model to render VTK objects.
"""
from bokeh.core.properties import String, Bool, Dict, Any, Override
from bokeh.models import HTMLBox
from bokeh.core.properties import (String, Bool, Dict, Any, Override,
Instance, Int, Float, PositiveInt)
from bokeh.models import HTMLBox, Model

vtk_cdn = "https://unpkg.com/vtk.js"


class VTKAxes(Model):
"""
A Bokeh model for axes
"""

xticker = Dict(String, Any)

yticker = Dict(String, Any)

zticker = Dict(String, Any)

origin = Any()

digits = Int(default=1)

show_grid = Bool(default=True)

grid_opacity = Float(default=0.1)

axes_opacity = Float(default=1)

fontsize = PositiveInt(default=12)


class VTKPlot(HTMLBox):
"""
A Bokeh model that wraps around a vtk-js library and renders it inside
Expand All @@ -24,6 +50,8 @@ class VTKPlot(HTMLBox):

camera = Dict(String, Any)

axes = Instance(VTKAxes)

enable_keybindings = Bool(default=False)

orientation_widget = Bool(default=False)
Expand Down
3 changes: 3 additions & 0 deletions panel/models/vtk/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export {VTKPlot} from "./vtk"
export {VTKVolumePlot} from "./vtkvolume"
export {VTKAxes} from "./vtkaxes"
Loading