From 71982a56fb47656d9a9c47e89ba93f5413812e09 Mon Sep 17 00:00:00 2001 From: Thiago Franco de Moraes Date: Mon, 17 Apr 2017 15:12:52 -0300 Subject: [PATCH] Adds threshold, manual segmentation and watershed to segmentation menu (#80) --- invesalius/constants.py | 3 +++ invesalius/data/slice_.py | 4 ++-- invesalius/gui/frame.py | 23 ++++++++++++++++++++++- invesalius/gui/task_slice.py | 14 ++++++++++++++ invesalius/style.py | 15 +++++++++------ 5 files changed, 50 insertions(+), 9 deletions(-) diff --git a/invesalius/constants.py b/invesalius/constants.py index f46f968..8664b7d 100644 --- a/invesalius/constants.py +++ b/invesalius/constants.py @@ -528,6 +528,9 @@ ID_FLOODFILL_MASK = wx.NewId() ID_FILL_HOLE_AUTO = wx.NewId() ID_REMOVE_MASK_PART = wx.NewId() ID_SELECT_MASK_PART = wx.NewId() +ID_MANUAL_SEGMENTATION = wx.NewId() +ID_WATERSHED_SEGMENTATION = wx.NewId() +ID_THRESHOLD_SEGMENTATION = wx.NewId() ID_FLOODFILL_SEGMENTATION = wx.NewId() ID_CROP_MASK = wx.NewId() diff --git a/invesalius/data/slice_.py b/invesalius/data/slice_.py index af70f59..47e9a01 100644 --- a/invesalius/data/slice_.py +++ b/invesalius/data/slice_.py @@ -196,10 +196,10 @@ class Slice(object): Publisher.subscribe(self.__redo_edition, 'Redo edition') Publisher.subscribe(self._fill_holes_auto, 'Fill holes automatically') - + def GetMaxSliceNumber(self, orientation): shape = self.matrix.shape - + # Because matrix indexing starts with 0 so the last slice is the shape # minu 1. if orientation == 'AXIAL': diff --git a/invesalius/gui/frame.py b/invesalius/gui/frame.py index 7ad0652..a467c68 100644 --- a/invesalius/gui/frame.py +++ b/invesalius/gui/frame.py @@ -449,6 +449,19 @@ class Frame(wx.Frame): elif id == const.ID_REORIENT_IMG: self.OnReorientImg() + elif id == const.ID_THRESHOLD_SEGMENTATION: + Publisher.sendMessage("Show panel", const.ID_THRESHOLD_SEGMENTATION) + Publisher.sendMessage('Enable style', const.STATE_DEFAULT) + + elif id == const.ID_MANUAL_SEGMENTATION: + Publisher.sendMessage("Show panel", const.ID_MANUAL_SEGMENTATION) + Publisher.sendMessage('Enable style', const.SLICE_STATE_EDITOR) + + elif id == const.ID_WATERSHED_SEGMENTATION: + Publisher.sendMessage("Show panel", const.ID_WATERSHED_SEGMENTATION) + # Publisher.sendMessage('Disable actual style') + Publisher.sendMessage('Enable style', const.SLICE_STATE_WATERSHED) + elif id == const.ID_FLOODFILL_MASK: self.OnFillHolesManually() @@ -664,7 +677,12 @@ class MenuBar(wx.MenuBar): const.ID_FLIP_Z, const.ID_SWAP_XY, const.ID_SWAP_XZ, - const.ID_SWAP_YZ,] + const.ID_SWAP_YZ, + const.ID_THRESHOLD_SEGMENTATION, + const.ID_MANUAL_SEGMENTATION, + const.ID_WATERSHED_SEGMENTATION, + const.ID_THRESHOLD_SEGMENTATION, + const.ID_FLOODFILL_SEGMENTATION,] self.__init_items() self.__bind_events() @@ -784,6 +802,9 @@ class MenuBar(wx.MenuBar): # Segmentation Menu segmentation_menu = wx.Menu() + self.threshold_segmentation = segmentation_menu.Append(const.ID_THRESHOLD_SEGMENTATION, _(u"Threshold")) + self.manual_segmentation = segmentation_menu.Append(const.ID_MANUAL_SEGMENTATION, _(u"Manual segmentation")) + self.watershed_segmentation = segmentation_menu.Append(const.ID_WATERSHED_SEGMENTATION, _(u"Watershed")) self.ffill_segmentation = segmentation_menu.Append(const.ID_FLOODFILL_SEGMENTATION, _(u"Region growing")) self.ffill_segmentation.Enable(False) diff --git a/invesalius/gui/task_slice.py b/invesalius/gui/task_slice.py index ff79f55..cb71a8d 100644 --- a/invesalius/gui/task_slice.py +++ b/invesalius/gui/task_slice.py @@ -342,6 +342,7 @@ class InnerFoldPanel(wx.Panel): Publisher.subscribe(self.OnRetrieveStyle, 'Retrieve task slice style') Publisher.subscribe(self.OnDisableStyle, 'Disable task slice style') Publisher.subscribe(self.OnCloseProject, 'Close project data') + Publisher.subscribe(self.OnColapsePanel, 'Show panel') def OnFoldPressCaption(self, evt): id = evt.GetTag().GetId() @@ -388,6 +389,19 @@ class InnerFoldPanel(wx.Panel): def OnCloseProject(self, pubsub_evt): self.fold_panel.Expand(self.fold_panel.GetFoldPanel(0)) + def OnColapsePanel(self, pubsub_evt): + panel_seg_id = { + const.ID_THRESHOLD_SEGMENTATION: 0, + const.ID_MANUAL_SEGMENTATION: 1, + const.ID_WATERSHED_SEGMENTATION: 2 + } + + try: + _id = panel_seg_id[pubsub_evt.data] + self.fold_panel.Expand(self.fold_panel.GetFoldPanel(_id)) + except KeyError: + pass + def GetMaskSelected(self): x= self.mask_prop_panel.GetMaskSelected() return self.mask_prop_panel.GetMaskSelected() diff --git a/invesalius/style.py b/invesalius/style.py index 29d3369..f694655 100644 --- a/invesalius/style.py +++ b/invesalius/style.py @@ -78,10 +78,10 @@ class StyleStateManager(object): const.STATE_DEFAULT def AddState(self, state): - + level = const.STYLE_LEVEL[state] max_level = max(self.stack.keys()) - + # Insert new state into stack self.stack[level] = state @@ -93,7 +93,7 @@ class StyleStateManager(object): level = const.STYLE_LEVEL[state] if level in self.stack.keys(): max_level = max(self.stack.keys()) - + # Remove item from stack self.stack.pop(level) @@ -104,9 +104,12 @@ class StyleStateManager(object): # level in stack has been removed if level == max_level: new_state = self.stack[new_max_level] - + return self.stack[new_max_level] - + max_level = max(self.stack.keys()) return self.stack[max_level] - + + def RemoveActualState(self): + max_level = max(self.stack.keys()) + return self.stack.pop(max_level) -- libgit2 0.21.2