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

12 7
from ..util import classproperty, bundled_files
13

14 7
vtk_cdn = "https://unpkg.com/vtk.js@14.16.4/dist/vtk.js"
15

16 7
class VTKAxes(Model):
17
    """
18
    A Bokeh model for axes
19
    """
20

21 7
    axes_opacity = Float(default=1)
22

23 7
    digits = Int(default=1)
24

25 7
    fontsize = PositiveInt(default=12)
26

27 7
    grid_opacity = Float(default=0.1)
28

29 7
    origin = Any()
30

31 7
    show_grid = Bool(default=True)
32

33 7
    xticker = Dict(String, Any)
34

35 7
    yticker = Dict(String, Any)
36

37 7
    zticker = Dict(String, Any)
38

39

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

47 7
    __javascript_raw__ = [vtk_cdn]
48

49 7
    @classproperty
50 2
    def __javascript__(cls):
51 7
        return bundled_files(AbstractVTKPlot)
52

53 7
    @classproperty
54 2
    def __js_skip__(cls):
55 0
        return {'vtk': cls.__javascript__}
56

57 7
    __js_require__ = {
58
        "paths": {"vtk": vtk_cdn[:-3]},
59
        "exports": {"vtk": None},
60
        "shim": {
61
            "vtk": {"exports": "vtk"},
62
        }
63
    }
64

65 7
    axes = Instance(VTKAxes)
66

67 7
    camera = Dict(String, Any)
68

69 7
    color_mappers = List(Instance(ColorMapper))
70

71 7
    height = Override(default=300)
72

73 7
    orientation_widget = Bool(default=False)
74

75 7
    interactive_orientation_widget = Bool(default=False)
76

77 7
    width = Override(default=300)
78

79

80 7
class VTKSynchronizedPlot(AbstractVTKPlot):
81
    """
82
    Bokeh model for plotting a VTK render window
83
    """
84

85 7
    arrays = Dict(String, Any)
86

87 7
    arrays_processed = List(String)
88

89 7
    enable_keybindings = Bool(default=False)
90

91 7
    one_time_reset = Bool(default=False)
92

93 7
    rebuild = Bool(default=False, help="""If true when scene change all the render is rebuilt from scratch""")
94

95 7
    scene = Dict(String, Any, help="""The serialized vtk.js scene on json format""")
96

97

98 7
class VTKJSPlot(AbstractVTKPlot):
99
    """
100
    Bokeh model for plotting a 3D scene saved in the `.vtk-js` format
101
    """
102

103 7
    data = String(help="""The serialized vtk.js data""")
104

105 7
    enable_keybindings = Bool(default=False)
106

107

108 7
class VTKVolumePlot(AbstractVTKPlot):
109
    """
110
    Bokeh model dedicated to plot a volumetric object with the help of vtk-js
111
    """
112

113 7
    ambient = Float(default=0.2)
114

115 7
    colormap = String(help="Colormap Name")
116

117 7
    controller_expanded = Bool(default=True, help="""
118
        If True the volume controller panel options is expanded in the view""")
119

120 7
    data = Dict(String, Any)
121

122 7
    diffuse = Float(default=0.7)
123

124 7
    display_slices = Bool(default=False)
125

126 7
    display_volume = Bool(default=True)
127

128 7
    edge_gradient = Float(default=0.2)
129

130 7
    interpolation = Enum(enumeration('fast_linear','linear','nearest'))
131

132 7
    mapper = Dict(String, Any)
133

134 7
    render_background = String(default='#52576e')
135

136 7
    rescale = Bool(default=False)
137

138 7
    sampling = Float(default=0.4)
139

140 7
    shadow = Bool(default=True)
141

142 7
    slice_i = Int(default=0)
143

144 7
    slice_j = Int(default=0)
145

146 7
    slice_k = Int(default=0)
147

148 7
    specular = Float(default=0.3)
149

150 7
    specular_power = Float(default=8.)

Read our documentation on viewing source code .

Loading