Commit 0fb929271d5ae19435319d35ba7ab543e723c13b
1 parent
0474cbd4
Exists in
master
and in
46 other branches
Increasing and decreasing the cursor size with the mouse scroll
Showing
3 changed files
with
41 additions
and
0 deletions
Show diff stats
invesalius/constants.py
| @@ -258,6 +258,7 @@ BRUSH_OP_NAME = [_("Draw"), _("Erase"), _("Threshold")] | @@ -258,6 +258,7 @@ BRUSH_OP_NAME = [_("Draw"), _("Erase"), _("Threshold")] | ||
| 258 | 258 | ||
| 259 | BRUSH_COLOUR = (0,0,1.0) | 259 | BRUSH_COLOUR = (0,0,1.0) |
| 260 | BRUSH_SIZE = 30 | 260 | BRUSH_SIZE = 30 |
| 261 | +BRUSH_MAX_SIZE = 100 | ||
| 261 | 262 | ||
| 262 | # Surface creation values. Each element's list contains: | 263 | # Surface creation values. Each element's list contains: |
| 263 | # 0: imagedata reformat ratio | 264 | # 0: imagedata reformat ratio |
invesalius/data/cursor_actors.py
| @@ -78,6 +78,7 @@ class CursorBase(object): | @@ -78,6 +78,7 @@ class CursorBase(object): | ||
| 78 | self.size = 15.0 | 78 | self.size = 15.0 |
| 79 | self.orientation = "AXIAL" | 79 | self.orientation = "AXIAL" |
| 80 | self.spacing = (1, 1, 1) | 80 | self.spacing = (1, 1, 1) |
| 81 | + self.position = (0, 0, 0) | ||
| 81 | if vtk.vtkVersion().GetVTKVersion() > '5.8.0': | 82 | if vtk.vtkVersion().GetVTKVersion() > '5.8.0': |
| 82 | self.mapper = vtk.vtkImageSliceMapper() | 83 | self.mapper = vtk.vtkImageSliceMapper() |
| 83 | cursor_property = vtk.vtkImageProperty() | 84 | cursor_property = vtk.vtkImageProperty() |
| @@ -108,6 +109,7 @@ class CursorBase(object): | @@ -108,6 +109,7 @@ class CursorBase(object): | ||
| 108 | def SetPosition(self, position): | 109 | def SetPosition(self, position): |
| 109 | # Overriding SetPosition method because in rectangles with odd | 110 | # Overriding SetPosition method because in rectangles with odd |
| 110 | # dimensions there is no half position. | 111 | # dimensions there is no half position. |
| 112 | + self.position = position | ||
| 111 | px, py, pz = position | 113 | px, py, pz = position |
| 112 | sx, sy, sz = self.spacing | 114 | sx, sy, sz = self.spacing |
| 113 | tx = self.actor.GetXRange()[1] - self.actor.GetXRange()[0] | 115 | tx = self.actor.GetXRange()[1] - self.actor.GetXRange()[0] |
invesalius/data/styles.py
| @@ -540,6 +540,11 @@ class EditorInteractorStyle(DefaultInteractorStyle): | @@ -540,6 +540,11 @@ class EditorInteractorStyle(DefaultInteractorStyle): | ||
| 540 | self.AddObserver("LeftButtonReleaseEvent", self.OnBrushRelease) | 540 | self.AddObserver("LeftButtonReleaseEvent", self.OnBrushRelease) |
| 541 | self.AddObserver("MouseMoveEvent", self.OnBrushMove) | 541 | self.AddObserver("MouseMoveEvent", self.OnBrushMove) |
| 542 | 542 | ||
| 543 | + self.RemoveObservers("MouseWheelForwardEvent") | ||
| 544 | + self.RemoveObservers("MouseWheelBackwardEvent") | ||
| 545 | + self.AddObserver("MouseWheelForwardEvent",self.EOnScrollForward) | ||
| 546 | + self.AddObserver("MouseWheelBackwardEvent", self.EOnScrollBackward) | ||
| 547 | + | ||
| 543 | def OnEnterInteractor(self, obj, evt): | 548 | def OnEnterInteractor(self, obj, evt): |
| 544 | if (self.viewer.slice_.buffer_slices[self.orientation].mask is None): | 549 | if (self.viewer.slice_.buffer_slices[self.orientation].mask is None): |
| 545 | return | 550 | return |
| @@ -683,6 +688,39 @@ class EditorInteractorStyle(DefaultInteractorStyle): | @@ -683,6 +688,39 @@ class EditorInteractorStyle(DefaultInteractorStyle): | ||
| 683 | self.viewer.slice_.apply_slice_buffer_to_mask(self.orientation) | 688 | self.viewer.slice_.apply_slice_buffer_to_mask(self.orientation) |
| 684 | self.viewer._flush_buffer = False | 689 | self.viewer._flush_buffer = False |
| 685 | 690 | ||
| 691 | + def EOnScrollForward(self, evt, obj): | ||
| 692 | + iren = self.viewer.interactor | ||
| 693 | + if iren.GetControlKey(): | ||
| 694 | + mouse_x, mouse_y = iren.GetEventPosition() | ||
| 695 | + render = iren.FindPokedRenderer(mouse_x, mouse_y) | ||
| 696 | + slice_data = self.viewer.get_slice_data(render) | ||
| 697 | + cursor = slice_data.cursor | ||
| 698 | + size = cursor.radius * 2 | ||
| 699 | + | ||
| 700 | + if size < 100: | ||
| 701 | + Publisher.sendMessage('Set edition brush size', size + 1) | ||
| 702 | + cursor.SetPosition(cursor.position) | ||
| 703 | + self.viewer.interactor.Render() | ||
| 704 | + | ||
| 705 | + else: | ||
| 706 | + self.OnScrollForward(obj, evt) | ||
| 707 | + | ||
| 708 | + def EOnScrollBackward(self, evt, obj): | ||
| 709 | + iren = self.viewer.interactor | ||
| 710 | + if iren.GetControlKey(): | ||
| 711 | + mouse_x, mouse_y = iren.GetEventPosition() | ||
| 712 | + render = iren.FindPokedRenderer(mouse_x, mouse_y) | ||
| 713 | + slice_data = self.viewer.get_slice_data(render) | ||
| 714 | + cursor = slice_data.cursor | ||
| 715 | + size = cursor.radius * 2 | ||
| 716 | + | ||
| 717 | + if size > 0: | ||
| 718 | + Publisher.sendMessage('Set edition brush size', size - 1) | ||
| 719 | + cursor.SetPosition(cursor.position) | ||
| 720 | + self.viewer.interactor.Render() | ||
| 721 | + else: | ||
| 722 | + self.OnScrollBackward(obj, evt) | ||
| 723 | + | ||
| 686 | def get_coordinate_cursor(self): | 724 | def get_coordinate_cursor(self): |
| 687 | # Find position | 725 | # Find position |
| 688 | x, y, z = self.picker.GetPickPosition() | 726 | x, y, z = self.picker.GetPickPosition() |