Commit 30b43a7b7ef99f984f162869e0acef40777bbac8

Authored by Thiago Franco de Moraes
1 parent e6b20353
Exists in ffill_gui

Using combobox to set region growing method

Showing 1 changed file with 151 additions and 94 deletions   Show diff stats
invesalius/gui/dialogs.py
@@ -1906,6 +1906,82 @@ class Panel3DConnectivity(wx.Panel): @@ -1906,6 +1906,82 @@ class Panel3DConnectivity(wx.Panel):
1906 self.Layout() 1906 self.Layout()
1907 1907
1908 1908
  1909 +class PanelFFillThreshold(wx.Panel):
  1910 + def __init__(self, parent, config, ID=-1, style=wx.TAB_TRAVERSAL|wx.NO_BORDER):
  1911 + wx.Panel.__init__(self, parent, ID, style=style)
  1912 +
  1913 + self.config = config
  1914 +
  1915 + self._init_gui()
  1916 +
  1917 + def _init_gui(self):
  1918 + import project as prj
  1919 +
  1920 + project = prj.Project()
  1921 + bound_min, bound_max = project.threshold_range
  1922 + colour = [i*255 for i in const.MASK_COLOUR[0]]
  1923 + colour.append(100)
  1924 +
  1925 + self.threshold = grad.GradientCtrl(self, -1, int(bound_min),
  1926 + int(bound_max), self.config.t0,
  1927 + self.config.t1, colour)
  1928 +
  1929 + # sizer
  1930 + sizer = wx.BoxSizer(wx.VERTICAL)
  1931 + sizer.AddSpacer(5)
  1932 + sizer.Add(self.threshold, 0, wx.EXPAND|wx.LEFT|wx.RIGHT, 5)
  1933 + sizer.AddSpacer(5)
  1934 +
  1935 + self.SetSizer(sizer)
  1936 + sizer.Fit(self)
  1937 + self.Layout()
  1938 +
  1939 + self.Bind(grad.EVT_THRESHOLD_CHANGING, self.OnSlideChanged, self.threshold)
  1940 + self.Bind(grad.EVT_THRESHOLD_CHANGED, self.OnSlideChanged, self.threshold)
  1941 +
  1942 + def OnSlideChanged(self, evt):
  1943 + self.config.t0 = int(self.threshold.GetMinValue())
  1944 + self.config.t1 = int(self.threshold.GetMaxValue())
  1945 + print self.config.t0, self.config.t1
  1946 +
  1947 +
  1948 +class PanelFFillDynamic(wx.Panel):
  1949 + def __init__(self, parent, config, ID=-1, style=wx.TAB_TRAVERSAL|wx.NO_BORDER):
  1950 + wx.Panel.__init__(self, parent, ID, style=style)
  1951 +
  1952 + self.config = config
  1953 +
  1954 + self._init_gui()
  1955 +
  1956 + def _init_gui(self):
  1957 + self.use_ww_wl = wx.CheckBox(self, -1, _(u"Use WW\&WL"))
  1958 + self.use_ww_wl.SetValue(self.config.use_ww_wl)
  1959 +
  1960 + self.deviation_min = wx.SpinCtrl(self, -1, value='%d' % self.config.dev_min, min=0, max=10000)
  1961 + self.deviation_max = wx.SpinCtrl(self, -1, value='%d' % self.config.dev_max, min=0, max=10000)
  1962 +
  1963 + sizer = wx.BoxSizer(wx.VERTICAL)
  1964 +
  1965 + sizer.Add(self.use_ww_wl)
  1966 + sizer.Add(self.deviation_min)
  1967 + sizer.Add(self.deviation_max)
  1968 +
  1969 + self.SetSizer(sizer)
  1970 + sizer.Fit(self)
  1971 + self.Layout()
  1972 +
  1973 + self.use_ww_wl.Bind(wx.EVT_CHECKBOX, self.OnSetUseWWWL)
  1974 + self.deviation_min.Bind(wx.EVT_SPINCTRL, self.OnSetDeviation)
  1975 + self.deviation_max.Bind(wx.EVT_SPINCTRL, self.OnSetDeviation)
  1976 +
  1977 + def OnSetUseWWWL(self, evt):
  1978 + self.config.use_ww_wl = self.use_ww_wl.GetValue()
  1979 +
  1980 + def OnSetDeviation(self, evt):
  1981 + self.config.dev_max = self.deviation_max.GetValue()
  1982 + self.config.dev_min = self.deviation_min.GetValue()
  1983 +
  1984 +
1909 class FFillOptionsDialog(wx.Dialog): 1985 class FFillOptionsDialog(wx.Dialog):
1910 def __init__(self, title, config): 1986 def __init__(self, title, config):
1911 pre = wx.PreDialog() 1987 pre = wx.PreDialog()
@@ -1969,7 +2045,7 @@ class FFillOptionsDialog(wx.Dialog): @@ -1969,7 +2045,7 @@ class FFillOptionsDialog(wx.Dialog):
1969 sizer.AddSpacer(5) 2045 sizer.AddSpacer(5)
1970 sizer.Add(self.panel3dcon, flag=wx.LEFT|wx.RIGHT|wx.EXPAND, border=7) 2046 sizer.Add(self.panel3dcon, flag=wx.LEFT|wx.RIGHT|wx.EXPAND, border=7)
1971 sizer.AddSpacer(5) 2047 sizer.AddSpacer(5)
1972 - sizer.AddSizer(self.close_btn, 0, flag=wx.ALIGN_RIGHT|wx.RIGHT, border=7) 2048 + sizer.Add(self.close_btn, 0, flag=wx.ALIGN_RIGHT|wx.RIGHT, border=7)
1973 sizer.AddSpacer(5) 2049 sizer.AddSpacer(5)
1974 2050
1975 self.SetSizer(sizer) 2051 self.SetSizer(sizer)
@@ -2113,157 +2189,137 @@ class FFillSegmentationOptionsDialog(wx.Dialog): @@ -2113,157 +2189,137 @@ class FFillSegmentationOptionsDialog(wx.Dialog):
2113 Create the widgets. 2189 Create the widgets.
2114 """ 2190 """
2115 import project as prj 2191 import project as prj
  2192 +
2116 # Target 2193 # Target
2117 - self.target_2d = wx.RadioButton(self, -1, _(u"2D - Actual slice"), style=wx.RB_GROUP)  
2118 - self.target_3d = wx.RadioButton(self, -1, _(u"3D - All slices")) 2194 + if sys.platform == "win32":
  2195 + border_style = wx.SIMPLE_BORDER
  2196 + else:
  2197 + border_style = wx.SUNKEN_BORDER
  2198 +
  2199 + self.panel_target = PanelTargeFFill(self, style=border_style|wx.TAB_TRAVERSAL)
  2200 + self.panel2dcon = Panel2DConnectivity(self, style=border_style|wx.TAB_TRAVERSAL)
  2201 + self.panel3dcon = Panel3DConnectivity(self, style=border_style|wx.TAB_TRAVERSAL)
2119 2202
2120 if self.config.target == "2D": 2203 if self.config.target == "2D":
2121 - self.target_2d.SetValue(1) 2204 + self.panel_target.target_2d.SetValue(1)
  2205 + self.panel2dcon.Enable(1)
  2206 + self.panel3dcon.Enable(0)
2122 else: 2207 else:
2123 - self.target_3d.SetValue(1) 2208 + self.panel_target.target_3d.SetValue(1)
  2209 + self.panel3dcon.Enable(1)
  2210 + self.panel2dcon.Enable(0)
2124 2211
2125 # Connectivity 2D 2212 # Connectivity 2D
2126 - self.conect2D_4 = wx.RadioButton(self, -1, "4", style=wx.RB_GROUP)  
2127 - self.conect2D_8 = wx.RadioButton(self, -1, "8")  
2128 -  
2129 if self.config.con_2d == 8: 2213 if self.config.con_2d == 8:
2130 - self.conect2D_8.SetValue(1) 2214 + self.panel2dcon.conect2D_8.SetValue(1)
2131 else: 2215 else:
2132 - self.conect2D_4.SetValue(1) 2216 + self.panel2dcon.conect2D_4.SetValue(1)
2133 self.config.con_2d = 4 2217 self.config.con_2d = 4
2134 2218
2135 # Connectivity 3D 2219 # Connectivity 3D
2136 - self.conect3D_6 = wx.RadioButton(self, -1, "6", style=wx.RB_GROUP)  
2137 - self.conect3D_18 = wx.RadioButton(self, -1, "18")  
2138 - self.conect3D_26 = wx.RadioButton(self, -1, "26")  
2139 -  
2140 if self.config.con_3d == 18: 2220 if self.config.con_3d == 18:
2141 - self.conect3D_18.SetValue(1) 2221 + self.panel3dcon.conect3D_18.SetValue(1)
2142 elif self.config.con_3d == 26: 2222 elif self.config.con_3d == 26:
2143 - self.conect3D_26.SetValue(1) 2223 + self.panel3dcon.conect3D_26.SetValue(1)
2144 else: 2224 else:
2145 - self.conect3D_6.SetValue(1)  
2146 -  
2147 - project = prj.Project()  
2148 - bound_min, bound_max = project.threshold_range  
2149 - colour = [i*255 for i in const.MASK_COLOUR[0]]  
2150 - colour.append(100)  
2151 - self.threshold = grad.GradientCtrl(self, -1, int(bound_min),  
2152 - int(bound_max), self.config.t0,  
2153 - self.config.t1, colour)  
2154 - self.threshold.SetMinSize((250, -1)) 2225 + self.panel3dcon.conect3D_6.SetValue(1)
2155 2226
2156 - self.method_threshold = wx.RadioButton(self, -1, _(u"Threshold"), style=wx.RB_GROUP)  
2157 - self.method_dynamic = wx.RadioButton(self, -1, _(u"Dynamic")) 2227 + self.cmb_method = wx.ComboBox(self, -1, choices=(_(u"Threshold"), _(u"Dynamic")), style=wx.CB_READONLY)
2158 2228
2159 if self.config.method == 'dynamic': 2229 if self.config.method == 'dynamic':
2160 - self.method_dynamic.SetValue(1) 2230 + self.cmb_method.SetSelection(1)
2161 else: 2231 else:
2162 - self.method_threshold.SetValue(1) 2232 + self.cmb_method.SetSelection(0)
2163 self.config.method = 'threshold' 2233 self.config.method = 'threshold'
2164 2234
2165 - self.use_ww_wl = wx.CheckBox(self, -1, _(u"Use WW\&WL"))  
2166 - self.use_ww_wl.SetValue(self.config.use_ww_wl) 2235 + self.panel_ffill_threshold = PanelFFillThreshold(self, self.config, -1)
  2236 + self.panel_ffill_threshold.SetMinSize((300, -1))
  2237 + self.panel_ffill_threshold.Hide()
2167 2238
2168 - self.deviation_min = wx.SpinCtrl(self, -1, value='%d' % self.config.dev_min, min=0, max=10000)  
2169 - self.deviation_max = wx.SpinCtrl(self, -1, value='%d' % self.config.dev_max, min=0, max=10000) 2239 + self.panel_ffill_dynamic = PanelFFillDynamic(self, self.config, -1)
  2240 + self.panel_ffill_dynamic.SetMinSize((300, -1))
  2241 + self.panel_ffill_dynamic.Hide()
  2242 +
  2243 + self.close_btn = wx.Button(self, wx.ID_CLOSE)
2170 2244
2171 # Sizer 2245 # Sizer
2172 sizer = wx.BoxSizer(wx.VERTICAL) 2246 sizer = wx.BoxSizer(wx.VERTICAL)
2173 2247
2174 - sizer.AddSpacer(7)  
2175 -  
2176 - sizer.Add(wx.StaticText(self, -1, _(u"Parameters")), flag=wx.LEFT, border=7)  
2177 sizer.AddSpacer(5) 2248 sizer.AddSpacer(5)
2178 - sizer.Add(self.target_2d, flag=wx.LEFT, border=9)  
2179 - sizer.Add(self.target_3d, flag=wx.LEFT, border=9)  
2180 -  
2181 - sizer.AddSpacer(7)  
2182 -  
2183 - sizer.Add(wx.StaticText(self, -1, _(u"2D Connectivity")), flag=wx.LEFT, border=9) 2249 + sizer.Add(wx.StaticText(self, -1, _(u"Parameters")), flag=wx.LEFT, border=5)
2184 sizer.AddSpacer(5) 2250 sizer.AddSpacer(5)
2185 - sizer_2d = wx.BoxSizer(wx.HORIZONTAL)  
2186 - sizer_2d.Add(self.conect2D_4, flag=wx.LEFT, border=11)  
2187 - sizer_2d.Add(self.conect2D_8, flag=wx.LEFT, border=11)  
2188 - sizer.Add(sizer_2d)  
2189 -  
2190 - sizer.AddSpacer(7)  
2191 -  
2192 - sizer.Add(wx.StaticText(self, -1, _(u"3D Connectivity")), flag=wx.LEFT, border=9) 2251 + sizer.Add(self.panel_target, flag=wx.LEFT|wx.RIGHT|wx.EXPAND, border=7)
2193 sizer.AddSpacer(5) 2252 sizer.AddSpacer(5)
2194 - sizer_3d = wx.BoxSizer(wx.HORIZONTAL)  
2195 - sizer_3d.Add(self.conect3D_6, flag=wx.LEFT, border=11)  
2196 - sizer_3d.Add(self.conect3D_18, flag=wx.LEFT, border=11)  
2197 - sizer_3d.Add(self.conect3D_26, flag=wx.LEFT, border=11)  
2198 - sizer.Add(sizer_3d)  
2199 -  
2200 - sizer.AddSpacer(7)  
2201 -  
2202 - sizer.Add(wx.StaticText(self, -1, _(u"Method")), flag=wx.LEFT, border=9) 2253 + sizer.Add(self.panel2dcon, flag=wx.LEFT|wx.RIGHT|wx.EXPAND, border=7)
2203 sizer.AddSpacer(5) 2254 sizer.AddSpacer(5)
2204 - sizer.Add(self.method_threshold, flag=wx.LEFT, border=11) 2255 + sizer.Add(self.panel3dcon, flag=wx.LEFT|wx.RIGHT|wx.EXPAND, border=7)
2205 sizer.AddSpacer(5) 2256 sizer.AddSpacer(5)
2206 - sizer.Add(self.threshold, flag=wx.LEFT|wx.RIGHT|wx.EXPAND, border=13) 2257 +
  2258 + sizer.Add(wx.StaticText(self, -1, _(u"Method")), flag=wx.LEFT, border=9)
2207 sizer.AddSpacer(5) 2259 sizer.AddSpacer(5)
2208 - sizer.Add(self.method_dynamic, flag=wx.LEFT, border=11) 2260 + sizer.Add(self.cmb_method, flag=wx.LEFT|wx.RIGHT|wx.EXPAND, border=7)
  2261 +
  2262 + if self.config.method == 'dynamic':
  2263 + self.cmb_method.SetSelection(1)
  2264 + self.panel_ffill_dynamic.Show()
  2265 + sizer.Add(self.panel_ffill_dynamic, flag=wx.LEFT, border=11)
  2266 + else:
  2267 + self.cmb_method.SetSelection(0)
  2268 + self.panel_ffill_threshold.Show()
  2269 + sizer.Add(self.panel_ffill_threshold, flag=wx.LEFT, border=11)
  2270 + self.config.method = 'threshold'
  2271 +
2209 sizer.AddSpacer(5) 2272 sizer.AddSpacer(5)
2210 - sizer.Add(self.use_ww_wl, flag=wx.LEFT, border=13) 2273 + sizer.Add(self.close_btn, 0, flag=wx.ALIGN_RIGHT|wx.RIGHT, border=5)
2211 sizer.AddSpacer(5) 2274 sizer.AddSpacer(5)
2212 - sizer.Add(self.deviation_min, flag=wx.LEFT, border=13)  
2213 - sizer.Add(self.deviation_max, flag=wx.LEFT, border=13)  
2214 -  
2215 - sizer.AddSpacer(7)  
2216 2275
2217 self.SetSizer(sizer) 2276 self.SetSizer(sizer)
2218 sizer.Fit(self) 2277 sizer.Fit(self)
2219 self.Layout() 2278 self.Layout()
2220 2279
2221 self.Bind(wx.EVT_RADIOBUTTON, self.OnSetRadio) 2280 self.Bind(wx.EVT_RADIOBUTTON, self.OnSetRadio)
2222 - self.Bind(grad.EVT_THRESHOLD_CHANGING, self.OnSlideChanged, self.threshold)  
2223 - self.Bind(grad.EVT_THRESHOLD_CHANGED, self.OnSlideChanged, self.threshold)  
2224 - self.use_ww_wl.Bind(wx.EVT_CHECKBOX, self.OnSetUseWWWL)  
2225 - self.deviation_min.Bind(wx.EVT_SPINCTRL, self.OnSetDeviation)  
2226 - self.deviation_max.Bind(wx.EVT_SPINCTRL, self.OnSetDeviation) 2281 + self.cmb_method.Bind(wx.EVT_COMBOBOX, self.OnSetMethod)
2227 self.Bind(wx.EVT_CLOSE, self.OnClose) 2282 self.Bind(wx.EVT_CLOSE, self.OnClose)
2228 2283
2229 def OnSetRadio(self, evt): 2284 def OnSetRadio(self, evt):
2230 # Target 2285 # Target
2231 - if self.target_2d.GetValue(): 2286 + if self.panel_target.target_2d.GetValue():
2232 self.config.target = "2D" 2287 self.config.target = "2D"
  2288 + self.panel2dcon.Enable(1)
  2289 + self.panel3dcon.Enable(0)
2233 else: 2290 else:
2234 self.config.target = "3D" 2291 self.config.target = "3D"
  2292 + self.panel3dcon.Enable(1)
  2293 + self.panel2dcon.Enable(0)
2235 2294
2236 # 2D 2295 # 2D
2237 - if self.conect2D_4.GetValue(): 2296 + if self.panel2dcon.conect2D_4.GetValue():
2238 self.config.con_2d = 4 2297 self.config.con_2d = 4
2239 - elif self.conect2D_8.GetValue(): 2298 + elif self.panel2dcon.conect2D_8.GetValue():
2240 self.config.con_2d = 8 2299 self.config.con_2d = 8
2241 2300
2242 # 3D 2301 # 3D
2243 - if self.conect3D_6.GetValue(): 2302 + if self.panel3dcon.conect3D_6.GetValue():
2244 self.config.con_3d = 6 2303 self.config.con_3d = 6
2245 - elif self.conect3D_18.GetValue(): 2304 + elif self.panel3dcon.conect3D_18.GetValue():
2246 self.config.con_3d = 18 2305 self.config.con_3d = 18
2247 - elif self.conect3D_26.GetValue(): 2306 + elif self.panel3dcon.conect3D_26.GetValue():
2248 self.config.con_3d = 26 2307 self.config.con_3d = 26
2249 2308
2250 - # Method  
2251 - if self.method_threshold.GetValue():  
2252 - self.config.method = 'threshold'  
2253 - else: 2309 + def OnSetMethod(self, evt):
  2310 + if self.cmb_method.GetSelection() == 1:
2254 self.config.method = 'dynamic' 2311 self.config.method = 'dynamic'
  2312 + self.panel_ffill_threshold.Hide()
  2313 + self.panel_ffill_dynamic.Show()
  2314 + self.GetSizer().Replace(self.panel_ffill_threshold, self.panel_ffill_dynamic)
  2315 + else:
  2316 + self.config.method = 'threshold'
  2317 + self.panel_ffill_dynamic.Hide()
  2318 + self.panel_ffill_threshold.Show()
  2319 + self.GetSizer().Replace(self.panel_ffill_dynamic, self.panel_ffill_threshold)
2255 2320
2256 - def OnSlideChanged(self, evt):  
2257 - self.config.t0 = int(self.threshold.GetMinValue())  
2258 - self.config.t1 = int(self.threshold.GetMaxValue())  
2259 - print self.config.t0, self.config.t1  
2260 -  
2261 - def OnSetUseWWWL(self, evt):  
2262 - self.config.use_ww_wl = self.use_ww_wl.GetValue()  
2263 -  
2264 - def OnSetDeviation(self, evt):  
2265 - self.config.dev_max = self.deviation_max.GetValue()  
2266 - self.config.dev_min = self.deviation_min.GetValue() 2321 + self.GetSizer().Fit(self)
  2322 + self.Layout()
2267 2323
2268 def OnClose(self, evt): 2324 def OnClose(self, evt):
2269 if self.config.dlg_visible: 2325 if self.config.dlg_visible:
@@ -2271,6 +2327,7 @@ class FFillSegmentationOptionsDialog(wx.Dialog): @@ -2271,6 +2327,7 @@ class FFillSegmentationOptionsDialog(wx.Dialog):
2271 evt.Skip() 2327 evt.Skip()
2272 self.Destroy() 2328 self.Destroy()
2273 2329
  2330 +
2274 class CropOptionsDialog(wx.Dialog): 2331 class CropOptionsDialog(wx.Dialog):
2275 2332
2276 def __init__(self, config): 2333 def __init__(self, config):