From 52fc0bb0ff2ee8367624b50b5b8e5bdf976dfc52 Mon Sep 17 00:00:00 2001 From: Thiago Franco de Moraes Date: Fri, 27 Feb 2015 10:16:26 -0300 Subject: [PATCH] Inverting the threshold pen when the control is pressed --- invesalius/constants.py | 1 + invesalius/data/slice_.py | 3 +++ invesalius/data/styles.py | 16 ++++++++++++++-- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/invesalius/constants.py b/invesalius/constants.py index f6db534..bb38a08 100644 --- a/invesalius/constants.py +++ b/invesalius/constants.py @@ -250,6 +250,7 @@ DEFAULT_BRUSH_FORMAT = BRUSH_CIRCLE BRUSH_DRAW = 0 BRUSH_ERASE = 1 BRUSH_THRESH = 2 +BRUSH_THRESH_ERASE = 3 DEFAULT_BRUSH_OP = BRUSH_THRESH BRUSH_OP_NAME = [_("Draw"), _("Erase"), _("Threshold")] diff --git a/invesalius/data/slice_.py b/invesalius/data/slice_.py index 194f51a..d408b4a 100644 --- a/invesalius/data/slice_.py +++ b/invesalius/data/slice_.py @@ -460,6 +460,9 @@ class Slice(object): # (1 * 253 + 1) and out ones gets value 1 (0 * 253 + 1). roi_m[index] = (((roi_i[index] >= thresh_min) & (roi_i[index] <= thresh_max)) * 253) + 1 + elif operation == const.BRUSH_THRESH_ERASE: + roi_m[index] = (((roi_i[index] >= thresh_min) + & (roi_i[index] <= thresh_max)) * 1) -1 elif operation == const.BRUSH_DRAW: roi_m[index] = 254 elif operation == const.BRUSH_ERASE: diff --git a/invesalius/data/styles.py b/invesalius/data/styles.py index 1056568..e48466b 100644 --- a/invesalius/data/styles.py +++ b/invesalius/data/styles.py @@ -556,9 +556,16 @@ class EditorInteractorStyle(DefaultInteractorStyle): if (self.viewer.slice_.buffer_slices[self.orientation].mask is None): return + viewer = self.viewer iren = viewer.interactor + operation = viewer._brush_cursor_op + if operation == const.BRUSH_THRESH: + if iren.GetControlKey(): + operation = const.BRUSH_THRESH_ERASE + + viewer._set_editor_cursor_visibility(1) mouse_x, mouse_y = iren.GetEventPosition() @@ -585,7 +592,7 @@ class EditorInteractorStyle(DefaultInteractorStyle): if position < 0: position = viewer.calculate_matrix_position(coord) - viewer.slice_.edit_mask_pixel(viewer._brush_cursor_op, cursor.GetPixels(), + viewer.slice_.edit_mask_pixel(operation, cursor.GetPixels(), position, radius, viewer.orientation) viewer._flush_buffer = True @@ -605,6 +612,11 @@ class EditorInteractorStyle(DefaultInteractorStyle): render = iren.FindPokedRenderer(mouse_x, mouse_y) slice_data = viewer.get_slice_data(render) + operation = viewer._brush_cursor_op + if operation == const.BRUSH_THRESH: + if iren.GetControlKey(): + operation = const.BRUSH_THRESH_ERASE + # TODO: Improve! #for i in self.slice_data_list: #i.cursor.Show(0) @@ -635,7 +647,7 @@ class EditorInteractorStyle(DefaultInteractorStyle): if position < 0: position = viewer.calculate_matrix_position(coord) - viewer.slice_.edit_mask_pixel(viewer._brush_cursor_op, cursor.GetPixels(), + viewer.slice_.edit_mask_pixel(operation, cursor.GetPixels(), position, radius, self.orientation) # TODO: To create a new function to reload images to viewer. viewer.OnScrollBar(update3D=False) -- libgit2 0.21.2