Commit 35f054eb0bf5128708802a7ea33d0ad2517e27fc
1 parent
f7650231
Exists in
master
and in
68 other branches
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
Showing
3 changed files
with
68 additions
and
37 deletions
Show diff stats
invesalius/data/volume.py
@@ -166,7 +166,6 @@ class Volume(): | @@ -166,7 +166,6 @@ class Volume(): | ||
166 | wl = self.wl | 166 | wl = self.wl |
167 | ps.Publisher().sendMessage('Set volume window and level text', | 167 | ps.Publisher().sendMessage('Set volume window and level text', |
168 | (ww, wl)) | 168 | (ww, wl)) |
169 | - ps.Publisher().sendMessage('Render volume viewer') | ||
170 | 169 | ||
171 | def OnSetRelativeWindowLevel(self, pubsub_evt): | 170 | def OnSetRelativeWindowLevel(self, pubsub_evt): |
172 | diff_ww, diff_wl = pubsub_evt.data | 171 | diff_ww, diff_wl = pubsub_evt.data |
invesalius/gui/default_viewers.py
@@ -21,12 +21,15 @@ import sys | @@ -21,12 +21,15 @@ 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 | + | ||
24 | import data.viewer_slice as slice_viewer | 25 | import data.viewer_slice as slice_viewer |
25 | import data.viewer_volume as volume_viewer | 26 | import data.viewer_volume as volume_viewer |
27 | +import project | ||
26 | import widgets.slice_menu as slice_menu_ | 28 | import widgets.slice_menu as slice_menu_ |
27 | 29 | ||
28 | from gui.widgets.clut_raycasting import CLUTRaycastingWidget, \ | 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 | class Panel(wx.Panel): | 34 | class Panel(wx.Panel): |
32 | def __init__(self, parent): | 35 | def __init__(self, parent): |
@@ -192,14 +195,12 @@ class Panel(wx.Panel): | @@ -192,14 +195,12 @@ class Panel(wx.Panel): | ||
192 | class VolumeInteraction(wx.Panel): | 195 | class VolumeInteraction(wx.Panel): |
193 | def __init__(self, parent, id): | 196 | def __init__(self, parent, id): |
194 | super(VolumeInteraction, self).__init__(parent, id) | 197 | super(VolumeInteraction, self).__init__(parent, id) |
198 | + self.can_show_raycasting_widget = 0 | ||
195 | self.__init_aui_manager() | 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 | #sizer = wx.BoxSizer(wx.HORIZONTAL) | 200 | #sizer = wx.BoxSizer(wx.HORIZONTAL) |
201 | #sizer.Add(volume_viewer.Viewer(self), 1, wx.EXPAND|wx.GROW) | 201 | #sizer.Add(volume_viewer.Viewer(self), 1, wx.EXPAND|wx.GROW) |
202 | #self.SetSizer(sizer) | 202 | #self.SetSizer(sizer) |
203 | + self.__bind_events() | ||
203 | self.__bind_events_wx() | 204 | self.__bind_events_wx() |
204 | #sizer.Fit(self) | 205 | #sizer.Fit(self) |
205 | 206 | ||
@@ -221,30 +222,65 @@ class VolumeInteraction(wx.Panel): | @@ -221,30 +222,65 @@ class VolumeInteraction(wx.Panel): | ||
221 | self.aui_manager.AddPane(self.clut_raycasting, self.s2) | 222 | self.aui_manager.AddPane(self.clut_raycasting, self.s2) |
222 | self.aui_manager.Update() | 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 | def ShowRaycastingWidget(self, evt_pubsub=None): | 243 | def ShowRaycastingWidget(self, evt_pubsub=None): |
225 | - self.clut_raycasting.SetRaycastPreset(None) | 244 | + self.can_show_raycasting_widget = 1 |
226 | if self.clut_raycasting.to_draw_points: | 245 | if self.clut_raycasting.to_draw_points: |
227 | p = self.aui_manager.GetPane(self.clut_raycasting) | 246 | p = self.aui_manager.GetPane(self.clut_raycasting) |
228 | p.Show() | 247 | p.Show() |
229 | self.aui_manager.Update() | 248 | self.aui_manager.Update() |
230 | 249 | ||
231 | def HideRaycastingWidget(self, evt_pubsub=None): | 250 | def HideRaycastingWidget(self, evt_pubsub=None): |
251 | + self.can_show_raycasting_widget = 0 | ||
232 | p = self.aui_manager.GetPane(self.clut_raycasting) | 252 | p = self.aui_manager.GetPane(self.clut_raycasting) |
233 | p.Hide() | 253 | p.Hide() |
234 | self.aui_manager.Update() | 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 | def OnPointChanged(self, evt): | 256 | def OnPointChanged(self, evt): |
243 | ps.Publisher.sendMessage('Set raycasting refresh', None) | 257 | ps.Publisher.sendMessage('Set raycasting refresh', None) |
244 | ps.Publisher().sendMessage('Render volume viewer', None) | 258 | ps.Publisher().sendMessage('Render volume viewer', None) |
245 | 259 | ||
246 | def OnCurveSelected(self, evt): | 260 | def OnCurveSelected(self, evt): |
247 | ps.Publisher.sendMessage('Set raycasting curve', evt.GetCurve()) | 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 | import wx.lib.platebtn as pbtn | 285 | import wx.lib.platebtn as pbtn |
250 | import wx.lib.buttons as btn | 286 | import wx.lib.buttons as btn |
invesalius/gui/widgets/clut_raycasting.py
1 | import bisect | 1 | import bisect |
2 | import math | 2 | import math |
3 | -import plistlib | ||
4 | import sys | 3 | import sys |
5 | 4 | ||
6 | import cairo | 5 | import cairo |
7 | import numpy | 6 | import numpy |
8 | import wx | 7 | import wx |
9 | -import wx.lib.pubsub as ps | ||
10 | import wx.lib.wxcairo | 8 | import wx.lib.wxcairo |
11 | 9 | ||
12 | -import project | ||
13 | - | ||
14 | FONT_COLOUR = (1, 1, 1) | 10 | FONT_COLOUR = (1, 1, 1) |
15 | LINE_COLOUR = (0.5, 0.5, 0.5) | 11 | LINE_COLOUR = (0.5, 0.5, 0.5) |
16 | LINE_WIDTH = 2 | 12 | LINE_WIDTH = 2 |
@@ -67,16 +63,16 @@ class CLUTRaycastingWidget(wx.Panel): | @@ -67,16 +63,16 @@ class CLUTRaycastingWidget(wx.Panel): | ||
67 | self.init = -1024 | 63 | self.init = -1024 |
68 | self.end = 2000 | 64 | self.end = 2000 |
69 | self.padding = 5 | 65 | self.padding = 5 |
66 | + self.previous_wl = 0 | ||
70 | self.to_render = False | 67 | self.to_render = False |
68 | + self.dragged = False | ||
71 | self.to_draw_points = 0 | 69 | self.to_draw_points = 0 |
70 | + self.point_dragged = None | ||
71 | + self.curve_dragged = None | ||
72 | self.histogram_pixel_points = [[0,0]] | 72 | self.histogram_pixel_points = [[0,0]] |
73 | self.histogram_array = [100,100] | 73 | self.histogram_array = [100,100] |
74 | - self.previous_wl = 0 | ||
75 | self.CalculatePixelPoints() | 74 | self.CalculatePixelPoints() |
76 | - self.dragged = False | ||
77 | - self.point_dragged = None | ||
78 | self.__bind_events_wx() | 75 | self.__bind_events_wx() |
79 | - self.__bind_events() | ||
80 | self.Show() | 76 | self.Show() |
81 | 77 | ||
82 | def SetRange(self, range): | 78 | def SetRange(self, range): |
@@ -101,12 +97,6 @@ class CLUTRaycastingWidget(wx.Panel): | @@ -101,12 +97,6 @@ class CLUTRaycastingWidget(wx.Panel): | ||
101 | self.Bind(wx.EVT_SIZE, self.OnSize) | 97 | self.Bind(wx.EVT_SIZE, self.OnSize) |
102 | self.Bind(wx.EVT_MOUSEWHEEL, self.OnWheel) | 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 | def OnEraseBackground(self, evt): | 100 | def OnEraseBackground(self, evt): |
111 | pass | 101 | pass |
112 | 102 | ||
@@ -258,6 +248,8 @@ class CLUTRaycastingWidget(wx.Panel): | @@ -258,6 +248,8 @@ class CLUTRaycastingWidget(wx.Panel): | ||
258 | curve.wl_px = (self.HounsfieldToPixel(curve.wl), | 248 | curve.wl_px = (self.HounsfieldToPixel(curve.wl), |
259 | self.OpacityToPixel(0)) | 249 | self.OpacityToPixel(0)) |
260 | self.Refresh() | 250 | self.Refresh() |
251 | + | ||
252 | + # A point in the preset has been changed, raising a event | ||
261 | evt = CLUTEvent(myEVT_CLUT_POINT , self.GetId(), i) | 253 | evt = CLUTEvent(myEVT_CLUT_POINT , self.GetId(), i) |
262 | self.GetEventHandler().ProcessEvent(evt) | 254 | self.GetEventHandler().ProcessEvent(evt) |
263 | 255 | ||
@@ -268,8 +260,12 @@ class CLUTRaycastingWidget(wx.Panel): | @@ -268,8 +260,12 @@ class CLUTRaycastingWidget(wx.Panel): | ||
268 | for node in curve.nodes: | 260 | for node in curve.nodes: |
269 | node.x += (x - self.previous_wl) | 261 | node.x += (x - self.previous_wl) |
270 | node.graylevel = self.PixelToHounsfield(node.x) | 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 | self.previous_wl = x | 269 | self.previous_wl = x |
274 | self.Refresh() | 270 | self.Refresh() |
275 | else: | 271 | else: |
@@ -303,7 +299,6 @@ class CLUTRaycastingWidget(wx.Panel): | @@ -303,7 +299,6 @@ class CLUTRaycastingWidget(wx.Panel): | ||
303 | return i | 299 | return i |
304 | return None | 300 | return None |
305 | 301 | ||
306 | - | ||
307 | def _has_clicked_in_line(self, position): | 302 | def _has_clicked_in_line(self, position): |
308 | """ | 303 | """ |
309 | Verify if was clicked in a line. If yes, it returns the insertion | 304 | Verify if was clicked in a line. If yes, it returns the insertion |
@@ -430,7 +425,7 @@ class CLUTRaycastingWidget(wx.Panel): | @@ -430,7 +425,7 @@ class CLUTRaycastingWidget(wx.Panel): | ||
430 | ctx.rectangle(x_left, y_superior, | 425 | ctx.rectangle(x_left, y_superior, |
431 | rectangle_width, y_inferior) | 426 | rectangle_width, y_inferior) |
432 | ctx.fill() | 427 | ctx.fill() |
433 | - | 428 | + |
434 | ctx.set_source_rgb(1, 1, 1) | 429 | ctx.set_source_rgb(1, 1, 1) |
435 | ctx.move_to(x_text, y_text1) | 430 | ctx.move_to(x_text, y_text1) |
436 | ctx.show_text("Value: %6d" % value) | 431 | ctx.show_text("Value: %6d" % value) |
@@ -577,8 +572,6 @@ class CLUTRaycastingWidget(wx.Panel): | @@ -577,8 +572,6 @@ class CLUTRaycastingWidget(wx.Panel): | ||
577 | return opacity | 572 | return opacity |
578 | 573 | ||
579 | def SetRaycastPreset(self, preset): | 574 | def SetRaycastPreset(self, preset): |
580 | - preset = project.Project().raycasting_preset | ||
581 | - print preset | ||
582 | if not preset: | 575 | if not preset: |
583 | self.to_draw_points = 0 | 576 | self.to_draw_points = 0 |
584 | elif preset['advancedCLUT']: | 577 | elif preset['advancedCLUT']: |
@@ -590,13 +583,12 @@ class CLUTRaycastingWidget(wx.Panel): | @@ -590,13 +583,12 @@ class CLUTRaycastingWidget(wx.Panel): | ||
590 | self.to_draw_points = 0 | 583 | self.to_draw_points = 0 |
591 | self.Refresh() | 584 | self.Refresh() |
592 | 585 | ||
593 | - def RefreshPoints(self, pubsub_evt): | ||
594 | - self.CalculatePixelPoints() | ||
595 | - self.Refresh() | ||
596 | - | ||
597 | def SetHistrogramArray(self, h_array): | 586 | def SetHistrogramArray(self, h_array): |
598 | self.histogram_array = h_array | 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 | class CLUTEvent(wx.PyCommandEvent): | 592 | class CLUTEvent(wx.PyCommandEvent): |
601 | def __init__(self , evtType, id, curve): | 593 | def __init__(self , evtType, id, curve): |
602 | wx.PyCommandEvent.__init__(self, evtType, id) | 594 | wx.PyCommandEvent.__init__(self, evtType, id) |
@@ -624,3 +616,7 @@ EVT_CLUT_POINT_CHANGED = wx.PyEventBinder(myEVT_CLUT_POINT_CHANGED, 1) | @@ -624,3 +616,7 @@ EVT_CLUT_POINT_CHANGED = wx.PyEventBinder(myEVT_CLUT_POINT_CHANGED, 1) | ||
624 | # Selected a curve | 616 | # Selected a curve |
625 | myEVT_CLUT_CURVE_SELECTED = wx.NewEventType() | 617 | myEVT_CLUT_CURVE_SELECTED = wx.NewEventType() |
626 | EVT_CLUT_CURVE_SELECTED = wx.PyEventBinder(myEVT_CLUT_CURVE_SELECTED, 1) | 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) |