From d97c6212269264e55f5d99e6bdac88a612da7883 Mon Sep 17 00:00:00 2001 From: tfmoraes Date: Mon, 6 Aug 2012 19:49:45 +0000 Subject: [PATCH] Added the option to swap axes --- invesalius/constants.py | 5 +++++ invesalius/data/mask.py | 6 ++++++ invesalius/data/slice_.py | 16 ++++++++++++++++ invesalius/data/viewer_slice.py | 7 ++++++- invesalius/gui/frame.py | 18 +++++++++++++++++- 5 files changed, 50 insertions(+), 2 deletions(-) diff --git a/invesalius/constants.py b/invesalius/constants.py index 72f0955..b2803e2 100644 --- a/invesalius/constants.py +++ b/invesalius/constants.py @@ -460,6 +460,11 @@ ID_START = wx.NewId() ID_FLIP_X = wx.NewId() ID_FLIP_Y = wx.NewId() ID_FLIP_Z = wx.NewId() + +ID_SWAP_XY = wx.NewId() +ID_SWAP_XZ = wx.NewId() +ID_SWAP_YZ = wx.NewId() + #--------------------------------------------------------- STATE_DEFAULT = 1000 STATE_WL = 1001 diff --git a/invesalius/data/mask.py b/invesalius/data/mask.py index 5e03083..c5c5169 100644 --- a/invesalius/data/mask.py +++ b/invesalius/data/mask.py @@ -49,6 +49,7 @@ class Mask(): def __bind_events(self): Publisher.subscribe(self.OnFlipVolume, 'Flip volume') + Publisher.subscribe(self.OnSwapVolumeAxes, 'Swap volume axes') def SavePlist(self, filename): mask = {} @@ -98,6 +99,11 @@ class Mask(): submatrix[:] = submatrix[:, :, ::-1] self.matrix[0, 0, 1::] = self.matrix[0, 0, :0:-1] + def OnSwapVolumeAxes(self, pubsub_evt): + axis0, axis1 = pubsub_evt.data + self.matrix = self.matrix.swapaxes(axis0, axis1) + print type(self.matrix) + def _save_mask(self, filename): shutil.copyfile(self.temp_file, filename) diff --git a/invesalius/data/slice_.py b/invesalius/data/slice_.py index 982a38e..ae5241b 100644 --- a/invesalius/data/slice_.py +++ b/invesalius/data/slice_.py @@ -134,6 +134,7 @@ class Slice(object): Publisher.subscribe(self.UpdateSlice3D,'Update slice 3D') Publisher.subscribe(self.OnFlipVolume, 'Flip volume') + Publisher.subscribe(self.OnSwapVolumeAxes, 'Swap volume axes') def GetMaxSliceNumber(self, orientation): shape = self.matrix.shape @@ -980,6 +981,21 @@ class Slice(object): for buffer_ in self.buffer_slices.values(): buffer_.discard_buffer() + def OnSwapVolumeAxes(self, pubsub_evt): + axis0, axis1 = pubsub_evt.data + self.matrix = self.matrix.swapaxes(axis0, axis1) + if (axis0, axis1) == (2, 1): + self.spacing = self.spacing[1], self.spacing[0], self.spacing[2] + elif (axis0, axis1) == (2, 0): + self.spacing = self.spacing[2], self.spacing[1], self.spacing[0] + elif (axis0, axis1) == (1, 0): + self.spacing = self.spacing[0], self.spacing[2], self.spacing[1] + + for buffer_ in self.buffer_slices.values(): + buffer_.discard_buffer() + + print type(self.matrix) + def OnExportMask(self, pubsub_evt): #imagedata = self.current_mask.imagedata imagedata = self.imagedata diff --git a/invesalius/data/viewer_slice.py b/invesalius/data/viewer_slice.py index e4dc34b..88ffbc8 100755 --- a/invesalius/data/viewer_slice.py +++ b/invesalius/data/viewer_slice.py @@ -1002,7 +1002,7 @@ class Viewer(wx.Panel): Publisher.subscribe(self.RemoveActors, 'Remove actors ' + str(ORIENTATIONS[self.orientation])) Publisher.subscribe(self.ReloadActualSlice, 'Reload actual slice') - + Publisher.subscribe(self.OnUpdateScroll, 'Update scroll') def SetDefaultCursor(self, pusub_evt): self.interactor.SetCursor(wx.StockCursor(wx.CURSOR_DEFAULT)) @@ -1502,6 +1502,11 @@ class Viewer(wx.Panel): self.set_slice_number(pos) self.interactor.Render() + def OnUpdateScroll(self, pubsub_evt): + max_slice_number = sl.Slice().GetNumberOfSlices(self.orientation) + self.scroll.SetScrollbar(wx.SB_VERTICAL, 1, max_slice_number, + max_slice_number) + def AddActors(self, pubsub_evt): "Inserting actors" actors, n = pubsub_evt.data diff --git a/invesalius/gui/frame.py b/invesalius/gui/frame.py index 314d308..9209c57 100755 --- a/invesalius/gui/frame.py +++ b/invesalius/gui/frame.py @@ -344,7 +344,11 @@ class Frame(wx.Frame): const.ID_FLIP_Y: 1, const.ID_FLIP_Z: 0}[id] self.FlipVolume(axis) - + elif id in (const.ID_SWAP_XY, const.ID_SWAP_XZ, const.ID_SWAP_YZ): + axes = {const.ID_SWAP_XY: (2, 1), + const.ID_SWAP_XZ: (2, 0), + const.ID_SWAP_YZ: (1, 0)}[id] + self.SwapAxes(axes) def OnSize(self, evt): """ Refresh GUI when frame is resized. @@ -418,6 +422,11 @@ class Frame(wx.Frame): Publisher.sendMessage('Flip volume', axis) Publisher.sendMessage('Reload actual slice') + def SwapAxes(self, axes): + Publisher.sendMessage('Swap volume axes', axes) + Publisher.sendMessage('Update scroll') + Publisher.sendMessage('Reload actual slice') + # ------------------------------------------------------------------ # ------------------------------------------------------------------ # ------------------------------------------------------------------ @@ -492,9 +501,16 @@ class MenuBar(wx.MenuBar): app(const.ID_FLIP_Y, _("A <-> P")) app(const.ID_FLIP_Z, _("T <-> B")) + swap_axes_menu = wx.Menu() + app = swap_axes_menu.Append + app(const.ID_SWAP_XY, _("R-L <-> A-P")) + app(const.ID_SWAP_XZ, _("R-L <-> T-B")) + app(const.ID_SWAP_YZ, _("A-P <-> T-B")) + file_edit = wx.Menu() app = file_edit.Append file_edit.AppendMenu(wx.NewId(), _('Flip'), flip_menu) + file_edit.AppendMenu(wx.NewId(), _('Swap axes'), swap_axes_menu) #app(wx.ID_UNDO, "Undo\tCtrl+Z") #app(wx.ID_REDO, "Redo\tCtrl+Y") #app(const.ID_EDIT_LIST, "Show Undo List...") -- libgit2 0.21.2