holoviz / panel
1
# coding: utf-8
2 6
"""
3
Defines custom VTKPlot bokeh model to render VTK objects.
4
"""
5 6
from bokeh.core.properties import (
6
    String, Bool, Dict, Any, Override, Instance, Int, Float, PositiveInt,
7
    Enum, List, Nullable
8
)
9 6
from bokeh.core.has_props import abstract
10 6
from bokeh.core.enums import enumeration
11 6
from bokeh.models import HTMLBox, Model, ColorMapper
12

13 6
from ..io.resources import bundled_files
14 6
from ..util import classproperty
15

16 6
vtk_cdn = "https://unpkg.com/vtk.js@14.16.4/dist/vtk.js"
17

18 6
class VTKAxes(Model):
19
    """
20
    A Bokeh model for axes
21
    """
22

23 6
    axes_opacity = Float(default=1)
24

25 6
    digits = Int(default=1)
26

27 6
    fontsize = PositiveInt(default=12)
28

29 6
    grid_opacity = Float(default=0.1)
30

31 6
    origin = Any()
32

33 6
    show_grid = Bool(default=True)
34

35 6
    xticker = Dict(String, Any)
36

37 6
    yticker = Dict(String, Any)
38

39 6
    zticker = Dict(String, Any)
40

41

42 6
@abstract
43 6
class AbstractVTKPlot(HTMLBox):
44
    """
45
    Abstract Bokeh model for vtk plots that wraps around a vtk-js library and
46
    renders it inside a Bokeh plot.
47
    """
48

49 6
    __javascript_raw__ = [vtk_cdn]
50

51 6
    @classproperty
52 2
    def __javascript__(cls):
53 6
        return bundled_files(AbstractVTKPlot)
54

55 6
    @classproperty
56 2
    def __js_skip__(cls):
57 0
        return {'vtk': cls.__javascript__}
58

59 6
    __js_require__ = {
60
        "paths": {"vtk": vtk_cdn[:-3]},
61
        "exports": {"vtk": None},
62
        "shim": {
63
            "vtk": {"exports": "vtk"},
64
        }
65
    }
66

67 6
    axes = Instance(VTKAxes)
68

69 6
    camera = Dict(String, Any)
70

71 6
    color_mappers = List(Instance(ColorMapper))
72

73 6
    height = Override(default=300)
74

75 6
    orientation_widget = Bool(default=False)
76

77 6
    interactive_orientation_widget = Bool(default=False)
78

79 6
    width = Override(default=300)
80

81 6
    annotations = List(Dict(String, Any))
82

83

84

85 6
class VTKSynchronizedPlot(AbstractVTKPlot):
86
    """
87
    Bokeh model for plotting a VTK render window
88
    """
89

90 6
    arrays = Dict(String, Any)
91

92 6
    arrays_processed = List(String)
93

94 6
    enable_keybindings = Bool(default=False)
95

96 6
    one_time_reset = Bool(default=False)
97

98 6
    rebuild = Bool(default=False, help="""If true when scene change all the render is rebuilt from scratch""")
99

100 6
    scene = Dict(String, Any, help="""The serialized vtk.js scene on json format""")
101

102

103 6
class VTKJSPlot(AbstractVTKPlot):
104
    """
105
    Bokeh model for plotting a 3D scene saved in the `.vtk-js` format
106
    """
107

108 6
    data = Nullable(String, help="""The serialized vtk.js data""")
109

110 6
    enable_keybindings = Bool(default=False)
111

112

113 6
class VTKVolumePlot(AbstractVTKPlot):
114
    """
115
    Bokeh model dedicated to plot a volumetric object with the help of vtk-js
116
    """
117

118 6
    ambient = Float(default=0.2)
119

120 6
    colormap = String(help="Colormap Name")
121

122 6
    controller_expanded = Bool(default=True, help="""
123
        If True the volume controller panel options is expanded in the view""")
124

125 6
    data = Nullable(Dict(String, Any))
126

127 6
    diffuse = Float(default=0.7)
128

129 6
    display_slices = Bool(default=False)
130

131 6
    display_volume = Bool(default=True)
132

133 6
    edge_gradient = Float(default=0.2)
134

135 6
    interpolation = Enum(enumeration('fast_linear','linear','nearest'))
136

137 6
    mapper = Dict(String, Any)
138

139 6
    render_background = String(default='#52576e')
140

141 6
    rescale = Bool(default=False)
142

143 6
    sampling = Float(default=0.4)
144

145 6
    shadow = Bool(default=True)
146

147 6
    slice_i = Int(default=0)
148

149 6
    slice_j = Int(default=0)
150

151 6
    slice_k = Int(default=0)
152

153 6
    specular = Float(default=0.3)
154

155 6
    specular_power = Float(default=8.)

Read our documentation on viewing source code .

Loading