16
16
from mayavi .core .ui .api import SceneEditor , MayaviScene , \
17
17
MlabSceneModel
18
18
19
+ try :
20
+ #---------------------------------------------------------------------------
21
+ # The layout of the dialog created
22
+ #---------------------------------------------------------------------------
23
+ VIEW = View (HGroup (
24
+ Group (
25
+ Item ('scene_y' ,
26
+ editor = SceneEditor (scene_class = Scene ),
27
+ height = 250 , width = 300 ),
28
+ Item ('scene_z' ,
29
+ editor = SceneEditor (scene_class = Scene ),
30
+ height = 250 , width = 300 ),
31
+ show_labels = False ,
32
+ ),
33
+ Group (
34
+ Item ('scene_x' ,
35
+ editor = SceneEditor (scene_class = Scene ),
36
+ height = 250 , width = 300 ),
37
+ Item ('scene3d' ,
38
+ editor = SceneEditor (scene_class = MayaviScene ),
39
+ height = 250 , width = 300 ),
40
+ show_labels = False ,
41
+ ),
42
+ ),
43
+ resizable = True ,
44
+ title = 'Volume Slicer' ,
45
+ )
46
+ except Exception as e :
47
+ VIEW = e
48
+
19
49
20
50
class VolumeSlicer (HasTraits ):
21
51
# The data to plot
@@ -37,13 +67,18 @@ class VolumeSlicer(HasTraits):
37
67
38
68
_axis_names = dict (x = 0 , y = 1 , z = 2 )
39
69
70
+ view = VIEW
71
+
40
72
#---------------------------------------------------------------------------
41
73
def __init__ (self , hist3D : np .ndarray , colormap : str = 'viridis' , interpolate = False , ** traits ):
42
74
self ._colormap = colormap
43
75
self ._cameraView = {"azimuth" : - 30 , "zenith" : 215 , "distance" : None , "pointingTowards" : None , "roll" : - 0 }
44
76
self ._cameraPitch = - 3
45
77
self ._interpolate = interpolate
46
78
79
+ if isinstance (VIEW , Exception ):
80
+ raise VIEW
81
+
47
82
super (VolumeSlicer , self ).__init__ (data = hist3D , ** traits )
48
83
49
84
# Force the creation of the image_plane_widgets:
@@ -174,38 +209,10 @@ def display_scene_z(self):
174
209
return self .make_side_view ('z' )
175
210
176
211
177
- #---------------------------------------------------------------------------
178
- # The layout of the dialog created
179
- #---------------------------------------------------------------------------
180
- view = View (HGroup (
181
- Group (
182
- Item ('scene_y' ,
183
- editor = SceneEditor (scene_class = Scene ),
184
- height = 250 , width = 300 ),
185
- Item ('scene_z' ,
186
- editor = SceneEditor (scene_class = Scene ),
187
- height = 250 , width = 300 ),
188
- show_labels = False ,
189
- ),
190
- Group (
191
- Item ('scene_x' ,
192
- editor = SceneEditor (scene_class = Scene ),
193
- height = 250 , width = 300 ),
194
- Item ('scene3d' ,
195
- editor = SceneEditor (scene_class = MayaviScene ),
196
- height = 250 , width = 300 ),
197
- show_labels = False ,
198
- ),
199
- ),
200
- resizable = True ,
201
- title = 'Volume Slicer' ,
202
- )
203
-
204
-
205
212
if __name__ == '__main__' :
206
213
# Volume Slicer example with some data
207
214
x , y , z = np .ogrid [- 5 :5 :64j , - 5 :5 :64j , - 5 :5 :64j ]
208
215
data = np .sin (3 * x ) / x + 0.05 * z ** 2 + np .cos (3 * y )
209
216
210
- m = VolumeSlicer (data = data )
217
+ m = VolumeSlicer (data )
211
218
m .show ()
0 commit comments