diff --git a/invesalius/data/volume.py b/invesalius/data/volume.py index c8d213c..58ec9be 100755 --- a/invesalius/data/volume.py +++ b/invesalius/data/volume.py @@ -166,7 +166,6 @@ class Volume(): wl = self.wl ps.Publisher().sendMessage('Set volume window and level text', (ww, wl)) - ps.Publisher().sendMessage('Render volume viewer') def OnSetRelativeWindowLevel(self, pubsub_evt): diff_ww, diff_wl = pubsub_evt.data diff --git a/invesalius/gui/default_viewers.py b/invesalius/gui/default_viewers.py index 079efd1..7596526 100755 --- a/invesalius/gui/default_viewers.py +++ b/invesalius/gui/default_viewers.py @@ -21,12 +21,15 @@ import sys import wx import wx.lib.agw.fourwaysplitter as fws import wx.lib.pubsub as ps + import data.viewer_slice as slice_viewer import data.viewer_volume as volume_viewer +import project import widgets.slice_menu as slice_menu_ from gui.widgets.clut_raycasting import CLUTRaycastingWidget, \ - EVT_CLUT_POINT_CHANGED, EVT_CLUT_CURVE_SELECTED + EVT_CLUT_POINT_CHANGED, EVT_CLUT_CURVE_SELECTED, \ + EVT_CLUT_CHANGED_CURVE_WL class Panel(wx.Panel): def __init__(self, parent): @@ -192,14 +195,12 @@ class Panel(wx.Panel): class VolumeInteraction(wx.Panel): def __init__(self, parent, id): super(VolumeInteraction, self).__init__(parent, id) + self.can_show_raycasting_widget = 0 self.__init_aui_manager() - ps.Publisher().subscribe(self.ShowRaycastingWidget, - 'Show raycasting widget') - ps.Publisher().subscribe(self.HideRaycastingWidget, - 'Hide raycasting widget') #sizer = wx.BoxSizer(wx.HORIZONTAL) #sizer.Add(volume_viewer.Viewer(self), 1, wx.EXPAND|wx.GROW) #self.SetSizer(sizer) + self.__bind_events() self.__bind_events_wx() #sizer.Fit(self) @@ -221,30 +222,65 @@ class VolumeInteraction(wx.Panel): self.aui_manager.AddPane(self.clut_raycasting, self.s2) self.aui_manager.Update() + def __bind_events_wx(self): + self.clut_raycasting.Bind(EVT_CLUT_POINT_CHANGED, self.OnPointChanged) + self.clut_raycasting.Bind(EVT_CLUT_CURVE_SELECTED , self.OnCurveSelected) + self.clut_raycasting.Bind(EVT_CLUT_CHANGED_CURVE_WL, + self.OnChangeCurveWL) + #self.Bind(wx.EVT_SIZE, self.OnSize) + #self.Bind(wx.EVT_MAXIMIZE, self.OnMaximize) + + def __bind_events(self): + ps.Publisher().subscribe(self.ShowRaycastingWidget, + 'Show raycasting widget') + ps.Publisher().subscribe(self.HideRaycastingWidget, + 'Hide raycasting widget') + ps.Publisher().subscribe(self.OnSetRaycastPreset, + 'Update raycasting preset') + ps.Publisher().subscribe( self.RefreshPoints, + 'Refresh raycasting widget points') + def ShowRaycastingWidget(self, evt_pubsub=None): - self.clut_raycasting.SetRaycastPreset(None) + self.can_show_raycasting_widget = 1 if self.clut_raycasting.to_draw_points: p = self.aui_manager.GetPane(self.clut_raycasting) p.Show() self.aui_manager.Update() def HideRaycastingWidget(self, evt_pubsub=None): + self.can_show_raycasting_widget = 0 p = self.aui_manager.GetPane(self.clut_raycasting) p.Hide() self.aui_manager.Update() - def __bind_events_wx(self): - self.clut_raycasting.Bind(EVT_CLUT_POINT_CHANGED, self.OnPointChanged) - self.clut_raycasting.Bind(EVT_CLUT_CURVE_SELECTED , self.OnCurveSelected) - #self.Bind(wx.EVT_SIZE, self.OnSize) - #self.Bind(wx.EVT_MAXIMIZE, self.OnMaximize) - def OnPointChanged(self, evt): ps.Publisher.sendMessage('Set raycasting refresh', None) ps.Publisher().sendMessage('Render volume viewer', None) def OnCurveSelected(self, evt): ps.Publisher.sendMessage('Set raycasting curve', evt.GetCurve()) + ps.Publisher().sendMessage('Render volume viewer') + + def OnChangeCurveWL(self, evt): + curve = evt.GetCurve() + ww, wl = self.clut_raycasting.GetCurveWWWl(curve) + ps.Publisher().sendMessage('Set raycasting wwwl', (ww, wl, curve)) + ps.Publisher().sendMessage('Render volume viewer') + + def OnSetRaycastPreset(self, evt_pubsub): + preset = project.Project().raycasting_preset + p = self.aui_manager.GetPane(self.clut_raycasting) + self.clut_raycasting.SetRaycastPreset(preset) + if self.clut_raycasting.to_draw_points and \ + self.can_show_raycasting_widget: + p.Show() + else: + p.Hide() + self.aui_manager.Update() + + def RefreshPoints(self, pubsub_evt): + self.clut_raycasting.CalculatePixelPoints() + self.clut_raycasting.Refresh() import wx.lib.platebtn as pbtn import wx.lib.buttons as btn diff --git a/invesalius/gui/widgets/clut_raycasting.py b/invesalius/gui/widgets/clut_raycasting.py index 2d193ae..4ee4ac0 100644 --- a/invesalius/gui/widgets/clut_raycasting.py +++ b/invesalius/gui/widgets/clut_raycasting.py @@ -1,16 +1,12 @@ import bisect import math -import plistlib import sys import cairo import numpy import wx -import wx.lib.pubsub as ps import wx.lib.wxcairo -import project - FONT_COLOUR = (1, 1, 1) LINE_COLOUR = (0.5, 0.5, 0.5) LINE_WIDTH = 2 @@ -67,16 +63,16 @@ class CLUTRaycastingWidget(wx.Panel): self.init = -1024 self.end = 2000 self.padding = 5 + self.previous_wl = 0 self.to_render = False + self.dragged = False self.to_draw_points = 0 + self.point_dragged = None + self.curve_dragged = None self.histogram_pixel_points = [[0,0]] self.histogram_array = [100,100] - self.previous_wl = 0 self.CalculatePixelPoints() - self.dragged = False - self.point_dragged = None self.__bind_events_wx() - self.__bind_events() self.Show() def SetRange(self, range): @@ -101,12 +97,6 @@ class CLUTRaycastingWidget(wx.Panel): self.Bind(wx.EVT_SIZE, self.OnSize) self.Bind(wx.EVT_MOUSEWHEEL, self.OnWheel) - def __bind_events(self): - ps.Publisher().subscribe(self.SetRaycastPreset, - 'Set raycasting preset') - ps.Publisher().subscribe( self.RefreshPoints, - 'Refresh raycasting widget points') - def OnEraseBackground(self, evt): pass @@ -258,6 +248,8 @@ class CLUTRaycastingWidget(wx.Panel): curve.wl_px = (self.HounsfieldToPixel(curve.wl), self.OpacityToPixel(0)) self.Refresh() + + # A point in the preset has been changed, raising a event evt = CLUTEvent(myEVT_CLUT_POINT , self.GetId(), i) self.GetEventHandler().ProcessEvent(evt) @@ -268,8 +260,12 @@ class CLUTRaycastingWidget(wx.Panel): for node in curve.nodes: node.x += (x - self.previous_wl) node.graylevel = self.PixelToHounsfield(node.x) - ps.Publisher().sendMessage('Set raycasting wwwl', - (curve.ww, curve.wl, self.curve_dragged)) + + # The window level has been changed, raising a event! + evt = CLUTEvent(myEVT_CLUT_CHANGED_CURVE_WL, self.GetId(), + self.curve_dragged) + self.GetEventHandler().ProcessEvent(evt) + self.previous_wl = x self.Refresh() else: @@ -303,7 +299,6 @@ class CLUTRaycastingWidget(wx.Panel): return i return None - def _has_clicked_in_line(self, position): """ Verify if was clicked in a line. If yes, it returns the insertion @@ -430,7 +425,7 @@ class CLUTRaycastingWidget(wx.Panel): ctx.rectangle(x_left, y_superior, rectangle_width, y_inferior) ctx.fill() - + ctx.set_source_rgb(1, 1, 1) ctx.move_to(x_text, y_text1) ctx.show_text("Value: %6d" % value) @@ -577,8 +572,6 @@ class CLUTRaycastingWidget(wx.Panel): return opacity def SetRaycastPreset(self, preset): - preset = project.Project().raycasting_preset - print preset if not preset: self.to_draw_points = 0 elif preset['advancedCLUT']: @@ -590,13 +583,12 @@ class CLUTRaycastingWidget(wx.Panel): self.to_draw_points = 0 self.Refresh() - def RefreshPoints(self, pubsub_evt): - self.CalculatePixelPoints() - self.Refresh() - def SetHistrogramArray(self, h_array): self.histogram_array = h_array + def GetCurveWWWl(self, curve): + return (self.curves[curve].ww, self.curves[curve].wl) + class CLUTEvent(wx.PyCommandEvent): def __init__(self , evtType, id, curve): wx.PyCommandEvent.__init__(self, evtType, id) @@ -624,3 +616,7 @@ EVT_CLUT_POINT_CHANGED = wx.PyEventBinder(myEVT_CLUT_POINT_CHANGED, 1) # Selected a curve myEVT_CLUT_CURVE_SELECTED = wx.NewEventType() EVT_CLUT_CURVE_SELECTED = wx.PyEventBinder(myEVT_CLUT_CURVE_SELECTED, 1) + +# Changed the wl from a curve +myEVT_CLUT_CHANGED_CURVE_WL = wx.NewEventType() +EVT_CLUT_CHANGED_CURVE_WL = wx.PyEventBinder(myEVT_CLUT_CHANGED_CURVE_WL, 1) -- libgit2 0.21.2