Commit c0e808289f3898a6191aa43da52781a5b5477cb4
1 parent
61ecc054
Exists in
ff_mask
Showing a dialog interface
Showing
2 changed files
with
68 additions
and
8 deletions
Show diff stats
invesalius/data/styles.py
| ... | ... | @@ -40,6 +40,7 @@ from scipy.ndimage import watershed_ift, generate_binary_structure |
| 40 | 40 | from skimage.morphology import watershed |
| 41 | 41 | from skimage import filter |
| 42 | 42 | |
| 43 | +from gui import dialogs | |
| 43 | 44 | from .measures import MeasureData |
| 44 | 45 | |
| 45 | 46 | from . import floodfill |
| ... | ... | @@ -1750,7 +1751,15 @@ class ReorientImageInteractorStyle(DefaultInteractorStyle): |
| 1750 | 1751 | buffer_.discard_image() |
| 1751 | 1752 | |
| 1752 | 1753 | |
| 1753 | -class FlooFillMaskInteractorStyle(DefaultInteractorStyle): | |
| 1754 | +class FFillConfig(object): | |
| 1755 | + __metaclass__= utils.Singleton | |
| 1756 | + def __init__(self): | |
| 1757 | + self.dlg_visible = False | |
| 1758 | + self.target = "2D" | |
| 1759 | + | |
| 1760 | + | |
| 1761 | +class FloodFillMaskInteractorStyle(DefaultInteractorStyle): | |
| 1762 | + dialog = None | |
| 1754 | 1763 | def __init__(self, viewer): |
| 1755 | 1764 | DefaultInteractorStyle.__init__(self, viewer) |
| 1756 | 1765 | |
| ... | ... | @@ -1761,6 +1770,13 @@ class FlooFillMaskInteractorStyle(DefaultInteractorStyle): |
| 1761 | 1770 | self.slice_actor = viewer.slice_data.actor |
| 1762 | 1771 | self.slice_data = viewer.slice_data |
| 1763 | 1772 | |
| 1773 | + self.config = FFillConfig() | |
| 1774 | + | |
| 1775 | + if not self.config.dlg_visible: | |
| 1776 | + self.config.dlg_visible = True | |
| 1777 | + dlg_ffill = dialogs.FFillOptionsDialog(self.config) | |
| 1778 | + dlg_ffill.Show() | |
| 1779 | + | |
| 1764 | 1780 | self.viewer.slice_.do_threshold_to_all_slices() |
| 1765 | 1781 | |
| 1766 | 1782 | self.AddObserver("LeftButtonPressEvent", self.OnFFClick) |
| ... | ... | @@ -1793,7 +1809,7 @@ class FlooFillMaskInteractorStyle(DefaultInteractorStyle): |
| 1793 | 1809 | cp_mask = mask.copy() |
| 1794 | 1810 | |
| 1795 | 1811 | from_3d = True |
| 1796 | - if from_3d: | |
| 1812 | + if self.config.target == "3D": | |
| 1797 | 1813 | neighbor_iter = ((-1, 0, 0), |
| 1798 | 1814 | (1, 0, 0), |
| 1799 | 1815 | (0, -1, 0), |
| ... | ... | @@ -1806,11 +1822,11 @@ class FlooFillMaskInteractorStyle(DefaultInteractorStyle): |
| 1806 | 1822 | (0, -1, 0), |
| 1807 | 1823 | (0, 1, 0)) |
| 1808 | 1824 | |
| 1809 | - neighbor_iter = [] | |
| 1810 | - for i in xrange(-1, 2): | |
| 1811 | - for j in xrange(-1, 2): | |
| 1812 | - for k in xrange(-1, 2): | |
| 1813 | - neighbor_iter.append((i, j, k)) | |
| 1825 | + # neighbor_iter = [] | |
| 1826 | + # for i in xrange(-1, 2): | |
| 1827 | + # for j in xrange(-1, 2): | |
| 1828 | + # for k in xrange(-1, 2): | |
| 1829 | + # neighbor_iter.append((i, j, k)) | |
| 1814 | 1830 | |
| 1815 | 1831 | if iren.GetControlKey(): |
| 1816 | 1832 | t0 = 254 |
| ... | ... | @@ -1887,7 +1903,7 @@ def get_style(style): |
| 1887 | 1903 | const.SLICE_STATE_EDITOR: EditorInteractorStyle, |
| 1888 | 1904 | const.SLICE_STATE_WATERSHED: WaterShedInteractorStyle, |
| 1889 | 1905 | const.SLICE_STATE_REORIENT: ReorientImageInteractorStyle, |
| 1890 | - const.SLICE_STATE_MASK_FFILL: FlooFillMaskInteractorStyle, | |
| 1906 | + const.SLICE_STATE_MASK_FFILL: FloodFillMaskInteractorStyle, | |
| 1891 | 1907 | } |
| 1892 | 1908 | return STYLES[style] |
| 1893 | 1909 | ... | ... |
invesalius/gui/dialogs.py
| ... | ... | @@ -1838,3 +1838,47 @@ def BitmapNotSameSize(): |
| 1838 | 1838 | |
| 1839 | 1839 | dlg.ShowModal() |
| 1840 | 1840 | dlg.Destroy() |
| 1841 | + | |
| 1842 | + | |
| 1843 | +class FFillOptionsDialog(wx.Dialog): | |
| 1844 | + def __init__(self, config): | |
| 1845 | + pre = wx.PreDialog() | |
| 1846 | + pre.Create(wx.GetApp().GetTopWindow(), -1, _(u'Floodfill'), style=wx.DEFAULT_DIALOG_STYLE|wx.FRAME_FLOAT_ON_PARENT) | |
| 1847 | + self.PostCreate(pre) | |
| 1848 | + | |
| 1849 | + self.config = config | |
| 1850 | + | |
| 1851 | + self._init_gui() | |
| 1852 | + | |
| 1853 | + def _init_gui(self): | |
| 1854 | + sizer = wx.GridBagSizer(3, 1) | |
| 1855 | + | |
| 1856 | + flag_labels = wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL | |
| 1857 | + | |
| 1858 | + self.target = wx.RadioBox(self, -1, _(u"Target"), | |
| 1859 | + choices=[_(u"Slice"), _(u"Volume")], | |
| 1860 | + style=wx.NO_BORDER | wx.HORIZONTAL) | |
| 1861 | + | |
| 1862 | + if self.config.target == "2D": | |
| 1863 | + self.target.SetSelection(0) | |
| 1864 | + else: | |
| 1865 | + self.target.SetSelection(1) | |
| 1866 | + | |
| 1867 | + sizer.Add(self.target, (0, 0)) | |
| 1868 | + | |
| 1869 | + self.SetSizer(sizer) | |
| 1870 | + sizer.Fit(self) | |
| 1871 | + self.Layout() | |
| 1872 | + | |
| 1873 | + self.target.Bind(wx.EVT_RADIOBOX, self.OnSetTarget) | |
| 1874 | + self.Bind(wx.EVT_CLOSE, self.OnClose) | |
| 1875 | + | |
| 1876 | + def OnSetTarget(self, evt): | |
| 1877 | + if self.target.GetSelection() == 0: | |
| 1878 | + self.config.target = "2D" | |
| 1879 | + else: | |
| 1880 | + self.config.target = "3D" | |
| 1881 | + | |
| 1882 | + def OnClose(self, evt): | |
| 1883 | + self.config.dlg_visible = False | |
| 1884 | + evt.Skip() | ... | ... |