From 2c9f1dc3e11f144a94eee586edf61a86b17338c5 Mon Sep 17 00:00:00 2001 From: Thiago Franco de Moraes Date: Mon, 22 Aug 2016 14:44:34 -0300 Subject: [PATCH] Gui improvements to Fill holes and remove parts (#48) --- invesalius/data/styles.py | 20 +++++++++++++++++--- invesalius/gui/dialogs.py | 98 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------------------------------- 2 files changed, 76 insertions(+), 42 deletions(-) diff --git a/invesalius/data/styles.py b/invesalius/data/styles.py index f5d6755..d22295b 100644 --- a/invesalius/data/styles.py +++ b/invesalius/data/styles.py @@ -22,6 +22,8 @@ import multiprocessing import tempfile import time +from concurrent import futures + import vtk import wx @@ -1779,6 +1781,8 @@ class FloodFillMaskInteractorStyle(DefaultInteractorStyle): self.fill_value = 254 self._dlg_title = _(u"Fill holes") + self._progr_title = _(u"Fill hole") + self._progr_msg = _(u"Filling hole ...") self.AddObserver("LeftButtonPressEvent", self.OnFFClick) @@ -1837,10 +1841,8 @@ class FloodFillMaskInteractorStyle(DefaultInteractorStyle): bstruct = np.zeros((3, 3, 1), dtype='uint8') bstruct[:, :, 0] = _bstruct - - floodfill.floodfill_threshold(mask, [[x, y, z]], self.t0, self.t1, self.fill_value, bstruct, mask) - if self.config.target == '2D': + floodfill.floodfill_threshold(mask, [[x, y, z]], self.t0, self.t1, self.fill_value, bstruct, mask) b_mask = self.viewer.slice_.buffer_slices[self.orientation].mask index = self.viewer.slice_.buffer_slices[self.orientation].index @@ -1853,6 +1855,16 @@ class FloodFillMaskInteractorStyle(DefaultInteractorStyle): self.viewer.slice_.current_mask.save_history(index, self.orientation, p_mask, b_mask) else: + with futures.ThreadPoolExecutor(max_workers=1) as executor: + future = executor.submit(floodfill.floodfill_threshold, mask, [[x, y, z]], self.t0, self.t1, self.fill_value, bstruct, mask) + + dlg = wx.ProgressDialog(self._progr_title, self._progr_msg, parent=None, style=wx.PD_APP_MODAL) + while not future.done(): + dlg.Pulse() + time.sleep(0.1) + + dlg.Destroy() + self.viewer.slice_.current_mask.save_history(0, 'VOLUME', self.viewer.slice_.current_mask.matrix.copy(), cp_mask) self.viewer.slice_.buffer_slices['AXIAL'].discard_mask() @@ -1912,6 +1924,8 @@ class RemoveMaskPartsInteractorStyle(FloodFillMaskInteractorStyle): self.fill_value = 1 self._dlg_title = _(u"Remove parts") + self._progr_title = _(u"Remove part") + self._progr_msg = _(u"Removing part ...") def get_style(style): diff --git a/invesalius/gui/dialogs.py b/invesalius/gui/dialogs.py index 839cdc8..2578ab7 100644 --- a/invesalius/gui/dialogs.py +++ b/invesalius/gui/dialogs.py @@ -1851,14 +1851,11 @@ class FFillOptionsDialog(wx.Dialog): self._init_gui() def _init_gui(self): - sizer = wx.GridBagSizer(5, 6) - - flag_labels = wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL - - # self.target = wx.RadioBox(self, -1, "", - # choices=[_(u"2D - Actual slice"), _(u"3D - Entire volume")], - # style=wx.NO_BORDER | wx.VERTICAL) - self.target_2d = wx.RadioButton(self, -1, _(u"2D - Actual slice")) + """ + Create the widgets. + """ + # Target + self.target_2d = wx.RadioButton(self, -1, _(u"2D - Actual slice"), style=wx.RB_GROUP) self.target_3d = wx.RadioButton(self, -1, _(u"3D - All slices")) if self.config.target == "2D": @@ -1866,54 +1863,77 @@ class FFillOptionsDialog(wx.Dialog): else: self.target_3d.SetValue(1) - choices2d = ["4", "8"] - choices3d = ["6", "18", "26"] - self.conect2D = wx.RadioBox(self, -1, _(u"2D Connectivity"), choices=choices2d, style=wx.NO_BORDER | wx.HORIZONTAL) - self.conect3D = wx.RadioBox(self, -1, _(u"3D Connectivity"), choices=choices3d, style=wx.NO_BORDER | wx.HORIZONTAL) + # Connectivity 2D + self.conect2D_4 = wx.RadioButton(self, -1, "4", style=wx.RB_GROUP) + self.conect2D_8 = wx.RadioButton(self, -1, "8") - try: - self.conect2D.SetSelection(choices2d.index(str(self.config.con_2d))) - except ValueError: - print "ERROR 2D" - self.conect2D.SetSelection(0) + if self.config.con_2d == 8: + self.conect2D_8.SetValue(1) + else: + self.conect2D_4.SetValue(1) self.config.con_2d = 4 - try: - self.conect3D.SetSelection(choices3d.index(str(self.config.con_3d))) - except ValueError: - print "ERROR 3D" - self.conect3D.SetSelection(0) - self.config.con_3d = 6 + # Connectivity 3D + self.conect3D_6 = wx.RadioButton(self, -1, "6", style=wx.RB_GROUP) + self.conect3D_18 = wx.RadioButton(self, -1, "18") + self.conect3D_26 = wx.RadioButton(self, -1, "26") + + if self.config.con_3d == 18: + self.conect3D_18.SetValue(1) + elif self.config.con_3d == 26: + self.conect3D_26.SetValue(1) + else: + self.conect3D_6.SetValue(1) + + # Sizer + sizer = wx.GridBagSizer(11, 6) + sizer.AddStretchSpacer((0, 0)) + + sizer.Add(wx.StaticText(self, -1, _(u"Parameters")), (1, 0), (1, 6), flag=wx.LEFT, border=7) + sizer.Add(self.target_2d, (2, 0), (1, 6), flag=wx.LEFT, border=9) + sizer.Add(self.target_3d, (3, 0), (1, 6), flag=wx.LEFT, border=9) + + sizer.AddStretchSpacer((4, 0)) - sizer.Add(wx.StaticText(self, -1, _(u"Parameters")), (0, 0), flag=wx.TOP|wx.LEFT|wx.RIGHT, border=7) - sizer.AddStretchSpacer((0, 5)) - sizer.Add(self.target_2d, (1, 0), (1, 3), flag=wx.LEFT|wx.RIGHT, border=9) - sizer.Add(self.target_3d, (2, 0), (1, 3), flag=wx.LEFT|wx.RIGHT, border=9) - sizer.Add(self.conect2D, (3, 0), flag=wx.TOP|wx.LEFT|wx.RIGHT, border=9) - sizer.Add(self.conect3D, (4, 0), flag=wx.ALL, border=9) + sizer.Add(wx.StaticText(self, -1, _(u"2D Connectivity")), (5, 0), (1, 6), flag=wx.LEFT, border=9) + sizer.Add(self.conect2D_4, (6, 0), flag=wx.LEFT, border=9) + sizer.Add(self.conect2D_8, (6, 1), flag=wx.LEFT, border=9) + + sizer.AddStretchSpacer((7, 0)) + + sizer.Add(wx.StaticText(self, -1, _(u"3D Connectivity")), (8, 0), (1, 6), flag=wx.LEFT, border=9) + sizer.Add(self.conect3D_6, (9, 0), flag=wx.LEFT, border=9) + sizer.Add(self.conect3D_18, (9, 1), flag=wx.LEFT, border=9) + sizer.Add(self.conect3D_26, (9, 2), flag=wx.LEFT, border=9) + sizer.AddStretchSpacer((10, 0)) self.SetSizer(sizer) sizer.Fit(self) self.Layout() - self.Bind(wx.EVT_RADIOBUTTON, self.OnSetTarget) - self.conect2D.Bind(wx.EVT_RADIOBOX, self.OnSetCon2D) - self.conect3D.Bind(wx.EVT_RADIOBOX, self.OnSetCon3D) + self.Bind(wx.EVT_RADIOBUTTON, self.OnSetRadio) self.Bind(wx.EVT_CLOSE, self.OnClose) - def OnSetTarget(self, evt): + def OnSetRadio(self, evt): + # Target if self.target_2d.GetValue(): self.config.target = "2D" else: self.config.target = "3D" - def OnSetCon2D(self, evt): - self.config.con_2d = int(self.conect2D.GetStringSelection()) - print self.config.con_2d + # 2D + if self.conect2D_4.GetValue(): + self.config.con_2d = 4 + elif self.conect2D_8.GetValue(): + self.config.con_2d = 8 - def OnSetCon3D(self, evt): - self.config.con_3d = int(self.conect3D.GetStringSelection()) - print self.config.con_3d + # 3D + if self.conect3D_6.GetValue(): + self.config.con_3d = 6 + elif self.conect3D_18.GetValue(): + self.config.con_3d = 18 + elif self.conect3D_26.GetValue(): + self.config.con_3d = 26 def OnClose(self, evt): if self.config.dlg_visible: -- libgit2 0.21.2