Commit 7af56b45db5070adf8c4aa291bd447d56b2ac021
1 parent
d30ecf1a
Exists in
master
and in
38 other branches
Ctrl-scroll changing watershed brush size
Showing
2 changed files
with
32 additions
and
16 deletions
Show diff stats
invesalius/data/styles.py
| ... | ... | @@ -948,33 +948,41 @@ class WaterShedInteractorStyle(DefaultInteractorStyle): |
| 948 | 948 | self.viewer.interactor.Render() |
| 949 | 949 | |
| 950 | 950 | def WOnScrollBackward(self, obj, evt): |
| 951 | + iren = self.viewer.interactor | |
| 951 | 952 | viewer = self.viewer |
| 952 | - iren = viewer.interactor | |
| 953 | 953 | if iren.GetControlKey(): |
| 954 | - if viewer.slice_.opacity > 0: | |
| 955 | - viewer.slice_.opacity -= 0.1 | |
| 956 | - self.viewer.slice_.buffer_slices['AXIAL'].discard_vtk_mask() | |
| 957 | - self.viewer.slice_.buffer_slices['CORONAL'].discard_vtk_mask() | |
| 958 | - self.viewer.slice_.buffer_slices['SAGITAL'].discard_vtk_mask() | |
| 959 | - viewer.OnScrollBar() | |
| 954 | + mouse_x, mouse_y = iren.GetEventPosition() | |
| 955 | + render = iren.FindPokedRenderer(mouse_x, mouse_y) | |
| 956 | + slice_data = self.viewer.get_slice_data(render) | |
| 957 | + cursor = slice_data.cursor | |
| 958 | + size = cursor.radius * 2 | |
| 959 | + size -= 1 | |
| 960 | + | |
| 961 | + if size > 0: | |
| 962 | + Publisher.sendMessage('Set watershed brush size', size) | |
| 963 | + cursor.SetPosition(cursor.position) | |
| 964 | + self.viewer.interactor.Render() | |
| 960 | 965 | else: |
| 961 | 966 | self.OnScrollBackward(obj, evt) |
| 962 | 967 | |
| 963 | - | |
| 964 | 968 | def WOnScrollForward(self, obj, evt): |
| 969 | + iren = self.viewer.interactor | |
| 965 | 970 | viewer = self.viewer |
| 966 | - iren = viewer.interactor | |
| 967 | 971 | if iren.GetControlKey(): |
| 968 | - if viewer.slice_.opacity < 1: | |
| 969 | - viewer.slice_.opacity += 0.1 | |
| 970 | - self.viewer.slice_.buffer_slices['AXIAL'].discard_vtk_mask() | |
| 971 | - self.viewer.slice_.buffer_slices['CORONAL'].discard_vtk_mask() | |
| 972 | - self.viewer.slice_.buffer_slices['SAGITAL'].discard_vtk_mask() | |
| 973 | - viewer.OnScrollBar() | |
| 972 | + mouse_x, mouse_y = iren.GetEventPosition() | |
| 973 | + render = iren.FindPokedRenderer(mouse_x, mouse_y) | |
| 974 | + slice_data = self.viewer.get_slice_data(render) | |
| 975 | + cursor = slice_data.cursor | |
| 976 | + size = cursor.radius * 2 | |
| 977 | + size += 1 | |
| 978 | + | |
| 979 | + if size <= 100: | |
| 980 | + Publisher.sendMessage('Set watershed brush size', size) | |
| 981 | + cursor.SetPosition(cursor.position) | |
| 982 | + self.viewer.interactor.Render() | |
| 974 | 983 | else: |
| 975 | 984 | self.OnScrollForward(obj, evt) |
| 976 | 985 | |
| 977 | - | |
| 978 | 986 | def OnBrushClick(self, obj, evt): |
| 979 | 987 | if (self.viewer.slice_.buffer_slices[self.orientation].mask is None): |
| 980 | 988 | return | ... | ... |
invesalius/gui/task_slice.py
| ... | ... | @@ -902,6 +902,7 @@ class WatershedTool(EditionTools): |
| 902 | 902 | self.SetAutoLayout(1) |
| 903 | 903 | |
| 904 | 904 | self.__bind_events_wx() |
| 905 | + self.__bind_pubsub_evt() | |
| 905 | 906 | |
| 906 | 907 | |
| 907 | 908 | def __bind_events_wx(self): |
| ... | ... | @@ -912,6 +913,9 @@ class WatershedTool(EditionTools): |
| 912 | 913 | self.btn_exp_watershed.Bind(wx.EVT_BUTTON, self.OnExpandWatershed) |
| 913 | 914 | self.btn_wconfig.Bind(wx.EVT_BUTTON, self.OnConfig) |
| 914 | 915 | |
| 916 | + def __bind_pubsub_evt(self): | |
| 917 | + Publisher.subscribe(self._set_brush_size, 'Set watershed brush size') | |
| 918 | + | |
| 915 | 919 | def ChangeMaskColour(self, pubsub_evt): |
| 916 | 920 | colour = pubsub_evt.data |
| 917 | 921 | self.gradient_thresh.SetColour(colour) |
| ... | ... | @@ -956,6 +960,10 @@ class WatershedTool(EditionTools): |
| 956 | 960 | # Strangelly this is being called twice |
| 957 | 961 | Publisher.sendMessage('Set watershed brush size',self.spin.GetValue()) |
| 958 | 962 | |
| 963 | + def _set_brush_size(self, pubsub_evt): | |
| 964 | + size = pubsub_evt.data | |
| 965 | + self.spin.SetValue(size) | |
| 966 | + | |
| 959 | 967 | def OnComboBrushOp(self, evt): |
| 960 | 968 | brush_op = self.combo_brush_op.GetValue() |
| 961 | 969 | Publisher.sendMessage('Set watershed operation', brush_op) | ... | ... |