-
-
Notifications
You must be signed in to change notification settings - Fork 483
/
vtk.py
160 lines (97 loc) · 3.43 KB
/
vtk.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
"""
Defines custom VTKPlot bokeh model to render VTK objects.
"""
from bokeh.core.enums import enumeration
from bokeh.core.has_props import abstract
from bokeh.core.properties import (
Any, Bool, Bytes, Dict, Enum, Float, Instance, Int, List, Nullable,
Override, Positive, String,
)
from bokeh.models import ColorMapper, Model
from ..config import config
from ..io.resources import bundled_files
from ..util import classproperty
from .layout import HTMLBox
vtk_cdn = f"{config.npm_cdn}/vtk.js@30.1.0/vtk.js"
class VTKAxes(Model):
"""
A Bokeh model for axes
"""
axes_opacity = Float(default=1)
digits = Int(default=1)
fontsize = Positive(Int, default=12)
grid_opacity = Float(default=0.1)
origin = Any()
show_grid = Bool(default=True)
xticker = Dict(String, Any)
yticker = Dict(String, Any)
zticker = Dict(String, Any)
@abstract
class AbstractVTKPlot(HTMLBox):
"""
Abstract Bokeh model for vtk plots that wraps around a vtk-js library and
renders it inside a Bokeh plot.
"""
__javascript_raw__ = [vtk_cdn]
@classproperty
def __javascript__(cls):
return bundled_files(AbstractVTKPlot)
@classproperty
def __js_skip__(cls):
return {'vtk': cls.__javascript__}
__js_require__ = {
"paths": {"vtk": vtk_cdn[:-3]},
"shim": {
"vtk": {"exports": "vtk"},
}
}
axes = Instance(VTKAxes)
camera = Dict(String, Any)
color_mappers = List(Instance(ColorMapper))
height = Override(default=300)
orientation_widget = Bool(default=False)
interactive_orientation_widget = Bool(default=False)
width = Override(default=300)
annotations = List(Dict(String, Any))
class VTKSynchronizedPlot(AbstractVTKPlot):
"""
Bokeh model for plotting a VTK render window
"""
arrays = Dict(String, Bytes)
arrays_processed = List(String)
enable_keybindings = Bool(default=False)
one_time_reset = Bool(default=False)
rebuild = Bool(default=False, help="""If true when scene change all the render is rebuilt from scratch""")
scene = Dict(String, Any, help="""The serialized vtk.js scene on json format""")
class VTKJSPlot(AbstractVTKPlot):
"""
Bokeh model for plotting a 3D scene saved in the `.vtk-js` format
"""
data = Nullable(Bytes, help="""The serialized vtk.js data""")
data_url = Nullable(String, help="The data URL")
enable_keybindings = Bool(default=False)
class VTKVolumePlot(AbstractVTKPlot):
"""
Bokeh model dedicated to plot a volumetric object with the help of vtk-js
"""
ambient = Float(default=0.2)
colormap = String(help="Colormap Name")
controller_expanded = Bool(default=True, help="""
If True the volume controller panel options is expanded in the view""")
data = Nullable(Dict(String, Any))
diffuse = Float(default=0.7)
display_slices = Bool(default=False)
display_volume = Bool(default=True)
edge_gradient = Float(default=0.2)
interpolation = Enum(enumeration('fast_linear','linear','nearest'))
mapper = Dict(String, Any)
nan_opacity = Float(default=1)
render_background = String(default='#52576e')
rescale = Bool(default=False)
sampling = Float(default=0.4)
shadow = Bool(default=True)
slice_i = Int(default=0)
slice_j = Int(default=0)
slice_k = Int(default=0)
specular = Float(default=0.3)
specular_power = Float(default=8.)