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,6 +27,7 @@ import wx.lib.pubsub as ps
27 import constants as const 27 import constants as const
28 import project as prj 28 import project as prj
29 import data.vtk_utils as vtku 29 import data.vtk_utils as vtku
  30 +from gui.widgets.clut_raycasting import CLUTRaycastingWidget
30 31
31 class Viewer(wx.Panel): 32 class Viewer(wx.Panel):
32 def __init__(self, parent): 33 def __init__(self, parent):
@@ -42,6 +43,7 @@ class Viewer(wx.Panel): @@ -42,6 +43,7 @@ class Viewer(wx.Panel):
42 43
43 sizer = wx.BoxSizer(wx.VERTICAL) 44 sizer = wx.BoxSizer(wx.VERTICAL)
44 sizer.Add(interactor, 1, wx.EXPAND) 45 sizer.Add(interactor, 1, wx.EXPAND)
  46 + self.sizer = sizer
45 self.SetSizer(sizer) 47 self.SetSizer(sizer)
46 self.Layout() 48 self.Layout()
47 49
@@ -160,7 +162,6 @@ class Viewer(wx.Panel): @@ -160,7 +162,6 @@ class Viewer(wx.Panel):
160 #self.Bind(wx.EVT_SIZE, self.OnSize) 162 #self.Bind(wx.EVT_SIZE, self.OnSize)
161 pass 163 pass
162 164
163 -  
164 def OnEnableBrightContrast(self, pubsub_evt): 165 def OnEnableBrightContrast(self, pubsub_evt):
165 style = self.style 166 style = self.style
166 style.AddObserver("MouseMoveEvent", self.OnMove) 167 style.AddObserver("MouseMoveEvent", self.OnMove)
@@ -300,6 +301,6 @@ class Viewer(wx.Panel): @@ -300,6 +301,6 @@ class Viewer(wx.Panel):
300 301
301 def SetWidgetInteractor(self, evt_pubsub=None): 302 def SetWidgetInteractor(self, evt_pubsub=None):
302 evt_pubsub.data.SetInteractor(self.interactor._Iren) 303 evt_pubsub.data.SetInteractor(self.interactor._Iren)
303 - 304 +
304 def AppendActor(self, evt_pubsub=None): 305 def AppendActor(self, evt_pubsub=None):
305 self.ren.AddActor(evt_pubsub.data) 306 self.ren.AddActor(evt_pubsub.data)
invesalius/data/volume.py
@@ -24,6 +24,7 @@ import wx @@ -24,6 +24,7 @@ import wx
24 import wx.lib.pubsub as ps 24 import wx.lib.pubsub as ps
25 25
26 import constants as const 26 import constants as const
  27 +from data import vtk_utils
27 import project as prj 28 import project as prj
28 29
29 Kernels = { 30 Kernels = {
@@ -132,7 +133,7 @@ class Volume(): @@ -132,7 +133,7 @@ class Volume():
132 133
133 def __load_preset_config(self): 134 def __load_preset_config(self):
134 self.config = prj.Project().raycasting_preset 135 self.config = prj.Project().raycasting_preset
135 - 136 +
136 def __update_colour_table(self): 137 def __update_colour_table(self):
137 if self.config['advancedCLUT']: 138 if self.config['advancedCLUT']:
138 self.Create16bColorTable(self.scale) 139 self.Create16bColorTable(self.scale)
@@ -155,7 +156,7 @@ class Volume(): @@ -155,7 +156,7 @@ class Volume():
155 colour = self.GetBackgroundColour() 156 colour = self.GetBackgroundColour()
156 ps.Publisher.sendMessage('Change volume viewer background colour', colour) 157 ps.Publisher.sendMessage('Change volume viewer background colour', colour)
157 ps.Publisher.sendMessage('Change volume viewer gui colour', colour) 158 ps.Publisher.sendMessage('Change volume viewer gui colour', colour)
158 - 159 +
159 160
160 def OnSetRelativeWindowLevel(self, pubsub_evt): 161 def OnSetRelativeWindowLevel(self, pubsub_evt):
161 diff_ww, diff_wl = pubsub_evt.data 162 diff_ww, diff_wl = pubsub_evt.data
@@ -360,10 +361,13 @@ class Volume(): @@ -360,10 +361,13 @@ class Volume():
360 361
361 def ApplyConvolution(self, imagedata): 362 def ApplyConvolution(self, imagedata):
362 number_filters = len(self.config['convolutionFilters']) 363 number_filters = len(self.config['convolutionFilters'])
  364 + update_progress= vtk_utils.ShowProgress(number_filters)
363 for filter in self.config['convolutionFilters']: 365 for filter in self.config['convolutionFilters']:
364 convolve = vtk.vtkImageConvolve() 366 convolve = vtk.vtkImageConvolve()
365 convolve.SetInput(imagedata) 367 convolve.SetInput(imagedata)
366 convolve.SetKernel5x5([i/60.0 for i in Kernels[filter]]) 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 convolve.Update() 371 convolve.Update()
368 imagedata = convolve.GetOutput() 372 imagedata = convolve.GetOutput()
369 return imagedata 373 return imagedata
@@ -372,11 +376,15 @@ class Volume(): @@ -372,11 +376,15 @@ class Volume():
372 proj = prj.Project() 376 proj = prj.Project()
373 image = proj.imagedata 377 image = proj.imagedata
374 378
  379 + update_progress= vtk_utils.ShowProgress(4)
  380 +
375 # Flip original vtkImageData 381 # Flip original vtkImageData
376 flip = vtk.vtkImageFlip() 382 flip = vtk.vtkImageFlip()
377 flip.SetInput(image) 383 flip.SetInput(image)
378 flip.SetFilteredAxis(1) 384 flip.SetFilteredAxis(1)
379 flip.FlipAboutOriginOn() 385 flip.FlipAboutOriginOn()
  386 + flip.AddObserver("ProgressEvent", lambda obj,evt:
  387 + update_progress(flip, "Fliping ..."))
380 flip.Update() 388 flip.Update()
381 389
382 image = flip.GetOutput() 390 image = flip.GetOutput()
@@ -388,6 +396,8 @@ class Volume(): @@ -388,6 +396,8 @@ class Volume():
388 cast.SetInput(image) 396 cast.SetInput(image)
389 cast.SetShift(abs(scale[0])) 397 cast.SetShift(abs(scale[0]))
390 cast.SetOutputScalarTypeToUnsignedShort() 398 cast.SetOutputScalarTypeToUnsignedShort()
  399 + cast.AddObserver("ProgressEvent", lambda obj,evt:
  400 + update_progress(cast, "Casting ..."))
391 cast.Update() 401 cast.Update()
392 image2 = cast 402 image2 = cast
393 self.imagedata = image2 403 self.imagedata = image2
@@ -423,6 +433,8 @@ class Volume(): @@ -423,6 +433,8 @@ class Volume():
423 volume_mapper.SetInput(image2) 433 volume_mapper.SetInput(image2)
424 volume_mapper.IntermixIntersectingGeometryOn() 434 volume_mapper.IntermixIntersectingGeometryOn()
425 435
  436 + volume_mapper.AddObserver("ProgressEvent", lambda obj,evt:
  437 + update_progress(volume_mapper, "Mapper ..."))
426 self.volume_mapper = volume_mapper 438 self.volume_mapper = volume_mapper
427 439
428 # TODO: Look to this 440 # TODO: Look to this
@@ -463,6 +475,8 @@ class Volume(): @@ -463,6 +475,8 @@ class Volume():
463 volume = vtk.vtkVolume() 475 volume = vtk.vtkVolume()
464 volume.SetMapper(volume_mapper) 476 volume.SetMapper(volume_mapper)
465 volume.SetProperty(volume_properties) 477 volume.SetProperty(volume_properties)
  478 + volume.AddObserver("ProgressEvent", lambda obj,evt:
  479 + update_progress(volume, "Volume ..."))
466 self.volume = volume 480 self.volume = volume
467 481
468 colour = self.GetBackgroundColour() 482 colour = self.GetBackgroundColour()
invesalius/gui/default_viewers.py
@@ -21,10 +21,10 @@ import sys @@ -21,10 +21,10 @@ import sys
21 import wx 21 import wx
22 import wx.lib.agw.fourwaysplitter as fws 22 import wx.lib.agw.fourwaysplitter as fws
23 import wx.lib.pubsub as ps 23 import wx.lib.pubsub as ps
24 -  
25 import data.viewer_slice as slice_viewer 24 import data.viewer_slice as slice_viewer
26 import data.viewer_volume as volume_viewer 25 import data.viewer_volume as volume_viewer
27 26
  27 +from gui.widgets.clut_raycasting import CLUTRaycastingWidget
28 28
29 class Panel(wx.Panel): 29 class Panel(wx.Panel):
30 def __init__(self, parent): 30 def __init__(self, parent):
@@ -32,6 +32,7 @@ class Panel(wx.Panel): @@ -32,6 +32,7 @@ class Panel(wx.Panel):
32 size=wx.Size(744, 656)) 32 size=wx.Size(744, 656))
33 33
34 self.__init_aui_manager() 34 self.__init_aui_manager()
  35 + self.__bind_events_wx()
35 #self.__init_four_way_splitter() 36 #self.__init_four_way_splitter()
36 #self.__init_mix() 37 #self.__init_mix()
37 38
@@ -87,6 +88,9 @@ class Panel(wx.Panel): @@ -87,6 +88,9 @@ class Panel(wx.Panel):
87 Bottom().Centre().Caption("Volume").\ 88 Bottom().Centre().Caption("Volume").\
88 MaximizeButton(True).CloseButton(False) 89 MaximizeButton(True).CloseButton(False)
89 90
  91 + self.s4 = s4
  92 + self.p4 = p4
  93 +
90 if sys.platform == 'win32': 94 if sys.platform == 'win32':
91 self.aui_manager.AddPane(p1, s1) 95 self.aui_manager.AddPane(p1, s1)
92 self.aui_manager.AddPane(p2, s2) 96 self.aui_manager.AddPane(p2, s2)
@@ -100,6 +104,17 @@ class Panel(wx.Panel): @@ -100,6 +104,17 @@ class Panel(wx.Panel):
100 104
101 self.aui_manager.Update() 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 def __init_four_way_splitter(self): 119 def __init_four_way_splitter(self):
105 120
@@ -166,10 +181,57 @@ class Panel(wx.Panel): @@ -166,10 +181,57 @@ class Panel(wx.Panel):
166 181
167 aui_manager.Update() 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 import wx.lib.platebtn as pbtn 237 import wx.lib.platebtn as pbtn
@@ -199,7 +261,7 @@ class VolumeViewerCover(wx.Panel): @@ -199,7 +261,7 @@ class VolumeViewerCover(wx.Panel):
199 wx.Panel.__init__(self, parent) 261 wx.Panel.__init__(self, parent)
200 262
201 sizer = wx.BoxSizer(wx.HORIZONTAL) 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 sizer.Add(VolumeToolPanel(self), 0, wx.EXPAND|wx.GROW) 265 sizer.Add(VolumeToolPanel(self), 0, wx.EXPAND|wx.GROW)
204 sizer.Fit(self) 266 sizer.Fit(self)
205 267
invesalius/gui/widgets/clut_raycasting.py
@@ -334,8 +334,8 @@ class CLUTRaycastingWidget(wx.Panel): @@ -334,8 +334,8 @@ class CLUTRaycastingWidget(wx.Panel):
334 self._draw_curves(ctx) 334 self._draw_curves(ctx)
335 self._draw_points(ctx) 335 self._draw_points(ctx)
336 self._draw_selection_curve(ctx, width) 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 def _build_histogram(self): 341 def _build_histogram(self):
@@ -396,7 +396,9 @@ class CLUTRaycastingWidget(wx.Panel): @@ -396,7 +396,9 @@ class CLUTRaycastingWidget(wx.Panel):
396 def SetRaycastPreset(self, preset): 396 def SetRaycastPreset(self, preset):
397 preset = project.Project().raycasting_preset 397 preset = project.Project().raycasting_preset
398 print preset 398 print preset
399 - if preset['advancedCLUT']: 399 + if not preset:
  400 + self.to_draw_points = 0
  401 + elif preset['advancedCLUT']:
400 self.to_draw_points = 1 402 self.to_draw_points = 1
401 self.points = preset['16bitClutCurves'] 403 self.points = preset['16bitClutCurves']
402 self.colours = preset['16bitClutColors'] 404 self.colours = preset['16bitClutColors']