Commit b3f71dbcf09f156bbcda36120ae4e32879163f73

Authored by tfmoraes
1 parent 2311d40c

Add: Show raycasting clut widget when the volume viewer is maximized

invesalius/data/viewer_volume.py
... ... @@ -27,6 +27,7 @@ import wx.lib.pubsub as ps
27 27 import constants as const
28 28 import project as prj
29 29 import data.vtk_utils as vtku
  30 +from gui.widgets.clut_raycasting import CLUTRaycastingWidget
30 31  
31 32 class Viewer(wx.Panel):
32 33 def __init__(self, parent):
... ... @@ -42,6 +43,7 @@ class Viewer(wx.Panel):
42 43  
43 44 sizer = wx.BoxSizer(wx.VERTICAL)
44 45 sizer.Add(interactor, 1, wx.EXPAND)
  46 + self.sizer = sizer
45 47 self.SetSizer(sizer)
46 48 self.Layout()
47 49  
... ... @@ -160,7 +162,6 @@ class Viewer(wx.Panel):
160 162 #self.Bind(wx.EVT_SIZE, self.OnSize)
161 163 pass
162 164  
163   -
164 165 def OnEnableBrightContrast(self, pubsub_evt):
165 166 style = self.style
166 167 style.AddObserver("MouseMoveEvent", self.OnMove)
... ... @@ -300,6 +301,6 @@ class Viewer(wx.Panel):
300 301  
301 302 def SetWidgetInteractor(self, evt_pubsub=None):
302 303 evt_pubsub.data.SetInteractor(self.interactor._Iren)
303   -
  304 +
304 305 def AppendActor(self, evt_pubsub=None):
305 306 self.ren.AddActor(evt_pubsub.data)
... ...
invesalius/data/volume.py
... ... @@ -24,6 +24,7 @@ import wx
24 24 import wx.lib.pubsub as ps
25 25  
26 26 import constants as const
  27 +from data import vtk_utils
27 28 import project as prj
28 29  
29 30 Kernels = {
... ... @@ -132,7 +133,7 @@ class Volume():
132 133  
133 134 def __load_preset_config(self):
134 135 self.config = prj.Project().raycasting_preset
135   -
  136 +
136 137 def __update_colour_table(self):
137 138 if self.config['advancedCLUT']:
138 139 self.Create16bColorTable(self.scale)
... ... @@ -155,7 +156,7 @@ class Volume():
155 156 colour = self.GetBackgroundColour()
156 157 ps.Publisher.sendMessage('Change volume viewer background colour', colour)
157 158 ps.Publisher.sendMessage('Change volume viewer gui colour', colour)
158   -
  159 +
159 160  
160 161 def OnSetRelativeWindowLevel(self, pubsub_evt):
161 162 diff_ww, diff_wl = pubsub_evt.data
... ... @@ -360,10 +361,13 @@ class Volume():
360 361  
361 362 def ApplyConvolution(self, imagedata):
362 363 number_filters = len(self.config['convolutionFilters'])
  364 + update_progress= vtk_utils.ShowProgress(number_filters)
363 365 for filter in self.config['convolutionFilters']:
364 366 convolve = vtk.vtkImageConvolve()
365 367 convolve.SetInput(imagedata)
366 368 convolve.SetKernel5x5([i/60.0 for i in Kernels[filter]])
  369 + convolve.AddObserver("ProgressEvent", lambda obj,evt:
  370 + update_progress(convolve, "%s ..." % filter))
367 371 convolve.Update()
368 372 imagedata = convolve.GetOutput()
369 373 return imagedata
... ... @@ -372,11 +376,15 @@ class Volume():
372 376 proj = prj.Project()
373 377 image = proj.imagedata
374 378  
  379 + update_progress= vtk_utils.ShowProgress(4)
  380 +
375 381 # Flip original vtkImageData
376 382 flip = vtk.vtkImageFlip()
377 383 flip.SetInput(image)
378 384 flip.SetFilteredAxis(1)
379 385 flip.FlipAboutOriginOn()
  386 + flip.AddObserver("ProgressEvent", lambda obj,evt:
  387 + update_progress(flip, "Fliping ..."))
380 388 flip.Update()
381 389  
382 390 image = flip.GetOutput()
... ... @@ -388,6 +396,8 @@ class Volume():
388 396 cast.SetInput(image)
389 397 cast.SetShift(abs(scale[0]))
390 398 cast.SetOutputScalarTypeToUnsignedShort()
  399 + cast.AddObserver("ProgressEvent", lambda obj,evt:
  400 + update_progress(cast, "Casting ..."))
391 401 cast.Update()
392 402 image2 = cast
393 403 self.imagedata = image2
... ... @@ -423,6 +433,8 @@ class Volume():
423 433 volume_mapper.SetInput(image2)
424 434 volume_mapper.IntermixIntersectingGeometryOn()
425 435  
  436 + volume_mapper.AddObserver("ProgressEvent", lambda obj,evt:
  437 + update_progress(volume_mapper, "Mapper ..."))
426 438 self.volume_mapper = volume_mapper
427 439  
428 440 # TODO: Look to this
... ... @@ -463,6 +475,8 @@ class Volume():
463 475 volume = vtk.vtkVolume()
464 476 volume.SetMapper(volume_mapper)
465 477 volume.SetProperty(volume_properties)
  478 + volume.AddObserver("ProgressEvent", lambda obj,evt:
  479 + update_progress(volume, "Volume ..."))
466 480 self.volume = volume
467 481  
468 482 colour = self.GetBackgroundColour()
... ...
invesalius/gui/default_viewers.py
... ... @@ -21,10 +21,10 @@ import sys
21 21 import wx
22 22 import wx.lib.agw.fourwaysplitter as fws
23 23 import wx.lib.pubsub as ps
24   -
25 24 import data.viewer_slice as slice_viewer
26 25 import data.viewer_volume as volume_viewer
27 26  
  27 +from gui.widgets.clut_raycasting import CLUTRaycastingWidget
28 28  
29 29 class Panel(wx.Panel):
30 30 def __init__(self, parent):
... ... @@ -32,6 +32,7 @@ class Panel(wx.Panel):
32 32 size=wx.Size(744, 656))
33 33  
34 34 self.__init_aui_manager()
  35 + self.__bind_events_wx()
35 36 #self.__init_four_way_splitter()
36 37 #self.__init_mix()
37 38  
... ... @@ -87,6 +88,9 @@ class Panel(wx.Panel):
87 88 Bottom().Centre().Caption("Volume").\
88 89 MaximizeButton(True).CloseButton(False)
89 90  
  91 + self.s4 = s4
  92 + self.p4 = p4
  93 +
90 94 if sys.platform == 'win32':
91 95 self.aui_manager.AddPane(p1, s1)
92 96 self.aui_manager.AddPane(p2, s2)
... ... @@ -100,6 +104,17 @@ class Panel(wx.Panel):
100 104  
101 105 self.aui_manager.Update()
102 106  
  107 + def __bind_events_wx(self):
  108 + self.aui_manager.Bind(wx.aui.EVT_AUI_PANE_MAXIMIZE, self.OnMaximize)
  109 + self.aui_manager.Bind(wx.aui.EVT_AUI_PANE_RESTORE, self.OnRestore)
  110 +
  111 + def OnMaximize(self, evt):
  112 + if evt.GetPane().name == self.s4.name:
  113 + ps.Publisher().sendMessage('Show raycasting widget', None)
  114 +
  115 + def OnRestore(self, evt):
  116 + if evt.GetPane().name == self.s4.name:
  117 + ps.Publisher().sendMessage('Hide raycasting widget', None)
103 118  
104 119 def __init_four_way_splitter(self):
105 120  
... ... @@ -166,10 +181,57 @@ class Panel(wx.Panel):
166 181  
167 182 aui_manager.Update()
168 183  
  184 +class VolumeInteraction(wx.Panel):
  185 + def __init__(self, parent, id):
  186 + super(VolumeInteraction, self).__init__(parent, id)
  187 + self.__init_aui_manager()
  188 + ps.Publisher().subscribe(self.ShowRaycastingWidget,
  189 + 'Show raycasting widget')
  190 + ps.Publisher().subscribe(self.HideRaycastingWidget,
  191 + 'Hide raycasting widget')
  192 + #sizer = wx.BoxSizer(wx.HORIZONTAL)
  193 + #sizer.Add(volume_viewer.Viewer(self), 1, wx.EXPAND|wx.GROW)
  194 + #self.SetSizer(sizer)
  195 + #self.__bind_events_wx()
  196 + #sizer.Fit(self)
  197 +
  198 + def __init_aui_manager(self):
  199 + self.aui_manager = wx.aui.AuiManager()
  200 + self.aui_manager.SetManagedWindow(self)
  201 +
  202 + p1 = volume_viewer.Viewer(self)
  203 + s1 = wx.aui.AuiPaneInfo().Centre().\
  204 + CloseButton(False).MaximizeButton(False).CaptionVisible(0)
  205 + self.s1 = s1
169 206  
  207 + self.clut_raycasting = CLUTRaycastingWidget(self, -1)
  208 + self.s2 = wx.aui.AuiPaneInfo().Centre().\
  209 + CloseButton(False).MaximizeButton(False).CaptionVisible(0).\
  210 + Hide()
170 211  
  212 + if sys.platform == 'win32':
  213 + self.aui_manager.AddPane(p1, s1)
  214 + self.aui_manager.AddPane(self.clut_raycasting, self.s2)
  215 + else:
  216 + self.aui_manager.AddPane(self.clut_raycasting, self.s2)
  217 + self.aui_manager.AddPane(p1, s1)
  218 + self.aui_manager.Update()
  219 +
  220 + def ShowRaycastingWidget(self, evt_pubsub=None):
  221 + p = self.aui_manager.GetPane(self.clut_raycasting)
  222 + p.Show()
  223 + self.aui_manager.Update()
  224 + self.clut_raycasting.SetRaycastPreset(None)
171 225  
  226 + def HideRaycastingWidget(self, evt_pubsub=None):
  227 + p = self.aui_manager.GetPane(self.clut_raycasting)
  228 + p.Hide()
  229 + self.aui_manager.Update()
172 230  
  231 + def __bind_events_wx(self):
  232 + #self.Bind(wx.EVT_SIZE, self.OnSize)
  233 + #self.Bind(wx.EVT_MAXIMIZE, self.OnMaximize)
  234 + pass
173 235  
174 236  
175 237 import wx.lib.platebtn as pbtn
... ... @@ -199,7 +261,7 @@ class VolumeViewerCover(wx.Panel):
199 261 wx.Panel.__init__(self, parent)
200 262  
201 263 sizer = wx.BoxSizer(wx.HORIZONTAL)
202   - sizer.Add(volume_viewer.Viewer(self), 1, wx.EXPAND|wx.GROW)
  264 + sizer.Add(VolumeInteraction(self, -1), 1, wx.EXPAND|wx.GROW)
203 265 sizer.Add(VolumeToolPanel(self), 0, wx.EXPAND|wx.GROW)
204 266 sizer.Fit(self)
205 267  
... ...
invesalius/gui/widgets/clut_raycasting.py
... ... @@ -334,8 +334,8 @@ class CLUTRaycastingWidget(wx.Panel):
334 334 self._draw_curves(ctx)
335 335 self._draw_points(ctx)
336 336 self._draw_selection_curve(ctx, width)
337   - #if self.point_dragged:
338   - # self._draw_selected_point_text(ctx)
  337 + if self.point_dragged:
  338 + self._draw_selected_point_text(ctx)
339 339  
340 340  
341 341 def _build_histogram(self):
... ... @@ -396,7 +396,9 @@ class CLUTRaycastingWidget(wx.Panel):
396 396 def SetRaycastPreset(self, preset):
397 397 preset = project.Project().raycasting_preset
398 398 print preset
399   - if preset['advancedCLUT']:
  399 + if not preset:
  400 + self.to_draw_points = 0
  401 + elif preset['advancedCLUT']:
400 402 self.to_draw_points = 1
401 403 self.points = preset['16bitClutCurves']
402 404 self.colours = preset['16bitClutColors']
... ...