Commit 71982a56fb47656d9a9c47e89ba93f5413812e09
Committed by
GitHub
1 parent
a7c8e435
Exists in
master
and in
6 other branches
Adds threshold, manual segmentation and watershed to segmentation menu (#80)
Adds threshold, manual segmentation and watershed to segmentation menu
Showing
5 changed files
with
50 additions
and
9 deletions
Show diff stats
invesalius/constants.py
@@ -528,6 +528,9 @@ ID_FLOODFILL_MASK = wx.NewId() | @@ -528,6 +528,9 @@ ID_FLOODFILL_MASK = wx.NewId() | ||
528 | ID_FILL_HOLE_AUTO = wx.NewId() | 528 | ID_FILL_HOLE_AUTO = wx.NewId() |
529 | ID_REMOVE_MASK_PART = wx.NewId() | 529 | ID_REMOVE_MASK_PART = wx.NewId() |
530 | ID_SELECT_MASK_PART = wx.NewId() | 530 | ID_SELECT_MASK_PART = wx.NewId() |
531 | +ID_MANUAL_SEGMENTATION = wx.NewId() | ||
532 | +ID_WATERSHED_SEGMENTATION = wx.NewId() | ||
533 | +ID_THRESHOLD_SEGMENTATION = wx.NewId() | ||
531 | ID_FLOODFILL_SEGMENTATION = wx.NewId() | 534 | ID_FLOODFILL_SEGMENTATION = wx.NewId() |
532 | ID_CROP_MASK = wx.NewId() | 535 | ID_CROP_MASK = wx.NewId() |
533 | 536 |
invesalius/data/slice_.py
@@ -196,10 +196,10 @@ class Slice(object): | @@ -196,10 +196,10 @@ class Slice(object): | ||
196 | Publisher.subscribe(self.__redo_edition, 'Redo edition') | 196 | Publisher.subscribe(self.__redo_edition, 'Redo edition') |
197 | 197 | ||
198 | Publisher.subscribe(self._fill_holes_auto, 'Fill holes automatically') | 198 | Publisher.subscribe(self._fill_holes_auto, 'Fill holes automatically') |
199 | - | 199 | + |
200 | def GetMaxSliceNumber(self, orientation): | 200 | def GetMaxSliceNumber(self, orientation): |
201 | shape = self.matrix.shape | 201 | shape = self.matrix.shape |
202 | - | 202 | + |
203 | # Because matrix indexing starts with 0 so the last slice is the shape | 203 | # Because matrix indexing starts with 0 so the last slice is the shape |
204 | # minu 1. | 204 | # minu 1. |
205 | if orientation == 'AXIAL': | 205 | if orientation == 'AXIAL': |
invesalius/gui/frame.py
@@ -449,6 +449,19 @@ class Frame(wx.Frame): | @@ -449,6 +449,19 @@ class Frame(wx.Frame): | ||
449 | elif id == const.ID_REORIENT_IMG: | 449 | elif id == const.ID_REORIENT_IMG: |
450 | self.OnReorientImg() | 450 | self.OnReorientImg() |
451 | 451 | ||
452 | + elif id == const.ID_THRESHOLD_SEGMENTATION: | ||
453 | + Publisher.sendMessage("Show panel", const.ID_THRESHOLD_SEGMENTATION) | ||
454 | + Publisher.sendMessage('Enable style', const.STATE_DEFAULT) | ||
455 | + | ||
456 | + elif id == const.ID_MANUAL_SEGMENTATION: | ||
457 | + Publisher.sendMessage("Show panel", const.ID_MANUAL_SEGMENTATION) | ||
458 | + Publisher.sendMessage('Enable style', const.SLICE_STATE_EDITOR) | ||
459 | + | ||
460 | + elif id == const.ID_WATERSHED_SEGMENTATION: | ||
461 | + Publisher.sendMessage("Show panel", const.ID_WATERSHED_SEGMENTATION) | ||
462 | + # Publisher.sendMessage('Disable actual style') | ||
463 | + Publisher.sendMessage('Enable style', const.SLICE_STATE_WATERSHED) | ||
464 | + | ||
452 | elif id == const.ID_FLOODFILL_MASK: | 465 | elif id == const.ID_FLOODFILL_MASK: |
453 | self.OnFillHolesManually() | 466 | self.OnFillHolesManually() |
454 | 467 | ||
@@ -664,7 +677,12 @@ class MenuBar(wx.MenuBar): | @@ -664,7 +677,12 @@ class MenuBar(wx.MenuBar): | ||
664 | const.ID_FLIP_Z, | 677 | const.ID_FLIP_Z, |
665 | const.ID_SWAP_XY, | 678 | const.ID_SWAP_XY, |
666 | const.ID_SWAP_XZ, | 679 | const.ID_SWAP_XZ, |
667 | - const.ID_SWAP_YZ,] | 680 | + const.ID_SWAP_YZ, |
681 | + const.ID_THRESHOLD_SEGMENTATION, | ||
682 | + const.ID_MANUAL_SEGMENTATION, | ||
683 | + const.ID_WATERSHED_SEGMENTATION, | ||
684 | + const.ID_THRESHOLD_SEGMENTATION, | ||
685 | + const.ID_FLOODFILL_SEGMENTATION,] | ||
668 | self.__init_items() | 686 | self.__init_items() |
669 | self.__bind_events() | 687 | self.__bind_events() |
670 | 688 | ||
@@ -784,6 +802,9 @@ class MenuBar(wx.MenuBar): | @@ -784,6 +802,9 @@ class MenuBar(wx.MenuBar): | ||
784 | 802 | ||
785 | # Segmentation Menu | 803 | # Segmentation Menu |
786 | segmentation_menu = wx.Menu() | 804 | segmentation_menu = wx.Menu() |
805 | + self.threshold_segmentation = segmentation_menu.Append(const.ID_THRESHOLD_SEGMENTATION, _(u"Threshold")) | ||
806 | + self.manual_segmentation = segmentation_menu.Append(const.ID_MANUAL_SEGMENTATION, _(u"Manual segmentation")) | ||
807 | + self.watershed_segmentation = segmentation_menu.Append(const.ID_WATERSHED_SEGMENTATION, _(u"Watershed")) | ||
787 | self.ffill_segmentation = segmentation_menu.Append(const.ID_FLOODFILL_SEGMENTATION, _(u"Region growing")) | 808 | self.ffill_segmentation = segmentation_menu.Append(const.ID_FLOODFILL_SEGMENTATION, _(u"Region growing")) |
788 | self.ffill_segmentation.Enable(False) | 809 | self.ffill_segmentation.Enable(False) |
789 | 810 |
invesalius/gui/task_slice.py
@@ -342,6 +342,7 @@ class InnerFoldPanel(wx.Panel): | @@ -342,6 +342,7 @@ class InnerFoldPanel(wx.Panel): | ||
342 | Publisher.subscribe(self.OnRetrieveStyle, 'Retrieve task slice style') | 342 | Publisher.subscribe(self.OnRetrieveStyle, 'Retrieve task slice style') |
343 | Publisher.subscribe(self.OnDisableStyle, 'Disable task slice style') | 343 | Publisher.subscribe(self.OnDisableStyle, 'Disable task slice style') |
344 | Publisher.subscribe(self.OnCloseProject, 'Close project data') | 344 | Publisher.subscribe(self.OnCloseProject, 'Close project data') |
345 | + Publisher.subscribe(self.OnColapsePanel, 'Show panel') | ||
345 | 346 | ||
346 | def OnFoldPressCaption(self, evt): | 347 | def OnFoldPressCaption(self, evt): |
347 | id = evt.GetTag().GetId() | 348 | id = evt.GetTag().GetId() |
@@ -388,6 +389,19 @@ class InnerFoldPanel(wx.Panel): | @@ -388,6 +389,19 @@ class InnerFoldPanel(wx.Panel): | ||
388 | def OnCloseProject(self, pubsub_evt): | 389 | def OnCloseProject(self, pubsub_evt): |
389 | self.fold_panel.Expand(self.fold_panel.GetFoldPanel(0)) | 390 | self.fold_panel.Expand(self.fold_panel.GetFoldPanel(0)) |
390 | 391 | ||
392 | + def OnColapsePanel(self, pubsub_evt): | ||
393 | + panel_seg_id = { | ||
394 | + const.ID_THRESHOLD_SEGMENTATION: 0, | ||
395 | + const.ID_MANUAL_SEGMENTATION: 1, | ||
396 | + const.ID_WATERSHED_SEGMENTATION: 2 | ||
397 | + } | ||
398 | + | ||
399 | + try: | ||
400 | + _id = panel_seg_id[pubsub_evt.data] | ||
401 | + self.fold_panel.Expand(self.fold_panel.GetFoldPanel(_id)) | ||
402 | + except KeyError: | ||
403 | + pass | ||
404 | + | ||
391 | def GetMaskSelected(self): | 405 | def GetMaskSelected(self): |
392 | x= self.mask_prop_panel.GetMaskSelected() | 406 | x= self.mask_prop_panel.GetMaskSelected() |
393 | return self.mask_prop_panel.GetMaskSelected() | 407 | return self.mask_prop_panel.GetMaskSelected() |
invesalius/style.py
@@ -78,10 +78,10 @@ class StyleStateManager(object): | @@ -78,10 +78,10 @@ class StyleStateManager(object): | ||
78 | const.STATE_DEFAULT | 78 | const.STATE_DEFAULT |
79 | 79 | ||
80 | def AddState(self, state): | 80 | def AddState(self, state): |
81 | - | 81 | + |
82 | level = const.STYLE_LEVEL[state] | 82 | level = const.STYLE_LEVEL[state] |
83 | max_level = max(self.stack.keys()) | 83 | max_level = max(self.stack.keys()) |
84 | - | 84 | + |
85 | # Insert new state into stack | 85 | # Insert new state into stack |
86 | self.stack[level] = state | 86 | self.stack[level] = state |
87 | 87 | ||
@@ -93,7 +93,7 @@ class StyleStateManager(object): | @@ -93,7 +93,7 @@ class StyleStateManager(object): | ||
93 | level = const.STYLE_LEVEL[state] | 93 | level = const.STYLE_LEVEL[state] |
94 | if level in self.stack.keys(): | 94 | if level in self.stack.keys(): |
95 | max_level = max(self.stack.keys()) | 95 | max_level = max(self.stack.keys()) |
96 | - | 96 | + |
97 | # Remove item from stack | 97 | # Remove item from stack |
98 | self.stack.pop(level) | 98 | self.stack.pop(level) |
99 | 99 | ||
@@ -104,9 +104,12 @@ class StyleStateManager(object): | @@ -104,9 +104,12 @@ class StyleStateManager(object): | ||
104 | # level in stack has been removed | 104 | # level in stack has been removed |
105 | if level == max_level: | 105 | if level == max_level: |
106 | new_state = self.stack[new_max_level] | 106 | new_state = self.stack[new_max_level] |
107 | - | 107 | + |
108 | return self.stack[new_max_level] | 108 | return self.stack[new_max_level] |
109 | - | 109 | + |
110 | max_level = max(self.stack.keys()) | 110 | max_level = max(self.stack.keys()) |
111 | return self.stack[max_level] | 111 | return self.stack[max_level] |
112 | - | 112 | + |
113 | + def RemoveActualState(self): | ||
114 | + max_level = max(self.stack.keys()) | ||
115 | + return self.stack.pop(max_level) |