Commit cbf7bc24d86915c573724ab462fb06f05c365c22
Committed by
GitHub
1 parent
56415f0e
Exists in
master
Adds possibility of user digits the angles when reorienting an image. (#111)
* Setting angles in gui * If user digits a non-number it backup to the last digited number
Showing
2 changed files
with
52 additions
and
6 deletions
Show diff stats
invesalius/data/styles.py
... | ... | @@ -1500,6 +1500,9 @@ class ReorientImageInteractorStyle(DefaultInteractorStyle): |
1500 | 1500 | self.AddObserver("MouseMoveEvent", self.OnMouseMove) |
1501 | 1501 | self.viewer.slice_data.renderer.AddObserver("StartEvent", self.OnUpdate) |
1502 | 1502 | |
1503 | + if self.viewer.orientation == 'AXIAL': | |
1504 | + Publisher.subscribe(self._set_reorientation_angles, 'Set reorientation angles') | |
1505 | + | |
1503 | 1506 | self.viewer.interactor.Bind(wx.EVT_LEFT_DCLICK, self.OnDblClick) |
1504 | 1507 | |
1505 | 1508 | def SetUp(self): |
... | ... | @@ -1670,6 +1673,15 @@ class ReorientImageInteractorStyle(DefaultInteractorStyle): |
1670 | 1673 | # print (z, y, x), tcoord |
1671 | 1674 | return tcoord |
1672 | 1675 | |
1676 | + def _set_reorientation_angles(self, pubsub_evt): | |
1677 | + ax, ay, az = pubsub_evt.data | |
1678 | + q = transformations.quaternion_from_euler(az, ay, ax) | |
1679 | + self.viewer.slice_.q_orientation = q | |
1680 | + | |
1681 | + self._discard_buffers() | |
1682 | + self.viewer.slice_.current_mask.clear_history() | |
1683 | + Publisher.sendMessage('Reload actual slice') | |
1684 | + | |
1673 | 1685 | def _create_line(self, x0, y0, x1, y1, color): |
1674 | 1686 | line = vtk.vtkLineSource() |
1675 | 1687 | line.SetPoint1(x0, y0, 0) | ... | ... |
invesalius/gui/dialogs.py
... | ... | @@ -1870,6 +1870,12 @@ class ReorientImageDialog(wx.Dialog): |
1870 | 1870 | pre.Create(wx.GetApp().GetTopWindow(), -1, _(u'Image reorientation'), style=wx.DEFAULT_DIALOG_STYLE|wx.FRAME_FLOAT_ON_PARENT) |
1871 | 1871 | self.PostCreate(pre) |
1872 | 1872 | |
1873 | + self._closed = False | |
1874 | + | |
1875 | + self._last_ax = "0.0" | |
1876 | + self._last_ay = "0.0" | |
1877 | + self._last_az = "0.0" | |
1878 | + | |
1873 | 1879 | self._init_gui() |
1874 | 1880 | self._bind_events() |
1875 | 1881 | self._bind_events_wx() |
... | ... | @@ -1884,9 +1890,9 @@ class ReorientImageDialog(wx.Dialog): |
1884 | 1890 | self.interp_method.Append(txt, im_code) |
1885 | 1891 | self.interp_method.SetValue(interp_methods_choices[2][0]) |
1886 | 1892 | |
1887 | - self.anglex = wx.TextCtrl(self, -1, "0.0", style=wx.TE_READONLY) | |
1888 | - self.angley = wx.TextCtrl(self, -1, "0.0", style=wx.TE_READONLY) | |
1889 | - self.anglez = wx.TextCtrl(self, -1, "0.0", style=wx.TE_READONLY) | |
1893 | + self.anglex = wx.TextCtrl(self, -1, "0.0") | |
1894 | + self.angley = wx.TextCtrl(self, -1, "0.0") | |
1895 | + self.anglez = wx.TextCtrl(self, -1, "0.0") | |
1890 | 1896 | |
1891 | 1897 | self.btnapply = wx.Button(self, -1, _("Apply")) |
1892 | 1898 | |
... | ... | @@ -1919,14 +1925,23 @@ class ReorientImageDialog(wx.Dialog): |
1919 | 1925 | |
1920 | 1926 | def _bind_events_wx(self): |
1921 | 1927 | self.interp_method.Bind(wx.EVT_COMBOBOX, self.OnSelect) |
1928 | + | |
1929 | + self.anglex.Bind(wx.EVT_KILL_FOCUS, self.OnLostFocus) | |
1930 | + self.angley.Bind(wx.EVT_KILL_FOCUS, self.OnLostFocus) | |
1931 | + self.anglez.Bind(wx.EVT_KILL_FOCUS, self.OnLostFocus) | |
1932 | + | |
1933 | + self.anglex.Bind(wx.EVT_SET_FOCUS, self.OnSetFocus) | |
1934 | + self.angley.Bind(wx.EVT_SET_FOCUS, self.OnSetFocus) | |
1935 | + self.anglez.Bind(wx.EVT_SET_FOCUS, self.OnSetFocus) | |
1936 | + | |
1922 | 1937 | self.btnapply.Bind(wx.EVT_BUTTON, self.apply_reorientation) |
1923 | 1938 | self.Bind(wx.EVT_CLOSE, self.OnClose) |
1924 | 1939 | |
1925 | 1940 | def _update_angles(self, pubsub_evt): |
1926 | 1941 | anglex, angley, anglez = pubsub_evt.data |
1927 | - self.anglex.SetValue("%.2f" % np.rad2deg(anglex)) | |
1928 | - self.angley.SetValue("%.2f" % np.rad2deg(angley)) | |
1929 | - self.anglez.SetValue("%.2f" % np.rad2deg(anglez)) | |
1942 | + self.anglex.SetValue("%.3f" % np.rad2deg(anglex)) | |
1943 | + self.angley.SetValue("%.3f" % np.rad2deg(angley)) | |
1944 | + self.anglez.SetValue("%.3f" % np.rad2deg(anglez)) | |
1930 | 1945 | |
1931 | 1946 | def _close_dialog(self, pubsub_evt): |
1932 | 1947 | self.Destroy() |
... | ... | @@ -1936,6 +1951,7 @@ class ReorientImageDialog(wx.Dialog): |
1936 | 1951 | self.Close() |
1937 | 1952 | |
1938 | 1953 | def OnClose(self, evt): |
1954 | + self._closed = True | |
1939 | 1955 | Publisher.sendMessage('Disable style', const.SLICE_STATE_REORIENT) |
1940 | 1956 | Publisher.sendMessage('Enable style', const.STATE_DEFAULT) |
1941 | 1957 | self.Destroy() |
... | ... | @@ -1944,6 +1960,24 @@ class ReorientImageDialog(wx.Dialog): |
1944 | 1960 | im_code = self.interp_method.GetClientData(self.interp_method.GetSelection()) |
1945 | 1961 | Publisher.sendMessage('Set interpolation method', im_code) |
1946 | 1962 | |
1963 | + def OnSetFocus(self, evt): | |
1964 | + self._last_ax = self.anglex.GetValue() | |
1965 | + self._last_ay = self.angley.GetValue() | |
1966 | + self._last_az = self.anglez.GetValue() | |
1967 | + | |
1968 | + def OnLostFocus(self, evt): | |
1969 | + if not self._closed: | |
1970 | + try: | |
1971 | + ax = np.deg2rad(float(self.anglex.GetValue())) | |
1972 | + ay = np.deg2rad(float(self.angley.GetValue())) | |
1973 | + az = np.deg2rad(float(self.anglez.GetValue())) | |
1974 | + except ValueError: | |
1975 | + self.anglex.SetValue(self._last_ax) | |
1976 | + self.angley.SetValue(self._last_ay) | |
1977 | + self.anglez.SetValue(self._last_az) | |
1978 | + return | |
1979 | + Publisher.sendMessage('Set reorientation angles', (ax, ay, az)) | |
1980 | + | |
1947 | 1981 | |
1948 | 1982 | class ImportBitmapParameters(wx.Dialog): |
1949 | 1983 | from os import sys | ... | ... |