From 30b43a7b7ef99f984f162869e0acef40777bbac8 Mon Sep 17 00:00:00 2001 From: Thiago Franco de Moraes Date: Mon, 19 Sep 2016 10:46:32 -0300 Subject: [PATCH] Using combobox to set region growing method --- invesalius/gui/dialogs.py | 245 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------------------------------------------------------------------------------------------- 1 file changed, 151 insertions(+), 94 deletions(-) diff --git a/invesalius/gui/dialogs.py b/invesalius/gui/dialogs.py index 1adec99..a9cf9ec 100644 --- a/invesalius/gui/dialogs.py +++ b/invesalius/gui/dialogs.py @@ -1906,6 +1906,82 @@ class Panel3DConnectivity(wx.Panel): self.Layout() +class PanelFFillThreshold(wx.Panel): + def __init__(self, parent, config, ID=-1, style=wx.TAB_TRAVERSAL|wx.NO_BORDER): + wx.Panel.__init__(self, parent, ID, style=style) + + self.config = config + + self._init_gui() + + def _init_gui(self): + import project as prj + + project = prj.Project() + bound_min, bound_max = project.threshold_range + colour = [i*255 for i in const.MASK_COLOUR[0]] + colour.append(100) + + self.threshold = grad.GradientCtrl(self, -1, int(bound_min), + int(bound_max), self.config.t0, + self.config.t1, colour) + + # sizer + sizer = wx.BoxSizer(wx.VERTICAL) + sizer.AddSpacer(5) + sizer.Add(self.threshold, 0, wx.EXPAND|wx.LEFT|wx.RIGHT, 5) + sizer.AddSpacer(5) + + self.SetSizer(sizer) + sizer.Fit(self) + self.Layout() + + self.Bind(grad.EVT_THRESHOLD_CHANGING, self.OnSlideChanged, self.threshold) + self.Bind(grad.EVT_THRESHOLD_CHANGED, self.OnSlideChanged, self.threshold) + + def OnSlideChanged(self, evt): + self.config.t0 = int(self.threshold.GetMinValue()) + self.config.t1 = int(self.threshold.GetMaxValue()) + print self.config.t0, self.config.t1 + + +class PanelFFillDynamic(wx.Panel): + def __init__(self, parent, config, ID=-1, style=wx.TAB_TRAVERSAL|wx.NO_BORDER): + wx.Panel.__init__(self, parent, ID, style=style) + + self.config = config + + self._init_gui() + + def _init_gui(self): + self.use_ww_wl = wx.CheckBox(self, -1, _(u"Use WW\&WL")) + self.use_ww_wl.SetValue(self.config.use_ww_wl) + + self.deviation_min = wx.SpinCtrl(self, -1, value='%d' % self.config.dev_min, min=0, max=10000) + self.deviation_max = wx.SpinCtrl(self, -1, value='%d' % self.config.dev_max, min=0, max=10000) + + sizer = wx.BoxSizer(wx.VERTICAL) + + sizer.Add(self.use_ww_wl) + sizer.Add(self.deviation_min) + sizer.Add(self.deviation_max) + + self.SetSizer(sizer) + sizer.Fit(self) + self.Layout() + + self.use_ww_wl.Bind(wx.EVT_CHECKBOX, self.OnSetUseWWWL) + self.deviation_min.Bind(wx.EVT_SPINCTRL, self.OnSetDeviation) + self.deviation_max.Bind(wx.EVT_SPINCTRL, self.OnSetDeviation) + + def OnSetUseWWWL(self, evt): + self.config.use_ww_wl = self.use_ww_wl.GetValue() + + def OnSetDeviation(self, evt): + self.config.dev_max = self.deviation_max.GetValue() + self.config.dev_min = self.deviation_min.GetValue() + + class FFillOptionsDialog(wx.Dialog): def __init__(self, title, config): pre = wx.PreDialog() @@ -1969,7 +2045,7 @@ class FFillOptionsDialog(wx.Dialog): sizer.AddSpacer(5) sizer.Add(self.panel3dcon, flag=wx.LEFT|wx.RIGHT|wx.EXPAND, border=7) sizer.AddSpacer(5) - sizer.AddSizer(self.close_btn, 0, flag=wx.ALIGN_RIGHT|wx.RIGHT, border=7) + sizer.Add(self.close_btn, 0, flag=wx.ALIGN_RIGHT|wx.RIGHT, border=7) sizer.AddSpacer(5) self.SetSizer(sizer) @@ -2113,157 +2189,137 @@ class FFillSegmentationOptionsDialog(wx.Dialog): Create the widgets. """ import project as prj + # 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 sys.platform == "win32": + border_style = wx.SIMPLE_BORDER + else: + border_style = wx.SUNKEN_BORDER + + self.panel_target = PanelTargeFFill(self, style=border_style|wx.TAB_TRAVERSAL) + self.panel2dcon = Panel2DConnectivity(self, style=border_style|wx.TAB_TRAVERSAL) + self.panel3dcon = Panel3DConnectivity(self, style=border_style|wx.TAB_TRAVERSAL) if self.config.target == "2D": - self.target_2d.SetValue(1) + self.panel_target.target_2d.SetValue(1) + self.panel2dcon.Enable(1) + self.panel3dcon.Enable(0) else: - self.target_3d.SetValue(1) + self.panel_target.target_3d.SetValue(1) + self.panel3dcon.Enable(1) + self.panel2dcon.Enable(0) # Connectivity 2D - self.conect2D_4 = wx.RadioButton(self, -1, "4", style=wx.RB_GROUP) - self.conect2D_8 = wx.RadioButton(self, -1, "8") - if self.config.con_2d == 8: - self.conect2D_8.SetValue(1) + self.panel2dcon.conect2D_8.SetValue(1) else: - self.conect2D_4.SetValue(1) + self.panel2dcon.conect2D_4.SetValue(1) self.config.con_2d = 4 # 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) + self.panel3dcon.conect3D_18.SetValue(1) elif self.config.con_3d == 26: - self.conect3D_26.SetValue(1) + self.panel3dcon.conect3D_26.SetValue(1) else: - self.conect3D_6.SetValue(1) - - project = prj.Project() - bound_min, bound_max = project.threshold_range - colour = [i*255 for i in const.MASK_COLOUR[0]] - colour.append(100) - self.threshold = grad.GradientCtrl(self, -1, int(bound_min), - int(bound_max), self.config.t0, - self.config.t1, colour) - self.threshold.SetMinSize((250, -1)) + self.panel3dcon.conect3D_6.SetValue(1) - self.method_threshold = wx.RadioButton(self, -1, _(u"Threshold"), style=wx.RB_GROUP) - self.method_dynamic = wx.RadioButton(self, -1, _(u"Dynamic")) + self.cmb_method = wx.ComboBox(self, -1, choices=(_(u"Threshold"), _(u"Dynamic")), style=wx.CB_READONLY) if self.config.method == 'dynamic': - self.method_dynamic.SetValue(1) + self.cmb_method.SetSelection(1) else: - self.method_threshold.SetValue(1) + self.cmb_method.SetSelection(0) self.config.method = 'threshold' - self.use_ww_wl = wx.CheckBox(self, -1, _(u"Use WW\&WL")) - self.use_ww_wl.SetValue(self.config.use_ww_wl) + self.panel_ffill_threshold = PanelFFillThreshold(self, self.config, -1) + self.panel_ffill_threshold.SetMinSize((300, -1)) + self.panel_ffill_threshold.Hide() - self.deviation_min = wx.SpinCtrl(self, -1, value='%d' % self.config.dev_min, min=0, max=10000) - self.deviation_max = wx.SpinCtrl(self, -1, value='%d' % self.config.dev_max, min=0, max=10000) + self.panel_ffill_dynamic = PanelFFillDynamic(self, self.config, -1) + self.panel_ffill_dynamic.SetMinSize((300, -1)) + self.panel_ffill_dynamic.Hide() + + self.close_btn = wx.Button(self, wx.ID_CLOSE) # Sizer sizer = wx.BoxSizer(wx.VERTICAL) - sizer.AddSpacer(7) - - sizer.Add(wx.StaticText(self, -1, _(u"Parameters")), flag=wx.LEFT, border=7) sizer.AddSpacer(5) - sizer.Add(self.target_2d, flag=wx.LEFT, border=9) - sizer.Add(self.target_3d, flag=wx.LEFT, border=9) - - sizer.AddSpacer(7) - - sizer.Add(wx.StaticText(self, -1, _(u"2D Connectivity")), flag=wx.LEFT, border=9) + sizer.Add(wx.StaticText(self, -1, _(u"Parameters")), flag=wx.LEFT, border=5) sizer.AddSpacer(5) - sizer_2d = wx.BoxSizer(wx.HORIZONTAL) - sizer_2d.Add(self.conect2D_4, flag=wx.LEFT, border=11) - sizer_2d.Add(self.conect2D_8, flag=wx.LEFT, border=11) - sizer.Add(sizer_2d) - - sizer.AddSpacer(7) - - sizer.Add(wx.StaticText(self, -1, _(u"3D Connectivity")), flag=wx.LEFT, border=9) + sizer.Add(self.panel_target, flag=wx.LEFT|wx.RIGHT|wx.EXPAND, border=7) sizer.AddSpacer(5) - sizer_3d = wx.BoxSizer(wx.HORIZONTAL) - sizer_3d.Add(self.conect3D_6, flag=wx.LEFT, border=11) - sizer_3d.Add(self.conect3D_18, flag=wx.LEFT, border=11) - sizer_3d.Add(self.conect3D_26, flag=wx.LEFT, border=11) - sizer.Add(sizer_3d) - - sizer.AddSpacer(7) - - sizer.Add(wx.StaticText(self, -1, _(u"Method")), flag=wx.LEFT, border=9) + sizer.Add(self.panel2dcon, flag=wx.LEFT|wx.RIGHT|wx.EXPAND, border=7) sizer.AddSpacer(5) - sizer.Add(self.method_threshold, flag=wx.LEFT, border=11) + sizer.Add(self.panel3dcon, flag=wx.LEFT|wx.RIGHT|wx.EXPAND, border=7) sizer.AddSpacer(5) - sizer.Add(self.threshold, flag=wx.LEFT|wx.RIGHT|wx.EXPAND, border=13) + + sizer.Add(wx.StaticText(self, -1, _(u"Method")), flag=wx.LEFT, border=9) sizer.AddSpacer(5) - sizer.Add(self.method_dynamic, flag=wx.LEFT, border=11) + sizer.Add(self.cmb_method, flag=wx.LEFT|wx.RIGHT|wx.EXPAND, border=7) + + if self.config.method == 'dynamic': + self.cmb_method.SetSelection(1) + self.panel_ffill_dynamic.Show() + sizer.Add(self.panel_ffill_dynamic, flag=wx.LEFT, border=11) + else: + self.cmb_method.SetSelection(0) + self.panel_ffill_threshold.Show() + sizer.Add(self.panel_ffill_threshold, flag=wx.LEFT, border=11) + self.config.method = 'threshold' + sizer.AddSpacer(5) - sizer.Add(self.use_ww_wl, flag=wx.LEFT, border=13) + sizer.Add(self.close_btn, 0, flag=wx.ALIGN_RIGHT|wx.RIGHT, border=5) sizer.AddSpacer(5) - sizer.Add(self.deviation_min, flag=wx.LEFT, border=13) - sizer.Add(self.deviation_max, flag=wx.LEFT, border=13) - - sizer.AddSpacer(7) self.SetSizer(sizer) sizer.Fit(self) self.Layout() self.Bind(wx.EVT_RADIOBUTTON, self.OnSetRadio) - self.Bind(grad.EVT_THRESHOLD_CHANGING, self.OnSlideChanged, self.threshold) - self.Bind(grad.EVT_THRESHOLD_CHANGED, self.OnSlideChanged, self.threshold) - self.use_ww_wl.Bind(wx.EVT_CHECKBOX, self.OnSetUseWWWL) - self.deviation_min.Bind(wx.EVT_SPINCTRL, self.OnSetDeviation) - self.deviation_max.Bind(wx.EVT_SPINCTRL, self.OnSetDeviation) + self.cmb_method.Bind(wx.EVT_COMBOBOX, self.OnSetMethod) self.Bind(wx.EVT_CLOSE, self.OnClose) def OnSetRadio(self, evt): # Target - if self.target_2d.GetValue(): + if self.panel_target.target_2d.GetValue(): self.config.target = "2D" + self.panel2dcon.Enable(1) + self.panel3dcon.Enable(0) else: self.config.target = "3D" + self.panel3dcon.Enable(1) + self.panel2dcon.Enable(0) # 2D - if self.conect2D_4.GetValue(): + if self.panel2dcon.conect2D_4.GetValue(): self.config.con_2d = 4 - elif self.conect2D_8.GetValue(): + elif self.panel2dcon.conect2D_8.GetValue(): self.config.con_2d = 8 # 3D - if self.conect3D_6.GetValue(): + if self.panel3dcon.conect3D_6.GetValue(): self.config.con_3d = 6 - elif self.conect3D_18.GetValue(): + elif self.panel3dcon.conect3D_18.GetValue(): self.config.con_3d = 18 - elif self.conect3D_26.GetValue(): + elif self.panel3dcon.conect3D_26.GetValue(): self.config.con_3d = 26 - # Method - if self.method_threshold.GetValue(): - self.config.method = 'threshold' - else: + def OnSetMethod(self, evt): + if self.cmb_method.GetSelection() == 1: self.config.method = 'dynamic' + self.panel_ffill_threshold.Hide() + self.panel_ffill_dynamic.Show() + self.GetSizer().Replace(self.panel_ffill_threshold, self.panel_ffill_dynamic) + else: + self.config.method = 'threshold' + self.panel_ffill_dynamic.Hide() + self.panel_ffill_threshold.Show() + self.GetSizer().Replace(self.panel_ffill_dynamic, self.panel_ffill_threshold) - def OnSlideChanged(self, evt): - self.config.t0 = int(self.threshold.GetMinValue()) - self.config.t1 = int(self.threshold.GetMaxValue()) - print self.config.t0, self.config.t1 - - def OnSetUseWWWL(self, evt): - self.config.use_ww_wl = self.use_ww_wl.GetValue() - - def OnSetDeviation(self, evt): - self.config.dev_max = self.deviation_max.GetValue() - self.config.dev_min = self.deviation_min.GetValue() + self.GetSizer().Fit(self) + self.Layout() def OnClose(self, evt): if self.config.dlg_visible: @@ -2271,6 +2327,7 @@ class FFillSegmentationOptionsDialog(wx.Dialog): evt.Skip() self.Destroy() + class CropOptionsDialog(wx.Dialog): def __init__(self, config): -- libgit2 0.21.2