Commit 52fc0bb0ff2ee8367624b50b5b8e5bdf976dfc52
1 parent
be816908
Exists in
master
and in
46 other branches
Inverting the threshold pen when the control is pressed
Showing
3 changed files
with
18 additions
and
2 deletions
Show diff stats
invesalius/constants.py
@@ -250,6 +250,7 @@ DEFAULT_BRUSH_FORMAT = BRUSH_CIRCLE | @@ -250,6 +250,7 @@ DEFAULT_BRUSH_FORMAT = BRUSH_CIRCLE | ||
250 | BRUSH_DRAW = 0 | 250 | BRUSH_DRAW = 0 |
251 | BRUSH_ERASE = 1 | 251 | BRUSH_ERASE = 1 |
252 | BRUSH_THRESH = 2 | 252 | BRUSH_THRESH = 2 |
253 | +BRUSH_THRESH_ERASE = 3 | ||
253 | DEFAULT_BRUSH_OP = BRUSH_THRESH | 254 | DEFAULT_BRUSH_OP = BRUSH_THRESH |
254 | BRUSH_OP_NAME = [_("Draw"), _("Erase"), _("Threshold")] | 255 | BRUSH_OP_NAME = [_("Draw"), _("Erase"), _("Threshold")] |
255 | 256 |
invesalius/data/slice_.py
@@ -460,6 +460,9 @@ class Slice(object): | @@ -460,6 +460,9 @@ class Slice(object): | ||
460 | # (1 * 253 + 1) and out ones gets value 1 (0 * 253 + 1). | 460 | # (1 * 253 + 1) and out ones gets value 1 (0 * 253 + 1). |
461 | roi_m[index] = (((roi_i[index] >= thresh_min) | 461 | roi_m[index] = (((roi_i[index] >= thresh_min) |
462 | & (roi_i[index] <= thresh_max)) * 253) + 1 | 462 | & (roi_i[index] <= thresh_max)) * 253) + 1 |
463 | + elif operation == const.BRUSH_THRESH_ERASE: | ||
464 | + roi_m[index] = (((roi_i[index] >= thresh_min) | ||
465 | + & (roi_i[index] <= thresh_max)) * 1) -1 | ||
463 | elif operation == const.BRUSH_DRAW: | 466 | elif operation == const.BRUSH_DRAW: |
464 | roi_m[index] = 254 | 467 | roi_m[index] = 254 |
465 | elif operation == const.BRUSH_ERASE: | 468 | elif operation == const.BRUSH_ERASE: |
invesalius/data/styles.py
@@ -556,9 +556,16 @@ class EditorInteractorStyle(DefaultInteractorStyle): | @@ -556,9 +556,16 @@ class EditorInteractorStyle(DefaultInteractorStyle): | ||
556 | if (self.viewer.slice_.buffer_slices[self.orientation].mask is None): | 556 | if (self.viewer.slice_.buffer_slices[self.orientation].mask is None): |
557 | return | 557 | return |
558 | 558 | ||
559 | + | ||
559 | viewer = self.viewer | 560 | viewer = self.viewer |
560 | iren = viewer.interactor | 561 | iren = viewer.interactor |
561 | 562 | ||
563 | + operation = viewer._brush_cursor_op | ||
564 | + if operation == const.BRUSH_THRESH: | ||
565 | + if iren.GetControlKey(): | ||
566 | + operation = const.BRUSH_THRESH_ERASE | ||
567 | + | ||
568 | + | ||
562 | viewer._set_editor_cursor_visibility(1) | 569 | viewer._set_editor_cursor_visibility(1) |
563 | 570 | ||
564 | mouse_x, mouse_y = iren.GetEventPosition() | 571 | mouse_x, mouse_y = iren.GetEventPosition() |
@@ -585,7 +592,7 @@ class EditorInteractorStyle(DefaultInteractorStyle): | @@ -585,7 +592,7 @@ class EditorInteractorStyle(DefaultInteractorStyle): | ||
585 | if position < 0: | 592 | if position < 0: |
586 | position = viewer.calculate_matrix_position(coord) | 593 | position = viewer.calculate_matrix_position(coord) |
587 | 594 | ||
588 | - viewer.slice_.edit_mask_pixel(viewer._brush_cursor_op, cursor.GetPixels(), | 595 | + viewer.slice_.edit_mask_pixel(operation, cursor.GetPixels(), |
589 | position, radius, viewer.orientation) | 596 | position, radius, viewer.orientation) |
590 | viewer._flush_buffer = True | 597 | viewer._flush_buffer = True |
591 | 598 | ||
@@ -605,6 +612,11 @@ class EditorInteractorStyle(DefaultInteractorStyle): | @@ -605,6 +612,11 @@ class EditorInteractorStyle(DefaultInteractorStyle): | ||
605 | render = iren.FindPokedRenderer(mouse_x, mouse_y) | 612 | render = iren.FindPokedRenderer(mouse_x, mouse_y) |
606 | slice_data = viewer.get_slice_data(render) | 613 | slice_data = viewer.get_slice_data(render) |
607 | 614 | ||
615 | + operation = viewer._brush_cursor_op | ||
616 | + if operation == const.BRUSH_THRESH: | ||
617 | + if iren.GetControlKey(): | ||
618 | + operation = const.BRUSH_THRESH_ERASE | ||
619 | + | ||
608 | # TODO: Improve! | 620 | # TODO: Improve! |
609 | #for i in self.slice_data_list: | 621 | #for i in self.slice_data_list: |
610 | #i.cursor.Show(0) | 622 | #i.cursor.Show(0) |
@@ -635,7 +647,7 @@ class EditorInteractorStyle(DefaultInteractorStyle): | @@ -635,7 +647,7 @@ class EditorInteractorStyle(DefaultInteractorStyle): | ||
635 | if position < 0: | 647 | if position < 0: |
636 | position = viewer.calculate_matrix_position(coord) | 648 | position = viewer.calculate_matrix_position(coord) |
637 | 649 | ||
638 | - viewer.slice_.edit_mask_pixel(viewer._brush_cursor_op, cursor.GetPixels(), | 650 | + viewer.slice_.edit_mask_pixel(operation, cursor.GetPixels(), |
639 | position, radius, self.orientation) | 651 | position, radius, self.orientation) |
640 | # TODO: To create a new function to reload images to viewer. | 652 | # TODO: To create a new function to reload images to viewer. |
641 | viewer.OnScrollBar(update3D=False) | 653 | viewer.OnScrollBar(update3D=False) |