diff --git a/invesalius/data/viewer_volume.py b/invesalius/data/viewer_volume.py index d29f9c6..0a1cf85 100755 --- a/invesalius/data/viewer_volume.py +++ b/invesalius/data/viewer_volume.py @@ -27,6 +27,7 @@ import wx.lib.pubsub as ps import constants as const import project as prj import data.vtk_utils as vtku +from gui.widgets.clut_raycasting import CLUTRaycastingWidget class Viewer(wx.Panel): def __init__(self, parent): @@ -42,6 +43,7 @@ class Viewer(wx.Panel): sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add(interactor, 1, wx.EXPAND) + self.sizer = sizer self.SetSizer(sizer) self.Layout() @@ -160,7 +162,6 @@ class Viewer(wx.Panel): #self.Bind(wx.EVT_SIZE, self.OnSize) pass - def OnEnableBrightContrast(self, pubsub_evt): style = self.style style.AddObserver("MouseMoveEvent", self.OnMove) @@ -300,6 +301,6 @@ class Viewer(wx.Panel): def SetWidgetInteractor(self, evt_pubsub=None): evt_pubsub.data.SetInteractor(self.interactor._Iren) - + def AppendActor(self, evt_pubsub=None): self.ren.AddActor(evt_pubsub.data) diff --git a/invesalius/data/volume.py b/invesalius/data/volume.py index 8c25001..ddebdf2 100755 --- a/invesalius/data/volume.py +++ b/invesalius/data/volume.py @@ -24,6 +24,7 @@ import wx import wx.lib.pubsub as ps import constants as const +from data import vtk_utils import project as prj Kernels = { @@ -132,7 +133,7 @@ class Volume(): def __load_preset_config(self): self.config = prj.Project().raycasting_preset - + def __update_colour_table(self): if self.config['advancedCLUT']: self.Create16bColorTable(self.scale) @@ -155,7 +156,7 @@ class Volume(): colour = self.GetBackgroundColour() ps.Publisher.sendMessage('Change volume viewer background colour', colour) ps.Publisher.sendMessage('Change volume viewer gui colour', colour) - + def OnSetRelativeWindowLevel(self, pubsub_evt): diff_ww, diff_wl = pubsub_evt.data @@ -360,10 +361,13 @@ class Volume(): def ApplyConvolution(self, imagedata): number_filters = len(self.config['convolutionFilters']) + update_progress= vtk_utils.ShowProgress(number_filters) for filter in self.config['convolutionFilters']: convolve = vtk.vtkImageConvolve() convolve.SetInput(imagedata) convolve.SetKernel5x5([i/60.0 for i in Kernels[filter]]) + convolve.AddObserver("ProgressEvent", lambda obj,evt: + update_progress(convolve, "%s ..." % filter)) convolve.Update() imagedata = convolve.GetOutput() return imagedata @@ -372,11 +376,15 @@ class Volume(): proj = prj.Project() image = proj.imagedata + update_progress= vtk_utils.ShowProgress(4) + # Flip original vtkImageData flip = vtk.vtkImageFlip() flip.SetInput(image) flip.SetFilteredAxis(1) flip.FlipAboutOriginOn() + flip.AddObserver("ProgressEvent", lambda obj,evt: + update_progress(flip, "Fliping ...")) flip.Update() image = flip.GetOutput() @@ -388,6 +396,8 @@ class Volume(): cast.SetInput(image) cast.SetShift(abs(scale[0])) cast.SetOutputScalarTypeToUnsignedShort() + cast.AddObserver("ProgressEvent", lambda obj,evt: + update_progress(cast, "Casting ...")) cast.Update() image2 = cast self.imagedata = image2 @@ -423,6 +433,8 @@ class Volume(): volume_mapper.SetInput(image2) volume_mapper.IntermixIntersectingGeometryOn() + volume_mapper.AddObserver("ProgressEvent", lambda obj,evt: + update_progress(volume_mapper, "Mapper ...")) self.volume_mapper = volume_mapper # TODO: Look to this @@ -463,6 +475,8 @@ class Volume(): volume = vtk.vtkVolume() volume.SetMapper(volume_mapper) volume.SetProperty(volume_properties) + volume.AddObserver("ProgressEvent", lambda obj,evt: + update_progress(volume, "Volume ...")) self.volume = volume colour = self.GetBackgroundColour() diff --git a/invesalius/gui/default_viewers.py b/invesalius/gui/default_viewers.py index 08b7bb4..1bafeb3 100755 --- a/invesalius/gui/default_viewers.py +++ b/invesalius/gui/default_viewers.py @@ -21,10 +21,10 @@ 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 +from gui.widgets.clut_raycasting import CLUTRaycastingWidget class Panel(wx.Panel): def __init__(self, parent): @@ -32,6 +32,7 @@ class Panel(wx.Panel): size=wx.Size(744, 656)) self.__init_aui_manager() + self.__bind_events_wx() #self.__init_four_way_splitter() #self.__init_mix() @@ -87,6 +88,9 @@ class Panel(wx.Panel): Bottom().Centre().Caption("Volume").\ MaximizeButton(True).CloseButton(False) + self.s4 = s4 + self.p4 = p4 + if sys.platform == 'win32': self.aui_manager.AddPane(p1, s1) self.aui_manager.AddPane(p2, s2) @@ -100,6 +104,17 @@ class Panel(wx.Panel): self.aui_manager.Update() + def __bind_events_wx(self): + self.aui_manager.Bind(wx.aui.EVT_AUI_PANE_MAXIMIZE, self.OnMaximize) + self.aui_manager.Bind(wx.aui.EVT_AUI_PANE_RESTORE, self.OnRestore) + + def OnMaximize(self, evt): + if evt.GetPane().name == self.s4.name: + ps.Publisher().sendMessage('Show raycasting widget', None) + + def OnRestore(self, evt): + if evt.GetPane().name == self.s4.name: + ps.Publisher().sendMessage('Hide raycasting widget', None) def __init_four_way_splitter(self): @@ -166,10 +181,57 @@ class Panel(wx.Panel): aui_manager.Update() +class VolumeInteraction(wx.Panel): + def __init__(self, parent, id): + super(VolumeInteraction, self).__init__(parent, id) + 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_wx() + #sizer.Fit(self) + + def __init_aui_manager(self): + self.aui_manager = wx.aui.AuiManager() + self.aui_manager.SetManagedWindow(self) + + p1 = volume_viewer.Viewer(self) + s1 = wx.aui.AuiPaneInfo().Centre().\ + CloseButton(False).MaximizeButton(False).CaptionVisible(0) + self.s1 = s1 + self.clut_raycasting = CLUTRaycastingWidget(self, -1) + self.s2 = wx.aui.AuiPaneInfo().Centre().\ + CloseButton(False).MaximizeButton(False).CaptionVisible(0).\ + Hide() + if sys.platform == 'win32': + self.aui_manager.AddPane(p1, s1) + self.aui_manager.AddPane(self.clut_raycasting, self.s2) + else: + self.aui_manager.AddPane(self.clut_raycasting, self.s2) + self.aui_manager.AddPane(p1, s1) + self.aui_manager.Update() + + def ShowRaycastingWidget(self, evt_pubsub=None): + p = self.aui_manager.GetPane(self.clut_raycasting) + p.Show() + self.aui_manager.Update() + self.clut_raycasting.SetRaycastPreset(None) + def HideRaycastingWidget(self, evt_pubsub=None): + p = self.aui_manager.GetPane(self.clut_raycasting) + p.Hide() + self.aui_manager.Update() + def __bind_events_wx(self): + #self.Bind(wx.EVT_SIZE, self.OnSize) + #self.Bind(wx.EVT_MAXIMIZE, self.OnMaximize) + pass import wx.lib.platebtn as pbtn @@ -199,7 +261,7 @@ class VolumeViewerCover(wx.Panel): wx.Panel.__init__(self, parent) sizer = wx.BoxSizer(wx.HORIZONTAL) - sizer.Add(volume_viewer.Viewer(self), 1, wx.EXPAND|wx.GROW) + sizer.Add(VolumeInteraction(self, -1), 1, wx.EXPAND|wx.GROW) sizer.Add(VolumeToolPanel(self), 0, wx.EXPAND|wx.GROW) sizer.Fit(self) diff --git a/invesalius/gui/widgets/clut_raycasting.py b/invesalius/gui/widgets/clut_raycasting.py index f6d5018..9b603c9 100644 --- a/invesalius/gui/widgets/clut_raycasting.py +++ b/invesalius/gui/widgets/clut_raycasting.py @@ -334,8 +334,8 @@ class CLUTRaycastingWidget(wx.Panel): self._draw_curves(ctx) self._draw_points(ctx) self._draw_selection_curve(ctx, width) - #if self.point_dragged: - # self._draw_selected_point_text(ctx) + if self.point_dragged: + self._draw_selected_point_text(ctx) def _build_histogram(self): @@ -396,7 +396,9 @@ class CLUTRaycastingWidget(wx.Panel): def SetRaycastPreset(self, preset): preset = project.Project().raycasting_preset print preset - if preset['advancedCLUT']: + if not preset: + self.to_draw_points = 0 + elif preset['advancedCLUT']: self.to_draw_points = 1 self.points = preset['16bitClutCurves'] self.colours = preset['16bitClutColors'] -- libgit2 0.21.2