Commit 35f054eb0bf5128708802a7ea33d0ad2517e27fc

Authored by tfmoraes
1 parent f7650231

ENH: Eliminated all pubsub messages in the clut raycasting widget. Now when the …

…user change the raycasting preset to advanced preset and the volume viewer is maximized it alters the raycasting preset in the clut raycasting widget
invesalius/data/volume.py
... ... @@ -166,7 +166,6 @@ class Volume():
166 166 wl = self.wl
167 167 ps.Publisher().sendMessage('Set volume window and level text',
168 168 (ww, wl))
169   - ps.Publisher().sendMessage('Render volume viewer')
170 169  
171 170 def OnSetRelativeWindowLevel(self, pubsub_evt):
172 171 diff_ww, diff_wl = pubsub_evt.data
... ...
invesalius/gui/default_viewers.py
... ... @@ -21,12 +21,15 @@ import sys
21 21 import wx
22 22 import wx.lib.agw.fourwaysplitter as fws
23 23 import wx.lib.pubsub as ps
  24 +
24 25 import data.viewer_slice as slice_viewer
25 26 import data.viewer_volume as volume_viewer
  27 +import project
26 28 import widgets.slice_menu as slice_menu_
27 29  
28 30 from gui.widgets.clut_raycasting import CLUTRaycastingWidget, \
29   - EVT_CLUT_POINT_CHANGED, EVT_CLUT_CURVE_SELECTED
  31 + EVT_CLUT_POINT_CHANGED, EVT_CLUT_CURVE_SELECTED, \
  32 + EVT_CLUT_CHANGED_CURVE_WL
30 33  
31 34 class Panel(wx.Panel):
32 35 def __init__(self, parent):
... ... @@ -192,14 +195,12 @@ class Panel(wx.Panel):
192 195 class VolumeInteraction(wx.Panel):
193 196 def __init__(self, parent, id):
194 197 super(VolumeInteraction, self).__init__(parent, id)
  198 + self.can_show_raycasting_widget = 0
195 199 self.__init_aui_manager()
196   - ps.Publisher().subscribe(self.ShowRaycastingWidget,
197   - 'Show raycasting widget')
198   - ps.Publisher().subscribe(self.HideRaycastingWidget,
199   - 'Hide raycasting widget')
200 200 #sizer = wx.BoxSizer(wx.HORIZONTAL)
201 201 #sizer.Add(volume_viewer.Viewer(self), 1, wx.EXPAND|wx.GROW)
202 202 #self.SetSizer(sizer)
  203 + self.__bind_events()
203 204 self.__bind_events_wx()
204 205 #sizer.Fit(self)
205 206  
... ... @@ -221,30 +222,65 @@ class VolumeInteraction(wx.Panel):
221 222 self.aui_manager.AddPane(self.clut_raycasting, self.s2)
222 223 self.aui_manager.Update()
223 224  
  225 + def __bind_events_wx(self):
  226 + self.clut_raycasting.Bind(EVT_CLUT_POINT_CHANGED, self.OnPointChanged)
  227 + self.clut_raycasting.Bind(EVT_CLUT_CURVE_SELECTED , self.OnCurveSelected)
  228 + self.clut_raycasting.Bind(EVT_CLUT_CHANGED_CURVE_WL,
  229 + self.OnChangeCurveWL)
  230 + #self.Bind(wx.EVT_SIZE, self.OnSize)
  231 + #self.Bind(wx.EVT_MAXIMIZE, self.OnMaximize)
  232 +
  233 + def __bind_events(self):
  234 + ps.Publisher().subscribe(self.ShowRaycastingWidget,
  235 + 'Show raycasting widget')
  236 + ps.Publisher().subscribe(self.HideRaycastingWidget,
  237 + 'Hide raycasting widget')
  238 + ps.Publisher().subscribe(self.OnSetRaycastPreset,
  239 + 'Update raycasting preset')
  240 + ps.Publisher().subscribe( self.RefreshPoints,
  241 + 'Refresh raycasting widget points')
  242 +
224 243 def ShowRaycastingWidget(self, evt_pubsub=None):
225   - self.clut_raycasting.SetRaycastPreset(None)
  244 + self.can_show_raycasting_widget = 1
226 245 if self.clut_raycasting.to_draw_points:
227 246 p = self.aui_manager.GetPane(self.clut_raycasting)
228 247 p.Show()
229 248 self.aui_manager.Update()
230 249  
231 250 def HideRaycastingWidget(self, evt_pubsub=None):
  251 + self.can_show_raycasting_widget = 0
232 252 p = self.aui_manager.GetPane(self.clut_raycasting)
233 253 p.Hide()
234 254 self.aui_manager.Update()
235 255  
236   - def __bind_events_wx(self):
237   - self.clut_raycasting.Bind(EVT_CLUT_POINT_CHANGED, self.OnPointChanged)
238   - self.clut_raycasting.Bind(EVT_CLUT_CURVE_SELECTED , self.OnCurveSelected)
239   - #self.Bind(wx.EVT_SIZE, self.OnSize)
240   - #self.Bind(wx.EVT_MAXIMIZE, self.OnMaximize)
241   -
242 256 def OnPointChanged(self, evt):
243 257 ps.Publisher.sendMessage('Set raycasting refresh', None)
244 258 ps.Publisher().sendMessage('Render volume viewer', None)
245 259  
246 260 def OnCurveSelected(self, evt):
247 261 ps.Publisher.sendMessage('Set raycasting curve', evt.GetCurve())
  262 + ps.Publisher().sendMessage('Render volume viewer')
  263 +
  264 + def OnChangeCurveWL(self, evt):
  265 + curve = evt.GetCurve()
  266 + ww, wl = self.clut_raycasting.GetCurveWWWl(curve)
  267 + ps.Publisher().sendMessage('Set raycasting wwwl', (ww, wl, curve))
  268 + ps.Publisher().sendMessage('Render volume viewer')
  269 +
  270 + def OnSetRaycastPreset(self, evt_pubsub):
  271 + preset = project.Project().raycasting_preset
  272 + p = self.aui_manager.GetPane(self.clut_raycasting)
  273 + self.clut_raycasting.SetRaycastPreset(preset)
  274 + if self.clut_raycasting.to_draw_points and \
  275 + self.can_show_raycasting_widget:
  276 + p.Show()
  277 + else:
  278 + p.Hide()
  279 + self.aui_manager.Update()
  280 +
  281 + def RefreshPoints(self, pubsub_evt):
  282 + self.clut_raycasting.CalculatePixelPoints()
  283 + self.clut_raycasting.Refresh()
248 284  
249 285 import wx.lib.platebtn as pbtn
250 286 import wx.lib.buttons as btn
... ...
invesalius/gui/widgets/clut_raycasting.py
1 1 import bisect
2 2 import math
3   -import plistlib
4 3 import sys
5 4  
6 5 import cairo
7 6 import numpy
8 7 import wx
9   -import wx.lib.pubsub as ps
10 8 import wx.lib.wxcairo
11 9  
12   -import project
13   -
14 10 FONT_COLOUR = (1, 1, 1)
15 11 LINE_COLOUR = (0.5, 0.5, 0.5)
16 12 LINE_WIDTH = 2
... ... @@ -67,16 +63,16 @@ class CLUTRaycastingWidget(wx.Panel):
67 63 self.init = -1024
68 64 self.end = 2000
69 65 self.padding = 5
  66 + self.previous_wl = 0
70 67 self.to_render = False
  68 + self.dragged = False
71 69 self.to_draw_points = 0
  70 + self.point_dragged = None
  71 + self.curve_dragged = None
72 72 self.histogram_pixel_points = [[0,0]]
73 73 self.histogram_array = [100,100]
74   - self.previous_wl = 0
75 74 self.CalculatePixelPoints()
76   - self.dragged = False
77   - self.point_dragged = None
78 75 self.__bind_events_wx()
79   - self.__bind_events()
80 76 self.Show()
81 77  
82 78 def SetRange(self, range):
... ... @@ -101,12 +97,6 @@ class CLUTRaycastingWidget(wx.Panel):
101 97 self.Bind(wx.EVT_SIZE, self.OnSize)
102 98 self.Bind(wx.EVT_MOUSEWHEEL, self.OnWheel)
103 99  
104   - def __bind_events(self):
105   - ps.Publisher().subscribe(self.SetRaycastPreset,
106   - 'Set raycasting preset')
107   - ps.Publisher().subscribe( self.RefreshPoints,
108   - 'Refresh raycasting widget points')
109   -
110 100 def OnEraseBackground(self, evt):
111 101 pass
112 102  
... ... @@ -258,6 +248,8 @@ class CLUTRaycastingWidget(wx.Panel):
258 248 curve.wl_px = (self.HounsfieldToPixel(curve.wl),
259 249 self.OpacityToPixel(0))
260 250 self.Refresh()
  251 +
  252 + # A point in the preset has been changed, raising a event
261 253 evt = CLUTEvent(myEVT_CLUT_POINT , self.GetId(), i)
262 254 self.GetEventHandler().ProcessEvent(evt)
263 255  
... ... @@ -268,8 +260,12 @@ class CLUTRaycastingWidget(wx.Panel):
268 260 for node in curve.nodes:
269 261 node.x += (x - self.previous_wl)
270 262 node.graylevel = self.PixelToHounsfield(node.x)
271   - ps.Publisher().sendMessage('Set raycasting wwwl',
272   - (curve.ww, curve.wl, self.curve_dragged))
  263 +
  264 + # The window level has been changed, raising a event!
  265 + evt = CLUTEvent(myEVT_CLUT_CHANGED_CURVE_WL, self.GetId(),
  266 + self.curve_dragged)
  267 + self.GetEventHandler().ProcessEvent(evt)
  268 +
273 269 self.previous_wl = x
274 270 self.Refresh()
275 271 else:
... ... @@ -303,7 +299,6 @@ class CLUTRaycastingWidget(wx.Panel):
303 299 return i
304 300 return None
305 301  
306   -
307 302 def _has_clicked_in_line(self, position):
308 303 """
309 304 Verify if was clicked in a line. If yes, it returns the insertion
... ... @@ -430,7 +425,7 @@ class CLUTRaycastingWidget(wx.Panel):
430 425 ctx.rectangle(x_left, y_superior,
431 426 rectangle_width, y_inferior)
432 427 ctx.fill()
433   -
  428 +
434 429 ctx.set_source_rgb(1, 1, 1)
435 430 ctx.move_to(x_text, y_text1)
436 431 ctx.show_text("Value: %6d" % value)
... ... @@ -577,8 +572,6 @@ class CLUTRaycastingWidget(wx.Panel):
577 572 return opacity
578 573  
579 574 def SetRaycastPreset(self, preset):
580   - preset = project.Project().raycasting_preset
581   - print preset
582 575 if not preset:
583 576 self.to_draw_points = 0
584 577 elif preset['advancedCLUT']:
... ... @@ -590,13 +583,12 @@ class CLUTRaycastingWidget(wx.Panel):
590 583 self.to_draw_points = 0
591 584 self.Refresh()
592 585  
593   - def RefreshPoints(self, pubsub_evt):
594   - self.CalculatePixelPoints()
595   - self.Refresh()
596   -
597 586 def SetHistrogramArray(self, h_array):
598 587 self.histogram_array = h_array
599 588  
  589 + def GetCurveWWWl(self, curve):
  590 + return (self.curves[curve].ww, self.curves[curve].wl)
  591 +
600 592 class CLUTEvent(wx.PyCommandEvent):
601 593 def __init__(self , evtType, id, curve):
602 594 wx.PyCommandEvent.__init__(self, evtType, id)
... ... @@ -624,3 +616,7 @@ EVT_CLUT_POINT_CHANGED = wx.PyEventBinder(myEVT_CLUT_POINT_CHANGED, 1)
624 616 # Selected a curve
625 617 myEVT_CLUT_CURVE_SELECTED = wx.NewEventType()
626 618 EVT_CLUT_CURVE_SELECTED = wx.PyEventBinder(myEVT_CLUT_CURVE_SELECTED, 1)
  619 +
  620 +# Changed the wl from a curve
  621 +myEVT_CLUT_CHANGED_CURVE_WL = wx.NewEventType()
  622 +EVT_CLUT_CHANGED_CURVE_WL = wx.PyEventBinder(myEVT_CLUT_CHANGED_CURVE_WL, 1)
... ...